Public: anyone can read this; the crew can change it.
/api/v1/search answers kind=pulls (and kind=issues meaning issues only), so a narrowed search returns N of the kind asked for #17001
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/7633-api-v1-search-answers-kind-pulls-and-kin → main 0 commits fork 1 thread · 1 unresolved
16 files
changed +95
−100
- docs/CLI.md
- docs/features/search-finds-guides.md
- src/actions/search.ts
- src/cli/commands/search.ts
- src/cli/main.ts
- src/contract/openapi/routes/getApiV1Search.ts
- src/core/search.ts
- src/http/mcp/reads.ts
- src/tui/forge.ts
- src/web/pages/search.ts
- test/cli-search.test.ts
- test/mcp-search.test.ts
- test/search-docs.test.ts
- test/search-note.test.ts
- test/search-page.test.ts
- test/search.test.ts
docs/CLI.md +3 −4
| @@ -425,11 +425,10 @@ the retry time and exits 6; a 401 exits 3. | ||
| 425 | 425 | Flags: |
| 426 | 426 | |
| 427 | 427 | - `--kind code|issues|pulls|repos|all` — one kind (exit 2 for anything |
| 428 | else). `issues` and `pulls` ask the API for its whole window and cut to | |
| 429 | `--limit` after keeping the one kind. | |
| 428 | else), passed to the API as it is: `issues` answers issues only and | |
| 429 | `pulls` pulls only, so `--limit` counts the kind asked for. | |
| 430 | 430 | - `--limit N` — at most N hits per kind, a whole number above 0. |
| 431 | - `--json` — the forge's answer as it came; for `--kind issues|pulls`, | |
| 432 | narrowed, with `truncated.issues` set when more matched. | |
| 431 | - `--json` — the forge's answer as it came. | |
| 433 | 432 | |
| 434 | 433 | console |
| 435 | 434 | $ forge search retry budget |
docs/features/search-finds-guides.md +10
| @@ -13,3 +13,13 @@ The same group comes back from `GET /api/v1/search` (`docs`, all five) and the | ||
| 13 | 13 | MCP `search` tool. The page shows the first two with a short snippet, to keep |
| 14 | 14 | the first view small. The terminal's palette (`ctrl+p`) has a **Guides** |
| 15 | 15 | section above Code: Enter reads the guide in the docs screen. |
| 16 | ||
| 17 | ## Narrowing to pull requests | |
| 18 | ||
| 19 | `kind=pulls` returns pull requests only, and `kind=issues` issues only, so a | |
| 20 | limit counts the kind asked for. The page has a **Pull requests** chip that | |
| 21 | links to `/search?q=…&kind=pulls` and shows as current; the API takes the same | |
| 22 | `kind` (`GET /api/v1/search?q=retry&kind=pulls`), and `forge search retry | |
| 23 | --kind pulls --limit 5` passes it through. In the terminal's search (palette, | |
| 24 | `ctrl+k`) start the query with `pulls:` — `pulls: retry` — for pull requests | |
| 25 | only. |
src/actions/search.ts +8 −3
| @@ -58,7 +58,7 @@ export function searchRefusal( | ||
| 58 | 58 | ): { code: "invalid_kind" | "invalid_limit"; message: string } | undefined { |
| 59 | 59 | if (rawKind !== null && rawKind !== undefined && rawKind !== "all" && searchKind(rawKind) === "all") { |
| 60 | 60 | const asked = rawKind.length > 40 ? `${rawKind.slice(0, 39)}…` : rawKind; |
| 61 | return { code: "invalid_kind", message: `kind ${JSON.stringify(asked)} is not a kind — use all, repos, issues or code` }; | |
| 61 | return { code: "invalid_kind", message: `kind ${JSON.stringify(asked)} is not a kind — use all, repos, issues, pulls or code` }; | |
| 62 | 62 | } |
| 63 | 63 | if (rawLimit !== null && rawLimit !== undefined) { |
| 64 | 64 | const n = typeof rawLimit === "number" ? rawLimit : /^\d{1,4}$/.test(rawLimit) ? Number(rawLimit) : 0; |
| @@ -158,7 +158,10 @@ export async function search( | ||
| 158 | 158 | setTimeout(() => during("search-warm-start", first, undefined, app), 0); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | const wants = (which: SearchKind) => kind === "all" || kind === which; | |
| 161 | // `issues` and `pulls` are one search over the conversations, narrowed to one kind in the query. | |
| 162 | const wants = (which: SearchKind) => | |
| 163 | kind === "all" || kind === which || (which === "issues" && kind === "pulls"); | |
| 164 | const only = kind === "issues" ? "issue" : kind === "pulls" ? "pull" : undefined; | |
| 162 | 165 | |
| 163 | 166 | const phase = input.phase ?? (() => {}); |
| 164 | 167 | // The visibility pass is the first of the repos' work, so its clock starts here. |
| @@ -199,12 +202,14 @@ export async function search( | ||
| 199 | 202 | .map((r) => r.id), |
| 200 | 203 | ), |
| 201 | 204 | actor !== undefined && isActive(actor) ? actor.id : undefined, |
| 205 | only, | |
| 202 | 206 | ) |
| 203 | 207 | : []; |
| 204 | 208 | const localIssueCount = issues.length; |
| 205 | 209 | |
| 206 | 210 | if (wants("issues") && input.live === true && actor !== undefined) { |
| 207 | issues.push(...(await liveIssues(app, actor, q, limit))); | |
| 211 | const live = await liveIssues(app, actor, q, limit); | |
| 212 | issues.push(...(only === undefined ? live : live.filter((h) => h.kind === only))); | |
| 208 | 213 | } |
| 209 | 214 | if (wants("issues")) phase("issues", performance.now() - issuesAt); |
| 210 | 215 |
src/cli/commands/search.ts +5 −41
| @@ -7,19 +7,13 @@ import { inert, type Out } from "../out.ts"; | ||
| 7 | 7 | import { displayWidth, pad, truncate } from "../../tui/term/width.ts"; |
| 8 | 8 | import type { Command } from "./types.ts"; |
| 9 | 9 | |
| 10 | /** The forge's default and ceiling for `limit` (`src/actions/search.ts`). */ | |
| 11 | const SEARCH_API_LIMIT = 20; | |
| 12 | const SEARCH_API_LIMIT_MAX = 100; | |
| 13 | ||
| 14 | 10 | const SEARCH_KINDS = ["code", "issues", "pulls", "repos", "all"] as const; |
| 15 | 11 | export type SearchFor = (typeof SEARCH_KINDS)[number]; |
| 16 | 12 | |
| 17 | 13 | /** |
| 18 | 14 | * `GET /api/v1/search` from a shell: every hit one line, grouped by kind. |
| 19 | * The API has no `pulls` kind — its `issues` answers both — so `--kind | |
| 20 | * issues` and `--kind pulls` ask for `issues` at the API's ceiling and | |
| 21 | * keep N of the one kind (`narrowConversations`): asking for N and then | |
| 22 | * filtering would print fewer than N, or none. | |
| 15 | * `--kind` and `--limit` go to the forge as they are: its `issues` and | |
| 16 | * `pulls` kinds each answer only theirs, so the limit counts that kind. | |
| 23 | 17 | */ |
| 24 | 18 | async function search(out: Out, args: Args): Promise<number> { |
| 25 | 19 | const words = args.positional.join(" ").trim(); |
| @@ -42,12 +36,9 @@ async function search(out: Out, args: Args): Promise<number> { | ||
| 42 | 36 | } |
| 43 | 37 | const loaded = await requireConfig(out); |
| 44 | 38 | if (typeof loaded === "number") return loaded; |
| 45 | const oneConversation = kind === "issues" || kind === "pulls"; | |
| 46 | 39 | const answer = await new ForgeApi(loaded.url, loaded.token).search(words, { |
| 47 | ...(kind === undefined ? {} : { kind: oneConversation ? "issues" : kind }), | |
| 48 | ...(oneConversation | |
| 49 | ? { limit: SEARCH_API_LIMIT_MAX } | |
| 50 | : limit === undefined ? {} : { limit }), | |
| 40 | ...(kind === undefined ? {} : { kind }), | |
| 41 | ...(limit === undefined ? {} : { limit }), | |
| 51 | 42 | }); |
| 52 | 43 | if (!answer.ok) { |
| 53 | 44 | const { message, retryAfter, status } = answer.error; |
| @@ -59,9 +50,7 @@ async function search(out: Out, args: Args): Promise<number> { | ||
| 59 | 50 | if (status === 429) return EXIT.rateLimited; |
| 60 | 51 | return status === 401 ? EXIT.notConfigured : EXIT.failed; |
| 61 | 52 | } |
| 62 | const found = oneConversation | |
| 63 | ? narrowConversations(answer.value, kind, limit ?? SEARCH_API_LIMIT) | |
| 64 | : answer.value; | |
| 53 | const found = answer.value; | |
| 65 | 54 | if (args.flag("json")) { |
| 66 | 55 | out.line(JSON.stringify(found)); |
| 67 | 56 | return EXIT.ok; |
| @@ -75,31 +64,6 @@ async function search(out: Out, args: Args): Promise<number> { | ||
| 75 | 64 | return EXIT.ok; |
| 76 | 65 | } |
| 77 | 66 | |
| 78 | /** | |
| 79 | * The answer with `issues` kept to one kind (`issue` or `pull`) and cut to | |
| 80 | * `limit`; `truncated.issues` is set when the cut dropped any, or when the | |
| 81 | * forge had already cut its own window, so `--json` and the group header | |
| 82 | * both say the list is not whole. Everything else passes through. | |
| 83 | */ | |
| 84 | export function narrowConversations( | |
| 85 | raw: unknown, | |
| 86 | kind: "issues" | "pulls", | |
| 87 | limit: number, | |
| 88 | ): unknown { | |
| 89 | if (typeof raw !== "object" || raw === null) return raw; | |
| 90 | const body = raw as Record<string, unknown>; | |
| 91 | const want = kind === "pulls" ? "pull" : "issue"; | |
| 92 | const kept = rowsOf(body["issues"]).filter((r) => r["kind"] === want); | |
| 93 | const truncated = (typeof body["truncated"] === "object" && body["truncated"] !== null | |
| 94 | ? body["truncated"] | |
| 95 | : {}) as Record<string, unknown>; | |
| 96 | return { | |
| 97 | ...body, | |
| 98 | issues: kept.slice(0, limit), | |
| 99 | truncated: { ...truncated, issues: truncated["issues"] === true || kept.length > limit }, | |
| 100 | }; | |
| 101 | } | |
| 102 | ||
| 103 | 67 | /** |
| 104 | 68 | * The search answer as lines no wider than `width - 1` where the text can |
| 105 | 69 | * give way: each kind headed by its name and count, then one hit a line — |
src/cli/main.ts +1 −1
| @@ -30,7 +30,7 @@ import { createOut } from "./out.ts"; | ||
| 30 | 30 | |
| 31 | 31 | // Callers (and tests) have always reached these through this file. |
| 32 | 32 | export { asks, askLines, type Confirm } from "./commands/asks.ts"; |
| 33 | export { searchLines, narrowConversations, type SearchFor } from "./commands/search.ts"; | |
| 33 | export { searchLines, type SearchFor } from "./commands/search.ts"; | |
| 34 | 34 | export { EXIT }; |
| 35 | 35 | |
| 36 | 36 | /** Every command by name, built once from `commands/index.ts`. */ |
src/contract/openapi/routes/getApiV1Search.ts +1 −1
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | import { type Route, limitTo } from "../shared.ts"; |
| 2 | 2 | import { SEARCH_LIMIT_MAX } from "../../../actions/search.ts"; |
| 3 | 3 | |
| 4 | export const route: Route = { method: "get", path: "/api/v1/search", summary: "Search guides, issues, pulls, repositories and code; `kind` narrows it", auth: false, role: "anonymous", query: { q: "string", kind: "string", limit: limitTo(SEARCH_LIMIT_MAX) }, refusals: { invalid_kind: "kind is not all, repos, issues or code (422)", invalid_limit: "limit is not a whole number from 1 to 100 (422)" }, reply: { repos: "array", issues: "array", code: "array", docs: "array of { title, path, snippet }, at most 5, guides matching; only for kind all", truncated: "object", moreCode: "boolean", codeSkipped: "boolean", note: "string, only when q is blank: what to send" } }; | |
| 4 | export const route: Route = { method: "get", path: "/api/v1/search", summary: "Search guides, issues, pulls, repositories and code; `kind` narrows it", auth: false, role: "anonymous", query: { q: "string", kind: "string", limit: limitTo(SEARCH_LIMIT_MAX) }, refusals: { invalid_kind: "kind is not all, repos, issues, pulls or code (422)", invalid_limit: "limit is not a whole number from 1 to 100 (422)" }, reply: { repos: "array", issues: "array", code: "array", docs: "array of { title, path, snippet }, at most 5, guides matching; only for kind all", truncated: "object", moreCode: "boolean", codeSkipped: "boolean", note: "string, only when q is blank: what to send" } }; |
src/core/search.ts +8 −3
| @@ -73,10 +73,10 @@ export const CODE_TOO_SHORT = `Code is searched for ${MIN_CODE_QUERY} or more ch | ||
| 73 | 73 | /** Longest line of code echoed back; the rest is off-screen anyway. */ |
| 74 | 74 | const MAX_LINE_CHARS = 400; |
| 75 | 75 | |
| 76 | export type SearchKind = "repos" | "issues" | "code" | "all"; | |
| 76 | export type SearchKind = "repos" | "issues" | "pulls" | "code" | "all"; | |
| 77 | 77 | |
| 78 | 78 | export function searchKind(raw: string | null): SearchKind { |
| 79 | return raw === "repos" || raw === "issues" || raw === "code" ? raw : "all"; | |
| 79 | return raw === "repos" || raw === "issues" || raw === "pulls" || raw === "code" ? raw : "all"; | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| @@ -100,7 +100,7 @@ export function repoQualifier(q: string): { readonly q: string; readonly repo?: | ||
| 100 | 100 | */ |
| 101 | 101 | export function searchNote(rawQ: string | null, kind: SearchKind = "all"): string | undefined { |
| 102 | 102 | if (cleanQuery(rawQ ?? "") === "") |
| 103 | return "q is empty — send what to find, e.g. q=parser&kind=code (kind=all|repos|issues|code)"; | |
| 103 | return "q is empty — send what to find, e.g. q=parser&kind=code (kind=all|repos|issues|pulls|code)"; | |
| 104 | 104 | // Only a search that asked for code is told the code was not grepped. |
| 105 | 105 | if ((kind === "all" || kind === "code") && !greppable(rawQ ?? "")) return CODE_TOO_SHORT; |
| 106 | 106 | return undefined; |
| @@ -422,8 +422,12 @@ export function searchLocalIssues( | ||
| 422 | 422 | sealedOk: ReadonlySet<string> = new Set(), |
| 423 | 423 | /** And the sealed reports this user filed, wherever they are. */ |
| 424 | 424 | sealedBy?: string, |
| 425 | /** Only this kind of conversation, so `limit` counts the kind asked for; unset: both. */ | |
| 426 | only?: "issue" | "pull", | |
| 425 | 427 | ): IssueHit[] { |
| 426 | 428 | if (repos.length === 0) return []; |
| 429 | // A two-value literal from the type, never caller text. | |
| 430 | const kindClause = only === undefined ? "" : `AND kind = '${only === "pull" ? "pull" : "issue"}'`; | |
| 427 | 431 | const byId = new Map(repos.map((r) => [r.id, r])); |
| 428 | 432 | // One arm a repository, so the compound stays far inside SQLite's 500. |
| 429 | 433 | const ids = [...byId.keys()].slice(0, MAX_SEARCH_REPOS); |
| @@ -448,6 +452,7 @@ export function searchLocalIssues( | ||
| 448 | 452 | WHERE repo_id = ?${i + 1} |
| 449 | 453 | AND title LIKE ?${ids.length + 1} ESCAPE '\\' COLLATE NOCASE |
| 450 | 454 | ${sealedClause} |
| 455 | ${kindClause} | |
| 451 | 456 | ORDER BY updated_at DESC |
| 452 | 457 | LIMIT ?${ids.length + 2})`, |
| 453 | 458 | ) |
src/http/mcp/reads.ts +1 −1
| @@ -55,7 +55,7 @@ export async function searchRun(ctx: Ctx, user: User | undefined, given: Args): | ||
| 55 | 55 | return bad("invalid", "`q` names one repository with repo: and `repo` another: give one"); |
| 56 | 56 | const args: Args = qualified.repo === undefined ? given : { ...given, repo: qualified.repo }; |
| 57 | 57 | const kind = args["kind"]; |
| 58 | if (kind !== undefined && typeof kind !== "string") return bad("invalid_kind", "kind is all, repos, issues or code"); | |
| 58 | if (kind !== undefined && typeof kind !== "string") return bad("invalid_kind", "kind is all, repos, issues, pulls or code"); | |
| 59 | 59 | const refusal = searchRefusal(kind, args["limit"] === undefined || typeof args["limit"] === "number" ? (args["limit"] as number | undefined) : NaN); |
| 60 | 60 | if (refusal) return bad(refusal.code, refusal.message); |
| 61 | 61 | const all = args["all"]; |
src/tui/forge.ts +5 −1
| @@ -816,10 +816,14 @@ export function forgeSearch(session: Session): (ctx: Ctx) => PaletteSearch { | ||
| 816 | 816 | const held = greps |
| 817 | 817 | ? guestCodeSearch(session.app, session.identity.remoteAddress) |
| 818 | 818 | : undefined; |
| 819 | // `pulls: retry` narrows to pull requests, as `kind=pulls` does on the page. | |
| 820 | const pullsOnly = /^pulls:\s*/i.test(query); | |
| 821 | const q = pullsOnly ? query.replace(/^pulls:\s*/i, "") : query; | |
| 819 | 822 | let found; |
| 820 | 823 | try { |
| 821 | 824 | found = await search(session.app, session.user, { |
| 822 | q: query, | |
| 825 | q, | |
| 826 | ...(pullsOnly ? { kind: "pulls" as const } : {}), | |
| 823 | 827 | limit: 8, |
| 824 | 828 | live, |
| 825 | 829 | withCode: held === undefined || held.allowed, |
src/web/pages/search.ts +7 −2
| @@ -291,6 +291,9 @@ const WORDS: readonly Words[] = [ | ||
| 291 | 291 | ["code", "Code", "Code", "No line of code matches"], |
| 292 | 292 | ]; |
| 293 | 293 | |
| 294 | /** A chip only: the page draws pulls in the issues section. */ | |
| 295 | const PULLS_CHIP: Words = ["pulls", "Pull requests", "", ""]; | |
| 296 | ||
| 294 | 297 | function searchHref( |
| 295 | 298 | a: Asked, |
| 296 | 299 | over: { kind?: SearchKind; live?: boolean; codeAll?: boolean } = {}, |
| @@ -479,7 +482,7 @@ export async function searchPage(ctx: Ctx): Promise<Response> { | ||
| 479 | 482 | const rendering = performance.now(); |
| 480 | 483 | |
| 481 | 484 | const chips = seg( |
| 482 | WORDS.map(([kind, label]) => ({ | |
| 485 | [...WORDS.slice(0, 3), PULLS_CHIP, ...WORDS.slice(3)].map(([kind, label]) => ({ | |
| 483 | 486 | label, |
| 484 | 487 | href: searchHref(a, { kind }), |
| 485 | 488 | current: kind === a.kind, |
| @@ -518,6 +521,8 @@ export async function searchPage(ctx: Ctx): Promise<Response> { | ||
| 518 | 521 | found.issues.map((hit) => issueHitRow(apps, hit)), |
| 519 | 522 | found.truncated.issues, |
| 520 | 523 | ], |
| 524 | // Drawn in the issues section, which is what `pulls` shows. | |
| 525 | pulls: () => [[], false], | |
| 521 | 526 | code: () => [ |
| 522 | 527 | found.code.map((hit) => codeHitRow(hit, a.query)), |
| 523 | 528 | found.truncated.code, |
| @@ -539,7 +544,7 @@ export async function searchPage(ctx: Ctx): Promise<Response> { | ||
| 539 | 544 | const guides = found.docs.length === 0 ? null : docsSection(found.docs); |
| 540 | 545 | const guidesFirst = guideTitleMatches(a.query, found.docs); |
| 541 | 546 | const sections = WORDS |
| 542 | .filter(([kind]) => kind !== "all" && (a.kind === "all" || a.kind === kind)) | |
| 547 | .filter(([kind]) => kind !== "all" && (a.kind === "all" || a.kind === kind || (a.kind === "pulls" && kind === "issues"))) | |
| 543 | 548 | .map((w) => ({ kind: w[0], html: section(a, w, ...rows[w[0]](), w[0] === "code" ? moreCode : null) })); |
| 544 | 549 | const ordered = [ |
| 545 | 550 | ...(guidesFirst ? [guides] : []), |
test/cli-search.test.ts +5 −39
| @@ -116,47 +116,13 @@ test("the words become q; --kind and --limit pass through, and the forge's defau | ||
| 116 | 116 | expect(narrowed.searchParams.get("kind")).toBe("code"); |
| 117 | 117 | expect(narrowed.searchParams.get("limit")).toBe("5"); |
| 118 | 118 | |
| 119 | // The API answers pulls inside `issues`; the CLI asks for that, at the | |
| 120 | // API's ceiling, and cuts to --limit itself after keeping the one kind. | |
| 119 | // The forge's own `pulls` kind counts the limit in pulls: nothing is kept on the client. | |
| 121 | 120 | await forge(["search", "retry", "--kind", "pulls", "--limit", "3"]); |
| 121 | expect(seen.at(-1)!.searchParams.get("kind")).toBe("pulls"); | |
| 122 | expect(seen.at(-1)!.searchParams.get("limit")).toBe("3"); | |
| 123 | await forge(["search", "retry", "--kind", "issues"]); | |
| 122 | 124 | expect(seen.at(-1)!.searchParams.get("kind")).toBe("issues"); |
| 123 | expect(seen.at(-1)!.searchParams.get("limit")).toBe("100"); | |
| 124 | }); | |
| 125 | ||
| 126 | /** Hits as the forge orders them: issues first, so a window of 1 holds no pull. */ | |
| 127 | const MIXED = { | |
| 128 | ...EMPTY, | |
| 129 | issues: [1, 2, 3, 4].map((n) => ({ | |
| 130 | source: "local", repo: { owner: "alice", name: "shop" }, number: n, | |
| 131 | kind: n <= 2 ? "issue" : "pull", title: `Retry ${n}`, state: "open", | |
| 132 | updatedAt: "2026-10-01T00:00:00Z", | |
| 133 | })), | |
| 134 | }; | |
| 135 | ||
| 136 | /** A fake that honours `limit` as the forge does: the first N hits. */ | |
| 137 | function windowed(answer: typeof MIXED): () => Response { | |
| 138 | return () => { | |
| 139 | const limit = Number(seen.at(-1)!.searchParams.get("limit") ?? "20"); | |
| 140 | return Response.json({ ...answer, issues: answer.issues.slice(0, limit) }); | |
| 141 | }; | |
| 142 | } | |
| 143 | ||
| 144 | test("--kind pulls --limit 1 prints a pull even when the forge ranks issues first", async () => { | |
| 145 | reply = windowed(MIXED); | |
| 146 | const pulls = await forge(["search", "retry", "--kind", "pulls", "--limit", "1"]); | |
| 147 | expect(pulls.code).toBe(EXIT.ok); | |
| 148 | expect(pulls.out).toBe("pulls (1, more not shown)\nalice/shop#3 Retry 3 open\n"); | |
| 149 | ||
| 150 | const issues = await forge(["search", "retry", "--kind", "issues", "--limit", "2"]); | |
| 151 | expect(issues.out).toBe("issues (2)\nalice/shop#1 Retry 1 open\nalice/shop#2 Retry 2 open\n"); | |
| 152 | ||
| 153 | // --json is the same narrowed answer, and says the list was cut. | |
| 154 | const json = await forge(["search", "retry", "--kind", "pulls", "--limit", "1", "--json"]); | |
| 155 | const body = JSON.parse(json.out); | |
| 156 | expect(body.issues.map((i: { number: number }) => i.number)).toEqual([3]); | |
| 157 | expect(body.truncated).toEqual({ repos: false, issues: true, code: false }); | |
| 158 | const whole = await forge(["search", "retry", "--kind", "pulls", "--json"]); | |
| 159 | expect(JSON.parse(whole.out).truncated.issues).toBe(false); | |
| 125 | expect(seen.at(-1)!.searchParams.has("limit")).toBe(false); | |
| 160 | 126 | }); |
| 161 | 127 | |
| 162 | 128 | test("prints code as owner/name:path:line and conversations as owner/name#N, each group headed", async () => { |
test/mcp-search.test.ts +1 −1
| @@ -87,7 +87,7 @@ describe("MCP search", () => { | ||
| 87 | 87 | const r = await tool(aliceRo, { q: " " }); |
| 88 | 88 | expect(r.value.repos).toEqual([]); |
| 89 | 89 | expect(r.value.note).toContain("q is empty"); |
| 90 | expect(r.value.note).toContain("kind=all|repos|issues|code"); | |
| 90 | expect(r.value.note).toContain("kind=all|repos|issues|pulls|code"); | |
| 91 | 91 | expect((await tool(aliceRo, { q: "glow", kind: "issues" })).value.note).toBeUndefined(); |
| 92 | 92 | }); |
| 93 | 93 |
test/search-docs.test.ts +8
| @@ -105,3 +105,11 @@ test("the terminal's palette search has a Guides section; Enter opens the guide" | ||
| 105 | 105 | expect(pushed.length).toBe(1); |
| 106 | 106 | expect(pushed[0]!.title).not.toBe(""); |
| 107 | 107 | }); |
| 108 | ||
| 109 | test("the terminal's palette search narrows to pull requests with a pulls: prefix", async () => { | |
| 110 | const guest = new Session(app, { sshUsername: "anyone", remoteAddress: "198.51.100.7", fingerprint: "SHA256:none" }); | |
| 111 | const ctx = { icons: "plain", toast: () => {}, push: () => {}, invalidate: () => {} } as unknown as Ctx; | |
| 112 | const items = await forgeSearch(guest)(ctx)("pulls: ulid", false, new AbortController().signal); | |
| 113 | expect(items.some((i) => i.section === "Repos" || i.section === "Code")).toBe(false); | |
| 114 | expect(items.every((i) => i.section !== "Issues & pulls" || i.hint?.startsWith("pull"))).toBe(true); | |
| 115 | }); |
test/search-note.test.ts +2 −2
| @@ -31,7 +31,7 @@ test("a missing or blank q answers the empty shape plus a note with an example a | ||
| 31 | 31 | expect(r.repos).toEqual([]); |
| 32 | 32 | expect(r.note).toContain("q is empty"); |
| 33 | 33 | expect(r.note).toContain("q=parser"); |
| 34 | expect(r.note).toContain("kind=all|repos|issues|code"); | |
| 34 | expect(r.note).toContain("kind=all|repos|issues|pulls|code"); | |
| 35 | 35 | } |
| 36 | 36 | }); |
| 37 | 37 | |
| @@ -43,7 +43,7 @@ test("an unknown or empty kind is a 422 invalid_kind listing the kinds", async ( | ||
| 43 | 43 | expect(res.status).toBe(422); |
| 44 | 44 | const body = (await res.json()) as any; |
| 45 | 45 | expect(body.error).toBe("invalid_kind"); |
| 46 | expect(body.message).toContain("all, repos, issues or code"); | |
| 46 | expect(body.message).toContain("all, repos, issues, pulls or code"); | |
| 47 | 47 | } |
| 48 | 48 | }); |
| 49 | 49 |
test/search-page.test.ts +9
| @@ -181,3 +181,12 @@ test("a narrowed empty search offers a widen link that differs from the page", a | ||
| 181 | 181 | expect(html).toContain("data-tell"); |
| 182 | 182 | } |
| 183 | 183 | }); |
| 184 | ||
| 185 | test("a Pull requests chip links to kind=pulls and is current there", async () => { | |
| 186 | const all = await (await get("/search?q=flux")).text(); | |
| 187 | expect(all).toContain("kind=pulls"); | |
| 188 | expect(all).toContain("Pull requests"); | |
| 189 | const pulls = await (await get("/search?q=flux&kind=pulls")).text(); | |
| 190 | const chip = /<a\b[^>]*href="[^"]*kind=pulls"[^>]*>/.exec(pulls)?.[0] ?? ""; | |
| 191 | expect(chip).toMatch(/aria-current/); | |
| 192 | }); |
test/search.test.ts +21 −1
| @@ -57,9 +57,10 @@ interface Results { | ||
| 57 | 57 | source: "local"; |
| 58 | 58 | repo: { owner: string; name: string }; |
| 59 | 59 | number: number; |
| 60 | kind?: "issue" | "pull"; | |
| 60 | 61 | title: string; |
| 61 | 62 | } |
| 62 | | { source: "origin"; fullName: string; number: number; title: string } | |
| 63 | | { source: "origin"; fullName: string; number: number; kind?: "issue" | "pull"; title: string } | |
| 63 | 64 | )[]; |
| 64 | 65 | code: { |
| 65 | 66 | repo: { owner: string; name: string }; |
| @@ -301,6 +302,25 @@ describe("search: one query, four sources", () => { | ||
| 301 | 302 | expect(results.issues.every((i) => i.source === "local")).toBe(true); |
| 302 | 303 | }); |
| 303 | 304 | |
| 305 | test("kind=pulls and kind=issues each answer only theirs, and the limit counts that kind", async () => { | |
| 306 | const repo = getRepo(app.db, "alice", "widget-engine")!; | |
| 307 | const add = app.db.query( | |
| 308 | `INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state) | |
| 309 | VALUES (?1, ?2, ?3, ?4, ?5, '', ?6, 'open')`, | |
| 310 | ); | |
| 311 | for (let n = 0; n < 155; n++) { | |
| 312 | const pull = n >= 150; | |
| 313 | add.run(`kp-${n}`, repo.id, 9000 + n, pull ? "pull" : "issue", `kindsplit ${pull ? "pull" : "issue"} ${n}`, aliceUser.id); | |
| 314 | } | |
| 315 | const pulls = await find("q=kindsplit&kind=pulls&limit=5"); | |
| 316 | expect(pulls.issues).toHaveLength(5); | |
| 317 | expect(pulls.issues.every((i) => i.kind === "pull")).toBe(true); | |
| 318 | const issues = await find("q=kindsplit&kind=issues&limit=100"); | |
| 319 | expect(issues.issues).toHaveLength(100); | |
| 320 | expect(issues.issues.every((i) => i.kind === "issue")).toBe(true); | |
| 321 | expect((await find("q=kindsplit&kind=all&limit=100")).issues.some((i) => i.kind === "pull")).toBe(true); | |
| 322 | }); | |
| 323 | ||
| 304 | 324 | test("code search finds a line, and names where it is", async () => { |
| 305 | 325 | const results = await find("q=capacitor&kind=code"); |
| 306 | 326 | expect(results.code.length).toBeGreaterThan(0); |
new above
offline
Medium: the page answers kind=pulls only by hand-typed URL. Add a Pulls kind chip (an <a>, as the others are) that links to kind=pulls and shows as current, so the web door matches the API and CLI.