fix(ui): ignore invalid usage export timestamps

This commit is contained in:
Peter Steinberger
2026-05-30 06:06:19 -04:00
parent 54bbe87cd5
commit 439c09668e
2 changed files with 21 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
// @vitest-environment node
import { describe, expect, it } from "vitest";
import { buildSessionsCsv } from "./usage-query.ts";
import type { UsageSessionEntry } from "./usageTypes.ts";
describe("usage query CSV export", () => {
it("omits invalid session updated timestamps instead of throwing", () => {
const csv = buildSessionsCsv([
{
key: "session-1",
label: "Session 1",
updatedAt: Number.POSITIVE_INFINITY,
usage: null,
} satisfies UsageSessionEntry,
]);
expect(csv).toContain("session-1,Session 1,,,,,,,,,,,,,,,");
});
});

View File

@@ -1,3 +1,4 @@
import { timestampMsToIsoString } from "../../../../src/shared/number-coercion.js";
import { normalizeLowercaseStringOrEmpty, uniqueStrings } from "../string-coerce.ts";
import { extractQueryTerms } from "../usage-helpers.ts";
import type { CostDailyEntry, UsageAggregates, UsageSessionEntry } from "./usageTypes.ts";
@@ -63,7 +64,7 @@ const buildSessionsCsv = (sessions: UsageSessionEntry[]): string => {
session.channel ?? "",
session.modelProvider ?? session.providerOverride ?? "",
session.model ?? session.modelOverride ?? "",
session.updatedAt ? new Date(session.updatedAt).toISOString() : "",
timestampMsToIsoString(session.updatedAt) ?? "",
usage?.durationMs ?? "",
usage?.messageCounts?.total ?? "",
usage?.messageCounts?.errors ?? "",