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>
142 lines
5.0 KiB
Python
142 lines
5.0 KiB
Python
"""Teste US-005 (PRD 5.10): VIN pe rand separat sub numarul de inmatriculare.
|
|
|
|
VIN-ul era randat ca <span> inline in aceeasi celula cu nr. Story-ul cere un
|
|
element block-level (div/small/p cu display:block) sub nr, in stil muted.
|
|
Testul asserteaza tipul elementului (block), nu doar prezenta textului.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import re
|
|
import tempfile
|
|
|
|
import pytest
|
|
from starlette.testclient import TestClient
|
|
|
|
|
|
def _create_account_user(email: str, name: str = "Service", password: str = "parolasecreta10"):
|
|
from app.accounts import create_account
|
|
from app.users import create_user
|
|
from app.db import get_connection
|
|
|
|
conn = get_connection()
|
|
try:
|
|
acct_id = create_account(conn, name, active=True)
|
|
create_user(conn, acct_id, email, password)
|
|
return acct_id
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def _login(client, email: str, password: str = "parolasecreta10") -> None:
|
|
resp = client.get("/login")
|
|
m = re.search(r'name="csrf_token"\s+value="([^"]+)"', resp.text) or \
|
|
re.search(r'value="([^"]+)"\s+name="csrf_token"', resp.text)
|
|
assert m
|
|
resp = client.post(
|
|
"/login",
|
|
data={"email": email, "parola": password, "csrf_token": m.group(1)},
|
|
)
|
|
assert resp.status_code == 303
|
|
|
|
|
|
def _ins(acct: int, *, vin: str = "", nr: str = "B01TST", status: str = "queued") -> int:
|
|
from app.db import get_connection
|
|
conn = get_connection()
|
|
try:
|
|
cur = conn.execute(
|
|
"INSERT INTO submissions (idempotency_key, account_id, status, payload_json) VALUES (?, ?, ?, ?)",
|
|
(
|
|
f"k-{os.urandom(5).hex()}", acct, status,
|
|
json.dumps({
|
|
"vin": vin,
|
|
"nr_inmatriculare": nr,
|
|
"data_prestatie": "2026-06-20",
|
|
"odometru_final": "100",
|
|
"prestatii": [{"cod_prestatie": "R-X"}],
|
|
}),
|
|
),
|
|
)
|
|
conn.commit()
|
|
return cur.lastrowid # type: ignore[return-value]
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(monkeypatch):
|
|
tmp = tempfile.mkdtemp()
|
|
monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "layout_test.db"))
|
|
monkeypatch.setenv("AUTOPASS_WEB_AUTH_REQUIRED", "true")
|
|
from app.config import get_settings
|
|
get_settings.cache_clear()
|
|
from app.web import ratelimit
|
|
ratelimit._hits.clear()
|
|
from app.main import app
|
|
with TestClient(app, follow_redirects=False) as c:
|
|
yield c
|
|
ratelimit._hits.clear()
|
|
get_settings.cache_clear()
|
|
|
|
|
|
def test_vin_pe_rand_separat_sub_nr(client):
|
|
"""VIN-ul apare intr-un element block-level cu clasa slim-vin (PRD 5.15 US-004).
|
|
|
|
PRD 5.10 (US-005): VIN era <div class="muted"> sub nr in coloana Vehicul.
|
|
PRD 5.15 (US-004): VIN e acum identificatorul PRINCIPAL, linia 1 a randului slim,
|
|
in <div class="slim-vin"> (mono, prominent, block-level). NU mai e muted.
|
|
"""
|
|
acct = _create_account_user("vin_layout@test.com")
|
|
_ins(acct, vin="WVWZZZ1JZXW000001", nr="B123XYZ")
|
|
_login(client, "vin_layout@test.com")
|
|
|
|
resp = client.get("/_fragments/submissions")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
|
|
# VIN trunchiat trebuie sa apara in HTML
|
|
assert "000001" in html, "VIN-ul trunchiat trebuie sa apara in lista slim"
|
|
|
|
# VIN e intr-un element block-level (div cu clasa slim-vin)
|
|
# Pattern: <div class="slim-vin">...000001...</div>
|
|
vin_fragment = "000001"
|
|
found_slim_vin = re.search(
|
|
rf'<div[^>]*class="slim-vin[^"]*"[^>]*>[^<]*{re.escape(vin_fragment)}[^<]*</div>',
|
|
html,
|
|
)
|
|
assert found_slim_vin, (
|
|
f"VIN '{vin_fragment}' trebuie sa fie in <div class=\"slim-vin\"> (block-level, "
|
|
f"mono, linia 1 a randului slim). HTML gasit: "
|
|
+ html[max(0, html.find(vin_fragment) - 80):html.find(vin_fragment) + 80]
|
|
)
|
|
|
|
|
|
def test_vin_lipsa_nu_genereaza_rand_gol(client):
|
|
"""Cand VIN-ul lipseste (sau e EMPTY='—'), slim-vin nu afiseaza '—' izolat.
|
|
Fallback: slim-vin afiseaza vehicul_nr (nr. inmatriculare) cu clasa muted.
|
|
(PRD 5.15 US-004: slim-vin are garda vin != '—')
|
|
"""
|
|
acct = _create_account_user("vin_gol@test.com")
|
|
sid = _ins(acct, vin="", nr="B999TST") # VIN gol -> vin_scurt='—'
|
|
_login(client, "vin_gol@test.com")
|
|
|
|
resp = client.get("/_fragments/submissions")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
|
|
# Randul trebuie sa existe
|
|
assert f'id="trimitere-row-{sid}"' in html
|
|
|
|
# slim-vin NU trebuie sa contina '—' izolat (VIN lipsa -> fallback vehicul_nr)
|
|
slim_vin_match = re.search(r'<div[^>]*class="slim-vin[^"]*"[^>]*>([^<]*)</div>', html)
|
|
assert slim_vin_match, "slim-vin lipseste din randul cu VIN gol"
|
|
slim_vin_content = slim_vin_match.group(1).strip()
|
|
assert slim_vin_content != "—", (
|
|
"slim-vin afiseaza '—' izolat cand VIN lipseste — "
|
|
"trebuie sa afiseze vehicul_nr ca fallback"
|
|
)
|
|
# Fallback: nr inmatriculare vizibil
|
|
assert "B999TST" in html, "Nr inmatriculare (fallback) lipseste cand VIN e gol"
|