mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 11:07:33 +00:00
[core] Stop parent git repos from breaking ESP-IDF/PlatformIO builds (#16994)
This commit is contained in:
@@ -150,6 +150,20 @@ def test_get_idedata_regenerates_on_corrupted_cache(setup_core: Path) -> None:
|
||||
assert result == {"cxx_path": "regen"}
|
||||
|
||||
|
||||
def test_get_idf_env_sets_git_ceiling_directories(setup_core: Path) -> None:
|
||||
"""The IDF env caps git's upward search at the config directory.
|
||||
|
||||
This stops ESP-IDF's `git describe` from walking into an uninitialized or
|
||||
corrupt git repo in a parent directory and failing the build.
|
||||
"""
|
||||
toolchain._cache().env.clear()
|
||||
# Set IDF_PATH so the framework-install branch is skipped.
|
||||
with patch.dict(os.environ, {"IDF_PATH": str(setup_core)}):
|
||||
env = toolchain._get_idf_env(version="5.5.4")
|
||||
assert CORE.config_dir == setup_core
|
||||
assert str(CORE.config_dir) in env["GIT_CEILING_DIRECTORIES"].split(os.pathsep)
|
||||
|
||||
|
||||
def test_get_core_framework_version_from_core_data():
|
||||
"""The version is read from CORE.data when validation populated it."""
|
||||
from esphome.components.esp32.const import KEY_ESP32, KEY_IDF_VERSION
|
||||
|
||||
@@ -196,6 +196,33 @@ def test_is_ha_addon(monkeypatch, value, expected):
|
||||
assert actual == expected
|
||||
|
||||
|
||||
def test_add_git_ceiling_directory_sets_when_unset():
|
||||
"""An empty env gets GIT_CEILING_DIRECTORIES set to the directory."""
|
||||
env: dict[str, str] = {}
|
||||
directory = Path("/home/user/config")
|
||||
helpers.add_git_ceiling_directory(env, directory)
|
||||
assert env["GIT_CEILING_DIRECTORIES"] == str(directory)
|
||||
|
||||
|
||||
def test_add_git_ceiling_directory_appends_to_existing():
|
||||
"""An existing value is preserved and the new directory is appended."""
|
||||
env = {"GIT_CEILING_DIRECTORIES": str(Path("/some/ceiling"))}
|
||||
directory = Path("/home/user/config")
|
||||
helpers.add_git_ceiling_directory(env, directory)
|
||||
assert env["GIT_CEILING_DIRECTORIES"].split(os.pathsep) == [
|
||||
str(Path("/some/ceiling")),
|
||||
str(directory),
|
||||
]
|
||||
|
||||
|
||||
def test_add_git_ceiling_directory_skips_duplicate():
|
||||
"""A directory already in the list is not appended again."""
|
||||
directory = Path("/home/user/config")
|
||||
env = {"GIT_CEILING_DIRECTORIES": str(directory)}
|
||||
helpers.add_git_ceiling_directory(env, directory)
|
||||
assert env["GIT_CEILING_DIRECTORIES"] == str(directory)
|
||||
|
||||
|
||||
def test_walk_files(fixture_path):
|
||||
path = fixture_path / "helpers"
|
||||
|
||||
|
||||
@@ -304,6 +304,11 @@ def test_run_platformio_cli_sets_environment_variables(
|
||||
)
|
||||
assert "PLATFORMIO_LIBDEPS_DIR" in os.environ
|
||||
assert "PYTHONWARNINGS" in os.environ
|
||||
# Caps git's upward search at the config dir so an uninitialized or
|
||||
# corrupt parent git repo can't break the framework's `git describe`.
|
||||
assert str(CORE.config_dir) in os.environ["GIT_CEILING_DIRECTORIES"].split(
|
||||
os.pathsep
|
||||
)
|
||||
|
||||
# Check command was called correctly — runs PlatformIO as a subprocess
|
||||
# via the esphome.platformio.runner entry point.
|
||||
|
||||
Reference in New Issue
Block a user