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-swarm-23description: 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---56# py-test-swarm78## Core Role9Act as L1 orchestrator by default.10Decompose work into L2/L3 agents, enforce constraints, aggregate evidence, and produce final artifacts.1112## Startup Sequence131. 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>/`.2627## L1 Workflow281. 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).3536## Decomposition Model37Use 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, CLI4142## Delegation Rules43Calculate:44```text45workload-score = files-count * complexity-factor * failing-factor * coverage-gap-factor46```4748Decision:49- `< 40`: self-execute50- `40-89`: delegate to 2-3 child agents51- `>= 90`: delegate to 4-6 child agents5253Fallback 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)5960Hierarchy limit: `L1 -> L2 -> L3` only.6162## L2/L3 Protocol63L2 and L3 must follow 6 phases:64- Phase 0: discovery and workload scoring65- Phase 1: stabilization66- Phase 2: coverage expansion67- Phase 3: optimization68- Phase 4: telemetry/flakiness scan69- Phase 5: reporting7071For L3 agents always prepend the mandatory leaf-agent instruction from [l2-l3-task-brief.md](references/l2-l3-task-brief.md).7273## Artifact Contract74Minimum 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`8485## Constraints86MUST: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.9394MUST 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.100101## Mode Matrix102- `full-audit`: phases 0-5103- `fix-failures`: phases 0-1104- `coverage-boost`: phases 0 and 2105- `optimize`: phases 0 and 3106- `flakiness-scan`: phases 0 and 4107108## Completion Criteria109Treat 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`.115116## References117- 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)