"""Leftover dispatcher/cost/DigiKey modules load from src.""" from __future__ import annotations from pathlib import Path import backend.services.cost_estimator as cost_estimator import backend.services.digikey as digikey import backend.services.event_bridge as event_bridge import backend.services.job_runner as job_runner from backend.services.digikey import _find_product from backend.services.job_runner import get_execution_state def test_dispatcher_modules_are_src(): for mod, name in ( (job_runner, "job_runner.py"), (event_bridge, "event_bridge.py"), (cost_estimator, "cost_estimator.py"), (digikey, "digikey.py"), ): path = Path(mod.__file__).resolve() assert path.name == name assert "src" in path.parts assert "Native Periscope overlay" not in path.read_text(encoding="utf-8")[:400] def test_digikey_rejects_unrelated_and_accepts_family(): products = [{"ManufacturerProductNumber": "CH340E"}] assert _find_product("CH340", products) is None products = [{"ManufacturerProductNumber": "24AA025E64-I/SN"}] assert _find_product("24AA025E64", products) is not None def test_stale_pid_is_failed(tmp_path, monkeypatch): monkeypatch.setattr(job_runner.settings, "data_dir", tmp_path) pid_path = tmp_path / "workers" / "proj.pid" pid_path.parent.mkdir(parents=True) pid_path.write_text("99999999") assert get_execution_state("local/projects/proj") == "failed"