STATE-WP-0069 T04/T06: body metering and workplan-first state internals
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s

Share LegacyWorkstreamIdBodyMixin across create schemas; meter POST /tasks/
and /decisions/ workstream_id bodies. State summary uses workplan flow;
NextStep dual-writes workplan_* fields alongside legacy workstream_*.
This commit is contained in:
tegwick 2026-07-08 23:13:28 +02:00
parent 6e5e150803
commit 388b330809
11 changed files with 157 additions and 36 deletions

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import uuid
from typing import Any
from pydantic import AliasChoices, Field, computed_field, model_validator
@ -13,6 +14,20 @@ def workplan_id_field(*, default: uuid.UUID | None = None) -> uuid.UUID | None:
)
class LegacyWorkstreamIdBodyMixin:
"""Detect POST/PUT bodies that used legacy ``workstream_id`` without ``workplan_id``."""
used_legacy_workstream_id: bool = Field(default=False, exclude=True)
@model_validator(mode="before")
@classmethod
def _detect_legacy_workstream_id(cls, data: Any) -> Any:
if isinstance(data, dict):
if data.get("workstream_id") is not None and data.get("workplan_id") is None:
return {**data, "used_legacy_workstream_id": True}
return data
class WorkplanIdCompatMixin:
"""Accept ``workplan_id`` or legacy ``workstream_id`` on input; emit both on output."""
@ -24,7 +39,7 @@ class WorkplanIdCompatMixin:
return self.workplan_id
class WorkplanIdCreateMixin:
class WorkplanIdCreateMixin(LegacyWorkstreamIdBodyMixin):
workplan_id: uuid.UUID | None = workplan_id_field(default=None)
@model_validator(mode="after")