بنقرة واحدة
e2e-agent-testing
Strategy for mocking Claude Code agents in E2E tests with canary validation against real behavior.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Strategy for mocking Claude Code agents in E2E tests with canary validation against real behavior.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Make Codex CLI behave more like Claude Code for Kookr by preserving the known fork, branch, build, deploy, daily upstream sync, and live-verification workflow for Claude-compatible skills, agents, settings, hooks, and related UX.
Kookr-internal extension to rfc-iterative-review that captures append-only critic traces for later meta-analysis of RFC reviewer subagents.
Analyze an open question by casting 3-5 deliberately conflicting expert roles, running them in parallel and blind to each other, sharpening them in a debate round, attacking their consensus with a devil's advocate, then synthesizing a verdict that preserves disagreement instead of averaging it. Use for decisions, strategy, idea generation, hypothesis triage, experiment post-mortems, or any question where a single lens would return "it depends".
Iterative RFC drafting workflow — draft in worktree, run parallel critic subagents, incorporate feedback over N rounds, present to user before any action
How to create, structure, and launch Kookr playbook tasks — reusable agent task templates with dynamic sources and project identity
Build a Ralph-like sequential Kookr task chain where each task completes one independent unit, records durable state, and spawns the next task with the same continuation contract. Use for issue batches, queue drains, staged migrations, or other long runs that should proceed one task at a time without relying on conversation memory.
| name | e2e-agent-testing |
| description | Strategy for mocking Claude Code agents in E2E tests with canary validation against real behavior. |
| keywords | e2e, mock, agent, claude code, haiku, canary test, FakeTerminalBackend, hook event, end-to-end, integration, cost |
| related | testing-patterns, playwright-e2e-patterns |
Most E2E tests should mock Claude Code using FakeTerminalBackend and event injection. One opt-in canary test validates that mocks match real Claude Code behavior. If Claude Code changes its hook event format, the canary test breaks first, the mock fixtures get updated, and all other tests stay accurate.
┌─────────────────────────────────────────────────────┐
│ e2e/canary.spec.ts (CANARY=1, real Claude + Haiku) │
│ Validates: mock event shapes match real behavior │
│ Runs: locally before merge (PR checklist item) │
└──────────────────────┬──────────────────────────────┘
│ if drift detected, update ↓
┌──────────────────────▼──────────────────────────────┐
│ e2e/fixtures/mock-events.ts │
│ Source of truth for mock hook events │
│ Used by: all E2E tests + unit tests │
└──────────────────────┬──────────────────────────────┘
│ imported by ↓
┌──────────────────────▼──────────────────────────────┐
│ e2e/kookr.spec.ts (fast, no real Claude) │
│ Uses: FakeTerminalBackend + inject-event endpoint │
│ Runs: every PR, every push │
└─────────────────────────────────────────────────────┘
| Scenario | Approach | Why |
|---|---|---|
| UI behavior (triage, launch, rename, keyboard) | Mock (FakeTerminalBackend + event injection) | No real agent needed; fast, deterministic |
| Anomaly detection (needs_input, permission_blocked) | Mock (inject specific hook events) | Tests detection logic, not Claude Code |
| Hook event parsing correctness | Unit test (hook-parser.test.ts) | Pure function, no I/O |
| Hook event shape still matches real Claude Code | Canary test (real Claude + Haiku) | Catches contract drift |
| Full agent lifecycle (launch, work, complete) | Mock for CI; canary for validation | Real agents are slow and cost money |
All E2E and most integration tests use FakeTerminalBackend instead of a real dtach-backed terminal. It's an in-memory implementation of the TerminalBackend interface that records calls without launching real processes.
src/adapters/fake-terminal-backend.tse2e/test-server.ts, most src/**/*.test.ts filesThe E2E test server exposes POST /api/test/inject-event to feed hook events directly into the ClaudeCodeAdapter, bypassing the hook file watcher. This lets tests simulate any agent behavior sequence.
// Inject a Stop event (triggers needs_input anomaly)
await request.post(`${BASE}/api/test/inject-event`, {
data: { tmuxName, event: mockStop() },
});
e2e/fixtures/mock-events.ts provides typed builders for every hook event type, plus shape metadata used by the canary test.
import { mockSessionStart, mockStop, mockPreToolUse } from './fixtures/mock-events';
// Use in E2E tests
await injectEvent(request, tmuxName, mockSessionStart());
await injectEvent(request, tmuxName, mockStop({ last_assistant_message: 'Custom message' }));
e2e/canary.spec.ts launches a real Claude Code instance with Haiku model (cheapest, fastest), captures the hook events it emits, and validates them against the mock fixture shapes.
# Run canary test (requires Claude Code CLI + API key)
CANARY=1 npx playwright test e2e/canary.spec.ts
# Cost: ~$0.001 per run (Haiku, trivial task)
# Duration: ~10-30 seconds
When to run it:
CANARY=1 npx playwright test e2e/canary.spec.ts
Requires: claude CLI, ANTHROPIC_API_KEY in env.
What it validates:
session_id, transcript_path, cwd, hook_event_nametool_namestop_hook_activeparseHookEvent() without errorsWhen adding a new E2E test:
FakeTerminalBackend — the test server already does thise2e/fixtures/mock-events.ts/api/test/inject-event to simulate agent behavior// Good: mock-based E2E test
test('new anomaly type appears as finding', async ({ page, request }) => {
await launchViaUI(page, 'Task', '/test/project');
const tmuxName = await getLatestTmuxName(request);
await injectEvent(request, tmuxName, mockSessionStart());
await injectEvent(request, tmuxName, mockStop());
await expect(page.locator('.finding-card')).toBeVisible();
});
Only in explicitly opt-in tests:
--model haiku to minimize costCANARY=1 environment variableWhen the canary test fails:
e2e/fixtures/mock-events.ts to match the new shapesrc/core/hook-parser.ts if the parsing contract changede2e/fixtures/mock-events.ts — Mock event builderse2e/canary.spec.ts — Canary validation teste2e/test-server.ts — E2E server with FakeTerminalBackendsrc/adapters/fake-terminal-backend.ts — In-memory terminal mocksrc/core/hook-parser.ts — Hook event parsing contract