/ork:cover [scope-or-feature]from ork
Generates comprehensive test suites for existing code across unit, integration, and e2e tiers. Automatically heals failing tests up to 3 times. Supports real-service integration testing.
Ships in ork. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Host-neutral workflow. Invoke by skill name (cover). Claude Code slash routing, YAML hook loaders, and .claude/chain live in references/claude-code.md.
Generate comprehensive test suites for existing code with real-service integration testing and automated failure healing.
Note: If
disableSkillShellExecutionis enabled (CC 2.1.91), the precondition check for vitest/jest won't run. Verify a test runner is installed before proceeding:npx vitest --versionornpx jest --version.
cover authentication flow
cover --model=opus payment processing
cover --tier=unit,integration user service
cover --real-services checkout pipeline
A pronoun target (this, them, the above) is read back from the conversation, announced in one line, and used: Read("../../shared/rules/target-resolution.md"), inline half.
SCOPE = "$ARGUMENTS" # e.g., "authentication flow"
# Flag parsing
MODEL_OVERRIDE = None
TIERS = ["unit", "integration", "e2e"] # default: all three
REAL_SERVICES = False
for token in "$ARGUMENTS".split():
if token.startswith("--model="):
MODEL_OVERRIDE = token.split("=", 1)[1]
SCOPE = SCOPE.replace(token, "").strip()
elif token.startswith("--tier="):
TIERS = token.split("=", 1)[1].split(",")
SCOPE = SCOPE.replace(token, "").strip()
elif token == "--real-services":
REAL_SERVICES = True
SCOPE = SCOPE.replace(token, "").strip()
Read $CLAUDE_EFFORT (CC 2.1.120+) first; explicit --effort= token wins as override. Default high when CC < 2.1.120 and no flag. Pattern matches assess + explore (#1540). Scale test generation depth:
| Effort Level | Tiers Generated | Agents | maxIterations to pass Phase 5 |
|---|---|---|---|
| low | Unit only | 1 agent | 2 (1 repair + 1 verify) |
| medium | Unit + Integration | 2 agents | 2 (1 repair + 1 verify) |
| high (default) | Unit + Integration + E2E | 3 agents | 3 (2 repairs + 1 verify) |
| xhigh (CC 2.1.111+) | Unit + Integration + E2E | 3 agents | 3 (the ceiling; xhigh adds agents, not heal passes) |
Values are what you pass as maxIterations in Phase 5. The script clamps to [2, 3]
(heal-loop.js), so anything outside that range is coerced, and the final iteration always
verifies rather than repairing. There is no 4-iteration mode.
Override: Explicit
--tier=flag or user selection overrides/effortdownscaling.
# Probe MCPs (parallel):
# memory is alwaysLoad in .mcp.json (CC 2.1.121+, #1541). Probe below kept as fallback for older CC:
ToolSearch(query="select:mcp__memory__search_nodes")
ToolSearch(query="select:mcp__context7__resolve-library-id")
Write(".claude/chain/capabilities.json", {
"memory": <true if found>,
"context7": <true if found>,
"skill": "cover",
"timestamp": now()
})
# Resume check:
Read(".claude/chain/state.json")
# If exists and skill == "cover": resume from current_phase
# Otherwise: initialize state
AskUserQuestion(
questions=[
{
"question": "What test tiers should I generate?",
"header": "Test Tiers",
"options": [
{"label": "Full coverage (Recommended)", "description": "Unit + Integration (real services) + E2E"},
{"label": "Unit + Integration", "description": "Skip E2E, focus on logic and service boundaries"},
{"label": "Unit only", "description": "Fast isolated tests for business logic"},
{"label": "E2E only", "description": "Playwright browser tests"}
],
"multiSelect": false
},
{
"question": "Healing strategy for failing tests?",
"header": "Failure Handling",
"options": [
{"label": "Auto-heal (Recommended)", "description": "Fix failing tests up to 3 iterations"},
{"label": "Generate only", "description": "Write tests, report failures, don't fix (skips the heal loop)"},
{"label": "Strict", "description": "All tests must pass or abort"}
],
"multiSelect": false
}
]
)
Override TIERS based on selection. Skip this step if --tier= flag was provided.
Finish line. Done means: every generated test runs, the suite is green or each remaining failure is reported with its heal-loop classification, and the coverage report is written. Follow Read("../../shared/rules/long-run-protocol.md"): keep going when a step needs no input from the user, stop and ask only when you can't continue without them or before anything destructive, check each subagent's evidence before accepting it, and mark anything you couldn't confirm with where you looked.
# 1. Create main task IMMEDIATELY
TaskCreate(subject=f"Cover: {SCOPE}", description="Generate comprehensive test suite with real-service testing", activeForm=f"Generating tests for {SCOPE}")
# 2. Create subtasks for each phase
TaskCreate(subject="Discover scope and detect frameworks", activeForm="Discovering test scope") # id=2
TaskCreate(subject="Analyze coverage gaps", activeForm="Analyzing coverage gaps") # id=3
TaskCreate(subject="Generate tests (parallel per tier)", activeForm="Generating tests") # id=4
TaskCreate(subject="Execute generated tests", activeForm="Running tests") # id=5
TaskCreate(subject="Heal failing tests", activeForm="Healing test failures") # id=6
TaskCreate(subject="Generate coverage report", activeForm="Generating report") # id=7
# 3. Set dependencies for sequential phases
TaskUpdate(taskId="3", addBlockedBy=["2"]) # Analysis needs discovery first
TaskUpdate(taskId="4", addBlockedBy=["3"]) # Generation needs gap map
TaskUpdate(taskId="5", addBlockedBy=["4"]) # Execution needs generated tests
TaskUpdate(taskId="6", addBlockedBy=["5"]) # Healing needs test results
TaskUpdate(taskId="7", addBlockedBy=["6"]) # Report needs healed suite
# 4. Update status as you progress
TaskUpdate(taskId="2", status="in_progress") # When starting
TaskUpdate(taskId="2", status="completed") # When done, repeat for each subtask
| Phase | Activities | Output |
|---|---|---|
| 1. Discovery | Detect frameworks, scan scope, find untested code | Framework map, file list |
| 2. Coverage Analysis | Run existing tests, rank risk targets per tier | Coverage baseline, risk targets with why |
| 3. Generation | Parallel test-generator agents per tier, then behaviour gate | Test files created, gate verdicts |
| 4. Execution | Run all generated tests | Pass/fail results |
| 5. Heal | Fix failures, re-run (max 3 iterations) | Green test suite |
| 6. Report | Coverage delta, test count, summary | Coverage report |
| After Phase | Handoff File | Key Outputs |
|---|---|---|
| 1. Discovery | 01-cover-discovery.json | Frameworks, scope files, tier plan |
| 2. Analysis | 02-cover-analysis.json | Baseline coverage, risk targets with why |
| 3. Generation | 03-cover-generation.json | Files created, test count per tier, behaviour gate verdicts |
| 5. Heal | 05-cover-healed.json | Final pass/fail, iterations used |
Detect the project's test infrastructure and scope the work.
# PARALLEL, all in ONE message:
# 1. Framework detection (hook handles this, but also scan manually)
Grep(pattern="vitest|jest|mocha|playwright|cypress", glob="package.json", output_mode="content")
Grep(pattern="pytest|unittest|hypothesis", glob="pyproject.toml", output_mode="content")
Grep(pattern="pytest|unittest|hypothesis", glob="requirements*.txt", output_mode="content")
# 2. Real-service infrastructure
Glob(pattern="**/docker-compose*.yml")
Glob(pattern="**/testcontainers*")
Grep(pattern="testcontainers", glob="**/package.json", output_mode="content")
Grep(pattern="testcontainers", glob="**/requirements*.txt", output_mode="content")
# 3. Existing test structure
Glob(pattern="**/tests/**/*.test.*")
Glob(pattern="**/tests/**/*.spec.*")
Glob(pattern="**/__tests__/**/*")
Glob(pattern="**/test_*.py")
# 4. Scope files (what to test)
# If SCOPE specified, find matching source files
Grep(pattern=SCOPE, output_mode="files_with_matches")
Real-service decision:
docker-compose*.yml found → integration tests use real servicestestcontainers in deps → use testcontainers for isolated service instances--real-services flag → error: "No docker-compose or testcontainers found. Install testcontainers or remove --real-services flag."Load real-service detection details: Read("references/real-service-detection.md")
Run existing tests for a baseline, then pick targets by RISK. Coverage is information for the report, never a target.
# Baseline: npx vitest run --coverage --reporter=json | pytest --cov=<scope> --cov-report=json | go test -coverprofile=coverage.out ./...
# Rank uncovered code by risk and record WHY each target was chosen:
# changed code, complex branches, error paths, security and money paths, past bugs
# gap_map[tier] = [{"target": "src/billing/refund.ts:roundRefund", "why": "money path, fixed in #812"}]
Output the baseline and the risk-ranked targets, each with its why, immediately (progressive output). Signals and how to find them: Read("references/behaviour-gate.md").
Spawn test-generator agents per tier. Launch ALL in ONE message with run_in_background=true.
Isolation: spawn each tier agent with
Agent(isolation="worktree"), one worktree per tier (unit / integration / e2e) so they don't conflict. The subagent bypass of the worktree-isolation guard was fixed in CC 2.1.154 and completed in 2.1.203; ork's floor is >= 2.1.220, so every supported session gets real isolation. Do not create worktrees by hand before spawning.The new branch's base comes from the
worktree.baseRefsetting, never from a hardcoded branch name. ork does not set it: a plugin cannot, and no ork settings file carries it. Unless the operator put"baseRef": "head"in.claude/settings.jsonor~/.claude/settings.json, CC's default"fresh"applies: every tier agent branches fromorigin/<default>, unpushed local commits are invisible to it, andtscfails with "cannot find module" for code you just wrote. Verify the setting before spawning. Full pattern:Read("../chain-patterns/references/worktree-agent-pattern.md")
# Unit tests agent (worktree-isolated)
if "unit" in TIERS:
Agent(
subagent_type="ork:test-generator",
isolation="worktree",
prompt=f"""Generate unit tests for: {SCOPE}
Risk targets, each with why: {gap_map["unit"]}
Framework: {detected_framework}
Existing tests: {existing_test_files}
Focus on:
- AAA pattern (Arrange-Act-Assert)
- Parametrized tests for multiple inputs
- MSW/VCR for HTTP mocking (never mock fetch directly)
- Factory-based test data (FactoryBoy/faker-js)
- Edge cases: empty input, errors, timeouts, boundary values
- BEHAVIOUR GATE: write a test ONLY if it asserts an observable result. Never write a
mock-call-only, assertion-free, tautological, or source-reading test (references/behaviour-gate.md)""",
run_in_background=True,
max_turns=50,
model=MODEL_OVERRIDE
)
# Integration + E2E agents follow the same pattern:
# - subagent_type="ork:test-generator", isolation="worktree", run_in_background=True, same targets + BEHAVIOUR GATE lines
# - Integration focus: API endpoints (Supertest/httpx), real DB, contract tests (Pact), Zod schema validation
# - E2E focus: Playwright, semantic locators, Page Object Model, axe-core a11y, visual regression
#
# Special case: emulate (Vercel Labs stateful API emulation):
# When integration tests need GitHub/Stripe/Resend/Okta/etc. emulated
# (HMAC webhooks, parallel port isolation, full config from scratch),
# spawn emulate-engineer instead of test-generator for that tier:
# - subagent_type="ork:emulate-engineer" (same isolation="worktree" form)
# - Pairs with emulate-seed skill for seed YAML patterns
Output each agent's results as soon as it returns. Don't wait for all agents.
Before Phase 4, run node "${CLAUDE_SKILL_DIR}/scripts/check-behaviour-tests.mjs" --json <new test files> over the NEW test files only. Exit 1 lists each rejected test with its rule: (a) only mock-call assertions, (b) no assertion, only tautologies (expect(true).toBe(true)), or only not-to-throw when not throwing is not the stated contract, (c) reads or greps source instead of executing it. Delete each rejected test (the whole file on drop, which means every recognised test was rejected) or rewrite it to assert an observable result, and re-run until exit 0. Never delete an unchecked file or test (no test recognised, or its body is declared elsewhere): review it by hand. Run it again after Phase 5. Record the verdicts in 03-cover-generation.json. Rules and limits: Read("references/behaviour-gate.md").
Focus mode (CC 2.1.101): In focus mode, include the full coverage report (before/after delta, test count per tier, files created) in your final message.
Run all generated tests and collect results.
# Run test commands per tier (PARALLEL if independent):
# Unit: npx vitest run tests/unit/ OR pytest tests/unit/
# Integration: npx vitest run tests/integration/ OR pytest tests/integration/
# E2E: npx playwright test
# Collect: pass count, fail count, error details, coverage delta
Do NOT hand-roll the loop. Run the real executor:
Workflow(
name="ork:heal-loop",
args={"testCommand": "<tier test command>", "tier": "unit", "testGlob": "tests/unit/",
"maxIterations": 3} # from the effort table above; omitted defaults to 3
)
# One invocation per tier that has failures.
Fan-out rule: a single pass is never a fallback when the selected failure handling runs the heal loop. Each tier with failures goes through the heal-loop Workflow call; if it does not run, end the run as BLOCKED and say why. "Generate only" skips the heal loop, so it is not a violation.
Refused workflow rule: a heal-loop call that is refused, errors or is unavailable is named before the run ends BLOCKED, heal-loop workflow not run (<refused|error|unavailable>: <reason>), and no tier's failures are reported as healed or handled, because the counted diagnose/repair loop in heal-loop.js did not run.
The iteration bound is enforced by the script, not by instruction. heal-loop.js
runs a real counted loop clamped to [2, 3]: each iteration spawns a diagnose agent that
actually executes the test command and returns structured pass/fail plus the verbatim
failure output, then a repair agent that receives that failure text and edits test files
only. It exits early the moment the suite is green.
The final iteration diagnoses but does not repair - there would be no run left to verify
that repair. So maxIterations: N means N diagnose runs and N-1 repair passes, and the
default 3 means 2 repairs. A ceiling of 1 is coerced to 2, since 1 would mean zero repairs.
Every failure is classified into the taxonomy (assertion, import, setup, timeout,
stale-selector, type, flaky, plus source-bug), which selects the fix strategy.
The workflow returns status: "healed" or a structured failure (status: "failed",
healed: false) carrying remaining_failures, failure_categories, and the per-iteration
ledger. Never report a "failed" result as a success: surface the still-failing tests in
the Phase 6 report.
Strategy detail (taxonomy table, fix rules, flaky prevention): Read("references/heal-loop-strategy.md")
Boundary: heal fixes TESTS, not source code. If a test fails because the source code has a bug, report it. Don't silently fix production code.
Generate coverage report with before/after comparison.
Full report layout (baseline→after table, tests-generated counts, heal iterations, files created, remaining gaps, next-steps commands): Read("references/coverage-report-template.md").
Full cover runs (unit + integration + E2E with heal loop) take 15-45 min. After the Phase 6 report is assembled, call PushNotification(message=f"ork:cover complete, {SCOPE}: {tests_kept} tests kept · {tests_dropped} dropped by behaviour gate · {heal_loops} heal iters", status="proactive"). Full rule: Read("../chain-patterns/rules/push-notification-on-completion.md").
Optionally schedule a weekly check that the risk targets keep their behaviour tests:
# Guard: Skip cron in headless/CI (CLAUDE_CODE_DISABLE_CRON)
# if env CLAUDE_CODE_DISABLE_CRON is set, run a single check instead
CronCreate(
schedule="0 2 * * 0",
prompt="Weekly drift check for {SCOPE}: run the tests covering the risk targets in 02-cover-analysis.json.
Alert if one was deleted or fails, or if newly changed code has no behaviour test. Coverage is reported as information only."
)
[PARTIAL view] first page (not an error) on oversized files. Re-read with explicit offset/limit so coverage analysis sees the whole file.Each test-generator agent receives: risk targets (each with why) for its tier, the behaviour gate rules, test framework config, real-service infrastructure (testcontainers, docker-compose), and fixture patterns from the project.
Use Monitor for streaming test execution output from background agents:
# Stream test suite output in real-time
Bash(command="npm test -- --coverage 2>&1", run_in_background=true)
Monitor(pid=test_task_id) # Each line → notification
Full pattern reference (until-condition gates, partial-result salvage, TaskOutput vs Monitor decision): Read("../chain-patterns/references/monitor-patterns.md").
Partial results (CC 2.1.98): If a test-generator crashes mid-generation, synthesize what it produced:
for agent_result in test_gen_results:
if "[PARTIAL RESULT]" in agent_result.output:
# Agent crashed: check if it wrote any test files before dying
partial_tests = Glob(pattern="**/tests/**/*.test.*", path=agent_result.worktree)
if partial_tests:
# 6 passing tests from a crashed agent > 0 tests
# Copy partial tests to main worktree, run them in Phase 4
for test_file in partial_tests:
Bash(command=f"cp {test_file} {main_worktree}/{test_file}")
# Flag as partial in report
A maxTurns stop is also partial since CC 2.1.246 (summary: "stopped at its N-turn limit (partial result; continue it with SendMessage to the task-id)"); continue that agent with SendMessage instead of re-spawning it.
Cross-session replies land in the parent (CC 2.1.248): when a subagent sends
SendMessageto another session, the reply is delivered to the parent session's conversation, never to the subagent; a subagent sends and moves on, the parent reads the answer. Cross-sessionSendMessage/ListAgentsalso work on Bedrock, Vertex and Foundry and with telemetry disabled (CC 2.1.248).
When a generated test fails, the healer agent can request context from the generator:
SendMessage(to="test-generator-unit", message="Test user_service_test.py:42 fails: TypeError on mock return. What's the expected shape?")
Standard chain: implement → cover → verify → commit. Use addBlockedBy between each.
Before claiming coverage is complete, apply: Read("../../shared/rules/verification-gate.md"). Run the coverage report fresh. "Should pass" is not evidence.
All test-generator agents report using: Read("../../shared/status-protocol.md"). BLOCKED if tests can't be written due to missing interfaces. NEEDS_CONTEXT if test expectations are unclear.
Done means all of these hold:
ork:implement: generates tests during implementation (Phase 5); use cover after for deeper coverageork:verify: grades existing tests 0-10; chain: implement → cover → verifytesting-unit / testing-integration / testing-e2e: knowledge skills loaded by test-generator agentsork:commit: commit generated test filesSession recovery (CC 2.1.108+): After idle periods or interruptions, use
/recapto restore conversational context alongside checkpoint-resume state. Enabled by default since CC 2.1.110 (even with telemetry disabled).
Load on demand with Read("references/<file>"):
| File | Content |
|---|---|
real-service-detection.md | Docker-compose/testcontainers detection, service startup, teardown |
heal-loop-strategy.md | Failure classification, fix patterns, iteration budget |
coverage-report-template.md | Report format, delta calculation, gap analysis |
behaviour-gate.md | Risk target signals, the three reject rules, checker usage and limits |
scripts/check-behaviour-tests.mjs | Phase 3b checker: per-test keep or reject verdicts for new test files |
workflows/heal-loop.js | Phase 5 executor: script-enforced 3-iteration repair loop (run via the Workflow tool) |
Version: 1.3.0 (September 2026): behaviour gate (Phase 3b checker) and risk-based targets replace percentage coverage targets
references/behaviour-gate.md (opens in a new tab)references/claude-code.md (opens in a new tab)references/coverage-report-template.md (opens in a new tab)references/heal-loop-strategy.md (opens in a new tab)references/real-service-detection.md (opens in a new tab)scripts/check-behaviour-tests.mjs (opens in a new tab)test-cases.json (opens in a new tab)workflows/heal-loop.js (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
sonnethighBash${CLAUDE_PLUGIN_ROOT}/hooks/bin/run-hook.mjs skill/test-framework-detectornpx claudepluginhub yonatangross/orchestkit --plugin ork-alpha82 skills in this plugin
/analyticsLocal OrchestKit usage analytics: agent and skill frequency, hook timing, session replay, cost estimates, model delegation trends. Use when reviewing usage, performance or costs./api-designAPI wire contracts for REST and GraphQL: resource shape, versioning and deprecation, RFC 9457 errors, OpenAPI. Use when designing an endpoint contract. Not for runtime code (use python-backend)./architecture-decision-recordNygard-format ADRs: context, decision, consequences, alternatives. Use when writing an ADR or recording an architectural decision.2 plugins ship this exact skill · first indexed Nov 23, 2026
Other plugins' skills for the same job