Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion pm-stack/aggregator/src/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<RefKey, GhItem>): 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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -217,6 +242,7 @@ export interface HealthInputs {
feedFileMtimeMs: number | null;
diagnosis?: SectionDiagnosis;
detail?: ProvenanceDetail;
itemsCoverage?: ItemsCoverage | null;
comments?: PendingCommentCounts;
}

Expand Down Expand Up @@ -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 },
};
}
9 changes: 9 additions & 0 deletions pm-stack/aggregator/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand Down
16 changes: 15 additions & 1 deletion pm-stack/aggregator/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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; }
Expand Down Expand Up @@ -1333,10 +1334,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 `<a class="badge ${cls}" href="${esc(item.url)}" title="${esc(item.title)}">${kind} ${esc(item.ref)}${draft}</a>`;
const marker = unverified ? " · unverified" : "";
const title = unverified ? `${item.title} (unverified — fixture state, not live GitHub data)` : item.title;
return `<a class="badge ${cls}${unverified ? " unverified" : ""}" href="${esc(item.url)}" title="${esc(title)}">${kind} ${esc(item.ref)}${draft}${marker}</a>`;
}

function stripHtml(items: Map<RefKey, GhItem>, links: BoardItem["links"]): string {
Expand Down Expand Up @@ -4485,6 +4492,11 @@ export function renderHealth(view: HealthView, provenance: Provenance): string {
return `<tr><td><a href="${esc(p.route)}">${esc(p.title)}</a></td><td><code>${esc(p.route)}</code></td><td>${last}</td></tr>`;
})
.join("");
const cov = view.itemsCoverage;
const coverageLine =
cov && cov.total > 0
? `<strong>${cov.resolvedLive} of ${cov.total}</strong> board items resolved from live data (project pool / projector) · <strong>${cov.fixture}</strong> resolved from fixtures (rendered hollow + "unverified") · coverage ratio <strong>${cov.ratio !== null ? cov.ratio.toFixed(2) : "—"}</strong> — 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",
Expand Down Expand Up @@ -4518,6 +4530,8 @@ ${degraded}${modeNote}
<h2>Jobs</h2>
<div class="card"><strong>Orchestration pass</strong><br>${orchLine}</div>
<div class="card"><strong>Fleet-feed collector</strong><br>${collLine}</div>
<h2>Item resolution coverage</h2>
<div class="card">${coverageLine}</div>
<h2>Dashboard comments</h2>
<div class="card"><strong>${view.comments.pendingMessages} message${view.comments.pendingMessages === 1 ? "" : "s"} awaiting triage</strong> · <strong>${view.comments.pendingGithub} GitHub comment${view.comments.pendingGithub === 1 ? "" : "s"} awaiting posting</strong> · ${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)</div>
<h2>Source facets</h2>
Expand Down
7 changes: 6 additions & 1 deletion pm-stack/aggregator/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { CommentsStore, validateNewComment } from "./comments.ts";
import { loadConfig } from "./config.ts";
import { itemServiceLinks } from "./service-links.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 { watchdogTierItems, WATCHDOG_PROBE_SERVICE_IDS } from "./watchdog.ts";
import { PAGES } from "./pages.ts";
import { allRefs, buildAttention, deriveToday, projectPace, type RoadmapGrain } from "./derive.ts";
Expand Down Expand Up @@ -89,12 +89,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<void> | null = null;
async function ensureProvenancePrimed(): Promise<void> {
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(),
Expand Down Expand Up @@ -147,6 +151,7 @@ async function healthContext(prime = true): Promise<HealthView> {
feedFileMtimeMs,
diagnosis: source.diagnostics?.().orchestration,
detail: source.provenanceDetail?.(),
itemsCoverage: lastItemsCoverage,
comments: await commentsStore.pendingCounts().catch(() => undefined),
});
}
Expand Down
14 changes: 11 additions & 3 deletions pm-stack/aggregator/src/sources/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
type Comment,
type DnsSection,
type GhItem,
type ItemResolution,
type Link,
type OrchestrationSection,
type ProjectPoolItem,
Expand Down Expand Up @@ -708,7 +709,7 @@ export function liveSource(cfg: Config, opts?: { standingAuto?: () => Promise<bo
const byRef = new Map(pool.map((p) => [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));
Expand All @@ -719,8 +720,15 @@ export function liveSource(cfg: Config, opts?: { standingAuto?: () => Promise<bo
rest = await projectorItems(cfg.projector.baseUrl, remaining).catch(() => 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) {
Expand Down
163 changes: 163 additions & 0 deletions pm-stack/aggregator/test/items-resolution.test.ts
Original file line number Diff line number Diff line change
@@ -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<RefKey, GhItem>([
["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<RefKey, GhItem>([
["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");
});
});
Loading