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
32 changes: 31 additions & 1 deletion pm-stack/aggregator/src/aa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1211,11 +1211,20 @@ export function isAaSection(v: unknown): v is AaFeedSection {
(r) => typeof r === "object" && r !== null && typeof r.testRunKey === "string" && typeof r.family === "string",
) &&
Array.isArray(s.configs) &&
// #4169: aaConfigsTable maps entries dereferencing c.modelName — a
// null entry passed this gate and threw in the render.
s.configs.every(
(c) => typeof c === "object" && c !== null && typeof (c as { modelName?: unknown }).modelName === "string",
) &&
Array.isArray(s.testRuns) &&
s.testRuns.every(
(r) =>
typeof r === "object" &&
r !== null &&
// #4169: aaTimingsTable dereferences r.modelVariantKey via
// variantLabel (.split) — an entry without a string key passed
// this gate and threw in the render.
typeof (r as { modelVariantKey?: unknown }).modelVariantKey === "string" &&
// #5289: snapshotDate is a date, not just a string — summarizeAa
// publishes these values verbatim as the batch's snapshot vintage,
// so gate them with isIsoDate like generatedAt above (date-only
Expand Down Expand Up @@ -1245,7 +1254,28 @@ export function isAaSection(v: unknown): v is AaFeedSection {
src !== null &&
typeof (src as { name?: unknown }).name === "string" &&
typeof (src as { kind?: unknown }).kind === "string",
)
) &&
// #4169: coverage, catalog, and cai are optional (absent when the
// collector could not build them) but the /aa renderer dereferences
// them when present — a present-but-malformed value passed this gate
// and threw in the render instead of degrading to the not-collected
// banner. Gate each at the depth its consumer dereferences it.
(s.coverage === undefined ||
(typeof s.coverage === "object" &&
s.coverage !== null &&
(["measuredNotPooled", "catalogNotPooledMeasured", "measuredNotInCatalog", "catalogNotPooledUnmeasured"] as const).every(
(k) => Array.isArray(s.coverage?.[k]) && (s.coverage?.[k] as unknown[]).every((n) => typeof n === "string"),
))) &&
(s.catalog === undefined ||
(Array.isArray(s.catalog) &&
s.catalog.every(
(e) =>
typeof e === "object" &&
e !== null &&
typeof (e as { provider?: unknown }).provider === "string" &&
Array.isArray((e as { routes?: unknown }).routes),
))) &&
(s.cai === undefined || (Array.isArray(s.cai) && s.cai.every((r) => typeof r === "object" && r !== null)))
);
}

Expand Down
6 changes: 3 additions & 3 deletions pm-stack/aggregator/test/aa-gate-2415.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function completeSection(): Record<string, unknown> {
rankings: [{ testRunKey: "run-1", family: "GPT" }],
thresholds: [{ testRunKey: "run-1", target: 42, usable: true }],
configs: [],
testRuns: [{ testRunKey: "run-1", snapshotDate: "2026-10-01" }],
testRuns: [{ testRunKey: "run-1", modelVariantKey: "openai|gpt-6-luna|max", snapshotDate: "2026-10-01" }],
};
}

