From 7b61e9b045718946fb8f2f36ac19bd3af2f0420e Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2026 11:29:28 -0600 Subject: [PATCH] fix(pm-aggregator): tolerate invalid in-flight refs --- pm-stack/aggregator/src/sources/live.ts | 12 ++- .../aggregator/test/board-in-flight.test.ts | 92 ++++++++++++++++++- 2 files changed, 100 insertions(+), 4 deletions(-) diff --git a/pm-stack/aggregator/src/sources/live.ts b/pm-stack/aggregator/src/sources/live.ts index 816dba144f..b3aa2dea20 100644 --- a/pm-stack/aggregator/src/sources/live.ts +++ b/pm-stack/aggregator/src/sources/live.ts @@ -613,6 +613,8 @@ const normTitle = (s: string): string => * - repeats inside the section itself (the same task lined up under * two goals, or twice under one) emit once, keyed by first ref, * else by normalized title. + * Only parseRef-accepted refs participate; invalid candidates are logged + * and otherwise behave as absent. * Tasks with no ref anywhere still emit (title only, no GitHub link). */ export function inFlightBoardItems(section: OrchestrationSection, existing: BoardItem[]): BoardItem[] { @@ -628,10 +630,16 @@ export function inFlightBoardItems(section: OrchestrationSection, existing: Boar if (item.linedUpStatus !== "in-progress" && item.linedUpStatus !== "queued" && item.linedUpStatus !== "blocked") continue; const refs: RefKey[] = []; - const add = (ref: RefKey) => { + const add = (ref: unknown) => { + if (!isValidRef(ref)) { + console.error( + `[board] WARNING: dropping invalid in-flight ref ${JSON.stringify(ref)} for task ${item.id}`, + ); + return; + } if (!refs.includes(ref)) refs.push(ref); }; - if (item.ref) add(item.ref); + if (item.ref !== undefined && item.ref !== null && item.ref !== "") add(item.ref); for (const ref of titleRefs(item.title)) add(ref); const remainingRefs = refs.filter((ref) => !existingRefs.has(ref)); if (refs.length > 0 && remainingRefs.length === 0) continue; diff --git a/pm-stack/aggregator/test/board-in-flight.test.ts b/pm-stack/aggregator/test/board-in-flight.test.ts index 2e85aacd2d..64e006866f 100644 --- a/pm-stack/aggregator/test/board-in-flight.test.ts +++ b/pm-stack/aggregator/test/board-in-flight.test.ts @@ -1,5 +1,5 @@ -import { describe, expect, test } from "bun:test"; -import type { BoardItem, GhItem, OrchestrationSection, Provenance } from "../src/model.ts"; +import { describe, expect, spyOn, test } from "bun:test"; +import type { BoardItem, GhItem, OrchestrationSection, Provenance, RefKey } from "../src/model.ts"; import { renderBoard } from "../src/render.ts"; import { inFlightBoardItems, titleRefs } from "../src/sources/live.ts"; @@ -130,6 +130,94 @@ describe("inFlightBoardItems", () => { ); expect(out).toHaveLength(1); expect(out[0].links).toEqual([{ ref: "developing-today/code#958", relation: "tracks" }]); + expect(out[0].repo).toBe("developing-today/code"); + }); + + test("a goal-id ref is dropped and the task remains title-only with a trace", () => { + const trace = spyOn(console, "error").mockImplementation(() => {}); + try { + const out = inFlightBoardItems( + section([task("Goal-level planning", "in-progress", { ref: "goal_a243772844c3" as RefKey })]), + [], + ); + + expect(out).toHaveLength(1); + expect(out[0].repo).toBe(""); + expect(out[0].links).toEqual([]); + expect(trace).toHaveBeenCalledWith(expect.stringContaining("dropping invalid in-flight ref")); + } finally { + trace.mockRestore(); + } + }); + + test("a non-string ref is dropped and the task remains title-only", () => { + const trace = spyOn(console, "error").mockImplementation(() => {}); + try { + const out = inFlightBoardItems( + section([task("Numeric external ref", "queued", { ref: 12345 as unknown as RefKey })]), + [], + ); + + expect(out).toHaveLength(1); + expect(out[0].repo).toBe(""); + expect(out[0].links).toEqual([]); + expect(trace).toHaveBeenCalledWith(expect.stringContaining("dropping invalid in-flight ref")); + } finally { + trace.mockRestore(); + } + }); + + test("a bare-number ref is dropped and the task remains title-only", () => { + const trace = spyOn(console, "error").mockImplementation(() => {}); + try { + const out = inFlightBoardItems( + section([task("Bare-number external ref", "queued", { ref: "812" as RefKey })]), + [], + ); + + expect(out).toHaveLength(1); + expect(out[0].repo).toBe(""); + expect(out[0].links).toEqual([]); + expect(trace).toHaveBeenCalledWith(expect.stringContaining("dropping invalid in-flight ref")); + } finally { + trace.mockRestore(); + } + }); + + test("an unsafe title-derived GitHub number is dropped", () => { + const trace = spyOn(console, "error").mockImplementation(() => {}); + try { + const out = inFlightBoardItems(section([task("code #9007199254740992 needs follow-up", "queued")]), []); + + expect(out).toHaveLength(1); + expect(out[0].repo).toBe(""); + expect(out[0].links).toEqual([]); + expect(trace).toHaveBeenCalledWith(expect.stringContaining("dropping invalid in-flight ref")); + } finally { + trace.mockRestore(); + } + }); + + test("a poisoned ref does not hide healthy tasks in the same lane", () => { + const trace = spyOn(console, "error").mockImplementation(() => {}); + try { + const out = inFlightBoardItems( + section([ + task("Healthy linked work", "in-progress", { ref: "developing-today/code#958" }), + task("Poisoned title-only work", "queued", { ref: "goal_a243772844c3" as RefKey }), + ]), + [], + ); + + expect(out.map((item) => item.title)).toEqual(["Healthy linked work", "Poisoned title-only work"]); + expect(out[0].repo).toBe("developing-today/code"); + expect(out[0].links).toEqual([{ ref: "developing-today/code#958", relation: "tracks" }]); + expect(out[1].repo).toBe(""); + expect(out[1].links).toEqual([]); + expect(trace).toHaveBeenCalledWith(expect.stringContaining("dropping invalid in-flight ref")); + } finally { + trace.mockRestore(); + } }); test("dedupes matched refs and ref-less title matches against Kaneo cards", () => {