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
26 changes: 22 additions & 4 deletions pm-stack/aggregator/src/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export async function fetchProjectSnapshot(
): Promise<ProjectSnapshot> {
const parsedItems: ProjectPoolItem[] = [];
const auditItems: GqlItem[] = [];
const seenItemIds = new Set<string>();
let firstPage: unknown;
let cursor: string | null = null;
let lastPageInfo: ReturnType<typeof projectPageInfo> | null = null;
Expand All @@ -353,13 +354,30 @@ export async function fetchProjectSnapshot(
if ((json as GqlProjectPage).errors) throw new Error("github GraphQL returned errors");
if (!firstPage) firstPage = json;
const nodes = (json as GqlProjectPage).data?.node?.items?.nodes ?? [];
auditItems.push(...nodes.filter((node): node is GqlItem => node !== null));
parsedItems.push(...parseProjectItems(json));
// #8599: overlapping pages (the board mutating mid-export) can
// deliver the same node twice. Deduplicate by item id at
// collection, first delivery wins: the audit distributions and
// the completeness check below are judged on the deduplicated
// export, so an over-delivered export still sums to totalItems
// and survives the feed-side isProjectAudit gate instead of
// being discarded as an absent snapshot. Fetch-side tolerance
// and feed-side strictness agree on the distinct-item count.
const freshNodes = nodes.filter((node): node is GqlItem => {
if (node === null) return false;
if (!node.id) return true;
if (seenItemIds.has(node.id)) return false;
seenItemIds.add(node.id);
return true;
});
auditItems.push(...freshNodes);
const freshIds = new Set(freshNodes.map((node) => node.id));
parsedItems.push(...parseProjectItems(json).filter((item) => freshIds.has(item.id)));
const info = projectPageInfo(json);
if (!info.hasNextPage) {
if (auditItems.length < info.totalCount) {
// Shortfall only: overlapping pages can over-deliver nodes, but
// fewer nodes than the board total means the export lost items.
// Shortfall only, judged on the deduplicated count: fewer
// distinct items than the board total means the export lost
// items. Over-delivery is absorbed by the dedupe above.
throw new Error(`github GraphQL project export incomplete (${auditItems.length}/${info.totalCount} items)`);
}
return {
Expand Down
28 changes: 27 additions & 1 deletion pm-stack/aggregator/test/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,32 @@ describe("collector projects parsing (GraphQL -> feed section)", () => {
expect(projectDisagreement(pool[0], section)).toBeNull();
});

test("overlapping pages: a node delivered twice is counted once and the audit survives the feed gate (#8599)", async () => {
// Page 1 delivers PVTI_1 + PVTI_2, page 2 repeats PVTI_2 and adds
// PVTI_3 (the board mutated mid-export). totalCount is 3 distinct
// items; without dedupe every distribution would sum to 4 and
// isProjectAudit would discard the fetched snapshot as absent.
const page1 = structuredClone(GQL);
page1.data.node.items.totalCount = 3;
page1.data.node.items.pageInfo = { hasNextPage: true, endCursor: "cursor-1" };
page1.data.node.items.nodes = [GQL.data.node.items.nodes[0], GQL.data.node.items.nodes[1]];
const page2 = structuredClone(GQL);
page2.data.node.items.totalCount = 3;
page2.data.node.items.pageInfo = { hasNextPage: false, endCursor: null };
page2.data.node.items.nodes = [GQL.data.node.items.nodes[1], GQL.data.node.items.nodes[2]];
const pages = [page1, page2];
let call = 0;
const mockFetch = (async () =>
new Response(JSON.stringify(pages[call++]), { status: 200 })) as unknown as typeof fetch;
const snapshot = await fetchProjectSnapshot("test-token", mockFetch, "2026-11-01T21:00:00.000Z");
expect(call).toBe(2);
expect(snapshot.audit.totalItems).toBe(3);
expect(snapshot.audit.counts.status).toEqual({ "(unset)": 1, Done: 1, "In Progress": 1 });
expect(isProjectAudit(snapshot.audit)).toBe(true);
// The pool is deduplicated by item id as well.
expect(snapshot.items.map((item) => item.id)).toEqual(["PVTI_1", "PVTI_2"]);
});

test("scheduled fetch keeps the full item total and publishes one-page audit metadata", async () => {
const mockFetch = (async () => new Response(JSON.stringify(GQL), { status: 200 })) as unknown as typeof fetch;
const snapshot = await fetchProjectSnapshot(
Expand All @@ -229,7 +255,7 @@ describe("collector projects parsing (GraphQL -> feed section)", () => {
expect(snapshot.audit.views).toEqual([{ id: "PVTV_board", name: "Board", layout: "BOARD_LAYOUT", filter: "Status:open" }]);
expect(snapshot.audit.counts.status).toEqual({ "(unset)": 1, Done: 1, "In Progress": 1 });
expect(snapshot.audit.counts.area).toEqual({ "(unset)": 2, "lab-cluster": 1 });
expect(snapshot.audit.counts.repo).toEqual({ "(unlinked)": 1, "developing-today/code": 1, "dezren39/nix": 1 });
expect(snapshot.audit.counts.repo).toEqual({ "(unlinked)": 1, "developing-today/code": 1, "dezren39/darwin-nix": 1 });
});
});

Expand Down
Loading