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
6 changes: 3 additions & 3 deletions pm-stack/aggregator/src/credential-lifecycle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { QuotaCurrentEntry } from "./model.ts";
import { isIsoDate } from "./validate.ts";

export type CredentialLifecycleState =
| "ok"
Expand Down Expand Up @@ -106,10 +107,9 @@ export function isCredentialLifecycleRow(value: unknown): value is CredentialLif
typeof row.label === "string" &&
typeof row.state === "string" &&
states.includes(row.state as CredentialLifecycleState) &&
typeof row.measuredAt === "string" &&
isIsoDate(row.measuredAt) &&
(row.credentialId === undefined || typeof row.credentialId === "string") &&
(row.expiresAt === undefined ||
(typeof row.expiresAt === "string" && Number.isFinite(Date.parse(row.expiresAt)))) &&
(row.expiresAt === undefined || isIsoDate(row.expiresAt)) &&
Comment on lines +110 to +112
(row.reason === undefined || typeof row.reason === "string") &&
(row.userAction === undefined ||
(typeof row.userAction === "object" &&
Expand Down
18 changes: 17 additions & 1 deletion pm-stack/aggregator/test/credential-lifecycle.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test";
import { buildAttentionFlags } from "../src/derive.ts";
import { lifecycleForEntry, safeProviderReason } from "../src/credential-lifecycle.ts";
import { isCredentialLifecycleRow, lifecycleForEntry, safeProviderReason } from "../src/credential-lifecycle.ts";
import { renderQuota } from "../src/render.ts";
import { overlayQuotaCurrent } from "../src/quota-current.ts";
import { sanitizeQuotaView } from "../src/feed.ts";
Expand Down Expand Up @@ -46,6 +46,22 @@ describe("credential lifecycle", () => {
expect(lifecycleForEntry(entry(), NOW).state).toBe("unknown");
});

test("requires valid ISO dates for lifecycle rows and counts refused rows", () => {
const valid = lifecycleForEntry(entry({ credentialExpiresAt: "2026-11-05T10:00:00.000Z" }), NOW);
expect(isCredentialLifecycleRow(valid)).toBe(true);
expect(isCredentialLifecycleRow({ ...valid, measuredAt: "not-a-date" })).toBe(false);
expect(isCredentialLifecycleRow({ ...valid, measuredAt: "2026-02-30T00:00:00.000Z" })).toBe(false);
expect(isCredentialLifecycleRow({ ...valid, expiresAt: "2026-02-30T00:00:00.000Z" })).toBe(false);
expect(isCredentialLifecycleRow({ ...valid, expiresAt: "March 3, 2026" })).toBe(false);

const sanitized = sanitizeQuotaView({
...emptyView(),
credentialLifecycle: [{ ...valid, measuredAt: "not-a-date" }],
});
expect(sanitized.droppedCredentialLifecycle).toBe(1);
expect(sanitized.view.dropped?.credentialLifecycle).toBe(1);
});

test("keeps not-configured distinct from provider errors and only labels explicit rejection", () => {
expect(lifecycleForEntry(entry({ state: "unconfigured" }), NOW).state).toBe("not-configured");
expect(lifecycleForEntry(entry({ state: "error", error: "HTTP 401" }), NOW).state).toBe("provider-error");
Expand Down
Loading