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
|
|
@ -7,9 +7,10 @@ import MAF-tainted modules freely (``verdicts``) — only ``notify.py`` itself m
|
|||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import json
|
||||
|
||||
from portfolio_optimiser.notify import ConsoleNotifier, Notifier
|
||||
from portfolio_optimiser.verdicts import ProposalFeatures, Verdict, capture_verdict
|
||||
from portfolio_optimiser.notify import ConsoleNotifier, FileNotifier, Notifier, _verdict_payload
|
||||
from portfolio_optimiser.verdicts import ProposalFeatures, Verdict, capture_verdict, verdict_to_dict
|
||||
|
||||
|
||||
def _verdict() -> Verdict:
|
||||
|
|
@ -40,3 +41,31 @@ def test_console_emits_id_and_decision() -> None:
|
|||
out = stream.getvalue()
|
||||
assert verdict.id in out
|
||||
assert verdict.decision in out
|
||||
|
||||
|
||||
def test_payload_matches_verdict_to_dict_oracle() -> None:
|
||||
"""DRIFT-ORACLE: the duck-typed ``_verdict_payload`` reproduces ``verdict_to_dict``'s exact
|
||||
NESTED shape (verdicts.py:124-139) without importing it at runtime — the test imports both
|
||||
(tests may pull MAF freely) and pins them equal, so a ``Verdict`` shape change goes RED here
|
||||
instead of silently diverging the notified payload."""
|
||||
verdict = _verdict()
|
||||
assert _verdict_payload(verdict) == verdict_to_dict(verdict)
|
||||
|
||||
|
||||
def test_file_notifier_byte_deterministic(tmp_path) -> None:
|
||||
"""FileNotifier appends one JSONL line per verdict — two writes of the same verdict are
|
||||
byte-identical, LF-terminated, nested per the oracle shape, and carry no wall-clock key."""
|
||||
path = tmp_path / "sub" / "notify.jsonl"
|
||||
verdict = _verdict()
|
||||
notifier = FileNotifier(str(path))
|
||||
notifier(verdict)
|
||||
first = path.read_bytes()
|
||||
notifier(verdict)
|
||||
second = path.read_bytes()
|
||||
assert second == first * 2 # identical appended line bytes
|
||||
line = first.decode("utf-8")
|
||||
assert line.endswith("\n")
|
||||
payload = json.loads(line)
|
||||
assert payload["id"] == verdict.id
|
||||
assert payload["proposal_features"]["affected_codes"] == ["03.1", "05.2"]
|
||||
assert not any(k in payload for k in ("date", "timestamp", "created", "ts"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue