Add mock Claude client support for E2E testing#12220
Draft
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
oooh cool |
Introduces a testing framework for Claude integration that allows Playwright tests to run with deterministic, pre-recorded Claude interactions instead of the real Claude CLI. This enables reliable, fast E2E testing of permission flows and user interactions without requiring an actual Claude API connection. Key components: - Mock scenario loader (mock_scenario.rs) that reads session snapshots from JSON files and creates mock transports for the Claude Agent SDK - Three initial test scenarios covering common permission flows: * permission-bash-echo.json - Basic Bash tool approval * permission-wildcard-test.json - Wildcard permission scoping * ask-user-question.json - AskUserQuestion tool interaction - Integration in session.rs via `testing` feature flag and CLAUDE_MOCK_SCENARIO environment variable - E2E test suite (claudePermissions.spec.ts) demonstrating permission approval UI interactions - Improved test stability with process cleanup and RUST_LOG passthrough The mock scenarios use the SDK's SessionSnapshot format and handle permission callback timing automatically - when a control_request appears in the scenario, subsequent messages are held until the SDK responds with control_response. Each test specifies its own scenario by passing CLAUDE_MOCK_SCENARIO to startGitButler(), which spawns a fresh but-server process with that env var.
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.
Introduces a testing framework for Claude integration that allows Playwright
tests to run with deterministic, pre-recorded Claude interactions instead of
the real Claude CLI. This enables reliable, fast E2E testing of permission
flows and user interactions without requiring an actual Claude API connection.
Key components:
JSON files and creates mock transports for the Claude Agent SDK
testingfeature flag and CLAUDE_MOCK_SCENARIOenvironment variable
UI interactions
The mock scenarios use the SDK's SessionSnapshot format and handle permission
callback timing automatically - when a control_request appears in the scenario,
subsequent messages are held until the SDK responds with control_response.
Each test specifies its own scenario by passing CLAUDE_MOCK_SCENARIO to
startGitButler(), which spawns a fresh but-server process with that env
var.
This is part 2 of 2 in a stack made with GitButler: