Repository navigation
Description
Task
T-081c· Milestone M7 — API · Size S · Priority P0 · Epic #7Implements FR-API-001 · FR-DSH-002
Branch
feat/t-081c-api-campaign-lifecycle-commands-and— one task = one branch = one PR (doc 32 §6)
Summary
Implement api/routers/campaign_commands.py with colon-suffixed custom-method routes returning 202 + updated Campaign (idempotent), and GET /campaigns/{id}/progress (counters + discovery-curve points).
Context / motivation
US-012 controls from the console; semantics in doc 12 §5.
Scope
In scope
NO_WORKERSwarning-level problem when starting without online workers (doc 12 §1.1).
Implementation guidance
- Router
api/routers/campaign_commands.pywith routes registered literally, e.g.@router.post("/campaigns/{campaign_id}:start")(doc 12 §2 note); add a regression test proving Starlette matches the colon path. - Delegate to the lifecycle state machine from T-041c (
CampaignLifecycle.apply(campaign_id, Command)); return 202 with the updatedCampaignDTO; a repeated command in the target state ⇒ 202 no-op (doc 12 §5). :startwhen no online worker supports the backend still transitions to RUNNING but addswarnings: [{code: "NO_WORKERS", …}]to the body (doc 12 §1.1 "warning-level"); the orchestrator raises theNO_WORKERSalert after 60 s (doc 21 §5.5).GET /campaigns/{id}/progress: counters by status/verdict, current phase,discovery_curve: [{run_ordinal, unique_modes}]computed from runs ordered by ordinal and mode assignment (cached per analysis id).- Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff
PLR2004); public APIs typed (mypy strict) and documented.
Acceptance criteria
- Transition tests (valid, idempotent, invalid → 409
CAMPAIGN_INVALID_TRANSITION). - Progress endpoint matches DB counts.
- Allowed-from table of doc 12 §5 fully covered (parametrised test, 4 commands × 7 states).
- Progress counts equal SQL ground truth on the seed dataset.
- Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
- Docs, config reference and CHANGELOG
Unreleasedupdated where behaviour, keys or interfaces changed. - Definition of Done (doc 32 §3) satisfied.
Tests required
tests/api/test_campaign_commands.py.
Dependencies
Blocked by: #147 (T-081b)
Blocks: #158 (T-084b)
Parallelization notes
Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:
backend/src/roboprobe/api/routers/campaign_commands.py
Independent file.
Definition of Done
Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-081c (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.
References
Design docs: doc 12 §5 · doc 12 §2 · doc 14 §3 · doc 12 §1.1 · doc 21 §5.5
Requirements: FR-API-001 · FR-DSH-002 (traceability: doc 28)
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity
CampaignCreatevalidation #147api/openapi.json) + oasdiff breaking-change check + schemathesis nightly #158