state-hub/api/schemas/intake.py
tegwick 88ba666c95
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 2s
Build and Publish Multi-Context Image / build-and-push (push) Successful in 1m23s
CUST-WP-0061-T01: intake work-record entity (stage 3)
Fresh hub entity per the founder-reviewed decision (not a suggestions
rename-bridge): kind: intake per canon/standards/work-record-types_v0.1.md,
lifecycle open -> vetted -> routed -> closed(promoted|declined|absorbed).

- api/models/base.py::new_uuid7 -- dependency-free RFC 9562 UUIDv7
  generator (48-bit ms timestamp, version/variant bits, random remainder);
  existing tables keep new_uuid (UUIDv4) unchanged, this is opt-in for new
  work-record entities per the identity-layering canon
- api/models/intake.py: Intake + IntakeNote ORM models, mirroring
  Decision's shape (topic/workplan/repo scope, lane, status, outcome,
  promoted_to back-link); CHECK constraints enforce scope-required,
  closed-requires-outcome, promoted-requires-promoted_to at the DB level
- migrations/a7c3e9f1b4d2: intakes + intake_notes tables, 3 enum types
- api/routers/intake.py: list/create/get/patch + /route + /close + /notes
  actions, mirroring decisions.py's pattern (409 on invalid transitions,
  progress event on close)
- api/schemas/intake.py: Pydantic create/update/route/close/note schemas
- mcp_server/server.py: create_intake, list_intakes, route_intake,
  close_intake tool wrappers
- tests/test_intake.py: 12 tests against the real Postgres test DB
  (create/list/scope-validation, full lifecycle incl. 409s and the
  promoted-requires-promoted_to constraint, notes, UUIDv7 verification)

Verified live against the running dev API + DB (not just pytest): applied
the migration, restarted the MCP server, and ran a full create -> route ->
close cycle over the real REST endpoints. No regressions: full existing
suite (test_routers_core, test_suggestions, test_mcp_smoke,
test_mcp_write_tools, test_mcp_registration, test_consistency_check,
test_consistency_sweep) all green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 00:27:45 +02:00

88 lines
2.5 KiB
Python

import uuid
from datetime import datetime
from pydantic import BaseModel, ConfigDict, model_validator
from api.models.intake import IntakeLane, IntakeOutcome, IntakeStatus
class IntakeCreate(BaseModel):
topic_id: uuid.UUID | None = None
workplan_id: uuid.UUID | None = None
repo_id: uuid.UUID | None = None
title: str
description: str | None = None
lane: IntakeLane = IntakeLane.green
origin: str | None = None
origin_ref: str | None = None
source_repo_path: str | None = None
@model_validator(mode="after")
def scope_required(self) -> "IntakeCreate":
if self.topic_id is None and self.workplan_id is None and self.repo_id is None:
raise ValueError("At least one of topic_id, workplan_id, or repo_id must be set")
return self
class IntakeUpdate(BaseModel):
title: str | None = None
description: str | None = None
lane: IntakeLane | None = None
status: IntakeStatus | None = None
origin: str | None = None
origin_ref: str | None = None
routed_note: str | None = None
class IntakeRoute(BaseModel):
"""Move an intake from open/vetted into routed — the state that makes
it eligible for the promotion transition (CUST-WP-0061-T03)."""
routed_note: str | None = None
class IntakeClose(BaseModel):
outcome: IntakeOutcome
promoted_to: str | None = None
note: str | None = None
@model_validator(mode="after")
def promoted_requires_target(self) -> "IntakeClose":
if self.outcome == IntakeOutcome.promoted and not self.promoted_to:
raise ValueError("outcome=promoted requires promoted_to")
return self
class IntakeNoteCreate(BaseModel):
content: str
author: str | None = None
class IntakeNoteRead(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: uuid.UUID
author: str | None = None
content: str
created_at: datetime
class IntakeRead(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: uuid.UUID
topic_id: uuid.UUID | None = None
workplan_id: uuid.UUID | None = None
repo_id: uuid.UUID | None = None
title: str
description: str | None = None
lane: IntakeLane
status: IntakeStatus
outcome: IntakeOutcome | None = None
origin: str | None = None
origin_ref: str | None = None
promoted_to: str | None = None
source_repo_path: str | None = None
routed_note: str | None = None
closed_at: datetime | None = None
created_at: datetime
updated_at: datetime
notes: list[IntakeNoteRead] = []