072: file A valider, contexte de fil (Thread-Index), fil dans la lecture, filtre informations dans Suivi

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XGaEeTZLvHXfYPUNWkgYoi
This commit is contained in:
claudeandClaude Sonnet 5.5 committed 2026-11-20 23:31:20 +01:00
1 parent 5d98d08a8b
commit c7c28f4079
5 files changed
+337 -16

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
import pytest
from app import analyse as a
from app.classifier import manual_classify_and_propose
from app.config import get_tunis_now_iso
from app.db import list_courses, get_classement
pytestmark = pytest.mark.regles_off
def _fiche(cat="Pb PO", course=None):
return {"categorie": cat, "confiance": "haute", "resume": "Resume.", "course": course,
"demande": {"reelle": False, "action": "", "echeance": ""}}
def _maintenant():
return get_tunis_now_iso()[:19]
def test_proposition_categorie_puis_acceptation(temp_db):
a.enregistrer("m1", _fiche(), "PO 123", "x@tt.tn", _maintenant(), temp_db)
items = a.a_valider(db_path=temp_db)
assert [(i["type"], i["propose"]) for i in items] == [("categorie", "Pb PO")]
a.decider("m1", "categorie", "accepter", temp_db)
c = get_classement("m1", temp_db)
assert c["categorie"] == "Pb PO" and c["source"] == "manuel"
assert a.a_valider(db_path=temp_db) == []
def test_refus_ne_revient_pas(temp_db):
a.enregistrer("m2", _fiche("Box 5G"), "Box", "x@tt.tn", _maintenant(), temp_db)
a.decider("m2", "categorie", "refuser", temp_db)
assert a.a_valider(db_path=temp_db) == []
assert get_classement("m2", temp_db) is None or get_classement("m2", temp_db)["categorie"] == "À classer"
def test_classement_manuel_jamais_propose(temp_db):
manual_classify_and_propose("m3", "Tunis", {"expediteur": "a@b", "objet": "x"}, db_path=temp_db)
a.enregistrer("m3", _fiche("Pb PO"), "x", "a@b", _maintenant(), temp_db)
assert a.a_valider(db_path=temp_db) == []
def test_course_acceptee_creee_une_fois(temp_db):
course = {"objets": ["dossier signé"], "documents": [], "sens": "sfax_tunis"}
a.enregistrer("m4", _fiche("À classer", course), "Dossier", "x@tt.tn", _maintenant(), temp_db)
items = a.a_valider(db_path=temp_db)
assert [(i["type"], i["sens"]) for i in items] == [("course", "sfax_tunis")]
r = a.decider("m4", "course", "accepter", temp_db)
assert r["course"]["message_id"] == "m4"
assert len([k for k in list_courses(None, db_path=temp_db) if k["message_id"] == "m4"]) == 1
assert a.a_valider(db_path=temp_db) == []
def test_decision_invalide(temp_db):
a.enregistrer("m5", _fiche(), "x", "x", _maintenant(), temp_db)
with pytest.raises(ValueError):
a.decider("m5", "autre", "accepter", temp_db)
with pytest.raises(LookupError):
a.decider("inconnu", "categorie", "accepter", temp_db)
+41
View File
@@ -0,0 +1,41 @@
import base64
import pytest
from app import analyse as a
from app.classifier import manual_classify_and_propose
pytestmark = pytest.mark.regles_off
def _ti(prefix: bytes, suffix: bytes = b"") -> str:
return base64.b64encode(prefix.ljust(22, b"\0") + suffix).decode()
def test_cle_fil_commune_malgre_suffixe_different():
assert a.cle_fil(_ti(b"abc", b"12345")) == a.cle_fil(_ti(b"abc", b"zzzzzz"))
assert a.cle_fil(_ti(b"abc")) != a.cle_fil(_ti(b"abd"))
def test_cle_fil_illisible():
assert a.cle_fil("") is None and a.cle_fil("!!!") is None
def _fiche(cat="Tunis", resume="R."):
return {"categorie": cat, "confiance": "haute", "resume": resume, "course": None,
"demande": {"reelle": False, "action": "", "echeance": ""}}
def test_contexte_fil_reprend_le_choix_de_nabil(temp_db):
fil = a.cle_fil(_ti(b"fil1"))
a.enregistrer("m1", _fiche("Tunis", "Course demandee pour lundi."), "Course Tunis", "x", "2026-11-18T10:00:00", temp_db, fil)
manual_classify_and_propose("m1", "Tunis", {"expediteur": "x", "objet": "Course Tunis"}, db_path=temp_db)
a.enregistrer("m2", _fiche("Sans objet"), "Re: autre objet", "x", "2026-11-19T10:00:00", temp_db, fil)
ctx = a.contexte_fil(fil, "m2", temp_db)
assert "categorie choisie par Nabil : Tunis" in ctx and "Course demandee pour lundi." in ctx
assert a.contexte_fil(fil, "m1", temp_db).count("\n") == 0
assert a.contexte_fil(None, "m2", temp_db) == ""
def test_prompt_mentionne_le_contexte():
m = a.construire_messages("o", "e", "corps", ["Tunis"], "- ctx")
assert "Contexte du fil" in m[1]["content"] and "conversation" in m[0]["content"]
assert "Contexte du fil" not in a.construire_messages("o", "e", "corps", ["Tunis"])[1]["content"]