Public: anyone can read this; the crew can change it.
/explore filters live in the URL: minimum forks, updated within, kind, with the same words in the explorer MCP tool #14133
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14046-explore-filters-live-in-the-url-minimum → main 6 commits fork 3 threads · 3 unresolved
11 files
changed +133
−22
docs/MCP.md +1 −1
| @@ -110,7 +110,7 @@ bytes in `tools/list`. After changing a tool run `bun scripts/mcp-table.ts`; | ||
| 110 | 110 | | `email_verify` | — | Send yourself a new verification link | 126 | |
| 111 | 111 | | `estimate` | — | Ask an issue's base rate, or record `event` with `p50`, `p90` (instants) and `basis` | 406 | |
| 112 | 112 | | `events` | — | Repository events | 259 | |
| 113 | | `explore` | — | The apps, people (and, for an admin, forges) you can see, ranked | 774 | | |
| 113 | | `explore` | — | The apps, people (and, for an admin, forges) you can see, ranked | 804 | | |
| 114 | 114 | | `family` | — | The forge that sent this one and, for a site admin, those it sent, with state, version | 205 | |
| 115 | 115 | | `features` | — | Apps absorbed as forge features: list, read, absorb or un-absorb, change typed settings | 357 | |
| 116 | 116 | | `feed` | — | Your ranked home timeline; `cursor` pages; saved filter applies | 604 | |
docs/features/explore.md +3
| @@ -47,6 +47,7 @@ What a person filters on `/explore` an agent filters with the same words. Each f | ||
| 47 | 47 | | Show archived | `archived=yes` | `?archived=yes` | `{ archived: "yes" }` | |
| 48 | 48 | | (owner link on a row) | `owner=name` | `?owner=name` | `{ owner: "name" }` | |
| 49 | 49 | | (type it) at least N forks by people | `forks=3` (0–1000) | `?forks=3` | `{ forks: "3" }` | |
| 50 | | (type it) the same floor, as shared links say it | `min_forks=3` (`forks=` wins when both are given); not a whole number from 0 to 1000 is `400` naming `min_forks`, on the page and the API | `?min_forks=3` | `{ min_forks: "3" }` | | |
| 50 | 51 | | (type it) at least N merges in 30 days | `ships=1` (0–1000) | `?ships=1` | `{ ships: "1" }` | |
| 51 | 52 | | (type it) awake in the last 30 days | `live=yes` (`no` is no filter) | `?live=yes` | `{ live: "yes" }` | |
| 52 | 53 | | Mine (signed in, beside the kind tabs) | `mine=yes` (`no` is no filter) | `?mine=yes` | `{ mine: "yes" }` | |
| @@ -54,6 +55,8 @@ What a person filters on `/explore` an agent filters with the same words. Each f | ||
| 54 | 55 | |
| 55 | 56 | The one line still works everywhere: `?q=kind:app sort:forks garden` and `{ q: "kind:app sort:forks garden" }` read the same as the separate parameters, and old `/explore?q=…` links keep working. When a parameter and the same key in `q` are both given, the parameter wins (`?q=sort:name&sort=forks` sorts by forks). A parameter's value is one word; one the explorer does not take is an unknown word like any typed in `q`, and is refused the same way (below). The terminal's search line takes only the line. It takes `forks:N`, `ships:N` and `live:yes` there too (`screens/dashboard.ts` reads the line with `readExploreLine`): `forks:1 live:no` leaves the rows the page leaves, and `forks:abc` or `live:maybe` is named under `Read as:` as `forks:abc is not a count`, `live:maybe is not an answer`. |
| 56 | 57 | |
| 58 | A bad `min_forks`, `since`, `updated` or `kind` parameter (`?since=9y`, `?kind=nope`) is `400` naming the parameter, on the page and the API alike (#14046): the API answers `{ "error": "invalid", "field": "since", "message": "since is not a window — use 1d, 7d, 30d" }`, and the page still draws the same sentence over the unfiltered list. The sentence names the parameter and never repeats the value. `since` is judged only when `updated` is not given, `min_forks` only when `forks` is not. | |
| 59 | ||
| 57 | 60 | The three return the same ordered rows (`test/explore-parity.test.ts`; the URL form in `test/explore-url.test.ts`). |
| 58 | 61 | |
| 59 | 62 | A `forks:` or `ships:` value that is not a whole number from 0 to 1000 (`abc`, `-1`, `1.5`, `1001`) and a `live:` that is not yes or no are unknown words like any other: `400` naming the word. Spawned forges carry no numbers, so any of the three leaves them out. The page's filter chips, `Drop` links and `Clear filters` carry the three words. |
src/actions/explore.ts +26 −2
| @@ -124,6 +124,30 @@ export function parseExploreQuery(line: string): ExploreQuery { | ||
| 124 | 124 | */ |
| 125 | 125 | export const EXPLORE_PARAMS = ["kind", "sort", "updated", "owner", "archived", "forks", "ships", "live", "mine"] as const; |
| 126 | 126 | |
| 127 | /** A filter parameter refused at the boundary: the parameter and the sentence naming it. */ | |
| 128 | export interface ExploreRefusal { | |
| 129 | readonly field: "min_forks" | "since" | "updated" | "kind"; | |
| 130 | readonly message: string; | |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * The first bad `min_forks`, `updated`, `since` or `kind` parameter, else null. A parameter the | |
| 135 | * line would not read (`min_forks` beside `forks`, `since` beside `updated`) is not judged. The | |
| 136 | * sentence names the parameter, never echoes the value. | |
| 137 | */ | |
| 138 | export function badExploreParam(get: (name: string) => string | null | undefined): ExploreRefusal | null { | |
| 139 | const given = (name: string) => (get(name) ?? "").trim(); | |
| 140 | const minForks = given("min_forks"); | |
| 141 | if (minForks !== "" && given("forks") === "" && countOf(minForks) === undefined) | |
| 142 | return { field: "min_forks", message: `min_forks is not a count — use a whole number from 0 to ${COUNT_MAX}` }; | |
| 143 | const window = given("updated") !== "" ? "updated" : "since"; | |
| 144 | if (given(window) !== "" && !Object.hasOwn(WINDOWS, given(window).toLowerCase())) | |
| 145 | return { field: window, message: `${window} is not a window — use ${Object.keys(WINDOWS).join(", ")}` }; | |
| 146 | if (given("kind") !== "" && !Object.hasOwn(KINDS, given("kind").toLowerCase())) | |
| 147 | return { field: "kind", message: `kind is not a kind — use ${KIND_WORDS.join(", ")}` }; | |
| 148 | return null; | |
| 149 | } | |
| 150 | ||
| 127 | 151 | /** |
| 128 | 152 | * The one line a request asks for: `q`, then each separate parameter as its |
| 129 | 153 | * `key:value` word. A value is one word (whitespace removed, so it cannot |
| @@ -133,8 +157,8 @@ export const EXPLORE_PARAMS = ["kind", "sort", "updated", "owner", "archived", " | ||
| 133 | 157 | export function exploreLineFrom(get: (name: string) => string | null | undefined): string { |
| 134 | 158 | const given = new Map<string, string>(); |
| 135 | 159 | for (const key of EXPLORE_PARAMS) { |
| 136 | // `since` is the same window as `updated`, in the words the chips are shared in. | |
| 137 | const raw = get(key) || (key === "updated" ? get("since") : "") || ""; | |
| 160 | // `since` is the same window as `updated`, and `min_forks` the same floor as `forks`. | |
| 161 | const raw = get(key) || (key === "updated" ? get("since") : key === "forks" ? get("min_forks") : "") || ""; | |
| 138 | 162 | const value = raw.replace(/\s+/g, "").slice(0, 100); |
| 139 | 163 | if (value !== "") given.set(key, value); |
| 140 | 164 | } |
src/http/api.ts +7 −3
| @@ -363,6 +363,7 @@ import { | ||
| 363 | 363 | exploreSuggestion, |
| 364 | 364 | readExploreLine, |
| 365 | 365 | exploreLineFrom, |
| 366 | badExploreParam, | |
| 366 | 367 | } from "../actions/explore.ts"; |
| 367 | 368 | import { frontInput, frontJson, setFront } from "../actions/front.ts"; |
| 368 | 369 | import { COPIES_PER_DAY, makeItYours } from "../actions/make_it_yours.ts"; |
| @@ -3657,17 +3658,20 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 3657 | 3658 | // Explore (#607): the rows /explore shows, for the same one line. |
| 3658 | 3659 | router.add("GET", "/api/v1/explore", async (ctx) => { |
| 3659 | 3660 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 3660 | // The separate `sort`, `kind` and `limit` parameters are refused with 422 | |
| 3661 | // naming the field; a word typed in `q` keeps its 400 `unknown_filter`. | |
| 3661 | // The separate `sort` and `limit` parameters are refused with 422 naming the | |
| 3662 | // field; a bad `min_forks`, `since`, `updated` or `kind` with 400 naming it, as | |
| 3663 | // the page does; a word typed in `q` keeps its 400 `unknown_filter`. | |
| 3662 | 3664 | const limitRaw = ctx.url.searchParams.get("limit"); |
| 3663 | 3665 | if (limitRaw !== null && !(/^\d{1,3}$/.test(limitRaw) && Number(limitRaw) >= 1 && Number(limitRaw) <= 100)) |
| 3664 | 3666 | return json({ error: "invalid", field: "limit", message: "limit is an integer from 1 to 100" }, 422); |
| 3665 | 3667 | const limit = limitRaw === null ? 30 : Number(limitRaw); |
| 3666 | 3668 | if (queryTooLong(ctx.url.searchParams.get("q"))) |
| 3667 | 3669 | return json({ error: "invalid", field: "q", message: QUERY_TOO_LONG }, 422); |
| 3670 | const refused = badExploreParam((name) => ctx.url.searchParams.get(name)); | |
| 3671 | if (refused !== null) return json({ error: "invalid", field: refused.field, message: refused.message }, 400); | |
| 3668 | 3672 | const line = exploreLineFrom((name) => ctx.url.searchParams.get(name)); |
| 3669 | 3673 | const { query, unknown } = readExploreLine(line); |
| 3670 | for (const field of ["sort", "kind"] as const) { | |
| 3674 | for (const field of ["sort"] as const) { | |
| 3671 | 3675 | const given = ctx.url.searchParams.get(field); |
| 3672 | 3676 | if (given !== null && given.trim() !== "" && unknown.some((w) => w.toLowerCase().startsWith(`${field}:`))) |
| 3673 | 3677 | return json({ error: "invalid", field, message: exploreNote(unknown) }, 422); |
src/http/mcp/tools/explore.ts +2 −1
| @@ -4,7 +4,7 @@ import { exploreRun } from "../reads.ts"; | ||
| 4 | 4 | |
| 5 | 5 | export const tool: Tool = { |
| 6 | 6 | name: "explore", |
| 7 | doc: "`{ kind: tree, app }`: `{ app, upstream, forks, truncated }`, rows `{ repo, follows, standing, updatedAt }` for the app, the chain above it (nearest first) and its direct forks, in the words of the forks page, only what you may read, drawn on the `ui://forge/explore` card as upstream, this and fork rows; else `{ q?, cursor? }` (`query` is the same, `q` wins): the apps and people you can see, ranked, with `total` and `line` (how many the filter leaves, in the page's words) and, when filtered, `clear` (the call that drops it), with their numbers and `why` (a short line on the ranking, absent when none); `kind:` `sort:` `updated:` `owner:` `archived:` `forks:N` `ships:N` `live:yes` `mine:yes` (your own apps) and words in one line; each also as its own argument (`since` = `updated`); page on with `cursor`", | |
| 7 | doc: "`{ kind: tree, app }`: `{ app, upstream, forks, truncated }`, rows `{ repo, follows, standing, updatedAt }` for the app, the chain above it (nearest first) and its direct forks, in the words of the forks page, only what you may read, drawn on the `ui://forge/explore` card as upstream, this and fork rows; else `{ q?, cursor? }` (`query` is the same, `q` wins): the apps and people you can see, ranked, with `total` and `line` (how many the filter leaves, in the page's words) and, when filtered, `clear` (the call that drops it), with their numbers and `why` (a short line on the ranking, absent when none); `kind:` `sort:` `updated:` `owner:` `archived:` `forks:N` `ships:N` `live:yes` `mine:yes` (your own apps) and words in one line; each also as its own argument (`since` = `updated`, `min_forks` = `forks`); page on with `cursor`", | |
| 8 | 8 | description: |
| 9 | 9 | "The apps, people (and, for an admin, forges) you can see, ranked.", |
| 10 | 10 | inputSchema: { |
| @@ -22,6 +22,7 @@ export const tool: Tool = { | ||
| 22 | 22 | }, |
| 23 | 23 | ...Object.fromEntries(EXPLORE_PARAMS.map((k) => [k, { type: "string", maxLength: 100 }])), |
| 24 | 24 | since: { type: "string", maxLength: 100 }, |
| 25 | min_forks: { type: "string", maxLength: 100 }, | |
| 25 | 26 | app: { type: "string", maxLength: 200, description: "With kind: tree" }, |
| 26 | 27 | cursor: { |
| 27 | 28 | type: "string", |
src/web/studio/explore.ts +10 −4
| @@ -14,6 +14,7 @@ import { | ||
| 14 | 14 | exploreCount, |
| 15 | 15 | exploreFiltered, |
| 16 | 16 | exploreLineFrom, |
| 17 | badExploreParam, | |
| 17 | 18 | exploreParams, |
| 18 | 19 | exploreNote, |
| 19 | 20 | exploreSuggestion, |
| @@ -183,7 +184,10 @@ export async function explorePage(ctx: Ctx): Promise<Response> { | ||
| 183 | 184 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 184 | 185 | const line = exploreLineFrom((name) => ctx.url.searchParams.get(name)); |
| 185 | 186 | const { query, unknown } = readExploreLine(line); |
| 186 | const note = exploreNote(unknown); | |
| 187 | // A bad `min_forks`, `since`, `updated` or `kind` is refused with 400 naming the parameter; | |
| 188 | // a bad word typed in `q` (or another parameter) keeps its noted 200. | |
| 189 | const refused = badExploreParam((name) => ctx.url.searchParams.get(name)); | |
| 190 | const note = refused?.message ?? exploreNote(unknown); | |
| 187 | 191 | const suggestion = exploreSuggestion(line); |
| 188 | 192 | const ranking = performance.now(); |
| 189 | 193 | const shown = await explorePageAt(ctx.app, ctx.auth.user, query, explorePageFrom((name) => ctx.url.searchParams.get(name))); |
| @@ -304,8 +308,10 @@ export async function explorePage(ctx: Ctx): Promise<Response> { | ||
| 304 | 308 | extra: "bare", |
| 305 | 309 | })}${pager(query, shown.page, shown.pages)}</div>`; |
| 306 | 310 | const drawn = page({ ctx, title: "Explore", description: "Apps, forges and people on this forge, ranked by use, forks, ships and freshness.", body: compact(body), feed: { href: "/explore.atom", title: "Explore" } }); |
| 307 | // An unknown filter is ignored with a plain note on the page (200); the API and the MCP stay | |
| 308 | // strict. | |
| 311 | // A refused parameter still draws the whole page, the unfiltered list under the note naming | |
| 312 | // it, so a person who followed a bad link lands somewhere usable; only the status says 400. | |
| 313 | // The same response is re-made with that status, keeping the drawn headers (security floor, | |
outdated
Only min_forks is refused with 400; a bad since or kind is still a noted 200 here. The issue asks for a 400 naming the parameter for every filter. Extend the refusal to since/updated/kind and update the #11819 test. |
||
| 314 | // CSP nonce) as they are. | |
| 309 | 315 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 310 | return drawn; | |
| 316 | return refused === null ? drawn : new Response(drawn.body, { status: 400, headers: drawn.headers }); | |
| 311 | 317 | } |
test/explore-api-paging.test.ts +5 −1
| @@ -100,7 +100,11 @@ describe("refusals", () => { | ||
| 100 | 100 | test("limit 101", () => refused("limit=101", "limit")); |
| 101 | 101 | test("an empty limit", () => refused("limit=", "limit")); |
| 102 | 102 | test("an unknown sort", () => refused("sort=bogus", "sort")); |
| 103 | test("an unknown kind", () => refused("kind=nope", "kind")); | |
| 103 | test("an unknown kind is a 400 naming kind, as the page (#14046)", async () => { | |
| 104 | const res = await get("kind=nope"); | |
| 105 | expect(res.status).toBe(400); | |
| 106 | expect(((await res.json()) as { field: string }).field).toBe("kind"); | |
| 107 | }); | |
| 104 | 108 | test("a cursor that is not one is still 400", async () => { |
| 105 | 109 | expect((await get("cursor=%25%25")).status).toBe(400); |
| 106 | 110 | }); |
test/explore-since.test.ts +2 −2
| @@ -76,9 +76,9 @@ test("since=7d and since=30d keep exactly the apps changed inside the window", a | ||
| 76 | 76 | expect(rows(await get("?kind=app&owner=pine&since=30d&sort=name"))).toEqual(["/pine/fresh", "/pine/stale"]); |
| 77 | 77 | }); |
| 78 | 78 | |
| 79 | test("an unknown since is ignored with a note, and the list is whole", async () => { | |
| 79 | test("an unknown since is a 400 with a note, and the list is whole (#14046)", async () => { | |
| 80 | 80 | const res = await fetch(`${servers.url}/explore?kind=app&owner=pine&since=9y`); |
| 81 | expect(res.status).toBe(200); | |
| 81 | expect(res.status).toBe(400); | |
| 82 | 82 | const html = await res.text(); |
| 83 | 83 | expect(rows(html).length).toBe(3); |
| 84 | 84 | expect(html).toContain("1d, 7d, 30d"); |
test/explore-url-filters.test.ts +3 −3
| @@ -95,11 +95,11 @@ test("a link with three filters renders the same rows as choosing them by hand", | ||
| 95 | 95 | expect((await get("/explore?kind=app")).html).not.toContain(">Mine<"); |
| 96 | 96 | }); |
| 97 | 97 | |
| 98 | test("an unknown filter value is ignored with a one-line note, never a 500", async () => { | |
| 98 | test("an unknown filter value is ignored with a one-line note, never a 500 (a bad kind or since is a 400, #14046)", async () => { | |
| 99 | 99 | const plain = listed((await get("/explore", olive)).html); |
| 100 | for (const qs of ["?mine=maybe", "?kind=zzz", "?sort=zzz", "?since=9y"]) { | |
| 100 | for (const [qs, status] of [["?mine=maybe", 200], ["?kind=zzz", 400], ["?sort=zzz", 200], ["?since=9y", 400]] as const) { | |
| 101 | 101 | const res = await get(`/explore${qs}`, olive); |
| 102 | expect(res.status).toBe(200); | |
| 102 | expect(res.status).toBe(status); | |
| 103 | 103 | expect(res.html).toContain('role="status"'); |
| 104 | 104 | expect(listed(res.html)).toEqual(plain); |
| 105 | 105 | } |
test/explore-url.test.ts +47 −5
| @@ -78,11 +78,13 @@ test("an unknown parameter is ignored; an invalid value is named and the default | ||
| 78 | 78 | expect(listed(bad.html)).toEqual(listed(plain.html)); |
| 79 | 79 | }); |
| 80 | 80 | |
| 81 | test("an unknown kind, sort or updated is a 200 with a plain note and the unfiltered list, escaped (#11819)", async () => { | |
| 81 | // Was a 200 for every bad value (#11819); #14046 makes a bad kind, updated or since a 400 naming | |
| 82 | // the parameter. The page under it is the same: the note and the unfiltered list, escaped. | |
| 83 | test("an unknown sort is a 200, an unknown kind or updated a 400, each with a plain note and the unfiltered list, escaped (#11819, #14046)", async () => { | |
| 82 | 84 | const plain = listed((await page("")).html); |
| 83 | for (const qs of ["?kind=bogus", "?sort=bogus", "?updated=9y", "?since=9y", `?kind=${encodeURIComponent("<script>x</script>")}`]) { | |
| 85 | for (const [qs, status] of [["?kind=bogus", 400], ["?sort=bogus", 200], ["?updated=9y", 400], ["?since=9y", 400], [`?kind=${encodeURIComponent("<script>x</script>")}`, 400]] as const) { | |
| 84 | 86 | const res = await page(qs); |
| 85 | expect(res.status).toBe(200); | |
| 87 | expect(res.status).toBe(status); | |
| 86 | 88 | expect(res.html).toContain('role="status"'); |
| 87 | 89 | expect(res.html).toMatch(/is not a (kind|sort|window)/); |
| 88 | 90 | expect(res.html).not.toContain("<script>x</script>"); |
| @@ -104,13 +106,13 @@ test("the chips link with separate parameters", async () => { | ||
| 104 | 106 | expect(exploreParams(readExploreLine("kind:app sort:forks owner:olive garden").query)).toBe("kind=app&sort=forks&owner=olive&q=garden"); |
| 105 | 107 | }); |
| 106 | 108 | |
| 107 | test("`since` is the `updated` window: same line, bad value is a noted 200 (#11232)", async () => { | |
| 109 | test("`since` is the `updated` window: same line, bad value is a noted 400 (#11232, #14046)", async () => { | |
| 108 | 110 | expect(exploreLineFrom((n) => (n === "since" ? "7d" : null))).toBe("updated:7d"); |
| 109 | 111 | expect(exploreLineFrom((n) => (n === "since" ? "9y" : null))).toBe("updated:9y"); |
| 110 | 112 | const ok = await fetch(`${servers.url}/explore?kind=app&since=7d`); |
| 111 | 113 | expect(ok.status).toBe(200); |
| 112 | 114 | const bad = await fetch(`${servers.url}/explore?since=9y`); |
| 113 | expect(bad.status).toBe(200); | |
| 115 | expect(bad.status).toBe(400); | |
| 114 | 116 | expect(await bad.text()).toContain("1d, 7d, 30d"); |
| 115 | 117 | }); |
| 116 | 118 | |
| @@ -159,3 +161,43 @@ test("active filters show as a chip row whose removes are links, escaped (#11819 | ||
| 159 | 161 | const hostile = await page(`?q=${encodeURIComponent('"><img src=x onerror=1>')}`); |
| 160 | 162 | expect(hostile.html).not.toContain("<img src=x"); |
| 161 | 163 | }); |
| 164 | ||
| 165 | test("since, updated and kind: a bad one is a 400 naming the parameter, on the page and the API (#14046)", async () => { | |
| 166 | const plain = listed((await page("")).html); | |
| 167 | for (const [qs, field, words] of [ | |
| 168 | ["since=9y", "since", "since is not a window"], | |
| 169 | ["updated=forever", "updated", "updated is not a window"], | |
| 170 | ["kind=nope", "kind", "kind is not a kind"], | |
| 171 | ["kind=app&since=1y", "since", "since is not a window"], | |
| 172 | ] as const) { | |
| 173 | const res = await page(`?${qs}`); | |
| 174 | expect(res.status).toBe(400); | |
| 175 | expect(res.html).toContain(words); | |
| 176 | // The bad parameter never narrows; a good one beside it still does. | |
| 177 | expect(listed(res.html)).toEqual(qs.startsWith("kind=app&") ? listed((await page("?kind=app")).html) : plain); | |
| 178 | const api = await fetch(`${servers.url}/api/v1/explore?${qs}`); | |
| 179 | expect(api.status).toBe(400); | |
| 180 | expect((await api.json()) as unknown).toMatchObject({ error: "invalid", field }); | |
| 181 | } | |
| 182 | // A good value, any case, still narrows; `updated` wins over `since`, which is then not judged. | |
| 183 | for (const qs of ["since=7d", "kind=APP", "updated=30d&since=nope"]) { | |
| 184 | expect((await page(`?${qs}`)).status).toBe(200); | |
| 185 | expect((await fetch(`${servers.url}/api/v1/explore?${qs}`)).status).toBe(200); | |
| 186 | } | |
| 187 | }); | |
| 188 | ||
| 189 | test("min_forks narrows the page and the API; a bad one is a 400 naming min_forks (#14046)", async () => { | |
| 190 | const plain = listed((await page("")).html); | |
| 191 | const ok = await page("?min_forks=1&kind=app"); | |
| 192 | expect(ok.status).toBe(200); | |
| 193 | expect(listed(ok.html).length).toBeLessThan(plain.length); | |
| 194 | for (const bad of ["abc", "-1", "1001"]) { | |
| 195 | const res = await page(`?min_forks=${bad}`); | |
| 196 | expect(res.status).toBe(400); | |
| 197 | expect(res.html).toContain("min_forks is not a count"); | |
| 198 | const api = await fetch(`${servers.url}/api/v1/explore?min_forks=${bad}`); | |
| 199 | expect(api.status).toBe(400); | |
| 200 | expect(((await api.json()) as { field: string }).field).toBe("min_forks"); | |
| 201 | } | |
| 202 | expect((await fetch(`${servers.url}/api/v1/explore?min_forks=0`)).status).toBe(200); | |
| 203 | }); |
test/explorer-filters.test.ts added +27
| @@ -0,0 +1,27 @@ | ||
| 1 | /** `min_forks` is the floor `forks:` names, in the words the issue shares links in (#14046). */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import { exploreLineFrom, readExploreLine } from "../src/actions/explore.ts"; | |
| 4 | ||
| 5 | const line = (p: Record<string, string>) => exploreLineFrom((n) => p[n]); | |
| 6 | ||
| 7 | test("min_forks, since and kind each narrow the one line", () => { | |
| 8 | expect(line({ min_forks: "3" })).toBe("forks:3"); | |
| 9 | expect(line({ since: "7d" })).toBe("updated:7d"); | |
| 10 | expect(line({ kind: "app" })).toBe("kind:app"); | |
| 11 | const q = readExploreLine(line({ min_forks: "3", since: "7d", kind: "app" })).query; | |
| 12 | expect([q.forks, q.updated, q.kind]).toEqual([3, "7d", "app"]); | |
| 13 | }); | |
| 14 | ||
| 15 | test("a bad value is named, left out, and never narrows", () => { | |
This checks only the parser. Add an HTTP-level test for the bad value that expects the 400 and the parameter name, and one for the good value. |
||
| 16 | for (const [k, v] of [["min_forks", "abc"], ["min_forks", "-1"], ["since", "9y"], ["kind", "nope"]] as const) { | |
| 17 | const read = readExploreLine(line({ [k]: v })); | |
| 18 | expect(read.unknown.length).toBe(1); | |
| 19 | expect(read.query.forks).toBeUndefined(); | |
| 20 | expect(read.query.updated).toBe("all"); | |
| 21 | expect(read.query.kind).toBe("all"); | |
| 22 | } | |
| 23 | }); | |
| 24 | ||
| 25 | test("forks wins over min_forks", () => { | |
| 26 | expect(line({ forks: "2", min_forks: "5" })).toBe("forks:2"); | |
| 27 | }); |
new above
offline
A bad min_forks (or since/kind) is folded into the line and reported only as a note on a 200. The boundary should answer 400 naming the parameter (min_forks), not forks.