---
name: delegate-tests-to-spt-test-engineer
description: "Write spt-core/spt-claude-code tests via the spt-test-engineer subagent, not inline"
metadata: 
  node_type: memory
  type: feedback
  originSessionId: 73618172-412e-4954-b8aa-e2c8955dfd49
---

When writing unit/integration tests or CI for spt-core (or side projects like spt-claude-code), delegate to the `spt-test-engineer` subagent (profile: `C:\Users\decid\Documents\projects\.claude\agents\spt-test-engineer.md`, model opus, project memory). Invoke via the Agent tool with `subagent_type: "spt-test-engineer"`.

**Why:** The user explicitly directed this (2026-06-19). That agent specializes in two test classes — coverage tests + "use-it-like-a-human" workflow/misuse tests — and keeps its own institutional test/CI memory across conversations.

**How to apply:** For any new test authoring during wave/milestone bringup (e.g. v0.13.0 W3/W4/W5), spawn the subagent rather than writing tests inline. Run it `run_in_background: true` while a live perch is active so messages stay reachable. The W1 tests this session were written inline BEFORE this instruction — fine as-is; apply going forward.

**Orchestration hazards (learned v0.13.0 W1b, 2026-06-19 — the hard way):**
- **NEVER run two spt-test-engineer subagents on the same crate/`target/` concurrently.** They collide on the cargo artifact-dir lock and can both edit the same test file → a Frankenstein/half-killed file. W1b: I launched a redundant 2nd fixer while the 1st was still finishing; the operator caught it. If a subagent seems stuck, `TaskStop` it and INDEPENDENTLY re-verify the on-disk result yourself (run the tests — you may run tests, the rule is only don't *author* them) before launching another. Serialize, or worktree-isolate one.
- **Constrain test subagents to DIRECT timeout'd runs.** A subagent that drives cargo via Monitor/`Tee-Object`/background-wait loops burned ~1M tokens emitting non-answers ("still running, awaiting monitor"). Tell it: run `timeout 120 cargo test ... | tail -40` synchronously, ≤4 iterations, no Monitor, report concretely.
- **`cargo test --test inject_control_wedge` HANGS on Windows** (threads-in-one-process; the real-PTY/rc-pump teardown leaves an abandoned reader that aborts the process `0xffffffff`). CI is safe because it uses `cargo nextest` (process-per-test). Locally use `cargo nextest run` or `--test-threads=1`. Follow-up: add a `serial_test` guard or a module-doc note. See [[spt-verification-gates]].
- After a real-PTY int run, kill orphan `inject_control_wedge` exes + `cmd.exe` FLOOD children or the next build's link step fails `LNK1104`.
- **The subagent can OVERSTEP "test module only" and edit IMPL files** (learned v0.13.2 W3c, 2026-06-22). To make the tree compile / its setup work, it may add or "fix" production code — W3c: it re-introduced a design I'd explicitly KILLED (a `manifest_cells` registry + `host_one` registration in livehost.rs + a re-added accessor in lifecycle.rs), 38 lines of dead/wrong impl. **Always `git diff --stat` after it returns** and confirm it touched ONLY the files you expected; revert any uninvited impl edits (`git checkout -- <file>` for ones you never legitimately changed) before running gates/committing. The subagent's own "the tree didn't compile when I started" note is the tell.
