diff --git a/robot-docs/testing.md b/robot-docs/testing.md index 475124b84..8004d0ff7 100644 --- a/robot-docs/testing.md +++ b/robot-docs/testing.md @@ -13,6 +13,15 @@ launches suites concurrently. Its end-to-end selection and web checks depend on the changed paths or `--full`. See [test.sh](../test.sh) for that selection and [Gleam lint](gleam-lint.md) for lint profiles. +The snapcompact tests in `gleam test` render frames through `albedo-render`. The +daemon looks for it in `priv/bin`, then on `PATH`. The gate installs it with +[native/render/install.sh](../native/render/install.sh) before its suites. When +`gleam test` runs alone and finds no renderer, its entry point, +[test/albedo_test.gleam](../test/albedo_test.gleam), runs that script first. The +script needs `cargo` from `nix develop`. Run it again after changing +`native/render`, because `gleam test` does not rebuild a renderer that is +already installed. + [test/resources.py](../test/resources.py) calculates concurrency limits from CPU and available memory. It reserves one quarter of memory and rejects a plan with less than 1 GiB available. `ALBEDO_TEST_*_JOBS` variables can override the diff --git a/test/albedo_test.gleam b/test/albedo_test.gleam index c1cbb7444..38c5e1828 100644 --- a/test/albedo_test.gleam +++ b/test/albedo_test.gleam @@ -1,8 +1,60 @@ +import albedo/harness/sdk/priv +import albedo/harness/sdk/subprocess +import gleam/dynamic +import gleam/int +import gleam/io +import gleam/option.{None} + +/// A first build compiles the renderer's whole dependency tree. +const build_timeout_ms = 900_000 + pub fn main() -> Nil { + ensure_renderer() isolate_home() run() } +/// The snapcompact tests render frames through albedo-render, which the +/// daemon finds in priv/bin or on PATH. test.sh installs it before this suite +/// runs; a bare `gleam test` builds it the same way when neither has it. This +/// runs before HOME moves, so cargo keeps the developer's registry cache. +fn ensure_renderer() -> Nil { + case + is_file(priv.path(["bin", "albedo-render"])), + subprocess.on_path("albedo-render") + { + True, _ | _, Ok(_) -> Nil + False, Error(Nil) -> { + io.println("albedo-render is missing; running native/render/install.sh") + // Cargo's progress goes to stderr, which the port leaves on the terminal. + case + subprocess.run( + "native/render/install.sh", + [], + None, + dynamic.list([]), + build_timeout_ms, + None, + ) + { + subprocess.Exited(0, _) -> Nil + subprocess.Exited(status, output) -> + panic as { + "native/render/install.sh exited with status " + <> int.to_string(status) + <> "; run it inside nix develop to build albedo-render\n" + <> output + } + subprocess.TimedOut -> + panic as "native/render/install.sh did not finish in 15 minutes" + } + } + } +} + +@external(erlang, "filelib", "is_file") +fn is_file(path: String) -> Bool + @external(erlang, "albedo_test_home", "isolate") fn isolate_home() -> Nil