From e31981c81293b3a2c8f1f3492ebf1ebd31155bc9 Mon Sep 17 00:00:00 2001 From: Michele Bigi Date: Mon, 21 Sep 2026 00:33:17 +0200 Subject: [PATCH] Persist recovered ferrite Z by comparing against the raw JSON. ComponentModel validation already fills impedance from quoted ohm@freq, so snapshotting the in-memory specs skipped the write. --- periscope/src/backend/periscopex/graph.py | 5 +++-- tests/test_inductor_specs.py | 24 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/periscope/src/backend/periscopex/graph.py b/periscope/src/backend/periscopex/graph.py index 56aeb79..c8688ec 100644 --- a/periscope/src/backend/periscopex/graph.py +++ b/periscope/src/backend/periscopex/graph.py @@ -182,8 +182,9 @@ def _load_component_models( from backend.periscopex.ferrite_z import find_mpn_pdf, recover_bead_specs pdf = find_mpn_pdf(model.mpn, *pdf_dirs) - before_z = getattr(specs, "impedance_ohm", None) - before_h = getattr(specs, "value_henries", None) + raw_specs = raw.get("specs") if isinstance(raw.get("specs"), dict) else {} + before_z = raw_specs.get("impedance_ohm") + before_h = raw_specs.get("value_henries") filled = recover_bead_specs(specs, extra_text=json.dumps(raw), pdf_path=pdf) if filled.impedance_ohm != before_z or filled.value_henries != before_h: try: diff --git a/tests/test_inductor_specs.py b/tests/test_inductor_specs.py index 3916265..175e683 100644 --- a/tests/test_inductor_specs.py +++ b/tests/test_inductor_specs.py @@ -220,6 +220,30 @@ def test_bead_mpn_datasheet_pdf_fills_z(tmp_path: Path): assert "100" in (persisted["specs"].get("value_formatted") or "") +def test_bead_live_json_persist_unstuffs_henries(tmp_path: Path): + models = tmp_path / "models" + models.mkdir() + payload = { + "mpn": "BLM21PG121SN1D", + "specs": { + "specs_type": "inductor", + "component_subtype": "passive.ferrite_bead", + "value_henries": 120.0, + "value_formatted": "120 ohm @ 100 MHz", + "package": "0805", + "current_rating_a": "3A", + "dcr_ohms": 0.03, + }, + } + (models / "BLM21PG121SN1D.json").write_text(json.dumps(payload) + "\n") + loaded = _load_component_models(models) + assert loaded["BLM21PG121SN1D"].impedance_ohm == 120.0 + assert loaded["BLM21PG121SN1D"].value_henries is None + persisted = json.loads((models / "BLM21PG121SN1D.json").read_text()) + assert persisted["specs"]["impedance_ohm"] == 120.0 + assert persisted["specs"]["value_henries"] is None + + def test_bead_mpn_datasheet_pdf_without_z_does_not_invent(tmp_path: Path): models = tmp_path / "models" models.mkdir()