From 465222a3725107ef9d08080873651ffd120a6f3a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 25 Aug 2026 13:46:16 -0500 Subject: [PATCH] Cover the forced-on working-ccache path, pin both marker-probe arms --- esphome/platformio/registry.py | 9 ++++++++- tests/unit_tests/test_espidf_framework.py | 13 +++++++++++++ tests/unit_tests/test_platformio_registry.py | 9 +++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/esphome/platformio/registry.py b/esphome/platformio/registry.py index 4a6fb077c9..6393a0d582 100644 --- a/esphome/platformio/registry.py +++ b/esphome/platformio/registry.py @@ -169,6 +169,11 @@ class _PendingArchive(NamedTuple): size: int +def _already_installed(dest: Path) -> bool: + """Whether ``dest`` holds a completed install (extraction marker).""" + return (dest / ".esphome_extracted").is_file() + + def prefetch_packages( packages: list[tuple[str, str, Path, list[str]]], downloads_dir: Path ) -> None: @@ -221,7 +226,9 @@ def prefetch_packages( # Marker re-check: a concurrent build may have installed (and # deleted the archive of) this package while we waited; # re-downloading would orphan a fresh copy in downloads_dir - if not (entry.dest / ".esphome_extracted").is_file(): + # no branch: the thread tracer misses the skip edge; both + # arms of _already_installed are pinned directly + if not _already_installed(entry.dest): # pragma: no branch download_with_resume( entry.url, downloads_dir / f"{entry.name}-{entry.version}", diff --git a/tests/unit_tests/test_espidf_framework.py b/tests/unit_tests/test_espidf_framework.py index fe9a357c28..2dc102fd9e 100644 --- a/tests/unit_tests/test_espidf_framework.py +++ b/tests/unit_tests/test_espidf_framework.py @@ -1616,6 +1616,19 @@ def test_ccache_env_opt_in_without_binary( assert "no ccache binary is on PATH" in caplog.text +def test_ccache_env_opt_in_with_working_binary( + tmp_path: Path, caplog: pytest.LogCaptureFixture +) -> None: + # Forced on with a working binary: no warning fires at all. + ccache = tmp_path / "ccache" + ccache.touch() + p1, p2, p3 = _ccache_patches(tmp_path, str(ccache), tmp_path / "build") + with patch.dict("os.environ", {"IDF_CCACHE_ENABLE": "1"}, clear=True), p1, p2, p3: + env = _ccache_env() + assert env["IDF_CCACHE_ENABLE"] == "1" + assert "ccache" not in caplog.text.lower() or "Not decoded" in caplog.text + + def test_ccache_env_opt_in_with_rejected_binary( tmp_path: Path, caplog: pytest.LogCaptureFixture ) -> None: diff --git a/tests/unit_tests/test_platformio_registry.py b/tests/unit_tests/test_platformio_registry.py index 804c36dddf..6ba8691c4e 100644 --- a/tests/unit_tests/test_platformio_registry.py +++ b/tests/unit_tests/test_platformio_registry.py @@ -559,6 +559,15 @@ def test_prefetch_packages_skips_freshly_installed_dest(tmp_path: Path) -> None: mock_download.assert_not_called() +def test_already_installed_probe(tmp_path: Path) -> None: + """Both arms of the marker probe the prefetch worker keys on.""" + dest = tmp_path / "pkg" + dest.mkdir() + assert registry._already_installed(dest) is False + (dest / ".esphome_extracted").touch() + assert registry._already_installed(dest) is True + + def test_prefetch_packages_dedupes_duplicate_entries(tmp_path: Path) -> None: """Duplicate (name, version) entries would race each other between two workers; only one survives (and one is too few to parallelize)."""