diff --git a/pm-stack/aggregator/src/model.ts b/pm-stack/aggregator/src/model.ts index a26c795a72..33feaaa557 100644 --- a/pm-stack/aggregator/src/model.ts +++ b/pm-stack/aggregator/src/model.ts @@ -500,6 +500,30 @@ export function parseRef(key: RefKey): GhRef { * number. Boundary validators and store-load gates route through this * instead of re-checking the shape with a local regex whose \d+ group * admits numbers parseRef (and refUrl) then throw on. */ +/** + * The ref contract (#6242, closing inventory #6243) — the disposition + * rules that live beside the validity rule above: + * 1. One validity rule: isValidRef is the only ref-validity test in + * the aggregator and the projector. No local regex or shape check + * re-derives it. parseRef keeps throwing: it is the internal + * assertion behind the typed RefKey promise for refs the code + * constructs itself. + * 2. Drop the ref, keep the item (stored / feed data): at the + * consumption step beside each gate, a ref field or edge that + * fails isValidRef is removed and the element survives without + * it. Direct user POSTs whose ref is the subject (comments / + * actions) keep the #4952 reject behaviour instead. + * 3. Producers mint only valid refs: every scrape or derivation + * that creates a ref routes candidates through isValidRef; a raw + * ref scrape that skips the filter is a defect per se. + * 4. Rendering and deriving never throw on a ref: stored/feed refs + * reach refUrl only through a safe-link treatment — valid -> + * anchor, invalid -> plain text (visible, never silently gone); + * derive paths treat an invalid edge as absent. + * 5. Drops are observable: every rule-2/3 drop leaves a trace (a log + * line or a provenance/count note at the consuming source). + * The per-site closing inventory against these rules is recorded on + * issue #6243 (Phase 4 of #6242). */ export function isValidRef(value: unknown): value is RefKey { if (typeof value !== "string") return false; try { diff --git a/pm-stack/aggregator/src/render.ts b/pm-stack/aggregator/src/render.ts index 09e9bc20bd..b8dd38ae00 100644 --- a/pm-stack/aggregator/src/render.ts +++ b/pm-stack/aggregator/src/render.ts @@ -1934,14 +1934,13 @@ export function sessionRecordLine( const parent = r.parentId ? ` · sub of ${esc(r.parentId)}` : ""; - const renderedRefs = r.taskRefs.flatMap((ref) => { - try { - return [`${esc(ref)}`]; - } catch { - // A malformed ref may still exist in an older or ungated in-memory - // record. Keep the session visible and omit only the invalid link. - return []; - } + const renderedRefs = r.taskRefs.map((ref) => { + // #6243 (ref contract rule 4, #6242): a malformed ref may still + // exist in an older or ungated in-memory record. Keep the session + // visible and render the invalid ref as plain text — the same + // treatment tierItemCard (#6149) and poolRefLink give it — never + // a throw, and never silently omitted. + return isValidRef(ref) ? `${esc(ref)}` : esc(ref); }); const refs = renderedRefs.length ? ` · ${renderedRefs.join(" ")}` : ""; // #1156: live records carry the session action set on the merged diff --git a/pm-stack/aggregator/test/ref-contract-6243.test.ts b/pm-stack/aggregator/test/ref-contract-6243.test.ts new file mode 100644 index 0000000000..de94b07d85 --- /dev/null +++ b/pm-stack/aggregator/test/ref-contract-6243.test.ts @@ -0,0 +1,66 @@ +// Ref contract Phase 4 (#6243, contract #6242): closing pinning tests. +// - sessionRecordLine alignment (required disposition 5): an invalid +// stored ref now renders as plain text (the rule-4 treatment), where +// it previously was silently omitted by a try/catch; a valid ref is +// the unchanged anchor control. Probe forms: unsafe-integer and +// non-GitHub shapes, per the phase acceptance. +// - The internal assertion stays: parseRef/refUrl still throw on a +// ref the code constructs wrongly (contract rule 1) — the safe +// treatment lives at the stored/feed boundary, not in parseRef. +// Run: bun test test/ref-contract-6243.test.ts +import { describe, expect, test } from "bun:test"; +import { isValidRef, parseRef, refUrl, type RefKey, type SessionRecord } from "../src/model.ts"; +import { sessionRecordLine } from "../src/render.ts"; + +function rec(taskRefs: string[]): SessionRecord { + return { + id: "ses_phase4", + source: "claude-code", + label: "Phase 4 probe", + agentId: "claude-code", + agentLabel: "Muse", + parentId: null, + status: "succeeded", + startedAt: "2026-11-08T00:00:00Z", + lastSeenAt: "2026-11-08T01:00:00Z", + taskRefs: taskRefs as RefKey[], + } as SessionRecord; +} + +const GOOD = "developing-today/code#6243"; +const BAD_UNSAFE = "developing-today/code#99999999999999999999"; +const BAD_SHAPE = "goal:keep-the-four-repos-healthy"; + +describe("sessionRecordLine renders invalid stored refs as plain text (#6243)", () => { + test("unsafe-integer ref: no throw, ref visible as plain text, no anchor", () => { + const html = sessionRecordLine(rec([BAD_UNSAFE])); + expect(html).toContain(BAD_UNSAFE); + expect(html).not.toContain(`href="https://github.com/developing-today/code/issues/99999999999999999999"`); + }); + test("non-GitHub ref: no throw, ref visible as plain text", () => { + const html = sessionRecordLine(rec([BAD_SHAPE])); + expect(html).toContain(BAD_SHAPE); + expect(html).not.toContain(" { + const html = sessionRecordLine(rec([GOOD])); + expect(html).toContain(`${GOOD}`); + }); + test("mixed refs: valid anchors, invalid is plain text, session survives", () => { + const html = sessionRecordLine(rec([GOOD, BAD_UNSAFE])); + expect(html).toContain(`${GOOD}`); + expect(html).toContain(BAD_UNSAFE); + }); +}); + +describe("the internal ref assertion stays total-checked (#6242 rule 1)", () => { + test("isValidRef is the shared rule", () => { + expect(isValidRef(GOOD)).toBe(true); + expect(isValidRef(BAD_UNSAFE)).toBe(false); + expect(isValidRef(BAD_SHAPE)).toBe(false); + }); + test("parseRef and refUrl still throw on invalid refs", () => { + expect(() => parseRef(BAD_UNSAFE as RefKey)).toThrow(); + expect(() => refUrl(BAD_SHAPE as RefKey)).toThrow(); + }); +});