fix: OSCBR role is IDENTITY (V3 contract has no NCM/CEST): v3 endpoint, provides_ncm=false, leading-zero NCM guard, backfill refuses until NCM is proven

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
gti
2026-09-26 12:00:05 -03:00
co-authored by Claude Sonnet 5
parent c68c6c67ed
commit ab65ddd679
4 changed files with 56 additions and 4 deletions
+17 -1
View File
@@ -31,7 +31,9 @@ def _oscbr(ncm_by_gtin, calls):
if g in ncm_by_gtin:
return httpx.Response(200, json={"ean": g, "nome": "PRODUTO X", "marca": "M", "ncm": ncm_by_gtin[g], "cest": "0300700"})
return httpx.Response(404, json={})
return Oscbr(httpx.Client(transport=httpx.MockTransport(handler)), None, "u", "p")
prov = Oscbr(httpx.Client(transport=httpx.MockTransport(handler)), None, "u", "p")
prov.provides_ncm = True # simulates a plan/answer that DOES carry NCM: exercises the backfill/promotion logic (the real V3 role is IDENTITY)
return prov
def _seed(env, n=6):
@@ -108,3 +110,17 @@ def test_provider_query_canonical_forms():
assert backfill.provider_query("00000078936683") == "78936683" # GTIN-8
assert backfill.provider_query("07891000100103") == "7891000100103" # EAN-13
assert backfill.provider_query("17891000100100") == "17891000100100" # GTIN-14 with indicator
def test_oscbr_real_role_is_identity_and_uses_the_v3_endpoint():
seen = []
def handler(request):
seen.append(request.url.path)
return httpx.Response(200, json={"ean": "7891000100103", "ean_tipo": "EAN13", "nome": "COLA 350ML", "marca": "X", "categoria": "Bebidas", "link_foto": "u"})
p = Oscbr(httpx.Client(transport=httpx.MockTransport(handler)), "tok")
r = p.lookup_gtin("7891000100103")
assert seen == ["/api/v3/gtin/7891000100103"] and r.found and r.title == "COLA 350ML" and r.ncm is None and r.cest is None
assert Oscbr.provides_ncm is False
legacy = Oscbr(httpx.Client(transport=httpx.MockTransport(lambda q: httpx.Response(200, json={"nome": "FEIJAO", "ncm": 7133399}))), "tok").lookup_gtin("7896116900029")
assert legacy.ncm == "07133399" # 7-digit integer restored to the 8-digit NCM