add examples, end-to-end tests, and Cargo.lock
Three examples: - basic.rs: query() one-shot prompt + cost reporting. - with_options.rs: system_prompt, model selection, effort, permission mode. - interactive.rs: Client multi-turn session with two back-to-back sends. Integration tests in tests/transport_end_to_end.rs spawn a tiny POSIX shell script (tests/fake_cli/fake-claude.sh) as a stand-in for the real claude CLI. The fake answers -v with a version, reads one user-message frame on stdin, and emits a fixed assistant + result pair on stdout, then blocks on stdin until close. This proves the spawn / write / read / disconnect lifecycle works without an authenticated claude install. Coverage: - query() round-trip: stream yields Assistant then Result. - Client round-trip: connect + send + drain to Result + disconnect. - CLI-not-found surfaces as a typed Error::CliNotFound. Cargo.lock is committed since this is, in practice, both a library and a binary (the examples link the crate). Locking dev-deps avoids surprise churn in CI.
This commit is contained in:
parent
6fab3d4581
commit
ecdb97f455
6 changed files with 795 additions and 0 deletions
20
tests/fake_cli/fake-claude.sh
Executable file
20
tests/fake_cli/fake-claude.sh
Executable file
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
# Tiny fake `claude` CLI for integration tests. Mimics the wire protocol:
|
||||
# reads newline-delimited JSON frames on stdin, emits assistant + result
|
||||
# frames on stdout. Echoes whatever the user said.
|
||||
#
|
||||
# Args: ignores everything except `-v` (prints a version, exits 0).
|
||||
|
||||
if [ "$1" = "-v" ]; then
|
||||
echo "2.1.0 (Claude Code)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Read one user-message frame (we don't actually parse it — just block on stdin).
|
||||
# After the first newline we emit one assistant message + one result message.
|
||||
read -r FIRST_LINE
|
||||
printf '{"type":"assistant","message":{"role":"assistant","content":[{"type":"text","text":"hello from fake"}],"model":"fake-model"},"session_id":"s1","uuid":"u1"}\n'
|
||||
printf '{"type":"result","subtype":"success","duration_ms":1,"duration_api_ms":1,"is_error":false,"num_turns":1,"session_id":"s1","total_cost_usd":0.0001}\n'
|
||||
|
||||
# Stay alive until stdin closes (so the parent can drain stdout cleanly).
|
||||
cat > /dev/null
|
||||
Loading…
Add table
Add a link
Reference in a new issue