Skip to content

Add mock Claude client support for E2E testing#12220

Draft
mtsgrd wants to merge 1 commit intomasterfrom
mg-branch-5
Draft

Add mock Claude client support for E2E testing#12220
mtsgrd wants to merge 1 commit intomasterfrom
mg-branch-5

Conversation

@mtsgrd
Copy link
Contributor

@mtsgrd mtsgrd commented Feb 4, 2026

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 is part 2 of 2 in a stack made with GitButler:

@vercel
Copy link

vercel bot commented Feb 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gitbutler-web Ready Ready Preview, Comment Feb 5, 2026 11:42am

Request Review

@github-actions github-actions bot added rust Pull requests that update Rust code @gitbutler/desktop @gitbutler/ui labels Feb 4, 2026
@estib-vega
Copy link
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@gitbutler/desktop @gitbutler/ui rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants