Public: anyone can read this; the crew can change it.
The explorer's filter state lives in the URL, so a filtered view can be sent and reloaded #13178
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/13161-the-explorer-s-filter-state-lives-in-the → main 9 commits fork 2 threads · 2 unresolved
7 files
changed +199
−19
docs/MCP.md +1 −1
| @@ -109,7 +109,7 @@ bytes in `tools/list`. After changing a tool run `bun scripts/mcp-table.ts`; | ||
| 109 | 109 | | `email_verify` | — | Send yourself a new verification link | 126 | |
| 110 | 110 | | `estimate` | — | Ask an issue's base rate, or record `event` with `p50`, `p90` (instants) and `basis` | 406 | |
| 111 | 111 | | `events` | — | Repository events | 259 | |
| 112 | | `explore` | — | The apps, people (and, for an admin, forges) you can see, ranked | 749 | | |
| 112 | | `explore` | — | The apps, people (and, for an admin, forges) you can see, ranked | 774 | | |
| 113 | 113 | | `family` | — | The forge that sent this one and, for a site admin, those it sent, with state, version | 205 | |
| 114 | 114 | | `features` | — | Apps absorbed as forge features: list, read, absorb or un-absorb, change typed settings | 357 | |
| 115 | 115 | | `feed` | — | Your ranked home timeline; `cursor` pages; saved filter applies | 604 | |
docs/features/explore.md +6 −1
| @@ -44,6 +44,7 @@ What a person filters on `/explore` an agent filters with the same words. Each f | ||
| 44 | 44 | | (type it) at least N forks by people | `forks=3` (0–1000) | `?forks=3` | `{ forks: "3" }` | |
| 45 | 45 | | (type it) at least N merges in 30 days | `ships=1` (0–1000) | `?ships=1` | `{ ships: "1" }` | |
| 46 | 46 | | (type it) awake in the last 30 days | `live=yes` (`no` is no filter) | `?live=yes` | `{ live: "yes" }` | |
| 47 | | Mine (signed in, beside the kind tabs) | `mine=yes` (`no` is no filter) | `?mine=yes` | `{ mine: "yes" }` | | |
| 47 | 48 | | the search box | `q=words` | `?q=words` | `{ q: "words" }` | |
| 48 | 49 | |
| 49 | 50 | 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`. |
| @@ -54,6 +55,10 @@ A `forks:` or `ships:` value that is not a whole number from 0 to 1000 (`abc`, ` | ||
| 54 | 55 | |
| 55 | 56 | An unknown filter word is refused the same way everywhere: `400` from the API (`{ "error": "unknown_filter", "message": "sort:bogus is not a sort — use score, forks, …", "suggest"? }`), an `unknown_filter` error from the MCP tool, and `400` on the page, which still draws the note, the did-you-mean link and the results. This replaces the earlier note-only answer (#7595). |
| 56 | 57 | |
| 58 | ## Mine (#13161) | |
| 59 | ||
| 60 | `mine=yes` (or `mine:yes` in a line) keeps the viewer's own apps and the viewer's own person row: the owner is the viewer's name. Signed out it matches nothing, never everyone. Filters live in the URL, so `/explore?kind=app&mine=yes&sort=fresh` reloads and sends as the same view, and equals choosing Apps, Mine and Fresh by hand, row for row (`test/explore-url-filters.test.ts`). The terminal's search line takes `mine:yes` the same way (`mine:yes` after `/`): a guest sees no rows, the signed-in viewer sees their own (`test/tui-dashboard-explore.test.ts`). A `mine:` value other than yes or no is an unknown word like the others. | |
| 61 | ||
| 57 | 62 | ## Paging (#11376) |
| 58 | 63 | |
| 59 | 64 | A list holds 60 rows a page. When there are more, `/explore` ends with a full-width **More results** button, a plain link to the same view (kind, sort, since, owner, archived and the words) plus `cursor=…`; the last page has none, and it works without JavaScript. A cursor belongs to one sort: one that is malformed, over 400 characters or made under another sort shows the first page with a one-line note, never an error. `GET /api/v1/explore` returns `next_cursor` and takes `?cursor=`, and the MCP `explore` tool takes and returns the same cursor. |
| @@ -77,6 +82,6 @@ Under the filters, `/explore` says how much a filter leaves: `66 results`, `2 ap | ||
| 77 | 82 | In the terminal the same sentence sits in the `Read as:` line under the search box (`Read as: kind:app · 2 apps · Esc clears`); Esc clears the line. |
| 78 | 83 | |
| 79 | 84 | ## What a row shows |
| 80 | A row shows the app's name, what it does in plain words, and the one signal that explains its place (the other numbers are left off the page; the API and the MCP still carry them all). The filter line is the search box and the kind tabs; "Sort and time" opens the sorts, the time windows and "Show archived", and stays open while one of them is set. The ranking order is unchanged. | |
| 85 | A row shows the app's name, what it does in plain words, and the one signal that explains its place (the other numbers are left off the page; the API and the MCP still carry them all). The filter line is the search box, the kind tabs and, signed in, "Mine"; "Sort and time" opens the sorts, the time windows and "Show archived", and stays open while one of them is set. The ranking order is unchanged. | |
| 81 | 86 | |
| 82 | 87 | The terminal's explore screen deliberately keeps the stacked numbers (forks, ships, likes, use) that the page leaves off: a terminal row has the width for them and no second tap to reach them. The ranking is the same on both. |
src/actions/explore.ts +38 −11
| @@ -65,6 +65,8 @@ export interface ExploreQuery { | ||
| 65 | 65 | readonly ships?: number; |
| 66 | 66 | /** `live:yes` — awake within the signal window (30 days). */ |
| 67 | 67 | readonly live?: boolean; |
| 68 | /** `mine:yes` — only the viewer's own apps and the viewer; nothing when signed out. */ | |
| 69 | readonly mine?: boolean; | |
| 68 | 70 | } |
| 69 | 71 | |
| 70 | 72 | /** The most a `forks:` or `ships:` word may ask for. */ |
| @@ -114,8 +116,10 @@ export function parseExploreQuery(line: string): ExploreQuery { | ||
| 114 | 116 | return readExploreLine(line).query; |
| 115 | 117 | } |
| 116 | 118 | |
| 117 | /** The filter names a request may carry as separate parameters (`?kind=app&sort=forks`), beside `q`. */ | |
| 118 | export const EXPLORE_PARAMS = ["kind", "sort", "updated", "owner", "archived", "forks", "ships", "live"] as const; | |
| 119 | /** | |
| 120 | * The filter names a request may carry as separate parameters (`?kind=app&sort=forks`), beside `q`. | |
| 121 | */ | |
| 122 | export const EXPLORE_PARAMS = ["kind", "sort", "updated", "owner", "archived", "forks", "ships", "live", "mine"] as const; | |
| 119 | 123 | |
| 120 | 124 | /** |
| 121 | 125 | * The one line a request asks for: `q`, then each separate parameter as its |
| @@ -150,18 +154,25 @@ export function exploreParams(query: ExploreQuery): string { | ||
| 150 | 154 | if (query.forks !== undefined) p.set("forks", String(query.forks)); |
| 151 | 155 | if (query.ships !== undefined) p.set("ships", String(query.ships)); |
| 152 | 156 | if (query.live === true) p.set("live", "yes"); |
| 157 | if (query.mine === true) p.set("mine", "yes"); | |
| 153 | 158 | if (query.text !== "") p.set("q", query.text); |
| 154 | 159 | return p.toString(); |
| 155 | 160 | } |
| 156 | 161 | |
| 157 | const EXPLORE_KEYS = /(^|\s)(kind|sort|updated|owner|archived|forks|ships|live):/i; | |
| 162 | const EXPLORE_KEYS = /(^|\s)(kind|sort|updated|owner|archived|forks|ships|live|mine):/i; | |
| 158 | 163 | |
| 159 | /** Whether a line has any word the explorer reads as a key, so every surface takes it as the explorer's. */ | |
| 164 | /** | |
| 165 | * Whether a line has any word the explorer reads as a key, so every surface takes it as the | |
| 166 | * explorer's. | |
| 167 | */ | |
| 160 | 168 | export function isExploreLine(line: string): boolean { |
| 161 | 169 | return EXPLORE_KEYS.test(line); |
| 162 | 170 | } |
| 163 | 171 | |
| 164 | /** The query and the `kind:`, `sort:`, `updated:`, `archived:` and `owner:` words it did not take, as typed. */ | |
| 172 | /** | |
| 173 | * The query and the `kind:`, `sort:`, `updated:`, `archived:` and `owner:` words it did not take, | |
| 174 | * as typed. | |
| 175 | */ | |
| 165 | 176 | export interface ExploreRead { |
| 166 | 177 | readonly query: ExploreQuery; |
| 167 | 178 | readonly unknown: readonly string[]; |
| @@ -177,6 +188,7 @@ export function readExploreLine(line: string): ExploreRead { | ||
| 177 | 188 | let forks: number | undefined; |
| 178 | 189 | let ships: number | undefined; |
| 179 | 190 | let live = false; |
| 191 | let mine = false; | |
| 180 | 192 | const words: string[] = []; |
| 181 | 193 | for (const word of line |
| 182 | 194 | .trim() |
| @@ -209,6 +221,9 @@ export function readExploreLine(line: string): ExploreRead { | ||
| 209 | 221 | } else if (k === "live" && value !== "") { |
| 210 | 222 | if (["yes", "no"].includes(value.toLowerCase())) live = value.toLowerCase() === "yes"; |
| 211 | 223 | else unknown.push(word); |
| 224 | } else if (k === "mine" && value !== "") { | |
| 225 | if (["yes", "no"].includes(value.toLowerCase())) mine = value.toLowerCase() === "yes"; | |
| 226 | else unknown.push(word); | |
| 212 | 227 | } else if (k === "q" && value !== "") words.push(value); |
| 213 | 228 | else words.push(word); |
| 214 | 229 | } |
| @@ -223,6 +238,7 @@ export function readExploreLine(line: string): ExploreRead { | ||
| 223 | 238 | ...(forks === undefined ? {} : { forks }), |
| 224 | 239 | ...(ships === undefined ? {} : { ships }), |
| 225 | 240 | ...(live ? { live } : {}), |
| 241 | ...(mine ? { mine } : {}), | |
| 226 | 242 | }, |
| 227 | 243 | unknown: unknown.slice(0, 5), |
| 228 | 244 | }; |
| @@ -242,7 +258,7 @@ export function exploreNote(unknown: readonly string[]): string { | ||
| 242 | 258 | const shown = word.length > 40 ? `${word.slice(0, 39)}…` : word; |
| 243 | 259 | if (key === "owner") return `${shown} is not a name`; |
| 244 | 260 | if (key === "updated") return `${shown} is not a window — use ${Object.keys(WINDOWS).join(", ")}`; |
| 245 | if (key === "archived" || key === "live") return `${shown} is not an answer — use yes, no`; | |
| 261 | if (key === "archived" || key === "live" || key === "mine") return `${shown} is not an answer — use yes, no`; | |
| 246 | 262 | if (key === "forks" || key === "ships") return `${shown} is not a count — use a whole number from 0 to ${COUNT_MAX}`; |
| 247 | 263 | const sort = key === "sort"; |
| 248 | 264 | return `${shown} is not a ${sort ? "sort" : "kind"} — use ${(sort ? SORTS : KIND_WORDS).join(", ")}`; |
| @@ -320,6 +336,7 @@ export function exploreLine(query: ExploreQuery): string { | ||
| 320 | 336 | query.forks === undefined ? "" : `forks:${query.forks}`, |
| 321 | 337 | query.ships === undefined ? "" : `ships:${query.ships}`, |
| 322 | 338 | query.live === true ? "live:yes" : "", |
| 339 | query.mine === true ? "mine:yes" : "", | |
| 323 | 340 | query.text, |
| 324 | 341 | ] |
| 325 | 342 | .filter((p) => p !== "") |
| @@ -380,7 +397,10 @@ export function whyOf( | ||
| 380 | 397 | return best === undefined ? undefined : { signal: best[0], text: text[best[0]] }; |
| 381 | 398 | } |
| 382 | 399 | |
| 383 | /** The one fork action an app row offers: the page's button and the MCP row's `action` say these words. */ | |
| 400 | /** | |
| 401 | * The one fork action an app row offers: the page's button and the MCP row's `action` say these | |
| 402 | * words. | |
| 403 | */ | |
| 384 | 404 | export const MAKE_IT_YOURS = { do: "make_it_yours", label: "Make it yours" } as const; |
| 385 | 405 | |
| 386 | 406 | export interface ExploreRow { |
| @@ -434,6 +454,7 @@ export const exploreFiltered = (q: ExploreQuery): boolean => | ||
| 434 | 454 | q.forks !== undefined || |
| 435 | 455 | q.ships !== undefined || |
| 436 | 456 | q.live === true || |
| 457 | q.mine === true || | |
| 437 | 458 | q.sort !== "score"; |
| 438 | 459 | |
| 439 | 460 | /** |
| @@ -476,7 +497,10 @@ export async function explore( | ||
| 476 | 497 | return described(app, rows.slice(0, ROWS), stamp); |
| 477 | 498 | } |
| 478 | 499 | |
| 479 | /** The rows as the API and the MCP send them: each with its `why` line when the ranking has one to say (omitted otherwise). */ | |
| 500 | /** | |
| 501 | * The rows as the API and the MCP send them: each with its `why` line when the ranking has one to | |
| 502 | * say (omitted otherwise). | |
| 503 | */ | |
| 480 | 504 | export function rowsWithWhy(app: App, query: ExploreQuery, items: readonly ExploreRow[]): (ExploreRow & { why?: string })[] { |
| 481 | 505 | const weights = frontWeights(app.db); |
| 482 | 506 | const now = Date.now(); |
| @@ -587,7 +611,7 @@ async function everything( | ||
| 587 | 611 | /** The forges this forge spawned, for a site admin asking for them. */ |
| 588 | 612 | async function forges(app: App, viewer: User | undefined, query: ExploreQuery): Promise<ExploreRow[]> { |
| 589 | 613 | // A spawned forge carries no time, so a window leaves it out. |
| 590 | if (query.updated !== "all" || query.owner !== undefined) return []; | |
| 614 | if (query.updated !== "all" || query.owner !== undefined || query.mine === true) return []; | |
| 591 | 615 | // Nor does it carry forks, ships or a wake time, so a number asked for leaves it out. |
| 592 | 616 | if ((query.forks ?? 0) > 0 || (query.ships ?? 0) > 0 || query.live === true) return []; |
| 593 | 617 | if (viewer?.isAdmin !== true || (query.kind !== "all" && query.kind !== "forge")) return []; |
| @@ -727,7 +751,8 @@ function rank( | ||
| 727 | 751 | }); |
| 728 | 752 | |
| 729 | 753 | const text = query.text.toLowerCase(); |
| 730 | const only = query.owner?.toLowerCase(); | |
| 754 | // `mine` is the viewer's own name as an owner; signed out it is a name no row has. | |
| 755 | const only = (query.mine === true ? (viewer?.username ?? "\0") : query.owner)?.toLowerCase(); | |
| 731 | 756 | // Kept rows are shared by every request that reads them: none may change. |
| 732 | 757 | const freeze = (row: ExploreRow): ExploreRow => { |
| 733 | 758 | Object.freeze(row.numbers); |
| @@ -751,7 +776,9 @@ function rank( | ||
| 751 | 776 | /** What a like adds to the score sort: modest next to forks (3) and ships (2). */ |
| 752 | 777 | export const LIKE_WEIGHT = 0.5; |
| 753 | 778 | |
| 754 | /** Likes on posts about each repository; the caller passes only repositories the viewer may read. */ | |
| 779 | /** | |
| 780 | * Likes on posts about each repository; the caller passes only repositories the viewer may read. | |
| 781 | */ | |
| 755 | 782 | function likesByRepo(db: Database, repoIds: readonly string[]): Map<string, number> { |
| 756 | 783 | const out = new Map<string, number>(); |
| 757 | 784 | if (repoIds.length === 0) return out; |
src/web/studio/explore.ts +11 −1
| @@ -71,7 +71,7 @@ const shorten = (term: string): string => | ||
| 71 | 71 | term.length > 24 ? `${term.slice(0, 23)}…` : term; |
| 72 | 72 | |
| 73 | 73 | /** The query with one optional key left out. */ |
| 74 | function dropped(query: ExploreQuery, key: "forks" | "ships" | "live" | "owner"): ExploreQuery { | |
| 74 | function dropped(query: ExploreQuery, key: "forks" | "ships" | "live" | "owner" | "mine"): ExploreQuery { | |
| 75 | 75 | const copy: Record<string, unknown> = { ...query }; |
| 76 | 76 | delete copy[key]; |
| 77 | 77 | return copy as unknown as ExploreQuery; |
| @@ -91,6 +91,7 @@ function terms(query: ExploreQuery): { term: string; without: ExploreQuery }[] { | ||
| 91 | 91 | if (query.forks !== undefined) out.push({ term: `forks:${query.forks}`, without: dropped(query, "forks") }); |
| 92 | 92 | if (query.ships !== undefined) out.push({ term: `ships:${query.ships}`, without: dropped(query, "ships") }); |
| 93 | 93 | if (query.live === true) out.push({ term: "live:yes", without: dropped(query, "live") }); |
| 94 | if (query.mine === true) out.push({ term: "mine:yes", without: dropped(query, "mine") }); | |
| 94 | 95 | const words = query.text.split(/\s+/).filter((w) => w !== ""); |
| 95 | 96 | words.forEach((word, i) => |
| 96 | 97 | out.push({ |
| @@ -237,6 +238,15 @@ export async function explorePage(ctx: Ctx): Promise<Response> { | ||
| 237 | 238 | })), |
| 238 | 239 | "Kind", |
| 239 | 240 | )} |
| 241 | ${ctx.auth.user === undefined | |
| 242 | ? html`` | |
| 243 | : seg([ | |
| 244 | { | |
| 245 | label: "Mine", | |
| 246 | href: href(query.mine === true ? dropped(query, "mine") : { ...query, mine: true }), | |
| 247 | current: query.mine === true, | |
| 248 | }, | |
| 249 | ])} | |
| 240 | 250 | </div> |
| 241 | 251 | ${chipRow(query)} |
| 242 | 252 | ${returned ? html`<p class="muted mb" role="status">That page link is not one for this list, so this is the first page.</p>` : html``} |
test/explore-budget.test.ts +16 −2
| @@ -1,4 +1,7 @@ | ||
| 1 | /** The ranked read behind explore answers under its budget over 200 repositories, and never shares a private row (#10946). */ | |
| 1 | /** | |
| 2 | * The ranked read behind explore answers under its budget over 200 repositories, and never shares a | |
| 3 | * private row (#10946). | |
| 4 | */ | |
| 2 | 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| @@ -19,7 +22,10 @@ let owner: User; | ||
| 19 | 22 | let stranger: User; |
| 20 | 23 | const all = parseExploreQuery(""); |
| 21 | 24 | const budget = budgetFor("/explore#read")!; |
| 22 | /** The best of a few reads, so one stall on a loaded machine is not a finding; a slow read is slow every time. */ | |
| 25 | /** | |
| 26 | * The best of a few reads, so one stall on a loaded machine is not a finding; a slow read is slow | |
| 27 | * every time. | |
| 28 | */ | |
| 23 | 29 | async function best(read: () => Promise<unknown>, runs = 3) { |
| 24 | 30 | let low = Infinity; |
| 25 | 31 | for (let i = 0; i < runs; i++) { |
| @@ -74,6 +80,14 @@ test("a read is under the budget for every sort", async () => { | ||
| 74 | 80 | } |
| 75 | 81 | }); |
| 76 | 82 | |
| 83 | test("mine=yes is under the budget, and shows only the viewer's own", async () => { | |
| 84 | const q = parseExploreQuery("kind:app mine:yes"); | |
| 85 | expect(await best(() => explore(app, owner, q))).toBeLessThan(budget.p95Ms); | |
| 86 | expect((await explore(app, owner, q)).every((r) => r.name.startsWith("olive/"))).toBe(true); | |
| 87 | expect(await explore(app, stranger, q)).toEqual([]); | |
| 88 | expect(await explore(app, undefined, q)).toEqual([]); | |
| 89 | }); | |
| 90 | ||
| 77 | 91 | test("a private app is not shown to another viewer after the owner's read is warm", async () => { |
| 78 | 92 | await explore(app, owner, all); |
| 79 | 93 | const mine = (await explore(app, owner, all)).map((r) => r.name); |
test/explore-url-filters.test.ts added +107
| @@ -0,0 +1,107 @@ | ||
| 1 | /** | |
| 2 | * The explorer's filters (kind, sort, freshness, mine) live in the URL: a link renders what | |
| 3 | * choosing by hand does (#13161). | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { createApp as insertApp } from "../src/core/apps.ts"; | |
| 12 | import { exploreLineFrom, exploreParams, readExploreLine } from "../src/actions/explore.ts"; | |
| 13 | import { createSession } from "../src/core/sessions.ts"; | |
| 14 | import { createUser } from "../src/core/users.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { quietLogs } from "./helpers/globals.ts"; | |
| 17 | import { proveAll } from "./helpers/verified.ts"; | |
| 18 | import { promote } from "./helpers/members.ts"; | |
| 19 | ||
| 20 | quietLogs(); | |
| 21 | let dir: string; | |
| 22 | let app: App; | |
| 23 | let servers: Servers; | |
| 24 | let olive = ""; | |
| 25 | let pine = ""; | |
| 26 | ||
| 27 | beforeAll(async () => { | |
| 28 | dir = await mkdtemp(join(tmpdir(), "forge-explore-filters-")); | |
| 29 | app = createApp({ dataDir: dir, port: 0 }); | |
| 30 | for (const [owner, names] of [["olive", ["garden", "kiln"]], ["pine", ["loom"]]] as const) { | |
| 31 | const made = await createUser(app.db, { origin: "seed", username: owner, email: `${owner}@forge.local`, password: "a-good-passphrase", adminIfFirst: false }); | |
| 32 | if (!made.ok) throw new Error(made.error); | |
| 33 | proveAll(app); | |
| 34 | promote(app.db, made.value); | |
| 35 | const cookie = `forge_session=${createSession(app.db, made.value.id).token}`; | |
| 36 | if (owner === "olive") olive = cookie; | |
| 37 | else pine = cookie; | |
| 38 | for (const n of names) { | |
| 39 | const repo = await createRepo(app, made.value, { name: n, visibility: "public" }); | |
| 40 | if (!repo.ok) throw new Error(String(repo.error)); | |
| 41 | const rec = insertApp(app.db, { repoId: repo.value.id, slug: `${owner}-${n}`, access: "public" }); | |
| 42 | if (!rec.ok) throw new Error(rec.error); | |
| 43 | } | |
| 44 | } | |
| 45 | servers = await serve(app); | |
| 46 | }); | |
| 47 | afterAll(async () => { | |
| 48 | await servers.stop(); | |
| 49 | app.db.close(); | |
| 50 | await rm(dir, { recursive: true, force: true }); | |
| 51 | }); | |
| 52 | ||
| 53 | const get = async (path: string, cookie = "") => { | |
| 54 | const res = await fetch(`${servers.url}${path}`, { headers: cookie === "" ? {} : { cookie } }); | |
| 55 | return { status: res.status, html: await res.text() }; | |
| 56 | }; | |
| 57 | const listed = (html: string): string[] => { | |
| 58 | const list = /<ul class="list">([\s\S]*?)<\/ul>/.exec(html); | |
| 59 | return list === null ? [] : [...list[1]!.matchAll(/<li[^>]*>[\s\S]*?<a href="(\/[^"?]*)">/g)].map((m) => m[1]!); | |
| 60 | }; | |
| 61 | /** The href of the control whose visible text is `label`, as the page wrote it. */ | |
| 62 | const linkTo = (html: string, label: string): string => { | |
| 63 | const found = new RegExp(`<a[^>]*href="([^"]+)"[^>]*>\\s*${label}\\s*</a>`).exec(html); | |
| 64 | if (found === null) throw new Error(`no control named ${label}`); | |
| 65 | return found[1]!.replace(/&/g, "&"); | |
| 66 | }; | |
| 67 | ||
| 68 | test("mine round-trips through the query string and narrows to the viewer's own", async () => { | |
| 69 | expect(readExploreLine("mine:yes").query.mine).toBe(true); | |
| 70 | expect(exploreLineFrom((n) => (n === "mine" ? "yes" : null))).toBe("mine:yes"); | |
| 71 | expect(exploreParams(readExploreLine("kind:app mine:yes").query)).toBe("kind=app&mine=yes"); | |
| 72 | expect(listed((await get("/explore?kind=app&mine=yes&sort=name", olive)).html)).toEqual(["/olive/garden", "/olive/kiln"]); | |
| 73 | expect(listed((await get("/explore?kind=app&mine=yes", pine)).html)).toEqual(["/pine/loom"]); | |
| 74 | // Signed out, nothing is yours. | |
| 75 | expect(listed((await get("/explore?kind=app&mine=yes")).html)).toEqual([]); | |
| 76 | }); | |
| 77 | ||
| 78 | test("the cache is keyed by the filters: mine and not mine never answer for each other", async () => { | |
| 79 | const all = listed((await get("/explore?kind=app", olive)).html); | |
| 80 | const mine = listed((await get("/explore?kind=app&mine=yes", olive)).html); | |
| 81 | expect(all.length).toBe(3); | |
| 82 | expect(mine.length).toBe(2); | |
| 83 | expect(listed((await get("/explore?kind=app", olive)).html)).toEqual(all); | |
| 84 | }); | |
| 85 | ||
| 86 | test("a link with three filters renders the same rows as choosing them by hand", async () => { | |
| 87 | // The by-hand route reaches sort=fresh; the link names that same sort, and the lists match in | |
| 88 | // order. | |
| 89 | const linked = await get("/explore?kind=app&mine=yes&sort=fresh", olive); | |
| 90 | let page = await get("/explore", olive); | |
| 91 | for (const label of ["Apps", "Mine", "Fresh"]) page = await get(linkTo(page.html, label), olive); | |
| 92 | expect(listed(page.html)).toEqual(listed(linked.html)); | |
| 93 | expect(listed(page.html).length).toBe(2); | |
| 94 | // Signed out there is no Mine control, and the link shows no rows. | |
| 95 | expect((await get("/explore?kind=app")).html).not.toContain(">Mine<"); | |
| 96 | }); | |
| 97 | ||
| 98 | test("an unknown filter value is ignored with a one-line note, never a 500", async () => { | |
| 99 | const plain = listed((await get("/explore", olive)).html); | |
| 100 | for (const qs of ["?mine=maybe", "?kind=zzz", "?sort=zzz", "?since=9y"]) { | |
| 101 | const res = await get(`/explore${qs}`, olive); | |
| 102 | expect(res.status).toBe(200); | |
| 103 | expect(res.html).toContain('role="status"'); | |
| 104 | expect(listed(res.html)).toEqual(plain); | |
| 105 | } | |
| 106 | expect((await get("/explore?mine=maybe", olive)).html).toContain("mine:maybe is not an answer — use yes, no"); | |
| 107 | }); |
test/tui-dashboard-explore.test.ts +20 −3
| @@ -1,4 +1,7 @@ | ||
| 1 | /** The launcher's search line with `kind:` or `sort:` is the explorer's, ranked by the page's action (#7325). */ | |
| 1 | /** | |
| 2 | * The launcher's search line with `kind:` or `sort:` is the explorer's, ranked by the page's action | |
| 3 | * (#7325). | |
| 4 | */ | |
| 2 | 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| @@ -64,7 +67,8 @@ afterAll(async () => { | ||
| 64 | 67 | await rm(dir, { recursive: true, force: true }); |
| 65 | 68 | }); |
| 66 | 69 | |
| 67 | async function typed(line: string, then: string[] = [], user: User | undefined = alice): Promise<string> { | |
| 70 | async function typed(line: string, then: string[] = [], who: User | null = alice): Promise<string> { | |
| 71 | const user = who ?? undefined; // null is a guest; leaving it out is alice | |
| 68 | 72 | const terminal = headlessTerminal(200, 32); |
| 69 | 73 | const { app } = createForgeApp( |
| 70 | 74 | forge, |
| @@ -127,11 +131,24 @@ test("enter on an app row opens it", async () => { | ||
| 127 | 131 | test("a guest's explorer rows hold no private repository; its owner's do", async () => { |
| 128 | 132 | expect(await typed("kind:app", [], bob)).toContain("bob/vault"); |
| 129 | 133 | expect(await typed("kind:app", [], alice)).not.toContain("bob/vault"); |
| 130 | const guest = await typed("kind:app", [], undefined); | |
| 134 | const guest = await typed("kind:app", [], null); | |
| 131 | 135 | expect(guest).toContain("alice/zed"); |
| 132 | 136 | expect(guest).not.toContain("bob/vault"); |
| 133 | 137 | }); |
| 134 | 138 | |
| 139 | test("mine:yes shows the signed-in viewer's own apps and a guest none", async () => { | |
| 140 | const own = await typed("kind:app mine:yes", [], alice); | |
| 141 | expect(own).toContain("alice/zed"); | |
| 142 | expect(own).not.toContain("bob/vault"); | |
| 143 | expect(own).toContain("Read as: kind:app mine:yes"); | |
| 144 | const theirs = await typed("kind:app mine:yes", [], bob); | |
| 145 | expect(theirs).toContain("bob/vault"); | |
| 146 | expect(theirs).not.toContain("alice/zed"); | |
| 147 | const guest = await typed("kind:app mine:yes", [], null); | |
| 148 | expect(guest).not.toContain("alice/zed"); | |
| 149 | expect(guest).not.toContain("bob/vault"); | |
| 150 | }); | |
| 151 | ||
| 135 | 152 | test("pin, mark and archive on an explorer row say they do not apply", async () => { |
| 136 | 153 | const text = await typed("kind:app sort:forks", ["enter", "p"]); |
| 137 | 154 | expect(text).toContain("act on your repositories"); |
new above
offline
Opening the 'Sort and time' details for mine makes the section's name wrong; once Mine moves out, drop this condition.