cajias/claude-skills/claude-workflow-tdd-harness
Claude Code and agent skill by cajias/claude-skills
- community
Checking that the SKILL.md file is still in the repository.
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.
Install
npx vskill@latest install cajias/claude-skills/claude-workflow-tdd-harnessSKILL.md
The same SKILL.md was published earlier as cajias/claude-skills/claude-workflow-tdd-harness.
claude-workflow-tdd-harness
Problem
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).
Context / Trigger Conditions
node --check path/to/workflow.jsfails withSyntaxError: Unexpected token 'export'orIllegal return statement.- You want to assert on a Workflow script's args contract (object / JSON string / undefined), phase order, agent schemas, short-circuit behavior, or budget gate WITHOUT a live Workflow call.
- You're adopting TDD for a plugin that ships Workflow scripts and want the test loop to be <5 seconds, not 5 minutes.
Solution
- Copy
scripts/harness.mjs(shipped with this skill) into your
project's tests/workflows/ directory.
- The harness exposes
runWorkflow({ scriptPath, args, mockAgent, mockWorkflow, budget }) which returns { result, error, agentCalls, workflowCalls, phases, logs } for assertions.
- Pattern for
mockAgent: dispatch byopts.labelso eachagent()
call can return a different shape (see Example).
- Write tests with
node:test+node:assert/strict.
How the harness works (read scripts/harness.mjs for the actual code):
- Reads the
.jsfile. - Strips
export const meta = {...}via balanced-brace counting that is
string-literal aware (won't get confused by { inside a string).
- Wraps the remaining body in
new AsyncFunction('args', 'phase', 'log', 'agent', 'parallel', 'pipeline', 'workflow', 'budget', body).
- Calls it with the mock injections.
- Returns the structured result for the test to assert on.
Verification
After dropping the harness in place:
should run without SyntaxError. The tests themselves drive what passes and what fails.
Example
Pattern for a single test:
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.
Notes
- Budget-gate tests need a STATEFUL
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.
- The harness's
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.
- The default
budgetis
{ total: null, spent: () => 0, remaining: () => Infinity } — override per-test when you want to drive gate behavior.
- Pair with
[[claude-workflow-authoring-gotchas]]to catch the
meta-literal + args-contract traps before they reach a live Workflow call.
References
- Cross-link:
[[claude-workflow-authoring-gotchas]]— the three traps
this harness pins as tests.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingplugins/testing/skills/claude-workflow-tdd-harness/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/cajias/claude-skills/claude-workflow-tdd-harness)