Skip to content

[quality] test: add 35 unit tests for MCP custom resources helpers#19561

Open
clubanderson wants to merge 1 commit into
mainfrom
quality/test-mcp-custom-resources
Open

[quality] test: add 35 unit tests for MCP custom resources helpers#19561
clubanderson wants to merge 1 commit into
mainfrom
quality/test-mcp-custom-resources

Conversation

@clubanderson

Copy link
Copy Markdown
Collaborator

Test Improvement

Adds 35 unit tests for 6 pure helper functions in pkg/api/handlers/mcp/custom_resources.go that had zero test coverage. The MCP package is at 15.8% coverage — the lowest non-cmd package in the Go codebase.

Tests added:

Function Tests What's verified
parseCustomResourceLimit 3 Default value (500), valid range (1-2000), invalid inputs (0, -1, 2001, abc, float)
parseCustomResourceContinueToken 3 Empty default (0), valid range (0-10000), invalid inputs (-1, 10001, abc)
parsePositiveIntQuery 4 Valid range (boundaries, interior), below min, above max, non-integer
paginateCustomResourceItems 6 Basic pagination, second page, offset past end, empty/nil input, exact boundary, partial last page
parseCRItem 4 Complete K8s object, minimal (name only), empty object, non-string label values skipped
minCustomResourceInt 5 All comparison cases including negatives and equality

Why this matters:

  • parseCRItem processes arbitrary K8s CRD data for the MCP interface used by external AI tools — bugs cause silent data loss
  • paginateCustomResourceItems controls fan-out pagination across clusters — off-by-one errors lead to duplicated or missing items
  • parsePositiveIntQuery validates user input — bypass could allow unbounded K8s list queries
  • These are all pure functions requiring no mocks

Fixes #19560


Filed by quality agent (hold-gated mode). Human review required.

…\n[quality] test: add 35 unit tests for MCP custom resources helpers\n\nAdds comprehensive unit tests for 6 pure helper functions in the MCP\ncustom resources handler that had zero test coverage. The package is\nat 15.8% coverage — these tests target the pagination, parsing, and\nvalidation functions:\n\n- parseCustomResourceLimit: 3 tests (default, valid values, invalid)\n- parseCustomResourceContinueToken: 3 tests (empty, valid, invalid)\n- parsePositiveIntQuery: 4 tests (range, below min, above max, non-int)\n- paginateCustomResourceItems: 6 tests (basic, second page, past end,\n empty, exact boundary, partial last page)\n- parseCRItem: 4 tests (complete, minimal, empty, non-string labels)\n- minCustomResourceInt: 5 tests (all comparison cases)\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>"
Copilot AI review requested due to automatic review settings June 25, 2026 01:40
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jun 25, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign eeshaansa for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@netlify

netlify Bot commented Jun 25, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole canceled.

Name Link
🔨 Latest commit 3080c8e
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a3c87162be2700008504eba

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @clubanderson — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🐝 Hi @clubanderson! I'm kubestellar-hive[bot], an automation bot for this repo.

Trusted users — org members and contributors with write access — can mention @kubestellar-hive in a comment to trigger repo automation.
On issues, that mention queues an automated fix attempt. On pull requests, it records extra context for existing automation.
This is not an interactive Q&A bot, so mentions should be treated as requests for automation rather than a conversation.

Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies.

@github-actions github-actions Bot added ai-generated Pull request generated by AI tier/1-lightweight labels Jun 25, 2026
@clubanderson clubanderson added hold Blocked — do not touch quality testing and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. dco-signoff: yes Indicates the PR's author has signed the DCO. ai-generated Pull request generated by AI tier/1-lightweight labels Jun 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the reliability of the MCP custom-resources handler helpers by adding unit test coverage for previously untested, pure helper functions in pkg/api/handlers/mcp/custom_resources.go, addressing the low coverage called out in #19560.

Changes:

  • Added unit tests for query parsing helpers (parseCustomResourceLimit, parseCustomResourceContinueToken, parsePositiveIntQuery) including defaulting, bounds, and invalid inputs.
  • Added unit tests for pagination (paginateCustomResourceItems) covering boundary and empty/nil input scenarios.
  • Added unit tests for unstructured CR parsing (parseCRItem) and comparison helper (minCustomResourceInt) across representative inputs.

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

Labels

hold Blocked — do not touch quality testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[quality] pkg/api/handlers/mcp at 15.8% coverage — 6 pure helpers untested in custom_resources.go

2 participants