diff --git a/scripts/jeannie-core b/scripts/jeannie-core index 3f0ae13..90dc9c6 100755 --- a/scripts/jeannie-core +++ b/scripts/jeannie-core @@ -3,6 +3,7 @@ set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" CORE_BIN="${JEANNIE_CORE_BIN:-${REPO_ROOT}/.lab/bin/jeannie-core}" +[[ "${CORE_BIN}" == /* ]] || CORE_BIN="${PWD}/${CORE_BIN}" core_sources_newer() { local source @@ -21,7 +22,10 @@ if [[ ! -x "${CORE_BIN}" || "${REPO_ROOT}/go.mod" -nt "${CORE_BIN}" ]] || core_s exit 1 fi mkdir -p "$(dirname "${CORE_BIN}")" - GOCACHE="${GOCACHE:-${REPO_ROOT}/.lab/go-build-cache}" go build -o "${CORE_BIN}" "${REPO_ROOT}/cmd/jeannie-core" + ( + cd "${REPO_ROOT}" + GOWORK=off GOCACHE="${GOCACHE:-${REPO_ROOT}/.lab/go-build-cache}" go build -o "${CORE_BIN}" ./cmd/jeannie-core + ) fi exec "${CORE_BIN}" "$@" diff --git a/scripts/jeannie-server b/scripts/jeannie-server index 537a82f..c1199e0 100755 --- a/scripts/jeannie-server +++ b/scripts/jeannie-server @@ -2,6 +2,7 @@ set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" SERVER_BIN="${JEANNIE_SERVER_BIN:-${REPO_ROOT}/.lab/bin/jeannie-server}" +[[ "${SERVER_BIN}" == /* ]] || SERVER_BIN="${PWD}/${SERVER_BIN}" server_sources_newer() { local source while IFS= read -r source; do @@ -12,6 +13,9 @@ server_sources_newer() { if [[ ! -x "${SERVER_BIN}" || "${REPO_ROOT}/go.mod" -nt "${SERVER_BIN}" ]] || server_sources_newer; then command -v go >/dev/null 2>&1 || { echo "go is required to build ${SERVER_BIN}" >&2; exit 1; } mkdir -p "$(dirname "${SERVER_BIN}")" - GOCACHE="${GOCACHE:-${REPO_ROOT}/.lab/go-build-cache}" go build -o "${SERVER_BIN}" "${REPO_ROOT}/cmd/jeannie-server" + ( + cd "${REPO_ROOT}" + GOWORK=off GOCACHE="${GOCACHE:-${REPO_ROOT}/.lab/go-build-cache}" go build -o "${SERVER_BIN}" ./cmd/jeannie-server + ) fi exec "${SERVER_BIN}" "$@" diff --git a/scripts/validate-homelab b/scripts/validate-homelab index 31c8511..a67f5a6 100755 --- a/scripts/validate-homelab +++ b/scripts/validate-homelab @@ -124,6 +124,7 @@ validate_unit_tests() { python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_ai_lab_suite.py' python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_status_focus.py' python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_status_app_snapshot.py' + python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_go_launchers.py' } main() { diff --git a/tests/jeannie/test_go_launchers.py b/tests/jeannie/test_go_launchers.py new file mode 100644 index 0000000..5d8bed0 --- /dev/null +++ b/tests/jeannie/test_go_launchers.py @@ -0,0 +1,49 @@ +"""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()