Skip to content

test: comprehensive shell passthrough test suite + extract into library#81

Merged
emal-avala merged 2 commits intomainfrom
feat/shell-passthrough-tests
Apr 6, 2026
Merged

test: comprehensive shell passthrough test suite + extract into library#81
emal-avala merged 2 commits intomainfrom
feat/shell-passthrough-tests

Conversation

@emal-avala
Copy link
Copy Markdown
Member

Summary

Extracts shell passthrough logic into a testable library module and adds 40 tests across 3 layers.

What changed

New module: crates/lib/src/services/shell_passthrough.rs (519 lines)

Extracts the ! prefix logic from repl.rs into reusable, testable functions:

  • capture_lines() — reads from any Read impl, captures to buffer with 50KB limit
  • run_and_capture() — spawns bash subprocess, streams output, returns CapturedOutput
  • build_context_message() — builds UserMessage(is_meta: true) from captured output

Refactored: crates/cli/src/ui/repl.rs (92 lines → 19 lines)

The ! handler now calls the library module. Same behavior, 73 fewer lines.

Test coverage

25 unit tests (in shell_passthrough.rs):

Category Tests What they verify
capture_lines 6 Under limit, truncation, empty, single line, callbacks after truncation, exact boundary
build_context_message 5 Header format, truncation suffix, empty→None, multiline, special chars
run_and_capture 10 stdout, stderr, mixed, multiline, empty, exit codes, cwd, callbacks, truncation, invalid cmd
Full pipeline 3 echo→message, empty→None, truncated→suffix

11 integration tests (in shell_passthrough_integration.rs):

Category Tests What they verify
Message system 3 Valid UserMessage, alternation compatibility, JSON roundtrip
Subprocess 5 cwd, exit codes, binary output, 500-line capture, complete lines on truncation
Content format 3 Header format, suffix position, special character preservation

4 E2E bash tests (section L in e2e-tests.sh):

Test What it verifies
L1 Tool output appears in /messages conversation history
L2 Multi-turn context retention with tool output
L3 Large output handling (1000 lines, no crash)
L4 stderr captured alongside stdout

Test results

621 tests total, 0 failures, 0 ignored
cargo clippy: 0 warnings
cargo fmt: clean

Test plan

  • cargo fmt --all -- --check — clean
  • cargo clippy -- -D warnings — zero warnings
  • cargo test — 621 tests pass (40 new)
  • E2E bash tests (L1-L4) require API key — tested in CI via release-e2e.yml

🤖 Generated with Claude Code

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Extract shell passthrough logic from repl.rs into a testable library
module at crates/lib/src/services/shell_passthrough.rs, then add tests
at every level:

Unit tests (25 tests in shell_passthrough.rs):
- capture_lines: under limit, truncation, empty, single line, callback
  called after truncation, exact boundary behavior
- build_context_message: header format, truncation suffix, empty returns
  None, multiline preservation, special characters
- run_and_capture: stdout, stderr, mixed, multiline, empty command, exit
  codes, cwd respect, callbacks, truncation, invalid commands
- Full pipeline: echo→message, empty→None, truncated→suffix

Integration tests (11 tests in shell_passthrough_integration.rs):
- Message system compatibility: valid UserMessage, alternation safe,
  serialization roundtrip
- Subprocess integration: cwd respect, exit codes, binary output,
  500-line capture, truncation preserves complete lines
- Content format: header format, truncation suffix position, special
  character preservation

E2E bash tests (4 tests in scripts/e2e-tests.sh section L):
- L1: Tool output appears in /messages conversation history
- L2: Multi-turn context retention with tool output
- L3: Large output handling (1000 lines)
- L4: stderr captured alongside stdout

Refactor: repl.rs ! prefix handler now calls shell_passthrough module
(19 lines vs 92 lines previously). Same behavior, fully testable.
@emal-avala emal-avala force-pushed the feat/shell-passthrough-tests branch from 9a96b71 to a7ae627 Compare April 6, 2026 20:11
@emal-avala emal-avala merged commit 78c7d21 into main Apr 6, 2026
13 of 14 checks passed
@emal-avala emal-avala deleted the feat/shell-passthrough-tests branch April 6, 2026 22:17
@emal-avala emal-avala mentioned this pull request Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant