Skip to content

pkg/mcp: add tests for readonly enforcement, delete validation, and help resources#3666

Open
Ankitsinghsisodya wants to merge 2 commits intoknative:mainfrom
Ankitsinghsisodya:fix/mcp-missing-test-coverage
Open

pkg/mcp: add tests for readonly enforcement, delete validation, and help resources#3666
Ankitsinghsisodya wants to merge 2 commits intoknative:mainfrom
Ankitsinghsisodya:fix/mcp-missing-test-coverage

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

Summary

  • tools_deploy_test.go and tools_delete_test.go each had a single happy-path test that manually set server.readonly = false, leaving the readonly guard in both handlers completely untested.
  • The mutual-exclusion validation in deleteHandler (exactly one of path or name must be provided) had no test coverage for either branch.
  • All 14 func://help/* resources registered in mcp.go had zero tests; the newHelpResource handler — URI construction, executor dispatch, args assembly, and response shape — was entirely unexercised.

Changes

  • pkg/mcp/tools_deploy_test.go: add TestTool_Deploy_Readonly — uses newTestPairWithReadonly(t, true) and asserts result.IsError.
  • pkg/mcp/tools_delete_test.go: add TestTool_Delete_Readonly, TestTool_Delete_BothPathAndName, and TestTool_Delete_NeitherPathNorName.
  • pkg/mcp/resources_test.go: add TestResource_Help — table-driven test over 6 func://help/* URIs that validates executor subcommand, args, response URI, MIME type, and body text.

Test plan

  • go test ./pkg/mcp/... passes (all 10 new tests green)
  • make test passes
  • make check passes

Copilot AI review requested due to automatic review settings May 6, 2026 21:46
@knative-prow knative-prow Bot requested review from dsimansk and jrangelramos May 6, 2026 21:46
@knative-prow knative-prow Bot added size/L 🤖 PR changes 100-499 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels May 6, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 6, 2026

Hi @Ankitsinghsisodya. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds targeted test coverage in pkg/mcp to ensure MCP tools/resources correctly enforce readonly mode, validate delete input, and correctly dispatch/shape help resource responses.

Changes:

  • Added readonly-mode negative-path tests for deploy and delete tools.
  • Added delete input validation tests for mutual exclusion and missing required selector (path vs name).
  • Added a table-driven test validating func://help/* resource dispatch (executor args) and response shape.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pkg/mcp/tools_deploy_test.go Adds a readonly enforcement test for the deploy tool.
pkg/mcp/tools_delete_test.go Adds readonly and input-validation error-path tests for delete.
pkg/mcp/resources_test.go Adds table-driven coverage for help resources’ executor dispatch and returned content.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/mcp/tools_delete_test.go Outdated
Comment thread pkg/mcp/tools_delete_test.go Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.94%. Comparing base (b819db5) to head (1fe74bb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3666      +/-   ##
==========================================
+ Coverage   54.42%   56.94%   +2.52%     
==========================================
  Files         181      181              
  Lines       20926    20926              
==========================================
+ Hits        11389    11917     +528     
+ Misses       8423     7803     -620     
- Partials     1114     1206      +92     
Flag Coverage Δ
e2e 36.14% <ø> (-0.02%) ⬇️
e2e go 32.74% <ø> (ø)
e2e node 28.47% <ø> (ø)
e2e python 33.11% <ø> (ø)
e2e quarkus 28.61% <ø> (+0.02%) ⬆️
e2e rust 28.01% <ø> (-0.02%) ⬇️
e2e springboot 26.49% <ø> (-0.03%) ⬇️
e2e typescript 28.58% <ø> (ø)
e2e-config-ci 17.88% <ø> (ø)
integration 17.42% <ø> (?)
unit macos-14 45.00% <ø> (+0.05%) ⬆️
unit macos-latest 45.00% <ø> (+0.05%) ⬆️
unit ubuntu-24.04-arm 45.18% <ø> (+0.05%) ⬆️
unit ubuntu-latest 45.85% <ø> (+0.05%) ⬆️
unit windows-latest 44.99% <ø> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@lkingland lkingland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the gap analysis in the description is accurate (the existing handler tests manually set server.readonly = false, so the guard was uncovered).

One heads-up: this PR and #3667 both add a function called TestResource_Help to pkg/mcp/resources_test.go, so whichever lands second will hit a merge conflict

/lgtm

@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label May 8, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 8, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Ankitsinghsisodya, lkingland

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow Bot added the approved 🤖 PR has been approved by an approver from all required OWNERS files. label May 8, 2026
@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label May 8, 2026
- Implemented TestResource_Help to validate help command behavior for various subcommands.
- Added tests for the delete tool to ensure it handles readonly mode and validation errors correctly when both path and name are provided, or neither is provided.
- Included TestTool_Delete_Readonly, TestTool_Delete_BothPathAndName, and TestTool_Delete_NeitherPathNorName to cover these scenarios.

These tests enhance the coverage and reliability of the MCP resource and tool functionalities.
- Simplified the test setup in TestTool_Delete_BothPathAndName and TestTool_Delete_NeitherPathNorName by removing the unused server variable from newTestPair.
- This change enhances code clarity and maintains the focus on testing the delete tool's functionality.
@Ankitsinghsisodya Ankitsinghsisodya force-pushed the fix/mcp-missing-test-coverage branch from fd13b24 to 1fe74bb Compare May 8, 2026 08:21
@knative-prow knative-prow Bot removed the lgtm 🤖 PR is ready to be merged. label May 8, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 8, 2026

New changes are detected. LGTM label has been removed.

@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label May 8, 2026
@knative-prow knative-prow Bot added size/M 🤖 PR changes 30-99 lines, ignoring generated files. and removed size/L 🤖 PR changes 100-499 lines, ignoring generated files. labels May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved 🤖 PR has been approved by an approver from all required OWNERS files. needs-ok-to-test 🤖 Needs an org member to approve testing size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants