Skip to content

[T-081b] API: campaigns CRUD with full CampaignCreate validation #147

Closed

Description

@CodewithJha

Task T-081b · Milestone M7 — API · Size M · Priority P0 · Epic #7

Implements 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

  • Campaign DTO (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 ∈ backend capabilities.supported_params (BACKEND_UNSUPPORTED_PARAM, offending names in errors[]); strategy registered and params valid against its schema (T-060); 1 ≤ batch_size ≤ runner.max_batch_size; budget ≤ runner.max_budget; seed defaulted from secrets.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 (filters status, strategy, backend; keyset by created_at desc), create (201 + Location, honours Idempotency-Key, start: true ⇒ calls lifecycle start), get (with ETag), PATCH (name, tags only; If-Match), DELETE (terminal only, 409 otherwise; cascades via repository, artefacts left for gc).
  • Campaign DTO per doc 12 §3.2 including counts, 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_budget
  • runner.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 Unreleased updated 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.py
  • backend/src/roboprobe/api/schemas/campaigns.py
  • backend/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)

Activity

  1. added this to the M7 — API milestone on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiREST + SSE API (FastAPI)milestone:M7M7 — APIpriority:P0Critical path / blocks otherssize:M1-3 daystaskChild task of a milestone epictype:featureNew functionality

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions