From f784279442164e2721eb53f78aaf62c56a38b8a5 Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Sat, 7 Nov 2026 23:59:15 -0600 Subject: [PATCH 1/2] =?UTF-8?q?feat(aggregator):=20global=20search=20slice?= =?UTF-8?q?=202=20=E2=80=94=20registry,=20DNS,=20services,=20tier=20items?= =?UTF-8?q?=20(#1212)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Search (slice 1, PR #3969) covered only board and roadmap subjects. Slice 2 extends searchWork with the registry/session records, the DNS register, the usage-hub services, and the orchestration tier items, each result carrying a stable detail href: /item/ for board/roadmap, /sessions?id=# for sessions, /dns#dns- for register rows (dnsTable now renders a per-domain anchor), /quota/service/ for services, and the session view or the /discuss/ page for tier items. renderSearch links each card to its own detail view and carries the freshness facets of every result kind home page; searchContext loads the extra sources fail-soft so one broken source never takes search down. Refs #1212 (slice 2 of the issue acceptance; does not close it). --- pm-stack/aggregator/src/pages.ts | 2 +- pm-stack/aggregator/src/render.ts | 22 +++- pm-stack/aggregator/src/search-view.ts | 116 +++++++++++++++++- pm-stack/aggregator/src/server.ts | 16 ++- pm-stack/aggregator/test/search-view.test.ts | 120 ++++++++++++++++++- 5 files changed, 263 insertions(+), 13 deletions(-) diff --git a/pm-stack/aggregator/src/pages.ts b/pm-stack/aggregator/src/pages.ts index 0a979ea503..99ab034794 100644 --- a/pm-stack/aggregator/src/pages.ts +++ b/pm-stack/aggregator/src/pages.ts @@ -161,7 +161,7 @@ export const PAGES: PageDef[] = [ title: "Search", route: "/search", api: "/api/search.json", - blurb: "Search board and roadmap work by title or linked issue/PR ref.", + blurb: "Search board, roadmap, registry sessions, DNS, services, and tier items by title or linked issue/PR ref.", group: "work", nav: "dropdown", }, diff --git a/pm-stack/aggregator/src/render.ts b/pm-stack/aggregator/src/render.ts index 11368f7ddc..83f0ea8170 100644 --- a/pm-stack/aggregator/src/render.ts +++ b/pm-stack/aggregator/src/render.ts @@ -116,6 +116,7 @@ import { blockedSummary, depthLayout, hasGraphEdges } from "./graph.ts"; import { EPIC_GRAPH_DEFAULT_CAP, epicGraph, epicSelector } from "./epic-graph.ts"; import { type AuthorIdentity } from "./registry.ts"; import type { SearchResult } from "./search-view.ts"; +import { dnsAnchor } from "./search-view.ts"; export function esc(s: unknown): string { return String(s ?? "") @@ -492,7 +493,7 @@ function layout( ${extra}${paletteHtml()}${KEYBOARD_SCRIPT}`; } -/** First-slice global search over board/roadmap subjects and linked refs. */ +/** Global search over board/roadmap subjects, linked refs, and the slice-2 sources (#1212): registry sessions, the DNS register, services, and tier items. */ export function renderSearch( query: string, results: SearchResult[], @@ -510,17 +511,28 @@ export function renderSearch( : `${esc(ref)} · unresolved`; }) .join(" "); - return `
${esc(result.title)}
${result.kind} · ${esc(result.summary)}${badges ? `
${badges}
` : ""}
`; + return `
${esc(result.title)}
${result.kind} · ${esc(result.summary)}${badges ? `
${badges}
` : ""}
`; }) .join(""); - const body = `

Search

Search board items and roadmap rows by subject, title, or linked issue/PR ref. Linked GitHub badges show their current projected state and whether the result is fixture-only.

${query ? `

${results.length} result${results.length === 1 ? "" : "s"} for “${esc(query)}”

${cards || '

No matching work found.

'}` : '

Enter a title or issue/PR reference to search.

'}`; + const body = `

Search

Search board items, roadmap rows, registry sessions, DNS domains, services, and tier items by subject, title, or linked issue/PR ref. Every result links to its own detail view. Linked GitHub badges show their current projected state and whether the result is fixture-only.

${query ? `

${results.length} result${results.length === 1 ? "" : "s"} for “${esc(query)}”

${cards || '

No matching work found.

'}` : '

Enter a title or issue/PR reference to search.

'}`; + // #1212 slice 2: the search page carries the same freshness facets + // as the home page of each result kind present (board/roadmap/items + // for work, registry for sessions, dns for the register, quota and + // usage for services, orchestration/attention/registry for tiers). + const chipKeys = new Set(["board", "roadmap", "items"]); + for (const result of results) { + if (result.kind === "registry") chipKeys.add("registry"); + if (result.kind === "dns") chipKeys.add("dns"); + if (result.kind === "service") { chipKeys.add("quota"); chipKeys.add("usage"); } + if (result.kind === "tier") { chipKeys.add("orchestration"); chipKeys.add("attention"); chipKeys.add("registry"); } + } return layout( "Search", body, provenance, "/search", "", - detail ? freshnessChips(detail, ["board", "roadmap", "items"]) : "", + detail ? freshnessChips(detail, [...chipKeys]) : "", ); } @@ -3840,7 +3852,7 @@ function dnsTable(entries: DnsEntry[], renewingSoon: Set, nextRenewal? const rows = entries .map( (e) => - `${esc(e.domain)}${esc(e.renewal)}${e.priceUsd != null ? `$${e.priceUsd.toFixed(2)}` : "—"}${esc(e.autoRenew)}${esc(e.plan)}${esc(e.review)}`, + `${esc(e.domain)}${esc(e.renewal)}${e.priceUsd != null ? `$${e.priceUsd.toFixed(2)}` : "—"}${esc(e.autoRenew)}${esc(e.plan)}${esc(e.review)}`, ) .join(""); return `
${rows || ''}
Domain register
DomainNext renewalPrice (list)Auto-renewPlan / statusReview?
none
`; diff --git a/pm-stack/aggregator/src/search-view.ts b/pm-stack/aggregator/src/search-view.ts index a2acef8ba8..3c27b5fb5c 100644 --- a/pm-stack/aggregator/src/search-view.ts +++ b/pm-stack/aggregator/src/search-view.ts @@ -1,23 +1,62 @@ -import type { BoardItem, GhItem, RefKey, RoadmapRow } from "./model.ts"; +import type { BoardItem, DnsSection, GhItem, RefKey, RoadmapRow, SaasService, SessionRecord, TierItem } from "./model.ts"; export interface SearchResult { - kind: "board" | "roadmap"; + kind: "board" | "roadmap" | "registry" | "dns" | "service" | "tier"; id: string; title: string; summary: string; refs: RefKey[]; + /** Stable detail view for this result (#1212 slice 2): every kind + * links to its own home detail route, not /item/ for all. */ + href: string; +} + +/** The non-board/roadmap subjects slice 2 adds, all optional so + * first-slice callers and fixtures keep working unchanged. */ +export interface SearchExtras { + registry?: SessionRecord[]; + dns?: DnsSection | null; + services?: SaasService[]; + tierItems?: TierItem[]; } function includesQuery(query: string, values: (string | undefined)[]): boolean { return values.some((value) => value?.toLowerCase().includes(query)); } -/** Search the first-slice canonical subjects and their projected GitHub refs. */ +/** Anchor id for a register row on /dns (dnsTable renders the same id). */ +export function dnsAnchor(domain: string): string { + return `dns-${domain.toLowerCase()}`; +} + +/** The stable session view: the registry page filtered to one record. */ +function sessionHref(id: string): string { + return `/sessions?id=${encodeURIComponent(id)}#${encodeURIComponent(id)}`; +} + +/** Mirror of render.ts tierItemObjectRef, kept local so the search + * view stays free of render imports: watchdog items key by their own + * id, ref-carrying items by their gh: ref, the rest by orch: id. */ +function tierObjectRef(item: TierItem): string { + if (item.source === "watchdog") return `orch:${item.id}`; + return item.ref ? `gh:${item.ref}` : `orch:${item.id}`; +} + +function tierHref(item: TierItem): string { + if (item.sessionId) return sessionHref(item.sessionId); + return `/discuss/${encodeURIComponent(tierObjectRef(item))}`; +} + +/** Search the canonical subjects and their projected GitHub refs. + * Slice 2 (#1212) adds the registry/session records, the DNS register, + * the usage-hub services, and the orchestration tier items, each + * linking to its stable detail view. */ export function searchWork( board: BoardItem[], rows: RoadmapRow[], items: Map, rawQuery: string, + extras: SearchExtras = {}, ): SearchResult[] { const query = rawQuery.trim().toLowerCase(); if (!query) return []; @@ -33,6 +72,7 @@ export function searchWork( title: item.title, summary: `${item.repo} · ${item.status}`, refs, + href: `/item/${encodeURIComponent(item.id)}`, }); } } @@ -59,6 +99,76 @@ export function searchWork( title: row.title, summary: `${row.area} · ${row.status} · ${row.horizon}`, refs, + href: `/item/${encodeURIComponent(row.subject)}`, + }); + } + } + + for (const record of extras.registry ?? []) { + const title = record.label || record.title || record.id; + if ( + includesQuery(query, [ + record.id, + record.label, + record.title, + record.agentId, + record.agentLabel, + record.status, + record.model, + record.directory, + ...record.taskRefs, + ]) + ) { + results.push({ + kind: "registry", + id: record.id, + title, + summary: `${record.agentLabel} · ${record.status}`, + refs: record.taskRefs, + href: sessionHref(record.id), + }); + } + } + + for (const entry of extras.dns?.entries ?? []) { + if ( + includesQuery(query, [entry.domain, entry.registrar, entry.dnsHost, entry.plan, entry.used, entry.review, entry.status]) + ) { + results.push({ + kind: "dns", + id: entry.domain, + title: entry.domain, + summary: `${entry.registrar} · ${entry.status} · renews ${entry.renewal}`, + refs: [], + href: `/dns#${dnsAnchor(entry.domain)}`, + }); + } + } + + for (const svc of extras.services ?? []) { + if (includesQuery(query, [svc.id, svc.name, svc.plan, svc.status, svc.group])) { + results.push({ + kind: "service", + id: svc.id, + title: svc.name, + summary: `${svc.group} · ${svc.plan}`, + refs: [], + href: `/quota/service/${encodeURIComponent(svc.id)}`, + }); + } + } + + for (const item of extras.tierItems ?? []) { + if ( + includesQuery(query, [item.id, item.title, item.kind, item.source, item.state, item.reason, item.ref, item.sessionId]) + ) { + results.push({ + kind: "tier", + id: item.id, + title: item.title, + summary: `${item.source} · ${item.state ?? item.kind}`, + refs: item.ref ? [item.ref] : [], + href: tierHref(item), }); } } diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index ad7d7abc4b..c82386d813 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -556,10 +556,22 @@ async function roadmapContext() { } async function searchContext(query: string) { - const [board, rows] = await Promise.all([source.board(), source.roadmap()]); + // #1212 slice 2: registry, DNS, services, and tier items join the + // board/roadmap subjects. Each extra source fails soft (empty on + // error) so one broken source never takes search down with it. + const [board, rows, registry, dns, usage, orchestration] = await Promise.all([ + source.board(), + source.roadmap(), + source.registry().catch(() => []), + source.dns().catch(() => null), + source.usage().catch(() => null), + source.orchestration().catch(() => null), + ]); const refs = [...new Set([...allRefs(board), ...allRefs(rows)])]; const items = await source.items(refs); - return { query, results: searchWork(board, rows, items, query), items }; + const tierItems = orchestration ? [...orchestration.tiers.needsDrew, ...orchestration.tiers.needsOrchestrator] : []; + const extras = { registry, dns, services: usage?.services ?? [], tierItems }; + return { query, results: searchWork(board, rows, items, query, extras), items }; } // #3321: watchdog gap-sync passes run whole and in observation diff --git a/pm-stack/aggregator/test/search-view.test.ts b/pm-stack/aggregator/test/search-view.test.ts index 2b13a74f92..44e19b5d09 100644 --- a/pm-stack/aggregator/test/search-view.test.ts +++ b/pm-stack/aggregator/test/search-view.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from "bun:test"; -import type { BoardItem, GhItem, Provenance, ProvenanceDetail, RefKey, RoadmapRow } from "../src/model.ts"; +import type { BoardItem, DnsSection, GhItem, Provenance, ProvenanceDetail, RefKey, RoadmapRow, SaasService, SessionRecord, TierItem } from "../src/model.ts"; import { renderSearch } from "../src/render.ts"; import { searchWork } from "../src/search-view.ts"; @@ -81,9 +81,125 @@ describe("global search first slice", () => { const results = searchWork(board, rows, projected, "1212"); const html = renderSearch("1212", results, projected, provenance, detail); expect(html).toContain('action="/search"'); - expect(html).toContain("Search board and roadmap work"); + expect(html).toContain("Search board items, roadmap rows, registry sessions, DNS domains, services, and tier items"); expect(html).toContain("Add global search"); expect(html).toContain("developing-today/code#1212"); expect(html).toContain("items · live"); }); }); + +const registry: SessionRecord[] = [ + { + id: "ses_searchfixture", + source: "opencode-laptop", + label: "Search fixture session", + agentId: "opencode:main", + agentLabel: "OpenCode main", + parentId: null, + status: "in-progress", + taskRefs: [ref], + }, +]; +const dns: DnsSection = { + generatedAt: "2026-11-01T00:00:00Z", + source: "fixture register", + totalAnnualListUsd: 12, + entries: [ + { + domain: "searchfixture.example", + registrar: "Fixture Registrar", + dnsHost: "Fixture DNS", + renewal: "2027-01-15", + autoRenew: "ON", + priceUsd: 12, + priorYearCost: "$12", + used: "fixture", + plan: "active use", + review: "no", + status: "active", + }, + ], +}; +const services: SaasService[] = [ + { + id: "searchfixture-db", + name: "Searchfixture DB", + group: "database", + plan: "Free", + status: "active", + metrics: [], + paygEstimate: null, + measuredAt: "2026-11-01T00:00:00Z", + sourceClass: "api", + sourceNote: "fixture", + cadenceDays: 7, + conflicts: [], + reads: [], + }, +]; +const tierItems: TierItem[] = [ + { + id: "tier-searchfixture", + kind: "task", + title: "Searchfixture tier task", + source: "opencode-laptop", + state: "blocked", + reason: "fixture reason", + since: "2026-11-01T00:00:00Z", + lastSeenAt: "2026-11-01T00:00:00Z", + ref, + }, +]; + +describe("global search slice 2 (#1212)", () => { + const extras = { registry, dns, services, tierItems }; + + test("finds registry sessions by label and task ref, linking to the session view", () => { + const byLabel = searchWork(board, rows, projected, "Search fixture session", extras); + expect(byLabel.map((r) => r.kind)).toEqual(["registry"]); + expect(byLabel[0].href).toBe("/sessions?id=ses_searchfixture#ses_searchfixture"); + const byRef = searchWork([], [], projected, "developing-today/code#1212", extras); + expect(byRef.map((r) => r.kind)).toContain("registry"); + }); + + test("finds DNS entries by domain, linking to the register row anchor", () => { + const results = searchWork([], [], projected, "searchfixture.example", extras); + expect(results.map((r) => r.kind)).toEqual(["dns"]); + expect(results[0].href).toBe("/dns#dns-searchfixture.example"); + }); + + test("finds services by name, linking to the service detail page", () => { + const results = searchWork([], [], projected, "Searchfixture DB", extras); + expect(results.map((r) => r.kind)).toEqual(["service"]); + expect(results[0].href).toBe("/quota/service/searchfixture-db"); + }); + + test("finds tier items by title, linking to their object discussion page", () => { + const results = searchWork([], [], projected, "Searchfixture tier task", extras); + expect(results.map((r) => r.kind)).toEqual(["tier"]); + expect(results[0].href).toBe("/discuss/gh%3Adeveloping-today%2Fcode%231212"); + }); + + test("board and roadmap results keep their /item/ detail links", () => { + const results = searchWork(board, rows, projected, "1212", extras); + const work = results.filter((r) => r.kind === "board" || r.kind === "roadmap"); + expect(work.map((r) => r.href)).toEqual([ + "/item/kaneo%3Apm-stack%2Ftask-1", + "/item/grist%3Aprogram%2Froadmap%2F7", + ]); + }); + + test("renders the new kinds with their home freshness facets", () => { + const results = searchWork([], [], projected, "searchfixture", extras); + expect(results.map((r) => r.kind).sort()).toEqual(["dns", "registry", "service", "tier"]); + const html = renderSearch("searchfixture", results, projected, provenance, detail); + expect(html).toContain("/quota/service/searchfixture-db"); + expect(html).toContain("/dns#dns-searchfixture.example"); + expect(html).toContain("dns · live"); + expect(html).toContain("registry · live"); + }); + + test("extras are optional: first-slice calls behave as before", () => { + expect(searchWork(board, rows, projected, "1212").map((r) => r.kind)).toEqual(["board", "roadmap"]); + }); +}); From 0ba2dc941d9cca5519e43c7b9df116eb81f885d3 Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Sun, 8 Nov 2026 00:27:59 -0600 Subject: [PATCH 2/2] aggregator: fix the four Codex findings on the slice-2 search PR (#1212) P1: tier/registry refs are filtered with isValidRef before they become GitHub badges, and renderSearch renders a non-GitHub ref as plain text instead of letting refUrl throw and fail /search. P2: searchContext resolves refs carried only by registry sessions and tier items. P2: the /dns row anchor id is escaped. P2: includesQuery only matches string values, so non-string optional fields (model: 7, a numeric registrar) no longer throw. Regression tests for each finding in search-view.test.ts. --- pm-stack/aggregator/src/render.ts | 9 +++- pm-stack/aggregator/src/search-view.ts | 18 ++++++-- pm-stack/aggregator/src/server.ts | 10 ++++- pm-stack/aggregator/test/search-view.test.ts | 45 +++++++++++++++++++- 4 files changed, 73 insertions(+), 9 deletions(-) diff --git a/pm-stack/aggregator/src/render.ts b/pm-stack/aggregator/src/render.ts index 83f0ea8170..bfae2b4039 100644 --- a/pm-stack/aggregator/src/render.ts +++ b/pm-stack/aggregator/src/render.ts @@ -506,9 +506,14 @@ export function renderSearch( const badges = result.refs .map((ref) => { const item = items.get(ref); + // Codex P1 on PR #7331 (defense in depth): a non-GitHub ref + // (tracked-goal id, orch: key) must never reach refUrl, which + // throws on it — render it as a plain-text badge instead. return item ? itemBadge(item) - : `${esc(ref)} · unresolved`; + : isValidRef(ref) + ? `${esc(ref)} · unresolved` + : `${esc(ref)} · unresolved`; }) .join(" "); return `
${esc(result.title)}
${result.kind} · ${esc(result.summary)}${badges ? `
${badges}
` : ""}
`; @@ -3852,7 +3857,7 @@ function dnsTable(entries: DnsEntry[], renewingSoon: Set, nextRenewal? const rows = entries .map( (e) => - `${esc(e.domain)}${esc(e.renewal)}${e.priceUsd != null ? `$${e.priceUsd.toFixed(2)}` : "—"}${esc(e.autoRenew)}${esc(e.plan)}${esc(e.review)}`, + `${esc(e.domain)}${esc(e.renewal)}${e.priceUsd != null ? `$${e.priceUsd.toFixed(2)}` : "—"}${esc(e.autoRenew)}${esc(e.plan)}${esc(e.review)}`, ) .join(""); return `
${rows || ''}
Domain register
DomainNext renewalPrice (list)Auto-renewPlan / statusReview?
none
`; diff --git a/pm-stack/aggregator/src/search-view.ts b/pm-stack/aggregator/src/search-view.ts index 3c27b5fb5c..d8b97a1da6 100644 --- a/pm-stack/aggregator/src/search-view.ts +++ b/pm-stack/aggregator/src/search-view.ts @@ -1,4 +1,5 @@ import type { BoardItem, DnsSection, GhItem, RefKey, RoadmapRow, SaasService, SessionRecord, TierItem } from "./model.ts"; +import { isValidRef } from "./model.ts"; export interface SearchResult { kind: "board" | "roadmap" | "registry" | "dns" | "service" | "tier"; @@ -20,8 +21,13 @@ export interface SearchExtras { tierItems?: TierItem[]; } -function includesQuery(query: string, values: (string | undefined)[]): boolean { - return values.some((value) => value?.toLowerCase().includes(query)); +function includesQuery(query: string, values: unknown[]): boolean { + // Codex P2 on PR #7331: accepted records can carry non-string optional + // fields (an unvalidated registry `model: 7`, a DNS `registrar`, ...); + // `value?.toLowerCase()` only guards nullish values and threw on those, + // taking down /search and /api/search.json for every query that reached + // the field. Only strings are searchable. + return values.some((value) => typeof value === "string" && value.toLowerCase().includes(query)); } /** Anchor id for a register row on /dns (dnsTable renders the same id). */ @@ -124,7 +130,7 @@ export function searchWork( id: record.id, title, summary: `${record.agentLabel} · ${record.status}`, - refs: record.taskRefs, + refs: record.taskRefs.filter(isValidRef), href: sessionHref(record.id), }); } @@ -167,7 +173,11 @@ export function searchWork( id: item.id, title: item.title, summary: `${item.source} · ${item.state ?? item.kind}`, - refs: item.ref ? [item.ref] : [], + // Codex P1 on PR #7331: a tier ref can be a tracked-goal id or + // another non-GitHub key; passing it on as a badge ref made + // renderSearch's refUrl throw and failed the whole /search + // request. Only owner/repo#N refs become GitHub badges. + refs: item.ref && isValidRef(item.ref) ? [item.ref] : [], href: tierHref(item), }); } diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index c82386d813..1c463cb532 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -65,6 +65,7 @@ import { type RoadmapReconciliation, } from "./roadmap-reconcile.ts"; import type { Comment, DashComment, GhItem, ProjectPoolItem, QuotaView, RefKey, UsageView } from "./model.ts"; +import { isValidRef } from "./model.ts"; import { buildEpicRollups } from "./epics.ts"; import { buildProgramData, programRefs } from "./program.ts"; import { @@ -567,9 +568,14 @@ async function searchContext(query: string) { source.usage().catch(() => null), source.orchestration().catch(() => null), ]); - const refs = [...new Set([...allRefs(board), ...allRefs(rows)])]; - const items = await source.items(refs); const tierItems = orchestration ? [...orchestration.tiers.needsDrew, ...orchestration.tiers.needsOrchestrator] : []; + // Codex P2 on PR #7331: refs carried only by the slice-2 sources + // (registry taskRefs, tier-item refs) join the resolution set, or + // their search badges always render unresolved even when the live + // pool/projector could resolve them. + const extraRefs = [...registry.flatMap((record) => record.taskRefs), ...tierItems.map((item) => item.ref)].filter(isValidRef); + const refs = [...new Set([...allRefs(board), ...allRefs(rows), ...extraRefs])]; + const items = await source.items(refs); const extras = { registry, dns, services: usage?.services ?? [], tierItems }; return { query, results: searchWork(board, rows, items, query, extras), items }; } diff --git a/pm-stack/aggregator/test/search-view.test.ts b/pm-stack/aggregator/test/search-view.test.ts index 44e19b5d09..bf2d632ca6 100644 --- a/pm-stack/aggregator/test/search-view.test.ts +++ b/pm-stack/aggregator/test/search-view.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from "bun:test"; import type { BoardItem, DnsSection, GhItem, Provenance, ProvenanceDetail, RefKey, RoadmapRow, SaasService, SessionRecord, TierItem } from "../src/model.ts"; -import { renderSearch } from "../src/render.ts"; +import { renderDns, renderSearch } from "../src/render.ts"; import { searchWork } from "../src/search-view.ts"; const ref = "developing-today/code#1212" as RefKey; @@ -203,3 +203,46 @@ describe("global search slice 2 (#1212)", () => { expect(searchWork(board, rows, projected, "1212").map((r) => r.kind)).toEqual(["board", "roadmap"]); }); }); + +describe("global search slice 2 - Codex findings on PR #7331", () => { + test("P1: a tier item whose ref is a tracked-goal id renders as text, never a GitHub badge", () => { + const goalTier: TierItem[] = [ + { ...tierItems[0], id: "tier-goalref", title: "Goalref tier task", ref: "goal_b647ff5c92f5" as RefKey }, + ]; + const results = searchWork([], [], projected, "Goalref tier task", { tierItems: goalTier }); + expect(results.map((r) => r.kind)).toEqual(["tier"]); + expect(results[0].refs).toEqual([]); + const html = renderSearch("Goalref tier task", results, projected, provenance, detail); + expect(html).toContain("Goalref tier task"); + }); + + test("P1: renderSearch survives a hand-built result carrying a non-GitHub ref", () => { + const results = [ + { kind: "tier" as const, id: "tier-x", title: "Hand built", summary: "s", refs: ["goal_b647ff5c92f5" as RefKey], href: "/discuss/orch%3Atier-x" }, + ]; + const html = renderSearch("Hand built", results, projected, provenance, detail); + expect(html).toContain("goal_b647ff5c92f5"); + }); + + test("P2: non-string optional fields do not break matching (registry model, DNS registrar)", () => { + const oddRegistry: SessionRecord[] = [ + { ...registry[0], id: "ses_odd", label: "Odd session", model: 7 as unknown as string, directory: "needle-dir" }, + ]; + expect(searchWork([], [], projected, "needle-dir", { registry: oddRegistry }).map((r) => r.kind)).toEqual(["registry"]); + const oddDns: DnsSection = { + ...dns, + entries: [{ ...dns.entries[0], domain: "odd.example", registrar: 7 as unknown as string, plan: "needle plan" }], + }; + expect(searchWork([], [], projected, "needle plan", { dns: oddDns }).map((r) => r.kind)).toEqual(["dns"]); + }); + + test("P2: the /dns row anchor escapes a domain carrying HTML metacharacters", () => { + const evil: DnsSection = { + ...dns, + entries: [{ ...dns.entries[0], domain: 'x">' }], + }; + const html = renderDns(evil, provenance, detail); + expect(html).not.toContain('id="dns-x">