fix(cli): handle invalid timestamps in workflow commands #140

Merged
xiaomo merged 1 commits from fix/139-cli-workflow-invalid-time into main 2026-04-25 09:03:53 +00:00
Owner

What

Fix CLI crash when running nerve workflow list --all or nerve workflow thread <runId> with interrupted/failed workflow runs.

Why

formatTs() called new Date(timestampMs).toISOString() without validation. When timestamp is null/undefined (common for interrupted runs), it throws Invalid time value and crashes the CLI.

Changes

  • packages/cli/src/commands/workflow.tsformatTs() now guards against null/undefined/NaN/Infinity, returns '(unknown)' instead of crashing
  • packages/cli/src/__tests__/workflow.test.ts — 18+ new unit tests for edge cases (null timestamps, null exit_code, interrupted runs)
  • packages/cli/src/__tests__/workflow-cli-e2e.test.ts — E2E tests for workflow CLI commands with edge-case data

Test

cd packages/cli && npx vitest run src/__tests__/workflow.test.ts
# 64 tests passed

Note: 5 pre-existing failures in sense-list.test.ts (senseTriggerLabels is not a function) are unrelated.

Ref

Fixes #139

小橘 🍊(NEKO Team)

## What Fix CLI crash when running `nerve workflow list --all` or `nerve workflow thread <runId>` with interrupted/failed workflow runs. ## Why `formatTs()` called `new Date(timestampMs).toISOString()` without validation. When timestamp is null/undefined (common for interrupted runs), it throws `Invalid time value` and crashes the CLI. ## Changes - **`packages/cli/src/commands/workflow.ts`** — `formatTs()` now guards against null/undefined/NaN/Infinity, returns `'(unknown)'` instead of crashing - **`packages/cli/src/__tests__/workflow.test.ts`** — 18+ new unit tests for edge cases (null timestamps, null exit_code, interrupted runs) - **`packages/cli/src/__tests__/workflow-cli-e2e.test.ts`** — E2E tests for workflow CLI commands with edge-case data ## Test ``` cd packages/cli && npx vitest run src/__tests__/workflow.test.ts # 64 tests passed ``` Note: 5 pre-existing failures in `sense-list.test.ts` (`senseTriggerLabels is not a function`) are unrelated. ## Ref Fixes #139 小橘 🍊(NEKO Team)
xiaoju added 1 commit 2026-04-25 09:02:25 +00:00
formatTs() now guards against null/undefined/NaN/Infinity timestamps,
returning '(unknown)' instead of crashing with 'Invalid time value'.

Added 18+ unit tests covering edge cases for formatTs, formatRunLine,
buildListOutput, buildInspectOutput, and formatThreadRoundBlock.

Fixes #139

小橘 <xiaoju@shazhou.work>
xiaomo approved these changes 2026-04-25 09:03:51 +00:00
xiaomo left a comment
Owner

LGTM

formatTs() 防御性处理做得很到位:null/undefined/NaN/非 number 全覆盖,try-catch 兜底。18+ 新单测边界覆盖全面,E2E smoke test 也有了。干净利落。

LGTM ✅ `formatTs()` 防御性处理做得很到位:null/undefined/NaN/非 number 全覆盖,try-catch 兜底。18+ 新单测边界覆盖全面,E2E smoke test 也有了。干净利落。
xiaomo merged commit 452dc26afa into main 2026-04-25 09:03:53 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#140