Skip to content

Conversation

@james2037
Copy link
Owner

This commit addresses code coverage gaps in src/Tool/Tool.php for the following areas:

  • initializeMetadata: I added tests for destructiveHint, idempotentHint, and openWorldHint annotations.
  • initialize/shutdown: I added tests to verify these lifecycle methods are callable and log their execution.
  • validateArguments/validateType: I added tests for 'integer', 'object', and 'any' parameter types.

During the process of adding tests for validateArguments, I identified and fixed the following bugs in src/Tool/Tool.php:

  • validateArguments: I changed !isset(\$arguments[\$name]) to !array_key_exists(\$name, \$arguments) to correctly handle required arguments that are present with a null value.
  • validateArguments: I changed if (isset(\$arguments[\$name])) to if (array_key_exists(\$name, \$arguments)) to ensure type validation occurs even for null values if the argument key is present.
  • validateType: I added an explicit check to allow null for the 'any' type and to disallow null by default for other basic types.

All new and existing tests pass, and linters are clean for the src directory. PHPStan errors remain in a test fixture but do not impact the production code.

This commit addresses code coverage gaps in `src/Tool/Tool.php`
for the following areas:

- `initializeMetadata`: I added tests for `destructiveHint`,
  `idempotentHint`, and `openWorldHint` annotations.
- `initialize`/`shutdown`: I added tests to verify these lifecycle
  methods are callable and log their execution.
- `validateArguments`/`validateType`: I added tests for 'integer',
  'object', and 'any' parameter types.

During the process of adding tests for `validateArguments`,
I identified and fixed the following bugs in `src/Tool/Tool.php`:

- `validateArguments`: I changed `!isset(\$arguments[\$name])` to
  `!array_key_exists(\$name, \$arguments)` to correctly handle
  required arguments that are present with a `null` value.
- `validateArguments`: I changed `if (isset(\$arguments[\$name]))`
  to `if (array_key_exists(\$name, \$arguments))` to ensure type
  validation occurs even for `null` values if the argument key
  is present.
- `validateType`: I added an explicit check to allow `null` for
  the 'any' type and to disallow `null` by default for other
  basic types.

All new and existing tests pass, and linters are clean for the `src`
directory. PHPStan errors remain in a test fixture but do not
impact the production code.
@codecov
Copy link

codecov bot commented Jun 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

This commit addresses feedback on the previous submission:

1.  **Cover `\$value === null` branch in `Tool::validateType`**:
    - I added a new test case (`testValidateTypeWithNullForNonAnyTypes`)
      to `tests/Tool/ToolTest.php`.
    - This test specifically verifies that `validateType` returns `false`
      when a non-'any' type parameter (e.g., 'string', 'integer')
      is given a `null` value.

2.  **Resolve PHPStan errors in `tests/Tool/Fixture/ValidationTestTool.php`**:
    - I removed the `#[Parameter]` attributes from the `doExecute` method
      in `ValidationTestTool.php`.
    - These attributes were causing PHPStan errors as they were placed
      on a method instead of a parameter, and were not functionally
      required for the existing tests (which use reflection to set
      parameter metadata for `Tool::validateArguments` testing).

All PHPUnit tests, PHPCS, and PHPStan checks now pass.
@github-actions
Copy link

github-actions bot commented Jun 4, 2025

🧪 Test Results Summary

PHPUnit Tests

✅ All tests passed!

Details: OK (232 tests, 939 assertions)

  • Total Tests: 232
  • Total Assertions: 939

Code Quality

  • PHPCS: ✅ No issues
  • PHPStan: ✅ No errors found

📁 Detailed Reports

  • Coverage Report: Download the test-outputs artifact for detailed HTML coverage report
  • Test Results: Check the "Tests" tab above for detailed test results
  • Raw Logs: View the "Actions" tab for complete output logs

This comment will update automatically when you push new commits.

Code Coverage

Code Coverage

Package Line Rate Health
Capability/CapabilityInterface.php 0%
Capability/ResourcesCapability.php 100%
Capability/ToolsCapability.php 100%
Exception/InvalidParamsException.php 0%
Exception/InvalidRequestException.php 0%
Exception/MethodNotSupportedException.php 0%
Exception/TransportException.php 0%
Message/JsonRpcMessage.php 100%
Registry/Registry.php 97%
Resource/Attribute/ResourceUri.php 100%
Resource/BlobResourceContents.php 100%
Resource/Resource.php 100%
Resource/ResourceContents.php 100%
Resource/ResourceRegistry.php 100%
Resource/TextResourceContents.php 100%
Server.php 69%
Tool/Attribute/Parameter.php 100%
Tool/Attribute/Tool.php 100%
Tool/Attribute/ToolAnnotations.php 100%
Tool/Content/AbstractContent.php 100%
Tool/Content/AbstractMediaContent.php 100%
Tool/Content/Annotations.php 100%
Tool/Content/AudioContent.php 100%
Tool/Content/ContentItemInterface.php 0%
Tool/Content/EmbeddedResource.php 100%
Tool/Content/ImageContent.php 100%
Tool/Content/TextContent.php 100%
Tool/Tool.php 100%
Tool/ToolRegistry.php 100%
Transport/AbstractTransport.php 0%
Transport/HttpTransport.php 70%
Transport/StdioTransport.php 96%
Transport/TransportInterface.php 0%
Summary 87% (858 / 981)

@james2037 james2037 merged commit 2496d16 into master Jun 4, 2025
3 checks passed
@james2037 james2037 deleted the cover-tool-branches branch June 4, 2025 22:08
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.

2 participants