Files
rar-autopass/tests/conftest.py
Claude Agent 3fc53534e2 feat(5.15+5.14): CLOSE — fix-uri code-review + embeddings functional
5.15 (propagare design + dashboard editare) si 5.14 (mapare LLM distilata)
inchise dupa /code-review high. 8 buguri reparate TDD:

- HIGH modal nu se deschidea pe randul slim (base.html: trimitere-slim)
- HIGH /repune trunchia prestatii (declaratie incompleta la RAR) -> iterare
  peste existing, codes pozitional
- HIGH embeddings incarca model ~230MB degeaba pe corpus gol -> poarta has_corpus()
- HIGH picker chips gol pe re-render eroare -> conn/account_id pe toate ramurile
- MED obs re-derivat dupa stergere explicita -> _merge_override pastreaza obs=''
- MED mapare salvata fara denumire poluă GOLD -> _record_gold_validation guard
- MED typo nome_prestatie -> nume_prestatie in select /repune
- MED bucketare timp +3h gresita iarna -> SQLite localtime + TZ=Europe/Bucharest

Embeddings WIRE-uit functional (PRD #15, decizie user): ensure_embeddings_corpus
construieste corpus din nomenclator, gated pe AUTOPASS_EMBEDDINGS_ENABLED (default
off). Marime model corectata ~50MB->~230MB (estimare PRD gresita).

Cleanup: hoist load_* din bucla bulk-fix; import re la top.
Regresie: 1256 passed, 1 deselected (live), 0 failed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 20:48:34 +00:00

64 lines
2.5 KiB
Python

"""Configurare pytest la nivel de suita: izoleaza testele de `.env`-ul de dezvoltare.
In working-dir exista un `.env` pentru probe live (ex. `AUTOPASS_REQUIRE_API_KEY=true`,
`AUTOPASS_WORKER_USE_TEST_CREDS=true`, creds RAR de test) care e citit automat de
pydantic Settings. Fara izolare, acele flag-uri ar regla tacit comportamentul
testelor: 401 pe rutele protejate si creds <test> in loc de fallback-ul pe cont.
Fixam un default sigur pe variabilele de mediu — care au PRECEDENTA peste fisierul
`.env` in pydantic-settings — deci neutralizam doar valorile din fisier, nu si o
variabila exportata explicit in shell. Testele care chiar verifica enforcement-ul
(auth pornit, creds <test>) il seteaza punctual prin `monkeypatch`/`object.__setattr__`.
"""
import hashlib
import os
import pytest
os.environ.setdefault("AUTOPASS_REQUIRE_API_KEY", "false")
os.environ.setdefault("AUTOPASS_WORKER_USE_TEST_CREDS", "false")
@pytest.fixture(autouse=True)
def _reset_embeddings_singleton():
"""Reseteaza singleton-ul global de embeddings intre teste (izolare de ordine).
`enrich_suggestions` foloseste `embeddings.has_corpus()` ca poarta; un test care
indexeaza corpusul pe singleton-ul global (ex. test_module_level_index_corpus)
altfel l-ar lasa populat -> teste ulterioare care cheama pending_unmapped ar primi
sugestii embedding spurioase. Resetam la None inainte si dupa fiecare test.
"""
try:
import app.embeddings as _emb
_emb._engine = None
except Exception:
pass
yield
try:
import app.embeddings as _emb
_emb._engine = None
except Exception:
pass
def make_test_cui(seed: str = "") -> str:
"""Factory centralizat (D#14, PRD 5.12 US-001): genereaza un CUI de test unic din seed.
Folosit de fixture-urile de test care creeaza conturi via /signup sau create_account
si au nevoie de un CUI unic per test (altfel unicitatea CUI-ului bloca al doilea signup
cu acelasi seed in acelasi DB de test).
Formatul 'ROTE' + 8 hex-uri e suficient de unic per DB de test (izolata per test).
"""
h = hashlib.md5(seed.encode()).hexdigest()[:8].upper()
return f"ROTE{h}"
def pytest_configure(config):
"""Markeri custom. `live` = teste care ating endpoint-ul real RAR (opt-in,
skip implicit; vezi tests/test_live_rar.py). Excludere: `-m 'not live'`."""
config.addinivalue_line(
"markers", "live: test live pe RAR test (necesita AUTOPASS_LIVE_RAR=1 + creds reale)"
)