From 330adb9ba41d3b254a80b42389d63ce9d0c950c2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 27 Aug 2026 12:53:06 -0500 Subject: [PATCH] Cover the placeholder-touch failure path --- tests/unit_tests/build_helpers/test_pch.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/unit_tests/build_helpers/test_pch.py b/tests/unit_tests/build_helpers/test_pch.py index 02d0ae31cc..28347b6343 100644 --- a/tests/unit_tests/build_helpers/test_pch.py +++ b/tests/unit_tests/build_helpers/test_pch.py @@ -261,6 +261,20 @@ def test_pch_cmake_consumer_empty_when_disabled( assert pch.pch_cmake_consumer("app", "${APP_SOURCES}") == "" +def test_guarded_prepare_logs_placeholder_failure( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture +) -> None: + """A failed placeholder touch must be traceable, not silent.""" + monkeypatch.delenv("ESPHOME_PCH_STRICT", raising=False) + + def boom() -> None: + raise RuntimeError("boom") + + # Missing build dir: the touch raises and only warns + pch.guarded_prepare(tmp_path / "missing", boom) + assert "Could not create the pch placeholder" in caplog.text + + def test_pch_degraded_raises_only_in_strict( monkeypatch: pytest.MonkeyPatch, ) -> None: