"""Launcher builds must use their own checkout, even from another Go module.""" import os import shutil import subprocess import tempfile import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[2] class GoLauncherTests(unittest.TestCase): def test_builds_from_launcher_checkout_not_caller(self): for name in ("jeannie-core", "jeannie-server"): with self.subTest(name=name), tempfile.TemporaryDirectory() as tmp: root = Path(tmp) / "checkout" (root / "scripts").mkdir(parents=True) (root / "cmd" / name).mkdir(parents=True) (root / "go.mod").write_text("module example.test/jeannie\n") shutil.copy(ROOT / "scripts" / name, root / "scripts" / name) caller = Path(tmp) / "other-module" caller.mkdir() (caller / "go.mod").write_text("module example.test/other\n") bindir = Path(tmp) / "bin" bindir.mkdir() fake_go = bindir / "go" fake_go.write_text( '#!/bin/sh\n' 'printf "%s\\n%s\\n%s\\n" "$PWD" "$GOWORK" "$4" > "$RECORD"\n' 'printf "#!/bin/sh\\nexit 0\\n" > "$3"\n' 'chmod +x "$3"\n' ) fake_go.chmod(0o755) record = Path(tmp) / "record" env = os.environ.copy() env.update(PATH=f"{bindir}:{env['PATH']}", RECORD=str(record), GOWORK="/unrelated/go.work") env.pop("JEANNIE_CORE_BIN", None) env.pop("JEANNIE_SERVER_BIN", None) subprocess.run(["bash", str(root / "scripts" / name)], cwd=caller, env=env, capture_output=True, text=True, check=True) self.assertEqual(record.read_text().splitlines(), [str(root), "off", f"./cmd/{name}"]) if __name__ == "__main__": unittest.main()