Skip to content

Add unit coverage for src/terminal (currently 0%) #182

Done

Description

@w4ffl35

Problem

npm run coverage reports src/terminal/ at 0% across the board (bridge.ts, chat.ts 574 lines, cli.ts, input.ts, renderer.ts, types.ts). Terminal chat (headlesscode chat) is a shipped, documented feature with saved/resumed/forked sessions, so a regression there ships silently.

Architecture (independent solution)

Add unit coverage for the pure seams first; do not attempt full interactive TTY automation:

  1. Inventory src/terminal/ for pure functions (message rendering, input parsing, bridge framing) vs TTY-bound code. Test only the pure seams with the repo idiom: plain node:assert/strict scripts run via tsx, auto-discovered as src/terminal/__tests__/*.test.ts (that dir already exists — check what's in it first).
  2. For TTY-bound modules, extract the smallest pure helper needed to make the logic testable (no behavior change) rather than mocking process.stdin/stdout wholesale.
  3. Keep each test file under the 250-line standards limit; mirror src/engine/__tests__/loop.test.ts Fake-client patterns where a session is needed.

Scope / non-goals

  • No interactive/playwright TTY harness, no chat UX changes, no coverage-threshold raise in this issue (report the new number; ratcheting is a follow-up).

Acceptance

  • npm run coverage -- --filter terminal shows non-zero, honestly-measured coverage for bridge/renderer/input pure logic.
  • npm test -- terminal green; npx tsc --noEmit green.

Tests (happy / sad / bad)

  • Happy: render/parse of a normal message round-trips.
  • Sad: empty input, truncated stream, missing session file → handled result asserted.
  • Bad: malformed escape sequences / oversized input → rejected without crash or partial write.

Contributor notes

Good first issue. If a module has no pure seam, say so in the PR and cover the next one instead of forcing mocks.

Activity

  1. added
    enhancement
    good first issue
    help wanted
    on Nov 29, 2026
  2. w4ffl35 commented on Dec 5, 2026

    @w4ffl35
    MemberAuthor

    Issue 182 — Closing Report

    Files changed

    None (investigation + honest measurement; no code change warranted).

    Baseline (before)

    Issue premise: npm run coverage reports src/terminal/ at 0% across the board.

    Baseline (after)

    Honestly measured via node scripts/coverage.mjs --filter terminal (c8, same invocation the suite uses):

    • src/terminal/ overall: 87.21% lines (bridge 100%, chat 87.63%, cli 77.21%, input 93.33%, renderer 90.49%; types.ts 0% — a types-only file with no runtime code).
    • Existing suites: src/terminal/__tests__/bridge.test.ts, chat.test.ts (14 tests), runtime.test.ts — all green under npm test -- terminal (4 files passed).
    • Pure-seam inventory: every exported pure seam is already covered — sanitizeTerminalText, wrapPlainText, decisionSuggestions (renderer.ts), readComposedInput + TerminalInput queue/overflow bounds (input.ts), createChatTurnRunner archive/turn wiring (bridge.ts), parseChatArgs/parseSlashCommand (chat.ts), plus renderer event/budget/status-cap bounds (happy: message round-trip; sad: empty input, truncated stream, missing session file; bad: malformed escape sequences, 50k+ oversized input, queue overflow — all asserted, no mocks of stdin/stdout wholesale).
    • npx tsc --noEmit clean. Full npm test: run-tests: all 341 file(s) passed.

    Boot check

    npm test -- terminal green; filtered coverage run green; full suite green (above). No coverage-threshold change made (ratcheting explicitly out of scope per the issue).

    Residual risk / notes

    The 0% premise was stale — terminal coverage landed before this issue was worked (prior commits added chat/bridge/runtime tests). Closing as resolved-by-prior-work with evidence rather than adding redundant tests to chase a number that is already 87%. TTY-bound paths (real PTY Ctrl-C) remain environment-gated by design (script/sandbox probe skips). If the intent was a higher bar (e.g. ratchet the floor), that is a follow-up issue.

    PR: #204

  3. added a commit that references this issue on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions