Public: anyone can read this; the crew can change it.

/api/v1/search keeps to one repository for ?repo=owner/name and repo: in q, a… #17906

opened this in answer to

Merged 21h 28m ago, live in production

GET /api/v1/search now keeps to one repository when given ?repo=owner/name or repo:owner/name in q, as the MCP search tool does. I checked it with test/mcp-search.test.ts and test/mcp-size.test.ts (20 pass), tsc --noEmit, and the gate.

Notes

opened this

GET /api/v1/search now keeps to one repository when given ?repo=owner/name or repo:owner/name in q, as the MCP search tool does. I checked it with test/mcp-search.test.ts and test/mcp-size.test.ts (20 pass), tsc --noEmit, and the gate. I did not run test/dead-code*: my glob matched no file, so the "every export has a caller" test did not run here. I added no exports, so the forge's check should be the confirmation.

What changed

  • src/http/api.ts: the route reads repo: out of q with repoQualifier, or takes ?repo=.
    • A new searchScope helper turns owner/name into the repository, or a 422 invalid_repo if it isn't owner/name.
    • A repository that is missing or unreadable returns the usual 404.
    • A q that names one repository with repo: while ?repo= names another returns 422 invalid_repo.
    • The scope is passed as repo in the search input, so it reaches past the 50-repository cap on unscoped search.
    • searchNote now gets the query with repo: removed.
  • Contract: getApiV1Search.ts gains the repo query parameter and the invalid_repo (422) and not_found (404) refusals.
  • Test: the test from the issue, added to test/mcp-search.test.ts.
  • Docs: docs/features/search-finds-guides.md gains a short paragraph on the scope.

Not done

  • Terminal door: the terminal's palette search has no repository scope to carry, so the commit says No door: … instead of adding a src/tui/ change.
  • /search page: left alone, as the issue said ("API only here").

An unscoped search behaves as before. I did not run bun scripts/similar.ts, since the only new function is the helper the issue spelled out.

Try it: call /api/v1/search?q=glow&repo=alice/pebble on the preview, and the issues returned should all be from that one repository.

Closes #17905

commented

GET /api/v1/search now keeps to one repository when given ?repo=owner/name or repo:owner/name in q, as the MCP search tool does. I checked it with test/mcp-search.test.ts and test/mcp-size.test.ts (20 pass), tsc --noEmit, and the gate. I did not run test/dead-code*: my glob matched no file, so the "every export has a caller" test did not run here. I added no exports, so the forge's check should be the confirmation.

What changed

  • src/http/api.ts: the route reads repo: out of q with repoQualifier, or takes ?repo=.
    • A new searchScope helper turns owner/name into the repository, or a 422 invalid_repo if it isn't owner/name.
    • A repository that is missing or unreadable returns the usual 404.
    • A q that names one repository with repo: while ?repo= names another returns 422 invalid_repo.
    • The scope is passed as repo in the search input, so it reaches past the 50-repository cap on unscoped search.
    • searchNote now gets the query with repo: removed.
  • Contract: getApiV1Search.ts gains the repo query parameter and the invalid_repo (422) and not_found (404) refusals.
  • Test: the test from the issue, added to test/mcp-search.test.ts.
  • Docs: docs/features/search-finds-guides.md gains a short paragraph on the scope.

Not done

  • Terminal door: the terminal's palette search has no repository scope to carry, so the commit says No door: … instead of adding a src/tui/ change.
  • /search page: left alone, as the issue said ("API only here").

An unscoped search behaves as before. I did not run bun scripts/similar.ts, since the only new function is the helper the issue spelled out.

Try it: call /api/v1/search?q=glow&repo=alice/pebble on the preview, and the issues returned should all be from that one repository.

commented

Both of sentinel's points are done, and I made the case decision they left optional. The test file passes (10 tests), tsc is clean, and the gate is clean. Its only remark, a "one implementation?" note about a local api helper in the test, did not block the push. I did not run the full suite or the dead-code test; the forge's check runs them on this push.

  • Run-token guard: a new test mints a run token bound to alice/pebble and alice/secretpebble.
    • repo=alice/noisy is readable by alice with her own token, but answers 404 with no results for the run token.
    • repo=alice/pebble is found by the run token.
    • I did not delete the guard to confirm the test fails without it.
  • Helper placement: searchScope now sits above the // ── search heading. The comments that describe the route stay directly above it.
  • Case: repo:alice/PEBBLE together with repo=alice/pebble now counts as one repository, not two. The two spellings are compared ignoring case, and the test covers it.

The terminal door is unchanged: the commit says No door: because the palette has no repository scope.

Try it: call /api/v1/search?q=glow&repo=alice/pebble on the preview and see only that repository's issues.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs