Repository navigation
Conversation
[Low impact] The change stays within audit-event creation in the CLI. The PR appears safe to merge, with non-blocking improvements to timestamp type checks and tests. FindingsFix with agent prompt### Issue 1
src/commands/audit-log.ts:28-29
`parseOccurredAt` accepts boolean values from an event file. The type cast does not change the value at runtime, so `false` becomes the Unix epoch and `true` becomes one millisecond later. Both pass the date check and reach `createEvent`.
Reject values other than strings and numbers after handling the allowed empty values, so malformed input cannot silently become an unrelated event time.
### Issue 2
src/commands/audit-log.spec.ts:110-112
The default-time test accepts any valid `Date`, including a fixed date in 1970. The new invalid-input tests check only that something throws, not that the user sees `Invalid occurredAt`. These tests could stay green if either promised behavior breaks.
Freeze the clock and compare the default time exactly. Also check `stderrOutput` for the intended error text; the shared handler prints that text before throwing a separate `CliExit`.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryConverts file-based
Reviews (1) · Last reviewed commit: "fix(audit-log): parse occurredAt from --..." · Reviewed by Greptile |
| const date = new Date(value as string | number | Date); | ||
| if (Number.isNaN(date.getTime())) { |
There was a problem hiding this comment.
Booleans become unrelated event times
parseOccurredAt accepts boolean values from an event file. The type cast does not change the value at runtime, so false becomes the Unix epoch and true becomes one millisecond later. Both pass the date check and reach createEvent.
Reject values other than strings and numbers after handling the allowed empty values, so malformed input cannot silently become an unrelated event time.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/audit-log.ts
Line: 28-29
Comment:
**Booleans become unrelated event times**
`parseOccurredAt` accepts boolean values from an event file. The type cast does not change the value at runtime, so `false` becomes the Unix epoch and `true` becomes one millisecond later. Both pass the date check and reach `createEvent`.
Reject values other than strings and numbers after handling the allowed empty values, so malformed input cannot silently become an unrelated event time.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| const [, event] = mockSdk.auditLogs.createEvent.mock.calls[0]; | ||
| expect(event.occurredAt).toBeInstanceOf(Date); | ||
| expect(Number.isNaN(event.occurredAt.getTime())).toBe(false); |
There was a problem hiding this comment.
The default-time test accepts any valid Date, including a fixed date in 1970. The new invalid-input tests check only that something throws, not that the user sees Invalid occurredAt. These tests could stay green if either promised behavior breaks.
Freeze the clock and compare the default time exactly. Also check stderrOutput for the intended error text; the shared handler prints that text before throwing a separate CliExit.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/audit-log.spec.ts
Line: 110-112
Comment:
**Tests miss time and message**
The default-time test accepts any valid `Date`, including a fixed date in 1970. The new invalid-input tests check only that something throws, not that the user sees `Invalid occurredAt`. These tests could stay green if either promised behavior breaks.
Freeze the clock and compare the default time exactly. Also check `stderrOutput` for the intended error text; the shared handler prints that text before throwing a separate `CliExit`.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Fixes #254.
workos audit-log create-event <org> --file event.jsonpassed the parsed JSON straight to the SDK, sooccurredAtstayed a string andserializeCreateAuditLogEventOptionsfailed onevent.occurredAt.toISOString()before any request went out. The flag path already turned--occurred-atinto aDate.This adds a small
parseOccurredAthelper used by both paths:--occurred-atbecomes aDateInvalid occurredAt: ...instead of reaching the SDK and failing with aRangeErrorfromtoISOString()The existing "creates event from file" test asserted the string was passed through unchanged, so I updated it to expect a
Dateand added tests for a file withoutoccurredAtand for invalid values from the file and the flag.Testing:
vitest run src/commands/audit-log.spec.ts: the 4 new/updated tests fail on main and pass with the change; fullvitest runis green (185 files, 3499 tests)tsc --noEmit,oxlintandoxfmt --checkpassrunAuditLogCreateEventwith the JSON file from the issue against a local HTTP server: on main it fails withevent.occurredAt.toISOString is not a function; with the change the server receives"occurred_at":"2026-09-28T08:53:08.000Z"AI-assisted; I reproduced the bug and ran the checks above myself.