From e8be7a21d97120c885cc8314ded3b0f4ed741c57 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 14:10:51 -0600 Subject: [PATCH 1/2] fix(aggregator): gate aa configs/testRuns/coverage/catalog/cai at render depth (#4169) --- pm-stack/aggregator/src/aa.ts | 32 ++++- pm-stack/aggregator/test/aa-gate-2415.test.ts | 6 +- pm-stack/aggregator/test/aa-gate-4169.test.ts | 110 ++++++++++++++++++ 3 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 pm-stack/aggregator/test/aa-gate-4169.test.ts diff --git a/pm-stack/aggregator/src/aa.ts b/pm-stack/aggregator/src/aa.ts index a001d8e60d..b6bc376100 100644 --- a/pm-stack/aggregator/src/aa.ts +++ b/pm-stack/aggregator/src/aa.ts @@ -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 @@ -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))) ); } diff --git a/pm-stack/aggregator/test/aa-gate-2415.test.ts b/pm-stack/aggregator/test/aa-gate-2415.test.ts index 25aac021d1..6c742341c6 100644 --- a/pm-stack/aggregator/test/aa-gate-2415.test.ts +++ b/pm-stack/aggregator/test/aa-gate-2415.test.ts @@ -17,7 +17,7 @@ function completeSection(): Record { 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" }], }; } @@ -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); }); @@ -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); }); diff --git a/pm-stack/aggregator/test/aa-gate-4169.test.ts b/pm-stack/aggregator/test/aa-gate-4169.test.ts new file mode 100644 index 0000000000..5f3f9f6717 --- /dev/null +++ b/pm-stack/aggregator/test/aa-gate-4169.test.ts @@ -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 { + 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); + }); +}); From 60a07afa10b22aba2e20ed9c2995af6a0f4bc573 Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Tue, 10 Nov 2026 20:26:47 -0600 Subject: [PATCH 2/2] test(aggregator): aa-gate-5289 fixtures carry modelVariantKey (#4169) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The #4169 gate requires a string modelVariantKey on testRuns entries (aaTimingsTable splits it); the #5289 fixtures built entries without one — exactly the fixture shape #4169 identifies as render-crashing. Add the key real collector rows carry. --- pm-stack/aggregator/test/aa-gate-5289.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pm-stack/aggregator/test/aa-gate-5289.test.ts b/pm-stack/aggregator/test/aa-gate-5289.test.ts index 9c2be2b8bb..f841d58880 100644 --- a/pm-stack/aggregator/test/aa-gate-5289.test.ts +++ b/pm-stack/aggregator/test/aa-gate-5289.test.ts @@ -19,13 +19,13 @@ function completeSection(): Record { 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 { const s = completeSection(); - s.testRuns = [{ testRunKey: "run-1", snapshotDate }]; + s.testRuns = [{ testRunKey: "run-1", modelVariantKey: "openai|gpt-6-luna|max", snapshotDate }]; return s; } @@ -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); });