diff --git a/pm-stack/aggregator/src/sources/live.ts b/pm-stack/aggregator/src/sources/live.ts index 9f68c9a342..f1110a6128 100644 --- a/pm-stack/aggregator/src/sources/live.ts +++ b/pm-stack/aggregator/src/sources/live.ts @@ -347,18 +347,29 @@ async function gristRoadmap(cfg: Config): Promise { * Enrich board items / roadmap rows with their cross-repo registry links. * This is the first-class requirement Kaneo cannot provide: the registry is * where a `code` task's link to an `opencode` PR lives. + * + * A failed registry read never throws and never blocks the board: the + * entry keeps its own links and the result reports `linksDegraded` so the + * caller can say so in its provenance (#8570) instead of claiming links + * it did not fetch. */ async function enrichWithRegistryLinks( baseUrl: string, entries: T[], subjectOf: (entry: T) => string, -): Promise { - return Promise.all( +): Promise<{ entries: T[]; linksDegraded: boolean }> { + let linksDegraded = false; + const enriched = await Promise.all( entries.map(async (entry) => { const extra = await projectorLinks(baseUrl, subjectOf(entry)); + if (extra === null) { + linksDegraded = true; + return entry; + } return extra.length ? { ...entry, links: mergeLinks(entry.links, extra) } : entry; }), ); + return { entries: enriched, linksDegraded }; } // --- Orchestrator in-flight lane ------------------------------------------- @@ -1374,9 +1385,14 @@ export function liveSource( provenance.board = "live (Kaneo; done aged out after 7 days, retired ROADMAP Done-table cards filtered)"; let merged = board; if (cfg.projector.baseUrl) { - merged = await enrichWithRegistryLinks(cfg.projector.baseUrl, board, (b) => b.id); - provenance.board = - "live (Kaneo + projector links; done aged out after 7 days, retired ROADMAP Done-table cards filtered)"; + const { entries, linksDegraded } = await enrichWithRegistryLinks(cfg.projector.baseUrl, board, (b) => b.id); + merged = entries; + // #8570: a dead registry degrades the links visibly — the board + // stays up on the Kaneo cards, and the chip names the outage + // instead of claiming "+ projector links" for links not fetched. + provenance.board = linksDegraded + ? "live (Kaneo + projector links unavailable (registry unreachable); done aged out after 7 days, retired ROADMAP Done-table cards filtered)" + : "live (Kaneo + projector links; done aged out after 7 days, retired ROADMAP Done-table cards filtered)"; } // In-flight lane (see inFlightBoardItems above): synthetic // entries from the fleet feed's orchestration section — the @@ -1409,8 +1425,14 @@ export function liveSource( let merged = rows; let label = "live (Grist)"; if (cfg.projector.baseUrl) { - merged = await enrichWithRegistryLinks(cfg.projector.baseUrl, rows, (r) => r.subject); - label = "live (Grist + projector links)"; + const { entries, linksDegraded } = await enrichWithRegistryLinks( + cfg.projector.baseUrl, + rows, + (r) => r.subject, + ); + merged = entries; + // #8570: same degraded-links honesty as the board path above. + label = linksDegraded ? "live (Grist + projector links unavailable (registry unreachable))" : "live (Grist + projector links)"; } // #1738: merge the repos' own roadmap files in alongside the // Grist rows. The repo-file read never throws (its failures diff --git a/pm-stack/aggregator/src/sources/projector.ts b/pm-stack/aggregator/src/sources/projector.ts index 11d761dc11..2587a6115e 100644 --- a/pm-stack/aggregator/src/sources/projector.ts +++ b/pm-stack/aggregator/src/sources/projector.ts @@ -313,10 +313,14 @@ export async function projectorLatestComments(baseUrl: string, refs: RefKey[]): return out; } -/** Registry links for one subject (kaneo:/grist:/gh:), from GET /links. */ -export async function projectorLinks(baseUrl: string, subject: string): Promise { +/** Registry links for one subject (kaneo:/grist:/gh:), from GET /links. + * A failed read returns null (fail-soft, like projectorItems and + * projectorComments) so callers can tell "registry unreachable" apart + * from "reachable but no links for this subject" (#8570: the board + * provenance must say the links are unavailable, not claim them). */ +export async function projectorLinks(baseUrl: string, subject: string): Promise { const r = await getJson(`${baseUrl}/links?subject=${encodeURIComponent(subject)}`); - if (!r.ok) return []; + if (!r.ok) return null; const rows = (r.json as { links?: ProjectorLinkRow[] }).links ?? []; // Stored rows bypass the projector's POST /links gate (legacy/seeded // data), so the shared ref rule (#4952) is applied here at the read diff --git a/pm-stack/aggregator/test/board-link-degradation-8570.test.ts b/pm-stack/aggregator/test/board-link-degradation-8570.test.ts new file mode 100644 index 0000000000..c6a8d17c9e --- /dev/null +++ b/pm-stack/aggregator/test/board-link-degradation-8570.test.ts @@ -0,0 +1,127 @@ +// #8570 Phase 3 acceptance: killing the projection module's intake must +// degrade board link data visibly (provenance chips say so) without taking +// the board down. The board enriches Kaneo cards with registry links from +// the projector; when that read fails the board must still serve the Kaneo +// cards while its provenance says the links are unavailable — never claim +// "+ projector links" for links it did not fetch. +// +// Run: bun test test/board-link-degradation-8570.test.ts +import { describe, expect, test } from "bun:test"; +import { mkdtemp, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { loadConfig } from "../src/config.ts"; +import { liveSource } from "../src/sources/live.ts"; +import { projectorLinks } from "../src/sources/live.ts"; + +const FEED = { + version: 1, + generatedAt: new Date().toISOString(), + quota: { pools: [], burn: [], choices: { hasHeadroom: [], burnBeforeReset: [], doNotStart: [] } }, + attention: [], +}; + +// Port 1 is never bound: reads against it fail with ECONNREFUSED through +// the real fetch, exercising the genuine fail-soft path (not a stubbed ok:false). +const DEAD_PROJECTOR = "http://127.0.0.1:1"; + +async function driveBoardWithDeadProjector() { + const dir = await mkdtemp(join(tmpdir(), "pm-link-degraded-")); + const feedFile = join(dir, "fleet-feed.json"); + await writeFile(feedFile, JSON.stringify(FEED)); + const projectsFile = join(dir, "kaneo-projects.json"); + await writeFile( + projectsFile, + JSON.stringify({ projects: [{ slug: "code", projectId: "p1", repository: "example-org/example-repo" }] }), + ); + const realFetch = globalThis.fetch; + globalThis.fetch = (async (input: unknown) => { + const url = String(input); + if (url.startsWith("http://127.0.0.1:1")) return realFetch(url); + const json = (body: unknown, headers: Record = {}) => + new Response(JSON.stringify(body), { status: 200, headers: { "Content-Type": "application/json", ...headers } }); + if (url.includes("/api/auth/sign-in/email")) return json({}, { "set-cookie": "session=test; Path=/" }); + if (url.includes("/api/workspace")) return json([{ id: "ws1" }]); + if (url.includes("/api/project?")) return json([{ id: "p1", slug: "code", name: "Code" }]); + if (url.includes("/api/task/tasks/")) + return json({ + data: { + columns: [ + { + id: "in-progress", + name: "In Progress", + tasks: [ + { + id: "t1", + number: 7, + title: "Work with links", + status: "in-progress", + externalLinks: [ + { + resourceType: "issue", + externalId: "42", + url: "https://github.com/example-org/example-repo/issues/42", + }, + ], + }, + ], + }, + ], + }, + pagination: { totalPages: 1 }, + }); + return new Response("not found", { status: 404 }); + }) as typeof fetch; + try { + const cfg = loadConfig({ + ...Bun.env, + PM_AGG_SOURCE: "live", + PM_AGG_FEED_FILE: feedFile, + PM_PROJECTOR_URL: DEAD_PROJECTOR, + PM_KANEO_PROJECTS_FILE: projectsFile, + KANEO_URL: "http://kaneo.test", + KANEO_ADMIN_EMAIL: "test@example.com", + KANEO_ADMIN_PASSWORD: "test-password", + }); + const src = liveSource(cfg); + const board = await src.board(); + return { board, provenance: src.provenance().board }; + } finally { + globalThis.fetch = realFetch; + } +} + +describe("board link degradation when the projector is unreachable (#8570)", () => { + test("board still serves the live Kaneo cards with degraded link provenance", async () => { + const { board, provenance } = await driveBoardWithDeadProjector(); + const kaneo = board.filter((b) => b.source === "kaneo"); + // The board is up: the dead projector took no card down with it. + expect(kaneo.map((b) => b.title)).toEqual(["Work with links"]); + // ... but the provenance chip is honest about the missing links. + expect(provenance).toContain("live (Kaneo"); + expect(provenance).toContain("projector links unavailable"); + expect(provenance).not.toContain("+ projector links;"); + }); + + test("projectorLinks reports a failed read as null, not an empty link list", async () => { + // A null read (registry unreachable) must stay distinguishable from + // a reachable registry that simply holds no links for the subject. + expect(await projectorLinks(DEAD_PROJECTOR, "kaneo:board-item")).toBeNull(); + }); + + test("projectorLinks still resolves a reachable registry's links", async () => { + const realFetch = globalThis.fetch; + globalThis.fetch = (async () => + new Response(JSON.stringify({ links: [{ ref: "example-org/example-repo#42", relation: "relates" }] }), { + status: 200, + headers: { "Content-Type": "application/json" }, + })) as unknown as typeof fetch; + try { + expect(await projectorLinks("http://projector", "kaneo:board-item")).toEqual([ + { ref: "example-org/example-repo#42", relation: "relates" }, + ]); + } finally { + globalThis.fetch = realFetch; + } + }); +}); diff --git a/pm-stack/aggregator/test/registry-ref-filter-6211.test.ts b/pm-stack/aggregator/test/registry-ref-filter-6211.test.ts index cb19eb471d..2f4d47cb91 100644 --- a/pm-stack/aggregator/test/registry-ref-filter-6211.test.ts +++ b/pm-stack/aggregator/test/registry-ref-filter-6211.test.ts @@ -59,18 +59,20 @@ const detail = Object.fromEntries( describe("projectorLinks ref filter (#6211)", () => { test("board subject: unsafe-integer registry ref dropped, good ref kept", async () => { - const links = await projectorLinks("http://projector", "kaneo:board-item"); + // #8570: projectorLinks is null only on a failed read; the stubbed + // registry answers, so the links resolve here. + const links = (await projectorLinks("http://projector", "kaneo:board-item")) ?? []; expect(links).toEqual([{ ref: GOOD, relation: "implements" }]); }); test("roadmap subject: non-GitHub-shaped and unsafe refs dropped, good ref kept", async () => { - const links = await projectorLinks("http://projector", "grist:roadmap-row"); + const links = (await projectorLinks("http://projector", "grist:roadmap-row")) ?? []; expect(links).toEqual([{ ref: GOOD, relation: "tracks" }]); }); test("/search renders a board item and roadmap row enriched from filtered registry links", async () => { - const boardLinks = await projectorLinks("http://projector", "kaneo:board-item"); - const roadmapLinks = await projectorLinks("http://projector", "grist:roadmap-row"); + const boardLinks = (await projectorLinks("http://projector", "kaneo:board-item")) ?? []; + const roadmapLinks = (await projectorLinks("http://projector", "grist:roadmap-row")) ?? []; const board: BoardItem[] = [ { id: "kaneo:pm-stack/task-6211",