Skip to content
Closed
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
4 changes: 2 additions & 2 deletions pm-stack/aggregator/src/quota-current.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function isQuotaCurrentWindow(value: unknown): value is QuotaCurrentFile["provid
(value.valueLabel === null || typeof value.valueLabel === "string") &&
finiteOrNull(value.windowSeconds) &&
(value.resetsAt === null || isIsoDate(value.resetsAt)) &&
typeof value.measuredAt === "string" &&
isIsoDate(value.measuredAt) &&
typeof value.source === "string" &&
(value.state === "ok" || value.state === "error")
);
Expand All @@ -72,7 +72,7 @@ function isQuotaCurrentEntry(value: unknown): value is QuotaCurrentEntry {
typeof value.providerName === "string" &&
typeof value.serviceId === "string" &&
(value.state === "ok" || value.state === "error" || value.state === "unconfigured") &&
typeof value.measuredAt === "string" &&
isIsoDate(value.measuredAt) &&
typeof value.source === "string" &&
(value.credentialWatch === undefined || typeof value.credentialWatch === "boolean") &&
(value.error === undefined || typeof value.error === "string") &&
Expand Down
49 changes: 49 additions & 0 deletions pm-stack/aggregator/test/quota-current.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,3 +893,52 @@ describe("out-of-range pctOfLimit drops, never clamps (#2582)", () => {
});
});
});

describe("parseQuotaCurrent measuredAt gates (#4987)", () => {
test("an entry whose measuredAt is impossible or non-ISO is dropped; valid siblings survive", () => {
for (const bad of ["2026-02-30T07:00:00.000Z", "2026-04-31T07:00:00.000Z", "March 2, 2026"]) {
const doc = JSON.parse(
JSON.stringify(
file([
entry({ serviceId: "meta:high-usage", measuredAt: bad, windows: [win("weekly", 42, iso(5 * 60_000))] }),
entry({ serviceId: "openai:codex", windows: [win("7-day", 17, iso(5 * 60_000))] }),
]),
),
);
const parsed = parseQuotaCurrent(doc);
expect(parsed?.sanitized.droppedProviders).toBe(1);
expect(parsed?.providers.map((p) => p.serviceId)).toEqual(["openai:codex"]);
}
});

test("a window whose measuredAt is impossible or non-ISO is dropped without dropping valid sibling windows", () => {
for (const bad of ["2026-02-30T07:00:00.000Z", "2026-04-31T07:00:00.000Z", "March 2, 2026"]) {
const doc = JSON.parse(
JSON.stringify(
file([
entry({
serviceId: "openai:codex",
windows: [win("7-day", 17, iso(5 * 60_000)), win("weekly", 42, bad)],
}),
]),
),
);
const parsed = parseQuotaCurrent(doc);
expect(parsed?.sanitized.droppedWindows).toBe(1);
expect(parsed?.providers[0].windows.map((w) => w.name)).toEqual(["7-day"]);
}
});

test("leap-date and normal measuredAt stamps still validate", () => {
const leap = "2024-02-29T07:00:00.000Z";
const doc = JSON.parse(
JSON.stringify(
file([entry({ serviceId: "openai:codex", measuredAt: leap, windows: [win("7-day", 17, leap)] })]),
),
);
const parsed = parseQuotaCurrent(doc);
expect(parsed?.sanitized).toEqual({ droppedProviders: 0, droppedWindows: 0 });
expect(parsed?.providers).toHaveLength(1);
expect(parsed?.providers[0].windows).toHaveLength(1);
});
});