Skip to content

Phase 3: Claude live test suite #6

Description

@tinkermonkey

Create the live Claude Code test file with six test cases that exercise CliProcess against the real claude binary. Tests gate on binary availability and credential presence, assert on event stream structure only (never on LLM-generated text), and run serially.

Requirements

  • Create src/__tests__/live/claude.live.test.ts
  • Entire suite must be gated in beforeAll using describe.skipIf(!claudeAvailable || !hasCredentials) — no test should fail if prerequisites are absent
  • Use collectLive() and assertEventStreamStructure() from Phase 1 helpers
  • Implement six test cases:
    1. Golden path: trivial prompt ("respond with exactly the word hello"), call assertEventStreamStructure(), assert DoneEvent.usage.inputTokens > 0 and usage.outputTokens > 0
    2. ReadyEvent fields: assert ReadyEvent.sessionId is a non-empty string and ReadyEvent.model is truthy
    3. Session resume: two sequential runs; second run uses isFirstMessage: false with sessionId from first run's DoneEvent; assert second ReadyEvent.sessionId matches captured ID; assert no ErrorEvent in either run
    4. AbortSignal mid-run: prompt for a long response, abort after ReadyEvent is received; assert final event is ErrorEvent { code: 'aborted' }
    5. OAuth auth path: skip individually if CLAUDE_CODE_OAUTH_TOKEN not present; run with only OAuth token in subprocess env; assert no ErrorEvent
    6. API key auth path: skip individually if ANTHROPIC_API_KEY not present; run with only API key in subprocess env; assert no ErrorEvent
  • Each test must set maxTimeout: 60 on ProcessOptions to prevent zombie processes
  • Tests must never assert on specific generated text content

Design Guidance

Implements the 'Claude Live Test Suite' section of the architecture design. The six test cases, their prompt strings, assertion strategies, and gating patterns are fully specified in the architecture's component design table for claude.live.test.ts. The credential isolation approach (removing unused credential from subprocess env) is documented in the architecture's auth path coverage section.

Acceptance Criteria

  • npm run test:live with no credentials set shows all Claude live tests as skipped (not failed)
  • npm run test:live with valid ANTHROPIC_API_KEY runs all six tests and they pass
  • Golden path test collects exactly one ReadyEvent, at least one TextEvent, and exactly one DoneEvent
  • Session resume test confirms second run's ReadyEvent.sessionId matches first run's DoneEvent.sessionId
  • AbortSignal test confirms final event has type === 'error' and code === 'aborted'
  • OAuth test is individually skipped when CLAUDE_CODE_OAUTH_TOKEN is absent
  • No test asserts on LLM-generated string content
  • Code is reviewed and approved

Dependencies

Phase 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions