feat(vwb): harden supervised verdict evidence

This commit is contained in:
Dom
2026-05-29 18:54:54 +02:00
parent d515b22d1b
commit 47377226f2
6 changed files with 121 additions and 0 deletions

View File

@@ -66,6 +66,13 @@ def store_competence_verdict(
context_signature = _context_signature(payload.get("context_signature"))
evidence = _mapping(payload.get("evidence"), field="evidence")
source = _mapping(payload.get("source"), field="source")
workflow_id = (
_optional_text(payload, "workflow_id")
or _optional_text(source, "workflow_id")
or _optional_text(evidence, "workflow_id")
or ""
)
step_results = _step_results(payload.get("step_results"))
record = {
"schema_version": SCHEMA_VERSION,
@@ -73,10 +80,12 @@ def store_competence_verdict(
"competence_id": competence.id,
"competence_source_path": competence.source_path,
"learning_state": competence.learning_state,
"workflow_id": workflow_id,
"verdict_kind": verdict_kind,
"verdict_at": verdict_at,
"verdict_by": str(payload.get("verdict_by") or "human:dom"),
"context_signature": context_signature,
"step_results": step_results,
"evidence": evidence,
"comments": str(payload.get("comments") or ""),
"source": source,
@@ -125,6 +134,16 @@ def _required_text(payload: Dict[str, Any], key: str) -> str:
return value.strip()
def _optional_text(payload: Dict[str, Any], key: str) -> Optional[str]:
value = payload.get(key)
if value is None:
return None
if not isinstance(value, str):
raise CompetenceVerdictError(f"{key} doit etre du texte")
text = value.strip()
return text or None
def _validate_uuid(value: str) -> None:
try:
parsed = uuid.UUID(value, version=4)
@@ -174,6 +193,19 @@ def _mapping(value: Any, *, field: str) -> Dict[str, Any]:
return dict(value)
def _step_results(value: Any) -> list[Dict[str, Any]]:
if value is None:
return []
if not isinstance(value, list):
raise CompetenceVerdictError("step_results doit etre une liste")
results: list[Dict[str, Any]] = []
for item in value:
if not isinstance(item, dict):
raise CompetenceVerdictError("step_results doit contenir des objets")
results.append(dict(item))
return results
def _append_jsonl(log_path: Path, record: Dict[str, Any]) -> None:
log_path.parent.mkdir(parents=True, exist_ok=True)
with log_path.open("a", encoding="utf-8") as handle: