feat(memory): filter gate-declined candidates from promotion preview

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-07 13:26:59 +02:00
co-authored by Claude Fable 5
parent cadbdf177a
commit bf7e850e6b
2 changed files with 67 additions and 6 deletions
+39 -1
View File
@@ -8,7 +8,9 @@ la rende un passo del workflow. Questi test fissano il contratto harness-side:
"""
from datetime import datetime
from tht.decisions import DecisionRecord
from tht.decisions import DecisionRecord, append_decision
from tht.memory import declined_promotion_seqs, reusable_promotions
from tht.session.models import SessionManifest
from tht.workflow import load_workflow
@@ -24,3 +26,39 @@ def test_promotion_decision_types_min_phase_is_f8():
wf = load_workflow()
assert wf.decision_min_phase("memory_promoted") == 8
assert wf.decision_min_phase("memory_promotion_declined") == 8
def _manifest() -> SessionManifest:
return SessionManifest(
id="s1", created_at=datetime(2026, 1, 1), question="domanda originale",
database="db", schema="public",
)
def test_declined_promotion_seqs_parses_seq_detail():
d = DecisionRecord(
seq=9, ts=datetime(2026, 1, 1), type="memory_promotion_declined",
subject="fact_x", detail="seq:5",
)
assert declined_promotion_seqs([d]) == {5}
def test_declined_promotion_seqs_ignores_malformed_and_other_types():
ds = [
DecisionRecord(seq=1, ts=datetime(2026, 1, 1),
type="memory_promotion_declined", subject="x", detail=""),
DecisionRecord(seq=2, ts=datetime(2026, 1, 1),
type="table_promoted", subject="x", detail="seq:3"),
]
assert declined_promotion_seqs(ds) == set()
def test_reusable_promotions_exclude_declined(tmp_path):
append_decision(tmp_path, type="table_promoted", subject="fact_a",
detail="tab principale", rationale="scelta reviewer") # seq 1
append_decision(tmp_path, type="concept_clarified", subject="attivo",
detail="flag_attivo = TRUE") # seq 2
append_decision(tmp_path, type="memory_promotion_declined",
subject="fact_a", detail="seq:1") # seq 3
cand = reusable_promotions(tmp_path, _manifest(), tmp_path / "registry.jsonl")
assert [c.decision_seq for c in cand] == [2]