Repository navigation
Description
Task
T-081b· Milestone M7 — API · Size M · Priority P0 · Epic #7Implements FR-API-001 · FR-DSH-001
Branch
feat/t-081b-api-campaigns-crud-with-full— one task = one branch = one PR (doc 32 §6)
Summary
Implement api/routers/campaigns.py list/create/get/patch/delete: validation per doc 12 §3.1 (space exists; backend registered and supports enabled unpinned params; strategy known and params valid; batch size bounds; budget ≤ runner.max_budget); resolved oracle thresholds snapshotted; start: true starts immediately.
Context / motivation
UC-02/FR-DSH-001 — the wizard posts here.
Scope
In scope
CampaignDTO (doc 12 §3.2) with counts,modes_found,first_failure_at, links.- DELETE only for terminal campaigns.
Implementation guidance
- Shared validation service
runner/campaign_factory.py:class CampaignFactory: def create(self, req: CampaignCreate, *, idempotency_key: str | None) -> Campaign, used by both the API and the CLI (campaign create -f) so the rules exist once. - Checks (doc 12 §3.1), each raising a typed error mapped by T-080b: space+version exists (
NOT_FOUND); backend registered; every enabled unpinned param ∈ backendcapabilities.supported_params(BACKEND_UNSUPPORTED_PARAM, offending names inerrors[]); strategy registered andparamsvalid against its schema (T-060);1 ≤ batch_size ≤ runner.max_batch_size;budget ≤ runner.max_budget; seed defaulted fromsecrets.randbits(31)if omitted, and stored. - Snapshot at creation: resolved oracle thresholds, selection defaults, space version and SUT profile version are stored on the campaign (reproducibility, doc 21 §2).
- Router
api/routers/campaigns.py: list (filtersstatus,strategy,backend; keyset bycreated_at desc), create (201 +Location, honoursIdempotency-Key,start: true⇒ calls lifecycle start), get (with ETag), PATCH (name,tagsonly; If-Match), DELETE (terminal only, 409 otherwise; cascades via repository, artefacts left forgc). CampaignDTO per doc 12 §3.2 includingcounts,modes_found,first_failure_at,links.- 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.
Configuration keys
From the configuration reference (doc 27). Keys marked (new) must be added to the typed settings models and appear in the generated reference (T-003c).
runner.max_budgetrunner.max_batch_size
Acceptance criteria
- Every validation rule has a failing-case test with the correct error code.
- Idempotent create with Idempotency-Key.
- CLI and API produce identical campaign rows for the same YAML (test).
- Snapshot fields populated and immutable after creation.
- DELETE of a RUNNING campaign → 409
CAMPAIGN_INVALID_TRANSITION. - 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_campaigns_crud.py.
Dependencies
Blocked by: #143 (T-080b), #145 (T-080d), #120 (T-060), #79 (T-041c)
Blocks: #148 (T-081c), #149 (T-081d), #151 (T-082a), #152 (T-082b), #157 (T-084a)
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/campaigns.pybackend/src/roboprobe/api/schemas/campaigns.pybackend/src/roboprobe/runner/campaign_factory.py
Parallel with other routers; T-081c adds command routes in a separate 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-081b (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 §3.1 · doc 12 §3.2 · doc 27 §1 · doc 03 §UC-02 · doc 21 §2
Requirements: FR-API-001 · FR-DSH-001 (traceability: doc 28)
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity
/meta(schemas for the wizard) #120:start|:pause|:resume|:cancel) and/progress#148/risk,/risk/slice?x=&y=&anchor=&resolution=) #152