From 12021eb26945263994dd5b9584fd873f0d201508 Mon Sep 17 00:00:00 2001 From: Claude Agent Date: Mon, 29 Jun 2026 07:29:14 +0000 Subject: [PATCH] =?UTF-8?q?feat(5.18):=20VERIFY+CLOSE=20=E2=80=94=20US-007?= =?UTF-8?q?=20badge=20sursa=20+=20fix=20findings=20code-review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VERIFY PASS pe corpus k-NN exemple etichetate (seed real 17181 Haiku, comis in 756f777): suita 1392 passed, 1 deselected (live); smoke init_db seeder (17181/NUL=2200/idempotent); toate codurile in nomenclator. US-007 (cerere user la CLOSE) — badge sursa pe sugestia fuzzy din editor: - _mapari.html: chip confirmat (GOLD) / similar (SILVER+k-NN) / non-operatie (NUL) - base.html: .sugg-sursa--{confirmat,similar,nul} pe tokeni de tema (color-mix) - routes.py: cheia `nul` adaugata in surse_sugestie default (finding cross-file) - tests/test_web_badge_sursa.py: gold/silver/nul/fara-sursa (4 teste) - E2E render live verificat in serverul real (/_fragments/mapari) CLOSE /code-review high (main..HEAD, 3 finder x 8 unghiuri) — runtime curat, invariant #13 intact; 3 findings low/cosmetic REPARATE + lock-uite: - shared_store.seed_suggestions: cod whitespace -> NULL (era ''), + test lock - genereaza_seed.py: with open(...) in loc de open().read() (FD leak tool offline) - embeddings.py: docstring-uri aliniate la [{cod, is_nul, similaritate}] ROADMAP: 5.18 LIVRAT. PRD: raport VERIFY/CLOSE scris. Co-Authored-By: Claude Opus 4.8 --- app/embeddings.py | 4 +- app/shared_store.py | 9 +- app/web/routes.py | 2 +- app/web/templates/_mapari.html | 13 +- app/web/templates/base.html | 12 ++ docs/ROADMAP.md | 3 +- .../prd-5.18-corpus-knn-exemple-etichetate.md | 67 ++++++++- tests/test_shared_store.py | 15 ++ tests/test_web_badge_sursa.py | 140 ++++++++++++++++++ tools/mapare-llm/genereaza_seed.py | 6 +- 10 files changed, 258 insertions(+), 13 deletions(-) create mode 100644 tests/test_web_badge_sursa.py diff --git a/app/embeddings.py b/app/embeddings.py index c4b3a2e..0bb8387 100644 --- a/app/embeddings.py +++ b/app/embeddings.py @@ -11,7 +11,7 @@ Design (PRD 5.14, Decision #16/#16b): API public (nivel modul): index_corpus(items) -> None - suggest_nearest(text, top_k) -> [{cod, similaritate}] + suggest_nearest(text, top_k) -> [{cod, is_nul, similaritate}] is_available() -> bool Clase (pentru teste / injectare backend): @@ -242,7 +242,7 @@ def index_corpus(items: list[dict], signature: str | None = None) -> None: def suggest_nearest(denumire: str, top_k: int = 3) -> list[dict]: - """Returneaza top_k sugestii [{cod, similaritate}] sau [] la eroare. + """Returneaza top_k sugestii [{cod, is_nul, similaritate}] sau [] la eroare. Sigur de apelat indiferent de starea backend-ului. """ diff --git a/app/shared_store.py b/app/shared_store.py index ee0a13e..1bc8169 100644 --- a/app/shared_store.py +++ b/app/shared_store.py @@ -46,9 +46,12 @@ def seed_suggestions( continue is_nul = 1 if item.get("is_nul") else 0 # NUL -> cod NULL obligatoriu (supresie stricta, #4) - cod = None if is_nul else ((item.get("cod_prestatie") or "") or None) - if cod: - cod = cod.strip().upper() + # Normalizeaza INAINTE de truthiness: un cod whitespace-only (" ") sau + # ne-string trebuie sa devina NULL, nu '' (altfel rand non-NUL cu cod gol). + cod = None + if not is_nul: + raw_cod = str(item.get("cod_prestatie") or "").strip().upper() + cod = raw_cod or None source = str(item.get("source") or "llm") confidence = float(item.get("confidence") or 0.0) cur = conn.execute( diff --git a/app/web/routes.py b/app/web/routes.py index ef74397..53dcf5c 100644 --- a/app/web/routes.py +++ b/app/web/routes.py @@ -1247,7 +1247,7 @@ def _nemapate_pentru_submission(row, nomenclator: list[dict], conn=None) -> list "denumire": item.get("denumire"), "suggestions": suggest_codes(item.get("denumire"), nomenclator, limit=5), "sugestie_principala": None, - "surse_sugestie": {"gold_partajat": None, "silver": None, "embedding": None}, + "surse_sugestie": {"gold_partajat": None, "silver": None, "embedding": None, "nul": False}, } # L14-S6: imbogatire cu GOLD partajat > SILVER > embeddings (SUGGESTION-ONLY, #13) if conn is not None: diff --git a/app/web/templates/_mapari.html b/app/web/templates/_mapari.html index b6da289..397b187 100644 --- a/app/web/templates/_mapari.html +++ b/app/web/templates/_mapari.html @@ -54,11 +54,22 @@
{{ e.denumire or '(fara denumire)' }}
+ {# 5.18 US-007: badge sursa pe sugestia sistemului — confirmat (GOLD) / similar + (SILVER+embedding k-NN) / non-operatie (pre-filtru NUL). Suggestion-only. #} + {% if e.sugestie_principala %} + {% if e.sugestie_principala.sursa == 'gold_partajat' %} + confirmat + {% else %} + similar + {% endif %} + {% elif e.surse_sugestie and e.surse_sugestie.nul %} + non-operatie + {% endif %} {% if e.suggestions %} {% for s in e.suggestions[:3] %} {{ s.cod_prestatie }} ({{ s.score|round|int }}%){% if not loop.last %}, {% endif %} {% endfor %} - {% else %}—{% endif %} + {% elif not e.sugestie_principala and not (e.surse_sugestie and e.surse_sugestie.nul) %}—{% endif %}