# Write Tests

Write tests for agents, tools, or pipelines.

**User request:** $ARGUMENTS

---

Read `CLAUDE.md` and `skills/write-tests/SKILL.md` fully before doing anything.

Based on the description above, create the appropriate test file(s) in `tests/` following the existing patterns in `test_base_agent.py` and `test_tools.py`.

**For `@tool` functions** — test directly without mocking (they are pure functions or async):
- Happy path with valid input
- Error path: what does it return when the input is bad or the external call fails? (must return `"ERROR: ..."` string, never raise)
- Edge cases: empty string, None, very long input, unexpected types

**For agent logic** — mock the LLM, test the agent's state handling:
- Does `execute()` read the right keys from state?
- Does it return a `Command` with the expected `goto` and `update` keys?
- Does `extract_json` fallback work when the LLM returns prose? Test with `{"raw": result}` fallback.
- Is `"results"` populated on the last agent? (`results: []` in the API response is a common failure)

**For the pipeline end-to-end** — use a real but cheap model (haiku) with a small input:
- Use N=1 or N=2 items, never the full production N — this catches round exhaustion early
- Assert that `response["results"]` is non-empty
- Assert that the JSON keys you expect actually exist in the result

**Specific cases to always cover:**
- `extract_json` on valid JSON, JSON inside markdown fences, and plain text (should return `{}`)
- Tool returning `"ERROR: ..."` string — does the agent handle it gracefully and not crash?
- State field missing from input — does the agent default safely or raise a clear error?
