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
27 changes: 25 additions & 2 deletions pm-stack/aggregator/src/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ interface GqlContent {
}
interface GqlItem {
id?: string;
databaseId?: number;
// ProjectV2Item.databaseId is a nullable Int in the GraphQL schema:
// null is a valid upstream shape, normalized away in parseProjectItems.
databaseId?: number | null;
type?: string;
content?: GqlContent | null;
fieldValues?: { nodes?: (GqlFieldValue | null)[] } | null;
Expand Down Expand Up @@ -141,7 +143,10 @@ export function parseProjectItems(json: unknown, projectUrl = PROJECT_URL): Proj
const blocks = !isPr ? (c.blocking?.nodes ?? []).map(edgeRef).filter((x): x is RefKey => x !== null) : [];
out.push({
id: item.id,
databaseId: item.databaseId,
// Normalize the nullable GraphQL databaseId to the model's optional
// number: null becomes absent, so a valid item is never dropped by
// isProjectPoolItem for an upstream null (Codex P2 on PR #4181).
databaseId: item.databaseId ?? undefined,
url: projectItemUrl(item.databaseId, projectUrl),
projectUrl,
ref: refKey({ repo, number: c.number }),
Expand Down Expand Up @@ -243,6 +248,24 @@ export function isProjectPoolItem(v: unknown): v is ProjectPoolItem {
typeof p.number === "number" &&
typeof p.issueUrl === "string" &&
typeof p.title === "string" &&
// url/projectUrl/contentKind and the Project single-select fields are
// required by the model and dereferenced by board/item renders; the
// gate must own their shapes (#2418).
typeof p.url === "string" &&
typeof p.projectUrl === "string" &&
(p.contentKind === "issue" || p.contentKind === "pr") &&
(p.status === null || typeof p.status === "string") &&
(p.area === null || typeof p.area === "string") &&
(p.horizon === null || typeof p.horizon === "string") &&
(p.kind === null || typeof p.kind === "string") &&
// Optional fields stay absence-friendly, but a present value must
// match its declared type: labels feeds .map/.includes in renders,
// so a string or non-string array crashes instead of dropping (#2418).
(p.databaseId === undefined || typeof p.databaseId === "number") &&
Comment thread
dezren39 marked this conversation as resolved.
Resolved
(p.draft === undefined || typeof p.draft === "boolean") &&
(p.labels === undefined || (Array.isArray(p.labels) && p.labels.every((x) => typeof x === "string"))) &&
(p.author === undefined || typeof p.author === "string") &&
(p.updatedAt === undefined || typeof p.updatedAt === "string") &&
(p.state === "open" || p.state === "closed" || p.state === "merged") &&
(p.parentRef === undefined || typeof p.parentRef === "string") &&
(p.epicRef === undefined || typeof p.epicRef === "string") &&
Expand Down
37 changes: 37 additions & 0 deletions pm-stack/aggregator/test/feed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,43 @@ describe("feed project-pool section gate (#2399)", () => {
expect(projectPoolSectionProblem([{ ...EDGElESS, blocks: "developing-today/code#1" }])).toBe("item 0");
});

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);
expect(isProjectPoolItem({ ...EDGElESS, labels: [42] })).toBe(false);
// required url/projectUrl/contentKind.
const noUrl = { ...EDGElESS } as Record<string, unknown>;
delete noUrl.url;
expect(isProjectPoolItem(noUrl)).toBe(false);
const noProjectUrl = { ...EDGElESS } as Record<string, unknown>;
delete noProjectUrl.projectUrl;
expect(isProjectPoolItem(noProjectUrl)).toBe(false);
const noKind = { ...EDGElESS } as Record<string, unknown>;
delete noKind.contentKind;
expect(isProjectPoolItem(noKind)).toBe(false);
expect(isProjectPoolItem({ ...EDGElESS, contentKind: "draft" })).toBe(false);
// required nullable fields: string or null only, never a wrong type or absent.
expect(isProjectPoolItem({ ...EDGElESS, status: 7 })).toBe(false);
expect(isProjectPoolItem({ ...EDGElESS, area: undefined })).toBe(false);
expect(isProjectPoolItem({ ...EDGElESS, horizon: false })).toBe(false);
expect(isProjectPoolItem({ ...EDGElESS, kind: ["Task"] })).toBe(false);
// present optional fields must match their declared types.
expect(isProjectPoolItem({ ...EDGElESS, databaseId: "42" })).toBe(false);
expect(isProjectPoolItem({ ...EDGElESS, draft: "yes" })).toBe(false);
expect(isProjectPoolItem({ ...EDGElESS, author: 42 })).toBe(false);
expect(isProjectPoolItem({ ...EDGElESS, updatedAt: null })).toBe(false);
// absent optional fields remain valid; a mixed pool drops only the bad entry.
const bare = { ...EDGElESS } as Record<string, unknown>;
delete bare.labels;
delete bare.databaseId;
delete bare.draft;
delete bare.author;
delete bare.updatedAt;
expect(isProjectPoolItem(bare)).toBe(true);
expect(poolFromFeed({ projects: [EDGElESS, { ...EDGElESS, labels: "blocked" }, GRAPHED] as unknown as never })).toHaveLength(2);
});


test("poolFromFeed is fail-soft: garbage sections yield no items, bad items drop", () => {
expect(poolFromFeed(null)).toEqual([]);
expect(poolFromFeed(undefined)).toEqual([]);
Expand Down
13 changes: 12 additions & 1 deletion pm-stack/aggregator/test/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { loadConfig } from "../src/config.ts";
import type { OrchestrationSection } from "../src/model.ts";
import { derivedProjectState, parseProjectItems, poolItemToGhItem, projectDisagreement, PROJECT_QUERY, resolveEpicRefs } from "../src/projects.ts";
import { derivedProjectState, isProjectPoolItem, parseProjectItems, poolItemToGhItem, projectDisagreement, PROJECT_QUERY, resolveEpicRefs } from "../src/projects.ts";
import { renderProjects } from "../src/render.ts";
import { liveSource } from "../src/sources/live.ts";

Expand Down Expand Up @@ -101,6 +101,17 @@ describe("collector projects parsing (GraphQL -> feed section)", () => {
expect(pool[1].state).toBe("closed");
});

test("a null GraphQL databaseId normalizes to absent and the item stays in the pool", () => {
const clone = structuredClone(GQL);
clone.data.node.items.nodes[0].databaseId = null;
const pool = parseProjectItems(clone);
expect(pool.length).toBe(2);
expect(pool[0].databaseId).toBeUndefined();
// projectItemUrl falls back to the bare board URL without an item id.
expect(pool[0].url).toBe("https://github.com/orgs/developing-today/projects/4");
expect(isProjectPoolItem(pool[0])).toBe(true);
});

test("derived state + disagreement", () => {
const pool = parseProjectItems(GQL);
// Open, no orchestration presence -> Todo, which disagrees with In Progress.
Expand Down
Loading