Test Runner Skill
Project-instruction file resolution:
CLAUDE.mdandAGENTS.md(Codex CLI) are transparent aliases — see skills/_shared/instruction-file-resolution.md. Wherever this skill mentionsCLAUDE.md, the alias rule applies.
Plugin root:
${CLAUDE_PLUGIN_ROOT}. Claude Code replaces this with the plugin's absolute path when it loads this file. Where it appears unreplaced — in a file this skill reads with the Read tool, or on Codex, Cursor or Pi — the plugin root is the directory that contains this skill'sskills/folder (two levels above the folder of this SKILL.md). Write that absolute path literally into every command that starts a plugin script: the Bash tool has no plugin variable, and shell variables do not survive between tool calls.
Soul
Before anything else, read and internalize soul.md in this skill directory. It defines WHO you are — your role as an orchestrator, your delegation boundaries, and your non-negotiable constraints.
Phase 0: Bootstrap Gate
Read skills/_shared/bootstrap-gate.md and execute the gate check. If GATE_CLOSED, invoke skills/bootstrap/SKILL.md and wait for completion. If GATE_OPEN, continue to Phase 1.
<HARD-GATE>
Do NOT proceed past Phase 0 if GATE_CLOSED. There is no bypass. Refer to skills/_shared/bootstrap-gate.md for the full HARD-GATE constraints.
</HARD-GATE>
Phase 1: Read Session Config + Resolve Target / Profile
Read and parse Session Config per skills/_shared/config-reading.md. Store result as $CONFIG.
Test-runner specific fields (parse these specifically):
test-runner.default-profile(default:smoke)test-runner.retention-days(default:30)test-command,typecheck-command,lint-command(used for context only — not driven here)
Target / Profile Resolution
Resolution order (first match wins):
- CLI argument
--target <name> --profile <name>(explicit, highest priority) - Policy file lookup —
.orchestrator/policy/test-profiles.jsonby target name (if present) - Convention-based detection (marker files):
playwright.config.{ts,js,mjs,cjs,mts}present → target typeweb, dispatchplaywright-driverPackage.swiftpresent → target typemac, dispatchpeekaboo-driver(seeskills/peekaboo-driver/SKILL.md)
- Fallback → emit error and halt:
```
Error: Cannot resolve target — provide --target or add .orchestrator/policy/test-profiles.json
```
Rubric and Target Label
Resolve the rubric and requested target right after the profile; verify the target against Phase 2 capture evidence before Phase 3 passes it to the evaluator.
RUBRIC — the selected profile's rubric field:
import { loadProfiles, getProfile } from 'scripts/lib/profiles/registry.mjs';
const reg = await loadProfiles(); // .orchestrator/policy/test-profiles.json
const hit = reg.ok ? getProfile(reg.profiles, PROFILE) : { ok: false };
const RUBRIC = hit.ok ? hit.profile.rubric : 'skills/test-runner/rubric-v2.md';
getProfile() already applies the schema default (scripts/lib/profiles/schema.mjs, rubric-v2) when a profile names no rubric, so a pin is honoured and an unpinned profile gets v2. No registry file or no matching profile (convention-based detection) → rubric-v2. The mac profiles pin rubric-v1.md on purpose: peekaboo writes ax-snapshots/<scenario>.json, no 1440/390 viewports, so the v2 human checks could never complete there.
TARGET_KIND / TARGET_URL — what the run actually looked at (rubric-v2 Hard rule 4):
- Consume
target_kindandtarget_urlfrom the/testhandoff. A recognized--target-kind(live,production-build,dev-server) overrides an operator statement; without that flag, use an explicit statement for this run, otherwisedev-server. An invalid or missing flag value forces the pairdev-server unknowneven if a URL was supplied. No profile field upgrades the kind. TARGET_URListarget_urlfrom--target-urlfirst, then the URL the operator named, then the web target'splaywright.config.{ts,js,mjs,cjs,mts}use.baseURL(read the file, never execute it); for a macOS target use the app path. No value, or an explicitly missing flag value, is the literalunknown. Use the resolved URL for browser navigation as well as labelling; a label must describe the target actually driven.- A
localhost/127.0.0.1/ branch-preview URL is alwaysdev-server, whatever was stated or flagged. - Unknown is never upgraded: the evaluator gets
dev-server unknown, and its report header saysDEV-SERVER RUN. - For web targets, treat
TARGET_KINDas requested until capture evidence confirms${TARGET_URL}was actually driven. GrantLIVE RUN/PRODUCTION-BUILD RUNonly when the per-page visited-URL record from Phase 2 supports that target. Missing records or any visited origin differing from${TARGET_URL}'s origin forceTARGET_KIND = dev-server; name the requested URL, observed URLs (or missing evidence), and mismatch in the report. Use the observed URL forTARGET_URL, orunknownif absent. After verification, setTARGET_HEADERtoLIVE RUN,PRODUCTION-BUILD RUN, orDEV-SERVER RUN — not the live state; no verdict about what users see.respectively; keepTarget: ${TARGET_KIND} ${TARGET_URL}consistent with that result.
Run ID
Generate a run ID immediately after target resolution:
import { makeRunId } from 'scripts/lib/test-runner/artifact-paths.mjs';
const runId = makeRunId(); // e.g. "your-target-app-1715688000123"
All artifact paths in subsequent phases derive from this run ID. Never use ad-hoc paths.
Status Report
After resolution, emit: Test Runner: target=[name] profile=[name] run_id=[runId] driver=[driver] rubric=[RUBRIC] target_label=[TARGET_KIND TARGET_URL]
Phase 2: Driver Dispatch
Determine ${RUN_DIR} from artifact-paths.mjs:runDirPath(runId) before dispatching any driver. All drivers write artifacts under ${RUN_DIR}/.
--since Filtering (when `since_ref` is provided)
When since_ref is set (passed from the /test --since <git-ref> handoff contract):
- Import and call
changedFilesSince(since_ref)fromscripts/lib/discovery/helpers.mjs. - If the helper throws (ref unresolvable), surface the error to the user and halt.
- If the result is
[](no files changed since the ref), emit:
```
No files changed since <since_ref>. Skipping test run.
```
and exit with status 0. Do NOT fall back to a full-repo test run.
- If the result is a non-empty array, JSON-stringify it and set
TEST_CHANGED_FILESin the driver subprocess environment (see driver invocations below). Driver-side filtering is deferred — drivers receive the env var but do not yet filter by it in this wave.
For each resolved driver:
Web (playwright-driver)
Dispatch via Bash per skills/playwright-driver/SKILL.md. Pass ${RUN_DIR}, ${TARGET_URL} as the navigation URL, and the expected route inventory (e.g. /start, with slugs only for artifact filenames) for the selected scope to the driver context. --target below remains the repository path; the runner has no --target-url option. The capture harness must navigate ${TARGET_URL} rather than silently using a different configured base URL; passing an environment variable alone does not configure Playwright's base URL. Require the capture pass to record the actual visited URL per page and viewport next to its artifact paths in ${RUN_DIR}/visited-urls.json. After capture, compare every recorded origin with ${TARGET_URL}'s origin and apply Phase 1's evidence gate before granting the target label; absent records also trigger the dev-server fallback. For rubric-v2, require each page’s screenshot and AX snapshot at both 1440 and 390 per the driver’s Per-Page Capture Contract. Pass the expected inventory and any capture gaps to Phase 3, even if Playwright tests fail; the evaluator must check expected pages, not just files that happened to exist.
# Example invocation shape (exact flags defined by playwright-driver SKILL.md)
TEST_CHANGED_FILES="${CHANGED_FILES_JSON}" node "${CLAUDE_PLUGIN_ROOT}/scripts/lib/playwright-driver/runner.mjs" \
--run-dir "${RUN_DIR}" \
--profile "${PROFILE}" \
--target "${TARGET}"
Where ${CHANGED_FILES_JSON} is JSON.stringify(changedFiles) when --since was provided, or an empty string otherwise.
Capture exit code. A non-zero exit from Playwright means test failures — these become findings for the UX evaluator. They are NOT a fatal error for the orchestrator. Continue to Phase 3 regardless of exit code.
Log: playwright-driver exited [code] — [N] test files captured under ${RUN_DIR}
macOS (peekaboo-driver)
See
skills/peekaboo-driver/SKILL.mdfor the full dispatch contract, permission probe, and artifact layout.
Pre-dispatch platform check: The driver's Phase 1 gate handles the platform and version checks (darwin + macOS 15.0+) and exits 0 (non-fatal skip) on incompatible systems. The orchestrator does not need to replicate these checks.
Permission probe: The driver runs its own Phase 2 permission probe via peekaboo permissions status --json. If required permissions (Screen Recording, Accessibility) are not granted, the driver surfaces an AUQ and exits 2 on failure. The orchestrator treats exit 2 as a driver-framework error, not a test failure.
Invocation:
# All inputs via environment variables — no positional arguments
RUN_DIR="${RUN_DIR}" TARGET="${TARGET}" PROFILE="${PROFILE}" bash skills/peekaboo-driver/SKILL.md
Any bash-driver shim or report helper you write for this dispatch is subject to .claude/rules/bash-harness-pitfalls.md (grep -c double-print, stdout-capture pollution, file-based aggregate verdicts, perl -pi script-surgery corruption).
Outputs the orchestrator must parse:
| Artifact | Description |
|---|---|
| ${RUN_DIR}/exit_code | Plain integer file written by driver before exit |
| ${RUN_DIR}/results.json | Driver summary: exit_code, scenarios_attempted, scenarios_passed, scenarios_failed |
| ${RUN_DIR}/ax-snapshots/<scenario>.json | peekaboo AX-tree output per scenario |
| ${RUN_DIR}/ax-snapshots/glass-modifiers-<ts>.json | Liquid Glass conformance artifact (consumed by ux-evaluator Check 4) |
| ${RUN_DIR}/screenshots/<step>-<ts>.png | Per-step screenshots (evidence for ux-evaluator findings) |
| ${RUN_DIR}/console.ndjson | Driver log events as NDJSON |
Exit-code semantics:
| Code | Meaning | Orchestrator Action |
|---|---|---|
| 0 | All captures succeeded (or platform skip) | Record pass or skip, continue to Phase 3 |
| 1 | At least one capture failed | Failures become findings (non-fatal) — continue to Phase 3 |
| 2 | Framework error (missing binary, permission denied, OS mismatch) | Surface as driver error; still continue to Phase 3 with available artifacts |
Capture exit code. Exit 1 (capture failures) produces findings for the UX evaluator — it is NOT fatal for the orchestrator. Exit 2 (framework error) is surfaced in the report but does not halt Phase 3. Continue to Phase 3 regardless of exit code.
Log: peekaboo-driver exited [code] — [N] scenarios captured under ${RUN_DIR}
Phase 3: UX Evaluator Dispatch
Invoke the ux-evaluator agent (agents/ux-evaluator.md) via the Agent tool. The agent reads driver artifacts under ${RUN_DIR}/ and applies ${RUBRIC} from Phase 1 § Rubric and Target Label. Under rubric-v2 (the default) that is six human checks per page at 1440 and 390 px first, then the four v1 mechanical checks. The agent writes findings.jsonl directly to ${RUN_DIR}/findings.jsonl — the coordinator does NOT need to forward findings through prompt context. rubric-v1.md applies to a profile that pins it (the mac profiles do) and to re-reading runs stamped "v1" — the same rule as rubric-v2 § Which rubric applies when and agents/ux-evaluator.md § Which rubric (#1961).
Pass the expected route inventory (including pages with capture gaps) in the evaluator prompt; checkReportComplete({ pages, coverage, judged }) must receive routes such as /start matching coverage.page and judged.page exactly, never filename slugs such as start. Pass the visited-URL record and any target mismatch, plus the evidence-verified TARGET_HEADER as report_header. The evaluator emits that single header line alongside Target:; preserve its incomplete marker as the first line when applicable.
Three rules from rubric-v2 the coordinator enforces too:
- Live target. Drive the live URL or a production build. A dev-server or branch-preview run is passed as
target: dev-server <url>and its report says so in the header — never present it as the live state. - Mechanics are a footnote. axe/console/onboarding/Liquid-Glass counts are never the summary verdict; "0 findings" from them is not "clean".
- Incomplete is incomplete. A report whose first line is
REPORT INCOMPLETE — human checks missing: …(or whose JSON verdict isBLOCKED) is relayed as incomplete, never summarised as a pass.
Agent({
description: `UX evaluate run ${runId}`,
prompt: `<scope: ${RUN_DIR}, rubric: ${RUBRIC}, target: ${TARGET_KIND} ${TARGET_URL}, report_header: ${TARGET_HEADER}, output: ${RUN_DIR}/findings.jsonl>`,
subagent_type: "ux-evaluator",
run_in_background: false
})
run_in_background: false is mandatory — Phase 4 depends on findings.jsonl being fully written before reconciliation begins.
After the agent completes, verify ${RUN_DIR}/findings.jsonl exists. If missing, emit a warning and skip Phase 4 (no findings to reconcile).
Phase 4: Issue Reconciliation
Read ${RUN_DIR}/findings.jsonl. Use the helpers in scripts/lib/test-runner/issue-reconcile.mjs for all glab/gh interactions — never call glab or gh directly.
Available Helper Functions (issue-reconcile.mjs)
| Function | Purpose |
|---|---|
| listExistingFindings({glabPath, project, label, maxBuffer}) | Query the tracker for all open from:test-runner issues; returns {ok, issues[], fingerprints: Set} |
| createFinding({glabPath, project, fingerprint, title, body, labels, dryRun, maxBuffer}) | Create a new issue; returns {ok, action: 'create', iid?, command?}. body must carry the **Fingerprint:** \<fp>\` sentinel for this same fingerprint, which is what dedup reads on the next run. Build it with buildIssueBody(finding, fingerprint). A missing or mismatched sentinel returns {ok: false, error: {code: 'VALIDATION'}}` before glab is spawned (#1331) |
| updateFinding({glabPath, project, iid, comment, dryRun, maxBuffer}) | Add a comment to an existing issue; returns {ok, action: 'comment', command?} |
| triageDecision(finding, candidates) | Pure decision: fingerprint-exact → ignore; Levenshtein ≤ 2 on title → update; else → create |
| reconcileFinding({finding, existingFingerprints, glabPath, dryRun}) | Track-A legacy helper — single-finding create-or-noop using a pre-built fingerprint Set |
Security notes (ADR-364 §C5, #388, #389):
- All execFile calls use
maxBuffer: 4 MBandshell: false. - Bodies > 65 536 bytes are rejected with
{ok: false, error: {code: 'BODY_TOO_LARGE', ...}}. **Fingerprint:**literals in free-text fields are replaced with__Fingerprint__before the authoritative sentinel line is appended (sentinel-injection hardening, #388).
Existing-Fingerprint Dedup
Before iterating findings, build the dedup set once:
import { listExistingFindings } from 'scripts/lib/test-runner/issue-reconcile.mjs';
const listResult = await listExistingFindings({ glabPath });
// listResult.ok === false → log and continue with empty Set (conservative)
const existingFingerprints = listResult.ok ? listResult.fingerprints : new Set();
const existingIssues = listResult.ok ? listResult.issues : [];
If the glab query fails, log the error and proceed with an empty fingerprint set (conservative: may create duplicate issues, safer than silently skipping).
Severity Routing
| Severity | Action |
|----------|--------|
| critical | Auto-create issue — no AUQ. Label: from:test-runner,priority::critical |
| high | Auto-create issue — no AUQ. Label: from:test-runner,priority::high |
| medium | Batched AUQ triage (see below) |
| low | Batched AUQ triage (see below) |
For critical and high, call triageDecision(finding, existingIssues) first. If action === 'ignore', skip. If action === 'update', call updateFinding(). If action === 'create', call createFinding().
Batched AUQ Triage (medium / low)
Group medium and low findings and present via a single AskUserQuestion call (mirror the discovery skill's Phase 5 Step 3 pattern):
AskUserQuestion({
questions: [{
question: `<N> medium/low findings to triage. How to handle?`,
header: "Triage",
options: [
{
label: "Create all (Recommended)",
description: "Files <N> new issues at once, all with label from:test-runner — fastest, and you can still close any of them afterwards."
},
{
label: "Review each",
description: "Walk through findings individually with create/update/ignore"
},
{
label: "Skip all",
description: "Dismiss medium/low; only critical/high get auto-filed"
}
],
multiSelect: false
}]
})
"Create all": For each medium/low finding call triageDecision(finding, existingIssues):
ignore→ skip silently.update→ callupdateFinding({iid: target, comment, ...}).create→ callcreateFinding({fingerprint, title, body, labels, ...}).
"Review each": Walk through findings one by one. For each, call triageDecision to get the recommended action, then present a per-finding AUQ with three options (Create / Update existing #<iid> / Skip). Honour the user's selection.
"Skip all": Dismiss all medium/low findings without filing. Log skipped: N medium/low findings (user dismissed).
Reconcile Outcomes
Collect outcomes from reconciliation calls into three buckets:
created[]— issue IIDs of newly created issuescommented[]— issue IIDs of existing issues that received a new commentnoop[]— fingerprints/IIDs where no action was taken (dedup hit or user dismissed)
Pass these buckets to Phase 5.
Phase 5: Report + JSONL Roll-up
report.md
Write ${RUN_DIR}/report.md — a markdown summary of the run. Carry the evidence-verified target label and evaluator's single report_header line through verbatim; do not append a second target header when incorporating the evaluator summary. Include any requested/observed URL mismatch or missing visited-URL evidence; do not replace the URL with the target name. Preserve the evaluator's incomplete marker as the first line when present. Minimum content:
# Test Run Report
**Run ID:** <runId>
Target: <TARGET_KIND> <TARGET_URL>
<TARGET_HEADER>
**Target name:** <target>
**Profile:** <profile>
**Timestamp:** <ISO 8601>
**Duration:** <ms>ms
## Findings Summary
| Severity | Count |
|----------|-------|
| critical | N |
| high | N |
| medium | N |
| low | N |
## Check Breakdown
| Check | Findings |
|-------|---------|
| <check_name> | N |
## Issue Actions
- **Created:** <IIDs>
- **Commented:** <IIDs>
- **No-op (dedup):** <IIDs>
## Driver Exit Codes
| Driver | Exit Code |
|--------|-----------|
| playwright | N |
JSONL Roll-up
Append one record to .orchestrator/metrics/test-runs.jsonl (path from artifact-paths.mjs:jsonlRollupPath()) via appendJsonlAtomic from scripts/lib/autopilot/telemetry.mjs. Never use appendFileSync — POSIX-atomic guarantee is required (per #376).
Schema v1:
{
"schema_version": 1,
"run_id": "your-target-app-1715688000123",
"timestamp": "2026-05-14T07:30:00Z",
"target": "your-target-app",
"profile": "smoke",
"drivers": ["playwright"],
"finding_counts": {"critical": 0, "high": 2, "medium": 5, "low": 3},
"issues": {"created": [388, 389], "commented": [], "noop": [380]},
"exit_code": 0,
"duration_ms": 12345
}
exit_code is the orchestrator's own exit code: 0 if no critical/high findings auto-created, 1 otherwise.
Final Status Line
Emit to stdout:
Test Runner complete: run_id=<runId> findings=[total] issues_created=[N] duration=[ms]ms
Anti-Patterns
- DO NOT invoke Playwright or Peekaboo directly from the coordinator prompt — always dispatch via the wrapper skills (
skills/playwright-driver/SKILL.md,skills/peekaboo-driver/SKILL.md). - DO NOT inline AX-tree dumps or screenshots into coordinator or agent prompt context — artifacts go to disk under
${RUN_DIR}. - DO NOT re-file existing findings — fingerprint-based dedup via
issue-reconcile.mjsis mandatory every run. - DO NOT use
@playwright/mcpfor browser drive — R5 hard-gate enforced byscripts/lib/validate/check-playwright-mcp-canary.mjs(4× token cost per Microsoft benchmark). - DO NOT call
glaborghdirectly — always go throughscripts/lib/test-runner/issue-reconcile.mjs(execFile + binary allowlist + arg-validation, per ADR-364 §C5). - DO NOT write JSONL via
appendFileSync— useappendJsonlAtomicfromscripts/lib/autopilot/telemetry.mjs.
Critical Rules
- NEVER auto-merge MRs created by issue-reconcile.
- NEVER persist artifacts outside
${RUN_DIR}— it is the single source of truth for a run. - NEVER call
glab/ghdirectly — always route throughissue-reconcile.mjs. - ALWAYS use the orchestrator's run-id everywhere (from
artifact-paths.mjs:makeRunId()). - ALWAYS invoke
appendJsonlAtomicfor JSONL roll-up — neverappendFileSync(POSIX-atomic guarantee, per #376). - ALWAYS set
run_in_background: falsefor theux-evaluatoragent dispatch — Phase 4 depends on its output.
Sub-File Reference
| File | Purpose |
|------|---------|
| soul.md | Orchestrator identity — read before Phase 0 |
| rubric-v2.md | Current UX rubric — six human checks first, v1 checks as footnote, live-target and incomplete-report rules — read by ux-evaluator agent |
| rubric-v1.md | Frozen v1 rubric (4 mechanical checks, fingerprint formula, findings JSON schema) — for runs stamped "v1" and as the footnote's check definitions |
Implementation Modules
| File | Purpose |
|------|---------|
| scripts/lib/test-runner/fingerprint.mjs | Stable 16-hex fingerprint per finding (deterministic, idempotent) |
| scripts/lib/test-runner/human-checks.mjs | Mechanical floor of the rubric-v2 human checks from AX snapshots + completeness check for the judged ones |
| scripts/lib/test-runner/artifact-paths.mjs | Run-dir + artifact path builders — pure functions, no side effects |
| scripts/lib/test-runner/issue-reconcile.mjs | glab/gh dispatch via execFile + binary allowlist (ADR-364 §C5) |