Skip to content

fix(api): validate discovery routes against published schemas - #10148

Closed
andriypolanski wants to merge 2 commits into
JSONbored:mainfrom
andriypolanski:fix/10040-discovery-schema-validation
Closed

fix(api): validate discovery routes against published schemas#10148
andriypolanski wants to merge 2 commits into
JSONbored:mainfrom
andriypolanski:fix/10040-discovery-schema-validation

Conversation

@andriypolanski

Copy link
Copy Markdown
Contributor

Summary

  • Derive FindOpportunitiesRequestSchema / IssueRagRetrieveRequestSchema from @loopover/contract's FindOpportunitiesInput / RetrieveIssueContextInput (single source for MCP, REST, OpenAPI).
  • Parse both discovery route bodies with those schemas before the hand-rolled validators; map schema failures onto the existing invalid_request + reason shapes.
  • Add .min(1) on RetrieveIssueContextInput owner/repo/title; stop silent truncation of over-long labels/body; document the cross-field targets/searchQuery rule on the OpenAPI operation.

Test plan

  • npx vitest run test/unit/find-opportunities.test.ts test/unit/mcp-issue-rag.test.ts test/unit/mcp-find-opportunities.test.ts test/unit/contract-registry.test.ts test/unit/openapi.test.ts
  • npx vitest run test/integration/api.test.ts -t "REGRESSION: discovery routes"
  • npm run ui:openapi

Fixes #10040

Single-source FindOpportunities and IssueRag request bodies from
@loopover/contract, enforce them on REST before hand-rolled checks, and
stop silent truncation of over-long labels/body.

Co-authored-by: Cursor <cursoragent@cursor.com>
@loopover-orb

loopover-orb Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Important

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏳ LoopOver is waiting…

LoopOver has seen this pull request and is waiting on CI checks to finish before reviewing it. This comment will update once the review runs.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed · 🟨 Waiting

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

❌ 3 Tests Failed:

Tests completed Failed Passed Skipped
2596 3 2593 0
View the top 3 failed test(s) by shortest run time
test/unit/issue-rag-mcp.test.ts > runIssueRagRetrieval (#4293) > covers validation branches for owner/title/body/labels/topK normalization
Stack Traces | 0.00213s run time
AssertionError: expected { ok: true, …(1) } to match object { ok: false, reason: 'title_too_long' }
(5 matching properties omitted from actual)

- Expected
+ Received

  {
-   "ok": false,
-   "reason": "title_too_long",
+   "ok": true,
  }

 ❯ test/unit/issue-rag-mcp.test.ts:50:7
test/unit/issue-rag-mcp.test.ts > runIssueRagRetrieval (#4293) > rejects oversized repos and invalid labels
Stack Traces | 0.013s run time
AssertionError: expected { ok: true, …(1) } to match object { ok: false, reason: 'repo_too_long' }
(5 matching properties omitted from actual)

- Expected
+ Received

  {
-   "ok": false,
-   "reason": "repo_too_long",
+   "ok": true,
  }

 ❯ test/unit/issue-rag-mcp.test.ts:25:154
test/unit/routes-issue-rag.test.ts > issue-rag retrieve route (#4293) > rejects invalid requests and malformed JSON bodies
Stack Traces | 0.0432s run time
AssertionError: expected { status: 'invalid_request', …(3) } to match object { status: 'invalid_request', …(1) }
(5 matching properties omitted from actual)

- Expected
+ Received

  {
-   "reason": "title_required",
+   "reason": "invalid_body",
    "status": "invalid_request",
  }

 ❯ test/unit/routes-issue-rag.test.ts:74:33

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 31, 2026
…lidation

Update validateIssueRagInput and route rejection expectations so length
bounds live on RetrieveIssueContextInput and empty/malformed bodies map
to invalid_body, matching the discovery schema gate.

Co-authored-by: Cursor <cursoragent@cursor.com>
@loopover-orb loopover-orb Bot closed this Jul 31, 2026
@loopover-orb

loopover-orb Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

This repository reviews pull requests one-shot: the PR must be correct as originally opened. Pushing an additional commit closes it automatically instead of restarting review — open a fresh pull request with every fix included.

@loopover-orb loopover-orb Bot added the review-evasion Gittensor contributor context label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. review-evasion Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

api(discovery): validate /v1/opportunities/find and /v1/issue-rag/retrieve against the schemas their spec publishes

1 participant