Show cached passives in the library and match IC PDFs by family MPN.

Decode EIA/Yageo/AVX chip codes into library specs, and find datasheets when the file is stored under the orderable catalog name.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-28 02:27:27 +02:00
co-authored by Cursor
parent 3be7d2fc21
commit 08cbbdc422
11 changed files with 534 additions and 80 deletions
+3 -1
View File
@@ -78,7 +78,9 @@ def test_library_catalog_lists_ics_passives_and_pdfs(storage):
assert cat["ics"][0]["pin_count"] == 2
assert cat["ics"][0]["has_datasheet"] is True
assert cat["passives"][0]["mpn"] == "Samsung CL10"
assert cat["simple"][0]["mpn"] == "CL10B474KA8NNNC"
assert cat["passive_parts"][0]["mpn"] == "CL10B474KA8NNNC"
assert cat["passive_parts"][0]["param_count"] >= 1
assert cat["simple"] == []
assert any(d["mpn"] == "CH340E" and d["has_extraction"] for d in cat["datasheets"])
+65
View File
@@ -0,0 +1,65 @@
from pathlib import Path
from backend.services.datasheet_finder import find_local_pdf
from backend.services.passive_from_mpn import specs_from_mpn
def test_walsin_c0g_18pf():
model = specs_from_mpn("0805CG180J500NT")
assert model is not None
specs = model.specs
assert specs.specs_type == "capacitor"
assert abs(specs.value_farads - 18e-12) < 1e-15
assert specs.package == "0805"
assert specs.dielectric == "C0G"
assert specs.tolerance == "±5%"
assert specs.voltage_rating_v == "50V"
def test_avx_c0g_150pf():
model = specs_from_mpn("08055A151FAT2A")
assert model is not None
specs = model.specs
assert abs(specs.value_farads - 150e-12) < 1e-15
assert specs.package == "0805"
assert specs.dielectric == "C0G"
assert specs.voltage_rating_v == "50V"
def test_chip_resistor_from_mpn():
model = specs_from_mpn("FRC0805F1212TS")
assert model is not None
assert abs(model.specs.value_ohms - 12100) < 0.1
assert model.specs.package == "0805"
assert model.specs.tolerance == "±1%"
model = specs_from_mpn("0805W8F2201T5E")
assert model is not None
assert abs(model.specs.value_ohms - 2200) < 0.1
def test_skips_murata_and_bare_value():
assert specs_from_mpn("GRM21A5C2J200JA01") is None
assert specs_from_mpn("18pF") is None
assert specs_from_mpn("CH340E") is None
def test_find_local_pdf_family_vs_orderable(tmp_path: Path):
pdf = tmp_path / "ESP32-S31-WROOM-3-N16R16V.pdf"
pdf.write_bytes(b"%PDF-1.4\n" + b"x" * 100)
hit = find_local_pdf(tmp_path, "ESP32-S31-WROOM-3")
assert hit is not None
assert hit.name == pdf.name
other = tmp_path / "only"
other.mkdir()
family = other / "ESP32-S31-WROOM-3.pdf"
family.write_bytes(b"%PDF-1.4\n" + b"y" * 100)
hit = find_local_pdf(other, "ESP32-S31-WROOM-3-N16R16V")
assert hit is not None
assert hit.name == family.name
def test_find_local_pdf_does_not_steal_sibling_die(tmp_path: Path):
(tmp_path / "CH340E.pdf").write_bytes(b"%PDF-1.4\n" + b"x" * 100)
assert find_local_pdf(tmp_path, "CH340") is None