diff --git a/tests/script/test_determine_jobs.py b/tests/script/test_determine_jobs.py index bf0842ed3f..21a0f30d78 100644 --- a/tests/script/test_determine_jobs.py +++ b/tests/script/test_determine_jobs.py @@ -1003,6 +1003,7 @@ _ESP32_PLATFORMIO_FULL_LIST_FILES = [ # PlatformIO subsystem (path-prefix trigger) + build generator ["esphome/platformio/runner.py"], ["esphome/platformio/toolchain.py"], + ["esphome/build_helpers/pch.py"], ["esphome/build_gen/platformio.py"], # Workflow / harness files ["script/test_build_components.py"], diff --git a/tests/unit_tests/components/esp32/test_pch_wiring.py b/tests/unit_tests/components/esp32/test_pch_wiring.py index 14b1b38257..6d909ae621 100644 --- a/tests/unit_tests/components/esp32/test_pch_wiring.py +++ b/tests/unit_tests/components/esp32/test_pch_wiring.py @@ -1,7 +1,7 @@ """The pch script must reach PlatformIO builds only; the native ESP-IDF toolchain has its own pch flow in build_gen/espidf.py.""" -from contextlib import suppress +from pathlib import Path from unittest.mock import patch import pytest @@ -16,18 +16,28 @@ from esphome.core import CORE [(Toolchain.PLATFORMIO, True), (Toolchain.ESP_IDF, False)], ) def test_copy_files_gates_pch_script_on_toolchain( - toolchain: Toolchain, copied: bool + toolchain: Toolchain, copied: bool, tmp_path: Path ) -> None: CORE.toolchain = toolchain + CORE.build_path = tmp_path + from esphome.components.esp32 import ( + KEY_ESP32, + KEY_EXTRA_BUILD_FILES, + KEY_FLASH_SIZE, + ) + with ( - patch.object(esp32, "_write_sdkconfig"), + patch.object(esp32, "_write_sdkconfig") as write_sdkconfig, patch.object(esp32, "_write_idf_component_yml"), patch.object(esp32, "copy_pch_script") as copy_script, patch.object(esp32, "write_file_if_changed"), patch.object(esp32, "get_partition_csv"), - patch.dict(CORE.data, {}, clear=False), - # Later copy_files steps need a full build dir; the pch gate runs first - suppress(Exception), + patch.dict( + CORE.data, + {KEY_ESP32: {KEY_EXTRA_BUILD_FILES: {}, KEY_FLASH_SIZE: "4MB"}}, + ), ): esp32.copy_files() + # Proves execution reached (and passed) the gate on both rows + assert write_sdkconfig.called assert copy_script.called is copied