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
21 changes: 16 additions & 5 deletions pm-stack/aggregator/src/brief.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// as unknown.

import type { Comment, GhState, OrchestrationSection, ProjectPoolItem, RefKey } from "./model.ts";
import { refUrl } from "./model.ts";
import { isValidRef, refUrl } from "./model.ts";
import { derivedProjectState, projectDisagreement, type DerivedProjectState } from "./projects.ts";

export interface BriefEvidence {
Expand Down Expand Up @@ -89,7 +89,8 @@ function buildItemBriefWithIndexes(
// as blocking while it is open — or while its state is unknown (absent
// from the pool): an unknown blocker is stated as unknown, not assumed
// resolved.
const blockers = (item.blockedBy ?? []).map((ref) => {
const rawBlockers = item.blockedBy ?? [];
const blockers = rawBlockers.filter(isValidRef).map((ref) => {
const target = byRef.get(ref);
return {
ref,
Expand All @@ -99,13 +100,18 @@ function buildItemBriefWithIndexes(
});
const activeBlockers = blockers.filter((b) => b.state === "open" || b.state === "unknown");
const blocked = activeBlockers.length > 0;
const invalidBlockerCount = rawBlockers.length - blockers.length;
const blockerText = !blockers.length
? "Not blocked — no “blocked by” edges in the projection."
? invalidBlockerCount
? `Unknown — ${invalidBlockerCount} malformed “blocked by” edge${invalidBlockerCount === 1 ? " was" : "s were"} omitted from the projection.`
: "Not blocked — no “blocked by” edges in the projection."
: blocked
? `Blocked by ${activeBlockers
.map((b) => `${b.ref}${b.state === "unknown" ? " (state unknown — not in the current pool)" : ""}`)
.join(", ")}.`
: `Not blocked — every recorded blocker (${blockers.map((b) => b.ref).join(", ")}) is closed or merged.`;
.join(", ")}.${invalidBlockerCount ? ` ${invalidBlockerCount} malformed edge${invalidBlockerCount === 1 ? " was" : "s were"} omitted.` : ""}`
: invalidBlockerCount
? `Unknown — valid blockers (${blockers.map((b) => b.ref).join(", ")}) are closed or merged, but ${invalidBlockerCount} malformed edge${invalidBlockerCount === 1 ? " was" : "s were"} omitted.`
: `Not blocked — every recorded blocker (${blockers.map((b) => b.ref).join(", ")}) is closed or merged.`;
const blockerEvidence: BriefEvidence = blocked
? { text: activeBlockers[0].ref, url: activeBlockers[0].url }
: itemEvidence;
Expand Down Expand Up @@ -153,6 +159,11 @@ function buildItemBriefWithIndexes(
text: `Resolve the blocker first: ${activeBlockers[0].ref}.`,
evidence: { text: activeBlockers[0].ref, url: activeBlockers[0].url },
};
} else if (invalidBlockerCount) {
nextAction = {
text: `Validate ${invalidBlockerCount} malformed “blocked by” edge${invalidBlockerCount === 1 ? "" : "s"} before treating this item as unblocked.`,
evidence: itemEvidence,
};
} else if (disagreement) {
nextAction = {
text: `Reconcile the disagreement: Project Status “${disagreement.project}” vs derived “${disagreement.derived}”.`,
Expand Down
23 changes: 14 additions & 9 deletions pm-stack/aggregator/src/epic-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// hold, is "unavailable" — never an empty success.

import type { ProjectPoolItem, RefKey } from "./model.ts";
import { isValidRef } from "./model.ts";
import { buildEpicRollups } from "./epics.ts";
import { effortWeight, modeOf } from "./weights.ts";

Expand Down Expand Up @@ -257,9 +258,9 @@ export function epicGraph(
const externalRefs = new Set<RefKey>();
const collectRefs = (item: ProjectPoolItem) => {
const targets = [
...(item.parentRef !== undefined ? [item.parentRef] : []),
...(item.blockedBy ?? []),
...(item.blocks ?? []),
...(isValidRef(item.parentRef) ? [item.parentRef] : []),
...(item.blockedBy ?? []).filter(isValidRef),
...(item.blocks ?? []).filter(isValidRef),
];
for (const target of targets) {
if (memberSet.has(target)) continue;
Expand Down Expand Up @@ -298,9 +299,13 @@ export function epicGraph(
};
for (const { item } of shown) {
if (!item) continue;
if (item.parentRef !== undefined) addEdge(item.parentRef, item.ref, "hierarchy");
for (const blocker of item.blockedBy ?? []) addEdge(item.ref, blocker, "dependency");
for (const blocked of item.blocks ?? []) addEdge(blocked, item.ref, "dependency");
if (isValidRef(item.parentRef)) addEdge(item.parentRef, item.ref, "hierarchy");
for (const blocker of item.blockedBy ?? []) {
if (isValidRef(blocker)) addEdge(item.ref, blocker, "dependency");
}
for (const blocked of item.blocks ?? []) {
if (isValidRef(blocked)) addEdge(blocked, item.ref, "dependency");
}
}

// Hierarchy layout, same discipline as depthLayout: DFS from roots
Expand Down Expand Up @@ -332,7 +337,7 @@ export function epicGraph(
// Summaries cover the FULL member set, before the node cap: a member
// hidden by the cap is still blocked, still counted, still ranked.
const unresolvedBlockersOf = (item: ProjectPoolItem): RefKey[] =>
(item.blockedBy ?? []).filter((b) => {
(item.blockedBy ?? []).filter(isValidRef).filter((b) => {
const blocker = byRef.get(b);
return blocker === undefined || blocker.state === "open";
});
Expand Down Expand Up @@ -427,8 +432,8 @@ export function epicGraph(
unresolved: false,
epic: item.kind === "Epic",
mode: modeOf(item.labels),
blockers: [...(item.blockedBy ?? [])],
dependents: [...(item.blocks ?? [])],
blockers: (item.blockedBy ?? []).filter(isValidRef),
dependents: (item.blocks ?? []).filter(isValidRef),
depth: pos.depth,
row: pos.row,
};
Expand Down
4 changes: 3 additions & 1 deletion pm-stack/aggregator/src/epics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ProjectPoolItem, RefKey } from "./model.ts";
import { isValidRef } from "./model.ts";

export interface EpicRollup {
/** Resolved pool items whose epicRef points at this epic. */
Expand All @@ -24,7 +25,7 @@ export function buildEpicRollups(pool: readonly ProjectPoolItem[]): Map<RefKey,
const byRef = new Map(pool.map((item) => [item.ref, item]));
const childrenByEpic = new Map<RefKey, ProjectPoolItem[]>();
for (const item of pool) {
if (!item.epicRef) continue;
if (!isValidRef(item.epicRef)) continue;
const children = childrenByEpic.get(item.epicRef) ?? [];
children.push(item);
childrenByEpic.set(item.epicRef, children);
Expand All @@ -44,6 +45,7 @@ export function buildEpicRollups(pool: readonly ProjectPoolItem[]): Map<RefKey,
if (
child.state === "open" &&
(child.blockedBy ?? []).some((ref) => {
if (!isValidRef(ref)) return false;
const blocker = byRef.get(ref);
return blocker === undefined || blocker.state === "open";
})
Expand Down
15 changes: 8 additions & 7 deletions pm-stack/aggregator/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
// chart or a fake zero.

import type { ProjectPoolItem, RefKey } from "./model.ts";
import { isValidRef } from "./model.ts";
import { effortWeight, modeOf } from "./weights.ts";

/** True when any pool item carries at least one graph edge. */
/** True when any pool item carries at least one valid graph edge. */
export function hasGraphEdges(items: readonly ProjectPoolItem[]): boolean {
return items.some(
(p) =>
p.parentRef !== undefined ||
p.epicRef !== undefined ||
(p.blockedBy?.length ?? 0) > 0 ||
(p.blocks?.length ?? 0) > 0,
isValidRef(p.parentRef) ||
isValidRef(p.epicRef) ||
(p.blockedBy ?? []).some(isValidRef) ||
(p.blocks ?? []).some(isValidRef),
);
}

Expand Down Expand Up @@ -83,7 +84,7 @@ export function blockedSummary(items: readonly ProjectPoolItem[]): BlockedSummar
const item = byRef.get(ref);
let best: RefKey[] = [ref];
for (const blocker of item?.blockedBy ?? []) {
if (!blockerUnresolved(blocker, byRef)) continue;
if (!isValidRef(blocker) || !blockerUnresolved(blocker, byRef)) continue;
const rest = chainFrom(blocker, visiting);
if (rest.length + 1 > best.length) best = [ref, ...rest];
}
Expand All @@ -94,7 +95,7 @@ export function blockedSummary(items: readonly ProjectPoolItem[]): BlockedSummar

for (const item of items) {
if (item.state !== "open") continue;
const blocked = (item.blockedBy ?? []).some((b) => blockerUnresolved(b, byRef));
const blocked = (item.blockedBy ?? []).some((b) => isValidRef(b) && blockerUnresolved(b, byRef));
if (!blocked) continue;
out.blockedCount += 1;
const w = effortWeight(item.labels);
Expand Down
16 changes: 8 additions & 8 deletions pm-stack/aggregator/src/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// whose fetch is injectable for tests), shared by the collector and
// the live source so the wire shape is parsed exactly once.
import type { GhItem, OrchestrationSection, ProjectPoolItem, RefKey } from "./model.ts";
import { refKey } from "./model.ts";
import { isValidRef, refKey } from "./model.ts";
import { workItemRefSet } from "./work-items.ts";

export const PROJECT_ID = "PVT_kwDOAZNvF84Bouay";
Expand Down Expand Up @@ -241,9 +241,9 @@ export async function fetchProjectPool(token: string, fetchFn: typeof fetch = fe

/** Structural check for a pool entry in a feed (collector + live share
* it, and the feed.ts section gate delegates to it — the two sides can
* never drift). Edge fields (#2399) are absence-friendly but
* shape-strict when present: a malformed edge fails the item, never
* the section. */
* never drift). Edge fields (#2399) are absence-friendly, but every
* present ref must satisfy the shared isValidRef rule: a malformed edge
* fails the item, never the section. */
export function isProjectPoolItem(v: unknown): v is ProjectPoolItem {
if (typeof v !== "object" || v === null) return false;
const p = v as Partial<ProjectPoolItem>;
Expand Down Expand Up @@ -277,10 +277,10 @@ export function isProjectPoolItem(v: unknown): v is ProjectPoolItem {
(p.closedAt === undefined || typeof p.closedAt === "string") &&
(p.mergedAt === undefined || typeof p.mergedAt === "string") &&
(p.state === "open" || p.state === "closed" || p.state === "merged") &&
(p.parentRef === undefined || typeof p.parentRef === "string") &&
(p.epicRef === undefined || typeof p.epicRef === "string") &&
(p.blockedBy === undefined || (Array.isArray(p.blockedBy) && p.blockedBy.every((x) => typeof x === "string"))) &&
(p.blocks === undefined || (Array.isArray(p.blocks) && p.blocks.every((x) => typeof x === "string")))
(p.parentRef === undefined || isValidRef(p.parentRef)) &&
(p.epicRef === undefined || isValidRef(p.epicRef)) &&
(p.blockedBy === undefined || (Array.isArray(p.blockedBy) && p.blockedBy.every(isValidRef))) &&
(p.blocks === undefined || (Array.isArray(p.blocks) && p.blocks.every(isValidRef)))
);
}

Expand Down
22 changes: 15 additions & 7 deletions pm-stack/aggregator/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6462,6 +6462,12 @@ ${trackedTable(live.tracked)}${poolSectionHtml}`;

const POOL_ITEM_CAP = 24;

/** Render a graph ref as a link only when it satisfies the shared ref rule. */
function poolRefLink(ref: RefKey): string {
const label = esc(ref);
return isValidRef(ref) ? `<a href="${esc(refUrl(ref))}">${label}</a>` : label;
}

/** The #2400 graph section of a project page: blocked weight + longest
* blocked chain and the depth-graph SVG, from the part-1 edge contract
* (#2399). Graceful absence is explicit: a pool with no effort labels
Expand All @@ -6478,7 +6484,7 @@ function poolGraphHtml(items: ProjectPoolItem[], allW: ReturnType<typeof summari
const blocked = blockedSummary(items);
const chainHtml =
blocked.longestChain.length >= 2
? ` · longest blocked chain: ${blocked.longestChain.map((r) => `<a href="${esc(refUrl(r))}">${esc(r)}</a>`).join(" → ")} (${blocked.longestChain.length - 1} link${blocked.longestChain.length === 2 ? "" : "s"})`
? ` · longest blocked chain: ${blocked.longestChain.map(poolRefLink).join(" → ")} (${blocked.longestChain.length - 1} link${blocked.longestChain.length === 2 ? "" : "s"})`
: "";
const blockedHtml = blocked.blockedCount
? `<p class="muted"><strong>Blocked weight: ${blocked.blockedWeight}</strong> across ${blocked.blockedCount} open item${blocked.blockedCount === 1 ? "" : "s"} waiting on an unresolved blocker${blocked.blockedUnsizedCount ? ` (${blocked.blockedUnsizedCount} of them unsized — counted, never zero-weighted)` : ""}${chainHtml}.</p>`
Expand Down Expand Up @@ -6588,9 +6594,9 @@ function epicGraphOneHtml(items: ProjectPoolItem[], entry: ReturnType<typeof epi
? `<ul class="epic-graph-list">${ranked
.map(
(r) => {
const blockerItems = r.blockers.map((b) => `<a href="${esc(refUrl(b))}">${esc(b)}</a>`);
const blockerItems = r.blockers.map((b) => poolRefLink(b));
const contributingItems = r.contributingItems.length > 0
? `<br><span class="muted">Contributing downstream epics: ${r.contributingItems.map((ci) => `<a href="${esc(refUrl(ci))}">${esc(ci)}</a>`).join(", ")}</span>`
? `<br><span class="muted">Contributing downstream epics: ${r.contributingItems.map((ci) => poolRefLink(ci)).join(", ")}</span>`
: "";
return `<li><a href="${esc(r.issueUrl)}">${esc(r.ref)}</a> — waiting on ${r.downstreamCount} distinct downstream open epic item${r.downstreamCount === 1 ? "" : "s"} via ${r.blockers.length} unresolved blocker${r.blockers.length === 1 ? "" : "s"}: ${blockerItems.join(", ")}${contributingItems}</li>`;
},
Expand Down Expand Up @@ -6635,7 +6641,8 @@ function epicGraphOneHtml(items: ProjectPoolItem[], entry: ReturnType<typeof epi
: n.epic
? `<rect x="${x - 6}" y="${y - 6}" width="12" height="12" fill="${n.state === "open" ? "#8957e5" : "#6e7781"}" stroke="#0d1117" stroke-width="1.5"/>`
: `<circle cx="${x}" cy="${y}" r="6" fill="${n.state === "open" ? "#bf8700" : "#6e7781"}" stroke="#0d1117" stroke-width="1.5"/>`;
return `${shape}<a href="${esc(n.issueUrl)}"><text x="${x + 11}" y="${y + 4}" font-size="11" fill="currentColor">${esc(label)}</text></a>`;
const nodeLabel = `<text x="${x + 11}" y="${y + 4}" font-size="11" fill="currentColor">${esc(label)}</text>`;
return `${shape}${isValidRef(n.ref) ? `<a href="${esc(n.issueUrl)}">${nodeLabel}</a>` : nodeLabel}`;
})
.join("");
const svg = g.edges.length
Expand All @@ -6648,13 +6655,14 @@ function epicGraphOneHtml(items: ProjectPoolItem[], entry: ReturnType<typeof epi
? "not in this pool / status unknown — unresolved"
: `issue ${esc(n.state ?? "unknown")}`;
const blockedBy = n.blockers.length
? `blocked by: ${n.blockers.map((b) => `<a href="${esc(refUrl(b))}">${esc(b)}</a>${unresolvedOf(b) ? " (unresolved)" : " (resolved)"}`).join(", ")}`
? `blocked by: ${n.blockers.map((b) => `${poolRefLink(b)}${unresolvedOf(b) ? " (unresolved)" : " (resolved)"}`).join(", ")}`
: "blocked by: none observed";
const blocks = n.dependents.length
? `blocks: ${n.dependents.map((b) => `<a href="${esc(refUrl(b))}">${esc(b)}</a>`).join(", ")}`
? `blocks: ${n.dependents.map(poolRefLink).join(", ")}`
: "blocks: none observed";
const name = n.title ? `${esc(n.title)}` : "(outside this pool — no title in this feed)";
return `<li><a href="${esc(n.issueUrl)}">${esc(n.ref)}</a> ${name} — ${stateText}; ${blockedBy}; ${blocks}</li>`;
const nodeRef = isValidRef(n.ref) ? `<a href="${esc(n.issueUrl)}">${esc(n.ref)}</a>` : esc(n.ref);
return `<li>${nodeRef} ${name} — ${stateText}; ${blockedBy}; ${blocks}</li>`;
})
.join("")}</ul>`;

Expand Down
23 changes: 23 additions & 0 deletions pm-stack/aggregator/test/brief.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ describe("buildItemBrief", () => {
expect(brief.blocker.text).toContain("Not blocked");
});

test("malformed blocker refs are omitted without losing valid blockers", () => {
const unsafe = "developing-today/code#99999999999999999999";
for (const badRef of [unsafe, "812"]) {
const brief = buildItemBrief(item({ number: 20, blockedBy: [badRef] }));
expect(brief.blocker.blockers).toEqual([]);
expect(brief.blocker.blocked).toBe(false);
expect(brief.blocker.text).toContain("Unknown");
expect(brief.blocker.text).toContain("malformed");
expect(brief.nextAction.text).toContain("Validate");
expect(brief.nextAction.text).not.toContain("not blocked");
}

const valid = buildItemBrief(item({ number: 21, blockedBy: ["developing-today/code#3"] }));
expect(valid.blocker.blocked).toBe(true);
expect(valid.blocker.blockers).toEqual([
{
ref: "developing-today/code#3",
url: "https://github.com/developing-today/code/issues/3",
state: "unknown",
},
]);
});

test("in-flight item: derived In Progress, last actor from latest comment", () => {
const it = item({ number: 12, updatedAt: "2026-10-30T10:30:00Z" });
const brief = buildItemBrief(it, {
Expand Down
34 changes: 34 additions & 0 deletions pm-stack/aggregator/test/epic-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ describe("epicSelector", () => {
test("no epics in the pool yields an empty selector", () => {
expect(epicSelector([item({ number: 1 }), item({ number: 2 })])).toEqual([]);
});

test("invalid-only blockers do not inflate selector or graph blocked counts", () => {
const pool = [
item({ number: 1, title: "Epic", kind: "Epic" }),
item({ number: 2, epicRef: R(1), blockedBy: ["812"] }),
item({ number: 3, epicRef: R(1), blockedBy: [R(99)] }),
];
expect(epicSelector(pool)[0]?.blockedCount).toBe(1);
const graph = epicGraph(pool, R(1));
expect(graph.blockedCount).toBe(1);
expect(graph.rankedBlocked.map((row) => row.ref)).toEqual([R(3)]);
});
});

describe("epicGraph", () => {
Expand Down Expand Up @@ -127,6 +139,28 @@ describe("epicGraph", () => {
expect(g.edges).toContainEqual({ from: R(3), to: R(2), type: "dependency" });
});

test("malformed one-hop refs are omitted while valid blockedBy and blocks edges render", () => {
const unsafe = "developing-today/code#99999999999999999999";
const pool = [
item({ number: 1, title: "Epic", kind: "Epic" }),
item({ number: 2, epicRef: R(1), blockedBy: ["812", R(3)], blocks: [unsafe, R(4)] }),
item({ number: 3 }),
item({ number: 4 }),
];
const g = epicGraph(pool, R(1));
expect(g.nodes.map((n) => n.ref)).not.toContain("812");
expect(g.nodes.map((n) => n.ref)).not.toContain(unsafe);
expect(g.edges).toContainEqual({ from: R(2), to: R(3), type: "dependency" });
expect(g.edges).toContainEqual({ from: R(4), to: R(2), type: "dependency" });
expect(g.rankedBlocked.find((r) => r.ref === R(2))?.blockers).toEqual([R(3)]);

const html = renderWith(pool);
expect(html).toContain('href="https://github.com/developing-today/code/issues/3"');
expect(html).toContain('href="https://github.com/developing-today/code/issues/4"');
expect(html).not.toContain('href="https://github.com/812/issues/"');
expect(html).not.toContain('href="https://github.com/developing-today/code/issues/99999999999999999999"');
});

test("truncation reports the true total and the cut count", () => {
const g = epicGraph(fixturePool(), R(1), 3);
expect(g.totalNodes).toBe(5);
Expand Down
18 changes: 18 additions & 0 deletions pm-stack/aggregator/test/feed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ describe("feed project-pool section gate (#2399)", () => {
expect(projectPoolSectionProblem([{ ...EDGElESS, blocks: "developing-today/code#1" }])).toBe("item 0");
});

test("every edge ref uses the shared parseRef validity rule and drops only its bad item", () => {
const unsafe = "developing-today/code#99999999999999999999";
const malformed = [
{ ...GRAPHED, blockedBy: [unsafe] },
{ ...GRAPHED, blockedBy: ["812"] },
{ ...GRAPHED, blocks: [unsafe] },
{ ...GRAPHED, parentRef: "812" },
{ ...GRAPHED, epicRef: unsafe },
];

expect(isProjectPoolItem(GRAPHED)).toBe(true);
for (const bad of malformed) expect(isProjectPoolItem(bad)).toBe(false);
expect(projectPoolSectionProblem([GRAPHED, malformed[0]])).toBe("item 1");
expect(
poolFromFeed({ projects: [EDGElESS, ...malformed, GRAPHED] as unknown as never }).map((p) => p.ref),
).toEqual([EDGElESS.ref, GRAPHED.ref]);
});

test("structural fields + optional-field types are gated (#2418)", () => {
// labels: a bare string or non-string members crash renders; both fail.
expect(isProjectPoolItem({ ...EDGElESS, labels: "blocked" })).toBe(false);
Expand Down
Loading