py-test-swarm
Core Role
Act as L1 orchestrator by default.
Decompose work into L2/L3 agents, enforce constraints, aggregate evidence, and produce final artifacts.
Startup Sequence
- Read memory:
../../../.ai/memory/agent-memory.md
../../../.ai/memory/memory-py-test-bot.md
../../../.claude/agents/ORCHESTRATION.md (sections 2-7)
- Read profile:
../../../.claude/agents/py-test-swarm.md
- Confirm input contract:
task_id (required)
mode (required): full_audit | fix_failures | coverage_boost | optimize | flakiness_scan
scope (optional, default all tests)
baseline_report (optional)
flakiness_runs (optional, default 5)
- Create artifact root:
reports/test-swarm/<task_id>/.
L1 Workflow
- Run Discovery baseline commands from l1-playbook.md.
- Build
00-swarm-plan.md with workload scores and parallel execution plan.
- Launch L2 agents with full task brief template from l2-l3-task-brief.md.
- Limit concurrent L2 agents to 4; run independent scopes in parallel.
- Collect all L2/L3
report.md, metrics.json, and telemetry JSONL.
- Build aggregated telemetry and flaky DB using telemetry-and-flaky-db.md.
- Produce
FINAL-REPORT.md from report-templates.md.
Decomposition Model
Use three axes:
- Architecture layers:
domain, application, infrastructure, composition, interfaces
- Test types:
unit, integration, e2e, architecture, contract, smoke, performance, security
- Infrastructure zones: adapters/providers, transformation, storage, DQ, retry/circuit-breaker, checkpoint/locking/heartbeat, observability, CLI
Delegation Rules
Calculate:
workload_score = files_count * complexity_factor * failing_factor * coverage_gap_factor
Decision:
< 40: self-execute
40-89: delegate to 2-3 child agents
>= 90: delegate to 4-6 child agents
Fallback delegation triggers (if formula is not practical):
- test files in scope
> 30
- failing tests
> 15
- modules without tests
> 10
- estimated runtime
> 20 min
- flaky rate
> 10% (spawn dedicated flaky triage agent)
Hierarchy limit: L1 -> L2 -> L3 only.
L2/L3 Protocol
L2 and L3 must follow 6 phases:
- Phase 0: discovery and workload scoring
- Phase 1: stabilization
- Phase 2: coverage expansion
- Phase 3: optimization
- Phase 4: telemetry/flakiness scan
- Phase 5: reporting
For L3 agents always prepend the mandatory leaf-agent instruction from l2-l3-task-brief.md.
Artifact Contract
Minimum required outputs:
reports/test-swarm/<task_id>/00-swarm-plan.md
reports/test-swarm/<task_id>/L2-*/report.md
reports/test-swarm/<task_id>/L2-*/metrics.json
reports/test-swarm/<task_id>/telemetry/raw/events_*.jsonl
reports/test-swarm/<task_id>/telemetry/aggregated/failure_stats.csv
reports/test-swarm/<task_id>/telemetry/aggregated/flaky_index.csv
reports/test-swarm/<task_id>/telemetry/failure_frequency_summary.md
reports/test-swarm/<task_id>/flakiness-database.json
reports/test-swarm/<task_id>/FINAL-REPORT.md
Constraints
MUST:
- Keep architecture boundaries and no I/O in domain.
- Use
uv run python -m pytest ... and uv run python -m mypy --strict ....
- Keep swarm changes in tests/reporting artifacts; do not modify production code unless explicitly requested outside swarm.
- Use VCR/respx for HTTP tests; keep secrets out of cassettes.
- Add regression tests for fixed failures when fixes are applied.
- Provide evidence (
file + lines + command) for architectural claims.
MUST NOT:
- Remove tests without rationale.
- Hide failures via unjustified
skip.
- Add test-only logic in
src/bioetl/.
- Exceed L3 depth.
- Leak secrets in logs/reports/cassettes.
Mode Matrix
full_audit: phases 0-5
fix_failures: phases 0-1
coverage_boost: phases 0 and 2
optimize: phases 0 and 3
flakiness_scan: phases 0 and 4
Completion Criteria
Treat task as done only when:
- all active agents wrote
report.md and metrics.json;
- L2 orchestrators aggregated L3 reports (if any);
- L1 generated
FINAL-REPORT.md;
- telemetry aggregates + flaky DB are generated;
- unresolved assumptions are explicitly marked
Requires Manual Review.
References
- L1 runbook and command sequence: l1-playbook.md
- L2/L3 task briefs and prompt templates: l2-l3-task-brief.md
- Report and metrics templates: report-templates.md
- Telemetry schema and flaky DB contract: telemetry-and-flaky-db.md
1---2name: py-test-swarm3description: Orchestrate hierarchical BioETL test swarms (L1/L2/L3) for full_audit, fix_failures, coverage_boost, optimize, and flakiness_scan with workload-based delegation, telemetry aggregation, flaky analysis, and final reporting in reports/test-swarm/task-id/FINAL-REPORT.md. Use when users request broad test campaigns, failure triage at scale, coverage expansion, or stability diagnostics across layers/providers.4---5
6# py-test-swarm
7
8## Core Role
9Act as L1 orchestrator by default.
10Decompose work into L2/L3 agents, enforce constraints, aggregate evidence, and produce final artifacts.
11
12## Startup Sequence
131. Read memory:
14- `../../../.ai/memory/agent-memory.md`
15- `../../../.ai/memory/memory-py-test-bot.md`
16- `../../../.claude/agents/ORCHESTRATION.md` (sections 2-7)
172. Read profile:
18- `../../../.claude/agents/py-test-swarm.md`
193. Confirm input contract:
20- `task_id` (required)
21- `mode` (required): `full_audit | fix_failures | coverage_boost | optimize | flakiness_scan`
22- `scope` (optional, default all tests)
23- `baseline_report` (optional)
24- `flakiness_runs` (optional, default `5`)
254. Create artifact root: `reports/test-swarm/<task_id>/`.
26
27## L1 Workflow
281. Run Discovery baseline commands from [l1-playbook.md](references/l1-playbook.md).
292. Build `00-swarm-plan.md` with workload scores and parallel execution plan.
303. Launch L2 agents with full task brief template from [l2-l3-task-brief.md](references/l2-l3-task-brief.md).
314. Limit concurrent L2 agents to 4; run independent scopes in parallel.
325. Collect all L2/L3 `report.md`, `metrics.json`, and telemetry JSONL.
336. Build aggregated telemetry and flaky DB using [telemetry-and-flaky-db.md](references/telemetry-and-flaky-db.md).
347. Produce `FINAL-REPORT.md` from [report-templates.md](references/report-templates.md).
35
36## Decomposition Model
37Use three axes:
38- Architecture layers: `domain`, `application`, `infrastructure`, `composition`, `interfaces`
39- Test types: `unit`, `integration`, `e2e`, `architecture`, `contract`, `smoke`, `performance`, `security`
40- Infrastructure zones: adapters/providers, transformation, storage, DQ, retry/circuit-breaker, checkpoint/locking/heartbeat, observability, CLI
41
42## Delegation Rules
43Calculate:
44```text
45workload_score = files_count * complexity_factor * failing_factor * coverage_gap_factor
46```
47
48Decision:
49- `< 40`: self-execute
50- `40-89`: delegate to 2-3 child agents
51- `>= 90`: delegate to 4-6 child agents
52
53Fallback delegation triggers (if formula is not practical):
54- test files in scope `> 30`
55- failing tests `> 15`
56- modules without tests `> 10`
57- estimated runtime `> 20 min`
58- flaky rate `> 10%` (spawn dedicated flaky triage agent)
59
60Hierarchy limit: `L1 -> L2 -> L3` only.
61
62## L2/L3 Protocol
63L2 and L3 must follow 6 phases:
64- Phase 0: discovery and workload scoring
65- Phase 1: stabilization
66- Phase 2: coverage expansion
67- Phase 3: optimization
68- Phase 4: telemetry/flakiness scan
69- Phase 5: reporting
70
71For L3 agents always prepend the mandatory leaf-agent instruction from [l2-l3-task-brief.md](references/l2-l3-task-brief.md).
72
73## Artifact Contract
74Minimum required outputs:
75- `reports/test-swarm/<task_id>/00-swarm-plan.md`
76- `reports/test-swarm/<task_id>/L2-*/report.md`
77- `reports/test-swarm/<task_id>/L2-*/metrics.json`
78- `reports/test-swarm/<task_id>/telemetry/raw/events_*.jsonl`
79- `reports/test-swarm/<task_id>/telemetry/aggregated/failure_stats.csv`
80- `reports/test-swarm/<task_id>/telemetry/aggregated/flaky_index.csv`
81- `reports/test-swarm/<task_id>/telemetry/failure_frequency_summary.md`
82- `reports/test-swarm/<task_id>/flakiness-database.json`
83- `reports/test-swarm/<task_id>/FINAL-REPORT.md`
84
85## Constraints
86MUST:
87- Keep architecture boundaries and no I/O in domain.
88- Use `uv run python -m pytest ...` and `uv run python -m mypy --strict ...`.
89- Keep swarm changes in tests/reporting artifacts; do not modify production code unless explicitly requested outside swarm.
90- Use VCR/respx for HTTP tests; keep secrets out of cassettes.
91- Add regression tests for fixed failures when fixes are applied.
92- Provide evidence (`file + lines + command`) for architectural claims.
93
94MUST NOT:
95- Remove tests without rationale.
96- Hide failures via unjustified `skip`.
97- Add test-only logic in `src/bioetl/`.
98- Exceed L3 depth.
99- Leak secrets in logs/reports/cassettes.
100
101## Mode Matrix
102- `full_audit`: phases 0-5
103- `fix_failures`: phases 0-1
104- `coverage_boost`: phases 0 and 2
105- `optimize`: phases 0 and 3
106- `flakiness_scan`: phases 0 and 4
107
108## Completion Criteria
109Treat task as done only when:
110- all active agents wrote `report.md` and `metrics.json`;
111- L2 orchestrators aggregated L3 reports (if any);
112- L1 generated `FINAL-REPORT.md`;
113- telemetry aggregates + flaky DB are generated;
114- unresolved assumptions are explicitly marked `Requires Manual Review`.
115
116## References
117- L1 runbook and command sequence: [l1-playbook.md](references/l1-playbook.md)
118- L2/L3 task briefs and prompt templates: [l2-l3-task-brief.md](references/l2-l3-task-brief.md)
119- Report and metrics templates: [report-templates.md](references/report-templates.md)
120- Telemetry schema and flaky DB contract: [telemetry-and-flaky-db.md](references/telemetry-and-flaky-db.md)