From 6154a42c0f575fc9db7424f009fe6d547605f028 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 10 Jul 2026 18:03:22 +0100 Subject: [PATCH] test(audit): prove invalid date filters stop before RPC (#103833) --- src/commands/audit.test.ts | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/commands/audit.test.ts b/src/commands/audit.test.ts index 69e65c94b47f..18630e927f33 100644 --- a/src/commands/audit.test.ts +++ b/src/commands/audit.test.ts @@ -1,5 +1,20 @@ import { describe, expect, it, vi } from "vitest"; -import { testApi } from "./audit.js"; +import type { RuntimeEnv } from "../runtime.js"; +import { auditListCommand, testApi } from "./audit.js"; + +const mocks = vi.hoisted(() => ({ + callGateway: vi.fn(), +})); + +vi.mock("../gateway/call.js", () => ({ + callGateway: mocks.callGateway, +})); + +const runtime: RuntimeEnv = { + log: vi.fn(), + error: vi.fn(), + exit: vi.fn(), +}; describe("audit command parsing", () => { it("parses ISO and millisecond timestamps", () => { @@ -17,6 +32,23 @@ describe("audit command parsing", () => { expect(() => testApi.parseAuditTimestamp("2026-02-30T00:00:00Z", flag)).toThrow(flag); }); + it.each(["--after", "--before"])("rejects parseable non-ISO values for %s", (flag) => { + for (const input of ["-1", "July 1, 2026"]) { + expect(Number.isNaN(Date.parse(input))).toBe(false); + expect(() => testApi.parseAuditTimestamp(input, flag)).toThrow(flag); + } + }); + + it.each([ + { flag: "--after", options: { after: "2026-02-30T00:00:00Z" } }, + { flag: "--before", options: { before: "July 1, 2026" } }, + ])("rejects invalid $flag before calling the Gateway", async ({ flag, options }) => { + mocks.callGateway.mockClear(); + + await expect(auditListCommand(options, runtime)).rejects.toThrow(flag); + expect(mocks.callGateway).not.toHaveBeenCalled(); + }); + it("keeps the original local-time result for timezone-less timestamps", () => { const input = "2026-07-01T00:00:00"; const localMs = 1_782_878_400_000;