fix(make): drop the previous checkout's env values and ignore a command-line ENV_SH

Two review points on #1951. When checkout A's .env was loaded and checkout B's loader runs in the same shell with the same INFINITO_INSTANCE, the instance reset never fired, the preserve loop kept A's INFINITO_CONTAINER as a caller value and B's loader then recorded B as loaded, so the stale value stuck. On a checkout change the loader now sources the previous .env in a subshell and unsets every key whose value is still that file's value; caller overrides differ from it and survive. The previous file is read only when it is a checkout's .env, with scripts/meta/env/load.sh beside it.

A command-line ENV_SH beats a := assignment in GNU make and travels to every sub-make through MAKEFLAGS, so make -C B ENV_SH=<A's loader> still ran A's loader. The Makefile now sets it with override.

Suppression: nocheck env-loader-internal-guard on the new INFINITO_ENV_LOADED_FILE read, as on the existing guard lines (operator-approved 2026-11-14). MEDUSA covers none of the 4 files; reviewed by hand.

🎯 Fix: 92 %
💥 Break: 4 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: ~100 %
🏆 Score: 88
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5.5 committed 2026-11-14 10:32:50 +00:00
1 parent 6ea3dc6f49
commit bf0e3fcd3e
4 files changed
+63 -12

No files matched your search

@@ -41,28 +41,45 @@ class TestCrossCheckout(unittest.TestCase):
subprocess.run(["touch", "-d", STAMP, str(dotenv)], check=True)
return root
def test_a_second_checkout_loads_its_own_dotenv(self) -> None:
caller = self.checkout(255, "caller_lane")
target = self.checkout(226, "target_lane")
def container_after(self, caller: Path, target: Path, **overrides: str) -> str:
script = (
f'source "{caller / LOADER}"\nsource "{target / LOADER}"\n'
'printf "%s" "${INFINITO_CONTAINER}"'
)
shown = subprocess.run(
return subprocess.run(
["bash", "-c", script],
env=clean_env(),
env=clean_env(**overrides),
capture_output=True,
text=True,
check=True,
).stdout
self.assertEqual("target_lane", shown)
def test_a_nested_make_reads_its_own_env_loader(self) -> None:
def test_a_second_checkout_loads_its_own_dotenv(self) -> None:
caller = self.checkout(255, "caller_lane")
target = self.checkout(226, "target_lane")
shown = subprocess.run(
self.assertEqual("target_lane", self.container_after(caller, target))
def test_a_second_checkout_of_the_same_instance_loads_its_own_dotenv(
self,
) -> None:
caller = self.checkout(226, "caller_lane")
target = self.checkout(226, "target_lane")
self.assertEqual("target_lane", self.container_after(caller, target))
def test_a_caller_override_survives_the_checkout_change(self) -> None:
caller = self.checkout(226, "caller_lane")
target = self.checkout(226, "target_lane")
shown = self.container_after(
caller, target, INFINITO_CONTAINER="operator_lane"
)
self.assertEqual("operator_lane", shown)
def env_sh_of_make(self, *args: str, **overrides: str) -> str:
return subprocess.run(
[
"make",
"--no-print-directory",
@@ -71,14 +88,27 @@ class TestCrossCheckout(unittest.TestCase):
"-n",
"--eval",
"cross-checkout-probe: ; @: $(info ENV_SH=$(ENV_SH))",
*args,
"cross-checkout-probe",
],
env=clean_env(ENV_SH=str(caller / LOADER)),
env=clean_env(**overrides),
capture_output=True,
text=True,
check=True,
).stdout
def test_a_nested_make_reads_its_own_env_loader(self) -> None:
caller = self.checkout(255, "caller_lane")
shown = self.env_sh_of_make(ENV_SH=str(caller / LOADER))
self.assertIn(f"ENV_SH={Path(PROJECT_ROOT) / LOADER}\n", shown)
def test_a_command_line_env_sh_cannot_select_another_loader(self) -> None:
caller = self.checkout(255, "caller_lane")
shown = self.env_sh_of_make(f"ENV_SH={caller / LOADER}")
self.assertIn(f"ENV_SH={Path(PROJECT_ROOT) / LOADER}\n", shown)