From 263a3b271503d6ceecaab7dc73b5175c6c189365 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Thu, 29 Oct 2026 15:54:44 -0500 Subject: [PATCH] =?UTF-8?q?feat(aggregator):=20per-item=20resolution=20sou?= =?UTF-8?q?rce=20=E2=80=94=20fixture=20badges=20render=20unverified,=20hea?= =?UTF-8?q?lth=20publishes=20coverage=20ratio=20(#1141)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pm-stack/aggregator/src/health.ts | 29 +++- pm-stack/aggregator/src/model.ts | 9 + pm-stack/aggregator/src/render.ts | 16 +- pm-stack/aggregator/src/server.ts | 7 +- pm-stack/aggregator/src/sources/live.ts | 14 +- .../aggregator/test/items-resolution.test.ts | 163 ++++++++++++++++++ 6 files changed, 232 insertions(+), 6 deletions(-) create mode 100644 pm-stack/aggregator/test/items-resolution.test.ts diff --git a/pm-stack/aggregator/src/health.ts b/pm-stack/aggregator/src/health.ts index 70edc9e5d0..78a1f95b15 100644 --- a/pm-stack/aggregator/src/health.ts +++ b/pm-stack/aggregator/src/health.ts @@ -19,7 +19,7 @@ import type { PendingCommentCounts } from "./comments.ts"; import type { Config } from "./config.ts"; import { ageMsText, GENERATED_AT_FUTURE_SKEW_MS, type FleetFeed, type SectionDiagnosis } from "./feed.ts"; -import type { ProvenanceDetail } from "./model.ts"; +import type { GhItem, ProvenanceDetail, RefKey } from "./model.ts"; import { PAGES } from "./pages.ts"; import { buildServices, type ServiceDef } from "./topology.ts"; @@ -118,6 +118,29 @@ export interface PageHealth { ageMs: number | null; } +/** Item resolution coverage (#1141): of the items one resolution pass + * served, how many came from live data (project pool + projector) and + * how many from fixtures. Untagged items (the source did not say) are + * counted in neither bucket — health never invents a source. */ +export interface ItemsCoverage { + resolvedLive: number; + fixture: number; + total: number; + /** resolvedLive / total; null when nothing tagged was resolved. */ + ratio: number | null; +} + +export function summarizeItemCoverage(items: Map): ItemsCoverage { + let resolvedLive = 0; + let fixture = 0; + for (const item of items.values()) { + if (item.resolution === "fixture") fixture++; + else if (item.resolution === "pool" || item.resolution === "projector") resolvedLive++; + } + const total = resolvedLive + fixture; + return { resolvedLive, fixture, total, ratio: total ? resolvedLive / total : null }; +} + export interface HealthView { /** The aggregator process itself is up if it assembled this view. */ status: "ok"; @@ -145,6 +168,8 @@ export interface HealthView { }; pages: PageHealth[]; facets: ProvenanceDetail | null; + /** #1141: resolved-live vs fixture counts from the priming pass. */ + itemsCoverage: ItemsCoverage | null; /** Dashboard comment loops (#1145): pending triage/posting counts, * so an unworked comment queue is visible on /health. */ comments: PendingCommentCounts; @@ -217,6 +242,7 @@ export interface HealthInputs { feedFileMtimeMs: number | null; diagnosis?: SectionDiagnosis; detail?: ProvenanceDetail; + itemsCoverage?: ItemsCoverage | null; comments?: PendingCommentCounts; } @@ -350,6 +376,7 @@ export async function buildHealth(inputs: HealthInputs, deps: HealthDeps = {}): }, pages: pageHealth(now), facets: inputs.detail ?? null, + itemsCoverage: inputs.itemsCoverage ?? null, comments: inputs.comments ?? { pendingMessages: 0, pendingGithub: 0, total: 0 }, }; } diff --git a/pm-stack/aggregator/src/model.ts b/pm-stack/aggregator/src/model.ts index 15a480d089..d822362169 100644 --- a/pm-stack/aggregator/src/model.ts +++ b/pm-stack/aggregator/src/model.ts @@ -25,6 +25,11 @@ export type GhKind = "issue" | "pr"; export type GhState = "open" | "closed" | "merged"; /** Live state of one GitHub issue or PR, as the projector projects it. */ +/** Per-item resolution source (#1141): which tier of Source.items() + * produced a GhItem. "pool" and "projector" are live data; "fixture" + * is invented fallback state and must never render as if it were live. */ +export type ItemResolution = "pool" | "projector" | "fixture"; + export interface GhItem { ref: RefKey; kind: GhKind; @@ -42,6 +47,10 @@ export interface GhItem { projectArea?: string | null; projectHorizon?: string | null; projectKind?: string | null; + /** How this item was resolved (#1141). Absent = the source did not + * say (e.g. whole-source fixtures mode, whose provenance already + * reports fixtures for every facet). */ + resolution?: ItemResolution; } /** diff --git a/pm-stack/aggregator/src/render.ts b/pm-stack/aggregator/src/render.ts index cfee5d640e..e578bb9784 100644 --- a/pm-stack/aggregator/src/render.ts +++ b/pm-stack/aggregator/src/render.ts @@ -121,6 +121,7 @@ a { color: #58a6ff; } .badge.near { background: #d2992233; border-color: #d29922; color: #e3b341; } .badge.walled { background: #f8514933; border-color: #f85149; color: #f85149; } .badge.src { background: #21262d; color: #e6edf3; } +.badge.unverified { background: transparent; border-style: dashed; opacity: 0.75; } .badge.drew { background: #f8514933; border-color: #f85149; color: #f85149; } .badge.orch { background: #1f6feb33; border-color: #1f6feb; color: #58a6ff; } .badge.moving { background: #2ea04333; border-color: #2ea043; color: #3fb950; } @@ -1324,10 +1325,16 @@ export function coverageHtml(coverage: SourceCoverage[]): string { } function itemBadge(item: GhItem): string { + // #1141: fixture-resolved state is invented fallback data — render it + // hollow (dashed, transparent) and named "unverified" so it can never + // be mistaken for a live badge on board/roadmap/item/program pages. + const unverified = item.resolution === "fixture"; const cls = item.state === "merged" ? "merged" : item.state === "open" ? "open" : "closed"; const kind = item.kind === "pr" ? (item.state === "merged" ? "PR merged" : "PR") : "issue"; const draft = item.draft ? " · draft" : ""; - return `${kind} ${esc(item.ref)}${draft}`; + const marker = unverified ? " · unverified" : ""; + const title = unverified ? `${item.title} (unverified — fixture state, not live GitHub data)` : item.title; + return `${kind} ${esc(item.ref)}${draft}${marker}`; } function stripHtml(items: Map, links: BoardItem["links"]): string { @@ -4463,6 +4470,11 @@ export function renderHealth(view: HealthView, provenance: Provenance): string { return `${esc(p.title)}${esc(p.route)}${last}`; }) .join(""); + const cov = view.itemsCoverage; + const coverageLine = + cov && cov.total > 0 + ? `${cov.resolvedLive} of ${cov.total} board items resolved from live data (project pool / projector) · ${cov.fixture} resolved from fixtures (rendered hollow + "unverified") · coverage ratio ${cov.ratio !== null ? cov.ratio.toFixed(2) : "—"} — measured on the health prime's board resolution pass, the same pass that sets the items facet provenance (#1141).` + : `not measured yet — coverage is computed on the health prime's board resolution pass (#1267); a pass that resolved no tagged items reports nothing rather than inventing a ratio.`; const facets = view.facets ? freshnessChips(view.facets, [ "board", @@ -4496,6 +4508,8 @@ ${degraded}${modeNote}

Jobs

Orchestration pass
${orchLine}
Fleet-feed collector
${collLine}
+

Item resolution coverage

+
${coverageLine}

Dashboard comments

${view.comments.pendingMessages} message${view.comments.pendingMessages === 1 ? "" : "s"} awaiting triage · ${view.comments.pendingGithub} GitHub comment${view.comments.pendingGithub === 1 ? "" : "s"} awaiting posting · ${view.comments.total} comment${view.comments.total === 1 ? "" : "s"} in the store (#1145 \u2014 a pending count that never drains means the triage/poster loop is not running)

Source facets

diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index 5234368fe9..b6a5406349 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -12,7 +12,7 @@ import { checkActionAgainstItem, effectiveNeedsOrder, effectiveStandingAuto, fin import { CommentsStore, validateNewComment } from "./comments.ts"; import { loadConfig } from "./config.ts"; import { loadFeed } from "./feed.ts"; -import { buildHealth, recordRender, type HealthView } from "./health.ts"; +import { buildHealth, recordRender, summarizeItemCoverage, type HealthView, type ItemsCoverage } from "./health.ts"; import { PAGES } from "./pages.ts"; import { allRefs, buildAttention, deriveToday, projectPace, type RoadmapGrain } from "./derive.ts"; import type { DashComment, RefKey } from "./model.ts"; @@ -87,12 +87,16 @@ const source = pickSource(); * which is precisely what health exists to report. */ let lastPrimedAt = 0; +/** #1141: item coverage measured by the latest priming pass (below), + * from the same board items() resolution that sets facet provenance. */ +let lastItemsCoverage: ItemsCoverage | null = null; let priming: Promise | null = null; async function ensureProvenancePrimed(): Promise { if (Date.now() - lastPrimedAt < 60_000) return; priming ??= (async () => { try { const { items } = await boardContext(); + lastItemsCoverage = summarizeItemCoverage(items); const refs = [...items.keys()]; await Promise.allSettled([ source.roadmap(), @@ -138,6 +142,7 @@ async function healthContext(): Promise { feedFileMtimeMs, diagnosis: source.diagnostics?.().orchestration, detail: source.provenanceDetail?.(), + itemsCoverage: lastItemsCoverage, comments: await commentsStore.pendingCounts().catch(() => undefined), }); } diff --git a/pm-stack/aggregator/src/sources/live.ts b/pm-stack/aggregator/src/sources/live.ts index ae9bbd44db..e4d1cd80e7 100644 --- a/pm-stack/aggregator/src/sources/live.ts +++ b/pm-stack/aggregator/src/sources/live.ts @@ -34,6 +34,7 @@ import { type Comment, type DnsSection, type GhItem, + type ItemResolution, type Link, type OrchestrationSection, type ProjectPoolItem, @@ -705,7 +706,7 @@ export function liveSource(cfg: Config, opts?: { standingAuto?: () => Promise [p.ref, p] as const)); for (const ref of refs) { const p = byRef.get(ref); - if (p) out.set(ref, poolItemToGhItem(p)); + if (p) out.set(ref, { ...poolItemToGhItem(p), resolution: "pool" }); } } const remaining = refs.filter((r) => !out.has(r)); @@ -716,8 +717,15 @@ export function liveSource(cfg: Config, opts?: { standingAuto?: () => Promise null); if (rest && rest.size > 0) projectorServed = true; } - if (!rest || rest.size === 0) rest = await fix.items(remaining); - for (const [k, v] of rest) out.set(k, v); + // #1141: every served item carries its resolution source, so + // fixture state can render as unverified and health can publish + // the live-vs-fixture coverage ratio from the same pass. + let restSource: ItemResolution = "projector"; + if (!rest || rest.size === 0) { + rest = await fix.items(remaining); + restSource = "fixture"; + } + for (const [k, v] of rest) out.set(k, { ...v, resolution: restSource }); } const poolServed = refs.length - remaining.length; if (poolServed > 0 && feed) { diff --git a/pm-stack/aggregator/test/items-resolution.test.ts b/pm-stack/aggregator/test/items-resolution.test.ts new file mode 100644 index 0000000000..904aa4c17d --- /dev/null +++ b/pm-stack/aggregator/test/items-resolution.test.ts @@ -0,0 +1,163 @@ +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 { summarizeItemCoverage } from "../src/health.ts"; +import type { GhItem, Provenance, RefKey } from "../src/model.ts"; +import { parseProjectItems } from "../src/projects.ts"; +import { renderItem } from "../src/render.ts"; +import { liveSource } from "../src/sources/live.ts"; + +// #1141: every item Source.items() serves carries its resolution source +// (pool | projector | fixture); fixture-resolved items render hollow + +// "unverified"; health publishes the live-vs-fixture coverage ratio +// computed from the same resolution pass. + +const GQL = { + data: { + node: { + title: "Developing Today", + number: 4, + url: "https://github.com/orgs/developing-today/projects/4", + items: { + totalCount: 1, + pageInfo: { hasNextPage: false, endCursor: null }, + nodes: [ + { + id: "PVTI_1", + databaseId: 111, + type: "ISSUE", + content: { + number: 508, + title: "EPIC: Basement cluster", + state: "OPEN", + url: "https://github.com/dezren39/nix/issues/508", + repository: { nameWithOwner: "dezren39/nix" }, + updatedAt: "2026-10-20T12:05:58Z", + author: { login: "dezren39" }, + }, + fieldValues: { nodes: [{ name: "In Progress", field: { name: "Status" } }] }, + }, + ], + }, + }, + }, +}; + +async function liveCfg(projectorUrl: string, withPool: boolean) { + const dir = await mkdtemp(join(tmpdir(), "pm-res-")); + const feedFile = join(dir, "fleet-feed.json"); + await writeFile( + feedFile, + JSON.stringify({ + version: 1, + generatedAt: new Date().toISOString(), + quota: { pools: [], burn: [], choices: { hasHeadroom: [], burnBeforeReset: [], doNotStart: [] } }, + attention: [], + projects: withPool ? parseProjectItems(GQL) : [], + }), + ); + return loadConfig({ PM_AGG_SOURCE: "live", PM_AGG_FEED_FILE: feedFile, PM_PROJECTOR_URL: projectorUrl }); +} + +const gh = (ref: RefKey, resolution?: GhItem["resolution"]): GhItem => ({ + ref, + kind: "issue", + url: `https://github.com/${ref.replace("#", "/issues/")}`, + title: `Item ${ref}`, + state: "open", + labels: [], + author: "dezren39", + updatedAt: "2026-10-29T00:00:00Z", + ...(resolution ? { resolution } : {}), +}); + +describe("items() resolution tagging (#1141)", () => { + test("pool refs tag pool; refs outside the pool fall back to fixtures and tag fixture", async () => { + const src = liveSource(await liveCfg("off", true)); + const items = await src.items(["dezren39/nix#508", "developing-today/code#752", "developing-today/code#999999"]); + expect(items.get("dezren39/nix#508")?.resolution).toBe("pool"); + // developing-today/code#752 exists only in the fixture data. + expect(items.get("developing-today/code#752")?.resolution).toBe("fixture"); + expect(items.has("developing-today/code#999999")).toBe(false); + }); + + test("projector-served refs tag projector", async () => { + const row = { + ref: "dezren39/nix#501", + repo: "dezren39/nix", + number: 501, + kind: "issue", + url: "https://github.com/dezren39/nix/issues/501", + title: "Basement cluster", + state: "open", + state_reason: null, + draft: 0, + merged: 0, + author: "dezren39", + labels: "[]", + assignees: "[]", + created_at: "2026-10-24T11:00:00Z", + updated_at: "2026-10-24T13:40:00Z", + closed_at: null, + merged_at: null, + }; + const server = Bun.serve({ + port: 0, + fetch: () => Response.json({ items: [row] }), + }); + try { + const src = liveSource(await liveCfg(`http://127.0.0.1:${server.port}`, false)); + const items = await src.items(["dezren39/nix#501"]); + expect(items.get("dezren39/nix#501")?.resolution).toBe("projector"); + } finally { + server.stop(true); + } + }); +}); + +describe("summarizeItemCoverage (#1141)", () => { + test("counts live vs fixture, ignores untagged, ratio is the live share", () => { + const items = new Map([ + ["a/b#1", gh("a/b#1", "pool")], + ["a/b#2", gh("a/b#2", "projector")], + ["a/b#3", gh("a/b#3", "fixture")], + ["a/b#4", gh("a/b#4")], + ]); + const cov = summarizeItemCoverage(items); + expect(cov.resolvedLive).toBe(2); + expect(cov.fixture).toBe(1); + expect(cov.total).toBe(3); + expect(cov.ratio).toBeCloseTo(2 / 3); + }); + + test("empty pass reports total 0 and a null ratio — never an invented number", () => { + const cov = summarizeItemCoverage(new Map()); + expect(cov.total).toBe(0); + expect(cov.ratio).toBeNull(); + }); +}); + +describe("fixture-resolved badges render unverified (#1141)", () => { + const PROV = { + board: "x", roadmap: "x", items: "x", comments: "x", quota: "x", usage: "x", + attention: "x", orchestration: "x", dns: "x", registry: "x", aa: "x", + } as Provenance; + + test("item page: fixture badge is hollow + named unverified; pool badge is untouched", () => { + const items = new Map([ + ["developing-today/code#752", gh("developing-today/code#752", "fixture")], + ["dezren39/nix#508", gh("dezren39/nix#508", "pool")], + ]); + const links = [ + { ref: "developing-today/code#752", relation: "tracks" as const }, + { ref: "dezren39/nix#508", relation: "tracks" as const }, + ]; + const html = renderItem("Subject", "subj", links, [], items, [], PROV); + expect(html).toContain("badge open unverified"); + expect(html).toContain("developing-today/code#752 · unverified"); + expect(html).toContain("unverified — fixture state, not live GitHub data"); + expect(html).not.toContain("dezren39/nix#508 · unverified"); + }); +});