fix: CLI workflow commands crash on Invalid time value + improve test coverage #139

Closed
opened 2026-04-25 08:55:04 +00:00 by xiaoju · 0 comments
Owner

Bug

nerve workflow list --all and nerve workflow thread <runId> crash with:

ERROR  Invalid time value
    at Date.toISOString (<anonymous>)
    at formatTs (cli.js:1205:25)

Root Cause

formatTs() in packages/cli/src/commands/workflow.ts:31 calls new Date(timestampMs).toISOString() without validating the input. When timestamp is null, undefined, or an invalid number, new Date() returns Invalid Date and .toISOString() throws.

Repro

  1. Run a workflow that gets interrupted (exit_code=null, possibly null timestamps in thread events)
  2. nerve workflow list --all → crash
  3. nerve workflow thread <runId> → crash

Fix Required

  1. formatTs(): Guard against invalid/null timestamps — return a fallback string like '(unknown)' instead of crashing
  2. Audit all callers: formatRunLine, formatThreadRoundBlock, buildThreadCommandOutput — ensure they handle null/undefined timestamps before passing to formatTs

Test Coverage

The existing packages/cli/src/__tests__/workflow.test.ts (546 lines) needs expansion:

Unit tests to add:

  • formatTs() with null, undefined, NaN, negative, 0, and valid timestamps
  • formatRunLine() / buildListOutput() with workflow runs that have null exit_code and edge-case timestamps
  • formatThreadRoundBlock() with null/missing timestamp in thread events
  • All formatter functions with interrupted/failed run data

E2E tests to add:

  • nerve workflow list --all against a real DB with mixed completed/interrupted/failed runs
  • nerve workflow thread <runId> for interrupted runs (the exact scenario that crashes)
  • nerve workflow inspect <runId> with edge cases
  • Verify CLI exits cleanly (exit code 0) even when data has nulls

Files

  • packages/cli/src/commands/workflow.ts — bug fix + formatter hardening
  • packages/cli/src/__tests__/workflow.test.ts — expand unit + e2e tests

Ref

Discovered via nerve workflow list --all --workflow workflow-generator crashing on interrupted runs.

小橘 🍊(NEKO Team)

## Bug `nerve workflow list --all` and `nerve workflow thread <runId>` crash with: ``` ERROR Invalid time value at Date.toISOString (<anonymous>) at formatTs (cli.js:1205:25) ``` ### Root Cause `formatTs()` in `packages/cli/src/commands/workflow.ts:31` calls `new Date(timestampMs).toISOString()` without validating the input. When `timestamp` is `null`, `undefined`, or an invalid number, `new Date()` returns `Invalid Date` and `.toISOString()` throws. ### Repro 1. Run a workflow that gets interrupted (exit_code=null, possibly null timestamps in thread events) 2. `nerve workflow list --all` → crash 3. `nerve workflow thread <runId>` → crash ### Fix Required 1. **`formatTs()`**: Guard against invalid/null timestamps — return a fallback string like `'(unknown)'` instead of crashing 2. **Audit all callers**: `formatRunLine`, `formatThreadRoundBlock`, `buildThreadCommandOutput` — ensure they handle null/undefined timestamps before passing to `formatTs` ## Test Coverage The existing `packages/cli/src/__tests__/workflow.test.ts` (546 lines) needs expansion: ### Unit tests to add: - `formatTs()` with null, undefined, NaN, negative, 0, and valid timestamps - `formatRunLine()` / `buildListOutput()` with workflow runs that have null exit_code and edge-case timestamps - `formatThreadRoundBlock()` with null/missing timestamp in thread events - All formatter functions with interrupted/failed run data ### E2E tests to add: - `nerve workflow list --all` against a real DB with mixed completed/interrupted/failed runs - `nerve workflow thread <runId>` for interrupted runs (the exact scenario that crashes) - `nerve workflow inspect <runId>` with edge cases - Verify CLI exits cleanly (exit code 0) even when data has nulls ## Files - `packages/cli/src/commands/workflow.ts` — bug fix + formatter hardening - `packages/cli/src/__tests__/workflow.test.ts` — expand unit + e2e tests ## Ref Discovered via `nerve workflow list --all --workflow workflow-generator` crashing on interrupted runs. 小橘 🍊(NEKO Team)
This repo is archived. You cannot comment on issues.
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#139