mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 02:54:26 +00:00
assertTrue(x > 0) fails as "False is not true" and hides the value that failed; assertGreater(x, 0) reports the actual count. Same predicate, so pass and fail are unchanged on every input. CodeQL py/imprecise-assert on both generator tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
"""The .env generator must import and run without any third-party module.
|
|
|
|
The dev-environment suite runs the generator inside a bare distro image,
|
|
before any dependency is installed. This probes the whole import closure of
|
|
``cli.meta.env`` plus every handler call, with non-stdlib imports blocked.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from . import PROJECT_ROOT
|
|
|
|
PROBE = PROJECT_ROOT / "tests" / "utils" / "bare_bootstrap_probe.py"
|
|
|
|
GUIDANCE = (
|
|
"The .env generator must import and run on the bare bootstrap python, "
|
|
"so every module it reaches at import time and at call time has to be "
|
|
"stdlib-only. Read SPOT files with utils.cache.files.read_text plus "
|
|
"utils.yaml_bootstrap.load_block or a stdlib line parse, never through "
|
|
"utils.cache.yaml."
|
|
)
|
|
|
|
|
|
class TestBareBootstrap(unittest.TestCase):
|
|
def _run(self, overlay: dict[str, str]) -> str:
|
|
env = {
|
|
k: v
|
|
for k, v in os.environ.items()
|
|
if not k.startswith(("INFINITO_", "GITHUB_")) and k != "ACT"
|
|
}
|
|
env.update(overlay)
|
|
with tempfile.TemporaryDirectory() as td:
|
|
result = subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-I",
|
|
str(PROBE),
|
|
str(PROJECT_ROOT),
|
|
str(Path(td) / ".env"),
|
|
],
|
|
env=env,
|
|
cwd=str(PROJECT_ROOT),
|
|
text=True,
|
|
capture_output=True,
|
|
check=False,
|
|
)
|
|
self.assertEqual(
|
|
result.returncode,
|
|
0,
|
|
f"{GUIDANCE}\n\nstdout:\n{result.stdout}\nstderr:\n{result.stderr}",
|
|
)
|
|
return result.stdout.strip()
|
|
|
|
def test_generator_runs_without_third_party_modules(self) -> None:
|
|
self.assertGreater(int(self._run({})), 0)
|
|
|
|
def test_generator_runs_on_the_github_actions_branch(self) -> None:
|
|
overlay = {"GITHUB_ACTIONS": "true", "GITHUB_REPOSITORY_OWNER": "acme"}
|
|
self.assertGreater(int(self._run(overlay)), 0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|