integration-test
Skill16 starsChanged 3 months agoApache-2.0View on GitHub
Write an end-to-end integration test that exercises a runtime path against the REAL Claude Code CLI driven by a mock Anthropic API. Use to prove a behavioural acceptance criterion actually works (session spawn, agent tools, permission flow, scheduled jobs, model selection, system-prompt injection) rather than that the code merely exists. This is how you catch "code is present and renders but the feature is dead" bugs that unit tests and static review miss.
- Reads credentials
5 other projects use a version of this.
Adopted by
Most recently taken up by
- DongDuong2001/pudo-code-systemtheir own version, first seen Oct 13, 2026
- prassanna-ravishankar/repowiretheir own version, first seen Oct 12, 2026
- phatysddev/skillstheir own version, first seen Oct 9, 2026
- u7-u7/dev-skillstheir own version, first seen Sep 21, 2026
- squall-chua/skillstheir own version, first seen Aug 9, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- prassanna-ravishankar/repowire★ 270same name
- phatysddev/skills★ 8same name
- DongDuong2001/pudo-code-system★ 5same name
- u7-u7/dev-skills★ 4same name
- squall-chua/skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository7 other files it gives its agents.
- accept-issueSkill
- browser-testSkill
- implement-issueSkill
- publish-releaseSkill
- refine-issueSkill
- regen-cli-commandsSkill
- review-issueSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
If you only need to assert a pure function's output, write a normal tests/*.test.ts vitest unit test instead.
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Integration-test a cockpit runtime path against the mock CLI
Unit tests prove a helper returns the right value. Static review proves the diff looks correct. Neither proves the feature actually works end to end. For anything whose value is runtime behaviour — the cockpit agent calling a tool, a session spawning with the right flags, a job posting to the inbox, the permission gate allowing/denying — the only honest evidence is driving the real Claude CLI and watching it happen. This harness does that with a scripted mock Anthropic API so it is deterministic and offline.
When to use
- A behavioural acceptance criterion: "the assistant calls a tool and it succeeds", "asking X returns Y", "a cockpit-agent tool is not denied".
- A spawn-time contract: the CLI receives
--system,--mcp-config, a model, a permission mode. - A regression you can only see at the wire level (what the CLI sent to the API, what came back, what rendered).
If you only need to assert a pure function's output, write a normal tests/*.test.ts vitest unit test instead. Use this harness when the proof requires a running CLI.
The harness (tests/integration/)
startHarness() (in tests/integration/harness.ts) boots three things in isolated tmpdirs: a mock Anthropic API on a random port that replays scripted SSE, a seeded COCKPIT_CONFIG_DIR + CLAUDE_CONFIG_DIR (password, a mock provider pointing the CLI at the mock, default model), and a cockpit server (node dist/server.js) on a random port. The Playwright fixture in tests/integration/fixtures.ts exposes a per-test harness and an already-authenticated page (it injects the cockpit_session cookie), so you navigate straight to authenticated routes.
Write a test
Model on tests/integration/hello.spec.ts. Import the fixture, skip when no CLI is present, script the mock, create a session, drive the UI, assert both the rendered output and what the CLI sent.
import { execSync } from "node:child_process";
import { textResponse, toolUseResponse } from "../mock-api/builder";
import { expect, test } from "./fixtures";
const CLAUDE_BIN = process.env.CLAUDE_BIN ?? "claude";
const CLAUDE_AVAILABLE = (() => {
try { execSync(`${CLAUDE_BIN} --version`, { stdio: "ignore" }); return true; } catch { return false; }
})();
test.skip(!CLAUDE_AVAILABLE, `claude binary not found at ${CLAUDE_BIN} (set CLAUDE_BIN env)`);
test("the cockpit agent calls a config tool and it is not denied", async ({ page, harness }) => {
// Script the mock: turn 1 emits a tool_use, turn 2 a final text answer.
harness.mock.setScript([
{ events: toolUseResponse("list_jobs", {}) },
{ events: textResponse("You have 2 scheduled jobs.") },
]);
const res = await page.request.post(`${harness.cockpitUrl}/api/sessions`, {
data: { cwd: harness.configDir, cockpitAgent: true, runtime: "pty" },
});
const { sessionId } = await res.json();
await page.goto(`${harness.cockpitUrl}/sessions/${sessionId}?cwd=${encodeURIComponent(harness.configDir)}`);
const input = page.getByTestId("message-input");
await expect(input).toBeVisible();
await page.waitForTimeout(5000); // let the eager PTY spawn settle before sending
await input.fill("list my jobs");
await page.getByTestId("btn-send").click();
await expect(page.getByText("You have 2 scheduled jobs.")).toBeVisible({ timeout: 30_000 });
// Assert what reached the API: the system prompt and the tool result round-tripped,
// so the tool was NOT denied. getRequests() returns { url, body } for each call.
const calls = harness.mock.getRequests().filter((r) => r.url.split("?")[0] === "/v1/messages");
expect(calls.length).toBeGreaterThanOrEqual(2); // tool turn + follow-up turn
expect(calls[0].body).toContain("Cockpit Assistant"); // --system prompt arrived
});Scripting the mock (tests/mock-api/builder.ts)
textResponse(text, stopReason?)— a plain assistant text turn.toolUseResponse(name, input, opts?)— an assistant turn that calls a tool (drives the permission/tool path).askUserQuestionResponse(...),errorResponse(status, message),messageStop(usage)for the other cases.harness.mock.setScript([{ events: <builder> }, ...])sets one entry per conversation turn; the last entry repeats if the CLI makes more calls.harness.mock.getRequests()returns every request the CLI made, withurlandbody. This is your wire-level assertion surface: the--systemprompt, the user message, and tool results all show up in/v1/messagesbodies. CLI calls carry a?beta=truequery, so match onr.url.split("?")[0].
Asserting spawn args without a browser
If you only need to prove the CLI was spawned with a flag (e.g. --system or --mcp-config is present for cockpitAgent sessions), a fast vitest unit test that spies on the spawn args is cheaper than a full browser run. Model on tests/session-manager-mcp-lifecycle.test.ts. Use the integration harness when the proof requires the CLI to actually run and respond.
Run it
npm run test:integration(thepretest:integrationscript runsnpm run buildfirst; the harness runsnode dist/server.jsin production mode, so rebuild after any source edit).- Needs the
claudebinary on PATH, orCLAUDE_BIN=/path/to/claude. Teststest.skipwhen it is absent — a skipped integration test is not a passing one. Do not treat a green run with everything skipped as verification; confirm the CLI was actually present. COCKPIT_IT_DEBUG=1surfaces cockpit's logs to stdout when a test hangs.runtimedefaults topty; pass{ runtime: "stream" }tostartHarness(or session create) to exercise the stream path.
Gotchas
- 60s per-test timeout. The PTY needs a settle window after session create before the first
message:send, or the send races the spawn — thewaitForTimeout(5000)in the example is load-bearing. - The mock replays a fixed script; it is not a real model. Script exactly the turns your path needs.
- Production-mode server means stale
dist/serves old code. If your change does not show up, you forgot to rebuild.
Reference
tests/integration/harness.ts, tests/integration/fixtures.ts, tests/integration/hello.spec.ts, tests/mock-api/builder.ts, tests/mock-api/server.ts.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