Expand All @@ -35,7 +35,7 @@ describe("isAaSection gate depth (#2415)", () => {

test("accepts a testRuns entry with a null snapshotDate", () => {
const s = completeSection();
s.testRuns = [{ testRunKey: "run-1", snapshotDate: null }];
s.testRuns = [{ testRunKey: "run-1", modelVariantKey: "openai|gpt-6-luna|max", snapshotDate: null }];
expect(isAaSection(s)).toBe(true);
});

Expand Down Expand Up @@ -83,7 +83,7 @@ describe("isAaSection gate depth (#2415)", () => {
nullEntry.testRuns = [null];
expect(isAaSection(nullEntry)).toBe(false);
const undefDate = completeSection();
undefDate.testRuns = [{ testRunKey: "run-1" }];
undefDate.testRuns = [{ testRunKey: "run-1", modelVariantKey: "openai|gpt-6-luna|max" }];
expect(isAaSection(undefDate)).toBe(false);
});

Expand Down
110 changes: 110 additions & 0 deletions pm-stack/aggregator/test/aa-gate-4169.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { describe, expect, test } from "bun:test";
import { isAaSection } from "../src/aa.ts";

// #4169: isAaSection's "ok" branch checked configs only as an array,
// testRuns entries only for snapshotDate, and never mentioned the
// optional coverage/catalog/cai fields — while renderAa dereferences
// configs entries (modelName), testRuns entries (modelVariantKey via
// variantLabel), the coverage name lists, catalog entries, and cai rows.
// Gate-passing malformed sections threw on /aa instead of degrading to
// the not-collected banner. The gate now checks each field at the depth
// its consumer dereferences it; absent optional fields stay valid.

function completeSection(): Record<string, unknown> {
return {
status: "ok",
generatedAt: "2026-11-01T00:00:00Z",
batch: "batch-1",
sources: [{ name: "ainventory.xlsx", kind: "sheet", importedAt: null, driveModifiedAt: null }],
rankings: [{ testRunKey: "run-1", family: "GPT" }],
thresholds: [{ testRunKey: "run-1", target: 42, usable: true }],
configs: [{ modelName: "GPT-6 Sol", benchmark: "AA" }],
testRuns: [{ testRunKey: "run-1", modelVariantKey: "openai|gpt-6-sol|max", snapshotDate: "2026-10-01" }],
coverage: {
measuredNotPooled: ["GPT-6 Sol"],
catalogNotPooledMeasured: ["GPT-6 Sol"],
measuredNotInCatalog: [],
catalogNotPooledUnmeasured: [],
},
catalog: [{ id: "openai/gpt-6-sol", provider: "openai", routes: ["pool-a"] }],
cai: [{ modelName: "GPT-6.1 Sol (xhigh)", family: "GPT-6.1 Sol", creator: "OpenAI" }],
};
}

describe("isAaSection gate depth (#4169)", () => {
test("accepts a complete section carrying every optional field", () => {
expect(isAaSection(completeSection())).toBe(true);
});

test("accepts a section with all optional fields absent", () => {
const s = completeSection();
delete s.coverage;
delete s.catalog;
delete s.cai;
expect(isAaSection(s)).toBe(true);
});

test("rejects configs=[null] and a configs entry without a string modelName", () => {
const nullEntry = completeSection();
nullEntry.configs = [null];
expect(isAaSection(nullEntry)).toBe(false);
const noName = completeSection();
noName.configs = [{ benchmark: "AA" }];
expect(isAaSection(noName)).toBe(false);
});

test("rejects a testRuns entry without a string modelVariantKey", () => {
const missing = completeSection();
missing.testRuns = [{ testRunKey: "run-1", snapshotDate: "2026-10-01" }];
expect(isAaSection(missing)).toBe(false);
const wrongType = completeSection();
wrongType.testRuns = [{ testRunKey: "run-1", modelVariantKey: 42, snapshotDate: "2026-10-01" }];
expect(isAaSection(wrongType)).toBe(false);
});

test("rejects coverage={} and a coverage name list of the wrong type", () => {
const empty = completeSection();
empty.coverage = {};
expect(isAaSection(empty)).toBe(false);
const stringField = completeSection();
stringField.coverage = {
measuredNotPooled: [],
catalogNotPooledMeasured: "GPT-6 Sol",
measuredNotInCatalog: [],
catalogNotPooledUnmeasured: [],
};
expect(isAaSection(stringField)).toBe(false);
const nonStringMember = completeSection();
nonStringMember.coverage = {
measuredNotPooled: [null],
catalogNotPooledMeasured: [],
measuredNotInCatalog: [],
catalogNotPooledUnmeasured: [],
};
expect(isAaSection(nonStringMember)).toBe(false);
});

test("rejects a non-array catalog and a catalog entry without provider/routes depth", () => {
const wrongType = completeSection();
wrongType.catalog = "openai/gpt-6-sol";
expect(isAaSection(wrongType)).toBe(false);
const nullEntry = completeSection();
nullEntry.catalog = [null];
expect(isAaSection(nullEntry)).toBe(false);
const noProvider = completeSection();
noProvider.catalog = [{ id: "openai/gpt-6-sol", routes: [] }];
expect(isAaSection(noProvider)).toBe(false);
const noRoutes = completeSection();
noRoutes.catalog = [{ id: "openai/gpt-6-sol", provider: "openai" }];
expect(isAaSection(noRoutes)).toBe(false);
});

test("rejects a non-array cai and a null cai row", () => {
const wrongType = completeSection();
wrongType.cai = "x";
expect(isAaSection(wrongType)).toBe(false);
const nullRow = completeSection();
nullRow.cai = [null];
expect(isAaSection(nullRow)).toBe(false);
});
});
8 changes: 4 additions & 4 deletions pm-stack/aggregator/test/aa-gate-5289.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ function completeSection(): Record<string, unknown> {
rankings: [{ testRunKey: "run-1", family: "GPT" }],
thresholds: [{ testRunKey: "run-1", target: 42, usable: true }],
configs: [],
testRuns: [{ testRunKey: "run-1", snapshotDate: "2026-10-01" }],
testRuns: [{ testRunKey: "run-1", modelVariantKey: "openai|gpt-6-luna|max", snapshotDate: "2026-10-01" }],
};
}

function sectionWithSnapshotDate(snapshotDate: unknown): Record<string, unknown> {
const s = completeSection();
s.testRuns = [{ testRunKey: "run-1", snapshotDate }];
s.testRuns = [{ testRunKey: "run-1", modelVariantKey: "openai|gpt-6-luna|max", snapshotDate }];
return s;
}

Expand All @@ -39,8 +39,8 @@ describe("isAaSection snapshotDate validity (#5289)", () => {
test("rejects a mixed section when any test run carries a bad snapshotDate", () => {
const s = completeSection();
s.testRuns = [
{ testRunKey: "run-1", snapshotDate: "2026-09-28" },
{ testRunKey: "run-2", snapshotDate: "2026-02-30" },
{ testRunKey: "run-1", modelVariantKey: "openai|gpt-6-luna|max", snapshotDate: "2026-09-28" },
{ testRunKey: "run-2", modelVariantKey: "openai|gpt-6-luna|max", snapshotDate: "2026-02-30" },
];
expect(isAaSection(s)).toBe(false);
});
Expand Down
Loading