/testing:claude-workflow-tdd-harnessfrom testing
Reusable Node.js harness for unit-testing Claude Code Workflow scripts (the `Workflow` tool's `.js` files) with `node:test`. Use when: (1) you need to test a Workflow script's args contract / phase order / per-agent schema shape WITHOUT actually invoking the Workflow tool (which spawns real agents, costs tokens, is slow, and is only available in the parent session); (2) `node --test` rejects the file with `SyntaxError: Unexpected token 'export'` or `Illegal return statement` because the script uses top-level `await`, top-level `return`, and injected globals (`agent`, `phase`, `log`, `budget`, `parallel`, `pipeline`, `workflow`); (3) you want a per-label mock-agent dispatch pattern so each `agent()` call can return a different shape; (4) you want budget-gate / short-circuit / phase-order tests to land before any live Workflow call. Ships a ~110-line ESM harness (no deps) that strips `export const meta = {...}` via brace-counting, wraps the body in `AsyncFunction`, injects configurable mocks for all Workflow globals.
Ships in testing. 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.
Workflow scripts use top-level await, top-level return,
export const meta = {...}, and globals injected by the Workflow runtime
(agent, phase, log, budget, parallel, pipeline, workflow) —
none of which standard node --test will accept. The only way to "test"
a Workflow script without this harness is to invoke the Workflow tool
live, which spawns real Claude agents (slow + expensive + only available
in the parent session).
node --check path/to/workflow.js fails with SyntaxError: Unexpected token 'export' or Illegal return statement.scripts/harness.mjs (shipped with this skill) into your
project's tests/workflows/ directory.runWorkflow({ scriptPath, args, mockAgent, mockWorkflow, budget })
which returns { result, error, agentCalls, workflowCalls, phases, logs }
for assertions.mockAgent: dispatch by opts.label so each agent()
call can return a different shape (see Example).node:test + node:assert/strict.How the harness works (read scripts/harness.mjs for the actual code):
.js file.export const meta = {...} via balanced-brace counting that is
string-literal aware (won't get confused by { inside a string).new AsyncFunction('args', 'phase', 'log', 'agent', 'parallel', 'pipeline', 'workflow', 'budget', body).After dropping the harness in place:
node --test tests/workflows/*.test.mjs
should run without SyntaxError. The tests themselves drive what passes
and what fails.
Pattern for a single test:
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { runWorkflow } from './harness.mjs'
const mockAgent = (_prompt, opts) => {
const label = opts?.label || ''
if (label === 'preflight') return { ok: true /* schema-shaped */ }
if (label === 'launch') return { ok: true, runId: 'r0', pid: 1 /* ... */ }
if (label.startsWith('watch:')) return { stillRunning: false /* ... */ }
return null
}
test('CONTRACT: args contract — happy path reaches first agent', async () => {
const r = await runWorkflow({
scriptPath: '/abs/path/to/my-workflow.js',
args: { workingDir: '/tmp/x' },
mockAgent,
})
assert.equal(r.error, null)
assert.match(r.agentCalls[0].prompt, /workingDir.*\/tmp\/x/)
})
Reference examples (real, exercised in production):
nautilus-competition/tests/workflows/babysitter.test.mjs — 7 tests
including preflight-short-circuit and budget gate.nautilus-competition/tests/workflows/single-team-driver.test.mjs — 7
tests including args contract for object / JSON-string / undefined and
gatePassed early-exit.nautilus-competition/tests/workflows/forensics.test.mjs — 6 tests
including phase order and per-team pipeline cardinality.remaining() mock because the script
calls budget.remaining() multiple times per loop iteration. A
constant-low value will exit the loop on iteration 0 before any agent
runs, which is rarely what you want to assert on.pipeline() mock iterates items sequentially (await per
item, stages applied in order) and passes the REAL runtime stage
contract (prevResult, originalItem, index) — scripts that use
originalItem in later stages (common for labeling) depend on this. If the production script depends on
per-item concurrency, use parallel(items.map(t => () => fn(t)))
instead and assert label cardinality, not wall-clock.budget is
{ total: null, spent: () => 0, remaining: () => Infinity } — override
per-test when you want to drive gate behavior.[[claude-workflow-authoring-gotchas]] to catch the
meta-literal + args-contract traps before they reach a live Workflow
call.[[claude-workflow-authoring-gotchas]] — the three traps
this harness pins as tests.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub cajias/claude-skills --plugin testing4 skills in this plugin
/mutation-verify-render-testsVerify that "scene-capture" / pixel-analysis tests for a graphical renderer (pygame,
canvas, matplotlib, headless GL, screenshot-diff) actually CATCH a broken render —
by mutation testing. Use when: (1) you've written or received tests that render a
frame headlessly and assert properties of the pixels (e.g. "pitch is green", "HUD
present", "sprites on screen"); (2) an agent reports "N scene tests passing" and you
need to know if they're REAL or hollow; (3) a pixel/region assertion passes but you
suspect it's satisfied by the wrong pixels (background, anti-aliasing, adjacent UI);
(4) before trusting any image-correctness test as a guard. The core technique:
temporarily break the renderer (stub the draw call) and confirm the test FAILS; then
restore and confirm it PASSES. A scene test that passes when the thing it checks is
removed is worthless.
/streamlit-ui-visual-verificationVerify Streamlit dashboard changes by opening a real browser — not just probing
the HTTP server. Use when: (1) you modified a Streamlit app and want to sign
off on the change, (2) a smoke test passed via curl/HTTP 200 but you haven't
actually looked at the page, (3) the change touched data-source selection,
tab widgets from `extra-streamlit-components`, or dropdown population wired
to a backend, (4) an exit gate / PR review needs UI evidence not just import
evidence. Covers the "server-up ≠ UI-works" trap, iframe-isolated widget
gotcha in extra-streamlit-components, Playwright MCP fallback when the
claude-in-chrome extension is disconnected, and the specific failure signature
where HTTP 200 + zero tracebacks + empty dropdowns means data binding silently
broke between modules and the UI layer.