diff --git a/CHANGELOG.md b/CHANGELOG.md index 69c8beb0..74954a86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to `mcp/sdk` will be documented in this file. * Fix `InMemorySessionStore::exists()` reporting a session past its TTL as existing, while `read()` already treated it as gone. * Fix `Psr16NotificationBus` subscribers missing the notifications published after the bus stayed quiet for longer than its TTL: the sequence counter no longer expires, and a subscriber whose cursor is ahead of a lost counter reads what the bus holds. * Fix `Session::save()` wiping the other keys of a session that the store failed to read, e.g. when `Psr16SessionStore` hits a cache error: it now returns `false` instead of writing the changed keys alone. +* Fix `EnumCompletionProvider` and `ListCompletionProvider` offering all values for the prefix `"0"` instead of only the values that start with it. * Add `Psr6SessionStore` and `Psr6NotificationBus`, which work like `Psr16SessionStore` and `Psr16NotificationBus` over a PSR-6 cache pool. `Builder::setDiscovery()` also accepts a PSR-6 pool as `$cache`. ### Client diff --git a/src/Capability/Completion/EnumCompletionProvider.php b/src/Capability/Completion/EnumCompletionProvider.php index 3c50eba5..f9816193 100644 --- a/src/Capability/Completion/EnumCompletionProvider.php +++ b/src/Capability/Completion/EnumCompletionProvider.php @@ -40,7 +40,7 @@ public function __construct(string $enumClass) public function getCompletions(string $currentValue): array { - if (empty($currentValue)) { + if ('' === $currentValue) { return $this->values; } diff --git a/src/Capability/Completion/ListCompletionProvider.php b/src/Capability/Completion/ListCompletionProvider.php index 45a41c45..5e066dec 100644 --- a/src/Capability/Completion/ListCompletionProvider.php +++ b/src/Capability/Completion/ListCompletionProvider.php @@ -31,7 +31,7 @@ public function __construct(array $values) public function getCompletions(string $currentValue): array { - if (empty($currentValue)) { + if ('' === $currentValue) { return $this->values; } diff --git a/tests/Unit/Capability/Completion/EnumCompletionProviderTest.php b/tests/Unit/Capability/Completion/EnumCompletionProviderTest.php index f0ca3d46..4bbc292a 100644 --- a/tests/Unit/Capability/Completion/EnumCompletionProviderTest.php +++ b/tests/Unit/Capability/Completion/EnumCompletionProviderTest.php @@ -32,10 +32,17 @@ public function testPrefixMatchesKeepCaseOrder(): void $this->assertSame([], $provider->getCompletions('missing')); } - public function testZeroPrefixOffersAllCases(): void + public function testEmptyPrefixOffersAllCases(): void { $provider = new EnumCompletionProvider(CompletionFixture::class); - $this->assertSame(['alpha', 'alpine', 'algebra', '0'], $provider->getCompletions('0')); + $this->assertSame(['alpha', 'alpine', 'algebra', '0'], $provider->getCompletions('')); + } + + public function testZeroIsMatchedAsPrefix(): void + { + $provider = new EnumCompletionProvider(CompletionFixture::class); + + $this->assertSame(['0'], $provider->getCompletions('0')); } } diff --git a/tests/Unit/Capability/Completion/ListCompletionProviderTest.php b/tests/Unit/Capability/Completion/ListCompletionProviderTest.php index 9a9ca9fc..4870d737 100644 --- a/tests/Unit/Capability/Completion/ListCompletionProviderTest.php +++ b/tests/Unit/Capability/Completion/ListCompletionProviderTest.php @@ -42,6 +42,13 @@ public function testNumericValuesBecomeStrings(): void $this->assertSame(['101', '102.5'], $provider->getCompletions('10')); } + public function testZeroIsMatchedAsPrefix(): void + { + $provider = new ListCompletionProvider(['zero', '0', '01']); + + $this->assertSame(['0', '01'], $provider->getCompletions('0')); + } + public function testKeysAreDiscarded(): void { $provider = new ListCompletionProvider([5 => 'a', 9 => 'b']);