feat(s52): MAF-free nested payload builder (verdict_to_dict oracle) + file notifier
This commit is contained in:
parent
d5b583349a
commit
f206dfbf65
2 changed files with 66 additions and 3 deletions
|
|
@ -15,8 +15,10 @@ Registered in ``tests/test_okf.py``'s ``_MAF_FREE_MODULES`` (direct-import guard
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
from typing import TYPE_CHECKING, Protocol, TextIO, runtime_checkable
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Protocol, TextIO, runtime_checkable
|
||||
|
||||
if TYPE_CHECKING: # verdicts imports agent_framework — keep it out of the runtime import graph
|
||||
from portfolio_optimiser.verdicts import Verdict
|
||||
|
|
@ -46,3 +48,35 @@ class ConsoleNotifier:
|
|||
|
||||
def __call__(self, verdict: Verdict) -> None:
|
||||
print(f"[notify] verdict {verdict.id} decision={verdict.decision}", file=self._stream)
|
||||
|
||||
|
||||
def _verdict_payload(verdict: Verdict) -> dict[str, Any]:
|
||||
"""NESTED, byte-deterministic, duck-typed payload — reproduces ``verdicts.verdict_to_dict``'s
|
||||
exact shape (verdicts.py:124-139) WITHOUT importing it (a runtime import would pull
|
||||
``agent_framework``). Pinned against drift by the ``== verdict_to_dict(v)`` oracle test."""
|
||||
f = verdict.proposal_features
|
||||
return {
|
||||
"id": verdict.id,
|
||||
"decision": verdict.decision,
|
||||
"rationale": verdict.rationale,
|
||||
"proposal_features": {
|
||||
"affected_codes": sorted(f.affected_codes),
|
||||
"measure_type": f.measure_type,
|
||||
"claimed_saving_nok": f.claimed_saving_nok,
|
||||
"description": f.description,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class FileNotifier:
|
||||
"""Appends one JSONL line per verdict (byte-deterministic: ``sort_keys`` + LF, no wall-clock —
|
||||
the ``outbox._dump`` idiom). Parent directories are created as needed."""
|
||||
|
||||
def __init__(self, path: str) -> None:
|
||||
self._path = Path(path)
|
||||
|
||||
def __call__(self, verdict: Verdict) -> None:
|
||||
self._path.parent.mkdir(parents=True, exist_ok=True)
|
||||
line = json.dumps(_verdict_payload(verdict), sort_keys=True) + "\n"
|
||||
with self._path.open("a", encoding="utf-8") as handle:
|
||||
handle.write(line)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue