feat(harness): phase.py rewrite + effective_decisions (D15 core fix, F2)
The single most important architectural fix vs ChironeWp3: ALL helpers consult effective_decisions() instead of raw list_decisions(), so the reopen-aware view is consistent everywhere (fixes the bug where approved_ctes/advance_problems conflated stale pre-reopen decisions with new ones). Model (corrected during TDD): - current_phase folds the audit (excluding retracted) with guard 'n == cur' -- already reopen-aware (old phase_approved:N after reopen to M<N don't advance). - effective_decisions = decisions whose phase <= current_phase. A sql_approved at phase 7 is stale when current_phase=4 after a rollback to F4, even if in the ledger. Rollback to F4 does NOT invalidate decisions of phases 1-3 (they stay effective). - decision_retracted markers excluded (audit-only). Also: session/models.py ported (SchemaLinking + Candidate with grounded_values D14a + concept_formulas D14b). MAX_PHASE/PHASE_NAMES read from workflow.yaml via load_workflow() (no duplication). Strada 2: ladder if-phase-N kept for now, generic prerequisites evaluator (F2 full) deferred. 7 phase tests + 20 total passing.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
from datetime import datetime
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, Field, ConfigDict
|
||||
|
||||
|
||||
# Stub locale di _YamlModel (in ChironeWp3 vive in mschema/models.py).
|
||||
# Qui serve solo come base con populate_by_name; mschema/ sara' portato nel Task A9.
|
||||
class _YamlModel(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
|
||||
class SessionManifest(_YamlModel):
|
||||
id: str
|
||||
created_at: datetime
|
||||
status: Literal["open", "closed", "finalized"] = "open"
|
||||
question: str
|
||||
database: str
|
||||
db_schema: str = Field(alias="schema")
|
||||
# D12/D15: autore della sessione (auth) e versione del workflow usato.
|
||||
author: str | None = None
|
||||
summary: str | None = None
|
||||
updated_at: datetime | None = None
|
||||
updated_by: str | None = None
|
||||
schema_version: int | None = None
|
||||
|
||||
|
||||
class Candidate(BaseModel):
|
||||
kind: Literal["table", "column"]
|
||||
name: str
|
||||
signals: dict = {}
|
||||
evidence: list[str] = []
|
||||
decision: Literal["promoted", "excluded", "pending"] = "pending"
|
||||
decision_seq: int | None = None
|
||||
# D14a: valori citati nella domanda ancorati a questa colonna/tabella.
|
||||
grounded_values: list[dict] = []
|
||||
|
||||
|
||||
class Join(BaseModel):
|
||||
from_: str = Field(alias="from")
|
||||
to: str
|
||||
source: str = ""
|
||||
decision: Literal["promoted", "excluded", "pending"] = "promoted"
|
||||
decision_seq: int | None = None
|
||||
|
||||
model_config = {"populate_by_name": True}
|
||||
|
||||
|
||||
class ExcludedItem(BaseModel):
|
||||
kind: Literal["table", "column"]
|
||||
name: str
|
||||
decision_seq: int | None = None
|
||||
|
||||
|
||||
class SchemaLinking(BaseModel):
|
||||
question: str
|
||||
candidates: list[Candidate] = []
|
||||
joins: list[Join] = []
|
||||
excluded: list[ExcludedItem] = []
|
||||
open_questions: list[str] = []
|
||||
# D14b: formule di concetto approvate, parte dello schema-linking.
|
||||
concept_formulas: list[dict] = []
|
||||
|
||||
model_config = {"extra": "forbid"}
|
||||
Reference in New Issue
Block a user