Reuse datasheet family aliases and skip the LLM for catalog passives.
Store BOM MPN and orderable code on the same PDF blob, derive TI datasheet slugs from package/Q1 codes, and map LCSC/DigiKey R/C/L parameters to specs without a model call. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -92,6 +92,14 @@ def test_ti_slugs_include_family():
|
||||
assert "mspm0g3507s" not in slugs
|
||||
|
||||
|
||||
def test_ti_slugs_from_orderable_code():
|
||||
slugs = _ti_slugs("INA228AQDGSRQ1")
|
||||
assert "ina228-q1" in slugs
|
||||
assert "ina228" in slugs
|
||||
slugs = _ti_slugs("SN74AXC1T45DBVR")
|
||||
assert "sn74axc1t45" in slugs
|
||||
|
||||
|
||||
def test_find_datasheet_uses_lcsc_then_skips_empty(monkeypatch):
|
||||
async def fake_lcsc(mpn, lcsc_id=None):
|
||||
return DatasheetHit(
|
||||
|
||||
@@ -19,6 +19,18 @@ def _client(tmp_path) -> TestClient:
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
def test_library_alias_resolves_family_mpn(storage):
|
||||
from backend.services.datasheet_store import resolve_datasheet, store_datasheet_bytes
|
||||
|
||||
store_datasheet_bytes(
|
||||
storage, PDF, "ESP32-S31-WROOM-3",
|
||||
extra_mpns=["ESP32-S31-WROOM-3-N16R16V"],
|
||||
)
|
||||
assert resolve_datasheet(storage, "ESP32-S31-WROOM-3")
|
||||
assert resolve_datasheet(storage, "ESP32-S31-WROOM-3-N16R16V")
|
||||
assert proj_svc.library_has_datasheet(storage, "ESP32-S31-WROOM-3")
|
||||
|
||||
|
||||
def test_save_datasheet_also_stores_in_library(storage):
|
||||
meta = proj_svc.create_project(storage, "local", "board")
|
||||
key = proj_svc.save_datasheet(storage, "local", meta.id, "CH340E", PDF)
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
from backend.services.passive_from_distributor import specs_from_distributor
|
||||
|
||||
|
||||
def test_lcsc_description_capacitor():
|
||||
model = specs_from_distributor(
|
||||
mpn="CL21B225KPFNNNE",
|
||||
params=[{"name": "Package / Case", "value": "0805"}],
|
||||
category="Capacitors / Ceramic Capacitors",
|
||||
description="2.2uF ±10% 10V X7R 0805",
|
||||
)
|
||||
assert model is not None
|
||||
specs = model.specs
|
||||
assert specs.component_subtype == "passive.capacitor.ceramic"
|
||||
assert abs(specs.value_farads - 2.2e-6) < 1e-12
|
||||
assert specs.dielectric == "X7R"
|
||||
assert specs.package == "0805"
|
||||
|
||||
|
||||
def test_digikey_params_resistor():
|
||||
model = specs_from_distributor(
|
||||
mpn="RC0805FR-0710KL",
|
||||
params=[
|
||||
{"name": "Resistance", "value": "10 kOhms"},
|
||||
{"name": "Tolerance", "value": "±1%"},
|
||||
{"name": "Power (Watts)", "value": "0.125W"},
|
||||
{"name": "Package / Case", "value": "0805 (2012 Metric)"},
|
||||
],
|
||||
category="Resistors / Chip Resistor - Surface Mount",
|
||||
description="RES SMD 10K OHM 1% 1/8W 0805",
|
||||
)
|
||||
assert model is not None
|
||||
assert model.specs.value_ohms == 10000
|
||||
assert model.specs.package == "0805"
|
||||
|
||||
|
||||
def test_skips_when_no_value():
|
||||
assert specs_from_distributor(
|
||||
mpn="MYSTERY",
|
||||
params=[{"name": "Manufacturer", "value": "Murata"}],
|
||||
category="",
|
||||
description="some module",
|
||||
) is None
|
||||
Reference in New Issue
Block a user