Repository navigation
Conversation
ClaudeAgentSDK::Testing::Cassette (require 'claude_agent_sdk/testing/cassette') records a session's stream-JSON frames to a JSONL file through the real transport and replays them in tests by playing the CLI's side: hooks, can_use_tool and SDK MCP tools run for real, and every frame the SDK writes is compared with the recording. Mismatches raise MismatchError from the read loop, so they reach query / ask / Client; verify! reports what a replay never reached. Options-fingerprint and pinned-CLI drift only warn. Built only on the public Transport contract; no existing code changes. Amp-Thread-ID: https://ampcode.com/threads/T-01a19fec-39e9-76e0-9914-6c8ab560a0c9 Co-authored-by: ya-luotao <luotao@hey.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
ClaudeAgentSDK::Testing::Cassette(require 'claude_agent_sdk/testing/cassette'): record a session's stream-JSON frames to a JSONL file once, then replay them in tests with no CLI subprocess and no API call.How it works
end_input/close. Hooks,can_use_tooland SDK MCP tools run for real, and what they send back is compared with the recording (match: :strictby default,:type, or any#callable).Cassette::MismatchErrorfrom the transport's read loop, so they surface fromquery/ask/Client. Raising from#writewould be swallowed:Query#handle_control_requesttreats a failed write of a control response as a callback failure (verified with a prototype).verify!pairs anything the SDK still wrote, ended or closed once it stopped reading, and reports mismatches, unreached events and unopened connections.verify!raisesCassette::Error.PINNED_CLI_VERSIONdrift only warn.Built only on the public
Transportcontract: no existing library code changes. Not loaded by a plainrequire 'claude_agent_sdk'(pinned inrequire_surface_spec).Deliberate trade-off
CLI output the SDK never read (an early
breakor disconnect) is not reported. A replay cannot tell whether test code used what the SDK delivered, sodocs/testing.mdtells users to assert on the result. A strict mode with an opt-in for truncation can be added later.Testing
spec/unit/testing/cassette_spec.rb. Recordings go through the realSubprocessCLITransportagainstFakeClaude; the executable is deleted before replay. Concurrency cases (close vs. in-flight write, publish ordering, concurrent closes, cancelled close) are pinned with method-level TracePoint hooks or stub transports, not source line numbers.bundle exec rspec4404/0,bundle exec rubocopclean,bundle exec rake rbs:validate rbs:test3993/0.Not yet done (P2): redaction, RSpec sugar, a recorded real-CLI integration example.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.