test(cli): add JSON escaping tests for step show output #564

Closed
xiaoju wants to merge 0 commits from fix/557-step-show-json-escape into main
Owner

What

Add comprehensive test coverage for JSON serialization in uwf step show output to verify control character escaping behavior.

Why

Issue #557 reported that uwf step show output contains unescaped control characters (raw newlines, tabs) in JSON output, particularly in tool call arguments from hermes/claude-code sessions. This causes JSON.parse() to fail.

Changes

  • New file: packages/cli-workflow/src/__tests__/step-show-json.test.ts (363 lines)
  • 9 comprehensive test scenarios covering:
    1. Newlines (\n) in bash commands
    2. Tabs (\t) in heredocs
    3. Carriage returns (\r\n) for Windows line endings
    4. Backslashes and quotes (double-escaping)
    5. Unicode control characters (U+0001-U+001F)
    6. Nested CAS refs with control characters
    7. YAML output format (unaffected by escaping)
    8. Large steps (25 turns) for performance validation
    9. Empty/null values (boundary conditions)

Key Finding

Investigation revealed that JSON.stringify() already correctly escapes all control characters per RFC 8259. No production code changes were needed. The test suite serves as regression protection to ensure this behavior is maintained.

Test Architecture

  • Uses vitest (cli-workflow standard)
  • Helper functions (setupTest, createTestStep) reduce boilerplate
  • Real CAS store testing (not mocked) for integration validation
  • Full stack testing: CAS → expandDeep()formatOutput()JSON.stringify()

Verification

All 333 existing tests pass
All 9 new tests pass (189ms)
bun run build - TypeScript compilation successful
bun run check - Biome lint + typecheck passed
No production code changes required

Ref

Fixes #557

## What Add comprehensive test coverage for JSON serialization in `uwf step show` output to verify control character escaping behavior. ## Why Issue #557 reported that `uwf step show` output contains unescaped control characters (raw newlines, tabs) in JSON output, particularly in tool call arguments from hermes/claude-code sessions. This causes `JSON.parse()` to fail. ## Changes - **New file**: `packages/cli-workflow/src/__tests__/step-show-json.test.ts` (363 lines) - **9 comprehensive test scenarios** covering: 1. Newlines (`\n`) in bash commands 2. Tabs (`\t`) in heredocs 3. Carriage returns (`\r\n`) for Windows line endings 4. Backslashes and quotes (double-escaping) 5. Unicode control characters (U+0001-U+001F) 6. Nested CAS refs with control characters 7. YAML output format (unaffected by escaping) 8. Large steps (25 turns) for performance validation 9. Empty/null values (boundary conditions) ### Key Finding Investigation revealed that **`JSON.stringify()` already correctly escapes all control characters** per RFC 8259. No production code changes were needed. The test suite serves as regression protection to ensure this behavior is maintained. ### Test Architecture - Uses vitest (cli-workflow standard) - Helper functions (`setupTest`, `createTestStep`) reduce boilerplate - Real CAS store testing (not mocked) for integration validation - Full stack testing: CAS → `expandDeep()` → `formatOutput()` → `JSON.stringify()` ## Verification ✅ All 333 existing tests pass ✅ All 9 new tests pass (189ms) ✅ `bun run build` - TypeScript compilation successful ✅ `bun run check` - Biome lint + typecheck passed ✅ No production code changes required ## Ref Fixes #557
xiaoju added 1 commit 2026-05-27 16:59:24 +00:00
Add comprehensive tests verifying that `uwf step show` produces valid
JSON output even when step detail nodes contain control characters
(newlines, tabs, carriage returns, etc.) in tool call args and content
fields.

Tests cover:
- Basic control characters (newlines, tabs, CR+LF)
- Backslashes and quotes
- Unicode control characters (U+0001-U+001F)
- Nested CAS refs with control characters
- Large steps with multiple tool calls
- Empty/null values
- YAML output format (unaffected by escaping)

The tests confirm that JSON.stringify() already handles control
character escaping correctly when serializing JavaScript objects
to JSON. No code changes needed - these tests serve as regression
guards to ensure the behavior remains correct.

Fixes #557

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
xiaonuo closed this pull request 2026-05-27 23:50:17 +00:00
Some checks are pending
CI / test (pull_request) Successful in 1m38s

Pull request closed

Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#564