Skip to content

Make client request handler results covariant - #770

Open
xixi-box wants to merge 1 commit into
modelcontextprotocol:mainfrom
xixi-box:fix/issue-768-7155eae-2c11e35f
Open

xixi-box wants to merge 1 commit into
modelcontextprotocol:mainfrom
xixi-box:fix/issue-768-7155eae-2c11e35f

Conversation

@xixi-box

Copy link
Copy Markdown

Fixes #768

PHPStan at level max rejects built-in handlers passed to the client builder because the handler interface declares its result type invariant. Declare the return-only result type covariant so elicitation, sampling, and roots handlers satisfy the existing builder contract while preserving PHP signatures and runtime behavior.

Fixes #768.

Tests: vendor/bin/phpstan analyse --level=max --debug --no-progress tests/Unit/Client/BuilderTest.php.
Result: vendor/bin/phpunit tests/Unit/Client tests/Integration/ElicitationTest.php tests/Integration/SamplingTest.php tests/Integration/SamplingToolsTest.php tests/Integration/RootsTest.php tests/Integration/StatelessClientTest.php on base before adding the regression: exit 0, OK (1458 tests, 5099 assertions).
Result: vendor/bin/phpstan analyse --level=max --debug --no-progress tests/Unit/Client/BuilderTest.php on base with the regression: exit 1, argument.type for elicitation, sampling, and roots registrations in testAddRequestHandlerAcceptsConcreteResultTypes.
Result: vendor/bin/phpstan analyse --level=max --debug --no-progress tests/Unit/Client/BuilderTest.php on patched: exit 0, [OK] No errors.
Result: vendor/bin/phpstan analyse --no-progress --level=max tests/Integration/ElicitationTest.php on base: exit 1 with the reported argument.type diagnostic at the existing elicitation registration.
Result: vendor/bin/phpstan analyse --level=max --no-progress tests/Integration/ElicitationTest.php src/Client/Handler/Request/RequestHandlerInterface.php on patched: exit 0, [OK] No errors.
Result: vendor/bin/phpunit --filter testAddRequestHandlerAcceptsConcreteResultTypes tests/Unit/Client/BuilderTest.php --log-junit /tmp/oss-scout-php-sdk-builder-junit.xml on patched: exit 0, OK (1 test, 3 assertions).
Result: vendor/bin/phpunit tests/Unit/Client tests/Integration/ElicitationTest.php tests/Integration/SamplingTest.php tests/Integration/SamplingToolsTest.php tests/Integration/RootsTest.php tests/Integration/StatelessClientTest.php on patched: exit 0, OK (1459 tests, 5102 assertions).
Result: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --dry-run --diff --using-cache=no src/Client/Handler/Request/RequestHandlerInterface.php tests/Unit/Client/BuilderTest.php: exit 0, found 0 of 2 files that can be fixed.
Result: make -C /tmp/oss-scout-php-sdk-ci.MUKCwl ci on an isolated copy of the patched sources: exit 0. Composer stable resolved the installed dependencies, CS Fixer changed 0 files, PHPStan reported no errors, and Deptrac reported 0 violations. Full PHPUnit run including unit, integration, and interop reported Tests: 4435, Assertions: 13692, Skipped: 8.
Regression coverage: tests/Unit/Client/BuilderTest.php.

Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Client] Builder::addRequestHandler() rejects the SDK's own handlers under PHPStan

1 participant