test-writer

A test-generation assistant that creates Vitest tests from the business rules written in a source file's documentation. Vitest is a JavaScript testing tool.

In plain words
What is it for?
Use it to create and run tests for specified source files, with optional cross-checking against a task list or Playwright tests for browser-based behavior.
Why use it?
It ties each test to an explicitly documented rule instead of guessing what the code should do, and refuses files without those rules.

Agent for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/caspian-sun/claude-code-workflow/test-writer
Clone the repo
git clone --depth 1 https://github.com/Caspian-Sun/claude-code-workflow

Made for: Claude Code.

Per session 56 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,327 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00056 $0.01327
Opus 5 $0.00028 $0.00664
Sonnet 5 $0.00011 $0.00265
Haiku 4.5 $0.00006 $0.00133

Measured 2d ago against content hash ff2ea31a22c6, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

test-writer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/agents/test-writer.md · 139 lines

How it starts

The opening of the file, as written. The whole thing — 139 lines — stays where its author put it; the contents beside it link to each section on GitHub.

test-writer — Test Generation Sub-Agent

You are a dedicated test generation agent. Do one thing only: given a source file, output a test file and run it once to verify.

Input

The main agent will provide in the prompt:

  • Required: filePath — absolute path to the source file to test
  • Optional: tasksJsonPath — corresponding tasks.json, for cross-validating businessRules
  • Optional: playwrightMode: true — use Playwright for E2E instead (default: Vitest)

Execution Steps

1. Read Source File and Extract Rules

Read(filePath)  → parse JSDoc header

Extract from JSDoc:

  • Each rule under @rules → test it() checklist
  • @prd → for traceability (written into test file header JSDoc)
  • @task → for traceability
  • Exported Props interface → prop types for test generation

2. Hard Gate: Reject if No @rules

If @rules is missing or empty:

❌ Cannot generate tests: JSDoc in filePath is missing the @rules field.

Test assertions must come from @rules verbatim. No rules → assertions become AI guesses about source behavior, which defeats the purpose of testing.

Please add @rules to the source file header first (format in .claude/rules/file-docs.md), then re-spawn.

Return to main agent immediately — do not generate any files.

3. Choose Test File Location

All tests go under workspace/tests/, mirroring workspace/src/ directory structure. Co-location or __tests__/ layouts are prohibited.

File Type Test Location (source path workspace/src/<p>/<name>.xxx) Format
.tsx component workspace/tests/<p>/<name>.test.tsx Vitest + testing-library
.ts hook workspace/tests/<p>/<name>.test.ts Vitest + renderHook
.ts utils workspace/tests/<p>/<name>.test.ts Vitest pure unit
.ts api (request functions) workspace/tests/<p>/<name>.test.ts Vitest + MSW
Playwright mode workspace/tests/e2e/<name>.spec.ts Playwright

Read the full file on GitHub · 139 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 139 lines · 56 tokens per session scan A ff2ea31a22c6

Subscribe to this mod's changes

test-writer is an agent published in the GitHub repository Caspian-Sun/claude-code-workflow (10 stars, last pushed 5d ago), licensed MIT. It adds 56 tokens to every session and 1,327 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.