"""The compiled applications a test loads into its own `erl`, never stale. Inside the gate, `ALBEDO_TEST_DAEMON` names the daemon snapshot the gate built from this checkout, and `gleam test` may be rebuilding `build/dev` meanwhile, so tests read the snapshot. Outside it, the checkout is built first through `apps/albedo/priv/bin/albedo-build`, once per process: `build/dev` can hold beams older than the source, and a test that loads them checks old code. """ import functools import os from pathlib import Path import subprocess ROOT = Path(__file__).resolve().parents[1] BUILD = ROOT / "apps/albedo/build/dev/erlang" @functools.cache def applications() -> Path: """The directory holding one directory per compiled application.""" snapshot = os.environ.get("ALBEDO_TEST_DAEMON") if snapshot: return Path(snapshot).parent subprocess.run([str(ROOT / "apps/albedo/priv/bin/albedo-build")], check=True) return BUILD def ebins() -> list[str]: """Every application's `ebin`, for `erl -pa`.""" root = applications() found = sorted(str(path) for path in root.glob("*/ebin")) if not found: raise RuntimeError(f"no compiled applications under {root}") return found