justintsus-experiment Public
// Renders each build's Issues and Pull requests list pages to static HTML, running each build's own// page glue (A: repo/list-search.ts, B: search/lists.ts) against the hidden-test fixture in node:sqlite// through a small D1 shim, then wrapping the body in the real renderPage layout.// node render.mjs <A|B> <outdir>import { mkdirSync, writeFileSync, symlinkSync, existsSync } from "node:fs";import { pathToFileURL } from "node:url";// Set WORKTREE_A and WORKTREE_B to checkouts of the two builds (Rebasely at 40d9e6fd and a69ca436).process.env.SEARCH_WORKTREE ??= process.env.WORKTREE_A;const H = await import(new URL("../../hidden-tests/helpers.mjs", import.meta.url).href);const WT = { A: process.env.WORKTREE_A, B: process.env.WORKTREE_B };const k = process.argv[2];const out = process.argv[3];const W = WT[k];const imp = (p) => import(pathToFileURL(`${W}/apps/web/src/${p}`).href);mkdirSync(out, { recursive: true });if (!existsSync(`${out}/static`)) symlinkSync(`${W}/apps/web/static`, `${out}/static`);const db = H.fixture();// more issues so there is a next page: 30 open issuesconst ins = db.prepare(`INSERT INTO issues (repo_id, number, org_id, author_id, title, body, state, labels, comments, created_at, updated_at) VALUES ('repo-1', ?, 'org-1', ?, ?, '', 'open', ?, ?, ?, ?)`);for (let n = 100; n < 130; n++) ins.run(n, H.ALICE, `Generated issue ${n}: login page slow`, JSON.stringify(n % 3 ? ["perf"] : ["perf", "needs review"]), n % 5, H.d("2026-09-01") + n * 3600_000, H.NOW - n * 60_000);const sqls = [];const stmt = (sql, params = []) => ({ bind: (...p) => stmt(sql, p), all: async () => { sqls.push({ sql, params }); return { results: db.prepare(sql).all(...params) }; }, first: async () => db.prepare(sql).get(...params) ?? null, run: async () => db.prepare(sql).run(...params), _exec: () => { sqls.push({ sql, params }); return { results: db.prepare(sql).all(...params) }; },});const DB = { prepare: (sql) => stmt(sql), batch: async (list) => list.map((s) => s._exec()) };const prs = new Map(H.PULLS.map(([n, au, ow, st, dr, ti, ca]) => [n, { number: n, title: ti, state: st, draft: !!dr, authorId: au, ownerId: ow, baseRef: "refs/heads/main", headRef: `refs/heads/feature-${n}`, createdAt: ca, mergedAt: st === "merged" ? ca + 86400000 : null, closedAt: st !== "open" ? ca + 86400000 : null, authorKind: ow ? "agent" : "user", comments: n, reviewers: 0, updatedAt: ca }]));const REPO = { idFromName: (x) => x, get: () => ({ prList: async (q) => ({ items: (q.numbers ?? []).map((n) => prs.get(n)).filter(Boolean), counts: { open: 0, closed: 0, merged: 0 }, next: null }) }) };const env = { DB, REPO };const { renderPage } = await imp("ui/layout.ts");const { issuesListBody, issuesHref } = await imp("ui/issues.ts");const { pullsListBody, pullsHref } = await imp("ui/pulls.ts");const api = await imp("search/api.ts");const repo = { org: "acme", repo: "widgets", visibility: "public" };const labels = new Map([[H.ME, { name: "Mira Chen", kind: "user" }], [H.ALICE, { name: "Alice Ng", kind: "user" }], [H.BOB, { name: "Bob Ortiz", kind: "user" }], [H.FIXER, { name: "fixer", kind: "agent" }]]);const sql = { repoId: "repo-1", orgId: "org-1", viewerId: H.ME, now: H.NOW };async function issuesBody(params) { const sp = new URLSearchParams(params); const base = issuesHref(repo); const common = { repo, nav: { member: true }, now: H.NOW, labels, canOpen: true, signedIn: true, membersOnly: false, paused: false }; if (k === "A") { const ls = await imp("repo/list-search.ts"); const ed = await imp("search/edit.ts"); const s = ls.listSearchOf(sp, "issues"); const list = s.query ? await ls.searchIssues(env, sql, s.query, s.page) : null; const q = s.query ?? ed.withState(ed.emptyQuery("issues"), "open"); return issuesListBody({ ...common, search: { input: s.input, errors: s.errors }, tab: s.query ? ed.stateTab(s.query) : null, tabHrefs: { open: ls.searchHref(base, ed.withState(q, "open")), closed: ls.searchHref(base, ed.withState(q, "closed")), all: ls.searchHref(base, ed.withState(q, "all")) }, filtered: s.query ? ed.hasFilters(s.query) : false, clearHref: ls.searchHref(base, ed.withState(ed.emptyQuery("issues"), "open")), labelHref: (name) => ls.searchHref(base, ed.withTerm(q, { kind: "label", neg: false, value: name }) ?? q), prevHref: list && s.page > 1 ? ls.searchHref(base, q, s.page - 1) : null, nextHref: list?.more ? ls.searchHref(base, q, s.page + 1) : null, items: list?.items ?? [], counts: list?.counts ?? { open: 0, closed: 0 } }); } const L = await imp("search/lists.ts"); const { searchHref } = await imp("ui/search.ts"); const input = L.inputOf(sp, "issues"); const parsed = api.parseQuery(input, "issues"); const n = L.pageOf(sp.get("page")); const list = parsed.ok ? await L.searchIssues(env, parsed.query, sql, n) : null; const links = parsed.ok ? L.linksOf(base, parsed.query, n, list?.more ?? false) : L.linksOfInvalid(base); const items = list?.items ?? []; const labelHrefs = new Map(); if (parsed.ok) for (const l of new Set(items.flatMap((x) => x.labels))) { const q = api.withLabel(parsed.query, l); if (q) labelHrefs.set(l, searchHref(base, api.serializeQuery(q))); } const counts = list?.counts ?? null; const tabs = [ { label: "Open", href: links.tabHref("open"), count: counts?.open ?? null, current: links.tab === "open" }, { label: "Closed", href: links.tabHref("closed"), count: counts?.closed ?? null, current: links.tab === "closed" }, { label: "All", href: links.tabHref(null), count: null, current: links.tab === "all" }, ]; return issuesListBody({ ...common, search: { target: "issues", action: base, value: parsed.ok ? links.canonical : input, errors: parsed.ok ? [] : parsed.errors }, tabs, filtered: links.filtered, tab: links.tab === "merged" ? null : links.tab, items, counts, labelHrefs, pages: links.pages, clear: links.clear });}async function pullsBody(params) { const sp = new URLSearchParams(params); const base = pullsHref(repo); const common = { repo, nav: { member: true }, now: H.NOW, labels, canOpen: false, paused: false, defaultBranch: "main", recent: [] }; if (k === "A") { const ls = await imp("repo/list-search.ts"); const ed = await imp("search/edit.ts"); const s = ls.listSearchOf(sp, "pulls"); const list = s.query ? await ls.searchPulls(env, sql, s.query, s.page) : null; const found = list?.rows ?? []; const items = found.map((r) => { const h = prs.get(r.number); return { number: r.number, title: r.title, state: r.state, draft: !!r.draft, authorId: r.author_id, baseRef: r.base_ref, headRef: r.head_ref, createdAt: r.created_at, mergedAt: r.merged_at, closedAt: r.closed_at, authorKind: h?.authorKind ?? "user", comments: h?.comments ?? 0 }; }); const q = s.query ?? ed.withState(ed.emptyQuery("pulls"), "open"); const tabHref = (t) => ls.searchHref(base, ed.withState(q, t)); return pullsListBody({ ...common, search: { input: s.input, errors: s.errors }, tab: s.query ? ed.stateTab(s.query) : null, tabHrefs: { open: tabHref("open"), merged: tabHref("merged"), closed: tabHref("closed"), all: tabHref("all") }, filtered: s.query ? ed.hasFilters(s.query) : false, clearHref: ls.searchHref(base, ed.withState(ed.emptyQuery("pulls"), "open")), prevHref: list && s.page > 1 ? ls.searchHref(base, q, s.page - 1) : null, nextHref: list?.more ? ls.searchHref(base, q, s.page + 1) : null, items, counts: list?.counts ?? { open: 0, closed: 0, merged: 0 } }); } const L = await imp("search/lists.ts"); const input = L.inputOf(sp, "pulls"); const parsed = api.parseQuery(input, "pulls"); const n = L.pageOf(sp.get("page")); const list = parsed.ok ? await L.searchPulls(env, parsed.query, sql, n) : null; const links = parsed.ok ? L.linksOf(base, parsed.query, n, list?.more ?? false) : L.linksOfInvalid(base); const counts = list?.counts ?? null; const tabs = [ { label: "Open", href: links.tabHref("open"), count: counts?.open ?? null, current: links.tab === "open" }, { label: "Merged", href: links.tabHref("merged"), count: counts?.merged ?? null, current: links.tab === "merged" }, { label: "Closed", href: links.tabHref("closed"), count: counts ? counts.closed + counts.merged : null, current: links.tab === "closed" }, { label: "All", href: links.tabHref(null), count: null, current: links.tab === "all" }, ]; return pullsListBody({ ...common, search: { target: "pulls", action: base, value: parsed.ok ? links.canonical : input, errors: parsed.ok ? [] : parsed.errors }, tabs, filtered: links.filtered, tab: links.tab, items: list?.items ?? [], openCount: counts?.open ?? null, pages: links.pages, clear: links.clear });}const BAD = 'is:open assignee:@me label:"needs review "x 🐛"bug -sort:updated-desc created:2026-02-30 "never closed';const pages = { "issues-default": () => issuesBody({}), "issues-query": () => issuesBody({ q: 'IS:Open label:" Needs Review " sort:updated-desc', page: "1" }), "issues-page2": () => issuesBody({ q: "is:open label:perf", page: "2" }), "issues-legacy": () => issuesBody({ state: "closed", label: "bug" }), "issues-invalid": () => issuesBody({ q: BAD }), "issues-xss": () => issuesBody({ q: '"><script>alert(1)</script> foo:<img src=x onerror=alert(1)> label:"<b>x</b>"' }), "pulls-default": () => pullsBody({}), "pulls-query": () => pullsBody({ q: "-author:@me is:closed sort:created-asc" }), "pulls-invalid": () => pullsBody({ q: 'is:open label:bug review-requested:@ME author:"Bob Smith" sort:comments-desc' }),};const index = {};for (const [name, f] of Object.entries(pages)) { sqls.length = 0; const body = await f(); const html = renderPage("production", { title: name, body, session: null, context: { org: repo.org, repo: repo.repo }, pathname: `/${repo.org}/${repo.repo}/issues` }); writeFileSync(`${out}/${name}.html`, html); index[name] = { bytes: html.length, sql: sqls.map((s) => ({ sql: s.sql, nparams: s.params.length })) };}writeFileSync(`${out}/index.json`, JSON.stringify(index, null, 1));console.log(k, "rendered", Object.keys(pages).length, "pages to", out);