feat: brouillon de reponse copiable, briefing, balayage mobile, resume de pieces jointes, apprentissage par exemples, sauvegarde quotidienne, vue Aujourd'hui, references PO/AO, correctif reponses vides des modeles de raisonnement
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XGaEeTZLvHXfYPUNWkgYoi
This commit is contained in:
1 parent
f87c56fee7
commit
054a4d64e8
15 files changed
+721
-19
No files matched your search
@@ -0,0 +1,14 @@
|
||||
from app import analyse as a
|
||||
|
||||
|
||||
def _f(act, ech):
|
||||
return {"categorie": "À classer", "confiance": "basse", "resume": "x", "course": None,
|
||||
"demande": {"reelle": True, "action": act, "echeance": ech}}
|
||||
|
||||
|
||||
def test_briefing_demandes_ouvertes_triees(temp_db):
|
||||
a.enregistrer("a", _f("Repondre", "30/11/2026"), "oa", "e@x", "2026-11-20T08:00:00", temp_db)
|
||||
a.enregistrer("b", _f("Signer", "25/11/2026"), "ob", "e@x", "2026-11-20T09:00:00", temp_db)
|
||||
r = a.briefing("2026-11-21", temp_db)
|
||||
assert [i["message_id"] for i in r["demandes_ouvertes"]] == ["b", "a"]
|
||||
assert r["courses_a_faire"] == [] and r["a_suivre_actifs"] == []
|
||||
@@ -0,0 +1,35 @@
|
||||
import pytest
|
||||
from app import brouillon as b, ia
|
||||
|
||||
|
||||
def test_assainir_garde_la_mise_en_page_et_retire_le_dangereux():
|
||||
h = b.assainir('<p onclick="x()">Bonjour <strong>Samia</strong></p><script>alert(1)</script><a href="http://x">lien</a><ul><li>un</li></ul>')
|
||||
assert h == "<p>Bonjour <strong>Samia</strong></p>lien<ul><li>un</li></ul>"
|
||||
assert "onclick" not in h and "script" not in h and "href" not in h
|
||||
|
||||
|
||||
def test_assainir_ferme_les_balises_et_echappe():
|
||||
assert b.assainir("<p>a < b <strong>gras") == "<p>a < b <strong>gras</strong></p>"
|
||||
|
||||
|
||||
def test_texte_brut():
|
||||
assert b.en_texte("<p>Bonjour,</p><p>Merci.<br>A bientot</p><ul><li>un</li></ul>") == "Bonjour,\nMerci.\nA bientot\n- un"
|
||||
|
||||
|
||||
def test_rediger_via_privaite_seulement(monkeypatch):
|
||||
vus = {}
|
||||
def faux(messages, max_tokens=30):
|
||||
vus["m"] = messages
|
||||
return "```html\n<p>Bonjour,</p><p>C'est note.</p><p>Cordialement,<br>Nabil Derouiche</p>\n```"
|
||||
monkeypatch.setattr(ia, "appeler_privaite", faux)
|
||||
r = b.rediger("PO 123", "x@tt.tn", "Merci de confirmer", "- ctx", "dire oui")
|
||||
assert r["objet"] == "RE: PO 123" and "<p>Bonjour,</p>" in r["html"] and "```" not in r["html"]
|
||||
assert "Contexte du fil" in vus["m"][1]["content"] and "dire oui" in vus["m"][1]["content"]
|
||||
|
||||
|
||||
def test_refus_net_si_privaite_injoignable(monkeypatch):
|
||||
def casse(messages, max_tokens=30):
|
||||
raise ia.IAIndisponible("PrivAiTe injoignable")
|
||||
monkeypatch.setattr(ia, "appeler_privaite", casse)
|
||||
with pytest.raises(ia.IAIndisponible):
|
||||
b.rediger("o", "e", "c")
|
||||
@@ -0,0 +1,35 @@
|
||||
import pytest
|
||||
from app import analyse as a
|
||||
from app.classifier import manual_classify_and_propose
|
||||
|
||||
pytestmark = pytest.mark.regles_off
|
||||
|
||||
|
||||
def _f(cat, resume="R."):
|
||||
return {"categorie": cat, "confiance": "haute", "resume": resume, "course": None,
|
||||
"demande": {"reelle": False, "action": "", "echeance": ""}}
|
||||
|
||||
|
||||
def test_exemples_max_par_categorie_et_pas_de_corps(temp_db):
|
||||
for i in range(5):
|
||||
manual_classify_and_propose("t%d" % i, "Tunis", {"expediteur": "a@b", "objet": "Course %d" % i}, db_path=temp_db)
|
||||
manual_classify_and_propose("p1", "Pb PO", {"expediteur": "c@d", "objet": "PO 1"}, db_path=temp_db)
|
||||
ex = a.exemples_nabil(temp_db)
|
||||
assert ex.count("=> Tunis") == 3 and "=> Pb PO" in ex
|
||||
|
||||
|
||||
def test_refus_devient_contre_exemple_et_stats(temp_db):
|
||||
a.enregistrer("m1", _f("Box 5G"), "Rapport regional", "x@tt.tn", "2026-11-21T09:00:00", temp_db)
|
||||
a.decider("m1", "categorie", "refuser", temp_db)
|
||||
assert "PAS Box 5G" in a.exemples_nabil(temp_db)
|
||||
a.enregistrer("m2", _f("CI"), "Travaux", "x@tt.tn", "2026-11-21T09:00:00", temp_db)
|
||||
a.decider("m2", "categorie", "accepter", temp_db)
|
||||
st = a.stats_acceptation(temp_db)
|
||||
assert st["total"] == {"acceptees": 1, "refusees": 1}
|
||||
assert st["categories"]["CI"]["acceptees"] == 1 and st["categories"]["Box 5G"]["refusees"] == 1
|
||||
|
||||
|
||||
def test_prompt_inclut_exemples_sans_imposer_de_regle():
|
||||
m = a.construire_messages("o", "e", "c", ["Tunis"], "", "- x | y => Tunis")
|
||||
assert "Exemples de choix reels" in m[0]["content"] and "autre categorie un autre jour" in m[0]["content"]
|
||||
assert "Exemples de choix reels" not in a.construire_messages("o", "e", "c", ["Tunis"])[0]["content"]
|
||||
@@ -0,0 +1,24 @@
|
||||
import io
|
||||
import zipfile
|
||||
import pytest
|
||||
from app import piece_ia as p
|
||||
|
||||
|
||||
def _docx(txt):
|
||||
b = io.BytesIO()
|
||||
with zipfile.ZipFile(b, "w") as z:
|
||||
z.writestr("word/document.xml", '<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:r><w:t>' + txt + "</w:t></w:r></w:p></w:body></w:document>")
|
||||
return b.getvalue()
|
||||
|
||||
|
||||
def test_texte_et_docx():
|
||||
long = "Bon de commande numero 4500123 pour la livraison de dix ordinateurs avant le 30/11/2026."
|
||||
assert "4500123" in p.extraire_texte("a.txt", long.encode())
|
||||
assert "4500123" in p.extraire_texte("a.docx", _docx(long))
|
||||
|
||||
|
||||
def test_type_inconnu_et_vide():
|
||||
with pytest.raises(p.SansTexte):
|
||||
p.extraire_texte("a.exe", b"x" * 100)
|
||||
with pytest.raises(p.SansTexte):
|
||||
p.extraire_texte("a.txt", b"court")
|
||||
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
import sqlite3
|
||||
from app import sauvegarde as s
|
||||
from app.db import init_db
|
||||
|
||||
|
||||
def _base(tmp_path):
|
||||
p = str(tmp_path / "courrier.db")
|
||||
init_db(p)
|
||||
return p
|
||||
|
||||
|
||||
def test_une_par_jour_et_rotation(tmp_path):
|
||||
db = _base(tmp_path)
|
||||
assert s.sauvegarder(db) is not None
|
||||
assert s.sauvegarder(db) is None
|
||||
d = s._dossier(db)
|
||||
for i in range(20):
|
||||
open(os.path.join(d, "courrier-2020-01-%02d.db" % (i + 1)), "w").write("x")
|
||||
s.sauvegarder(db, force=True)
|
||||
assert len(s.liste(db)) == s.CONSERVES
|
||||
assert s.liste(db)[0]["jour"] >= "2026"
|
||||
|
||||
|
||||
def test_copie_lisible(tmp_path):
|
||||
db = _base(tmp_path)
|
||||
n = s.sauvegarder(db)
|
||||
c = sqlite3.connect(os.path.join(s._dossier(db), n))
|
||||
assert c.execute("select count(*) from sqlite_master").fetchone()[0] > 0
|
||||
c.close()
|
||||
Reference in new issue
Block a user