feat(maria-dashboard): reset pentru firele de discutie active
Nu exista nicio cale sa resetezi manual un fir blocat pe o discutie veche (nici comanda de chat, nici buton) — un test in grupul "Maria Test" a ramas ancorat pe un subiect vechi fara sa poata fi curatat fara interventie directa pe server. Sectiune noua in dashboard, intre "Trimise la suport" si "Clienti cunoscuti": listeaza firele active din ~/.maria-bridge/conversations/ si le sterge la cerere (rutele GET/POST /api/maria/fire), cu aceeasi sanitizare de nume de fisier ca rag/fir.py (oglinda, nu import — coliziune de modul intre proiecte). 11/11 teste (6 noi + cele de clienti), fara regresii. Co-Authored-By: Claude Agent <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
"""Teste pentru firele de discutie Maria din dashboard/api.py.
|
||||
|
||||
Apeleaza direct functiile, cu MARIA_STATE_DIR mutat in tmp — la fel ca
|
||||
test_maria_clients.py.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import pathlib
|
||||
import re
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(ROOT))
|
||||
sys.path.insert(0, str(ROOT / "dashboard"))
|
||||
|
||||
api = pytest.importorskip("api", reason="dashboard/api.py")
|
||||
|
||||
JID = "120363409761730101@g.us"
|
||||
|
||||
|
||||
def _sanitizat(jid: str) -> str:
|
||||
# aceeasi transformare ca rag/fir.py:_cale
|
||||
return re.sub(r"[^0-9a-zA-Z@._-]", "_", jid) + ".json"
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def maria_dir(tmp_path, monkeypatch):
|
||||
d = tmp_path / "maria-bridge"
|
||||
d.mkdir()
|
||||
monkeypatch.setattr(api, "MARIA_STATE_DIR", d)
|
||||
return d
|
||||
|
||||
|
||||
def _scrie_fir(d, jid=JID, ancora="ORA-06550 la salvarea facturii", schimburi=None):
|
||||
conv = d / "conversations"
|
||||
conv.mkdir(parents=True, exist_ok=True)
|
||||
fir = {"jid": jid, "at": 1700000000.0, "ancora": ancora,
|
||||
"schimburi": schimburi if schimburi is not None else [{"rol": "om", "text": "buna"}]}
|
||||
(conv / _sanitizat(jid)).write_text(json.dumps(fir, ensure_ascii=False), encoding="utf-8")
|
||||
return fir
|
||||
|
||||
|
||||
def test_lista_fire(maria_dir):
|
||||
_scrie_fir(maria_dir)
|
||||
fire = api.maria_fire()
|
||||
assert len(fire) == 1
|
||||
assert fire[0]["jid"] == JID
|
||||
assert fire[0]["ancora"] == "ORA-06550 la salvarea facturii"
|
||||
assert fire[0]["schimburi"] == 1
|
||||
|
||||
|
||||
def test_sterge_fir(maria_dir):
|
||||
_scrie_fir(maria_dir)
|
||||
assert api.maria_delete_fir(JID) is True
|
||||
assert not (maria_dir / "conversations" / _sanitizat(JID)).exists()
|
||||
|
||||
|
||||
def test_sterge_a_doua_oara_esueaza(maria_dir):
|
||||
_scrie_fir(maria_dir)
|
||||
api.maria_delete_fir(JID)
|
||||
assert api.maria_delete_fir(JID) is False
|
||||
|
||||
|
||||
def test_fisier_corupt_e_ignorat(maria_dir):
|
||||
conv = maria_dir / "conversations"
|
||||
conv.mkdir(parents=True, exist_ok=True)
|
||||
(conv / "stricat.json").write_text("{nu e json", encoding="utf-8")
|
||||
assert api.maria_fire() == []
|
||||
|
||||
|
||||
def test_director_lipsa(maria_dir):
|
||||
assert api.maria_fire() == []
|
||||
|
||||
|
||||
def test_jid_gol_ridica_valueerror(maria_dir):
|
||||
with pytest.raises(ValueError):
|
||||
api.maria_delete_fir("")
|
||||
Reference in New Issue
Block a user