From 09684ad3bbaca6b94f4e7aea892149c9258fac78 Mon Sep 17 00:00:00 2001 From: Yaraslau Tamashevich Date: Sat, 28 Nov 2026 17:17:46 +0100 Subject: [PATCH 1/8] ci: run every job on GitHub-hosted runners Remove the self-hosted runner path. The last six CI runs used no self-hosted runner: probe-self-hosted always fell back to ubuntu-24.04, so job behaviour is unchanged. - ci.yml: delete the probe-self-hosted job, give its four dependents a literal `runs-on: ubuntu-24.04`, drop PACE_ADDR, the PACE_AUTO_INSTALL flag, PACE_PREFETCH_GROUP, the pace-cc stats steps, and every condition that only distinguished self-hosted from hosted runners. - nightly-slow-checks.yml: drop PACE_PREFETCH_GROUP, which only pace-cc read. - Delete .github/self-hosted-runner/ and the scripts that tested it. - scripts/coverage.sh: reword the profraw comment to the reason that still applies to any reused workspace. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01No1NzndCGtpCccptcyk6Tb --- .github/self-hosted-runner/.gitattributes | 3 - .github/self-hosted-runner/Dockerfile | 167 ----- .github/self-hosted-runner/README.md | 655 ------------------ .../bootstrap-cloud-node.sh | 317 --------- .github/self-hosted-runner/config.example | 26 - .../self-hosted-runner/deregister-runner.sh | 79 --- .github/self-hosted-runner/entrypoint.sh | 127 ---- .../install-runner-units.sh | 193 ------ .../self-hosted-runner/job-started-hook.sh | 75 -- .../lastrada-runner@.service.in | 118 ---- .github/self-hosted-runner/run-runner.sh | 124 ---- .github/workflows/ci.yml | 389 +---------- .github/workflows/nightly-slow-checks.yml | 1 - scripts/coverage.sh | 6 +- scripts/test_run_runner.sh | 205 ------ scripts/test_runner_entrypoint.sh | 166 ----- scripts/test_runner_job_hook.sh | 194 ------ scripts/test_runner_units.sh | 472 ------------- 18 files changed, 38 insertions(+), 3279 deletions(-) delete mode 100644 .github/self-hosted-runner/.gitattributes delete mode 100644 .github/self-hosted-runner/Dockerfile delete mode 100644 .github/self-hosted-runner/README.md delete mode 100644 .github/self-hosted-runner/bootstrap-cloud-node.sh delete mode 100644 .github/self-hosted-runner/config.example delete mode 100755 .github/self-hosted-runner/deregister-runner.sh delete mode 100644 .github/self-hosted-runner/entrypoint.sh delete mode 100755 .github/self-hosted-runner/install-runner-units.sh delete mode 100755 .github/self-hosted-runner/job-started-hook.sh delete mode 100644 .github/self-hosted-runner/lastrada-runner@.service.in delete mode 100755 .github/self-hosted-runner/run-runner.sh delete mode 100644 scripts/test_run_runner.sh delete mode 100644 scripts/test_runner_entrypoint.sh delete mode 100644 scripts/test_runner_job_hook.sh delete mode 100755 scripts/test_runner_units.sh diff --git a/.github/self-hosted-runner/.gitattributes b/.github/self-hosted-runner/.gitattributes deleted file mode 100644 index 75d2efee1..000000000 --- a/.github/self-hosted-runner/.gitattributes +++ /dev/null @@ -1,3 +0,0 @@ -# entrypoint.sh runs inside a Linux container via its shebang; CRLF line -# endings (e.g. from Windows core.autocrlf=true checkouts) break that. -*.sh text eol=lf diff --git a/.github/self-hosted-runner/Dockerfile b/.github/self-hosted-runner/Dockerfile deleted file mode 100644 index 54e367d8b..000000000 --- a/.github/self-hosted-runner/Dockerfile +++ /dev/null @@ -1,167 +0,0 @@ -# Self-hosted GitHub Actions runner for LASTRADA-Software/morph. -# -# Base is plain Ubuntu 24.04, matching the ubuntu-24.04 GitHub-hosted label -# the existing ci.yml jobs use. This image intentionally does NOT prebake -# gcc/clang/sccache -- ci.yml's jobs already bootstrap their own toolchain -# via apt-get / apt.llvm.org / sccache-release downloads on every run, so -# duplicating that here would just be a second place to keep in sync. -FROM ubuntu:24.04 - -ARG RUNNER_VERSION=2.337.0 -ARG TARGETARCH=x64 -ARG CMAKE_VERSION=3.31.12 - -ENV DEBIAN_FRONTEND=noninteractive - -# GitHub-hosted ubuntu-24.04 runner images bundle ~500 packages that -# ci.yml's jobs rely on without installing themselves (perl, python3, -# binutils' nm, a base gcc/g++/make toolchain, ...). A bare ubuntu:24.04 -# Docker image has none of that, so it's listed out explicitly here -# rather than discovered one "command not found" at a time -- python3 -# (clang-tidy, coverage script), perl (deprecation-lint, -# test-type-name-lint scripts), binutils' nm (ladder-sanitizers' -# instrumentation check), build-essential for a base gcc/g++/make -# (ci.yml still installs its own pinned gcc-15/clang versions on top). -# cmake is intentionally NOT installed from apt here -- see below. -RUN apt-get update -q && apt-get install -y --no-install-recommends \ - curl \ - ca-certificates \ - git \ - jq \ - sudo \ - software-properties-common \ - gnupg2 \ - lsb-release \ - wget \ - tar \ - gzip \ - python3 \ - perl \ - binutils \ - build-essential \ - && rm -rf /var/lib/apt/lists/* - -# Anonymous HTTPS clones from this image are unreliable over HTTP/2, and -# CMakeLists.txt's FetchContent fallback for glaze does exactly one of -# those per configure: GitHub answers the info/refs GET with 200 and then -# the git-upload-pack POST on the same reused HTTP/2 connection with a -# spurious 401 (`www-authenticate: Basic realm="GitHub"`), which git turns -# into `could not read Username for 'https://github.com'` and CMake into -# "Failed to clone repository". Measured here at ~7 failures in 10 -# ls-remotes; with -c http.version=HTTP/1.1 (or protocol.version=0) it is -# 10 in 10. It is the client stack, not the network or the IP -- the same -# clone from the Docker host, same public address, is 10 in 10 -- and not -# git's version either: git 2.55 from ppa:git-core/ppa in this image fails -# at the same rate as the distro's 2.43, because both link Ubuntu 24.04's -# libcurl 8.5.0/nghttp2 1.59. There is no newer libcurl to install on -# 24.04, so the fix is to keep git off HTTP/2 entirely. Only -# authenticated requests escape the 401 (git retries with credentials), -# which is why actions/checkout has always worked here and only the -# dependency clone fails. System-wide rather than per-repo: the bug is in -# the HTTP stack, so it applies to every clone any job makes. -RUN git config --system http.version HTTP/1.1 - -# Ubuntu 24.04's apt package is CMake 3.28.3. GitHub-hosted ubuntu-24.04 -# ships a newer CMake from Kitware's own release archive rather than the -# distro package, and that gap is not cosmetic: linux-all-features' -# configure step failed here with "Impossible to link target ... -# because the link item ... has already occurred with the feature -# 'WHOLE_ARCHIVE', which is not allowed" on 3.28.3 -- a false positive in -# $ duplicate-feature detection, an area -# CMake was still actively patching in the 3.28-3.30 range. The same -# configure passes cleanly on GitHub-hosted ubuntu-24.04, confirming this -# is a CMake-version gap, not a real target-graph conflict in -# cmake/morph_add_rung.cmake. Installed directly from Kitware's binary -# release rather than a PPA/apt repo, to pin an exact known-good version. -RUN curl -fsSL -o cmake.tar.gz \ - "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz" \ - && tar -xzf cmake.tar.gz --strip-components=1 -C /usr/local \ - && rm cmake.tar.gz - -# clang (installed per-job from apt.llvm.org, not baked into this image) -# uses libstdc++'s headers by default, not its own libc++. Stock -# ubuntu:24.04's default libstdc++ is 13.x, which predates C++23 -# (needs GCC 14+) -- morph's headers use it unconditionally, so any -# clang-only job leg (no gcc install step of its own) fails to compile -# with "fatal error: 'print' file not found" unless a modern-enough -# libstdc++ already exists on the box. ci.yml's own "Install GCC 15" step -# pulls libstdc++-15-dev in as a side effect of gcc-15/g++-15 on legs that -# run it, but clang-only legs (clang-release, clang-asan, ...) never do -- -# GitHub-hosted ubuntu-24.04 apparently ships a modern-enough libstdc++ by -# default, which this doesn't unless it's here explicitly. Same PPA -# ci.yml's own gcc-15 step uses, so this tracks that step's version rather -# than diverging from it. -RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test \ - && apt-get update -q \ - && apt-get install -y --no-install-recommends libstdc++-15-dev \ - && rm -rf /var/lib/apt/lists/* - -# Packages GitHub-hosted ubuntu-24.04 ships that morph's own jobs never -# needed, but Pace's and Lightweight's do now that one fleet serves all -# three repositories. Each was found absent by auditing those two repos' -# Linux jobs against this image, not guessed: -# -# pkg-config Lightweight resolves unixodbc, libzip and yaml-cpp through -# find_package(PkgConfig). The one most likely to be a hard -# configure failure rather than a slowdown. -# python-is-python3 -# `python`, not just `python3`. jurplel/install-qt-action -# shells out to bare `python`, so morph's own "Install Qt -# 6.8.1" step dies with `python: command not found` without -# it -- observed live, failing four jobs (all optional -# features gcc+clang, Application ladder, ladder ASan+UBSan) -# the first time those legs actually landed on this fleet. -# GitHub-hosted ubuntu-24.04 provides the alias; a bare -# ubuntu:24.04 with python3 installed does not. -# zstd what actions/cache compresses with when it is present; both -# repos use actions/cache, and without it they fall back to gzip. -# unzip assumed present by several actions and archive steps. -# file/rsync shelled out to by some actions. -# locales the image otherwise has only C/C.utf8, so tests asserting -# formatted output diverge from GitHub-hosted. -# -# LANG is deliberately NOT set here: generating the locale lets a job opt in, -# while forcing it would change the behaviour of morph's existing jobs as a -# side effect of a change made for two other repositories. -RUN apt-get update -q && apt-get install -y --no-install-recommends \ - pkg-config \ - python-is-python3 \ - zstd \ - unzip \ - file \ - rsync \ - locales \ - && locale-gen en_US.UTF-8 \ - && rm -rf /var/lib/apt/lists/* - -RUN useradd -m -s /bin/bash runner \ - && usermod -aG sudo runner \ - && echo "runner ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/runner - -# GitHub-hosted ubuntu-24.04 runners ship /usr/local/bin writable by the -# runner user (ci.yml's "Install sccache" step untars straight into it, -# with no sudo). Stock ubuntu:24.04 leaves it root:root 755, which makes -# that same step fail with "Permission denied" here. -RUN chown runner:runner /usr/local/bin - -USER runner -WORKDIR /home/runner/actions-runner - -RUN curl -fsSL -o actions-runner.tar.gz \ - "https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-${TARGETARCH}-${RUNNER_VERSION}.tar.gz" \ - && tar xzf actions-runner.tar.gz \ - && rm actions-runner.tar.gz - -# Installs libicu/libssl/etc. that the runner's dotnet host needs. -RUN sudo ./bin/installdependencies.sh - -COPY --chown=runner:runner entrypoint.sh /home/runner/entrypoint.sh -COPY --chown=runner:runner job-started-hook.sh /home/runner/job-started-hook.sh -RUN sudo chmod +x /home/runner/entrypoint.sh /home/runner/job-started-hook.sh - -# The runner reads this from its own process environment and runs the hook -# before every job. See job-started-hook.sh for why it must be per-job rather -# than per-container-start. -ENV ACTIONS_RUNNER_HOOK_JOB_STARTED=/home/runner/job-started-hook.sh - -ENTRYPOINT ["/home/runner/entrypoint.sh"] diff --git a/.github/self-hosted-runner/README.md b/.github/self-hosted-runner/README.md deleted file mode 100644 index 904d23fee..000000000 --- a/.github/self-hosted-runner/README.md +++ /dev/null @@ -1,655 +0,0 @@ -# Self-hosted Linux runner (Docker) - -Runs **organisation-level** GitHub Actions runners for `LASTRADA-Software` -inside Docker containers, supervised by systemd. Used by `ci.yml`'s -`linux-compilers`, `linux-sanitizers`, `ladder-tests`, and -`ladder-sanitizers` jobs whenever a runner is online and idle (see -**ci.yml integration** below). - -## Which repositories use this - -The runners register against the **`LASTRADA-Software` organisation**, not a -single repository, and belong to the `linux-docker` runner group. The group -is scoped to `morph`, `pace` and `Lightweight` and has -`allows_public_repositories: true` — which it must, because all three are -public and the organisation's `Default` group does not allow public -repositories at all. - -Adding a fourth repository is one call against the group; no -re-registration and no restart: - -```bash -gh api -X PUT \ - "orgs/LASTRADA-Software/actions/runner-groups//repositories/" -``` - -A consuming repository needs a `RUNNER_STATUS_TOKEN` secret with -organisation self-hosted-runner read access (`admin:org`, or a fine-grained -PAT with "Self-hosted runners: Read-only"), and a `probe-self-hosted` job -like the one in this repository's `ci.yml`. Without the secret the probe -falls back to GitHub-hosted, which is also what forked-repo PRs get. - -Any number of hosts can register runners to the organisation; they are -indistinguishable to `ci.yml` — a job lands on whichever is online and -idle. Which machines are currently registered is not recorded here (it -changes): read it off the organisation's **Settings → Actions → Runners**, -or `gh api orgs/LASTRADA-Software/actions/runners`. Registrations for hosts -that no longer exist stay listed there as `offline` and are harmless — the -probe counts only online, non-busy ones — but are worth deleting so the -list reflects what actually runs. - -Multiple runners exist so a multi-leg matrix (`linux-compilers` has 4, -`linux-sanitizers` has 3) actually runs its legs in parallel instead of -queueing behind each other on one runner process — each container is a -single runner that executes exactly one job at a time. The CPU cap exists -so 4 concurrent compiles cannot each try to claim the whole machine at -once (oversubscription would make every leg slower, not just share what's -already scarce). - -The image is plain Ubuntu 24.04 with just the runner binary and enough -packages (`sudo`, `curl`, `git`, build-essential-adjacent tooling) to -bootstrap a toolchain — it does **not** prebake gcc/clang/sccache. Jobs -install those themselves the same way `ci.yml`'s GitHub-hosted jobs do, so -there is one place, not two, to keep compiler versions in sync. It does pin -a specific CMake (Kitware release, not the Ubuntu 24.04 apt package — see -the Dockerfile's own comment on a `$` false -positive that apt's 3.28.3 hits and GitHub-hosted's newer CMake doesn't) and -a modern `libstdc++-15-dev` (clang's default standard-library headers, -needed for C++23 `` regardless of which matrix leg runs first). - -## Requirements - -- Docker, on any Linux x86_64 host (a cloud VM, a spare machine, WSL2/Docker - Desktop on Windows). The container itself is Linux regardless of host OS. -- systemd, to supervise the runner containers via - `lastrada-runner@N.service` (see **Quick start** below). A host without - it (Docker Desktop, WSL2) falls back to the plain `docker run` path - documented under **Docker Desktop / WSL2 (no systemd)**. -- `gh` CLI authenticated with **`admin:org`** access on `LASTRADA-Software` - (needed because the runners are organisation-level, not repo-level — - each start mints its own one-hour registration token via - `run-runner.sh`; the credential stays on the host and never enters a - container). - -## Quick start (any host, including a fresh cloud VM) - -```bash -# 1. Get the code onto the box. Cloning the whole repo is simplest; step 2 -# needs Dockerfile, entrypoint.sh and job-started-hook.sh, and step 3 -# needs install-runner-units.sh plus config.example, -# lastrada-runner@.service.in, run-runner.sh and deregister-runner.sh -# alongside it -- all from this same directory, so a partial copy has -# to bring all eight. -git clone https://github.com/LASTRADA-Software/morph.git -cd morph/.github/self-hosted-runner - -# 2. Build the image. -docker build -t lastrada-runner:latest . - -# 3. Install the systemd units (already in this directory from step 1). No -# token needed -- each runner mints its own on every start. Needs `gh` -# authenticated with admin:org on LASTRADA-Software; that credential -# stays on this host and never enters a container. -./install-runner-units.sh - -# 4. Check it registered. -systemctl --user status 'lastrada-runner@*' -gh api orgs/LASTRADA-Software/actions/runners \ - --jq '.runners[] | {name,status,busy,labels:[.labels[].name]}' -``` - -It will show up in the organisation under **Settings → Actions → -Runners**, in the `linux-docker` group, and any workflow (in `morph`, -`pace`, or `Lightweight`) with `runs-on: [self-hosted, ...]` matching -its labels can pick up jobs on it — see the **Trust boundary** note below -before wiring one up. - -## On a fresh cloud instance (e.g. Hetzner) - -Same steps as **Quick start** above, from scratch on a bare VM, plus -installing Docker itself: - -```bash -# Docker isn't preinstalled on a plain Ubuntu/Debian Hetzner image. -curl -fsSL https://get.docker.com | sh - -git clone https://github.com/LASTRADA-Software/morph.git -cd morph/.github/self-hosted-runner -docker build -t lastrada-runner:latest . - -# gh needs to be authenticated with admin:org on LASTRADA-Software on this -# box -- run-runner.sh (invoked by systemd on every start, including every -# restart) mints its own registration token locally each time. -sudo ./install-runner-units.sh -``` - -`install-runner-units.sh` writes `/etc/lastrada-runner/config` from -`config.example` the first time it runs and never overwrites it again -(it prints `kept existing ...` on a re-run instead). `config.example`'s -defaults (`RUNNER_COUNT=5`, `RUNNER_CPUS=2`, `RUNNER_MEMORY=6g`) are sized -for the maintainer's own 12-CPU host, not necessarily this VM — edit that -file to match before or after the first install, then re-run -`install-runner-units.sh` to pick up the change (it also disables any -instance left over above the new `RUNNER_COUNT`). - -Working out that sizing by hand is what `bootstrap-cloud-node.sh` automates -instead — see **Bootstrapping a cloud node with its own pace-kv** below, -which also sets up a local `pace-kv` daemon. - -## Keep the daemon's version equal to the newest Pace release - -`CompileCache.cmake` has each container auto-install the **newest released** -`pace-cc`, and Pace's wire versions do not interoperate in either -direction. So a daemon pinned to an older release rejects the client the -containers install, and every self-hosted build compiles uncached. - -Pace was called fastcached before 0.6.0 (`fastcached` is now `pace-kv`, -`fastcache-cc` is `pace-cc`, `fastcached_*` metrics are `pace_*`); the output -quoted below was captured then and keeps the old names. - -This has already happened once here. The host daemon was pinned to 0.1.1 on -2026-09-08; fastcached released 0.2.0 on 2026-09-09; the containers began -installing the 0.2.0 client, and from then until 2026-09-15 every -self-hosted build reported - -``` --- [cache] Not using fastcache-cc at host.docker.internal:6674: rejected (unsupported-version) --- [cache] No other compiler-cache launcher found (sccache, ccache); caching disabled -``` - -and the daemon served literally nothing — `fastcached_cmd_get_total 0`, -`fastcached_cmd_set_total 0`. Nothing failed; the builds were just slower, -which is why it went unnoticed for a week. - -To check, on the host: - -```bash -curl -s http://127.0.0.1:9260/metrics | grep -E 'cmd_(get|set)_total|get_(hits|misses)_total' -``` - -Both counters sitting at zero while self-hosted jobs run means the fleet is -not using the cache at all. Compare `pace-kv --version` against the latest -release and upgrade the daemon to match. - -## Bootstrapping a cloud node with its own pace-kv - -`bootstrap-cloud-node.sh` sets up a fresh Linux VM (bare Ubuntu/Debian — -this is what a Hetzner box ships) with both a `pace-kv` daemon and N -self-hosted runner containers, all sized from the machine's actual -`nproc`/`/proc/meminfo` at run time — it does not hardcode a worker count -or per-worker CPU/RAM the way earlier revisions of this doc did. Run as -root (or with `sudo` available): - -```bash -curl -fsSLo bootstrap-cloud-node.sh \ - https://raw.githubusercontent.com/LASTRADA-Software/morph/master/.github/self-hosted-runner/bootstrap-cloud-node.sh -chmod +x bootstrap-cloud-node.sh - -./bootstrap-cloud-node.sh -``` - -No registration token to mint or pass in — `gh` just needs to be -installed and authenticated *on this box*, with `admin:org` on -`LASTRADA-Software`, before running the script (it checks `gh auth status` -up front and refuses otherwise). Unlike the token, this can't be minted -elsewhere and copied over: every runner start from here on, including -every restart, calls `gh` locally via `run-runner.sh`. - -### The sizing rule - -- `pace-kv` gets a **fixed** 2 GiB RAM / 10 GiB on-disk cap and 1 CPU, - regardless of machine size (`PACE_KV_MEMORY_GB`/`PACE_KV_DISK_GB`/ - `PACE_KV_CPUS` env vars override this) — deliberately not scaled with - the box, unlike the workers below. -- A small OS/Docker-daemon reserve is held back too: `max(1 GiB, 10% of - total RAM)`, never handed to any container (`OS_RESERVE_MEM_GB` - overrides). -- Whatever CPUs remain after pace-kv's 1-CPU reservation are divided - into workers of **2 CPUs each** (`WORKER_CPUS` overrides) — - `worker_count = floor(remaining_cpus / 2)`. Each worker's RAM is the - remaining RAM (after pace-kv + the OS reserve) split evenly across - that many workers. -- The script refuses to proceed rather than start an undersized setup: a - box with fewer than 3 CPUs total (1 for pace-kv + 2 for one worker) - or where the RAM split would leave a worker under 1 GiB exits with an - error instead of silently running something too small to compile C++ - in. Confirmed by hand: a 2-CPU/4GiB box is genuinely too small under - this scheme (1 pace-kv + one 2-CPU worker needs 3 CPUs minimum) — - provision at least 4 CPUs to get one real worker with headroom. - -### What it does, step by step - -1. Installs Docker if not already present (`get.docker.com`). -2. Clones (or reuses, `git pull --ff-only`) `morph` and `pace` - checkouts under `$HOME` (`MORPH_ROOT`/`PACE_ROOT` override). -3. Builds Pace's own image from its Dockerfile and starts it, - capped per the sizing rule above, with persistent storage under - `/var/lib/pace-kv` (`PACE_KV_STORAGE_DIR` overrides). -4. Builds this directory's runner image, tagged `lastrada-runner:latest`. -5. Writes `/etc/lastrada-runner/config` with the computed sizing - (`GITHUB_ORG=LASTRADA-Software`, `RUNNER_GROUP=linux-docker`, - `RUNNER_COUNT`, per-worker `RUNNER_CPUS`/`RUNNER_MEMORY`, - `PACE_ADDR=host.docker.internal:6674`) and runs - `install-runner-units.sh`, which installs and enables one - `lastrada-runner@N.service` per worker under systemd. Every worker's - `run-runner.sh` always passes `--add-host=host.docker.internal:host-gateway` - — what makes `host.docker.internal` resolve to the Docker host's own IP - on plain Linux Docker Engine (Docker Desktop provides this - automatically). This only matters because `ci.yml`'s own job-level - `PACE_ADDR` (see **ci.yml integration** below) always sends the - literal `host.docker.internal:6674` itself, so that is what actually has - to resolve on every runner host, cloud or otherwise. -6. Each unit's `run-runner.sh` mints its own fresh registration token from - `orgs/LASTRADA-Software/actions/runners/registration-token` on every - start — nothing is passed into the script and no token is stored in a - container. `gh` needs to stay installed and authenticated with - `admin:org` on the cloud box itself for as long as the fleet runs there, - not just for this one invocation. - -## Stopping / deregistering - -```bash -systemctl --user stop 'lastrada-runner@1' # or plain `systemctl`, system install -``` - -Deregistration happens on the **host**, not inside the container. -`run-runner.sh` starts every container with `-e RUNNER_SELF_DEREGISTER=0`, -which tells `entrypoint.sh` to skip installing its own `EXIT` trap; the -unit's `ExecStop=-/deregister-runner.sh %i` looks this runner up -by name against the organisation's runners API and `DELETE`s it instead, -using the host's own `gh` login. That split exists because the container's -only credential by stop time is the *registration* token it started with, -and GitHub expires those after about an hour — a container that has been up -longer than that would have its own `config.sh remove` fail, stranding the -registration and its live session (which GitHub then holds in a "Conflict. -Retrying until reconnected" state for a couple of minutes on the next -start). The host's `gh` credential has no such expiry, so it deregisters -instead. `run-runner.sh` also clears any stale registration for this name -before every start, as a second layer against the same failure. - -Separately — and unrelated to deregistration — systemd sends `SIGTERM` to -the `docker run -i` process that is this unit's main process; sig-proxy (on -by default without `-t`) relays it straight into the container, and the -runner process there exits, ending whatever job is currently running rather -than letting it finish. There is no drain. `TimeoutStopSec=90` is only the -ceiling before a `SIGKILL` if that hasn't happened by then; in practice a -stop or restart completes in a few seconds — verified from a real restart's -journal, `Stopping ...` to `Stopped` in about 3 seconds — so that budget is -essentially never used. The unit's `ExecStopPost` also force-removes the -container by name as a backstop, since `--rm` alone only covers a clean -exit. If the container is killed harder than a normal stop (host crash, -`docker kill`, out-of-memory), or `deregister-runner.sh` itself fails to -reach the API, the runner can be left registered but shows as offline; -remove it manually via the organisation's **Settings → Actions → Runners**, -or `gh api -X DELETE orgs/LASTRADA-Software/actions/runners/`. - -To stop the fleet for good rather than just for now, disable the unit(s) -too (`systemctl --user disable --now 'lastrada-runner@*'`), or lower -`RUNNER_COUNT` in the config and re-run `install-runner-units.sh`, which -disables whatever instances that leaves in excess. - -### Host restarts - -systemd owns the containers, and each start mints its own registration -token — so a reboot re-registers cleanly no matter how long the machine was -off. - -This was not always true, and the failure was expensive. Until 2026-09-14 -the containers ran `--restart unless-stopped` with `RUNNER_TOKEN` baked into -the container environment at `docker run` time. A GitHub registration token -expires after about an hour, so every reboot after that hour re-ran -`config.sh` against a dead token: 404, exit 1, Docker restarts it, forever. -Five containers sat in that loop from 2026-09-08 to 2026-09-14 — 5,972 -failed registrations on one of them — and nothing reported it. - -Two changes make it unreachable rather than unlikely. There is no stored -token to go stale, because `run-runner.sh` mints one per start. And a -failure is now bounded and visible: `StartLimitBurst=12` puts the unit into -`failed` after twelve attempts within a 900-second (15-minute) -`StartLimitIntervalSec` window, so `systemctl --user status -'lastrada-runner@*'` shows red instead of a loop nobody looks at. - -That 12/900 budget is wider than a first cut of 5 attempts over 10 minutes, -and deliberately so. `lastrada-runner@.service`'s `After=docker.service -network-online.target` / `Wants=network-online.target` only resolve for a -**system** install (`systemctl`, run as root) — both names are system -units, and under `systemctl --user`, the mode this README's **Quick start** -uses, neither resolves at all, so a user-mode install has *no* boot -ordering against Docker or the network. At boot this unit can start racing -a Docker daemon that is still coming up. With `RestartSec=30`, 5 attempts -gave only 150 seconds of runway before the unit went permanently `failed` — -not enough margin against a slow-booting host's Docker daemon, observed -taking close to two minutes to come up. 12 attempts at the same -`RestartSec=30` gives at least 360 seconds (6 minutes) of runway, and the -900-second window is widened in step so it can't itself lapse mid-burst. -It is still bounded, not a return to the unbounded-retry failure this -`StartLimit` exists to prevent — a genuinely dead credential still ends in -a visible `failed` state, just with a realistic amount of runway first. - -Hosts without systemd (Docker Desktop, WSL2) still use the plain `docker -run` path below. That path is reboot-fragile by design: it has the same -one-hour token, and re-running the `docker run` command with a fresh token -is the recovery. - -### Docker Desktop / WSL2 (no systemd) - -With no supervisor to mint a fresh token per start, `entrypoint.sh` falls -back to reading one from `RUNNER_TOKEN` in the container's own environment -instead of stdin: - -```bash -gh api -X POST orgs/LASTRADA-Software/actions/runners/registration-token --jq '.token' - -docker run -d \ - --name lastrada-docker-1 \ - --restart unless-stopped \ - -e RUNNER_TOKEN="" \ - lastrada-runner:latest -``` - -This is the path described just above: the token is only good for about an -hour, so a Docker Desktop restart or a host reboot more than an hour after -this `docker run` leaves `config.sh` registering against a dead token. -Recovery is re-running the command above with a fresh token — there is -nothing else to fix, since `entrypoint.sh` already removes stale -`.runner`/`.credentials` files unconditionally before calling `config.sh`; -that part of the container's local state was never the problem. - -## Environment variables (`entrypoint.sh`) - -| Variable | Required | Default | Notes | -|-----------------|----------|-----------------------------------------|-------| -| `RUNNER_TOKEN` | no | — | Fallback registration token for the plain `docker run` path only, ~1 hour TTL. Under systemd the token arrives on **stdin** from `run-runner.sh` instead, so it never sits in the container environment where a job could read it out of `/proc/1/environ`. | -| `RUNNER_SCOPE_URL` | no | `https://github.com/LASTRADA-Software` | What `config.sh --url` registers against. | -| `RUNNER_GROUP` | no | `linux-docker` | Runner group to join. Must allow public repositories. | -| `RUNNER_NAME` | no | `lastrada-docker-` | Under systemd, `run-runner.sh` always sets this explicitly to `-` from the config instead of relying on the default; only the plain `docker run` path needs to set it by hand for multiple runners to stay distinguishable in the organisation's runner list. | -| `RUNNER_LABELS` | no | `self-hosted,Linux,X64,lastrada-docker` | Only change this if you also update the `runs-on:` label list in the workflow(s) that should target it. | -| `RUNNER_SELF_DEREGISTER` | no | `1` (enabled) | Set to `0` to skip `entrypoint.sh`'s own `EXIT`-trap deregistration. `run-runner.sh` always passes `0` under systemd, because the host-side `ExecStop=deregister-runner.sh` (see **Stopping / deregistering**) does it instead, with a credential that doesn't expire the way the container's registration token does. Only the plain `docker run` path (no systemd) needs the trap, and leaves this unset so it defaults to enabled. | - -## Trust boundary - -A self-hosted runner executes arbitrary job code on whatever host runs the -container — a cloud VM here, or your own machine. `linux-compilers`, -`linux-sanitizers`, `ladder-tests`, and `ladder-sanitizers` inherit `ci.yml`'s top-level `on: pull_request:` -trigger with no fork restriction of their own, but -they cannot actually run on this runner from a forked PR: `probe-self-hosted` -picks the runner by reading the `RUNNER_STATUS_TOKEN` repo secret (see -**ci.yml integration** below), and a `pull_request` (not -`pull_request_target`) event triggered from a fork never receives repo -secrets at all — a GitHub platform guarantee, not something this -workflow implements itself. `RUNNER_STATUS_TOKEN` therefore comes through -empty for any forked PR, which the probe's own script already treats as -"no runner available" and falls back to `ubuntu-24.04` — the fork's build -still runs, just never on self-hosted hardware. No separate fork check is -needed as long as every self-hosted job keeps going through -`probe-self-hosted` rather than hardcoding `runs-on: [self-hosted, ...]` -directly. - -## Running more than one runner - -Each container is one runner process, and capacity is controlled by -`RUNNER_COUNT` in the systemd config (`config.example`, installed to -`~/.config/lastrada-runner/config` for a user install or -`/etc/lastrada-runner/config` for a system one) rather than a manual loop -of `docker run` commands. `install-runner-units.sh` enables one -`lastrada-runner@N.service` per index from `1` to `RUNNER_COUNT`, and each -unit's `run-runner.sh ` mints its own token and starts its own -container — no coordination between them is needed, they all just poll -the same organisation's job queue. To add or remove capacity, edit -`RUNNER_COUNT` in the config and re-run `install-runner-units.sh`: it -enables the new instances and disables whatever is left over above the -new count. - -Per-worker sizing is `RUNNER_CPUS`/`RUNNER_MEMORY` in that same config, -which `run-runner.sh` passes straight through as `--cpus=`/`--memory=` on -`docker run` — a CFS quota, **not** a pinned `--cpuset-cpus`. That -distinction used to be load-bearing here and still is: `--cpus=N` throttles -a container without changing what it *sees*, so `nproc` inside a 2-CPU -container on a 12-processor host still answers **12**, and anything that -fans out on `nproc` directly — ninja run without a cap, `ctest -j`, -`clang-tidy-diff`'s own `-j "$(nproc)"` — oversubscribes the box regardless -of the quota. Measured here once, before this fleet's config-driven sizing -existed: **32 OOM kills** across five containers on one run, `g++: fatal -error: Killed signal terminated program cc1plus` in every one. -`CMAKE_BUILD_PARALLEL_LEVEL` (also set per worker in `config`, and matched -to `RUNNER_CPUS` by convention — `config.example`'s own comment says so, -nothing enforces it automatically) is what actually bounds the one build -step every self-hosted job runs, `cmake --build --preset`, since that tool -reads the variable instead of `nproc`. The Linux jobs that would otherwise -exercise an uncapped `ctest -j`/`clang-tidy-diff` (`valgrind`, `clang-tidy`) -are kept off this fleet entirely — see **ci.yml integration** above — so -raising `RUNNER_COUNT` or lowering `RUNNER_CPUS` without also updating -`CMAKE_BUILD_PARALLEL_LEVEL` is a real, if currently unexercised, way to -reintroduce this. - -`run-runner.sh` always passes `--add-host=host.docker.internal:host-gateway` -regardless of host type — Docker Desktop provides that name automatically, -a bare Linux Engine does not, and `ci.yml` sends the literal -`host.docker.internal:6674` to every self-hosted job. Without it the -address does not resolve and every job silently compiles uncached. - -## ci.yml integration - -None of `linux-compilers`, `linux-sanitizers`, `ladder-tests`, or -`ladder-sanitizers` hardcode `runs-on:`. A -`probe-self-hosted` job that runs first checks the runners API for an -online, non-busy runner labeled `lastrada-docker` and outputs the label -set each of them should use — self-hosted if one is free, otherwise the -plain `ubuntu-24.04` GitHub-hosted label. Nothing needs to be started or -stopped by hand for this fallback to work; it's just naturally in effect -whenever no `lastrada-docker` runner happens to be online or all of them -are busy on another job. `linux-coverage`, `linux-qt`, -`valgrind`, and `clang-tidy` are intentionally left on `ubuntu-24.04` for -now, with no `probe-self-hosted` dependency at all. - -The one piece that doesn't come for free: `GITHUB_TOKEN` cannot call the -runners API, and — because the fleet is organisation-level, not -repo-level — the *repo* runners endpoint wouldn't answer for it even if -it could: `GET /repos/.../actions/runners` returns zero for these -runners, silently, with no error to notice. The probe therefore calls -`GET https://api.github.com/orgs/LASTRADA-Software/actions/runners` -instead, authenticated with a repo secret named `RUNNER_STATUS_TOKEN`, -which must carry **organisation-level self-hosted-runner read access** — -either `admin:org` on a classic PAT, or a fine-grained PAT with -"Self-hosted runners: Read-only" granted **on the `LASTRADA-Software` -organisation**, not scoped to this repo alone (a repo-scoped grant, even -with "Administration: Read-only", cannot see an org-level runner and the -call comes back empty exactly like a missing secret). It cannot register, -delete, or otherwise manage runners, and has no code access. Set it up -once at **Settings → Secrets and variables → Actions → New repository -secret**. Until that secret exists, the probe always falls back to -`ubuntu-24.04` — nothing breaks, the jobs above just never pick up the -self-hosted path. - -Forked-repo pull requests never receive repo secrets at all (GitHub -withholds them for security), so `RUNNER_STATUS_TOKEN` reads as empty -there and the probe falls back the same way — no separate handling -needed for that case. - -## Dependency clones and HTTP/2 - -`CMakeLists.txt` fetches glaze through CPM when no installed copy is -found, so a Linux configure whose CPM source cache (`.cache/cpm`, restored -by `actions/cache`) misses does one anonymous -`git clone https://github.com/stephenberry/glaze.git` — an unauthenticated -clone. Inside this image that clone fails -most of the time: GitHub answers the `info/refs` GET with 200 and then -the `git-upload-pack` POST on the same reused HTTP/2 connection with a -spurious `401` and `www-authenticate: Basic realm="GitHub"`, which -surfaces as - -``` -fatal: could not read Username for 'https://github.com': No such device or address -fatal: expected flush after ref listing -Had to git clone more than once: 3 times. -CMake Error ... Failed to clone repository: 'https://github.com/stephenberry/glaze.git' -``` - -and fails Configure. It looks like a credentials or rate-limit problem and -is neither: it is Ubuntu 24.04's libcurl 8.5.0 / nghttp2 1.59 speaking -HTTP/2. Measured from a running runner container, ~7 of 10 `ls-remote`s -fail; with `-c http.version=HTTP/1.1` or `-c protocol.version=0`, 10 of -10 succeed. The same clone from the Docker host (same public address, -libcurl 8.21) is 10 of 10, and upgrading git inside the container to 2.55 -from `ppa:git-core/ppa` changes nothing — the libcurl underneath is the -same, and 24.04 has no newer one to install. Only *authenticated* -requests escape the 401, because git retries them with credentials, which -is why `actions/checkout` has always worked here and only the dependency -clone breaks. - -The Dockerfile therefore pins `git config --system http.version HTTP/1.1`. -Containers built from an older image keep failing until they are -recreated; to fix a running one in place, without disturbing the job it -may be executing: - -```bash -docker exec -u root lastrada-docker-1 git config --system http.version HTTP/1.1 -``` - -## Compiler cache: pace-cc - -`linux-compilers`, `linux-sanitizers`, `ladder-tests`, and -`ladder-sanitizers` each set `PACE_ADDR=host.docker.internal:6674` -as job-level env — but **only** when `probe-self-hosted` chose the -self-hosted path; it is left empty on the GitHub-hosted fallback, where -`host.docker.internal` does not resolve (it isn't a Docker container) and -morph's `cmake/CompileCache.cmake` has no daemon to reach anyway. - -`PACE_AUTO_INSTALL` is a plain CMake `option()`, not something -`CompileCache.cmake` reads from the environment the way it does -`PACE_ADDR` — a job-level env var of that name would be silently -ignored, reaching only `option()`'s CMake-cache default rather than -CompileCache.cmake's auto-install logic. So `ci.yml` never sets it as env -at all. Instead each of those five jobs precomputes a same-named job-level -env var, `MORPH_PACE_AUTO_INSTALL_FLAG`, whose value on the -self-hosted path is the literal string `-DPACE_AUTO_INSTALL=ON` (and -empty on the GitHub-hosted fallback), and every Configure step splices -`$MORPH_PACE_AUTO_INSTALL_FLAG` directly onto the `cmake --preset` -command line, so the flag reaches CMake the only way it can take effect. - -`host.docker.internal:6674` is the same literal address on every host -- -`ci.yml` hardcodes it, it does not vary by which runner picks up the job -- -which means **every host running these runners needs its own `pace-kv` -daemon reachable at that address from inside its containers**. There is -no single shared cache across hosts; each host caches its own compiles. -How `host.docker.internal` resolves differs by platform: - -- **Docker Desktop (Windows/macOS hosts)**: resolves automatically to - whatever the host's `127.0.0.1` means — i.e. that machine's own - `pace-kv` service (kept outside this repository). That service must be **running** and its - `pace-kv.yaml` must **bind `0.0.0.0`**, not the default `127.0.0.1`, - or a container cannot reach it at all (`127.0.0.1` inside a container - means the container itself). -- **Plain Linux Docker Engine (a workstation or a cloud VM)**: does - **not** provide `host.docker.internal` automatically the way Docker - Desktop does. `bootstrap-cloud-node.sh` adds it explicitly via - `--add-host=host.docker.internal:host-gateway` on each worker - container — confirmed live (`REACHABLE` from inside a worker to - `pace-kv` on the same box). A worker started without that flag on a - Linux host would fail to resolve the address and fall through to - `sccache` instead (never a hard failure, just a slower cache). -- **A Linux workstation that already runs `pace-kv` for its own - builds**: the daemon there is typically bound to `127.0.0.1` and built - from source, and neither is usable by a container as-is. See the two - subsections below. - -### A workstation that already runs its own pace-kv - -A developer machine's `pace-kv` listens on loopback, which inside a -container means the container itself. Two ways to give the runners a cache -on such a host; the second is what these runners are set up for: - -1. **Add a listener on the Docker bridge gateway** to the existing daemon — - `listeners:` in `pace-kv.yaml` supersedes `bind`/`port`, so both - endpoints must be spelled out: - - ```yaml - listeners: - - address: 127.0.0.1 - port: 6674 - - address: 172.17.0.1 # what host-gateway resolves to - port: 6674 - ``` - - One cache serving both the developer's builds and the runners. Requires - the version match described below, which a from-source daemon does not - have. - -2. **Run a second daemon, as a host process**, bound to the bridge address - only and left on a released version, with the personal one untouched on - loopback — e.g. as a `systemd --user` unit (`pace-kv-ci.service`) - running the 0.1.1 release binary: - - ```yaml - # ~/.local/opt/pace-0.6.0/pace-kv-ci.yaml - listeners: - - address: 172.17.0.1 # the bridge gateway, not the LAN - port: 6674 - storage_path: /home//.local/state/pace-kv-ci/cache - storage_max_disk: 30g - storage_max_value: 256m - max_memory: 8g - metrics: true # loopback-only, on a port the personal - metrics_bind: 127.0.0.1 # daemon does not use, so cache behaviour - metrics_port: 9260 # on the runners can actually be measured - ``` - - A daemon rather than a container, deliberately: the runners reach it at - `host.docker.internal:6674` either way, and a host process is one less - moving part than a container publishing a port back to its own host. Give - it **its own `storage_path`** — started without `--config` it would read - the personal `pace-kv.yaml` and two daemons would write one cache file. - - The Ubuntu release binary links `libyaml-cpp 0.8`; a distribution that - ships 0.9 (Arch, for one) can vendor just that library beside the binary - and point `LD_LIBRARY_PATH` at it from the unit, rather than installing - anything system-wide or building from source. - - Two caches on one host, which costs nothing that matters: the runners - compile in their own checkouts and share almost no entries with the - developer's tree anyway. The two daemons do not collide — one binds - `127.0.0.1:6674`, the other `172.17.0.1:6674`. - -### The daemon and the launcher have to be version-compatible - -`PACE_AUTO_INSTALL=ON` fetches the newest **released** `pace-cc` -from the Pace project's GitHub Releases. A daemon built from that -project's `master` can be far ahead of its last release and **refuses that -client**, which is why the daemon serving the runners has to be a release -build, not whatever from-source one is already on the box. - -Measured here: `fastcached 0.1.1-599-gea414a2` (a from-source master build) -against the auto-installed `fastcache-cc` 0.1.1, configuring from inside a -runner container — - -``` --- [cache] Auto-installed fastcache-cc (/home/runner/.cache/fastcache-cc/0.1.1/Linux-x86_64/fastcache-cc) --- [cache] Not using fastcache-cc at host.docker.internal:6674: rejected (unsupported-version --- [cache] No other compiler-cache launcher found (sccache, ccache); caching disabled -``` - -The same container against a `fastcached` 0.1.1 release build selects it, -and a second build from a wiped build directory hits the cache -(`fastcached_get_hits_total` 0 → 3). Note the last line of the failing run: -on the self-hosted path `ci.yml` deliberately does not install `sccache`, -so a rejected `pace-cc` is not a slower cache, it is **no cache at -all** — and it says so in the configure log rather than failing, which is -what makes it easy to miss. - -This applies to `bootstrap-cloud-node.sh` too, which builds `pace-kv` -from a `master` checkout. - -If a host has no `pace-kv` reachable at all (or `PACE_ADDR` is -left unset there), the module falls back to `sccache` (already installed -by every job) with zero other changes needed; see -`cmake/CompileCache.cmake`'s own header comment for the full -pace-cc → sccache → ccache → none preference order. - -`PACE_AUTO_INSTALL=ON` is what lets this work without prebaking -`pace-cc` into the runner image: on first configure, CMake downloads -a prebuilt `pace-cc` binary from the Pace project's own -GitHub Releases (cached per-user, per-version, so this costs one download -per container, not per build) — see -`cmake/CompileCache.cmake`'s "Optional auto-install" section for exactly -how, including its own SHA256 verification and total inability to fail a -configure (a fetch that fails just falls through to sccache). diff --git a/.github/self-hosted-runner/bootstrap-cloud-node.sh b/.github/self-hosted-runner/bootstrap-cloud-node.sh deleted file mode 100644 index 73a65d796..000000000 --- a/.github/self-hosted-runner/bootstrap-cloud-node.sh +++ /dev/null @@ -1,317 +0,0 @@ -#!/usr/bin/env bash -# Bootstraps a fresh Linux cloud VM (e.g. a Hetzner box) to run BOTH a -# pace-kv compile-cache daemon and N self-hosted GitHub Actions runner -# containers for LASTRADA-Software/morph, sized dynamically from whatever -# CPU/RAM the machine actually has -- nothing here is a hardcoded "2 workers, -# 2 CPUs, 4 GB" assumption. Run as root (or with sudo) on a bare Ubuntu/Debian -# VM; safe to re-run (idempotent: reuses Docker if already installed, rebuilds -# images, replaces the existing pace-kv container by name, reinstalls the -# systemd units that own the runner containers' lifecycle, and then restarts -# those units one at a time so a rebuilt runner image is actually picked up -- -# never touching an already-written /etc/lastrada-runner/config, so an -# operator's hand-tuned settings, e.g. a lowered RUNNER_COUNT, survive a -# re-run instead of being reverted to this run's detected sizing). -# -# Usage: -# ./bootstrap-cloud-node.sh -# -# No registration token is needed up front: each runner mints its own, fresh, -# on every start (see run-runner.sh). This box needs `gh` authenticated with -# admin:org on LASTRADA-Software instead -- a credential that stays on the -# host and never enters a container. The preflight below proves that with a -# real, read-only org-scoped API call (not just `gh auth status`, which only -# proves *some* credential is stored, not that it has admin:org against this -# org) -- and it runs that call through $SUDO, because the systemd units -# install-runner-units.sh installs run as whatever identity $SUDO resolves to -# (root, under sudo), so root's own `gh` credential is the one that actually -# has to be authenticated, not the invoking user's. -# -# Optional env vars (override the dynamic sizing below): -# RUNNER_NAME_PREFIX - defaults to "morph-cloud-$(hostname)" -# PACE_KV_MEMORY_GB - defaults to 2 (fixed, not scaled with machine size) -# PACE_KV_DISK_GB - defaults to 10 -# PACE_KV_CPUS - defaults to 1 -# PACE_KV_STORAGE_DIR - defaults to /var/lib/pace-kv (persistent cache -# storage, survives container recreation) -# WORKER_CPUS - defaults to 2 (each worker gets this many) -# OS_RESERVE_MEM_GB - defaults to max(1, 10% of total RAM), left -# unallocated to any container for the OS/Docker -# daemon/sshd/etc. -# -# pace-kv's --storage-max-value is fixed at 256m (matches the maintainer's -# already-tuned Windows daemon config -- debug objects have been observed up -# to ~122 MB) rather than left at whatever the daemon's own compiled-in -# default is. -set -euo pipefail - -if [ "$(id -u)" -ne 0 ] && ! command -v sudo >/dev/null 2>&1; then - echo "ERROR: run as root, or install sudo first." >&2 - exit 1 -fi -SUDO="" -[ "$(id -u)" -ne 0 ] && SUDO="sudo" - -# `command` is a shell builtin, not an executable, so `sudo command -v gh` -# can never work -- sudo execs a program named "command", which doesn't -# exist, and always fails regardless of whether gh is actually installed. -# Run the lookup inside a shell instead (through $SUDO, or directly when -# $SUDO is empty/root) so the builtin resolves in the identity that will -# actually run the systemd units. -if ! $SUDO sh -c 'command -v gh' >/dev/null 2>&1; then - echo "ERROR: the gh CLI is required -- each runner mints its own" >&2 - echo " registration token on every start." >&2 - exit 1 -fi - -# `gh auth status` is not enough here: it only proves some credential is -# stored, not that it has admin:org against LASTRADA-Software, nor that it -# belongs to the identity the systemd units actually run as. Query an -# endpoint that requires org-level self-hosted-runner read (admin:org) and -# mints/changes nothing, through $SUDO so it exercises the exact credential -# store install-runner-units.sh's units will use. -if ! $SUDO gh api orgs/LASTRADA-Software/actions/runners --jq '.total_count' >/dev/null 2>&1; then - echo "ERROR: could not list LASTRADA-Software's self-hosted runners via gh." >&2 - echo " The credential the runner units will use must be authenticated" >&2 - echo " with admin:org on LASTRADA-Software." >&2 - if [ -n "$SUDO" ]; then - echo " This ran as root (via sudo), because that's the identity the" >&2 - echo " systemd units install as -- so it's root's own gh credential" >&2 - echo " that needs 'gh auth login', not the invoking user's." >&2 - fi - exit 1 -fi - -RUNNER_NAME_PREFIX="${RUNNER_NAME_PREFIX:-morph-cloud-$(hostname)}" -PACE_KV_MEMORY_GB="${PACE_KV_MEMORY_GB:-2}" -PACE_KV_DISK_GB="${PACE_KV_DISK_GB:-10}" -PACE_KV_CPUS="${PACE_KV_CPUS:-1}" -WORKER_CPUS="${WORKER_CPUS:-2}" - -# ── 1. Detect this machine's actual resources ────────────────────────────── -# Never hardcode a worker count/size here -- the whole point of this script -# is that it reads the box it's actually running on, so the same script -# works on a 2-CPU/4GB dev box and a 16-CPU/64GB one without editing anything. -TOTAL_CPUS="$(nproc)" -TOTAL_MEM_KB="$(awk '/MemTotal/ {print $2}' /proc/meminfo)" -TOTAL_MEM_GB=$(( TOTAL_MEM_KB / 1024 / 1024 )) - -OS_RESERVE_MEM_GB="${OS_RESERVE_MEM_GB:-$(( TOTAL_MEM_GB / 10 > 1 ? TOTAL_MEM_GB / 10 : 1 ))}" - -echo "Detected: ${TOTAL_CPUS} CPUs, ${TOTAL_MEM_GB} GiB RAM." -echo "Reserving: pace-kv=${PACE_KV_CPUS} CPU/${PACE_KV_MEMORY_GB}GiB, OS/Docker=${OS_RESERVE_MEM_GB}GiB." - -# ── 2. Work out how many workers fit in what's left ──────────────────────── -REMAINING_CPUS=$(( TOTAL_CPUS - PACE_KV_CPUS )) -REMAINING_MEM_GB=$(( TOTAL_MEM_GB - PACE_KV_MEMORY_GB - OS_RESERVE_MEM_GB )) - -if [ "$REMAINING_CPUS" -lt "$WORKER_CPUS" ]; then - echo "ERROR: only ${REMAINING_CPUS} CPU(s) left after pace-kv's reservation," >&2 - echo " but each worker needs ${WORKER_CPUS}. Lower WORKER_CPUS or" >&2 - echo " PACE_KV_CPUS, or use a bigger machine." >&2 - exit 1 -fi - -WORKER_COUNT=$(( REMAINING_CPUS / WORKER_CPUS )) - -if [ "$WORKER_COUNT" -lt 1 ]; then - echo "ERROR: computed 0 workers (remaining CPUs=${REMAINING_CPUS}, per-worker=${WORKER_CPUS})." >&2 - exit 1 -fi - -WORKER_MEM_GB=$(( REMAINING_MEM_GB / WORKER_COUNT )) - -if [ "$WORKER_MEM_GB" -lt 1 ]; then - echo "ERROR: ${WORKER_COUNT} workers would get ${WORKER_MEM_GB} GiB RAM each --" >&2 - echo " too little for a real C++ compile. Reduce WORKER_COUNT (lower" >&2 - echo " total CPUs / raise WORKER_CPUS) or use a bigger machine." >&2 - exit 1 -fi - -echo "Plan: ${WORKER_COUNT} worker(s) x ${WORKER_CPUS} CPU / ${WORKER_MEM_GB} GiB RAM each." -echo " (uses $(( PACE_KV_CPUS + WORKER_COUNT * WORKER_CPUS ))/${TOTAL_CPUS} CPUs," \ - "$(( PACE_KV_MEMORY_GB + WORKER_COUNT * WORKER_MEM_GB + OS_RESERVE_MEM_GB ))/${TOTAL_MEM_GB} GiB RAM)" - -# ── 3. Docker ──────────────────────────────────────────────────────────── -if ! command -v docker >/dev/null 2>&1; then - echo "Installing Docker..." - curl -fsSL https://get.docker.com | $SUDO sh -fi - -# ── 4. Get the source ──────────────────────────────────────────────────── -# Always a fixed, well-known path rather than "detect whether this script -# happens to be sitting inside a checkout already" -- this script is meant -# to be fetched standalone (curl, see the README's own quick-start), where -# there is no surrounding checkout to detect, and a relative-path heuristic -# would be one more thing to get subtly wrong depending on where it's run -# from. MORPH_ROOT/PACE_ROOT still override for anyone who already -# has a checkout somewhere specific. -MORPH_ROOT="${MORPH_ROOT:-$HOME/morph}" -if [ ! -d "$MORPH_ROOT/.git" ]; then - git clone https://github.com/LASTRADA-Software/morph.git "$MORPH_ROOT" -else - git -C "$MORPH_ROOT" pull --ff-only -fi - -PACE_ROOT="${PACE_ROOT:-$HOME/pace}" -if [ ! -d "$PACE_ROOT/.git" ]; then - git clone https://github.com/LASTRADA-Software/pace.git "$PACE_ROOT" -else - git -C "$PACE_ROOT" pull --ff-only -fi - -# ── 5. Build and start pace-kv ─────────────────────────────────────── -# Built from source (the Dockerfile in Pace's own repo) rather than -# downloading the prebuilt release binary used for pace-cc: the daemon -# needs to keep running as a long-lived container, which is what its own -# Dockerfile is already set up for, including the runtime-stage slimming. -echo "" -echo "=== Building pace-kv ===" -$SUDO docker build -t pace-kv:latest "$PACE_ROOT" - -$SUDO docker rm -f pace-kv 2>/dev/null || true -PACE_KV_STORAGE_DIR="${PACE_KV_STORAGE_DIR:-/var/lib/pace-kv}" -$SUDO mkdir -p "$PACE_KV_STORAGE_DIR" - -# --metrics: the image's own HEALTHCHECK is `pace-kv --healthcheck`, -# which needs the running daemon to answer on its metrics endpoint -- -# omitting this here means `docker ps` reports the container "(unhealthy)" -# forever even though the daemon itself is fine (confirmed live: dropping -# --metrics while overriding every other default CMD arg left the daemon -# genuinely serving requests but Docker's own health probe failing with -# exit 1 on every check). --metrics-bind=0.0.0.0 so the healthcheck can -# reach it the same way the daemon's cache port is reachable. -$SUDO docker run -d \ - --name pace-kv \ - --restart unless-stopped \ - --cpus="${PACE_KV_CPUS}" \ - --memory="${PACE_KV_MEMORY_GB}g" \ - -p 6674:6674 \ - -v "${PACE_KV_STORAGE_DIR}:/data" \ - pace-kv:latest \ - --bind=0.0.0.0 \ - --metrics \ - --metrics-bind=0.0.0.0 \ - --max-memory="${PACE_KV_MEMORY_GB}g" \ - --storage=/data \ - --storage-max-disk="${PACE_KV_DISK_GB}g" \ - --storage-max-value=256m - -echo "pace-kv started: ${PACE_KV_CPUS} CPU, ${PACE_KV_MEMORY_GB}GiB RAM, ${PACE_KV_DISK_GB}GiB disk cap, storage at ${PACE_KV_STORAGE_DIR}" - -# ── 6. Build the runner image ─────────────────────────────────────────── -echo "" -echo "=== Building the lastrada self-hosted runner image ===" -$SUDO docker build -t lastrada-runner:latest "$MORPH_ROOT/.github/self-hosted-runner" - -# ── 7. Configure and start the workers ────────────────────────────────── -# systemd supervises the containers, not Docker: one owner, a fresh -# registration token per start, and a bounded start limit so a broken -# credential shows up as a failed unit instead of retrying forever. The -# per-worker token minting that used to live here is gone -- run-runner.sh -# mints one per start, which covers the single-use property by construction. -echo "" -echo "=== Installing systemd units for ${WORKER_COUNT} worker(s) ===" - -$SUDO mkdir -p /etc/lastrada-runner - -# Never clobber a config an operator has tuned -- same rule and message style -# as install-runner-units.sh's own config.example handling. Without this, a -# re-run (the documented way to pick up an image fix, see section 8 below) -# would silently revert e.g. a hand-lowered RUNNER_COUNT back to whatever this -# run's hardware detection computes. -if [ ! -e /etc/lastrada-runner/config ]; then - $SUDO tee /etc/lastrada-runner/config >/dev/null </dev/null || true)" - if [ "$status" = "online" ]; then - echo " ${runner_name} is online (after ${waited}s)" - return 0 - fi - sleep 2 - waited=$(( waited + 2 )) - done - echo " WARNING: ${runner_name} did not report online within ${RUNNER_ONLINE_TIMEOUT}s;" >&2 - echo " continuing with the rest of the fleet -- check its status manually:" >&2 - echo " gh api orgs/${ACTUAL_GITHUB_ORG}/actions/runners --jq '.runners[] | {name,status,busy}'" >&2 - return 0 -} - -for i in $(seq 1 "$ACTUAL_RUNNER_COUNT"); do - runner_name="${ACTUAL_RUNNER_NAME_PREFIX}-${i}" - echo "restarting lastrada-runner@${i} (${runner_name})" - $SUDO systemctl restart "lastrada-runner@${i}.service" - wait_for_runner_online "$runner_name" -done - -echo "" -echo "=== Done ===" -echo "pace-kv: docker logs pace-kv" -echo "workers: systemctl status 'lastrada-runner@*'" -echo "worker logs: journalctl -u 'lastrada-runner@1' -f" -echo "verify runners: gh api orgs/LASTRADA-Software/actions/runners --jq '.runners[] | {name,status,busy}'" diff --git a/.github/self-hosted-runner/config.example b/.github/self-hosted-runner/config.example deleted file mode 100644 index d5a02fca4..000000000 --- a/.github/self-hosted-runner/config.example +++ /dev/null @@ -1,26 +0,0 @@ -# Copied to ~/.config/lastrada-runner/config (user install) or -# /etc/lastrada-runner/config (system install) by install-runner-units.sh. - -# Registration is organisation-level so one fleet serves morph, Pace -# and Lightweight. -GITHUB_ORG=LASTRADA-Software - -# The runner group must allow public repositories -- all three consuming -# repositories are public, and the organisation's Default group does not. -RUNNER_GROUP=linux-docker - -RUNNER_COUNT=5 -RUNNER_NAME_PREFIX=lastrada-docker -RUNNER_LABELS=self-hosted,Linux,X64,lastrada-docker - -# Five runners x 2 CPUs uses 10 of this host's 12, leaving two for the OS and -# the natively-running pace-kv daemon. Matches CMAKE_BUILD_PARALLEL_LEVEL. -RUNNER_CPUS=2 -RUNNER_MEMORY=6g - -RUNNER_IMAGE=lastrada-runner:latest - -# pace-kv runs on the host (bound to the Docker bridge), not in a -# container; host.docker.internal is how a container reaches it. -PACE_ADDR=host.docker.internal:6674 -CMAKE_BUILD_PARALLEL_LEVEL=2 diff --git a/.github/self-hosted-runner/deregister-runner.sh b/.github/self-hosted-runner/deregister-runner.sh deleted file mode 100755 index 30c6656ee..000000000 --- a/.github/self-hosted-runner/deregister-runner.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env bash -# Deregisters one runner from the GitHub organisation. Called from the host -# by systemd's ExecStop=-@LIBEXEC@/deregister-runner.sh %i (see -# lastrada-runner@.service.in). -# -# Usage: deregister-runner.sh -# -# Why the host does this and not the container: entrypoint.sh's own EXIT trap -# deregisters with `config.sh remove --token`, but the only token it has is -# the REGISTRATION token it started with, and GitHub expires those after -# ~1 hour. Stopping a container that has been up longer than that makes the -# trap's removal fail, stranding both the registration and its live session -# -- the replacement then sits in "A session for this runner already exists -# ... Conflict. Retrying until reconnected" for a couple of minutes. The -# host's `gh` credential has no such expiry, so this script -- not the -# container -- owns deregistration under systemd; run-runner.sh passes the -# container `-e RUNNER_SELF_DEREGISTER=0` so it stands down and the two -# never race each other or double-remove. -# -# Must never fail the stop: a missing runner, a `gh` API error, or an absent -# `gh` binary are all reported and this still exits 0. Systemd runs ExecStop -# on every ordinary restart, not just a shutdown; a script that could fail -# here would turn routine restarts into red units. The leading `-` on the -# ExecStop= line is a second, belt-and-braces guard for the same thing. -# -# LASTRADA_RUNNER_DRY_RUN=1 prints what would be deleted instead of deleting, -# so scripts/test_runner_units.sh can assert the id-resolution logic without -# calling the GitHub API. -set -euo pipefail - -if [ "$#" -lt 1 ]; then - echo "usage: deregister-runner.sh " >&2 - exit 1 -fi -readonly index="$1" - -config="${LASTRADA_RUNNER_CONFIG:-${XDG_CONFIG_HOME:-$HOME/.config}/lastrada-runner/config}" -if [ ! -r "$config" ]; then - echo "deregister-runner.sh: no readable config at ${config}; nothing to deregister" >&2 - exit 0 -fi -# shellcheck disable=SC1090 -. "$config" - -if [ -z "${GITHUB_ORG:-}" ] || [ -z "${RUNNER_NAME_PREFIX:-}" ]; then - echo "deregister-runner.sh: config missing GITHUB_ORG or RUNNER_NAME_PREFIX; nothing to deregister" >&2 - exit 0 -fi - -readonly name="${RUNNER_NAME_PREFIX}-${index}" -readonly gh="${LASTRADA_RUNNER_GH:-gh}" - -if ! command -v "$gh" >/dev/null 2>&1; then - echo "deregister-runner.sh: '${gh}' not found on PATH; cannot deregister ${name}" >&2 - exit 0 -fi - -runner_id="$("$gh" api "orgs/${GITHUB_ORG}/actions/runners" \ - --jq ".runners[] | select(.name == \"${name}\") | .id" 2>/dev/null)" || { - echo "deregister-runner.sh: failed to query runners for ${name}; leaving it as-is" >&2 - exit 0 -} - -if [ -z "$runner_id" ]; then - echo "deregister-runner.sh: no registration found for ${name}; nothing to remove" - exit 0 -fi - -if [ -n "${LASTRADA_RUNNER_DRY_RUN:-}" ]; then - echo "deregister-runner.sh: would delete ${name} (id ${runner_id})" - exit 0 -fi - -if "$gh" api -X DELETE "orgs/${GITHUB_ORG}/actions/runners/${runner_id}" >/dev/null 2>&1; then - echo "deregister-runner.sh: removed ${name} (id ${runner_id})" -else - echo "deregister-runner.sh: failed to remove ${name} (id ${runner_id}); it may reappear as stale" >&2 -fi -exit 0 diff --git a/.github/self-hosted-runner/entrypoint.sh b/.github/self-hosted-runner/entrypoint.sh deleted file mode 100644 index 7620b513d..000000000 --- a/.github/self-hosted-runner/entrypoint.sh +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/env bash -# Registers this container as an organisation-level self-hosted runner for -# LASTRADA-Software, then blocks running jobs until stopped. -# -# The registration token arrives on **stdin** from run-runner.sh, which mints -# a fresh one per start. It is deliberately not an environment variable: -# every job on this container can read `env` and /proc/1/environ, these are -# public repositories running contributor-authored build code, and a live -# registration token would let such code enrol its own machine into the -# runner group. RUNNER_TOKEN is still honoured as a fallback for the plain -# `docker run` path documented in README.md for Docker Desktop hosts, which -# have no systemd to run the wrapper. -# -# Environment: -# RUNNER_TOKEN - fallback registration token when stdin carries none -# RUNNER_SCOPE_URL - defaults to the LASTRADA-Software organisation -# RUNNER_GROUP - runner group to join; defaults to linux-docker -# RUNNER_NAME - defaults to "lastrada-docker-$HOSTNAME" -# RUNNER_LABELS - defaults to "self-hosted,Linux,X64,lastrada-docker" -# RUNNER_SELF_DEREGISTER - set to "0" to skip this container's own EXIT-time -# deregistration; defaults to enabled (see below) -set -euo pipefail - -# Reads the first line of stdin when there is one, else falls back to the -# environment. Kept as a function so scripts/test_runner_entrypoint.sh can -# assert the precedence without running a registration. -read_runner_token() { - local from_stdin="" - if [ ! -t 0 ]; then - IFS= read -r from_stdin || true - fi - if [ -n "$from_stdin" ]; then - printf '%s' "$from_stdin" - else - printf '%s' "${RUNNER_TOKEN:-}" - fi -} - -# Removes this runner's registration; the body of the EXIT trap below. -cleanup() { - echo "Removing runner registration..." - ./config.sh remove --token "${runner_token}" || true -} - -# Installs the cleanup trap unless the host is already doing this job. -# -# Under systemd, run-runner.sh sets RUNNER_SELF_DEREGISTER=0 and -# lastrada-runner@.service.in's ExecStop runs deregister-runner.sh on the -# HOST instead: this container's only credential is the REGISTRATION token -# it started with, and GitHub expires those after ~1 hour, so by the time a -# long-lived container is stopped this trap's own `config.sh remove` would -# fail here and strand the registration -- exactly what host-side ExecStop -# exists to avoid. Standalone (`docker run`, no systemd -- the path -# documented in README.md for Docker Desktop/WSL2), there is no host -# supervisor to do it, so this trap must remain the only mechanism; -# RUNNER_SELF_DEREGISTER unset here defaults to enabled, leaving that path -# unchanged. -# -# Kept as a function, like read_runner_token, so -# scripts/test_runner_entrypoint.sh can assert -- behaviourally, by actually -# letting the trap fire -- whether cleanup runs, not just grep the source for -# a string. -install_deregister_trap() { - if [ "${RUNNER_SELF_DEREGISTER:-1}" = "0" ]; then - return 0 - fi - trap cleanup EXIT -} - -# Sourced by the self-test: define the functions above, do nothing else. -if [ -n "${LASTRADA_RUNNER_ENTRYPOINT_SOURCE_ONLY:-}" ]; then - return 0 2>/dev/null || exit 0 -fi - -RUNNER_SCOPE_URL="${RUNNER_SCOPE_URL:-https://github.com/LASTRADA-Software}" -RUNNER_GROUP="${RUNNER_GROUP:-linux-docker}" -RUNNER_NAME="${RUNNER_NAME:-lastrada-docker-${HOSTNAME}}" -RUNNER_LABELS="${RUNNER_LABELS:-self-hosted,Linux,X64,lastrada-docker}" - -cd /home/runner/actions-runner - -runner_token="$(read_runner_token)" -if [ -z "$runner_token" ]; then - echo "ERROR: no registration token on stdin and RUNNER_TOKEN is unset." >&2 - exit 1 -fi - -install_deregister_trap - -# A restart re-runs this entrypoint. Under systemd the container is always -# fresh (--rm), so there is nothing left on disk -- but the plain `docker run` -# path reuses one container across restarts, where .runner/.credentials from -# the previous registration survive and make `--replace` refuse with "Cannot -# configure the runner because it is already configured". Removing them is a -# local operation; it does not call the GitHub API. -rm -f .runner .credentials .credentials_rsaparams - -./config.sh \ - --url "${RUNNER_SCOPE_URL}" \ - --token "${runner_token}" \ - --name "${RUNNER_NAME}" \ - --labels "${RUNNER_LABELS}" \ - --runnergroup "${RUNNER_GROUP}" \ - --work "_work" \ - --unattended \ - --replace - -# Under systemd the host owns deregistration (run-runner.sh sets -# RUNNER_SELF_DEREGISTER=0, ExecStop runs deregister-runner.sh) and no EXIT -# trap is installed here -- so replace this shell with run.sh rather than -# running it as a child. -# -# That matters because Docker signals only PID 1. As a child, run.sh never -# sees SIGTERM: bash takes it instead and dies, tearing the container down -# and killing the runner abruptly under whatever job it was running. As -# PID 1 it receives the signal itself, and run.sh already traps it -# (`trap 'kill -INT -$PID' INT TERM`) to forward an interrupt to the runner -# process group -- the shutdown path the runner is designed for. -# TimeoutStopSec in the unit still bounds how long that may take. -# -# Standalone (`docker run`, no systemd) the EXIT trap IS the deregistration -# mechanism and `exec` would discard it, so that path keeps run.sh as a child. -if [ "${RUNNER_SELF_DEREGISTER:-1}" = "0" ]; then - exec ./run.sh -fi - -./run.sh diff --git a/.github/self-hosted-runner/install-runner-units.sh b/.github/self-hosted-runner/install-runner-units.sh deleted file mode 100755 index 6ea43be2a..000000000 --- a/.github/self-hosted-runner/install-runner-units.sh +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/env bash -# Installs the systemd units that supervise the self-hosted runner fleet. -# -# Two modes, chosen by who runs it (or by LASTRADA_RUNNER_FORCE_SYSTEM, below): -# -# as a normal user -> user units under ~/.config/systemd/user, controlled -# with `systemctl --user`. Needs lingering -# (`loginctl enable-linger $USER`) to start at boot -# without a login session -- this script checks that -# and enables it itself if it's off. This is the mode -# used on the maintainer's workstation, where `gh` is -# already authenticated for that user. -# as root -> system units under /etc/systemd/system. This is what -# bootstrap-cloud-node.sh uses on a fresh VM. -# -# LASTRADA_RUNNER_PREFIX_DIR redirects every install path under one directory, -# and LASTRADA_RUNNER_NO_SYSTEMCTL=1 skips the systemctl calls (and, see -# below, the lingering check too), so scripts/test_runner_units.sh can render -# and inspect the unit without touching the real system. -# -# LASTRADA_RUNNER_FORCE_SYSTEM=1 selects the root/system path regardless of -# the running user's actual uid, so scripts/test_runner_units.sh can render -# and assert the system-unit variant -- the one bootstrap-cloud-node.sh -# depends on -- without actually running as root. -set -euo pipefail - -readonly here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - -if [ "$(id -u)" -eq 0 ] || [ -n "${LASTRADA_RUNNER_FORCE_SYSTEM:-}" ]; then - unit_dir="/etc/systemd/system" - config_dir="/etc/lastrada-runner" - libexec_dir="/usr/local/libexec/lastrada-runner" - wantedby="multi-user.target" - systemctl=(systemctl) -else - unit_dir="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user" - config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/lastrada-runner" - libexec_dir="${XDG_DATA_HOME:-$HOME/.local/share}/lastrada-runner" - wantedby="default.target" - systemctl=(systemctl --user) - - # User units only start at boot without a login session if lingering is - # enabled for this user; otherwise the whole fleet simply never comes - # back after a reboot, silently. Irrelevant to the root/system path - # above, where units are system-wide and lingering doesn't apply. Uses - # `loginctl` rather than touching systemd state directly so this honours - # a stubbed `loginctl` on PATH the same way the systemctl calls below - # honour a stubbed `systemctl` -- see scripts/test_runner_units.sh. - # - # Skipped entirely under LASTRADA_RUNNER_NO_SYSTEMCTL: that flag's whole - # contract is "render files, don't touch the real system", and - # `loginctl` mutates real login-manager state just as much as `systemctl` - # does. Checked *before* anything below tries to call `loginctl`, not - # after -- this used to run unconditionally, ahead of the - # LASTRADA_RUNNER_NO_SYSTEMCTL check further down, so isolation-mode - # callers (including this script's own self-test) were mutating real - # lingering state despite the flag, and an environment with no usable - # login session (an ordinary GitHub Actions runner, for instance) could - # fail `loginctl` outright and abort the install before any file was - # rendered. - # - # Non-fatal even when it does run: a missing or failing `loginctl` must - # not abort an otherwise-successful install, it should just warn loudly - # that the fleet won't survive a reboot and say exactly what to run. - if [ -n "${LASTRADA_RUNNER_NO_SYSTEMCTL:-}" ]; then - echo "LASTRADA_RUNNER_NO_SYSTEMCTL set; skipping the lingering check (this mode must not touch loginctl either)" - elif ! command -v loginctl >/dev/null 2>&1; then - echo "warning: loginctl not found on PATH; cannot check or enable lingering for ${USER} -- this fleet will NOT survive a reboot until you run: loginctl enable-linger ${USER}" >&2 - else - linger_state="$(loginctl show-user "$USER" --property=Linger 2>/dev/null || true)" - if [ "$linger_state" != "Linger=yes" ]; then - echo "lingering is off for ${USER}; enabling it (loginctl enable-linger ${USER}) so this fleet survives a reboot without a login session" - if ! loginctl enable-linger "$USER" 2>/dev/null; then - echo "warning: 'loginctl enable-linger ${USER}' failed -- this fleet will NOT survive a reboot until you run: loginctl enable-linger ${USER}" >&2 - fi - else - echo "lingering already enabled for ${USER}" - fi - fi -fi - -if [ -n "${LASTRADA_RUNNER_PREFIX_DIR:-}" ]; then - unit_dir="${LASTRADA_RUNNER_PREFIX_DIR}${unit_dir}" - config_dir="${LASTRADA_RUNNER_PREFIX_DIR}${config_dir}" - libexec_dir="${LASTRADA_RUNNER_PREFIX_DIR}${libexec_dir}" -fi - -mkdir -p "$unit_dir" "$config_dir" "$libexec_dir" - -install -m 0755 "${here}/run-runner.sh" "${libexec_dir}/run-runner.sh" -install -m 0755 "${here}/deregister-runner.sh" "${libexec_dir}/deregister-runner.sh" - -# Never clobber a config an operator has tuned; config.example is the -# reference, the installed file is theirs. -if [ ! -e "${config_dir}/config" ]; then - install -m 0600 "${here}/config.example" "${config_dir}/config" - echo "wrote ${config_dir}/config" -else - echo "kept existing ${config_dir}/config" -fi - -# shellcheck disable=SC1091 -. "${config_dir}/config" -: "${RUNNER_COUNT:?config must set RUNNER_COUNT}" -: "${RUNNER_NAME_PREFIX:?config must set RUNNER_NAME_PREFIX}" - -# A non-numeric RUNNER_COUNT is not caught by the check above (":?" only -# rejects empty/unset), and feeding it to `seq` below is not caught by `set -# -e` either: a failed command substitution inside a `for ... in $(...)` -# word-list does not trip -e, so the enable loop below would silently run -# zero times while the script still reaches its success banner and exits 0 -- -# a fleet of zero runners, reported as a successful install. Fail loudly here -# instead. -case "$RUNNER_COUNT" in - ''|*[!0-9]*) - echo "install-runner-units.sh: RUNNER_COUNT must be a positive integer, got '${RUNNER_COUNT}'" >&2 - exit 1 - ;; -esac -if [ "$RUNNER_COUNT" -eq 0 ]; then - echo "install-runner-units.sh: RUNNER_COUNT must be a positive integer, got '${RUNNER_COUNT}'" >&2 - exit 1 -fi - -docker_bin="$(command -v docker || true)" -if [ -z "$docker_bin" ]; then - echo "install-runner-units.sh: docker not found on PATH; cannot resolve @DOCKER@ for ExecStopPost" >&2 - exit 1 -fi - -sed \ - -e "s|@LIBEXEC@|${libexec_dir}|g" \ - -e "s|@CONFIG@|${config_dir}/config|g" \ - -e "s|@PREFIX@|${RUNNER_NAME_PREFIX}|g" \ - -e "s|@WANTEDBY@|${wantedby}|g" \ - -e "s|@DOCKER@|${docker_bin}|g" \ - "${here}/lastrada-runner@.service.in" >"${unit_dir}/lastrada-runner@.service" -echo "wrote ${unit_dir}/lastrada-runner@.service" - -if [ -n "${LASTRADA_RUNNER_NO_SYSTEMCTL:-}" ]; then - echo "LASTRADA_RUNNER_NO_SYSTEMCTL set; not touching systemd" - exit 0 -fi - -"${systemctl[@]}" daemon-reload - -# Disable instances left over from a previously larger fleet, so shrinking -# RUNNER_COUNT actually shrinks it. -# -# `systemctl list-unit-files 'lastrada-runner@*.service'` does NOT work for -# this: for a template unit, list-unit-files only ever shows the template -# itself (`lastrada-runner@.service`), never the instances enabled from it. -# Verified live against this exact fleet: -# -# $ systemctl --user list-unit-files 'lastrada-runner@*.service' --no-legend --plain -# lastrada-runner@.service indirect enabled -# -# ...while `~/.config/systemd/user/default.target.wants/` actually holds the -# five enablement symlinks lastrada-runner@1.service .. @5.service. The same -# is true of any templated unit (e.g. getty@.service vs. getty@tty1.service). -# `systemctl list-units --all` is not a substitute either -- it only shows -# *loaded* units, not everything enabled. So enumerate the enablement -# symlinks directly. -for existing_path in "${unit_dir}/${wantedby}.wants/lastrada-runner@"*.service; do - [ -e "$existing_path" ] || continue - existing="$(basename "$existing_path")" - idx="${existing#lastrada-runner@}" - idx="${idx%.service}" - # The redirect below used to be the only guard against a non-numeric idx - # ([ -gt ] on a non-integer would abort the script under `set -e`), but - # this loop is inside `if`, which is already `set -e`-exempt -- so it did - # not do what it appeared to. Skip non-numeric idx values explicitly - # instead of relying on that. - case "$idx" in - ''|*[!0-9]*) - echo "skipping ${existing}: index '${idx}' is not numeric" >&2 - continue - ;; - esac - if [ "$idx" -gt "$RUNNER_COUNT" ]; then - echo "disabling ${existing} (beyond RUNNER_COUNT=${RUNNER_COUNT})" - "${systemctl[@]}" disable --now "$existing" || true - fi -done - -for i in $(seq 1 "$RUNNER_COUNT"); do - "${systemctl[@]}" enable --now "lastrada-runner@${i}.service" - echo "enabled lastrada-runner@${i}" -done - -echo -echo "status: ${systemctl[*]} status 'lastrada-runner@*'" -echo "logs: journalctl${systemctl[1]:+ --user} -u 'lastrada-runner@1' -f" diff --git a/.github/self-hosted-runner/job-started-hook.sh b/.github/self-hosted-runner/job-started-hook.sh deleted file mode 100755 index 6ffcf6d52..000000000 --- a/.github/self-hosted-runner/job-started-hook.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env bash -# ACTIONS_RUNNER_HOOK_JOB_STARTED -- runs before every job on this container. -# -# Removes sccache and ccache from the PATH directories a job can install into. -# CompileCache.cmake's PACE_AUTO_INSTALL path fires only when none of -# pace-cc/sccache/ccache is already on PATH, so a compile-cache binary -# left behind by a previous job silently costs the next one its connection to -# the host pace-kv daemon -- the build still succeeds, just uncached. -# -# This has to run between jobs, not at container start: one fleet now serves -# morph, Pace and Lightweight, and the contamination happens when a -# Lightweight job (hendrikmuhs/ccache-action apt-installs ccache) is followed -# by a morph job on the same container. -# -# pace-cc is deliberately NOT removed. When it is present, auto-install -# is unnecessary and CompileCache.cmake simply uses it, which is the outcome -# we want; removing it would force a re-download on every job. -# -# A target can be package-managed (ccache-action apt-installs ccache) or not -# (sccache is an unpackaged tarball). `rm -f`-ing a package-managed binary -# leaves dpkg still recording the package as installed, so the *next* job's -# `apt-get install ccache` reports "already the newest version" and installs -# nothing -- the binary never comes back, breaking every later ccache job on -# that container. So ownership is checked at runtime with `dpkg -S`: an owned -# target is removed with `apt-get remove`, so dpkg's state stays consistent -# and a later install genuinely reinstalls it; an unowned target is `rm -f`'d -# as before. LASTRADA_RUNNER_DPKG / LASTRADA_RUNNER_APT let tests substitute -# stub binaries, the same way run-runner.sh's LASTRADA_RUNNER_GH/DOCKER do. -# -# Never fails the job: a hook that exits non-zero aborts the run it was meant -# to help. Missing directory, missing tool, unremovable file, and a missing -# or failing dpkg/apt-get all fall through to "leave it, continue". -set -euo pipefail - -dirs="${LASTRADA_RUNNER_HOOK_DIRS:-/usr/local/bin /usr/bin /home/runner/.cargo/bin}" -dpkg_bin="${LASTRADA_RUNNER_DPKG:-dpkg}" -apt_bin="${LASTRADA_RUNNER_APT:-apt-get}" - -# Prints the name of the package owning $1 on stdout and returns 0, or prints -# nothing and returns 0 if the target is unowned, dpkg has no opinion, or -# dpkg itself is missing/erroring -- any of which sends the caller to rm. -owning_package() { - local target="$1" line - line="$("$dpkg_bin" -S "$target" 2>/dev/null)" || return 0 - printf '%s\n' "${line%%:*}" -} - -remove_via_apt() { - local pkg="$1" - "$apt_bin" remove -y -qq "$pkg" >/dev/null 2>&1 || - sudo "$apt_bin" remove -y -qq "$pkg" >/dev/null 2>&1 -} - -for dir in $dirs; do - [ -d "$dir" ] || continue - for tool in sccache ccache; do - target="${dir}/${tool}" - [ -e "$target" ] || continue - - pkg="$(owning_package "$target")" - if [ -n "$pkg" ]; then - if remove_via_apt "$pkg"; then - echo "job-started-hook: removed package ${pkg} owning ${target}" - else - echo "job-started-hook: could not remove package ${pkg} owning ${target}, continuing" >&2 - fi - elif rm -f "$target" 2>/dev/null || sudo rm -f "$target" 2>/dev/null; then - echo "job-started-hook: removed ${target}" - else - echo "job-started-hook: could not remove ${target}, continuing" >&2 - fi - done -done - -exit 0 diff --git a/.github/self-hosted-runner/lastrada-runner@.service.in b/.github/self-hosted-runner/lastrada-runner@.service.in deleted file mode 100644 index 4d1f3a4bb..000000000 --- a/.github/self-hosted-runner/lastrada-runner@.service.in +++ /dev/null @@ -1,118 +0,0 @@ -# Template unit: one instance per runner, lastrada-runner@1 .. lastrada-runner@N. -# Rendered by install-runner-units.sh, which substitutes the @...@ paths for -# either a user install (systemctl --user) or a system one. -[Unit] -Description=LASTRADA self-hosted GitHub Actions runner %i -Documentation=https://github.com/LASTRADA-Software/morph/blob/master/.github/self-hosted-runner/README.md -# These two only resolve for the system install (systemctl, run as root): -# docker.service and network-online.target are system units. Under -# `systemctl --user` -- the mode install-runner-units.sh uses for a normal -# user, and what the README's Quick start walks through -- neither name -# resolves at all ("could not be found"), so for a user install these lines -# are inert: zero boot ordering against Docker or the network. Resilience for -# that mode comes instead from the widened StartLimit*/RestartSec budget -# below, not from ordering directives that don't apply to it. -After=docker.service network-online.target -Wants=network-online.target - -# StartLimit* belong in [Unit] -- systemd moved them here in v229 and ignores -# them in [Service]. That is not cosmetic: without a working start limit this -# unit retries forever exactly like the `--restart unless-stopped` policy it -# replaces, and a broken credential produces thousands of silent retries -# instead of a failed unit somebody can see. -# -# Sized for user-mode boot, which (see After=/Wants= above) has no ordering -# against docker.service or the network: at boot this unit can start racing -# a Docker daemon that is still coming up. The old 5-attempts/600s pairing -# with RestartSec=30 below gave only 5*30s = 150s (2.5 min) of runway before -# going permanently `failed` -- barely covering, with no margin, the ~2 -# minutes a slow-booting host's Docker daemon has been observed to take -# (journal-verified: containers self-update within ~1 minute of finally -# starting). Burst=12 at the same RestartSec=30 gives >=12*30s = 360s (6 min) -# of runway -- 3x the observed 2-minute case -- before the unit gives up and -# shows red, which is still bounded, not the unbounded retries this StartLimit -# exists to prevent. IntervalSec is widened in step with it (900s, i.e. 15 -# min) so the rolling window comfortably outlasts that 6-minute worst case -# and can't itself lapse mid-burst and mask a genuinely broken unit forever. -StartLimitIntervalSec=900 -StartLimitBurst=12 - -[Service] -Type=exec -Environment=LASTRADA_RUNNER_CONFIG=@CONFIG@ -ExecStart=@LIBEXEC@/run-runner.sh %i - -# Deregisters this runner from the organisation from the HOST, not the -# container. By stop time the container's only credential -- the -# REGISTRATION token entrypoint.sh started with -- can easily be over an -# hour old and GitHub will have expired it, so its own EXIT trap's removal -# would fail and strand both the registration and its live session (see -# deregister-runner.sh and run-runner.sh for the full story, including the -# ~2-minute "Conflict. Retrying until reconnected" that stranding causes). -# The host's `gh` credential never expires that way. run-runner.sh passes -# the container `-e RUNNER_SELF_DEREGISTER=0` so entrypoint.sh's trap stands -# down and the two sides never race each other or double-remove. -# -# `-` because a runner already removed, or a `gh` API failure, must not fail -# the stop -- deregister-runner.sh already exits 0 for those on its own; -# this is a second, belt-and-braces guard, the same reasoning as -# ExecStopPost's `-` below. -ExecStop=-@LIBEXEC@/deregister-runner.sh %i - -# --rm covers a clean exit; this covers a SIGKILL or a Docker daemon restart -# leaving the container behind still holding the name. `-` so a missing -# container is not a stop failure. @DOCKER@ is resolved at install time by -# install-runner-units.sh (`command -v docker`), not hardcoded to -# /usr/bin/docker -- run-runner.sh itself honours LASTRADA_RUNNER_DOCKER/PATH -# for where docker lives, and the leading `-` means a wrong hardcoded path -# here would fail silently, permanently disabling this cleanup backstop on -# any host where docker isn't at /usr/bin/docker. -ExecStopPost=-@DOCKER@ rm -f @PREFIX@-%i - -# Brings a runner back after an OOM kill mid-link without waiting for a -# reboot. Each restart re-runs run-runner.sh, which mints a fresh token -- -# there is no stored credential that can go stale. -Restart=always -RestartSec=30 - -# The stop sequence in practice, given the host-side ExecStop above (not the -# container's own EXIT trap -- see ExecStop's comment). Verified live against -# this exact fleet (lastrada-runner@2, journalctl --user -u lastrada-runner@2): -# -# 11:17:47 Stopping LASTRADA self-hosted GitHub Actions runner 2... -# 11:17:48 deregister-runner.sh: removed lastrada-docker-2 (id 10097) -# 11:18:08 The runner no longer exists on the server. Cleaning up local configuration. -# √ Removed .credentials -# √ Removed .runner -# Runner listener exit with 0 return code, stop the service, no retry needed. -# Exiting runner... -# 11:18:08 Stopped LASTRADA self-hosted GitHub Actions runner 2. -# -# ExecStop's deregister-runner.sh removes the registration via the host's -# `gh` credential in ~1s; the container's own Runner.Listener, on its next -# poll, discovers it no longer exists on the server, cleans up its local -# `.credentials`/`.runner` state, and exits 0 on its own -- the API removal -# drives that exit, not a signal to the container. The ~20s gap above -# (11:17:48 -> 11:18:08) is that listener noticing, not the deregister call -# itself, which already completed a moment after "Stopping" was logged. -# -# `docker run -i` (no -t) still has sig-proxy on by default, so a container -# that has NOT noticed removal by the time systemd's stop timeout would -# otherwise trip still gets SIGTERM relayed straight into it as a fallback. -# -# ExecStopPost's `docker rm -f` is a further backstop for a container that -# somehow outlived its client (SIGKILL, daemon restart) -- normally it never -# fires. A job in flight is killed, not drained, by a stop or restart mid-job. -# TimeoutStopSec=90 below is essentially never used in the common case. -# -# Because sig-proxy relays it, the docker client exits with the container's -# own exit code for a signal-terminated process: 128+15=143, not 0. Without -# the line below, systemd treats that as a failed unit -- every deliberate -# stop or restart shows red in `systemctl status`, drowning the signal -# StartLimitBurst exists to create. 143 from this client is a normal, -# clean stop, so tell systemd not to flag it as a failure. -SuccessExitStatus=143 -TimeoutStopSec=90 - -[Install] -WantedBy=@WANTEDBY@ diff --git a/.github/self-hosted-runner/run-runner.sh b/.github/self-hosted-runner/run-runner.sh deleted file mode 100755 index 6eca22e06..000000000 --- a/.github/self-hosted-runner/run-runner.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env bash -# Starts one self-hosted runner container in the foreground, with a -# registration token minted fresh for this start. -# -# Usage: run-runner.sh -# -# systemd's lastrada-runner@.service is the only intended caller. -# -# The token is minted here rather than baked into the container by whoever -# created it. A GitHub registration token expires after ~1 hour, so a token -# captured at `docker run` time is dead on every restart after that hour -- -# which is exactly what left five containers restart-looping for six days -# (5,972 failed registrations) until this script existed. Minting per start -# means there is no stored credential that can go stale. -# -# LASTRADA_RUNNER_DRY_RUN=1 prints the docker argv and the stdin payload instead -# of executing, so scripts/test_run_runner.sh can assert the launch contract -# without Docker or GitHub. -set -euo pipefail - -if [ "$#" -lt 1 ]; then - echo "usage: run-runner.sh " >&2 - exit 1 -fi -readonly index="$1" - -config="${LASTRADA_RUNNER_CONFIG:-${XDG_CONFIG_HOME:-$HOME/.config}/lastrada-runner/config}" -if [ ! -r "$config" ]; then - echo "run-runner.sh: no readable config at ${config}" >&2 - exit 1 -fi -# shellcheck disable=SC1090 -. "$config" - -: "${GITHUB_ORG:?config must set GITHUB_ORG}" -: "${RUNNER_NAME_PREFIX:?config must set RUNNER_NAME_PREFIX}" -: "${RUNNER_GROUP:?config must set RUNNER_GROUP}" -: "${RUNNER_LABELS:?config must set RUNNER_LABELS}" -: "${RUNNER_IMAGE:?config must set RUNNER_IMAGE}" -: "${RUNNER_CPUS:?config must set RUNNER_CPUS}" -: "${RUNNER_MEMORY:?config must set RUNNER_MEMORY}" - -readonly name="${RUNNER_NAME_PREFIX}-${index}" -readonly gh="${LASTRADA_RUNNER_GH:-gh}" -readonly docker="${LASTRADA_RUNNER_DOCKER:-docker}" - -# Organisation-level, not repo-level: one fleet serves morph, Pace and -# Lightweight. Needs admin:org on whatever credential gh holds -- and that -# credential stays on the host, never entering a container. -token="$("$gh" api -X POST \ - "orgs/${GITHUB_ORG}/actions/runners/registration-token" --jq '.token // empty')" - -# `--jq '.token // empty'` covers a missing field, but `gh` has printed the -# literal string "null" for one instead of empty output on some versions -- -# and `[ -z "null" ]` is false, so that alone would slip a garbage token -# through to the container. Check both. -if [ -z "$token" ] || [ "$token" = "null" ]; then - echo "run-runner.sh: minted an empty or null registration token" >&2 - exit 1 -fi - -# A container from a previous start can outlive its unit (SIGKILL, daemon -# crash) and still own the name; --rm only covers a clean exit. -"$docker" rm -f "$name" >/dev/null 2>&1 || true - -# Clear any registration this name still holds server-side before starting. -# -# entrypoint.sh's EXIT trap deregisters with `config.sh remove --token`, but -# the only token it has is the REGISTRATION token it started with, and GitHub -# expires those after ~1 hour. So stopping a container that has been up -# longer than that prints "Failed: Removing runner from the server" and -# leaves both the registration and its live session behind. The replacement -# then sits in "A session for this runner already exists ... Conflict. -# Retrying until reconnected" for minutes until GitHub reaps the old session -# -- observed live on a fleet restarted seven hours after it came up. -# -# The host credential has no such expiry, so do it here. The container -# deliberately holds no credential that could: that is the point of minting -# per start and passing the token on stdin. -if [ -z "${LASTRADA_RUNNER_DRY_RUN:-}" ]; then - stale_id="$("$gh" api "orgs/${GITHUB_ORG}/actions/runners" \ - --jq ".runners[] | select(.name == \"${name}\") | .id" 2>/dev/null || true)" - if [ -n "$stale_id" ]; then - echo "run-runner.sh: clearing stale registration for ${name} (id ${stale_id})" - "$gh" api -X DELETE \ - "orgs/${GITHUB_ORG}/actions/runners/${stale_id}" >/dev/null 2>&1 || true - fi -fi - -argv=( - "$docker" run --rm -i - --name "$name" - "--cpus=${RUNNER_CPUS}" - "--memory=${RUNNER_MEMORY}" - --add-host=host.docker.internal:host-gateway - -e "RUNNER_NAME=${name}" - -e "RUNNER_SCOPE_URL=https://github.com/${GITHUB_ORG}" - -e "RUNNER_GROUP=${RUNNER_GROUP}" - -e "RUNNER_LABELS=${RUNNER_LABELS}" - # Under systemd, ExecStop (deregister-runner.sh) deregisters this runner - # from the host, where the credential hasn't expired -- see that script's - # header and the unit template for why. Tell entrypoint.sh's own EXIT - # trap to stand down so removal is never attempted twice, or attempted a - # second time with a token that is certain to be stale by then. - -e "RUNNER_SELF_DEREGISTER=0" - # A host config written before the rename to Pace still says FASTCACHE_ADDR; - # the container only ever gets the PACE_ spelling, the one pace-cc reads. - -e "PACE_ADDR=${PACE_ADDR:-${FASTCACHE_ADDR:-}}" - -e "CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL:-2}" - "${RUNNER_IMAGE}" -) - -if [ -n "${LASTRADA_RUNNER_DRY_RUN:-}" ]; then - printf '%s\n' "${argv[@]}" - printf 'STDIN:%s\n' "$token" - exit 0 -fi - -# The token goes in on stdin, never in the environment. Every job on this -# container can read `env` and /proc/1/environ, and a live registration token -# would let contributor-authored code enrol its own machine into the runner -# group. `exec` so systemd tracks the docker client directly and its SIGTERM -# reaches the container rather than an intermediate shell. -exec "${argv[@]}" <<<"$token" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 123c1f2b4..590563e2b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,26 +66,7 @@ env: # to hold every job's build. The Windows job overrides it, since MSVC has no # equivalent. MORPH_DEBUG_INFO: lines - # Attributes every pace-cc invocation to this one job, so the - # "pace-cc stats" steps below can report *this* build's hit rate. - # Without it they call `--show-stats` bare, which reads the whole - # invocations log -- a self-hosted runner's lifetime totals across every job - # it has ever run. A run of `Linux / all optional features (clang)` that - # compiled 609 translation units reported "80.0% of 9157 cacheable": roughly - # fifteen jobs' worth, of which this job was 6.6%. The step exists to say - # whether the build was cached and structurally could not, which is the - # failure AGENTS.md puts first -- a hit rate says nothing until you know how - # many compilations it was offered. - # - # A group id rather than `--zero-stats`: zeroing is a process-wide truncation - # of a log this runner's other concurrent jobs are also writing to, so it - # would race them and destroy their numbers as well as the history. The id is - # explicitly not part of the cache key (see `pace-cc --help`, - # PACE_PREFETCH_GROUP), so this partitions the *statistics* and never - # the cache itself -- jobs still read each other's entries. - PACE_PREFETCH_GROUP: "${{ github.run_id }}-${{ github.job }}" - # A UTF-8 locale on every runner. The hosted image sets one and the - # self-hosted Docker runners do not; under "C", Qt warns that it switched to + # A UTF-8 locale on every runner: under "C", Qt warns that it switched to # C.UTF-8, and the ladder's render smokes fail on any Qt warning. LC_ALL: C.UTF-8 LANG: C.UTF-8 @@ -223,93 +204,10 @@ jobs: if: endsWith(matrix.preset, '-debug') run: ctest --preset ${{ matrix.preset }} - # Picks a self-hosted lastrada-docker runner for the Linux legs when one is - # registered, online, and idle; falls back to the GitHub-hosted label - # otherwise. The runners are ORGANISATION-level (one fleet serves morph, - # Pace and Lightweight), so this queries the org endpoint -- the - # repo endpoint returns zero for them and every run would silently go - # GitHub-hosted with no error anywhere. - # - # GITHUB_TOKEN can't call the runners API, so this needs - # RUNNER_STATUS_TOKEN: a PAT with organisation self-hosted-runner read - # access (admin:org, or fine-grained "Self-hosted runners: Read-only" on - # LASTRADA-Software), stored as a repo secret. Forked-repo PRs don't get - # repo secrets at all (the token comes through empty), which this treats - # the same as "no runner online": fall back to GitHub-hosted. A failed - # curl, or a 200 response whose body is missing or the wrong shape for - # `.runners`, are treated the same way. See - # .github/self-hosted-runner/README.md for the fleet itself. - probe-self-hosted: - name: Probe self-hosted runner - runs-on: ubuntu-24.04 - outputs: - runs_on: ${{ steps.probe.outputs.runs_on }} - steps: - - name: Check for an idle lastrada-docker runner - id: probe - env: - RUNNER_STATUS_TOKEN: ${{ secrets.RUNNER_STATUS_TOKEN }} - run: | - set -euo pipefail - fallback='["ubuntu-24.04"]' - - if [ -z "${RUNNER_STATUS_TOKEN}" ]; then - echo "No RUNNER_STATUS_TOKEN (e.g. a forked-repo PR) -- using GitHub-hosted." - echo "runs_on=${fallback}" >> "$GITHUB_OUTPUT" - exit 0 - fi - - runners=$(curl -fsSL \ - -H "Authorization: Bearer ${RUNNER_STATUS_TOKEN}" \ - -H "Accept: application/vnd.github+json" \ - "https://api.github.com/orgs/LASTRADA-Software/actions/runners") || { - echo "Runners API call failed -- using GitHub-hosted." - echo "runs_on=${fallback}" >> "$GITHUB_OUTPUT" - exit 0 - } - - online=$(echo "${runners}" | jq '[(.runners // [])[] | - select(.status == "online" and .busy == false and - (.labels | map(.name) | contains(["lastrada-docker"])))] | length') || { - echo "Malformed runners response -- using GitHub-hosted." - echo "runs_on=${fallback}" >> "$GITHUB_OUTPUT" - exit 0 - } - - if ! [[ "${online}" =~ ^[0-9]+$ ]]; then - online=0 - fi - - if [ "${online}" -gt 0 ]; then - echo "Found an idle lastrada-docker runner -- using self-hosted." - echo 'runs_on=["self-hosted", "Linux", "X64", "lastrada-docker"]' >> "$GITHUB_OUTPUT" - else - echo "No idle lastrada-docker runner -- using GitHub-hosted." - echo "runs_on=${fallback}" >> "$GITHUB_OUTPUT" - fi - # ── Linux: GCC and Clang plain builds ──────────────────────────────── linux-compilers: name: Linux / ${{ matrix.preset }} - needs: probe-self-hosted - runs-on: ${{ fromJSON(needs.probe-self-hosted.outputs.runs_on) }} - env: - # Only set on the self-hosted path: host.docker.internal does not - # resolve on a GitHub-hosted VM (it is not a Docker container), and an - # address that is merely unreachable rather than refusing the - # connection stalls pace-cc's TCP connect for up to ~2m30s per - # matrix leg (CompileCache.cmake's own measured worst case) instead of - # failing fast -- so this must stay empty on that path, not just - # "wrong but harmless". - PACE_ADDR: ${{ contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted') && 'host.docker.internal:6674' || '' }} - # PACE_AUTO_INSTALL is a plain CMake option(), not something - # CompileCache.cmake reads from the environment the way it does - # PACE_ADDR -- an env var of this name is silently ignored, only - # -DPACE_AUTO_INSTALL=ON on the cmake command line reaches it - # (confirmed live: PACE_ADDR landed in CMakeCache.txt from the - # environment, PACE_AUTO_INSTALL stayed OFF). This is that flag, - # precomputed once so every Configure step below can just splice it in. - MORPH_PACE_AUTO_INSTALL_FLAG: ${{ contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted') && '-DPACE_AUTO_INSTALL=ON' || '' }} + runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: @@ -376,33 +274,25 @@ jobs: test -s /tmp/llvm.sh sudo bash /tmp/llvm.sh ${{ env.CLANG_VERSION }} - # Skipped on the self-hosted path, which caches through pace-cc: - # CompileCache.cmake only auto-installs pace-cc when no other - # launcher is on PATH, so installing sccache there would disable it. - name: Set up sccache - if: "!contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" uses: ./.github/actions/sccache-setup # No -DCMAKE_..._COMPILER_LAUNCHER=sccache here on purpose: leaving the # launcher unset lets cmake/CompileCache.cmake's own auto-detection run, - # which prefers pace-cc (this job's PACE_ADDR, set above, only - # when running self-hosted) and falls back to the sccache install steps - # above when no daemon answers -- e.g. this exact job on the - # GitHub-hosted fallback runner, which never gets a PACE_ADDR to - # begin with. Setting the launcher explicitly, as every other Linux job - # still does, would make CompileCache.cmake bail out before it ever + # which prefers pace-cc when a daemon answers and otherwise picks the + # sccache set up above. Setting the launcher explicitly, as every other + # Linux job does, would make CompileCache.cmake bail out before it ever # probes for pace-cc (see that file's own comment). - name: Configure (gcc) if: startsWith(matrix.preset, 'gcc-') - run: cmake --preset ${{ matrix.preset }} $MORPH_PACE_AUTO_INSTALL_FLAG + run: cmake --preset ${{ matrix.preset }} - name: Configure (clang) if: startsWith(matrix.preset, 'clang-') run: | cmake --preset ${{ matrix.preset }} \ -DCMAKE_C_COMPILER=clang-${{ env.CLANG_VERSION }} \ - -DCMAKE_CXX_COMPILER=clang++-${{ env.CLANG_VERSION }} \ - $MORPH_PACE_AUTO_INSTALL_FLAG + -DCMAKE_CXX_COMPILER=clang++-${{ env.CLANG_VERSION }} # One compile per CPU, not ninja's default of two more. The heaviest # translation units peak at 2.5-3.4 GB each, so six at once outgrow a @@ -427,55 +317,12 @@ jobs: # unfalsifiable: a thrashing cache and a working one look identical # from the outside, and only the build-step duration hints at which # one you have. `|| true` so a stats failure never fails the job. - # - # Guarded the same way as the Set up sccache step above: - # sccache is never installed on the self-hosted path (pace-cc is - # used there instead), so `sccache --show-stats` would just fail - # "command not found" there. - name: sccache stats - if: "always() && !contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" + if: always() run: sccache --show-stats || true - # Cache statistics for this leg. The `sccache stats` step is skipped - # whenever the probe put this job on the self-hosted fleet, because - # sccache is not the launcher there -- pace-cc is. Nothing replaced - # it, so those legs ran with no cache reporting at all: exactly the - # "unfalsifiable" state the sccache step's own comment warns about, where - # a thrashing cache and a working one look identical from the outside and - # only the build duration hints at which one you have. - # - # The line that matters is - # unavailable : N (x% of all compiles -- CACHE NOT REACHED) - # which is how a daemon that is configured but never answering shows up. - # Configure still prints "Enabling pace-cc at ..." in that case and - # the build simply takes as long as a cold one, so no other signal in the - # job would reveal it. - # - # Mirror of the sccache step's condition, so exactly one of the two runs. - # `|| true` for the same reason it has one: a stats failure must never - # fail the job. - - name: pace-cc stats - if: "always() && contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" - run: | - FC="$(command -v pace-cc || true)" - if [ -z "$FC" ]; then - FC="$(ls -t "$HOME"/.cache/pace-cc/*/*/pace-cc 2>/dev/null | head -1 || true)" - fi - if [ -z "$FC" ]; then - echo "::warning::pace-cc not found on a self-hosted runner -- the build ran uncached." - exit 0 - fi - echo "launcher: $FC PACE_ADDR=${PACE_ADDR:-}" - # This job's own numbers, not the runner's lifetime totals. The - # bare form is kept underneath because the whole-runner view is - # what shows eviction pressure across jobs, which a single job's - # slice cannot. - "$FC" --show-stats --prefetch-group "$PACE_PREFETCH_GROUP" || true - echo "--- whole runner, all jobs (context for the above) ---" - "$FC" --show-stats || true - - name: Upload the sccache entries this build used - if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && !contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted') + if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') uses: ./.github/actions/sccache-upload with: name: ${{ github.job }}-${{ strategy.job-index }} @@ -483,16 +330,7 @@ jobs: # ── Linux: sanitizers + coverage (all clang) ───────────────────────── linux-sanitizers: name: Linux / ${{ matrix.preset }} - needs: probe-self-hosted - runs-on: ${{ fromJSON(needs.probe-self-hosted.outputs.runs_on) }} - env: - # See linux-compilers' identical env block for why PACE_ADDR is - # conditional, and why PACE_AUTO_INSTALL has to be a -D flag - # (MORPH_PACE_AUTO_INSTALL_FLAG) rather than an env var of that - # name -- CompileCache.cmake declares it as a plain option(), which - # CMake never reads from the environment. - PACE_ADDR: ${{ contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted') && 'host.docker.internal:6674' || '' }} - MORPH_PACE_AUTO_INSTALL_FLAG: ${{ contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted') && '-DPACE_AUTO_INSTALL=ON' || '' }} + runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: @@ -521,11 +359,7 @@ jobs: test -s /tmp/llvm.sh sudo bash /tmp/llvm.sh ${{ env.CLANG_VERSION }} - # Skipped on the self-hosted path, which caches through pace-cc: - # CompileCache.cmake only auto-installs pace-cc when no other - # launcher is on PATH, so installing sccache there would disable it. - name: Set up sccache - if: "!contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" uses: ./.github/actions/sccache-setup # morph::net and the SQLite offline queue are opt-in, but they are also @@ -538,7 +372,7 @@ jobs: # loop executor are where a terminal application's threading lives. # # No -DCMAKE_..._COMPILER_LAUNCHER=sccache: see linux-compilers' Configure - # steps for why leaving it unset is what lets pace-cc be selected. + # steps for why the launcher is left to CompileCache.cmake. - name: Configure run: | cmake --preset ${{ matrix.preset }} \ @@ -547,14 +381,12 @@ jobs: -DMORPH_BUILD_TUI=ON \ -DMORPH_BUILD_OFFLINE_SQLITE=ON \ -DCMAKE_C_COMPILER=clang-${{ env.CLANG_VERSION }} \ - -DCMAKE_CXX_COMPILER=clang++-${{ env.CLANG_VERSION }} \ - $MORPH_PACE_AUTO_INSTALL_FLAG + -DCMAKE_CXX_COMPILER=clang++-${{ env.CLANG_VERSION }} # Sanitizer-instrumented compiles and links of the heaviest test files go past the runner's 16 GB and 3 GB of # swap at one job per CPU, and the runner is lost with no compiler error. Extra swap costs nothing unless it - # is needed; the Build step prints the swap used. A self-hosted runner sizes its own memory. + # is needed; the Build step prints the swap used. - name: Add swap for the build's heaviest compiles - if: runner.environment == 'github-hosted' run: | sudo fallocate -l 12G /mnt/build-swap sudo chmod 600 /mnt/build-swap @@ -669,61 +501,20 @@ jobs: if: "!cancelled()" run: ctest --preset ${{ matrix.preset }} --parallel "$(nproc)" -L tui --no-tests=error --output-on-failure - # Cache statistics for this leg. The `sccache stats` step is skipped - # whenever the probe put this job on the self-hosted fleet, because - # sccache is not the launcher there -- pace-cc is. Nothing replaced - # it, so those legs ran with no cache reporting at all: exactly the - # "unfalsifiable" state the sccache step's own comment warns about, where - # a thrashing cache and a working one look identical from the outside and - # only the build duration hints at which one you have. - # - # The line that matters is - # unavailable : N (x% of all compiles -- CACHE NOT REACHED) - # which is how a daemon that is configured but never answering shows up. - # Configure still prints "Enabling pace-cc at ..." in that case and - # the build simply takes as long as a cold one, so no other signal in the - # job would reveal it. - # - # Mirror of the sccache step's condition, so exactly one of the two runs. - # `|| true` for the same reason it has one: a stats failure must never - # fail the job. - - name: pace-cc stats - if: "always() && contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" - run: | - FC="$(command -v pace-cc || true)" - if [ -z "$FC" ]; then - FC="$(ls -t "$HOME"/.cache/pace-cc/*/*/pace-cc 2>/dev/null | head -1 || true)" - fi - if [ -z "$FC" ]; then - echo "::warning::pace-cc not found on a self-hosted runner -- the build ran uncached." - exit 0 - fi - echo "launcher: $FC PACE_ADDR=${PACE_ADDR:-}" - # This job's own numbers, not the runner's lifetime totals. The - # bare form is kept underneath because the whole-runner view is - # what shows eviction pressure across jobs, which a single job's - # slice cannot. - "$FC" --show-stats --prefetch-group "$PACE_PREFETCH_GROUP" || true - echo "--- whole runner, all jobs (context for the above) ---" - "$FC" --show-stats || true - - name: sccache stats - if: "always() && !contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" + if: always() run: sccache --show-stats || true - name: Upload the sccache entries this build used - if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && !contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted') + if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') uses: ./.github/actions/sccache-upload with: name: ${{ github.job }}-${{ strategy.job-index }} # ── Linux: coverage (clang, ladder + Qt) ───────────────────────────── # - # Split out of linux-sanitizers (which used to carry this as a 4th - # clang-coverage matrix leg) so plain asan/tsan/ubsan can move onto the - # self-hosted probe while this leg -- the one that builds the full - # ladder stack (ODBC/SQLite/yaml-cpp/zip) and Qt, and uploads to - # Codecov -- stays pinned to ubuntu-24.04. + # A job of its own rather than a linux-sanitizers leg: it builds the full + # ladder stack (ODBC/SQLite/yaml-cpp/zip) and Qt, and uploads to Codecov. linux-coverage: name: Linux / clang-coverage runs-on: ubuntu-24.04 @@ -995,16 +786,7 @@ jobs: # ── Linux: application ladder testkit (path-filtered) ───────────────── ladder-tests: name: Application ladder - needs: probe-self-hosted - runs-on: ${{ fromJSON(needs.probe-self-hosted.outputs.runs_on) }} - env: - # See linux-compilers' identical env block for why PACE_ADDR is - # conditional, and why PACE_AUTO_INSTALL has to be a -D flag - # (MORPH_PACE_AUTO_INSTALL_FLAG) rather than an env var of that - # name -- CompileCache.cmake declares it as a plain option(), which - # CMake never reads from the environment. - PACE_ADDR: ${{ contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted') && 'host.docker.internal:6674' || '' }} - MORPH_PACE_AUTO_INSTALL_FLAG: ${{ contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted') && '-DPACE_AUTO_INSTALL=ON' || '' }} + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 with: @@ -1177,10 +959,10 @@ jobs: sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test sudo apt-get update -q # libsqlite3-dev: Lightweight's own CMakeLists.txt does - # find_package(SQLite3) as a system CONFIG package. GitHub-hosted - # ubuntu-24.04 ships it preinstalled; a bare self-hosted image does - # not, so configure fails with "Could NOT find SQLite3" the moment - # MORPH_BUILD_LADDER=ON pulls Lightweight in without it. + # find_package(SQLite3) as a system CONFIG package. ubuntu-24.04 + # ships it preinstalled; installing it explicitly keeps configure + # from failing with "Could NOT find SQLite3" the moment + # MORPH_BUILD_LADDER=ON pulls Lightweight in. # unixodbc-dev + libsqliteodbc: the application ladder fetches the # Lightweight ORM, whose CMake runs # `pkg_check_modules(ODBC REQUIRED odbc)`, and whose ladder fixtures @@ -1210,16 +992,12 @@ jobs: modules: qtwebsockets qtmultimedia cache: true - # Skipped on the self-hosted path, which caches through pace-cc: - # CompileCache.cmake only auto-installs pace-cc when no other - # launcher is on PATH, so installing sccache there would disable it. - name: Set up sccache - if: "steps.filter.outputs.run == 'true' && !contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" + if: steps.filter.outputs.run == 'true' uses: ./.github/actions/sccache-setup # No -DCMAKE_..._COMPILER_LAUNCHER=sccache: see linux-compilers' - # Configure steps for why leaving it unset is what lets pace-cc - # be selected. + # Configure steps for why the launcher is left to CompileCache.cmake. # Bank is rung 2, so -DMORPH_LADDER_RUNGS=all already adds it through the # rung loop; -DMORPH_BUILD_BANK_EXAMPLE=ON asks for it explicitly as # well, and the root adds examples/bank itself only when the ladder is @@ -1244,14 +1022,13 @@ jobs: -DMORPH_BUILD_QT_QUICK=ON \ -DMORPH_BUILD_LADDER=ON \ -DMORPH_LADDER_RUNGS=all \ - -DMORPH_BUILD_BANK_EXAMPLE=ON \ - $MORPH_PACE_AUTO_INSTALL_FLAG + -DMORPH_BUILD_BANK_EXAMPLE=ON # The build ends by linking the largest test binaries, debug information and all, several at once; past the # runner's 16 GB and 3 GB of swap that ends in exit 143 with no compiler error. Extra swap costs nothing unless - # it is needed; the Build step prints the swap used. A self-hosted runner sizes its own memory. + # it is needed; the Build step prints the swap used. - name: Add swap for the build's heaviest links - if: steps.filter.outputs.run == 'true' && runner.environment == 'github-hosted' + if: steps.filter.outputs.run == 'true' run: | sudo fallocate -l 12G /mnt/build-swap sudo chmod 600 /mnt/build-swap @@ -1396,53 +1173,12 @@ jobs: # unfalsifiable: a thrashing cache and a working one look identical # from the outside, and only the build-step duration hints at which # one you have. `|| true` so a stats failure never fails the job. - # - # Guarded the same way as the Set up sccache step above: - # sccache is never installed on the self-hosted path. - name: sccache stats - if: "always() && steps.filter.outputs.run == 'true' && !contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" + if: always() && steps.filter.outputs.run == 'true' run: sccache --show-stats || true - # Cache statistics for this leg. The `sccache stats` step is skipped - # whenever the probe put this job on the self-hosted fleet, because - # sccache is not the launcher there -- pace-cc is. Nothing replaced - # it, so those legs ran with no cache reporting at all: exactly the - # "unfalsifiable" state the sccache step's own comment warns about, where - # a thrashing cache and a working one look identical from the outside and - # only the build duration hints at which one you have. - # - # The line that matters is - # unavailable : N (x% of all compiles -- CACHE NOT REACHED) - # which is how a daemon that is configured but never answering shows up. - # Configure still prints "Enabling pace-cc at ..." in that case and - # the build simply takes as long as a cold one, so no other signal in the - # job would reveal it. - # - # Mirror of the sccache step's condition, so exactly one of the two runs. - # `|| true` for the same reason it has one: a stats failure must never - # fail the job. - - name: pace-cc stats - if: "always() && steps.filter.outputs.run == 'true' && contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" - run: | - FC="$(command -v pace-cc || true)" - if [ -z "$FC" ]; then - FC="$(ls -t "$HOME"/.cache/pace-cc/*/*/pace-cc 2>/dev/null | head -1 || true)" - fi - if [ -z "$FC" ]; then - echo "::warning::pace-cc not found on a self-hosted runner -- the build ran uncached." - exit 0 - fi - echo "launcher: $FC PACE_ADDR=${PACE_ADDR:-}" - # This job's own numbers, not the runner's lifetime totals. The - # bare form is kept underneath because the whole-runner view is - # what shows eviction pressure across jobs, which a single job's - # slice cannot. - "$FC" --show-stats --prefetch-group "$PACE_PREFETCH_GROUP" || true - echo "--- whole runner, all jobs (context for the above) ---" - "$FC" --show-stats || true - - name: Upload the sccache entries this build used - if: "steps.filter.outputs.run == 'true' && github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && !contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" + if: steps.filter.outputs.run == 'true' && github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') uses: ./.github/actions/sccache-upload with: name: ${{ github.job }}-${{ strategy.job-index }} @@ -1471,16 +1207,7 @@ jobs: # design and ASan's shadow-memory overhead compounds that. ladder-sanitizers: name: Application ladder / ASan+UBSan - needs: probe-self-hosted - runs-on: ${{ fromJSON(needs.probe-self-hosted.outputs.runs_on) }} - env: - # See linux-compilers' identical env block for why PACE_ADDR is - # conditional, and why PACE_AUTO_INSTALL has to be a -D flag - # (MORPH_PACE_AUTO_INSTALL_FLAG) rather than an env var of that - # name -- CompileCache.cmake declares it as a plain option(), which - # CMake never reads from the environment. - PACE_ADDR: ${{ contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted') && 'host.docker.internal:6674' || '' }} - MORPH_PACE_AUTO_INSTALL_FLAG: ${{ contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted') && '-DPACE_AUTO_INSTALL=ON' || '' }} + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 with: @@ -1563,16 +1290,12 @@ jobs: modules: qtwebsockets qtmultimedia cache: true - # Skipped on the self-hosted path, which caches through pace-cc: - # CompileCache.cmake only auto-installs pace-cc when no other - # launcher is on PATH, so installing sccache there would disable it. - name: Set up sccache - if: "steps.filter.outputs.run == 'true' && !contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" + if: steps.filter.outputs.run == 'true' uses: ./.github/actions/sccache-setup # No -DCMAKE_..._COMPILER_LAUNCHER=sccache: see linux-compilers' - # Configure steps for why leaving it unset is what lets pace-cc - # be selected. + # Configure steps for why the launcher is left to CompileCache.cmake. # MORPH_BUILD_UNIT_TESTS=OFF: this job runs the ladder and the Qt # transport suites only, and morph_tests and morph_table_tests were a # third of its compiles. "Linux / clang-asan" builds and runs them under @@ -1586,8 +1309,7 @@ jobs: -DMORPH_LADDER_RUNGS=all \ -DMORPH_BUILD_UNIT_TESTS=OFF \ -DCMAKE_C_COMPILER=clang-${{ env.CLANG_VERSION }} \ - -DCMAKE_CXX_COMPILER=clang++-${{ env.CLANG_VERSION }} \ - $MORPH_PACE_AUTO_INSTALL_FLAG + -DCMAKE_CXX_COMPILER=clang++-${{ env.CLANG_VERSION }} # QT_QPA_PLATFORM=offscreen at build time as well as test time: Catch2's # catch_discover_tests() runs each Qt-linked test binary once during the @@ -1685,53 +1407,12 @@ jobs: # unfalsifiable: a thrashing cache and a working one look identical # from the outside, and only the build-step duration hints at which # one you have. `|| true` so a stats failure never fails the job. - # - # Guarded the same way as the Set up sccache step above: - # sccache is never installed on the self-hosted path. - name: sccache stats - if: "always() && steps.filter.outputs.run == 'true' && !contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" + if: always() && steps.filter.outputs.run == 'true' run: sccache --show-stats || true - # Cache statistics for this leg. The `sccache stats` step is skipped - # whenever the probe put this job on the self-hosted fleet, because - # sccache is not the launcher there -- pace-cc is. Nothing replaced - # it, so those legs ran with no cache reporting at all: exactly the - # "unfalsifiable" state the sccache step's own comment warns about, where - # a thrashing cache and a working one look identical from the outside and - # only the build duration hints at which one you have. - # - # The line that matters is - # unavailable : N (x% of all compiles -- CACHE NOT REACHED) - # which is how a daemon that is configured but never answering shows up. - # Configure still prints "Enabling pace-cc at ..." in that case and - # the build simply takes as long as a cold one, so no other signal in the - # job would reveal it. - # - # Mirror of the sccache step's condition, so exactly one of the two runs. - # `|| true` for the same reason it has one: a stats failure must never - # fail the job. - - name: pace-cc stats - if: "always() && steps.filter.outputs.run == 'true' && contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" - run: | - FC="$(command -v pace-cc || true)" - if [ -z "$FC" ]; then - FC="$(ls -t "$HOME"/.cache/pace-cc/*/*/pace-cc 2>/dev/null | head -1 || true)" - fi - if [ -z "$FC" ]; then - echo "::warning::pace-cc not found on a self-hosted runner -- the build ran uncached." - exit 0 - fi - echo "launcher: $FC PACE_ADDR=${PACE_ADDR:-}" - # This job's own numbers, not the runner's lifetime totals. The - # bare form is kept underneath because the whole-runner view is - # what shows eviction pressure across jobs, which a single job's - # slice cannot. - "$FC" --show-stats --prefetch-group "$PACE_PREFETCH_GROUP" || true - echo "--- whole runner, all jobs (context for the above) ---" - "$FC" --show-stats || true - - name: Upload the sccache entries this build used - if: "steps.filter.outputs.run == 'true' && github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && !contains(needs.probe-self-hosted.outputs.runs_on, 'self-hosted')" + if: steps.filter.outputs.run == 'true' && github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') uses: ./.github/actions/sccache-upload with: name: ${{ github.job }}-${{ strategy.job-index }} diff --git a/.github/workflows/nightly-slow-checks.yml b/.github/workflows/nightly-slow-checks.yml index d1fad2b3d..da677d1a6 100644 --- a/.github/workflows/nightly-slow-checks.yml +++ b/.github/workflows/nightly-slow-checks.yml @@ -41,7 +41,6 @@ env: # than that leaves the stats step reading a fresh server's zero counters. SCCACHE_IDLE_TIMEOUT: "0" MORPH_DEBUG_INFO: lines - PACE_PREFETCH_GROUP: "${{ github.run_id }}-${{ github.job }}" CLANG_VERSION: "22" CATCH2_VERSION: "3.4.0" QT_VERSION: "6.8.1" diff --git a/scripts/coverage.sh b/scripts/coverage.sh index 0f41774c6..571b01173 100644 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -70,9 +70,9 @@ MANIFEST="$OUT/coverage_objects.txt" # has succeeded, every time. That makes the profile set for *this* run exactly # "everything written since the last successful `coverage.sh`", which is a # bound with no reliance on wall-clock time or on the caller remembering a -# separate clean step: a workspace that runs `coverage.sh` at all, including a -# persistent self-hosted-runner workspace across many CI runs, can never carry -# a `.profraw` forward past the run that consumed it. `check_coverage_profiles.sh` +# separate clean step: a workspace that runs `coverage.sh` at all, however +# many times it is reused, can never carry a `.profraw` forward past the run +# that consumed it. `check_coverage_profiles.sh` # holds this as a gate of its own, on the same terms as the two neighbouring # ones below -- a separate script because a gate nobody tests reports green # whether or not it still detects anything, and diff --git a/scripts/test_run_runner.sh b/scripts/test_run_runner.sh deleted file mode 100644 index ee58f03c8..000000000 --- a/scripts/test_run_runner.sh +++ /dev/null @@ -1,205 +0,0 @@ -#!/usr/bin/env bash -# Usage: bash scripts/test_run_runner.sh -# -# Self-test for .github/self-hosted-runner/run-runner.sh, which is what -# systemd runs to start one self-hosted runner container. -# -# The launch contract is the whole point of the script and every clause of it -# is a past or potential outage: -# -# * the token is minted per start, from the ORG endpoint -- a token baked -# into a container at creation time expires in ~1 hour and left five -# containers restart-looping for six days; -# * the token travels on stdin, never in `-e` -- every job on the container -# can read /proc/1/environ, and these are public repositories running -# contributor-authored build code; -# * `--rm` and no `--restart` -- Docker must not supervise a container -# systemd is already supervising. -# -# None of that is observable from the outside once the script execs docker, so -# it is asserted through LASTRADA_RUNNER_DRY_RUN with stub gh/docker binaries. -set -euo pipefail - -readonly repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -readonly launcher="${repo_root}/.github/self-hosted-runner/run-runner.sh" - -failures=0 -note() { printf 'ok: %s\n' "$*"; } -fail() { - printf 'error: %s\n' "$*" >&2 - failures=$((failures + 1)) -} - -scratch="$(mktemp -d)" -trap 'rm -rf "$scratch"' EXIT - -# ── stubs ──────────────────────────────────────────────────────────────────── -cat >"${scratch}/gh" <<'STUB' -#!/usr/bin/env bash -printf '%s\n' "$*" >>"${STUB_GH_LOG}" -printf '%s\n' "${STUB_GH_TOKEN:-tok-ABC123}" -STUB -chmod +x "${scratch}/gh" - -cat >"${scratch}/docker" <<'STUB' -#!/usr/bin/env bash -exit 0 -STUB -chmod +x "${scratch}/docker" - -cat >"${scratch}/config" <<'CONF' -GITHUB_ORG=LASTRADA-Software -RUNNER_NAME_PREFIX=lastrada-docker -RUNNER_GROUP=linux-docker -RUNNER_LABELS=self-hosted,Linux,X64,lastrada-docker -RUNNER_CPUS=2 -RUNNER_MEMORY=6g -RUNNER_IMAGE=lastrada-runner:latest -PACE_ADDR=host.docker.internal:6674 -CMAKE_BUILD_PARALLEL_LEVEL=2 -CONF - -export STUB_GH_LOG="${scratch}/gh.log" -: >"${STUB_GH_LOG}" - -out="$(LASTRADA_RUNNER_DRY_RUN=1 \ - LASTRADA_RUNNER_CONFIG="${scratch}/config" \ - LASTRADA_RUNNER_GH="${scratch}/gh" \ - LASTRADA_RUNNER_DOCKER="${scratch}/docker" \ - bash "$launcher" 3 2>&1)" || { - fail "run-runner.sh exited non-zero in dry-run mode:" - printf '%s\n' "$out" >&2 - exit 1 -} - -has() { printf '%s\n' "$out" | grep -qxF -- "$1"; } - -# ── the token is minted per start, against the org endpoint ────────────────── -if grep -q 'orgs/LASTRADA-Software/actions/runners/registration-token' "${STUB_GH_LOG}"; then - note "mints from the organisation registration-token endpoint" -else - fail "did not call the org registration-token endpoint; gh saw: $(cat "${STUB_GH_LOG}")" -fi - -if grep -q 'repos/' "${STUB_GH_LOG}"; then - fail "still calling a repo-level endpoint: $(cat "${STUB_GH_LOG}")" -else - note "no repo-level endpoint call" -fi - -# ── the token goes in on stdin and nowhere else ────────────────────────────── -if has 'STDIN:tok-ABC123'; then - note "token delivered on stdin" -else - fail "token was not delivered on stdin" -fi - -# Each argv element prints on its own line, so the -e and its value are -# separate lines -- match the value line, not "-e RUNNER_TOKEN", which -# would never match and would make this assertion vacuous. -if printf '%s\n' "$out" | grep -q '^RUNNER_TOKEN='; then - fail "token passed via -e RUNNER_TOKEN; jobs on the container could read it" -else - note "no RUNNER_TOKEN environment argument" -fi - -if printf '%s\n' "$out" | grep -v '^STDIN:' | grep -q 'tok-ABC123'; then - fail "the token leaked into the docker argv" -else - note "token absent from the docker argv" -fi - -# ── the cache address reaches the container as PACE_ADDR ───────────────────── -if has 'PACE_ADDR=host.docker.internal:6674'; then - note "PACE_ADDR passed to the container" -else - fail "PACE_ADDR=host.docker.internal:6674 missing from the docker argv" -fi - -# A config predating the rename names FASTCACHE_ADDR; it must still arrive. -sed -i 's/^PACE_ADDR=/FASTCACHE_ADDR=/' "${scratch}/config" -legacy="$(LASTRADA_RUNNER_DRY_RUN=1 \ - LASTRADA_RUNNER_CONFIG="${scratch}/config" \ - LASTRADA_RUNNER_GH="${scratch}/gh" \ - LASTRADA_RUNNER_DOCKER="${scratch}/docker" \ - bash "$launcher" 3 2>&1)" || legacy="" -if printf '%s\n' "$legacy" | grep -qxF -- 'PACE_ADDR=host.docker.internal:6674'; then - note "a FASTCACHE_ADDR config still reaches the container as PACE_ADDR" -else - fail "a FASTCACHE_ADDR config did not reach the container as PACE_ADDR" -fi - -# ── systemd owns the lifecycle, not Docker ─────────────────────────────────── -if has '--rm'; then - note "--rm present" -else - fail "--rm missing; containers would accumulate" -fi - -if printf '%s\n' "$out" | grep -q -- '--restart'; then - fail "--restart present; Docker would fight systemd for the lifecycle" -else - note "no --restart flag" -fi - -# ── resource caps and identity ─────────────────────────────────────────────── -for expected in '--cpus=2' '--memory=6g' 'lastrada-docker-3'; do - if has "$expected"; then - note "${expected} present" - else - fail "${expected} missing from the docker argv" - fi -done - -if printf '%s\n' "$out" | grep -q 'morph-docker'; then - fail "the retired morph-docker name/label is still emitted" -else - note "no morph-docker name or label" -fi - -# ── the container must not race the host's ExecStop deregistration ───────── -# Under systemd, ExecStop (deregister-runner.sh) removes the registration -# from the host -- see that script and the unit template for why. Without -# this flag the container's own entrypoint.sh EXIT trap would also try, with -# a registration token that is likely stale by stop time, doubling the -# removal attempt for no benefit. -if has 'RUNNER_SELF_DEREGISTER=0'; then - note "RUNNER_SELF_DEREGISTER=0 present" -else - fail "RUNNER_SELF_DEREGISTER=0 missing; the container would race the host's ExecStop deregistration" -fi - -# ── a missing config must fail loudly, not launch an unconfigured runner ───── -if LASTRADA_RUNNER_DRY_RUN=1 LASTRADA_RUNNER_CONFIG="${scratch}/absent" \ - bash "$launcher" 1 >/dev/null 2>&1; then - fail "a missing config file was accepted" -else - note "a missing config file is rejected" -fi - -# ── a missing index must fail loudly ───────────────────────────────────────── -if LASTRADA_RUNNER_DRY_RUN=1 LASTRADA_RUNNER_CONFIG="${scratch}/config" \ - LASTRADA_RUNNER_GH="${scratch}/gh" LASTRADA_RUNNER_DOCKER="${scratch}/docker" \ - bash "$launcher" >/dev/null 2>&1; then - fail "a missing runner index was accepted" -else - note "a missing runner index is rejected" -fi - -# ── a null registration token must fail loudly, not launch a misconfigured -# runner -- `gh api --jq '.token'` prints the literal string "null" when the -# response has no token field, which `[ -z "$token" ]` alone would not catch. -if STUB_GH_TOKEN=null \ - LASTRADA_RUNNER_DRY_RUN=1 LASTRADA_RUNNER_CONFIG="${scratch}/config" \ - LASTRADA_RUNNER_GH="${scratch}/gh" LASTRADA_RUNNER_DOCKER="${scratch}/docker" \ - bash "$launcher" 1 >/dev/null 2>&1; then - fail "a null registration token was accepted" -else - note "a null registration token is rejected" -fi - -if [ "$failures" -ne 0 ]; then - printf '\n%d check(s) failed\n' "$failures" >&2 - exit 1 -fi -printf '\nall run-runner.sh launch-contract checks passed\n' diff --git a/scripts/test_runner_entrypoint.sh b/scripts/test_runner_entrypoint.sh deleted file mode 100644 index 881d6451d..000000000 --- a/scripts/test_runner_entrypoint.sh +++ /dev/null @@ -1,166 +0,0 @@ -#!/usr/bin/env bash -# Usage: bash scripts/test_runner_entrypoint.sh -# -# Self-test for read_runner_token() and install_deregister_trap() in -# .github/self-hosted-runner/entrypoint.sh. -# -# Two callers deliver the registration token two different ways and both must -# keep working: systemd's run-runner.sh pipes it on stdin (so it never enters -# the container environment, where any job could read it), while the plain -# `docker run -e RUNNER_TOKEN=...` path documented for Docker Desktop hosts -# has no stdin to pipe. Getting the precedence wrong fails closed in the worst -# way -- the runner registers with an empty token and the container -# restart-loops, which is the exact failure this whole change exists to end. -# -# Separately, exactly one side must ever deregister a runner: under systemd -# the host's ExecStop does it (deregister-runner.sh, with a credential that -# hasn't expired); standalone (`docker run`, no systemd) this container's own -# EXIT trap is the only mechanism there is. install_deregister_trap() picks -# between them based on RUNNER_SELF_DEREGISTER, and that choice is asserted -# below behaviourally -- by actually letting the trap fire -- not textually. -set -euo pipefail - -readonly repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -readonly entrypoint="${repo_root}/.github/self-hosted-runner/entrypoint.sh" - -failures=0 -note() { printf 'ok: %s\n' "$*"; } -fail() { - printf 'error: %s\n' "$*" >&2 - failures=$((failures + 1)) -} - -# Sourcing must not run the registration; the guard makes that safe. -resolve() { - # shellcheck disable=SC1090 - LASTRADA_RUNNER_ENTRYPOINT_SOURCE_ONLY=1 . "$entrypoint" - read_runner_token -} - -got="$(printf 'tok-from-stdin\n' | (RUNNER_TOKEN= resolve))" -if [ "$got" = "tok-from-stdin" ]; then - note "stdin token is used" -else - fail "stdin token not used; got '${got}'" -fi - -got="$(printf 'tok-from-stdin\n' | (RUNNER_TOKEN=tok-from-env resolve))" -if [ "$got" = "tok-from-stdin" ]; then - note "stdin wins over RUNNER_TOKEN" -else - fail "stdin did not win over the environment; got '${got}'" -fi - -got="$(printf '' | (RUNNER_TOKEN=tok-from-env resolve))" -if [ "$got" = "tok-from-env" ]; then - note "falls back to RUNNER_TOKEN when stdin is empty" -else - fail "no fallback to RUNNER_TOKEN; got '${got}'" -fi - -got="$(printf '' | (RUNNER_TOKEN= resolve))" -if [ -z "$got" ]; then - note "yields empty when neither source has a token" -else - fail "invented a token from nowhere: '${got}'" -fi - -# ── the registration itself must be org-scoped and group-aware ─────────────── -# These assert against the actual config.sh argument line, not just that the -# variable name appears somewhere in the file -- a hardcoded --url value with -# the RUNNER_SCOPE_URL comment/default left untouched must fail here. -if grep -Eq '^[[:space:]]*--url[[:space:]]+"\$\{RUNNER_SCOPE_URL\}"[[:space:]]*\\?[[:space:]]*$' "$entrypoint"; then - note "config.sh's --url argument is \"\${RUNNER_SCOPE_URL}\"" -else - fail "config.sh's --url argument is not literally \"\${RUNNER_SCOPE_URL}\"" -fi - -if grep -Eq '^[[:space:]]*--runnergroup[[:space:]]+"\$\{RUNNER_GROUP\}"[[:space:]]*\\?[[:space:]]*$' "$entrypoint"; then - note "config.sh's --runnergroup argument is \"\${RUNNER_GROUP}\"" -else - fail "config.sh's --runnergroup argument is not literally \"\${RUNNER_GROUP}\"" -fi - -if grep -Eq '^[[:space:]]*--labels[[:space:]]+"\$\{RUNNER_LABELS\}"[[:space:]]*\\?[[:space:]]*$' "$entrypoint"; then - note "config.sh's --labels argument is \"\${RUNNER_LABELS}\"" -else - fail "config.sh's --labels argument is not literally \"\${RUNNER_LABELS}\"" -fi - -# The start-time sccache wipe belongs in the per-job hook, not here. Match -# case-insensitively with no fixed wording so quoting/rm-flag/whitespace -# reformatting of a reintroduced wipe can't slip past this check. -if grep -qi 'sccache' "$entrypoint"; then - fail "entrypoint.sh still mentions sccache; the wipe belongs in the job hook" -else - note "start-time sccache wipe removed" -fi - -# ── labels must be the agreed set, and the retired name must be fully gone ── -if grep -qF 'RUNNER_LABELS="${RUNNER_LABELS:-self-hosted,Linux,X64,lastrada-docker}"' "$entrypoint"; then - note "RUNNER_LABELS defaults to self-hosted,Linux,X64,lastrada-docker" -else - fail "RUNNER_LABELS default is not exactly self-hosted,Linux,X64,lastrada-docker" -fi - -if grep -qi 'morph-docker' "$entrypoint"; then - fail "entrypoint.sh still mentions the retired morph-docker label" -else - note "morph-docker does not appear in entrypoint.sh" -fi - -# ── the EXIT deregistration trap is owned by exactly one side ──────────────── -# Behavioural, not textual: source entrypoint.sh into a real subshell, point -# it at a stub ./config.sh standing in for the runner binary, call -# install_deregister_trap, and let the subshell actually exit -- then look at -# what the stub observed, not at what the source text says. Under systemd, -# run-runner.sh sets RUNNER_SELF_DEREGISTER=0 and the host's ExecStop -# (deregister-runner.sh) removes the registration instead; standalone -# (`docker run`, no systemd) this trap remains the only mechanism. -trap_scratch="$(mktemp -d)" -trap 'rm -rf "$trap_scratch"' EXIT - -cat >"${trap_scratch}/config.sh" <<'STUB' -#!/usr/bin/env bash -printf 'config.sh called: %s\n' "$*" >>"${TRAP_STUB_LOG}" -STUB -chmod +x "${trap_scratch}/config.sh" - -run_trap_subshell() { - # $1: value to export as RUNNER_SELF_DEREGISTER, or "" to leave it unset. - ( - cd "$trap_scratch" - export TRAP_STUB_LOG="${trap_scratch}/config-calls.log" - if [ -n "$1" ]; then - export RUNNER_SELF_DEREGISTER="$1" - else - unset RUNNER_SELF_DEREGISTER 2>/dev/null || true - fi - # shellcheck disable=SC1090 - LASTRADA_RUNNER_ENTRYPOINT_SOURCE_ONLY=1 . "$entrypoint" - runner_token="tok-for-trap-test" - install_deregister_trap - ) -} - -: >"${trap_scratch}/config-calls.log" -run_trap_subshell "0" -if [ -s "${trap_scratch}/config-calls.log" ]; then - fail "cleanup ran ./config.sh remove even though RUNNER_SELF_DEREGISTER=0: $(cat "${trap_scratch}/config-calls.log")" -else - note "trap is skipped when RUNNER_SELF_DEREGISTER=0" -fi - -: >"${trap_scratch}/config-calls.log" -run_trap_subshell "" -if grep -q 'remove' "${trap_scratch}/config-calls.log"; then - note "trap is installed and runs ./config.sh remove when RUNNER_SELF_DEREGISTER is unset" -else - fail "trap did not run ./config.sh remove when RUNNER_SELF_DEREGISTER is unset" -fi - -if [ "$failures" -ne 0 ]; then - printf '\n%d check(s) failed\n' "$failures" >&2 - exit 1 -fi -printf '\nall entrypoint token-resolution checks passed\n' diff --git a/scripts/test_runner_job_hook.sh b/scripts/test_runner_job_hook.sh deleted file mode 100644 index b8cc77c04..000000000 --- a/scripts/test_runner_job_hook.sh +++ /dev/null @@ -1,194 +0,0 @@ -#!/usr/bin/env bash -# Usage: bash scripts/test_runner_job_hook.sh -# -# Self-test for .github/self-hosted-runner/job-started-hook.sh. -# -# CompileCache.cmake auto-installs pace-cc only when NONE of -# pace-cc/sccache/ccache is already on PATH. Now that one container -# serves morph, Pace and Lightweight, a previous job can leave a -# compile-cache binary behind -- hendrikmuhs/ccache-action apt-installs -# ccache; Pace's own jobs install sccache -- and silently cost the next -# job its connection to the host pace-kv daemon. The loss is invisible: -# the build still succeeds, just uncached. -# -# The asymmetry is the subtle part and is asserted in both directions: -# sccache and ccache must go, pace-cc must STAY. Removing pace-cc -# would force a fresh download on every single job. -# -# A second asymmetry cuts across the first: sccache is an unpackaged tarball -# download, but ccache-action apt-installs ccache, so `rm -f`-ing it leaves -# dpkg believing the package is still present -- the next job's -# `apt-get install ccache` becomes a no-op, and the binary never comes back. -# The hook checks ownership with `dpkg -S` and removes owned tools with -# `apt-get remove` instead of `rm`. LASTRADA_RUNNER_DPKG/LASTRADA_RUNNER_APT -# swap in stub binaries below so this is exercised without root or a real -# package manager, the same way LASTRADA_RUNNER_GH/DOCKER stub run-runner.sh. -set -euo pipefail - -readonly repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -readonly hook="${repo_root}/.github/self-hosted-runner/job-started-hook.sh" - -failures=0 -note() { printf 'ok: %s\n' "$*"; } -fail() { - printf 'error: %s\n' "$*" >&2 - failures=$((failures + 1)) -} - -scratch="$(mktemp -d)" -trap 'rm -rf "$scratch"' EXIT -mkdir -p "${scratch}/bin_a" "${scratch}/bin_b" - -for f in "${scratch}/bin_a/sccache" "${scratch}/bin_a/ccache" \ - "${scratch}/bin_a/pace-cc" "${scratch}/bin_b/ccache"; do - printf '#!/bin/sh\nexit 0\n' >"$f" - chmod +x "$f" -done - -LASTRADA_RUNNER_HOOK_DIRS="${scratch}/bin_a ${scratch}/bin_b" bash "$hook" >/dev/null - -for gone in "${scratch}/bin_a/sccache" "${scratch}/bin_a/ccache" \ - "${scratch}/bin_b/ccache"; do - if [ -e "$gone" ]; then - fail "$(basename "$gone") survived in $(dirname "$gone")" - else - note "removed $(basename "$gone") from $(basename "$(dirname "$gone")")" - fi -done - -if [ -e "${scratch}/bin_a/pace-cc" ]; then - note "pace-cc left in place" -else - fail "pace-cc was removed; every job would re-download it" -fi - -# A directory that does not exist must not fail the job before it starts. -if LASTRADA_RUNNER_HOOK_DIRS="${scratch}/absent" bash "$hook" >/dev/null 2>&1; then - note "a missing directory is tolerated" -else - fail "a missing directory made the hook fail, which would fail the job" -fi - -# Running twice must be a no-op, not an error. -if LASTRADA_RUNNER_HOOK_DIRS="${scratch}/bin_a ${scratch}/bin_b" \ - bash "$hook" >/dev/null 2>&1; then - note "re-running on an already-clean tree succeeds" -else - fail "the hook is not idempotent" -fi - -# ── package-owned tools go through apt-get, not rm ────────────────────────── -# dpkg stub: ccache is owned by a package, sccache is not (mirroring reality: -# sccache is never apt-installed). apt stub: records its argv instead of -# touching anything, so a surviving file proves rm was never used on it. -pkg_scratch="${scratch}/pkg" -mkdir -p "${pkg_scratch}/bin" -for f in ccache sccache pace-cc; do - printf '#!/bin/sh\nexit 0\n' >"${pkg_scratch}/bin/${f}" - chmod +x "${pkg_scratch}/bin/${f}" -done - -cat >"${pkg_scratch}/dpkg" <<'DPKG' -#!/bin/sh -# args: -S -case "$2" in - */ccache) echo "ccache-stub-pkg: $2"; exit 0 ;; - *) exit 1 ;; -esac -DPKG -chmod +x "${pkg_scratch}/dpkg" - -apt_log="${pkg_scratch}/apt.log" -cat >"${pkg_scratch}/apt" <>"${apt_log}" -exit 0 -APT -chmod +x "${pkg_scratch}/apt" - -LASTRADA_RUNNER_HOOK_DIRS="${pkg_scratch}/bin" \ -LASTRADA_RUNNER_DPKG="${pkg_scratch}/dpkg" \ -LASTRADA_RUNNER_APT="${pkg_scratch}/apt" \ -bash "$hook" >/dev/null - -if [ -e "${pkg_scratch}/bin/ccache" ]; then - note "package-owned ccache was left for apt-get, not rm'd" -else - fail "package-owned ccache was deleted with rm; dpkg would still think it is installed" -fi - -if [ -e "$apt_log" ] && grep -q -- '-qq ccache-stub-pkg' "$apt_log"; then - note "apt-get remove was invoked for the package owning ccache" -else - fail "apt-get remove was not invoked for the package owning ccache" -fi - -if [ -e "${pkg_scratch}/bin/sccache" ]; then - fail "unowned sccache survived; it should still be rm'd" -else - note "unowned sccache was removed with rm" -fi - -if [ -e "${pkg_scratch}/bin/pace-cc" ]; then - note "pace-cc untouched on the package-aware path too" -else - fail "pace-cc was removed on the package-aware path" -fi - -# ── a failing dpkg must not fail the job ──────────────────────────────────── -# No package information means "treat as unowned", not "abort the job": the -# tool still gets rm'd. -dpkg_err_scratch="${scratch}/dpkg_errors" -mkdir -p "${dpkg_err_scratch}/bin" -printf '#!/bin/sh\nexit 0\n' >"${dpkg_err_scratch}/bin/ccache" -chmod +x "${dpkg_err_scratch}/bin/ccache" -cat >"${dpkg_err_scratch}/dpkg" <<'DPKG' -#!/bin/sh -echo "dpkg: stub failure" >&2 -exit 2 -DPKG -chmod +x "${dpkg_err_scratch}/dpkg" - -if LASTRADA_RUNNER_HOOK_DIRS="${dpkg_err_scratch}/bin" \ - LASTRADA_RUNNER_DPKG="${dpkg_err_scratch}/dpkg" \ - bash "$hook" >/dev/null 2>&1; then - note "a failing dpkg does not fail the hook" -else - fail "a failing dpkg made the hook fail, which would fail the job" -fi - -# ── a failing apt-get must not fail the job ───────────────────────────────── -apt_err_scratch="${scratch}/apt_errors" -mkdir -p "${apt_err_scratch}/bin" -printf '#!/bin/sh\nexit 0\n' >"${apt_err_scratch}/bin/ccache" -chmod +x "${apt_err_scratch}/bin/ccache" -cat >"${apt_err_scratch}/dpkg" <<'DPKG' -#!/bin/sh -echo "ccache-stub-pkg: $2" -exit 0 -DPKG -chmod +x "${apt_err_scratch}/dpkg" -cat >"${apt_err_scratch}/apt" <<'APT' -#!/bin/sh -echo "apt: stub failure" >&2 -exit 1 -APT -chmod +x "${apt_err_scratch}/apt" - -# The hook's apt-get fallback tries sudo, which can't succeed unattended -# here; timeout guards against any environment where that unexpectedly blocks -# instead of failing fast. -if timeout 15 env LASTRADA_RUNNER_HOOK_DIRS="${apt_err_scratch}/bin" \ - LASTRADA_RUNNER_DPKG="${apt_err_scratch}/dpkg" \ - LASTRADA_RUNNER_APT="${apt_err_scratch}/apt" \ - bash "$hook" >/dev/null 2>&1; then - note "a failing apt-get does not fail the hook" -else - fail "a failing apt-get made the hook fail, which would fail the job" -fi - -if [ "$failures" -ne 0 ]; then - printf '\n%d check(s) failed\n' "$failures" >&2 - exit 1 -fi -printf '\nall job-hook checks passed\n' diff --git a/scripts/test_runner_units.sh b/scripts/test_runner_units.sh deleted file mode 100755 index f71a31c99..000000000 --- a/scripts/test_runner_units.sh +++ /dev/null @@ -1,472 +0,0 @@ -#!/usr/bin/env bash -# Usage: bash scripts/test_runner_units.sh -# -# Self-test for .github/self-hosted-runner/install-runner-units.sh and the -# unit template it renders. -# -# The unit is the whole supervision story, and two of its directives are the -# difference between a visible failure and the six-day silent outage this -# change exists to prevent: -# -# StartLimitBurst/StartLimitIntervalSec must land in [Unit], not [Service]. -# systemd moved them in v229 and silently ignores them in the wrong -# section -- the unit would then retry forever exactly like the Docker -# restart policy it replaces, and nothing would ever show as failed. -# -# Restart=always is what brings a runner back after an OOM kill without -# waiting for a reboot. -# -# Neither is observable without rendering the unit, so it is rendered into a -# scratch prefix and inspected, then handed to `systemd-analyze verify`. -# -# Also covers deregister-runner.sh, since it is installed by -# install-runner-units.sh and wired in by ExecStop=-@LIBEXEC@/deregister-runner.sh -# %i in the unit template: that its path is installed and its ExecStop= -# actually renders with the substituted path, and that its own GitHub -# id-resolution logic (against a stub gh) picks the right id, deletes -# nothing for an absent name, and never fails the stop even when gh does. -set -euo pipefail - -readonly repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -readonly installer="${repo_root}/.github/self-hosted-runner/install-runner-units.sh" - -failures=0 -note() { printf 'ok: %s\n' "$*"; } -fail() { - printf 'error: %s\n' "$*" >&2 - failures=$((failures + 1)) -} - -scratch="$(mktemp -d)" -trap 'rm -rf "$scratch"' EXIT - -LASTRADA_RUNNER_PREFIX_DIR="$scratch" LASTRADA_RUNNER_NO_SYSTEMCTL=1 \ - bash "$installer" >/dev/null - -unit="$(find "$scratch" -name 'lastrada-runner@.service' -print -quit)" -if [ -z "$unit" ]; then - fail "no lastrada-runner@.service was rendered" - printf '\n%d check(s) failed\n' "$failures" >&2 - exit 1 -fi -note "unit rendered at ${unit#"$scratch"/}" - -if grep -q '@[A-Z]*@' "$unit"; then - fail "unsubstituted placeholders remain: $(grep -o '@[A-Z]*@' "$unit" | sort -u | tr '\n' ' ')" -else - note "all placeholders substituted" -fi - -# StartLimit* must be in [Unit]; systemd ignores them in [Service]. Track -# both directives independently -- a mutation that moves only one of the two -# must still be caught. -section="" -start_limit_burst_section="" -start_limit_interval_section="" -while IFS= read -r line; do - case "$line" in - \[*\]) section="$line" ;; - StartLimitBurst=*) start_limit_burst_section="$section" ;; - StartLimitIntervalSec=*) start_limit_interval_section="$section" ;; - esac -done <"$unit" - -if [ "$start_limit_burst_section" = "[Unit]" ]; then - note "StartLimitBurst is in [Unit]" -else - fail "StartLimitBurst is in '${start_limit_burst_section:-nowhere}', must be [Unit] or systemd ignores it" -fi - -if [ "$start_limit_interval_section" = "[Unit]" ]; then - note "StartLimitIntervalSec is in [Unit]" -else - fail "StartLimitIntervalSec is in '${start_limit_interval_section:-nowhere}', must be [Unit] or systemd ignores it" -fi - -for directive in 'Restart=always' 'StartLimitBurst=12' 'StartLimitIntervalSec=900'; do - if grep -qxF "$directive" "$unit"; then - note "${directive} present" - else - fail "${directive} missing" - fi -done - -if grep -q 'ExecStart=.*run-runner.sh %i' "$unit"; then - note "ExecStart calls run-runner.sh with the instance index" -else - fail "ExecStart does not call run-runner.sh %i" -fi - -config="$(find "$scratch" -name config -print -quit)" -if [ -n "$config" ] && grep -q '^RUNNER_CPUS=2$' "$config"; then - note "config written with RUNNER_CPUS=2" -else - fail "config missing or RUNNER_CPUS is not 2" -fi - -if [ -n "$config" ] && grep -q 'morph-docker' "$config"; then - fail "the retired morph-docker name/label is in the config" -else - note "config carries no morph-docker name or label" -fi - -wrapper="$(find "$scratch" -name run-runner.sh -print -quit)" -if [ -n "$wrapper" ] && [ -x "$wrapper" ]; then - note "wrapper installed and executable" -else - fail "wrapper not installed or not executable" -fi - -deregister_wrapper="$(find "$scratch" -name deregister-runner.sh -print -quit)" -if [ -n "$deregister_wrapper" ] && [ -x "$deregister_wrapper" ]; then - note "deregister-runner.sh installed and executable" -else - fail "deregister-runner.sh not installed or not executable" -fi - -# ExecStop must render with the actual substituted @LIBEXEC@ path, not just -# be free of leftover @...@ markers in general (the generic placeholder scan -# above would not catch a forgotten ExecStop= line entirely, since a missing -# line leaves no placeholder behind to find). -if [ -n "$deregister_wrapper" ] && grep -qxF "ExecStop=-${deregister_wrapper} %i" "$unit"; then - note "ExecStop renders with the substituted deregister-runner.sh path" -else - fail "ExecStop missing or not correctly substituted (expected 'ExecStop=-${deregister_wrapper} %i')" -fi - -# systemd's own opinion of the rendered unit. -if command -v systemd-analyze >/dev/null 2>&1; then - staging="${scratch}/verify" - mkdir -p "$staging" - # Instantiate %i rather than verifying the template itself: systemd-analyze - # cannot resolve %i in a bare foo@.service path, and would fail for that - # reason rather than for any defect in the unit. - sed 's/%i/1/g' "$unit" >"${staging}/lastrada-runner-verify.service" - # Exit status alone does not gate this: a directive in the wrong section - # (e.g. StartLimitIntervalSec under [Service]) makes systemd-analyze print - # "Unknown key ... ignoring." to stderr and still exit 0. So the *output* - # is the signal, checked regardless of exit status -- and the one kind of - # noise this scratch prefix legitimately produces (ExecStart pointing at - # a wrapper that was not actually installed there) is carved out by - # matching only that specific message, so an "Unknown key" line -- or - # anything else systemd-analyze complains about -- is never swallowed by - # the carve-out. - out="$(systemd-analyze verify "${staging}/lastrada-runner-verify.service" 2>&1)" || true - unexpected="$(printf '%s\n' "$out" | grep -v 'Command .* is not executable' || true)" - if [ -n "$unexpected" ]; then - fail "systemd-analyze verify complained about the unit:" - printf '%s\n' "$unexpected" >&2 - else - note "systemd-analyze verify clean apart from the scratch ExecStart path" - fi -else - note "systemd-analyze absent; skipping unit verification" -fi - -# The systemctl-driving code -- daemon-reload, the shrink loop, `enable --now` -# -- is never reached above: that run always sets LASTRADA_RUNNER_NO_SYSTEMCTL, -# which returns before any of it. Exercise it here against a stub systemctl -# placed first on PATH that only logs its argv and exits 0. This is the only -# systemctl the installer can reach in this invocation, so nothing here can -# touch the real system. -# -# Crucially, `list-unit-files 'lastrada-runner@*.service'` is NOT how the -# installer finds existing instances (see install-runner-units.sh for why: -# for a template unit, that command only ever shows the template itself, -# never the enabled instances). So the stub must not emit fabricated -# per-instance list-unit-files rows -- the real systemctl never does. It -# instead prints the *template's* row, exactly as verified live: -# -# $ systemctl --user list-unit-files 'lastrada-runner@*.service' --no-legend --plain -# lastrada-runner@.service indirect enabled -# -# The real fleet state instead lives as enablement symlinks under -# /.wants/. So this test represents "a previously larger -# fleet" the same way: it pre-creates those symlinks in the scratch prefix -# before running the installer. -stub_bin="$(mktemp -d)" -scratch2="$(mktemp -d)" -trap 'rm -rf "$scratch" "$stub_bin" "$scratch2"' EXIT - -systemctl_log="${stub_bin}/systemctl.log" -: >"$systemctl_log" -cat >"${stub_bin}/systemctl" <>"${systemctl_log}" -args=("\$@") -if [ "\${args[0]:-}" = "--user" ]; then - args=("\${args[@]:1}") -fi -if [ "\${args[0]:-}" = "list-unit-files" ]; then - # This is what the real systemctl prints for a templated unit: only the - # template's own row, never per-instance rows. If the installer were - # still (mis)using this command to find instances to disable, it would - # see nothing here and the shrink assertions below would fail. - printf 'lastrada-runner@.service indirect enabled\n' -fi -exit 0 -STUBEOF -chmod +x "${stub_bin}/systemctl" - -# Pre-seed enablement symlinks representing a previously larger fleet: -# instances 1..5 within the config.example default RUNNER_COUNT=5 (must be -# left alone), plus 6 and 7 beyond it (must be disabled). These live under -# /.wants/, which for a non-root run under -# LASTRADA_RUNNER_PREFIX_DIR is -# "${scratch2}${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user/default.target.wants". -wants_dir="${scratch2}${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user/default.target.wants" -mkdir -p "$wants_dir" -for i in 1 2 3 4 5 6 7; do - ln -s "../lastrada-runner@.service" "${wants_dir}/lastrada-runner@${i}.service" -done - -if ! PATH="${stub_bin}:${PATH}" LASTRADA_RUNNER_PREFIX_DIR="$scratch2" \ - bash "$installer" >/dev/null 2>"${stub_bin}/installer.stderr"; then - fail "installer exited non-zero against the stubbed systemctl:" - cat "${stub_bin}/installer.stderr" >&2 -fi - -# The stub logs "--user daemon-reload" for a non-root run and plain -# "daemon-reload" for a root one; normalize away the leading --user so the -# assertions below do not care which mode ran. -normalized_log="${stub_bin}/systemctl.normalized.log" -sed -e 's/^--user //' "$systemctl_log" >"$normalized_log" - -if grep -qxF 'daemon-reload' "$normalized_log"; then - note "daemon-reload was called" -else - fail "daemon-reload was not called" -fi - -enable_missing=0 -for i in $(seq 1 5); do - if ! grep -qxF "enable --now lastrada-runner@${i}.service" "$normalized_log"; then - enable_missing=1 - fail "enable --now lastrada-runner@${i}.service was not called" - fi -done -if [ "$enable_missing" -eq 0 ]; then - note "enable --now called for lastrada-runner@1..5" -fi - -shrink_missing=0 -for i in 6 7; do - if ! grep -qxF "disable --now lastrada-runner@${i}.service" "$normalized_log"; then - shrink_missing=1 - fail "disable --now lastrada-runner@${i}.service (beyond RUNNER_COUNT) was not called" - fi -done -if [ "$shrink_missing" -eq 0 ]; then - note "disable --now called for the instances beyond RUNNER_COUNT (6, 7)" -fi - -in_range_touched=0 -for i in 1 2 3 4 5; do - if grep -qxF "disable --now lastrada-runner@${i}.service" "$normalized_log"; then - in_range_touched=1 - fail "disable --now was called for lastrada-runner@${i}.service, which is within RUNNER_COUNT" - fi -done -if [ "$in_range_touched" -eq 0 ]; then - note "the in-range instances (1..5) were left alone" -fi - -# ── both install modes: user vs. system ────────────────────────────────────── -# Everything above ran the installer as whoever is running this script -- -# normally a non-root developer or a CI job -- so it only ever exercised the -# non-root branch of install-runner-units.sh: ~/.config/systemd/user, -# default.target, `systemctl --user`. bootstrap-cloud-node.sh depends on the -# OTHER branch -- the root/system one taken when `id -u` is 0: /etc/systemd/ -# system, /etc/lastrada-runner, /usr/local/libexec/lastrada-runner, -# multi-user.target, plain `systemctl` with no --user -- and nothing above -# ever rendered or asserted it. A change that silently broke that branch (the -# wrong WantedBy, or system mode reusing a user-mode path) would ship -# unnoticed with every check above still green. -# -# install-runner-units.sh honours LASTRADA_RUNNER_FORCE_SYSTEM=1 precisely so -# this can be exercised without actually running as root: it forces the -# root/system branch regardless of the real uid, defaulting to the ordinary -# UID-based detection when unset (as every check above relied on). - -# First, confirm the render already done at the top of this script (no -# LASTRADA_RUNNER_FORCE_SYSTEM set, run as this non-root user) actually took -# the user-mode branch, not just that *a* unit came out the other end. This -# does not weaken or replace any assertion already made against $unit/$config -# above -- it adds mode-specific checks on the same render. -case "$unit" in - "$scratch"*/systemd/user/lastrada-runner@.service) note "user mode: unit rendered under systemd/user" ;; - *) fail "user mode: unit not rendered under systemd/user (got ${unit})" ;; -esac -case "$config" in - "$scratch"*/lastrada-runner/config) note "user mode: config rendered under .../lastrada-runner, not /etc" ;; - *) fail "user mode: config not rendered under .../lastrada-runner (got ${config})" ;; -esac -case "$wrapper" in - "$scratch"*/lastrada-runner/run-runner.sh) note "user mode: wrapper rendered under a user data dir, not /usr/local/libexec" ;; - *) fail "user mode: wrapper not rendered under a .../lastrada-runner data dir, or wrongly under /usr/local/libexec (got ${wrapper})" ;; -esac -if grep -qxF 'WantedBy=default.target' "$unit"; then - note "user mode: WantedBy=default.target" -else - fail "user mode: WantedBy=default.target missing (got $(grep '^WantedBy=' "$unit" || echo 'nothing'))" -fi - -# Now render the system variant fresh, forced via LASTRADA_RUNNER_FORCE_SYSTEM -# so this does not need to actually run as root, into its own scratch prefix -# so it cannot be confused with the user-mode render above. -system_scratch="$(mktemp -d)" -trap 'rm -rf "$scratch" "$stub_bin" "$scratch2" "$system_scratch"' EXIT - -LASTRADA_RUNNER_PREFIX_DIR="$system_scratch" LASTRADA_RUNNER_NO_SYSTEMCTL=1 \ - LASTRADA_RUNNER_FORCE_SYSTEM=1 \ - bash "$installer" >/dev/null - -system_unit="$(find "$system_scratch" -name 'lastrada-runner@.service' -print -quit)" -if [ -z "$system_unit" ]; then - fail "system mode: no lastrada-runner@.service was rendered" -else - case "$system_unit" in - "${system_scratch}/etc/systemd/system/lastrada-runner@.service") note "system mode: unit rendered under /etc/systemd/system" ;; - *) fail "system mode: unit not rendered under /etc/systemd/system (got ${system_unit})" ;; - esac - if grep -qxF 'WantedBy=multi-user.target' "$system_unit"; then - note "system mode: WantedBy=multi-user.target" - else - fail "system mode: WantedBy=multi-user.target missing (got $(grep '^WantedBy=' "$system_unit" || echo 'nothing'))" - fi -fi - -system_config="$(find "$system_scratch" -name config -print -quit)" -case "$system_config" in - "${system_scratch}/etc/lastrada-runner/config") note "system mode: config rendered under /etc/lastrada-runner" ;; - *) fail "system mode: config not rendered under /etc/lastrada-runner (got ${system_config:-nothing})" ;; -esac - -system_wrapper="$(find "$system_scratch" -name run-runner.sh -print -quit)" -case "$system_wrapper" in - "${system_scratch}/usr/local/libexec/lastrada-runner/run-runner.sh") - if [ -x "$system_wrapper" ]; then - note "system mode: wrapper rendered under /usr/local/libexec/lastrada-runner" - else - fail "system mode: wrapper at the expected path is not executable (${system_wrapper})" - fi - ;; - *) fail "system mode: wrapper not rendered under /usr/local/libexec/lastrada-runner (got ${system_wrapper:-nothing})" ;; -esac - -# Finally, confirm the systemctl invocation itself differs between the two -# modes: user mode drives `systemctl --user ...`, system mode drives plain -# `systemctl ...`. Re-exercise system mode against a stub systemctl on PATH -# (the only "systemctl" this invocation can reach), mirroring the user-mode -# exercise above -- that one's normalized log already proves user mode's raw -# invocations carried a leading "--user" (stripped before its assertions by -# `sed -e 's/^--user //'`); this proves system mode's raw invocations do not. -system_stub_bin="$(mktemp -d)" -system_stub_scratch="$(mktemp -d)" -trap 'rm -rf "$scratch" "$stub_bin" "$scratch2" "$system_scratch" "$system_stub_bin" "$system_stub_scratch"' EXIT - -system_systemctl_log="${system_stub_bin}/systemctl.log" -: >"$system_systemctl_log" -cat >"${system_stub_bin}/systemctl" <>"${system_systemctl_log}" -if [ "\${1:-}" = "list-unit-files" ]; then - printf 'lastrada-runner@.service indirect enabled\n' -fi -exit 0 -STUBEOF -chmod +x "${system_stub_bin}/systemctl" - -if ! PATH="${system_stub_bin}:${PATH}" LASTRADA_RUNNER_PREFIX_DIR="$system_stub_scratch" \ - LASTRADA_RUNNER_FORCE_SYSTEM=1 \ - bash "$installer" >/dev/null 2>"${system_stub_bin}/installer.stderr"; then - fail "installer exited non-zero in forced-system mode against the stubbed systemctl:" - cat "${system_stub_bin}/installer.stderr" >&2 -fi - -if grep -qxF 'daemon-reload' "$system_systemctl_log"; then - note "system mode: systemctl invoked as plain 'systemctl' (no --user)" -else - fail "system mode: expected a plain 'daemon-reload' call (no --user) in the systemctl log: $(cat "$system_systemctl_log")" -fi -if grep -q -- '--user' "$system_systemctl_log"; then - fail "system mode: systemctl was invoked with --user, which is the user-mode invocation, not system" -else - note "system mode: no --user ever appeared in the systemctl invocations" -fi -if grep -qxF -- '--user daemon-reload' "$systemctl_log"; then - note "user mode: systemctl invoked as 'systemctl --user' (raw log carried --user)" -else - fail "user mode: expected the raw systemctl log to carry a leading --user (got: $(cat "$systemctl_log"))" -fi - -# ── deregister-runner.sh: GitHub id resolution ─────────────────────────────── -# ExecStop above runs deregister-runner.sh; exercise its id-resolution logic -# against a stub gh, the same way scripts/test_run_runner.sh exercises -# run-runner.sh's token minting. Reuses the config install-runner-units.sh -# wrote earlier in this script (GITHUB_ORG=LASTRADA-Software, -# RUNNER_NAME_PREFIX=lastrada-docker), so index 3 resolves to the name -# "lastrada-docker-3". -readonly deregister="${repo_root}/.github/self-hosted-runner/deregister-runner.sh" - -dereg_scratch="$(mktemp -d)" -trap 'rm -rf "$scratch" "$stub_bin" "$scratch2" "$system_scratch" "$system_stub_bin" "$system_stub_scratch" "$dereg_scratch"' EXIT - -cat >"${dereg_scratch}/gh" <<'STUB' -#!/usr/bin/env bash -printf '%s\n' "$*" >>"${DEREG_GH_LOG}" -if [ "${DEREG_GH_FAIL:-}" = "1" ]; then - exit 1 -fi -if [ "$1" = "api" ] && [ "${3:-}" = "--jq" ]; then - if [ -n "${DEREG_RUNNER_NAME:-}" ] && printf '%s\n' "$4" | grep -qF "\"${DEREG_RUNNER_NAME}\""; then - printf '%s\n' "${DEREG_RUNNER_ID:-9001}" - fi -fi -exit 0 -STUB -chmod +x "${dereg_scratch}/gh" - -export DEREG_GH_LOG="${dereg_scratch}/gh.log" - -# Resolves the right id for an existing name. -: >"$DEREG_GH_LOG" -out="$(DEREG_RUNNER_NAME=lastrada-docker-3 DEREG_RUNNER_ID=9001 \ - LASTRADA_RUNNER_CONFIG="$config" LASTRADA_RUNNER_GH="${dereg_scratch}/gh" \ - LASTRADA_RUNNER_DRY_RUN=1 \ - bash "$deregister" 3 2>&1)" && rc=0 || rc=$? -if [ "$rc" -eq 0 ] && printf '%s\n' "$out" | grep -q '9001'; then - note "deregister-runner.sh resolves the id of an existing runner" -else - fail "deregister-runner.sh did not resolve id 9001 for lastrada-docker-3 (exit ${rc}); got: ${out}" -fi - -# Exits 0 and deletes nothing when the name is absent. -: >"$DEREG_GH_LOG" -out="$(DEREG_RUNNER_NAME=some-other-runner DEREG_RUNNER_ID=9002 \ - LASTRADA_RUNNER_CONFIG="$config" LASTRADA_RUNNER_GH="${dereg_scratch}/gh" \ - bash "$deregister" 3 2>&1)" && rc=0 || rc=$? -if [ "$rc" -ne 0 ]; then - fail "deregister-runner.sh exited ${rc} for an absent runner, must exit 0" -elif grep -q -- '-X DELETE' "$DEREG_GH_LOG"; then - fail "deregister-runner.sh issued a DELETE for a runner that was never resolved: $(cat "$DEREG_GH_LOG")" -else - note "deregister-runner.sh exits 0 and deletes nothing when the name is absent" -fi - -# Exits 0 even when gh fails outright. -: >"$DEREG_GH_LOG" -out="$(DEREG_GH_FAIL=1 \ - LASTRADA_RUNNER_CONFIG="$config" LASTRADA_RUNNER_GH="${dereg_scratch}/gh" \ - bash "$deregister" 3 2>&1)" && rc=0 || rc=$? -if [ "$rc" -eq 0 ]; then - note "deregister-runner.sh exits 0 when gh fails" -else - fail "deregister-runner.sh exited ${rc} when gh failed, must exit 0" -fi - -if [ "$failures" -ne 0 ]; then - printf '\n%d check(s) failed\n' "$failures" >&2 - exit 1 -fi -printf '\nall unit-installation checks passed\n' From 7c27ddbfd7dcb3494de7285c70d06569371e9c95 Mon Sep 17 00:00:00 2001 From: Yaraslau Tamashevich Date: Sat, 28 Nov 2026 17:18:39 +0100 Subject: [PATCH 2/8] ci: check a rewritten push's changed lines against its parent clang-tidy-diff diffed a push against github.event.before. After master was rewritten that commit was gone from the history, git diff failed with "bad object" and the job exited 128 without checking anything; the first push of a branch names all zeros and fails the same way. Such a push is now checked against HEAD^. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01No1NzndCGtpCccptcyk6Tb --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 590563e2b..44ad431a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1714,6 +1714,12 @@ jobs: else BASE_SHA="${{ github.event.before }}" fi + # A push that rewrote the branch names a `before` that is no longer in its history, and the first push of a + # branch names all zeros; neither can be diffed against, so the push is checked against its parent instead. + if ! git cat-file -e "${BASE_SHA}^{commit}" 2>/dev/null; then + echo "Base ${BASE_SHA} is not in this checkout; checking the push against HEAD^" + BASE_SHA="$(git rev-parse HEAD^)" + fi # The left-hand side of the pipeline below is *expected* to fail: # `find` exits non-zero when one of its two search roots is absent, # and `head -1` closing the pipe SIGPIPEs it. The `-z` test is what From 49defb4006d733479edb406fc36039fa6403d554 Mon Sep 17 00:00:00 2001 From: Yaraslau Tamashevich Date: Sat, 28 Nov 2026 19:24:28 +0100 Subject: [PATCH 3/8] ci: build linux-compilers and linux-sanitizers in the shared CI image Both jobs run Configure, Build and Test inside ghcr.io/lastrada-software/cpp-ci with its seeded pace-cc compile cache (morph/{clang,gcc,sanitizers}.cow), so they start warm instead of compiling from scratch. The compiler install, the sccache setup, stats and upload steps are gone from these two jobs. Configure is retried on a fresh build tree when it comes out with caching disabled, and a pace-cc stats step makes the hit rate visible in the log. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01No1NzndCGtpCccptcyk6Tb --- .github/workflows/ci.yml | 321 ++++++++++++++++++++++++--------------- 1 file changed, 201 insertions(+), 120 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44ad431a2..99d225240 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -208,6 +208,12 @@ jobs: linux-compilers: name: Linux / ${{ matrix.preset }} runs-on: ubuntu-24.04 + # `packages: read` so the job can pull the shared CI image, a private + # package; a job-level block replaces the file's floor, so `contents: read` + # is restated for checkout. + permissions: + contents: read + packages: read strategy: fail-fast: false matrix: @@ -229,70 +235,93 @@ jobs: key: cpm-${{ runner.os }}-${{ hashFiles('cmake/CPM.cmake', '**/CMakeLists.txt') }} restore-keys: cpm-${{ runner.os }}- - - name: Install GCC 15 and ninja - if: startsWith(matrix.preset, 'gcc-') - run: | - sudo apt-get update -q - sudo apt-get install -y software-properties-common - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - sudo apt-get update -q - sudo apt-get install -y gcc-15 g++-15 ninja-build catch2 - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-15 15 - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-15 15 - - - name: Install Clang ${{ env.CLANG_VERSION }} from apt.llvm.org - if: startsWith(matrix.preset, 'clang-') + # Configure, Build and Test run inside the shared CI image, which carries + # clang 22, gcc 14 and 15, ninja, catch2, libsqlite3 and the pace-cc + # launcher with a compile-cache seed warmed from master. It is a + # `docker run`, not a job `container:`, so the cache restore and the other + # host actions stay on the host; the workspace is mounted at its host path, + # which is also the path the seed was warmed at, so the seeded compile + # commands match. It runs as the runner's own user so the checkout stays + # the runner's, and `--init` reaps orphaned children. + # + # A local pace-kv serves a copy of the seed store for this leg's group, so + # the image's store is not modified. The container has its own network + # namespace, so its 127.0.0.1:6674 is private. Configure finds pace-cc on + # PATH and pace-kv at its default address. The probe waits until a compile + # is served, because the configure-time check gives the daemon 2 s and a + # seed this size can take longer than that to open. + - name: Start the shared CI image and its seeded compile cache + env: + IMAGE: ghcr.io/lastrada-software/cpp-ci:latest + SEED: ${{ startsWith(matrix.preset, 'gcc-') && 'gcc' || 'clang' }} + GHCR_TOKEN: ${{ github.token }} run: | - sudo apt-get update -q - sudo apt-get install -y ninja-build catch2 - # Download, check, then execute -- not - # `wget -qO- https://apt.llvm.org/llvm.sh | sudo bash`. - # `wget -q` writes no error document, so on an HTTP 4xx/5xx it exits - # 8 having written zero bytes. `bash` then reads an empty script, - # does nothing, and exits 0 -- and GitHub runs `run:` under `bash -e` - # without pipefail, so the pipeline's status is bash's, not wget's. - # That step reports success having installed no compiler, and the leg - # goes red several steps later at Configure, naming a missing - # compiler rather than the download that never happened. - # - # Measured against apt.llvm.org itself, on a path that 404s: - # - # $ curl -sSL -o llvm.sh https://apt.llvm.org/does-not-exist.sh - # exit=0 564 bytes of error page - # $ curl -sSL --fail -o llvm.sh https://apt.llvm.org/does-not-exist.sh - # curl: (22) The requested URL returned error: 404 - # exit=22 - # - # Same three lines as the sccache-setup action's install step, so the - # repository has one download idiom rather than two: `--fail` so the - # download reports its own failure, a file so nothing downstream runs - # when it does, and `test -s` for the 200-with-empty-body case that - # `--fail` cannot see. This is not a retry policy and it does not make - # an apt.llvm.org outage less likely -- it makes the step that failed - # be the step the log names. - curl -sSL --fail -o /tmp/llvm.sh https://apt.llvm.org/llvm.sh - test -s /tmp/llvm.sh - sudo bash /tmp/llvm.sh ${{ env.CLANG_VERSION }} - - - name: Set up sccache - uses: ./.github/actions/sccache-setup - - # No -DCMAKE_..._COMPILER_LAUNCHER=sccache here on purpose: leaving the - # launcher unset lets cmake/CompileCache.cmake's own auto-detection run, - # which prefers pace-cc when a daemon answers and otherwise picks the - # sccache set up above. Setting the launcher explicitly, as every other - # Linux job does, would make CompileCache.cmake bail out before it ever - # probes for pace-cc (see that file's own comment). - - name: Configure (gcc) - if: startsWith(matrix.preset, 'gcc-') - run: cmake --preset ${{ matrix.preset }} - - - name: Configure (clang) - if: startsWith(matrix.preset, 'clang-') + set -euo pipefail + printf '%s' "$GHCR_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin + if ! docker pull --quiet "$IMAGE"; then + echo "::error title=shared CI image::cannot pull ${IMAGE}. It is a private package: its 'Manage Actions access' must list this repository, and a pull request from a fork cannot read it." + exit 1 + fi + docker run -d --init --name ci-image \ + --user "$(id -u):$(id -g)" -e HOME=/tmp/home \ + -v "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" -w "$GITHUB_WORKSPACE" \ + "$IMAGE" sleep infinity + docker exec ci-image bash -euo pipefail -c ' + mkdir -p "$HOME" + cp "$PACE_CACHE_SEED_DIR/morph/'"$SEED"'.cow" /tmp/seed.cow + ls -l /tmp/seed.cow + gcc --version | head -n1 + clang++-22 --version | head -n1' + docker exec -d ci-image bash -c \ + 'pace-kv --bind=127.0.0.1 --port=6674 --storage=/tmp/seed.cow --storage-shards=1 --log-level=warn > /tmp/pace-kv.log 2>&1' + docker exec ci-image bash -euo pipefail -c ' + mkdir -p /tmp/probe && cd /tmp/probe + printf "int ciReady() { return 0; }\n" > ready.cpp + for attempt in $(seq 24); do + if PACE_SOURCE_DIR=/tmp/probe PACE_BINARY_DIR=/tmp/probe PACE_VERBOSE=1 \ + PACE_NO_STATS=1 PACE_TIMEOUT=30s timeout 60 \ + pace-cc clang++-22 -c ready.cpp -o ready.o 2> err \ + && grep -qE "pace-cc: (HIT|MISS) key=" err; then + echo "pace-kv is serving (attempt $attempt)"; exit 0 + fi + sleep 5 + done + cat err /tmp/pace-kv.log; exit 1' + # The prefix the steps below run their commands through; the variables + # named here are passed from the step environment into the image. + echo "IN_IMAGE=docker exec -e MORPH_TEST_LOG_LEVEL -e TSAN_OPTIONS ci-image" >> "$GITHUB_ENV" + + # Configure is retried when it comes out with caching off. Its pace-kv + # probe allows 2 s, and a seed store just opened can miss that once after + # the start step's own probe was served: CMake then only reports it and + # the leg would build uncached. Each attempt gets a fresh build tree so + # the retry probes again rather than reading the tree's held answer. + # + # The launcher flags are left unset: setting one makes CompileCache.cmake + # skip pace-cc. The compiler flags are exactly those the seed was warmed + # with, because a differing flag changes every cache key. + - name: Configure + env: + PRESET: ${{ matrix.preset }} run: | - cmake --preset ${{ matrix.preset }} \ - -DCMAKE_C_COMPILER=clang-${{ env.CLANG_VERSION }} \ - -DCMAKE_CXX_COMPILER=clang++-${{ env.CLANG_VERSION }} + set -euo pipefail + case "$PRESET" in + gcc-*) cc=gcc-15; cxx=g++-15 ;; + clang-*) cc=clang-${{ env.CLANG_VERSION }}; cxx=clang++-${{ env.CLANG_VERSION }} ;; + *) echo "::error::no compiler for preset $PRESET"; exit 1 ;; + esac + log="$RUNNER_TEMP/configure.log" + for attempt in 1 2 3; do + ${IN_IMAGE} cmake --preset "$PRESET" \ + -DCMAKE_C_COMPILER="$cc" -DCMAKE_CXX_COMPILER="$cxx" 2>&1 | tee "$log" + if ! grep -q "caching disabled" "$log"; then + exit 0 + fi + echo "::warning::configure attempt $attempt came out with caching disabled; retrying" + rm -rf "build/$PRESET" + sleep 5 + done + echo "::warning::the compile cache stayed disabled; this leg builds uncached" # One compile per CPU, not ninja's default of two more. The heaviest # translation units peak at 2.5-3.4 GB each, so six at once outgrow a @@ -300,7 +329,7 @@ jobs: # communication" rather than a compiler error. Every Linux build step # below passes the same --parallel for the same reason. - name: Build - run: cmake --build --preset ${{ matrix.preset }} --parallel "$(nproc)" + run: ${IN_IMAGE} cmake --build --preset ${{ matrix.preset }} --parallel "$(nproc)" # Release legs run the suite too: these are the only builds with NDEBUG # defined, so code on those paths runs nowhere else. @@ -311,26 +340,24 @@ jobs: # under ASan, ran 56 minutes one at a time. Tests that share a resource # say so with RESOURCE_LOCK (the ladder's database) or RUN_SERIAL. - name: Test - run: ctest --preset ${{ matrix.preset }} --parallel "$(nproc)" + run: ${IN_IMAGE} ctest --preset ${{ matrix.preset }} --parallel "$(nproc)" - # Cumulative hit/miss for this leg. Without it the cache is - # unfalsifiable: a thrashing cache and a working one look identical - # from the outside, and only the build-step duration hints at which - # one you have. `|| true` so a stats failure never fails the job. - - name: sccache stats + # Cumulative hit/miss for this leg, read from inside the image where the + # cache daemon runs. Without it the cache is unfalsifiable: a seed that + # never hits and one that does look identical from the outside. + - name: Report pace-cc effectiveness if: always() - run: sccache --show-stats || true - - - name: Upload the sccache entries this build used - if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') - uses: ./.github/actions/sccache-upload - with: - name: ${{ github.job }}-${{ strategy.job-index }} - + run: ${IN_IMAGE} pace-cc --show-stats || true # ── Linux: sanitizers + coverage (all clang) ───────────────────────── linux-sanitizers: name: Linux / ${{ matrix.preset }} runs-on: ubuntu-24.04 + # `packages: read` so the job can pull the shared CI image, a private + # package; a job-level block replaces the file's floor, so `contents: read` + # is restated for checkout. + permissions: + contents: read + packages: read strategy: fail-fast: false matrix: @@ -348,19 +375,61 @@ jobs: key: cpm-${{ runner.os }}-${{ hashFiles('cmake/CPM.cmake', '**/CMakeLists.txt') }} restore-keys: cpm-${{ runner.os }}- - - name: Install Clang ${{ env.CLANG_VERSION }} from apt.llvm.org + # Configure, Build and Test run inside the shared CI image, which carries + # clang 22, gcc 14 and 15, ninja, catch2, libsqlite3 and the pace-cc + # launcher with a compile-cache seed warmed from master. It is a + # `docker run`, not a job `container:`, so the cache restore and the other + # host actions stay on the host; the workspace is mounted at its host path, + # which is also the path the seed was warmed at, so the seeded compile + # commands match. It runs as the runner's own user so the checkout stays + # the runner's, and `--init` reaps orphaned children. + # + # A local pace-kv serves a copy of the seed store for this leg's group, so + # the image's store is not modified. The container has its own network + # namespace, so its 127.0.0.1:6674 is private. Configure finds pace-cc on + # PATH and pace-kv at its default address. The probe waits until a compile + # is served, because the configure-time check gives the daemon 2 s and a + # seed this size can take longer than that to open. + - name: Start the shared CI image and its seeded compile cache + env: + IMAGE: ghcr.io/lastrada-software/cpp-ci:latest + SEED: sanitizers + GHCR_TOKEN: ${{ github.token }} run: | - sudo apt-get update -q - sudo apt-get install -y ninja-build catch2 libsqlite3-dev - # --fail, a file, and a non-empty check -- never `wget -qO- | sudo - # bash`: see linux-compilers' identical install step for why the piped - # form reports success having installed nothing. - curl -sSL --fail -o /tmp/llvm.sh https://apt.llvm.org/llvm.sh - test -s /tmp/llvm.sh - sudo bash /tmp/llvm.sh ${{ env.CLANG_VERSION }} - - - name: Set up sccache - uses: ./.github/actions/sccache-setup + set -euo pipefail + printf '%s' "$GHCR_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin + if ! docker pull --quiet "$IMAGE"; then + echo "::error title=shared CI image::cannot pull ${IMAGE}. It is a private package: its 'Manage Actions access' must list this repository, and a pull request from a fork cannot read it." + exit 1 + fi + docker run -d --init --name ci-image \ + --user "$(id -u):$(id -g)" -e HOME=/tmp/home \ + -v "$GITHUB_WORKSPACE:$GITHUB_WORKSPACE" -w "$GITHUB_WORKSPACE" \ + "$IMAGE" sleep infinity + docker exec ci-image bash -euo pipefail -c ' + mkdir -p "$HOME" + cp "$PACE_CACHE_SEED_DIR/morph/'"$SEED"'.cow" /tmp/seed.cow + ls -l /tmp/seed.cow + gcc --version | head -n1 + clang++-22 --version | head -n1' + docker exec -d ci-image bash -c \ + 'pace-kv --bind=127.0.0.1 --port=6674 --storage=/tmp/seed.cow --storage-shards=1 --log-level=warn > /tmp/pace-kv.log 2>&1' + docker exec ci-image bash -euo pipefail -c ' + mkdir -p /tmp/probe && cd /tmp/probe + printf "int ciReady() { return 0; }\n" > ready.cpp + for attempt in $(seq 24); do + if PACE_SOURCE_DIR=/tmp/probe PACE_BINARY_DIR=/tmp/probe PACE_VERBOSE=1 \ + PACE_NO_STATS=1 PACE_TIMEOUT=30s timeout 60 \ + pace-cc clang++-22 -c ready.cpp -o ready.o 2> err \ + && grep -qE "pace-cc: (HIT|MISS) key=" err; then + echo "pace-kv is serving (attempt $attempt)"; exit 0 + fi + sleep 5 + done + cat err /tmp/pace-kv.log; exit 1' + # The prefix the steps below run their commands through; the variables + # named here are passed from the step environment into the image. + echo "IN_IMAGE=docker exec -e MORPH_TEST_LOG_LEVEL -e TSAN_OPTIONS ci-image" >> "$GITHUB_ENV" # morph::net and the SQLite offline queue are opt-in, but they are also # where the memory/threading/UB risk actually lives (raw sockets, an I/O @@ -371,17 +440,35 @@ jobs: # morph::tui is built too: its event pump, its posted redraws and its # loop executor are where a terminal application's threading lives. # - # No -DCMAKE_..._COMPILER_LAUNCHER=sccache: see linux-compilers' Configure - # steps for why the launcher is left to CompileCache.cmake. + # Configure is retried when it comes out with caching off. Its pace-kv + # probe allows 2 s, and a seed store just opened can miss that once after + # the start step's own probe was served: CMake then only reports it and + # the leg would build uncached. Each attempt gets a fresh build tree so + # the retry probes again rather than reading the tree's held answer. + # + # The launcher flags are left unset: setting one makes CompileCache.cmake + # skip pace-cc. The compiler flags are exactly those the seed was warmed + # with, because a differing flag changes every cache key. - name: Configure run: | - cmake --preset ${{ matrix.preset }} \ - -DMORPH_LINK_JOBS=1 \ - -DMORPH_BUILD_NET=ON \ - -DMORPH_BUILD_TUI=ON \ - -DMORPH_BUILD_OFFLINE_SQLITE=ON \ - -DCMAKE_C_COMPILER=clang-${{ env.CLANG_VERSION }} \ - -DCMAKE_CXX_COMPILER=clang++-${{ env.CLANG_VERSION }} + set -euo pipefail + log="$RUNNER_TEMP/configure.log" + for attempt in 1 2 3; do + ${IN_IMAGE} cmake --preset ${{ matrix.preset }} \ + -DMORPH_LINK_JOBS=1 \ + -DMORPH_BUILD_NET=ON \ + -DMORPH_BUILD_TUI=ON \ + -DMORPH_BUILD_OFFLINE_SQLITE=ON \ + -DCMAKE_C_COMPILER=clang-${{ env.CLANG_VERSION }} \ + -DCMAKE_CXX_COMPILER=clang++-${{ env.CLANG_VERSION }} 2>&1 | tee "$log" + if ! grep -q "caching disabled" "$log"; then + exit 0 + fi + echo "::warning::configure attempt $attempt came out with caching disabled; retrying" + rm -rf "build/${{ matrix.preset }}" + sleep 5 + done + echo "::warning::the compile cache stayed disabled; this leg builds uncached" # Sanitizer-instrumented compiles and links of the heaviest test files go past the runner's 16 GB and 3 GB of # swap at one job per CPU, and the runner is lost with no compiler error. Extra swap costs nothing unless it @@ -396,7 +483,7 @@ jobs: - name: Build run: | - cmake --build --preset ${{ matrix.preset }} --parallel "$(nproc)" + ${IN_IMAGE} cmake --build --preset ${{ matrix.preset }} --parallel "$(nproc)" free -m grep -E '^(pswpin|pswpout) ' /proc/vmstat @@ -427,7 +514,7 @@ jobs: clang-ubsan) mode=ubsan ;; *) echo "::error::no sanitizer mode for preset ${{ matrix.preset }}"; exit 1 ;; esac - bash scripts/check_sanitizer_instrumentation.sh build/${{ matrix.preset }} "$mode" + ${IN_IMAGE} bash scripts/check_sanitizer_instrumentation.sh build/${{ matrix.preset }} "$mode" - name: Test env: @@ -491,7 +578,7 @@ jobs: if [ "${{ matrix.preset }}" = "clang-asan" ] || [ "${{ matrix.preset }}" = "clang-tsan" ]; then EXCLUDE_ARGS+=(-E "OomInjector|morph#108") fi - ctest --preset ${{ matrix.preset }} --parallel "$(nproc)" "${EXCLUDE_ARGS[@]}" + ${IN_IMAGE} ctest --preset ${{ matrix.preset }} --parallel "$(nproc)" "${EXCLUDE_ARGS[@]}" # The tui suite ran at all. The step above passes just as well when # MORPH_BUILD_TUI was dropped from the configure, or quietly turned off, @@ -499,18 +586,11 @@ jobs: # tui cases, and `--no-tests=error` turns "selected nothing" red. - name: The tui suite was built and ran if: "!cancelled()" - run: ctest --preset ${{ matrix.preset }} --parallel "$(nproc)" -L tui --no-tests=error --output-on-failure + run: ${IN_IMAGE} ctest --preset ${{ matrix.preset }} --parallel "$(nproc)" -L tui --no-tests=error --output-on-failure - - name: sccache stats + - name: Report pace-cc effectiveness if: always() - run: sccache --show-stats || true - - - name: Upload the sccache entries this build used - if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') - uses: ./.github/actions/sccache-upload - with: - name: ${{ github.job }}-${{ strategy.job-index }} - + run: ${IN_IMAGE} pace-cc --show-stats || true # ── Linux: coverage (clang, ladder + Qt) ───────────────────────────── # # A job of its own rather than a linux-sanitizers leg: it builds the full @@ -536,8 +616,9 @@ jobs: sudo apt-get update -q sudo apt-get install -y ninja-build catch2 libsqlite3-dev # --fail, a file, and a non-empty check -- never `wget -qO- | sudo - # bash`: see linux-compilers' identical install step for why the piped - # form reports success having installed nothing. + # bash`: `run:` is `bash -e` without pipefail, so the pipeline's status + # is bash's, and a failed download leaves bash an empty script that + # exits 0 -- success having installed nothing. curl -sSL --fail -o /tmp/llvm.sh https://apt.llvm.org/llvm.sh test -s /tmp/llvm.sh sudo bash /tmp/llvm.sh ${{ env.CLANG_VERSION }} @@ -996,8 +1077,8 @@ jobs: if: steps.filter.outputs.run == 'true' uses: ./.github/actions/sccache-setup - # No -DCMAKE_..._COMPILER_LAUNCHER=sccache: see linux-compilers' - # Configure steps for why the launcher is left to CompileCache.cmake. + # No -DCMAKE_..._COMPILER_LAUNCHER=sccache: an explicit launcher makes + # CompileCache.cmake skip its own detection, which prefers pace-cc. # Bank is rung 2, so -DMORPH_LADDER_RUNGS=all already adds it through the # rung loop; -DMORPH_BUILD_BANK_EXAMPLE=ON asks for it explicitly as # well, and the root adds examples/bank itself only when the ladder is @@ -1273,7 +1354,7 @@ jobs: sudo apt-get install -y ninja-build catch2 libsqlite3-dev \ unixodbc-dev libsqliteodbc libyaml-cpp-dev libzip-dev libgl1-mesa-dev libpulse0 # --fail, a file, and a non-empty check -- never `wget -qO- | sudo - # bash`: see linux-compilers' identical install step for why the piped + # bash`: see linux-coverage's identical install step for why the piped # form reports success having installed nothing. curl -sSL --fail -o /tmp/llvm.sh https://apt.llvm.org/llvm.sh test -s /tmp/llvm.sh @@ -1294,8 +1375,8 @@ jobs: if: steps.filter.outputs.run == 'true' uses: ./.github/actions/sccache-setup - # No -DCMAKE_..._COMPILER_LAUNCHER=sccache: see linux-compilers' - # Configure steps for why the launcher is left to CompileCache.cmake. + # No -DCMAKE_..._COMPILER_LAUNCHER=sccache: an explicit launcher makes + # CompileCache.cmake skip its own detection, which prefers pace-cc. # MORPH_BUILD_UNIT_TESTS=OFF: this job runs the ladder and the Qt # transport suites only, and morph_tests and morph_table_tests were a # third of its compiles. "Linux / clang-asan" builds and runs them under @@ -1443,7 +1524,7 @@ jobs: - name: Install clang-format ${{ env.CLANG_VERSION }} run: | # --fail, a file, and a non-empty check -- never `wget -qO- | sudo - # bash`: see linux-compilers' identical install step for why the piped + # bash`: see linux-coverage's identical install step for why the piped # form reports success having installed nothing. curl -sSL --fail -o /tmp/llvm.sh https://apt.llvm.org/llvm.sh test -s /tmp/llvm.sh @@ -1574,7 +1655,7 @@ jobs: libgl1-mesa-dev libxkbcommon-x11-0 libxcb-cursor0 libxcb-icccm4 \ libxcb-keysyms1 libxcb-shape0 libxcb-xinerama0 # --fail, a file, and a non-empty check -- never `wget -qO- | sudo - # bash`: see linux-compilers' identical install step for why the piped + # bash`: see linux-coverage's identical install step for why the piped # form reports success having installed nothing. curl -sSL --fail -o /tmp/llvm.sh https://apt.llvm.org/llvm.sh test -s /tmp/llvm.sh From 604f9a95dbcc3b320e604ede08bbf137eccd92ba Mon Sep 17 00:00:00 2001 From: Yaraslau Tamashevich Date: Sat, 28 Nov 2026 19:25:10 +0100 Subject: [PATCH 4/8] ci: build cold when the image has no seed for the leg's group The published image carries morph's seeds only once they have been warmed and assembled into it. Until then the copy failed and took the leg with it; the leg now warns and builds against an empty store. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01No1NzndCGtpCccptcyk6Tb --- .github/workflows/ci.yml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99d225240..8035d5780 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -268,8 +268,14 @@ jobs: "$IMAGE" sleep infinity docker exec ci-image bash -euo pipefail -c ' mkdir -p "$HOME" - cp "$PACE_CACHE_SEED_DIR/morph/'"$SEED"'.cow" /tmp/seed.cow - ls -l /tmp/seed.cow + # An image published before this group was first warmed has no seed for + # it: the leg then builds against an empty store, cold, rather than failing. + if [ -f "$PACE_CACHE_SEED_DIR/morph/'"$SEED"'.cow" ]; then + cp "$PACE_CACHE_SEED_DIR/morph/'"$SEED"'.cow" /tmp/seed.cow + ls -l /tmp/seed.cow + else + echo "::warning title=compile-cache seed::the image has no morph/'"$SEED"'.cow; this leg builds cold" + fi gcc --version | head -n1 clang++-22 --version | head -n1' docker exec -d ci-image bash -c \ @@ -408,8 +414,14 @@ jobs: "$IMAGE" sleep infinity docker exec ci-image bash -euo pipefail -c ' mkdir -p "$HOME" - cp "$PACE_CACHE_SEED_DIR/morph/'"$SEED"'.cow" /tmp/seed.cow - ls -l /tmp/seed.cow + # An image published before this group was first warmed has no seed for + # it: the leg then builds against an empty store, cold, rather than failing. + if [ -f "$PACE_CACHE_SEED_DIR/morph/'"$SEED"'.cow" ]; then + cp "$PACE_CACHE_SEED_DIR/morph/'"$SEED"'.cow" /tmp/seed.cow + ls -l /tmp/seed.cow + else + echo "::warning title=compile-cache seed::the image has no morph/'"$SEED"'.cow; this leg builds cold" + fi gcc --version | head -n1 clang++-22 --version | head -n1' docker exec -d ci-image bash -c \ From ef06d2daa3f93aa0cbc5c2ee6879ccc141c9822e Mon Sep 17 00:00:00 2001 From: Yaraslau Tamashevich Date: Sat, 28 Nov 2026 19:42:52 +0100 Subject: [PATCH 5/8] test: split morph_tests into six unit-test executables morph_tests was one 1.5 GB coverage-instrumented binary whose link peaked at 13534 MB (GNU ld, clang-coverage). It is now six binaries built by one function, morph_add_unit_test_binary, so every binary gets the same links, definitions, warnings, sanitizer/coverage instrumentation and test discovery: binary cases link peak (MB) morph_core_tests 860 3137 morph_runtime_tests 1317 3697 morph_forms_tests 848 2709 morph_ui_document_tests 804 3103 morph_ui_shell_tests 982 4409 morph_ui_table_tests 812 4141 The case counts sum to 5623, the count morph_tests listed, and the sorted list of names is identical. ctest -N reports 5639 before and after with the same set of targets built. The coverage manifest lists all six binaries. Source order within each list is the order it had in morph_tests, since some files rely on static-initialisation order within one binary. The OOM injector (a global operator new override) stays in the one binary that tests it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01No1NzndCGtpCccptcyk6Tb --- .github/workflows/ci.yml | 6 +- .github/workflows/nightly-slow-checks.yml | 4 +- CMakeLists.txt | 6 +- CONTRIBUTING.md | 4 +- README.md | 4 +- cmake/compiler_options.cmake | 6 +- cmake/tsan.supp | 2 +- cmake/valgrind.supp | 2 +- docs/BUILDING.md | 6 +- docs/spec/security.md | 4 +- docs/spec/table/table.md | 2 +- examples/TESTING.md | 10 +- examples/common/testkit/step_executor.hpp | 2 +- scripts/check_branch_coverage.py | 18 +- tests/CMakeLists.txt | 655 ++++++++++++---------- tests/bench/CMakeLists.txt | 2 +- tests/bench/bench_dispatch_latency.cpp | 2 +- tests/bench_interpreter.cpp | 8 +- tests/bench_mount.cpp | 2 +- tests/net/test_push_tables.cpp | 2 +- tests/offline_sqlite/CMakeLists.txt | 2 +- tests/push_records_late.cpp | 2 +- tests/soak/CMakeLists.txt | 2 +- tests/soak/test_soak_switch_backend.cpp | 2 +- tests/test_action_log.cpp | 2 +- tests/test_coverage_gaps.cpp | 2 +- tests/test_extension_bag_spike.cpp | 4 +- tests/test_forms_conformance_corpus.cpp | 2 +- tests/test_journal_format_versioning.cpp | 2 +- tests/test_remote_reply_envelopes.cpp | 2 +- tests/test_support.hpp | 6 +- tests/test_views.cpp | 2 +- 32 files changed, 406 insertions(+), 371 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8035d5780..ff74899b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -691,7 +691,7 @@ jobs: -DCMAKE_C_COMPILER_LAUNCHER=sccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=sccache - # The instrumented link of morph_tests alone peaks near 13.5 GB, so Configure allows one link at a time + # Each instrumented unit-test link peaks at 3-4.5 GB; Configure allows one link at a time # (MORPH_LINK_JOBS=1), and the compiles that run beside it need more than the runner's 16 GB and 3 GB of swap. # Extra swap costs nothing unless it is needed; the Build step prints the swap used. - name: Add swap for the build's heaviest compiles @@ -1390,7 +1390,7 @@ jobs: # No -DCMAKE_..._COMPILER_LAUNCHER=sccache: an explicit launcher makes # CompileCache.cmake skip its own detection, which prefers pace-cc. # MORPH_BUILD_UNIT_TESTS=OFF: this job runs the ladder and the Qt - # transport suites only, and morph_tests and morph_table_tests were a + # transport suites only, and the morph_*_tests unit suites and morph_table_tests were a # third of its compiles. "Linux / clang-asan" builds and runs them under # the same sanitizers. - name: Configure (clang-asan, ladder + Qt on) @@ -1419,7 +1419,7 @@ jobs: # would read as "rungs are ASan-clean" rather than "rungs were never # checked". That is not hypothetical — before the AF_SANITIZER blocks # landed in cmake/morph_add_rung.cmake and examples/common/CMakeLists.txt, - # -DAF_SANITIZER=asan instrumented morph_tests and nothing under + # -DAF_SANITIZER=asan instrumented the unit-test binaries and nothing under # examples/. # # Not a hand-rolled `nm | grep __asan_` over diff --git a/.github/workflows/nightly-slow-checks.yml b/.github/workflows/nightly-slow-checks.yml index da677d1a6..e35be2e9a 100644 --- a/.github/workflows/nightly-slow-checks.yml +++ b/.github/workflows/nightly-slow-checks.yml @@ -83,7 +83,7 @@ jobs: - name: Run tests under Valgrind run: | status=0 - for suite in tests/morph_tests tests/net/morph_net_tests tests/offline_sqlite/morph_offline_sqlite_tests; do + for suite in tests/morph_core_tests tests/morph_runtime_tests tests/morph_forms_tests tests/morph_ui_document_tests tests/morph_ui_shell_tests tests/morph_ui_table_tests tests/net/morph_net_tests tests/offline_sqlite/morph_offline_sqlite_tests; do binary="build/gcc-debug/$suite" if [ ! -x "$binary" ]; then echo "::error::expected Valgrind suite $binary was not built" @@ -91,7 +91,7 @@ jobs: fi echo "── memcheck: $suite ──" EXTRA_ARGS=() - if [ "$suite" = "tests/morph_tests" ]; then + if [ "$suite" = "tests/morph_core_tests" ]; then # [registration-phase] forks a child that exits holding the parent's # heap; under memcheck the child reports it as leaked and exits 1. EXTRA_ARGS=("~[oom-injector]" "~[issue108]" "~[registration-phase]") diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b8e1b5eb..ee8ba5ee3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,10 +32,10 @@ if(CMAKE_GENERATOR MATCHES "Ninja" AND MORPH_LINK_JOBS GREATER 0) endif() option(MORPH_BUILD_TESTS "Build tests" ON) -# OFF builds no target under tests/ itself: morph_tests, morph_table_tests and the compile checks. A job that runs only +# OFF builds no target under tests/ itself: morph_core_tests, morph_runtime_tests, morph_forms_tests, morph_ui_document_tests, morph_ui_shell_tests, morph_ui_table_tests, morph_table_tests and the compile checks. A job that runs only # the ladder's or a frontend's suites sets it, since those targets are most of its build and another job builds and # runs them. The suites in tests// and the ladder's are still built under MORPH_BUILD_TESTS. -option(MORPH_BUILD_UNIT_TESTS "Build the library's own suites in tests/ (morph_tests, morph_table_tests, compile checks)" ON) +option(MORPH_BUILD_UNIT_TESTS "Build the library's own suites in tests/ (morph_core_tests, morph_runtime_tests, morph_forms_tests, morph_ui_document_tests, morph_ui_shell_tests, morph_ui_table_tests, morph_table_tests, compile checks)" ON) option(MORPH_BUILD_SHARED "Build morph::morph as a shared library (MORPH_API marks what it exports; symbols are hidden by default)" OFF) # A shared morph links a shared core-cpp (CORE_CPP_BUILD_SHARED): core-cpp keeps # process and thread state of its own, such as the current executor, and a @@ -1207,7 +1207,7 @@ if(MORPH_BUILD_TESTS) # ── The `--log-level` gate, shared by every Catch2 suite ──────────────── # - # morph::log used to default to LogLevel::debug, so a plain `morph_tests` + # morph::log used to default to LogLevel::debug, so a plain `morph_core_tests` # run wrote 2,949 lines of framework tracing to stderr against 23 lines of # actual Catch2 output. The library default is now `warn`; these two targets # are what take a *test* run down to silent while keeping the stream one diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aa4b112e2..4d3d7a3ca 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -183,7 +183,7 @@ serialising independent rungs behind one file. where the type system allows it, a Catch2 runtime `REQUIRE` where it does not (an exception's `what()`, a `RemoteServer` reply string, a glaze option that has no reachable symbol). It runs as part of the - normal `morph_tests` target, so it is checked under every compiler in + normal unit-test targets, so it is checked under every compiler in the CI matrix. - a gate removed on 2026-09-23 (the "Drift guard" workflow) asserts every pinned value is still cited in the spec file that documents it, @@ -307,7 +307,7 @@ If you built a single target rather than the whole preset, the sweep refuses instead, which applies no floor and says so: ```sh -bash scripts/check_sanitizer_instrumentation.sh --binary build/clang-tsan/tests/morph_tests tsan +bash scripts/check_sanitizer_instrumentation.sh --binary build/clang-tsan/tests/morph_core_tests tsan ``` ## Security diff --git a/README.md b/README.md index 214671edc..e0291a240 100644 --- a/README.md +++ b/README.md @@ -115,8 +115,8 @@ On Linux: ```sh cmake --preset clang-release -cmake --build build/clang-release --target morph_tests -./build/clang-release/tests/morph_tests +cmake --build build/clang-release --target morph_core_tests morph_runtime_tests morph_forms_tests morph_ui_document_tests morph_ui_shell_tests morph_ui_table_tests +./build/clang-release/tests/morph_core_tests ``` To use morph in your own project, install it and use diff --git a/cmake/compiler_options.cmake b/cmake/compiler_options.cmake index d744a84ef..993dfd86a 100644 --- a/cmake/compiler_options.cmake +++ b/cmake/compiler_options.cmake @@ -781,7 +781,7 @@ endif() # # The classifier is the repository's own naming convention, which every test # executable already follows: an EXECUTABLE whose name ends in `_tests` -# (morph_tests, morph_net_tests, morph_qt_tests, morph_offline_sqlite_tests, +# (morph_core_tests, morph_ui_table_tests, morph_net_tests, morph_qt_tests, morph_offline_sqlite_tests, # morph_net_qt_interop_tests, ladder_common_tests, ladder__tests) is a # test binary. Deriving it from the name rather than from a per-call flag is # the same move: a new test executable is registered by @@ -922,7 +922,7 @@ function(morph_write_coverage_object_manifest) return() endif() get_property(_morph_cov_objects GLOBAL PROPERTY MORPH_COVERAGE_TEST_OBJECTS) - if(NOT _morph_cov_objects AND TARGET morph_tests) + if(NOT _morph_cov_objects AND TARGET morph_core_tests) message(FATAL_ERROR "morph: coverage: AF_COVERAGE is ON and the test suite is being " "built, but no target was registered as a coverage object. " @@ -973,7 +973,7 @@ function(apply_bigobj target) # folding, full /Zi debug info), aborting with C1128 ("number of # sections exceeded object file format limit"). Several unrelated # targets have hit this independently as they grew (morph_forms_demo, - # lab_forms_demo_module, morph_tests) -- call this on any target built + # lab_forms_demo_module, the morph_*_tests unit suites) -- call this on any target built # from demo/example/ladder sources instead of waiting for it to recur. # /bigobj switches to the extended section-count format; harmless on # Release and on other compilers. diff --git a/cmake/tsan.supp b/cmake/tsan.supp index 6efdec67f..9d93d05b9 100644 --- a/cmake/tsan.supp +++ b/cmake/tsan.supp @@ -19,7 +19,7 @@ # ── What this file is not, and what second_deadlock_stack=1 buys ─────────── # # Both points below are about an intermittent `lock-order-inversion` -- seen -# once in six full `morph_tests` runs, with its stack lost -- and they are +# once in six full unit-test runs, with its stack lost -- and they are # written here because this is the file the next person will open. # # 1. Every `race:` entry below is a **suppression**, so none of them could diff --git a/cmake/valgrind.supp b/cmake/valgrind.supp index 9ebd1913b..305d33fb4 100644 --- a/cmake/valgrind.supp +++ b/cmake/valgrind.supp @@ -16,7 +16,7 @@ Memcheck:Leak match-leak-kinds: reachable ... - obj:*morph_tests* + obj:*morph_*_tests* fun:_dl_init } diff --git a/docs/BUILDING.md b/docs/BUILDING.md index 8f127ae19..0e7eee4f8 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -30,8 +30,8 @@ On Linux the presets fetch what they need; no package manager is required: ```sh cmake --preset clang-release -cmake --build build/clang-release --target morph_tests -./build/clang-release/tests/morph_tests +cmake --build build/clang-release --target morph_core_tests morph_runtime_tests morph_forms_tests morph_ui_document_tests morph_ui_shell_tests morph_ui_table_tests +./build/clang-release/tests/morph_core_tests ``` `gcc-release`, `clang-debug` and the sanitizer presets (`clang-asan`, @@ -44,7 +44,7 @@ need `VCPKG_ROOT` set. | Option | Default | What it builds | |---|---|---| | `MORPH_BUILD_TESTS` | `ON` | The unit tests | -| `MORPH_BUILD_UNIT_TESTS` | `ON` | With `MORPH_BUILD_TESTS`, the library's own suites in `tests/` (`morph_tests`, `morph_table_tests`, the compile checks); a job running only the ladder or a frontend suite turns it off | +| `MORPH_BUILD_UNIT_TESTS` | `ON` | With `MORPH_BUILD_TESTS`, the library's own suites in `tests/` (`morph_core_tests`, `morph_runtime_tests`, `morph_forms_tests`, `morph_ui_document_tests`, `morph_ui_shell_tests`, `morph_ui_table_tests`, `morph_table_tests`, the compile checks); a job running only the ladder or a frontend suite turns it off | | `MORPH_BUILD_SHARED` | `OFF` | Build `morph::morph` as a shared library. Every symbol is hidden unless `MORPH_API` marks it, on every platform; see below | | `MORPH_BUILD_EXAMPLES` | `ON` | The dependency-free examples (forms, concepts, gallery, LIMS gallery); the generic client when a frontend is on | | `MORPH_BUILD_CLIENT` | `ON` | `morph::client`, the generic client's source and shell | diff --git a/docs/spec/security.md b/docs/spec/security.md index a23b1e54b..1b4dc63e6 100644 --- a/docs/spec/security.md +++ b/docs/spec/security.md @@ -255,8 +255,8 @@ not apply to morph's own suite: several test files (`test_session_auth.cpp`, `test_security_fixes.cpp`, `test_policy_hardening.cpp`, `test_register_authorization.cpp`) deliberately exercise the reference `hmacSha256` through its default argument, and `tests/CMakeLists.txt` undoes -the inherited definition for the `morph_tests` target alone (a `-U` in that -target's compile options, which CMake expands after the interface `-D`). +the inherited definition for the unit-test targets alone (a `-U` in their +compile options, which CMake expands after the interface `-D`). `MORPH_BUILD_TESTS=ON` and `MORPH_REQUIRE_VETTED_HMAC=ON` therefore compose: CI builds and tests exactly that combination, which is what keeps the option from rotting. The guard's own correctness — that it blocks the default, still diff --git a/docs/spec/table/table.md b/docs/spec/table/table.md index 34f99c6b1..8ed057eef 100644 --- a/docs/spec/table/table.md +++ b/docs/spec/table/table.md @@ -2904,7 +2904,7 @@ subtracted. ### Benchmarks: client cache and window -`morph_table_tests` and `morph_ui_tests`, `"[.benchmark]"`, beside `bench_interpreter.cpp` and `bench_mount.cpp`. +`morph_table_tests` and `morph_ui_table_tests`, `"[.benchmark]"`, beside `bench_interpreter.cpp` and `bench_mount.cpp`. | Id | Measures | Budget | Catches | |---|---|---|---| diff --git a/examples/TESTING.md b/examples/TESTING.md index 88b822873..2ae5adc3d 100644 --- a/examples/TESTING.md +++ b/examples/TESTING.md @@ -499,7 +499,7 @@ Open framework facts every WASM client must respect (verified): `morph::exec::ThreadPoolExecutor` — and running just that test under `clang-tsan` in a CI leg of its own. No current rung has such a test, so there is no TSan leg over ladder code; the library's own TSan coverage - (`linux-sanitizers`, `morph_tests`) is separate and unaffected. + (`linux-sanitizers`, the `morph_*_tests` unit suites) is separate and unaffected. - **Coverage wiring.** The `clang-coverage` CI leg builds the full ladder (`-DMORPH_BUILD_QT=ON -DMORPH_BUILD_LADDER=ON -DMORPH_LADDER_RUNGS=all`) @@ -511,10 +511,10 @@ Open framework facts every WASM client must respect (verified): `include/morph`'s own targets use; the instrumentation is a link option too, so every executable that links an instrumented library needs it. `scripts/coverage.sh` merges multiple instrumented binaries into one report - via llvm-cov's `-object` flag: one `TEST_EXE` positional (the library's - `morph_tests`) plus an `OBJECT_ARGS` array populated with every other test - binary that exists in the build (`ladder_common_tests` and each - `ladder__tests`, each guarded by `if [ -x "$BINARY" ]` so the script + via llvm-cov's `-object` flag: an `OBJECT_ARGS` array populated from `coverage_objects.txt` (the library's + `morph_*_tests` unit suites) plus every other test binary that exists in the build + (`ladder_common_tests` and each `ladder__tests`, each guarded by + `if [ -x "$BINARY" ]` so the script keeps working for a configure that did not build that rung), and adds `examples/common` and each rung's `include`, `src` and `screens` to the positional source-path filter alongside `include/morph`. AUTOMOC's diff --git a/examples/common/testkit/step_executor.hpp b/examples/common/testkit/step_executor.hpp index 81481c42d..5758d0585 100644 --- a/examples/common/testkit/step_executor.hpp +++ b/examples/common/testkit/step_executor.hpp @@ -20,7 +20,7 @@ /// design: same name, same API, same rationale. It is duplicated rather than /// shared for exactly the reason `strand_interleaver.hpp`'s /// `DeterministicExecutor` is duplicated from that same header -- -/// `tests/test_support.hpp` is a private header for `morph_tests`' own +/// `tests/test_support.hpp` is a private header for the library's own unit-test /// translation units and has no reachable include path from `examples/`. /// That reachability gap, not the absence of the semantics, is why a ladder /// async-job test has to reach for this copy instead of spinning a real pool. diff --git a/scripts/check_branch_coverage.py b/scripts/check_branch_coverage.py index 72ba5a5c0..491c44030 100644 --- a/scripts/check_branch_coverage.py +++ b/scripts/check_branch_coverage.py @@ -136,8 +136,8 @@ # on, and the test binary whose presence in coverage_objects.txt proves it was. # # `cmake --preset clang-coverage` alone -- the flow scripts/coverage.sh's own -# usage line documents -- profiles exactly one binary, morph_tests, and -# morph_tests compiles nothing under include/morph/net or include/morph/qt: +# usage line documents -- profiles only the unit-test binaries, and +# those compile nothing under include/morph/net or include/morph/qt: # those come from tests/net and tests/qt, gated behind MORPH_BUILD_NET and # MORPH_BUILD_QT, both `option(... OFF)`. Without this table the vacuity check # below fails that configure and blames a dropped subsystem for an option simply @@ -925,27 +925,27 @@ def run_ambiguous(allowlist): fail("a non-disambiguating `context` was accepted", output) # ── The manifest-aware vacuity rule ──────────────────────────────────── - # `cmake --preset clang-coverage` with nothing else profiles morph_tests - # alone, and morph_tests compiles nothing under include/morph/net or + # `cmake --preset clang-coverage` with nothing else profiles the unit-test + # binaries alone, and they compile nothing under include/morph/net or # include/morph/qt. Without these four cases the gate fails that configure # and blames a dropped subsystem for an option being off. partial_build = {name: recs for name, recs in _every_subsystem().items() if not name.startswith(("include/morph/net/", "include/morph/qt/"))} - code, output = run(partial_build, profiled=["morph_tests"]) + code, output = run(partial_build, profiled=["morph_core_tests"]) if code == 0 and "not enforced: include/morph/net was not built" in output: note("ok: a configure that did not build tests/net is reported, not failed") else: fail("a subset configure was failed rather than reported", output) - code, output = run(partial_build, profiled=["morph_tests", "morph_net_tests", + code, output = run(partial_build, profiled=["morph_core_tests", "morph_net_tests", "morph_qt_tests"]) if code != 0 and "contributes no branch records" in output: note("ok: a subsystem missing while its suite WAS profiled still fails") else: fail("a profiled-but-absent subsystem was accepted", output) - code, output = run(_every_subsystem(), profiled=["morph_tests"]) + code, output = run(_every_subsystem(), profiled=["morph_core_tests"]) if code != 0 and "table is stale" in output: note("ok: records present while the mapped suite was not profiled fails") else: @@ -979,14 +979,14 @@ def run_ambiguous(allowlist): subset_low = {name: recs for name, recs in _every_subsystem(low_core).items() if not name.startswith(("include/morph/net/", "include/morph/qt/"))} - code, output = run(subset_low, profiled=["morph_tests"]) + code, output = run(subset_low, profiled=["morph_core_tests"]) if code == 0 and "would fail under CI's configure" in output: note("ok: a floor breach on a subset build is reported, not failed") else: fail("a subset build was failed on a floor it cannot reach", output) code, output = run(_every_subsystem(low_core), - profiled=["morph_tests", "morph_net_tests", "morph_qt_tests"]) + profiled=["morph_core_tests", "morph_net_tests", "morph_qt_tests"]) if code != 0 and "below its 94% floor" in output: note("ok: a floor breach on a full build still fails") else: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6ff06123f..220ec8059 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -91,136 +91,16 @@ if(EMSCRIPTEN) return() endif() -add_executable(morph_tests +# Core suite: executors, completions, bridge, registry, actions, security and policy. +set(MORPH_CORE_TEST_SOURCES oom_injector.cpp test_oom_injector.cpp test_executor.cpp test_executor_scope.cpp test_io_loop.cpp test_example.cpp - test_push_records.cpp - test_push_effects.cpp test_cov_c_effects.cpp - test_cov_c_forms_values.cpp - test_cov_h_forms_rules.cpp - test_cov_h_forms_values.cpp - test_cov_h_rational.cpp - test_cov_h_views_columns.cpp - test_cov_c_forms_session.cpp - test_cov_f_forms_session.cpp test_cov_c_observability.cpp - test_cov_c_ui_document_mutations.cpp - test_cov_c_ui_document_grids.cpp - test_cov_c_ui_document_tables.cpp - test_cov_c_ui_interpreter_inputs.cpp - test_push_watch_table.cpp - test_push_catalog.cpp - test_push_channel.cpp - test_push_watch.cpp - test_push_cache.cpp - test_ui_interpreter_cache.cpp - ui_table_model_support.cpp - test_ui_table_model_window_rows.cpp - test_ui_table_model_table_catalog.cpp - test_ui_table_model_model_table.cpp - test_ui_table_model_value_rows.cpp - test_ui_table_model_action_table.cpp - test_ui_table_model_filter_menu.cpp - test_ui_table_model_copy_collection.cpp - test_ui_table_model_view_selection.cpp - test_ui_table_model_row_changes.cpp - test_ui_table_model_model_cells.cpp - test_ui_table_model_cell_walk.cpp - test_ui_table_model_cell_reads.cpp - test_ui_table_model_cell_edits.cpp - test_ui_table_model_cell_errors.cpp - test_ui_grid.cpp - test_ui_cov_grid_form_rows.cpp - test_ui_cov_grid_keys.cpp - test_ui_cov_expression.cpp - test_ui_cov_h_expression.cpp - test_ui_cov_h_theme.cpp - test_ui_cov_h_page_layout.cpp - test_ui_cov_h_navigator.cpp - test_ui_cov_h_table_dialogs.cpp - test_ui_cov_h_table_state.cpp - test_ui_cov_h_interp_download.cpp - test_ui_cov_h_interp_lowering.cpp - test_ui_cov_interp_lowering.cpp - test_ui_cov_interp_elements.cpp - test_ui_cov_grid_unknown.cpp - test_ui_cov_j_grid_source.cpp - test_ui_cov_j_page_mount.cpp - test_ui_cov_j_mount_labels.cpp - test_ui_cov_j_filter_pages.cpp - test_ui_cov_j_explorer_search.cpp - test_ui_cov_j_custom_checks.cpp - test_ui_cov_j_workspace_head.cpp - test_ui_cov_j_filter_menu.cpp - test_ui_cov_j_controller.cpp - test_ui_cov_j_custom_source.cpp - test_ui_cov_j_mount_keys.cpp - test_ui_cov_j_explorer.cpp - test_ui_cov_grid_paste.cpp - test_ui_cov_grid_rows.cpp - test_ui_cov_interp_rows.cpp - test_ui_cov_grid_model.cpp - test_ui_cov_grid_fixed.cpp - test_ui_cov_interp_collections.cpp - test_ui_cov_interp_forms.cpp - test_ui_cov_mount_extents.cpp - test_ui_cov_interp_fixed_grid.cpp - test_ui_cov_d_form_grid.cpp - test_ui_cov_d_fixed_grid.cpp - test_ui_cov_d_custom_screen_checks.cpp - test_ui_cov_d_custom_screen_words.cpp - test_ui_cov_d_shell_parts.cpp - test_ui_cov_d_chat_tools.cpp - test_ui_cov_d_workspace.cpp - test_ui_cov_d_rows_bound.cpp - test_ui_cov_g_action_table_view.cpp - test_ui_cov_g_document_loader.cpp - test_ui_cov_g_table_points.cpp - test_ui_cov_g_menu_walk.cpp - test_ui_cov_g_rows_decorators.cpp - test_ui_cov_g_model_grid.cpp - test_ui_cov_g_element_values.cpp - test_ui_cov_g_model_table_binds.cpp - test_ui_cov_g_host_commands.cpp - test_ui_cov_g_typed_table.cpp - test_ui_cov_g_filter_menu.cpp - test_ui_cov_g_window_fetch.cpp - test_ui_cov_g_model_grid_values.cpp - test_ui_cov_g_grid_controller.cpp - test_ui_cov_g_form_grid_rows.cpp - test_ui_cov_g_fixed_grid_source.cpp - test_ui_cov_d_rows_state.cpp - test_ui_cov_d_chart.cpp - test_ui_cov_d_grid_groups.cpp - test_ui_cov_d_host.cpp - test_ui_cov_d_shell_frame.cpp - test_ui_cov_d_grid_bound.cpp - forms/test_forms_derive.cpp - test_ui_table_state.cpp - test_push_agent.cpp - test_mcp_transport.cpp - test_chat_settle.cpp - test_chat_origin.cpp - test_chat_service_seams.cpp - test_chat_protocol.cpp - test_chat_screen_tools.cpp - test_chat_service.cpp - test_chat_transcription.cpp - test_chat_dictation_audio.cpp - test_chat_propose_screen.cpp - test_chat_config.cpp - test_chat_conversations.cpp - test_chat_context.cpp - test_chat_client.cpp - test_chat_panel.cpp - test_push_documents.cpp - test_push_refresh_keys.cpp - push_records_late.cpp test_executor_extra.cpp test_strand.cpp test_completion.cpp @@ -232,7 +112,6 @@ add_executable(morph_tests test_storage_owner.cpp test_coroutine_client.cpp test_coroutine_model.cpp - test_async_delay.cpp test_model.cpp test_post_commit_tail.cpp test_logger.cpp @@ -248,21 +127,12 @@ add_executable(morph_tests test_registration_same_line.cpp test_principal.cpp test_bridge_local.cpp - test_bridge_remote.cpp test_bridge_pending_calls.cpp test_bridge_execute_json.cpp test_bridge_raw.cpp raw_dispatch_models.cpp - test_bridge_pending_calls.cpp - test_remote_extra.cpp - test_remote_server_strand.cpp - test_remote_connection_scope.cpp - test_remote_cancel.cpp - test_remote_step_interleaving.cpp - test_remote_execute_ordering.cpp test_action_validation.cpp test_action_guard.cpp - test_action_wire_rejection.cpp test_security_fixes.cpp test_bridge_lifetime.cpp test_bridge_bind_paths.cpp @@ -274,11 +144,68 @@ add_executable(morph_tests test_dispatch_di.cpp test_handler_binding.cpp test_switch_backend.cpp + test_bridge_fixes.cpp + test_completion_branches.cpp + test_issues.cpp + test_concurrency_invariants.cpp + test_coverage_gaps.cpp + test_coverage_extra.cpp + test_shared_instances.cpp + test_strong_id_keys.cpp + test_session_auth.cpp + test_policy_hardening.cpp + test_register_authorization.cpp + test_register_session.cpp + test_control_byte_escaping.cpp + test_opaque_model_ids.cpp + test_graceful_shutdown.cpp + test_pinned_facts.cpp + test_version.cpp + test_callback_scope.cpp + test_cancellation_policy.cpp + test_file_io_ops.cpp + test_extension_bag_spike.cpp + test_action_refusal.cpp +) +# Runtime suite: push, chat, remote, wire, offline queue, journal and reactive state. +set(MORPH_RUNTIME_TEST_SOURCES + test_push_records.cpp + test_push_effects.cpp + test_push_watch_table.cpp + test_push_catalog.cpp + test_push_channel.cpp + test_push_watch.cpp + test_push_cache.cpp + test_push_agent.cpp + test_mcp_transport.cpp + test_chat_settle.cpp + test_chat_origin.cpp + test_chat_service_seams.cpp + test_chat_protocol.cpp + test_chat_screen_tools.cpp + test_chat_service.cpp + test_chat_transcription.cpp + test_chat_dictation_audio.cpp + test_chat_propose_screen.cpp + test_chat_config.cpp + test_chat_conversations.cpp + test_chat_context.cpp + test_chat_client.cpp + test_chat_panel.cpp + test_push_documents.cpp + test_push_refresh_keys.cpp + push_records_late.cpp + test_async_delay.cpp + test_bridge_remote.cpp + test_remote_extra.cpp + test_remote_server_strand.cpp + test_remote_connection_scope.cpp + test_remote_cancel.cpp + test_remote_step_interleaving.cpp + test_remote_execute_ordering.cpp + test_action_wire_rejection.cpp test_async_registration.cpp test_network_monitor.cpp - test_forms_boolean_anyof_wire.cpp - test_forms_dom_access.cpp - test_forms_exact_bounds.cpp test_offline_queue.cpp test_file_offline_queue.cpp test_replay_ledger.cpp @@ -286,17 +213,9 @@ add_executable(morph_tests test_reconnect_coordinator.cpp test_offline_integration.cpp test_conflict_resolution.cpp - test_bridge_fixes.cpp - test_completion_branches.cpp - test_issues.cpp - test_concurrency_invariants.cpp test_subscription.cpp - test_coverage_gaps.cpp - test_coverage_extra.cpp test_coverage_push95.cpp test_server_limits.cpp - test_shared_instances.cpp - test_strong_id_keys.cpp test_wire_encode_fault.cpp test_wire_hardening.cpp test_wire_omitted_fields.cpp @@ -310,6 +229,31 @@ add_executable(morph_tests test_journal_format_versioning.cpp test_journal_payload_evolution.cpp test_outbox.cpp + test_reactive_signal.cpp + test_reactive_computed.cpp + test_reactive_misuse.cpp + test_reactive_scope.cpp + test_reactive_store.cpp + test_reactive_scheduler.cpp + test_reactive_query.cpp + test_reactive_mutation.cpp + test_reactive_control_bridge.cpp + test_remote_envelope_service.cpp + test_async_ask_defaults.cpp +) + +# Forms suite: the forms engine, rules, rational and quantity values, and rendering. +set(MORPH_FORMS_TEST_SOURCES + test_cov_c_forms_values.cpp + test_cov_h_forms_rules.cpp + test_cov_h_forms_values.cpp + test_cov_h_rational.cpp + test_cov_c_forms_session.cpp + test_cov_f_forms_session.cpp + forms/test_forms_derive.cpp + test_forms_boolean_anyof_wire.cpp + test_forms_dom_access.cpp + test_forms_exact_bounds.cpp test_rational_checked.cpp test_rational_wire_policy.cpp test_rational.cpp @@ -358,81 +302,40 @@ add_executable(morph_tests test_forms_engine_wizard.cpp test_forms_engine_collection_view.cpp test_forms_engine_wizard_view.cpp - test_session_auth.cpp - test_policy_hardening.cpp - test_register_authorization.cpp - test_register_session.cpp - test_control_byte_escaping.cpp - test_opaque_model_ids.cpp - test_graceful_shutdown.cpp - test_pinned_facts.cpp - test_version.cpp - test_callback_scope.cpp - test_reactive_signal.cpp - test_reactive_computed.cpp - test_reactive_misuse.cpp - test_reactive_scope.cpp - test_reactive_store.cpp - test_reactive_scheduler.cpp - test_reactive_query.cpp - test_reactive_mutation.cpp - test_reactive_control_bridge.cpp +) + +# UI document suite: the document, expressions, interpreter, authoring and mounting. +set(MORPH_UI_DOCUMENT_TEST_SOURCES + test_cov_h_views_columns.cpp + test_cov_c_ui_document_mutations.cpp + test_cov_c_ui_interpreter_inputs.cpp + test_ui_interpreter_cache.cpp + test_ui_cov_expression.cpp + test_ui_cov_h_expression.cpp + test_ui_cov_h_theme.cpp + test_ui_cov_h_page_layout.cpp + test_ui_cov_h_interp_download.cpp + test_ui_cov_h_interp_lowering.cpp + test_ui_cov_interp_lowering.cpp + test_ui_cov_interp_elements.cpp + test_ui_cov_interp_rows.cpp + test_ui_cov_interp_collections.cpp + test_ui_cov_interp_forms.cpp + test_ui_cov_mount_extents.cpp + test_ui_cov_g_document_loader.cpp + test_ui_cov_g_menu_walk.cpp + test_ui_cov_g_rows_decorators.cpp + test_ui_cov_g_element_values.cpp + test_ui_cov_g_filter_menu.cpp + test_ui_cov_g_window_fetch.cpp test_ui_view.cpp - test_ui_recording_backend.cpp test_ui_mount.cpp test_ui_controlled.cpp test_ui_structure.cpp test_ui_foreach.cpp - test_ui_table.cpp test_ui_cell_format.cpp - test_ui_cov_table_cell_format.cpp - test_ui_cov_table_config.cpp - test_ui_cov_table_filter_menu.cpp - test_ui_cov_table_state.cpp - test_ui_cov_table_engine_rows.cpp - test_ui_cov_table_window_rows.cpp - test_ui_cov_table_views_menu.cpp - test_ui_cov_table_filter_dialog.cpp - test_ui_cov_table_model_columns.cpp - test_ui_cov_table_rows_pure.cpp - test_ui_cov_table_window_state.cpp - test_ui_cov_table_runs.cpp - test_ui_cov_table_mount.cpp - test_ui_cov_table_state_model.cpp - test_ui_cov_h_table_state_model.cpp - test_ui_cov_i_views.cpp - test_ui_cov_i_cell_menu.cpp - test_ui_cov_i_rows_table.cpp - test_ui_cov_i_collection.cpp - test_ui_cov_i_rows_columns.cpp - test_ui_cov_i_stored_state.cpp - test_ui_cov_i_groups.cpp - test_ui_cov_i_table_gestures.cpp - test_ui_cov_i_views_menu.cpp - test_ui_cov_i_sort_dialog.cpp - test_ui_table_config.cpp - bench_interpreter.cpp - bench_mount.cpp - test_ui_frontend.cpp test_ui_conformance.cpp - test_ui_cov_e_conformance_faults.cpp - test_ui_cov_e_recording_backend.cpp - test_ui_cov_e_interpreter.cpp - test_ui_cov_f_interpreter.cpp - test_ui_spotlight_recording.cpp - test_ui_common.cpp - test_ui_custom.cpp - test_ui_shell_frame.cpp - test_ui_shell_tours.cpp - test_ui_shell_parts.cpp - test_ui_explorer.cpp - test_ui_workspace.cpp - test_ui_workspace_start.cpp - test_ui_field.cpp - test_ui_kinds.cpp - test_ui_step_detail.cpp test_ui_chart_bars.cpp - test_ui_table_row_span.cpp test_ui_value.cpp test_ui_include_order.cpp test_ui_messages.cpp @@ -442,13 +345,11 @@ add_executable(morph_tests test_ui_interpreter_control.cpp test_ui_interpreter_relations.cpp test_ui_interpreter_calculation.cpp - test_ui_interpreter_models.cpp test_ui_interpreter_permissions.cpp test_ui_interpreter_forms.cpp test_ui_bound_decimals.cpp test_ui_interpreter_commands.cpp test_ui_document_page.cpp - test_ui_interpreter_table.cpp test_ui_interpreter_chart.cpp test_ui_chart_scale.cpp test_ui_stretch_columns.cpp @@ -461,26 +362,65 @@ add_executable(morph_tests test_ui_author.cpp test_ui_author_forms.cpp test_ui_width_class.cpp - test_cancellation_policy.cpp - test_file_io_ops.cpp - test_extension_bag_spike.cpp - test_remote_envelope_service.cpp + test_ui_theme.cpp + test_ui_evaluate.cpp + test_ui_interpreter_detail.cpp +) +# UI shell suite: the shell, host, custom screens, tours, workspace, services and recording backend. +set(MORPH_UI_SHELL_TEST_SOURCES + test_ui_cov_h_navigator.cpp + test_ui_cov_j_page_mount.cpp + test_ui_cov_j_mount_labels.cpp + test_ui_cov_j_filter_pages.cpp + test_ui_cov_j_explorer_search.cpp + test_ui_cov_j_custom_checks.cpp + test_ui_cov_j_workspace_head.cpp + test_ui_cov_j_filter_menu.cpp + test_ui_cov_j_controller.cpp + test_ui_cov_j_custom_source.cpp + test_ui_cov_j_mount_keys.cpp + test_ui_cov_j_explorer.cpp + test_ui_cov_d_custom_screen_checks.cpp + test_ui_cov_d_custom_screen_words.cpp + test_ui_cov_d_shell_parts.cpp + test_ui_cov_d_chat_tools.cpp + test_ui_cov_d_workspace.cpp + test_ui_cov_d_rows_bound.cpp + test_ui_cov_g_host_commands.cpp + test_ui_cov_d_rows_state.cpp + test_ui_cov_d_chart.cpp + test_ui_cov_d_host.cpp + test_ui_cov_d_shell_frame.cpp + test_ui_recording_backend.cpp + test_ui_frontend.cpp + test_ui_cov_e_conformance_faults.cpp + test_ui_cov_e_recording_backend.cpp + test_ui_cov_e_interpreter.cpp + test_ui_cov_f_interpreter.cpp + test_ui_spotlight_recording.cpp + test_ui_common.cpp + test_ui_custom.cpp + test_ui_shell_frame.cpp + test_ui_shell_tours.cpp + test_ui_shell_parts.cpp + test_ui_explorer.cpp + test_ui_workspace.cpp + test_ui_workspace_start.cpp + test_ui_field.cpp + test_ui_kinds.cpp + test_ui_step_detail.cpp test_ui_bundle.cpp test_ui_service.cpp test_ui_queueing_dispatcher.cpp test_ui_service_client.cpp test_ui_app_root.cpp test_ui_backend_switch.cpp - test_ui_theme.cpp - test_ui_evaluate.cpp test_ui_file_store.cpp test_ui_file.cpp test_ui_route.cpp test_ui_host.cpp test_ui_dev_reload.cpp test_ui_inspector.cpp - test_ui_interpreter_detail.cpp - test_async_ask_defaults.cpp test_ui_route_history.cpp test_ui_preferences.cpp test_ui_preference_sync.cpp @@ -508,111 +448,206 @@ add_executable(morph_tests test_ui_spotlight_edges.cpp test_ui_catalogue.cpp test_ui_texts.cpp - test_ui_locale_table.cpp - test_action_refusal.cpp ) -target_link_libraries(morph_tests - PRIVATE - morph::morph - morph_test_main - "$" +# UI table suite: the table model, grid and table interpreter coverage, and the interpreter benchmarks. +set(MORPH_UI_TABLE_TEST_SOURCES + test_cov_c_ui_document_grids.cpp + test_cov_c_ui_document_tables.cpp + ui_table_model_support.cpp + test_ui_table_model_window_rows.cpp + test_ui_table_model_table_catalog.cpp + test_ui_table_model_model_table.cpp + test_ui_table_model_value_rows.cpp + test_ui_table_model_action_table.cpp + test_ui_table_model_filter_menu.cpp + test_ui_table_model_copy_collection.cpp + test_ui_table_model_view_selection.cpp + test_ui_table_model_row_changes.cpp + test_ui_table_model_model_cells.cpp + test_ui_table_model_cell_walk.cpp + test_ui_table_model_cell_reads.cpp + test_ui_table_model_cell_edits.cpp + test_ui_table_model_cell_errors.cpp + test_ui_grid.cpp + test_ui_cov_grid_form_rows.cpp + test_ui_cov_grid_keys.cpp + test_ui_cov_h_table_dialogs.cpp + test_ui_cov_h_table_state.cpp + test_ui_cov_grid_unknown.cpp + test_ui_cov_j_grid_source.cpp + test_ui_cov_grid_paste.cpp + test_ui_cov_grid_rows.cpp + test_ui_cov_grid_model.cpp + test_ui_cov_grid_fixed.cpp + test_ui_cov_interp_fixed_grid.cpp + test_ui_cov_d_form_grid.cpp + test_ui_cov_d_fixed_grid.cpp + test_ui_cov_g_action_table_view.cpp + test_ui_cov_g_table_points.cpp + test_ui_cov_g_model_grid.cpp + test_ui_cov_g_model_table_binds.cpp + test_ui_cov_g_typed_table.cpp + test_ui_cov_g_model_grid_values.cpp + test_ui_cov_g_grid_controller.cpp + test_ui_cov_g_form_grid_rows.cpp + test_ui_cov_g_fixed_grid_source.cpp + test_ui_cov_d_grid_groups.cpp + test_ui_cov_d_grid_bound.cpp + test_ui_table_state.cpp + test_ui_table.cpp + test_ui_cov_table_cell_format.cpp + test_ui_cov_table_config.cpp + test_ui_cov_table_filter_menu.cpp + test_ui_cov_table_state.cpp + test_ui_cov_table_engine_rows.cpp + test_ui_cov_table_window_rows.cpp + test_ui_cov_table_views_menu.cpp + test_ui_cov_table_filter_dialog.cpp + test_ui_cov_table_model_columns.cpp + test_ui_cov_table_rows_pure.cpp + test_ui_cov_table_window_state.cpp + test_ui_cov_table_runs.cpp + test_ui_cov_table_mount.cpp + test_ui_cov_table_state_model.cpp + test_ui_cov_h_table_state_model.cpp + test_ui_cov_i_views.cpp + test_ui_cov_i_cell_menu.cpp + test_ui_cov_i_rows_table.cpp + test_ui_cov_i_collection.cpp + test_ui_cov_i_rows_columns.cpp + test_ui_cov_i_stored_state.cpp + test_ui_cov_i_groups.cpp + test_ui_cov_i_table_gestures.cpp + test_ui_cov_i_views_menu.cpp + test_ui_cov_i_sort_dialog.cpp + test_ui_table_config.cpp + bench_interpreter.cpp + bench_mount.cpp + test_ui_table_row_span.cpp + test_ui_interpreter_models.cpp + test_ui_interpreter_table.cpp + test_ui_locale_table.cpp ) -apply_warnings(morph_tests) +# One unit-test executable per source list. Linking every file into a single binary peaks past 13 GB under the +# coverage build; several binaries keep each link a fraction of that and let an edit relink only its own suite. Every +# setting a suite needs is applied here, to every binary alike, so none can miss one: a binary only pays for the +# definitions its files do not read. +function(morph_add_unit_test_binary target) + add_executable(${target} ${ARGN}) -# Several individual test files (schema/rule template instantiation over many -# action/form types, e.g. test_quantity_forms.cpp) have independently pushed -# their .obj's COFF section count past the 32-bit SN_LOFF format's limit -# under MSVC Debug (no /Og folding, full /Zi debug info), aborting with C1128 -# ("number of sections exceeded object file format limit") -- three separate -# unrelated branches hit this on that one file alone, each adding only a -# little more template-instantiation weight. Rather than chase this file by -# file as it recurs, /bigobj is applied to the whole target: harmless on -# Release and on other compilers, and it costs nothing on the files that -# don't need it. -target_compile_options(morph_tests PRIVATE - $<$:/bigobj> -) + target_link_libraries(${target} + PRIVATE + morph::morph + morph_test_main + "$" + ) -# Forwards CMakeLists.txt's project(VERSION ...) into tests/test_version.cpp -# so it can static_assert the checked-in include/morph/version.hpp constants -# never drift from the build system's declared version. -target_compile_definitions(morph_tests PRIVATE - MORPH_CMAKE_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} - MORPH_CMAKE_VERSION_MINOR=${PROJECT_VERSION_MINOR} - MORPH_CMAKE_VERSION_PATCH=${PROJECT_VERSION_PATCH} -) + apply_warnings(${target}) -# The shared forms corpora. Each is one file with several readers -- this -# suite (the compiled evaluators and the forms engine) and the QML suite -- -# all pointed at it from CMake so none can quietly grow its own copy. -target_compile_definitions(morph_tests PRIVATE - MORPH_FORMS_RULE_CORPUS="${CMAKE_CURRENT_SOURCE_DIR}/data/rule_corpus.json" - MORPH_FORMS_INSTANCE_BOUNDS="${CMAKE_CURRENT_SOURCE_DIR}/data/instance_bounds.json" - MORPH_FORMS_BODY_CORPUS="${CMAKE_CURRENT_SOURCE_DIR}/data/body_corpus.json") -# The UI document corpora: JSON files, so another implementation of the -# document and expr/1 can run the same cases. -target_compile_definitions(morph_tests PRIVATE - MORPH_UI_MESSAGES_CORPUS="${CMAKE_CURRENT_SOURCE_DIR}/ui/corpus/messages.json" - MORPH_UI_EXPRESSIONS_CORPUS="${CMAKE_CURRENT_SOURCE_DIR}/ui/corpus/expressions.json" - MORPH_UI_DOCUMENTS_CORPUS="${CMAKE_CURRENT_SOURCE_DIR}/ui/corpus/documents.json") + # Several individual test files (schema/rule template instantiation over many + # action/form types, e.g. test_quantity_forms.cpp) have independently pushed + # their .obj's COFF section count past the 32-bit SN_LOFF format's limit + # under MSVC Debug (no /Og folding, full /Zi debug info), aborting with C1128 + # ("number of sections exceeded object file format limit") -- three separate + # unrelated branches hit this on that one file alone, each adding only a + # little more template-instantiation weight. Rather than chase this file by + # file as it recurs, /bigobj is applied to the whole target: harmless on + # Release and on other compilers, and it costs nothing on the files that + # don't need it. + target_compile_options(${target} PRIVATE + $<$:/bigobj> + ) -# The shipped surfaces of the Qt Quick theme, which the contrast check reads. -target_compile_definitions(morph_tests PRIVATE - MORPH_PAPER_THEME_QML="${CMAKE_SOURCE_DIR}/src/qt_quick/qml/Theme.qml") + # Forwards CMakeLists.txt's project(VERSION ...) into tests/test_version.cpp + # so it can static_assert the checked-in include/morph/version.hpp constants + # never drift from the build system's declared version. + target_compile_definitions(${target} PRIVATE + MORPH_CMAKE_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} + MORPH_CMAKE_VERSION_MINOR=${PROJECT_VERSION_MINOR} + MORPH_CMAKE_VERSION_PATCH=${PROJECT_VERSION_PATCH} + ) -# The authoring goldens: builder output checked against JSON files. -target_compile_definitions(morph_tests PRIVATE MORPH_UI_GOLDEN_DIR="${CMAKE_CURRENT_SOURCE_DIR}/ui/golden") + # The shared forms corpora. Each is one file with several readers -- this + # suite (the compiled evaluators and the forms engine) and the QML suite -- + # all pointed at it from CMake so none can quietly grow its own copy. + target_compile_definitions(${target} PRIVATE + MORPH_FORMS_RULE_CORPUS="${CMAKE_CURRENT_SOURCE_DIR}/data/rule_corpus.json" + MORPH_FORMS_INSTANCE_BOUNDS="${CMAKE_CURRENT_SOURCE_DIR}/data/instance_bounds.json" + MORPH_FORMS_BODY_CORPUS="${CMAKE_CURRENT_SOURCE_DIR}/data/body_corpus.json") -target_include_directories(morph_tests PRIVATE ${CMAKE_BINARY_DIR}/generated) + # The UI document corpora: JSON files, so another implementation of the + # document and expr/1 can run the same cases. + target_compile_definitions(${target} PRIVATE + MORPH_UI_MESSAGES_CORPUS="${CMAKE_CURRENT_SOURCE_DIR}/ui/corpus/messages.json" + MORPH_UI_EXPRESSIONS_CORPUS="${CMAKE_CURRENT_SOURCE_DIR}/ui/corpus/expressions.json" + MORPH_UI_DOCUMENTS_CORPUS="${CMAKE_CURRENT_SOURCE_DIR}/ui/corpus/documents.json") -# MORPH_REQUIRE_VETTED_HMAC is a *deployment* switch aimed at application call -# sites; it rides in on morph::morph's INTERFACE compile definitions. morph's -# own suite deliberately exercises the reference hmacSha256 through its default -# argument (test_session_auth.cpp, test_security_fixes.cpp, -# test_policy_hardening.cpp, test_register_authorization.cpp), so the inherited -# definition is undefined again for this target only. Without this, configuring -# the documented `-DMORPH_REQUIRE_VETTED_HMAC=ON` would fail to build unless -# tests were also switched off — which would leave the option itself untested. -# The guard's own correctness is proven independently by the three try_compile -# probes below, which set/omit the macro per probe regardless of the option. -# -# COMPILE_OPTIONS rather than COMPILE_DEFINITIONS: CMake's compile rule expands -# before , so a `-U` in the flags reliably wins over the `-D` -# inherited from the interface target. -if(MORPH_REQUIRE_VETTED_HMAC) - target_compile_options(morph_tests PRIVATE - "$,/UMORPH_REQUIRE_VETTED_HMAC,-UMORPH_REQUIRE_VETTED_HMAC>") -endif() + # The shipped surfaces of the Qt Quick theme, which the contrast check reads. + target_compile_definitions(${target} PRIVATE + MORPH_PAPER_THEME_QML="${CMAKE_SOURCE_DIR}/src/qt_quick/qml/Theme.qml") -# /w14062 (enabled project-wide) only fires when an enum switch has no -# `default`; test_pinned_facts.cpp's exhaustive enum-cardinality switches keep -# a `default:` (so GCC/Clang's -Wswitch-default does not fire), which would -# otherwise exempt them from MSVC's check. /w14061 fires even with a default -# present. Scoped to this one file rather than project-wide -- see the plan's -# Global Constraints for why. -set_source_files_properties(test_pinned_facts.cpp PROPERTIES - COMPILE_OPTIONS "$<$:/w14061>" -) + # The authoring goldens: builder output checked against JSON files. + target_compile_definitions(${target} PRIVATE MORPH_UI_GOLDEN_DIR="${CMAKE_CURRENT_SOURCE_DIR}/ui/golden") -if(DEFINED AF_SANITIZER) - apply_sanitizers(morph_tests ${AF_SANITIZER}) -endif() -if(AF_COVERAGE) - apply_coverage(morph_tests) -endif() + target_include_directories(${target} PRIVATE ${CMAKE_BINARY_DIR}/generated) + + # MORPH_REQUIRE_VETTED_HMAC is a *deployment* switch aimed at application call + # sites; it rides in on morph::morph's INTERFACE compile definitions. morph's + # own suite deliberately exercises the reference hmacSha256 through its default + # argument (test_session_auth.cpp, test_security_fixes.cpp, + # test_policy_hardening.cpp, test_register_authorization.cpp), so the inherited + # definition is undefined again for this target only. Without this, configuring + # the documented `-DMORPH_REQUIRE_VETTED_HMAC=ON` would fail to build unless + # tests were also switched off — which would leave the option itself untested. + # The guard's own correctness is proven independently by the three try_compile + # probes below, which set/omit the macro per probe regardless of the option. + # + # COMPILE_OPTIONS rather than COMPILE_DEFINITIONS: CMake's compile rule expands + # before , so a `-U` in the flags reliably wins over the `-D` + # inherited from the interface target. + if(MORPH_REQUIRE_VETTED_HMAC) + target_compile_options(${target} PRIVATE + "$,/UMORPH_REQUIRE_VETTED_HMAC,-UMORPH_REQUIRE_VETTED_HMAC>") + endif() + + # /w14062 (enabled project-wide) only fires when an enum switch has no + # `default`; test_pinned_facts.cpp's exhaustive enum-cardinality switches keep + # a `default:` (so GCC/Clang's -Wswitch-default does not fire), which would + # otherwise exempt them from MSVC's check. /w14061 fires even with a default + # present. Scoped to this one file rather than project-wide -- see the plan's + # Global Constraints for why. + set_source_files_properties(test_pinned_facts.cpp PROPERTIES + COMPILE_OPTIONS "$<$:/w14061>" + ) + + if(DEFINED AF_SANITIZER) + apply_sanitizers(${target} ${AF_SANITIZER}) + endif() + if(AF_COVERAGE) + apply_coverage(${target}) + endif() + + include(Catch) + # Every test is sub-second in practice; cap each at 120s so a hung/deadlocked + # test fails fast instead of stalling the whole CI job (observed: a single test + # hanging blocked a Windows runner for over half an hour). + # + # The one case that needed more, the strand race test tagged `[slow]`, went + # with morph's own strand when morph moved to core-cpp's `KeyedStrands`, which + # carries its own race tests. + catch_discover_tests(${target} DISCOVERY_MODE PRE_TEST PROPERTIES TIMEOUT 120) +endfunction() + +morph_add_unit_test_binary(morph_core_tests ${MORPH_CORE_TEST_SOURCES}) +morph_add_unit_test_binary(morph_runtime_tests ${MORPH_RUNTIME_TEST_SOURCES}) +morph_add_unit_test_binary(morph_forms_tests ${MORPH_FORMS_TEST_SOURCES}) +morph_add_unit_test_binary(morph_ui_document_tests ${MORPH_UI_DOCUMENT_TEST_SOURCES}) +morph_add_unit_test_binary(morph_ui_shell_tests ${MORPH_UI_SHELL_TEST_SOURCES}) +morph_add_unit_test_binary(morph_ui_table_tests ${MORPH_UI_TABLE_TEST_SOURCES}) -include(Catch) -# Every test is sub-second in practice; cap each at 120s so a hung/deadlocked -# test fails fast instead of stalling the whole CI job (observed: a single test -# hanging blocked a Windows runner for over half an hour). -# -# The one case that needed more, the strand race test tagged `[slow]`, went -# with morph's own strand when morph moved to core-cpp's `KeyedStrands`, which -# carries its own race tests. -catch_discover_tests(morph_tests DISCOVERY_MODE PRE_TEST PROPERTIES TIMEOUT 120) # ── Two-binary journal-path skew test ─────────────────────────────────────── # The executable form of the journal's data-at-rest contract: an diff --git a/tests/bench/CMakeLists.txt b/tests/bench/CMakeLists.txt index f873222e4..7f467a0d4 100644 --- a/tests/bench/CMakeLists.txt +++ b/tests/bench/CMakeLists.txt @@ -1,6 +1,6 @@ # Opt-in throughput/latency benchmark against a trivial echo model (measures # framework dispatch overhead, not business logic). Built only under -# -DMORPH_BUILD_LOAD_TESTS=ON; never part of the default `morph_tests` target +# -DMORPH_BUILD_LOAD_TESTS=ON; never part of the default unit-test targets # or the fast ctest sweep. See docs/spec/testing_strategy.md. add_executable(morph_bench bench_dispatch_latency.cpp) target_link_libraries(morph_bench PRIVATE morph::morph morph_test_main) diff --git a/tests/bench/bench_dispatch_latency.cpp b/tests/bench/bench_dispatch_latency.cpp index 6ac8aa388..4fbd6697d 100644 --- a/tests/bench/bench_dispatch_latency.cpp +++ b/tests/bench/bench_dispatch_latency.cpp @@ -5,7 +5,7 @@ // business logic). See docs/spec/testing_strategy.md. // // Opt-in: built only under -DMORPH_BUILD_LOAD_TESTS=ON, never part of the -// default `morph_tests` target. Writes a JSON artifact to +// default unit-test targets. Writes a JSON artifact to // BENCH_ARTIFACT_DIR/bench_dispatch_latency.json (the build directory) so CI // can archive successive runs and diff them for regressions; also enforces a // regression gate via CHECK on p99 latency and minimum concurrency-1 diff --git a/tests/bench_interpreter.cpp b/tests/bench_interpreter.cpp index ae0d3bfdc..831d06732 100644 --- a/tests/bench_interpreter.cpp +++ b/tests/bench_interpreter.cpp @@ -3,7 +3,7 @@ // Interpreter measurements: mounting a ui/1 document with a table, and re-running its reactive graph after a // state change. Hidden, so ctest never runs it; run it by tag on a Release build: // -// morph_tests "[.benchmark][interpreter]" +// morph_ui_table_tests "[.benchmark][interpreter]" #include #include @@ -94,7 +94,7 @@ TEST_CASE("interpreter bench: update state read by a mounted screen", "[.benchma // docs/spec/table/table.md, "Benchmarks: every surface". Each case first REQUIREs that the path it times was reached. // Run on a Release build: // -// morph_tests "[.benchmark][baseline]" +// morph_ui_table_tests "[.benchmark][baseline]" namespace { @@ -423,7 +423,7 @@ TEST_CASE("interpreter baseline: U5 a collection of 20,000", "[.benchmark][basel // reloaded list with one row renamed answered, to settled. docs/spec/table/table.md, "Performance". Run on a // Release build: // -// morph_tests "interpreter bench: a collection of 20\,000 rows*" (Catch2 reads an unescaped comma as a list) +// morph_ui_table_tests "interpreter bench: a collection of 20\,000 rows*" (Catch2 reads an unescaped comma as a list) TEST_CASE("interpreter bench: a collection of 20,000 rows: mount, sort, one row edited", "[.benchmark][interpreter]") { constexpr std::size_t kRows = 20'000; bench::WideTableSource const source{{.rows = kRows, .columns = 30, .seed = 1}}; @@ -775,7 +775,7 @@ TEST_CASE("interpreter bench: U1 U2 split between the source and the engine", "[ // D7: the Shift-click that adds a third key to a settled two-key sort of 100,000 document rows, click to settled. // docs/spec/table/table.md, "Performance"; budget 50 ms. Run on a Release build: // -// morph_tests "interpreter bench: a third sort key on 100,000 rows" +// morph_ui_table_tests "interpreter bench: a third sort key on 100,000 rows" TEST_CASE("interpreter bench: a third sort key on 100,000 rows", "[.benchmark][interpreter]") { constexpr std::size_t kRows = 100'000; std::string items; diff --git a/tests/bench_mount.cpp b/tests/bench_mount.cpp index 19b3bb139..379479661 100644 --- a/tests/bench_mount.cpp +++ b/tests/bench_mount.cpp @@ -4,7 +4,7 @@ // "Table row virtualization — design", Task 0): hidden, so ctest never runs it; run it by tag on // a Release build: // -// morph_tests "[.benchmark][mount]" +// morph_ui_table_tests "[.benchmark][mount]" // // Two questions, both load-bearing for that design's Option A (a row's reactive state stays alive // for every key in the data; only its widget comes and goes with the viewport): diff --git a/tests/net/test_push_tables.cpp b/tests/net/test_push_tables.cpp index f612fe808..c9007cc9b 100644 --- a/tests/net/test_push_tables.cpp +++ b/tests/net/test_push_tables.cpp @@ -1014,7 +1014,7 @@ struct WideWindow { // B3, recorded and not a gate. 50 ms each way, through the rows a model-backed table reads: a header sort's new // chain to the accepted page (bound 150 ms), and the filter the last key of a text condition sends to the accepted // page (bound 150 ms after the filter menu's 250 ms debounce, which "a condition applies once after typing pauses" -// gates in morph_tests). Each change costs one round trip: one first-page fetch. Unbuilt on the host that wrote it, +// gates in the unit tests). Each change costs one round trip: one first-page fetch. Unbuilt on the host that wrote it, // and its mutation not run: WindowRows sending a query change twice (restart called a second time in `setSort` or // `setFilter`) makes `firstPages` grow by two. TEST_CASE("table benchmark: a sort change and a text filter over a socket with 50 ms each way", diff --git a/tests/offline_sqlite/CMakeLists.txt b/tests/offline_sqlite/CMakeLists.txt index 6d5944cd6..7738390e5 100644 --- a/tests/offline_sqlite/CMakeLists.txt +++ b/tests/offline_sqlite/CMakeLists.txt @@ -1,7 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # # Built only when MORPH_BUILD_OFFLINE_SQLITE=ON (see top-level CMakeLists.txt); -# keeps the SQLite3 dependency out of the default morph_tests target. +# keeps the SQLite3 dependency out of the default unit-test targets. add_executable(morph_offline_sqlite_tests test_sqlite_offline_queue.cpp diff --git a/tests/push_records_late.cpp b/tests/push_records_late.cpp index 4f4386995..2d3d77c4e 100644 --- a/tests/push_records_late.cpp +++ b/tests/push_records_late.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // // Registers a record after the action that returns it and the effects that name -// it: listed after test_push_effects.cpp in morph_tests, so its static +// it: listed after test_push_effects.cpp in the same test binary, so its static // initialiser runs later. Matching is lazy, so the order must not matter. #include "push_records_late.hpp" diff --git a/tests/soak/CMakeLists.txt b/tests/soak/CMakeLists.txt index 1a53217d9..0e394623c 100644 --- a/tests/soak/CMakeLists.txt +++ b/tests/soak/CMakeLists.txt @@ -1,6 +1,6 @@ # Opt-in soak tests: switchBackend/reconnect churn over many cycles, checking # resource stability rather than a single-shot outcome. Built only under -# -DMORPH_BUILD_LOAD_TESTS=ON; never part of the default `morph_tests` target +# -DMORPH_BUILD_LOAD_TESTS=ON; never part of the default unit-test targets # or the fast ctest sweep. See docs/spec/testing_strategy.md. # # Task 4 adds a second source file (test_soak_reconnect_churn.cpp) to this diff --git a/tests/soak/test_soak_switch_backend.cpp b/tests/soak/test_soak_switch_backend.cpp index 418dc697c..5354d054b 100644 --- a/tests/soak/test_soak_switch_backend.cpp +++ b/tests/soak/test_soak_switch_backend.cpp @@ -7,7 +7,7 @@ // See docs/spec/testing_strategy.md and docs/spec/core/backend.md. // // Opt-in: built only under -DMORPH_BUILD_LOAD_TESTS=ON (see tests/soak/CMakeLists.txt), -// never part of the default `morph_tests` target or the fast ctest sweep. +// never part of the default unit-test targets or the fast ctest sweep. // // Scale: default cycle counts are small enough to run in a few seconds so this // still works as a CI smoke check. For an actual multi-hour soak run, override: diff --git a/tests/test_action_log.cpp b/tests/test_action_log.cpp index 2e124314e..bac173e15 100644 --- a/tests/test_action_log.cpp +++ b/tests/test_action_log.cpp @@ -1148,7 +1148,7 @@ TEST_CASE( // ── setActionLog / defaultActionLog / ScopedActionLog ─────────────────────── // -// morph_tests runs every TEST_CASE in one process, and the default action log +// A test binary runs every TEST_CASE in one process, and the default action log // is process-wide global state — every test here uses ScopedActionLog so its // override never leaks into a test that runs after it, regardless of order. diff --git a/tests/test_coverage_gaps.cpp b/tests/test_coverage_gaps.cpp index f42978501..e5b932ca0 100644 --- a/tests/test_coverage_gaps.cpp +++ b/tests/test_coverage_gaps.cpp @@ -355,7 +355,7 @@ TEST_CASE("Default logger sink lambda body is invoked", "[coverage][logger]") { // This one line reaching the real stderr is the assertion: the default sink // has no seam to observe it through, so exercising its body means letting it // write. Worded to say so, because it is the only log record a default - // `morph_tests` run emits and would otherwise read as a stray error. + // unit-test run emits and would otherwise read as a stray error. morph::log::logError("default-sink-coverage: expected, proves the default sink body ran"); } diff --git a/tests/test_extension_bag_spike.cpp b/tests/test_extension_bag_spike.cpp index 9ee410cb6..5bccd0e1e 100644 --- a/tests/test_extension_bag_spike.cpp +++ b/tests/test_extension_bag_spike.cpp @@ -78,7 +78,7 @@ using EB_Value = glz::generic_u64; // // Stands in for a real "AddCustomField persists to a metadata table" — a single // process-wide registry is enough to answer the schema/decode/journal question -// without building actual persistence. Thread-safe because morph_tests runs +// without building actual persistence. Thread-safe because the unit-test binary runs // Catch2 test cases that may share global state across the binary. class EB_CustomFieldRegistry { public: @@ -402,7 +402,7 @@ TEST_CASE("Extension-bag spike: journal replay reconstructs a custom field's rec // A fresh registry/dispatcher pair, not the process-wide singletons // replay() defaults to — this test's PE_-sibling // (test_journal_payload_evolution.cpp's PEFixture) does the same, so no - // test leans on whatever else morph_tests has registered. + // test leans on whatever else the binary has registered. morph::model::detail::ModelRegistryFactory registry; morph::model::detail::ActionDispatcher dispatcher; registry.registerModel("EB_ContactModel"); diff --git a/tests/test_forms_conformance_corpus.cpp b/tests/test_forms_conformance_corpus.cpp index 37195d7ca..ab528d78d 100644 --- a/tests/test_forms_conformance_corpus.cpp +++ b/tests/test_forms_conformance_corpus.cpp @@ -20,7 +20,7 @@ // // Types here are prefixed CF (Conformance Fixture) and kept at file scope // (not inside an anonymous namespace) -- every test .cpp in this directory -// links into one morph_tests binary, and file-scope, non-anonymous- +// links into one test binary, and file-scope, non-anonymous- // namespaced types risk ODR collisions across translation units // (test_quantity_forms.cpp reserves the QF prefix for the same reason). diff --git a/tests/test_journal_format_versioning.cpp b/tests/test_journal_format_versioning.cpp index 3208e589e..92942abe0 100644 --- a/tests/test_journal_format_versioning.cpp +++ b/tests/test_journal_format_versioning.cpp @@ -181,7 +181,7 @@ TEST_CASE( // Model/action for the replay-equivalence test below. "JV_" is a fresh prefix, // distinct from every other test_*.cpp's BRIDGE_REGISTER_MODEL/ACTION type ids // (those are process-wide singleton registrations shared by the whole -// morph_tests binary, so ids must not collide across translation units). +// test binary, so ids must not collide across translation units). struct JVDeposit { int amount = 0; }; diff --git a/tests/test_remote_reply_envelopes.cpp b/tests/test_remote_reply_envelopes.cpp index 53eea09c6..ac9102182 100644 --- a/tests/test_remote_reply_envelopes.cpp +++ b/tests/test_remote_reply_envelopes.cpp @@ -14,7 +14,7 @@ // of them is read the reply: it takes the one field it needs and lets the rest // go unexamined. A mutation run measures what that costs -- the // `reply(...)` call itself can be deleted at twenty sites in `remote.hpp` -// and `morph_tests` stayed green, because no case at those sites asserts on +// and the unit tests stayed green, because no case at those sites asserts on // the envelope the deleted call would have produced. // // So this file reads the reply, once per kind, on both the accepting and the diff --git a/tests/test_support.hpp b/tests/test_support.hpp index 9c40ab961..54a622d48 100644 --- a/tests/test_support.hpp +++ b/tests/test_support.hpp @@ -62,7 +62,7 @@ struct InlineExecutor : ::morph::exec::IExecutor { /// than shared across the two build trees — that header has no reachable /// include path from `tests/` (`morph_ladder_testkit`'s own include /// directories do not cover the repo-root `tests/` directory, and -/// `test_support.hpp` is a private header for `morph_tests`' own +/// `test_support.hpp` is a private header for the unit-test binaries' own /// translation units, not an installed/exported one) — matching this /// codebase's established convention for small, self-contained internal /// details that would otherwise need new cross-module plumbing to share. @@ -180,7 +180,7 @@ class DeterministicExecutor : public ::morph::exec::IExecutor { // take the step from the environment so that the two arms differ in nothing // else — not even code layout: // -// poll step | inside waitUntil | morph_tests wall | serial ctest +// poll step | inside waitUntil | test-binary wall | serial ctest // ----------+------------------+------------------+--------------- // 5 ms | 17.27 s (n=3) | 84.9 / 88.2 s | 110.6 / 111.5 s // 1 ms | 7.53 s (n=3) | 75.2 / 77.5 s | 102.0 / 104.3 s @@ -190,7 +190,7 @@ class DeterministicExecutor : public ::morph::exec::IExecutor { // quantisation and nothing else. It is not more waiting; it is the same waiting // rounded up. The wall-clock delta agrees with it, about 10 s on the binary and // about 8 s under `ctest`, which is how CI runs the suite. Roughly 11% of a -// `morph_tests` run is this step. +// test-binary run is this step. // // The step is nonetheless left at 5 ms, and lowering it is a separate change // that needs its own evidence. 433 call sites inherit this default, and the diff --git a/tests/test_views.cpp b/tests/test_views.cpp index e26413431..16d3c4fb8 100644 --- a/tests/test_views.cpp +++ b/tests/test_views.cpp @@ -24,7 +24,7 @@ // --------------------------------------------------------------------------- // A miniature registered model/action set (unique "Vt" prefix — this file is -// linked into the same morph_tests binary as every other test TU, so type and +// linked into the same test binary as the other test TU, so type and // registration names must not collide with any other test file's). // --------------------------------------------------------------------------- From aa9a7b00e9ebd302691a383d6d16dfa89834dcd9 Mon Sep 17 00:00:00 2001 From: Yaraslau Tamashevich Date: Sat, 28 Nov 2026 20:21:41 +0100 Subject: [PATCH 6/8] test: keep the bench's run line inside the column limit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01No1NzndCGtpCccptcyk6Tb --- tests/bench_interpreter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/bench_interpreter.cpp b/tests/bench_interpreter.cpp index 831d06732..20013d17b 100644 --- a/tests/bench_interpreter.cpp +++ b/tests/bench_interpreter.cpp @@ -423,7 +423,9 @@ TEST_CASE("interpreter baseline: U5 a collection of 20,000", "[.benchmark][basel // reloaded list with one row renamed answered, to settled. docs/spec/table/table.md, "Performance". Run on a // Release build: // -// morph_ui_table_tests "interpreter bench: a collection of 20\,000 rows*" (Catch2 reads an unescaped comma as a list) +// morph_ui_table_tests "interpreter bench: a collection of 20\,000 rows*" +// +// The comma is escaped because Catch2 reads an unescaped one as a list of test names. TEST_CASE("interpreter bench: a collection of 20,000 rows: mount, sort, one row edited", "[.benchmark][interpreter]") { constexpr std::size_t kRows = 20'000; bench::WideTableSource const source{{.rows = kRows, .columns = 30, .seed = 1}}; From feb380238000eb1b2e8665ea2e2c7446c6d18470 Mon Sep 17 00:00:00 2001 From: Yaraslau Tamashevich Date: Sat, 28 Nov 2026 21:59:22 +0100 Subject: [PATCH 7/8] fix(ui): the backend conformance suite reports a widget the probe did not find The layout cases measured the widgets the probe returned by dereferencing them, so a backend that reported no widget where a case expected one made the suite read through a null pointer (UBSan: reference binding to null pointer of type 'const Widget') instead of failing the case. Geometry::of and textOf now take the pointer and fail the case when it is null, and containerOf does the same for the cases that open a child as a container. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01No1NzndCGtpCccptcyk6Tb --- .../morph/ui/testing/backend_conformance.hpp | 291 ++++++++++-------- 1 file changed, 158 insertions(+), 133 deletions(-) diff --git a/include/morph/ui/testing/backend_conformance.hpp b/include/morph/ui/testing/backend_conformance.hpp index 7765eafa4..c27dacf7a 100644 --- a/include/morph/ui/testing/backend_conformance.hpp +++ b/include/morph/ui/testing/backend_conformance.hpp @@ -1929,6 +1929,24 @@ class Geometry { return bounds.value_or(WidgetBounds{}); } + /// @brief Where @p widget is drawn; zero, with the case failed, when the probe found no widget there or reads + /// no geometry. A case measures what the probe reported, and a backend under test can report nothing. + /// @param widget The widget, or null when the probe found none. + /// @return Its bounds. + [[nodiscard]] WidgetBounds of(Widget const* widget) { + _checks->that(widget != nullptr, "the probe reports no widget where the case expects one"); + return widget == nullptr ? WidgetBounds{} : of(*widget); + } + + /// @brief Where @p text draws its lines; zero, with the case failed, when the probe found no widget there or + /// reads none. + /// @param text The text, or null when the probe found none. + /// @return The box around its lines. + [[nodiscard]] WidgetBounds textOf(Widget const* text) { + _checks->that(text != nullptr, "the probe reports no widget where the case expects one"); + return text == nullptr ? WidgetBounds{} : textOf(*text); + } + /// @brief Checks that a length is what it should be, within one unit. /// @param what What is measured, for the message. /// @param expected The length it should be. @@ -1973,6 +1991,13 @@ struct Measured { std::vector children; }; +/// @brief @p widget as a container; null when the probe found no widget there or it holds no children. +/// @param widget The widget, or null. +/// @return The container, or null. +[[nodiscard]] inline ContainerWidget const* containerOf(Widget const* widget) { + return widget == nullptr ? nullptr : asContainer(*widget); +} + /// @brief The container a case measures, inside the root `insideColumn` or `insideRow` made. /// @param probe The backend under test. /// @param view The mount. @@ -2001,8 +2026,8 @@ struct Measured { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the row holds two children"); if (children.size() == 2) { - geometry.near("the capped stretch child's width", 20, geometry.of(*children.at(0)).width); - geometry.near("its stretch sibling's width", 40, geometry.of(*children.at(1)).width); + geometry.near("the capped stretch child's width", 20, geometry.of(children.at(0)).width); + geometry.near("its stretch sibling's width", 40, geometry.of(children.at(1)).width); } return checks.result(); } @@ -2024,13 +2049,13 @@ struct Measured { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the column holds two texts"); if (children.size() == 2) { - WidgetBounds const box = geometry.of(*children.at(0)); - WidgetBounds const ink = geometry.textOf(*children.at(0)); + WidgetBounds const box = geometry.of(children.at(0)); + WidgetBounds const ink = geometry.textOf(children.at(0)); geometry.near("the end-aligned text's right edge", box.x + 20, ink.x + ink.width); checks.that(ink.x - box.x > 15, "the end-aligned text starts " + std::to_string(ink.x - box.x) + " units in, not near the end of its 20 units"); - WidgetBounds const startBox = geometry.of(*children.at(1)); - WidgetBounds const startInk = geometry.textOf(*children.at(1)); + WidgetBounds const startBox = geometry.of(children.at(1)); + WidgetBounds const startInk = geometry.textOf(children.at(1)); geometry.near("the start-aligned text's left edge", startBox.x, startInk.x); } return checks.result(); @@ -2050,8 +2075,8 @@ struct Measured { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the row holds two children"); if (children.size() == 2) { - geometry.near("the percent child's width", 15, geometry.of(*children.at(0)).width); - geometry.near("its stretch sibling's width", 45, geometry.of(*children.at(1)).width); + geometry.near("the percent child's width", 15, geometry.of(children.at(0)).width); + geometry.near("its stretch sibling's width", 45, geometry.of(children.at(1)).width); } return checks.result(); } @@ -2070,8 +2095,8 @@ struct Measured { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the row holds two children"); if (children.size() == 2) { - geometry.near("the capped percent child's width", 10, geometry.of(*children.at(0)).width); - geometry.near("its stretch sibling's width", 50, geometry.of(*children.at(1)).width); + geometry.near("the capped percent child's width", 10, geometry.of(children.at(0)).width); + geometry.near("its stretch sibling's width", 50, geometry.of(children.at(1)).width); } return checks.result(); } @@ -2107,7 +2132,7 @@ struct Measured { std::vector widths; widths.reserve(panes.size()); for (Widget const* const pane : panes) { - widths.push_back(geometry.of(*pane).width); + widths.push_back(geometry.of(pane).width); } return widths; }; @@ -2144,7 +2169,7 @@ struct Measured { std::vector const panes = measured(probe, *view).children; checks.that(panes.size() == 2, "the splitter holds two panes"); if (panes.size() == 2) { - geometry.near("a pane capped at 8", 8, geometry.of(*panes.at(0)).width); + geometry.near("a pane capped at 8", 8, geometry.of(panes.at(0)).width); } return checks.result(); } @@ -2168,10 +2193,10 @@ struct Measured { "both columns hold two children"); if (padded.children.size() == 2 && plain.children.size() == 2 && padded.container != nullptr && plain.container != nullptr) { - WidgetBounds const box = geometry.of(*padded.container); - WidgetBounds const first = geometry.of(*padded.children.at(0)); - WidgetBounds const bareBox = geometry.of(*plain.container); - WidgetBounds const bareFirst = geometry.of(*plain.children.at(0)); + WidgetBounds const box = geometry.of(padded.container); + WidgetBounds const first = geometry.of(padded.children.at(0)); + WidgetBounds const bareBox = geometry.of(plain.container); + WidgetBounds const bareFirst = geometry.of(plain.children.at(0)); checks.that(first.x > box.x, "a padded column's child starts inside its left edge"); checks.that(bareFirst.x == bareBox.x, "an unpadded column's child starts at its left edge"); checks.that(bareFirst.y == bareBox.y, "an unpadded column's child starts at its top edge"); @@ -2198,10 +2223,10 @@ struct Measured { atEnds.container != nullptr; checks.that(found, "both columns hold one child"); if (found) { - WidgetBounds const sideBox = geometry.of(*atSides.container); - WidgetBounds const sideChild = geometry.of(*atSides.children.at(0)); - WidgetBounds const endBox = geometry.of(*atEnds.container); - WidgetBounds const endChild = geometry.of(*atEnds.children.at(0)); + WidgetBounds const sideBox = geometry.of(atSides.container); + WidgetBounds const sideChild = geometry.of(atSides.children.at(0)); + WidgetBounds const endBox = geometry.of(atEnds.container); + WidgetBounds const endChild = geometry.of(atEnds.children.at(0)); checks.that(sideChild.y == sideBox.y, "a column padded [0, 4] starts its child at its top edge"); checks.that(sideChild.x > sideBox.x, "a column padded [0, 4] starts its child inside its left edge"); checks.that(endChild.x == endBox.x, "a column padded [4, 0] starts its child at its left edge"); @@ -2224,9 +2249,9 @@ struct Measured { Measured const found = measured(probe, view); checks.that(found.container != nullptr && found.children.size() == 2, "the column holds two children"); if (found.container != nullptr && found.children.size() == 2) { - WidgetBounds const box = geometry.of(*found.container); - WidgetBounds const inset = geometry.of(*found.children.at(0)); - WidgetBounds const bleeding = geometry.of(*found.children.at(1)); + WidgetBounds const box = geometry.of(found.container); + WidgetBounds const inset = geometry.of(found.children.at(0)); + WidgetBounds const bleeding = geometry.of(found.children.at(1)); checks.that(inset.x > box.x, "the sibling stays inside the column's padding"); geometry.near("the bleeding child's left edge, against the column's", box.x, bleeding.x); geometry.near("the bleeding child's width, against the column's", box.width, bleeding.width); @@ -2248,13 +2273,13 @@ struct Measured { Checks checks; Geometry geometry{probe, checks}; Measured const found = measured(probe, view); - ContainerWidget const* const held = found.children.size() == 1 ? asContainer(*found.children.at(0)) : nullptr; + ContainerWidget const* const held = found.children.size() == 1 ? containerOf(found.children.at(0)) : nullptr; checks.that(found.container != nullptr && held != nullptr && probe.childCount(*held) == 2, "the panel holds a column of two children"); if (found.container != nullptr && held != nullptr && probe.childCount(*held) == 2) { - WidgetBounds const frame = geometry.of(*found.container); - WidgetBounds const bleeding = geometry.of(*probe.childAt(*held, 0)); - WidgetBounds const inside = geometry.of(*probe.childAt(*held, 1)); + WidgetBounds const frame = geometry.of(found.container); + WidgetBounds const bleeding = geometry.of(probe.childAt(*held, 0)); + WidgetBounds const inside = geometry.of(probe.childAt(*held, 1)); // The frame's border is a cell or a pixel or two; the padding is several cells. checks.that(bleeding.x >= frame.x && bleeding.x - frame.x <= 1.0, "the bleeding child starts at the frame's inner left edge, not past the padding: it is " + @@ -2289,16 +2314,16 @@ struct Measured { probe.settle(); Geometry geometry{probe, checks}; Measured const found = measured(probe, view); - ContainerWidget const* const page = found.children.empty() ? nullptr : asContainer(*found.children.at(0)); + ContainerWidget const* const page = found.children.empty() ? nullptr : containerOf(found.children.at(0)); ContainerWidget const* const held = - page != nullptr && probe.childCount(*page) == 1 ? asContainer(*probe.childAt(*page, 0)) : nullptr; + page != nullptr && probe.childCount(*page) == 1 ? containerOf(probe.childAt(*page, 0)) : nullptr; std::string const where = scrolls ? " (a page that scrolls)" : ""; checks.that(found.container != nullptr && held != nullptr && probe.childCount(*held) >= 2, "the tabs node holds a page with a column of children" + where); if (found.container != nullptr && held != nullptr && probe.childCount(*held) >= 2) { - WidgetBounds const node = geometry.of(*found.container); - WidgetBounds const bleeding = geometry.of(*probe.childAt(*held, 0)); - WidgetBounds const inside = geometry.of(*probe.childAt(*held, 1)); + WidgetBounds const node = geometry.of(found.container); + WidgetBounds const bleeding = geometry.of(probe.childAt(*held, 0)); + WidgetBounds const inside = geometry.of(probe.childAt(*held, 1)); geometry.near("the bleeding child's left edge, against the tabs node's" + where, node.x, bleeding.x); geometry.near("the bleeding child's width, against the tabs node's" + where, node.width, bleeding.width); checks.that(inside.x - node.x >= 1.5, "the sibling stays inside the page inset" + where + ": it is " + @@ -2321,7 +2346,7 @@ struct Measured { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the row holds two children"); if (children.size() == 2) { - geometry.near("a content text with minWidth 30", 30, geometry.of(*children.at(0)).width); + geometry.near("a content text with minWidth 30", 30, geometry.of(children.at(0)).width); } return checks.result(); } @@ -2340,9 +2365,9 @@ struct Measured { std::vector const& children = inside.children; checks.that(children.size() == 1, "the column holds one child"); if (children.size() == 1) { - WidgetBounds const outer = geometry.of(*inside.container); + WidgetBounds const outer = geometry.of(inside.container); geometry.near("the column's width", 70, outer.width); - WidgetBounds const card = geometry.of(*children.at(0)); + WidgetBounds const card = geometry.of(children.at(0)); geometry.near("a stretch child with maxWidth 44 across a 70-unit column", 44, card.width); geometry.near("its left edge, at the column's start", outer.x, card.x); } @@ -2364,8 +2389,8 @@ struct Measured { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the column holds two children"); if (children.size() == 2) { - geometry.near("the capped stretch child's height", 5, geometry.of(*children.at(0)).height); - geometry.near("its stretch sibling's height", 15, geometry.of(*children.at(1)).height); + geometry.near("the capped stretch child's height", 5, geometry.of(children.at(0)).height); + geometry.near("its stretch sibling's height", 15, geometry.of(children.at(1)).height); } return checks.result(); } @@ -2383,8 +2408,8 @@ struct Measured { Measured const inside = measured(probe, view); checks.that(inside.children.size() == 1, "the row holds one child"); if (inside.children.size() == 1) { - WidgetBounds const outer = geometry.of(*inside.container); - WidgetBounds const text = geometry.of(*inside.children.at(0)); + WidgetBounds const outer = geometry.of(inside.container); + WidgetBounds const text = geometry.of(inside.children.at(0)); geometry.near("the text's height", 1, text.height); geometry.near("the text's offset down the row", 1, text.y - outer.y); } @@ -2408,9 +2433,9 @@ struct Measured { if (inside.children.size() != 3) { continue; } - WidgetBounds const outer = geometry.of(*inside.container); - WidgetBounds const first = geometry.of(*inside.children.at(0)); - WidgetBounds const last = geometry.of(*inside.children.at(2)); + WidgetBounds const outer = geometry.of(inside.container); + WidgetBounds const first = geometry.of(inside.children.at(0)); + WidgetBounds const last = geometry.of(inside.children.at(2)); geometry.near(justify == Justify::End ? "end: the last child's end" : "between: the last child's end", outer.y + outer.height, last.y + last.height); if (justify == Justify::Between) { @@ -2443,8 +2468,8 @@ struct Measured { if (inside.children.size() != 1) { continue; } - WidgetBounds const outer = geometry.of(*inside.container); - WidgetBounds const placed = geometry.of(*inside.children.at(0)); + WidgetBounds const outer = geometry.of(inside.container); + WidgetBounds const placed = geometry.of(inside.children.at(0)); double const before = placed.x - outer.x; double const after = (outer.x + outer.width) - (placed.x + placed.width); geometry.near(own ? "alignSelf center: the capped child's width" : "align center: the card's width", @@ -2498,9 +2523,9 @@ struct Measured { std::vector const textRow = table == nullptr ? std::vector{} : rowCells(probe, *table, 1); checks.that(badgeRow.size() == 1 && textRow.size() == 1, "the table holds two rows of one cell"); if (badgeRow.size() == 1 && textRow.size() == 1) { - WidgetBounds const outer = geometry.of(*table); - WidgetBounds const badge = geometry.of(*badgeRow.front()); - WidgetBounds const text = geometry.of(*textRow.front()); + WidgetBounds const outer = geometry.of(table); + WidgetBounds const badge = geometry.of(badgeRow.front()); + WidgetBounds const text = geometry.of(textRow.front()); geometry.near("the badge's right edge, against the column's text's", text.x + text.width, badge.x + badge.width); checks.that(badge.x - outer.x > 15, "the badge is not at the end of its 30-unit column: it starts " + @@ -2539,9 +2564,9 @@ struct Measured { std::vector const data = table == nullptr ? std::vector{} : rowCells(probe, *table, 1); checks.that(heading.size() == 1 && data.size() == 2, "the table holds a heading of one cell and a row of two"); if (heading.size() == 1 && data.size() == 2) { - WidgetBounds const across = geometry.of(*heading.front()); - WidgetBounds const first = geometry.of(*data.front()); - WidgetBounds const second = geometry.of(*data.back()); + WidgetBounds const across = geometry.of(heading.front()); + WidgetBounds const first = geometry.of(data.front()); + WidgetBounds const second = geometry.of(data.back()); geometry.near("the heading cell's left edge, against the first column's cell's", first.x, across.x); geometry.near("the heading cell's right edge, against the second column's cell's", second.x + second.width, across.x + across.width); @@ -2592,10 +2617,10 @@ struct Measured { std::vector const second = table == nullptr ? std::vector{} : rowCells(probe, *table, 1); checks.that(second.size() == 2, "the table holds a row of two cells at its second"); if (first.size() == 2 && second.size() == 2 && last.size() == 2) { - WidgetBounds const spanning = geometry.of(*first.front()); - WidgetBounds const top = geometry.of(*first.back()); - WidgetBounds const bottom = geometry.of(*last.back()); - WidgetBounds const covered = geometry.of(*second.front()); + WidgetBounds const spanning = geometry.of(first.front()); + WidgetBounds const top = geometry.of(first.back()); + WidgetBounds const bottom = geometry.of(last.back()); + WidgetBounds const covered = geometry.of(second.front()); checks.that(covered.width <= 0 || covered.height <= 0, "the covered cell has no bounds: " + std::to_string(covered.width) + " by " + std::to_string(covered.height)); @@ -2635,7 +2660,7 @@ struct Measured { // the click would let a frontend that hides the cell pass. Geometry geometry{probe, checks}; if (first.size() == 2 && last.size() == 2) { - bool const drawn = geometry.of(*first.front()).height > 0; + bool const drawn = geometry.of(first.front()).height > 0; checks.that(drawn, "the spanning cell has bounds to click on"); if (drawn) { probe.clickAt(*first.front(), *last.back()); @@ -2672,9 +2697,9 @@ struct Measured { std::vector const cells = table == nullptr ? std::vector{} : rowCells(probe, *table, 0); checks.that(cells.size() == 3, "the row holds three cells"); if (cells.size() == 3) { - WidgetBounds const tall = geometry.of(*cells.at(0)); - WidgetBounds const top = geometry.of(*cells.at(1)); - WidgetBounds const bottom = geometry.of(*cells.at(2)); + WidgetBounds const tall = geometry.of(cells.at(0)); + WidgetBounds const top = geometry.of(cells.at(1)); + WidgetBounds const bottom = geometry.of(cells.at(2)); checks.that(tall.height >= 4.5, "the five-line cell is " + std::to_string(tall.height) + " units tall"); geometry.near("a valign Start cell's top, against the row's", tall.y, top.y); geometry.near("a valign End cell's bottom, against the row's", tall.y + tall.height, bottom.y + bottom.height); @@ -2704,8 +2729,8 @@ struct Measured { std::vector const shorter = table == nullptr ? std::vector{} : rowCells(probe, *table, 1); checks.that(longer.size() == 1 && shorter.size() == 1, "the table holds two rows of one cell"); if (longer.size() == 1 && shorter.size() == 1) { - geometry.near("the long text's height, against the short text's", geometry.of(*shorter.front()).height, - geometry.of(*longer.front()).height); + geometry.near("the long text's height, against the short text's", geometry.of(shorter.front()).height, + geometry.of(longer.front()).height); } return checks.result(); } @@ -2961,10 +2986,10 @@ struct SelectionReport { Measured const inside = measured(probe, view); checks.that(inside.children.size() == 2, "the column holds a scroll and a bar"); if (inside.children.size() == 2) { - WidgetBounds const outer = geometry.of(*inside.container); - WidgetBounds const bar = geometry.of(*inside.children.at(1)); + WidgetBounds const outer = geometry.of(inside.container); + WidgetBounds const bar = geometry.of(inside.children.at(1)); geometry.near("the bar's bottom, at the column's", outer.y + outer.height, bar.y + bar.height); - checks.that(geometry.of(*inside.children.at(0)).height < 20, + checks.that(geometry.of(inside.children.at(0)).height < 20, "the scroll is as tall as the column or taller, so the bar is pushed out of it"); } return checks.result(); @@ -3026,8 +3051,8 @@ struct SelectionReport { checks.that(false, "the row is a column of a scroll and a bar"); return checks.result(); } - WidgetBounds const outer = geometry.of(*inside.container); - WidgetBounds const bar = geometry.of(*probe.childAt(*content, 1)); + WidgetBounds const outer = geometry.of(inside.container); + WidgetBounds const bar = geometry.of(probe.childAt(*content, 1)); geometry.near("the bar's bottom, at the column's", outer.y + outer.height, bar.y + bar.height); return checks.result(); } @@ -3071,7 +3096,7 @@ struct WrappingRow { if (found.children.size() != 2) { return 1.0; } - return geometry.of(*found.children.at(1)).x - geometry.of(*found.children.at(0)).x - 12.0; + return geometry.of(found.children.at(1)).x - geometry.of(found.children.at(0)).x - 12.0; } /// @brief Case: a wrapping row starts a line only when its next child does not fit. @@ -3094,11 +3119,11 @@ struct WrappingRow { mountWrappingRow(probe, static_cast(std::ceil(36.0 + (2.0 * step))) + 1, texts()); checks.that(wide.measured.children.size() == 3, "the wrapping row holds three texts"); if (wide.measured.children.size() == 3) { - double const top = geometry.of(*wide.measured.children.at(0)).y; + double const top = geometry.of(wide.measured.children.at(0)).y; geometry.near("the second text's top, on the first's line", top, - geometry.of(*wide.measured.children.at(1)).y); + geometry.of(wide.measured.children.at(1)).y); geometry.near("the third text's top, on the first's line", top, - geometry.of(*wide.measured.children.at(2)).y); + geometry.of(wide.measured.children.at(2)).y); } } { @@ -3106,9 +3131,9 @@ struct WrappingRow { WrappingRow const narrow = mountWrappingRow(probe, 30, texts()); checks.that(narrow.measured.children.size() == 3, "the narrow wrapping row holds three texts"); if (narrow.measured.children.size() == 3) { - WidgetBounds const row = geometry.of(*narrow.measured.container); - WidgetBounds const first = geometry.of(*narrow.measured.children.at(0)); - WidgetBounds const third = geometry.of(*narrow.measured.children.at(2)); + WidgetBounds const row = geometry.of(narrow.measured.container); + WidgetBounds const first = geometry.of(narrow.measured.children.at(0)); + WidgetBounds const third = geometry.of(narrow.measured.children.at(2)); geometry.near("the third text's left, at the row's", row.x, third.x); checks.that(third.y >= first.y + first.height - 0.5, "the third text is below the first line"); geometry.near("the row's height, the two lines'", third.y + third.height - row.y, row.height); @@ -3136,8 +3161,8 @@ struct WrappingRow { WrappingRow const wide = mountWrappingRow(probe, 40, children()); checks.that(wide.measured.children.size() == 2, "the wrapping row holds two texts"); if (wide.measured.children.size() == 2) { - WidgetBounds const stretch = geometry.of(*wide.measured.children.at(0)); - WidgetBounds const fixed = geometry.of(*wide.measured.children.at(1)); + WidgetBounds const stretch = geometry.of(wide.measured.children.at(0)); + WidgetBounds const fixed = geometry.of(wide.measured.children.at(1)); geometry.near("the stretch text's width, the line less the fixed text and a step", 28.0 - step, stretch.width); geometry.near("the fixed text's top, on the stretch text's line", stretch.y, fixed.y); @@ -3147,8 +3172,8 @@ struct WrappingRow { WrappingRow const narrow = mountWrappingRow(probe, 20, children()); checks.that(narrow.measured.children.size() == 2, "the narrow wrapping row holds two texts"); if (narrow.measured.children.size() == 2) { - WidgetBounds const stretch = geometry.of(*narrow.measured.children.at(0)); - WidgetBounds const fixed = geometry.of(*narrow.measured.children.at(1)); + WidgetBounds const stretch = geometry.of(narrow.measured.children.at(0)); + WidgetBounds const fixed = geometry.of(narrow.measured.children.at(1)); geometry.near("the stretch text's width, alone on its line", 20.0, stretch.width); checks.that(fixed.y >= stretch.y + stretch.height - 0.5, "the fixed text is on the next line"); } @@ -3162,8 +3187,8 @@ struct WrappingRow { WrappingRow const row = mountWrappingRow(probe, 30, std::move(made)); checks.that(row.measured.children.size() == 2, "the row of a short stretch text holds two texts"); if (row.measured.children.size() == 2) { - WidgetBounds const stretch = geometry.of(*row.measured.children.at(0)); - WidgetBounds const fixed = geometry.of(*row.measured.children.at(1)); + WidgetBounds const stretch = geometry.of(row.measured.children.at(0)); + WidgetBounds const fixed = geometry.of(row.measured.children.at(1)); geometry.near("the fixed text's top, on a short stretch text's line", stretch.y, fixed.y); } } @@ -3307,18 +3332,18 @@ struct WrappingRow { Geometry geometry{probe, checks}; Measured const inside = measured(probe, view); checks.that(inside.children.size() == 1, "the column holds the splitter"); - ContainerWidget const* const panes = inside.children.size() == 1 ? asContainer(*inside.children.at(0)) : nullptr; + ContainerWidget const* const panes = inside.children.size() == 1 ? containerOf(inside.children.at(0)) : nullptr; checks.that(panes != nullptr && probe.childCount(*panes) == 2, "the splitter holds two panes"); if (panes != nullptr && probe.childCount(*panes) == 2) { - WidgetBounds const outerBox = geometry.of(*inside.container); + WidgetBounds const outerBox = geometry.of(inside.container); for (std::size_t index = 0; index < 2; ++index) { - geometry.near("a pane's height", 20, geometry.of(*probe.childAt(*panes, index)).height); + geometry.near("a pane's height", 20, geometry.of(probe.childAt(*panes, index)).height); } - ContainerWidget const* const pinnedPane = asContainer(*probe.childAt(*panes, 1)); + ContainerWidget const* const pinnedPane = containerOf(probe.childAt(*panes, 1)); checks.that(pinnedPane != nullptr && probe.childCount(*pinnedPane) == 2, "the second pane holds a scroll and a bar"); if (pinnedPane != nullptr && probe.childCount(*pinnedPane) == 2) { - WidgetBounds const bar = geometry.of(*probe.childAt(*pinnedPane, 1)); + WidgetBounds const bar = geometry.of(probe.childAt(*pinnedPane, 1)); geometry.near("the bar's bottom, at the column's", outerBox.y + outerBox.height, bar.y + bar.height); } } @@ -3379,8 +3404,8 @@ struct WrappingRow { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the grid holds two cells"); if (children.size() == 2) { - geometry.near("the fixed(10) track's cell width", 10, geometry.of(*children.at(0)).width); - geometry.near("the stretch track's cell width", 30, geometry.of(*children.at(1)).width); + geometry.near("the fixed(10) track's cell width", 10, geometry.of(children.at(0)).width); + geometry.near("the stretch track's cell width", 30, geometry.of(children.at(1)).width); } return checks.result(); } @@ -3400,8 +3425,8 @@ struct WrappingRow { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the grid holds two cells"); if (children.size() == 2) { - geometry.near("the short cell's width", 30, geometry.of(*children.at(0)).width); - geometry.near("the long cell's width", 30, geometry.of(*children.at(1)).width); + geometry.near("the short cell's width", 30, geometry.of(children.at(0)).width); + geometry.near("the long cell's width", 30, geometry.of(children.at(1)).width); } return checks.result(); } @@ -3451,7 +3476,7 @@ struct MinColumnGridSpec { if (found.children.empty()) { return made; } - if (ContainerWidget const* const cells = asContainer(*found.children.at(0)); cells != nullptr) { + if (ContainerWidget const* const cells = containerOf(found.children.at(0)); cells != nullptr) { for (std::size_t index = 0; index < probe.childCount(*cells); ++index) { made.cells.push_back(probe.childAt(*cells, index)); } @@ -3472,9 +3497,9 @@ struct MinColumnGridSpec { Geometry geometry{probe, checks}; checks.that(made.cells.size() == 3, "the grid holds three cells"); if (made.cells.size() == 3) { - WidgetBounds const first = geometry.of(*made.cells.at(0)); - WidgetBounds const second = geometry.of(*made.cells.at(1)); - WidgetBounds const third = geometry.of(*made.cells.at(2)); + WidgetBounds const first = geometry.of(made.cells.at(0)); + WidgetBounds const second = geometry.of(made.cells.at(1)); + WidgetBounds const third = geometry.of(made.cells.at(2)); geometry.near("the third cell's left edge, under the first", first.x, third.x); checks.that(second.x > first.x + 1.0, "the second cell is in a column of its own"); checks.that(third.y > first.y + 0.5, "the third cell starts the next row"); @@ -3492,9 +3517,9 @@ struct MinColumnGridSpec { Geometry geometry{probe, checks}; checks.that(made.cells.size() == 3, "the grid holds three cells"); if (made.cells.size() == 3) { - WidgetBounds const first = geometry.of(*made.cells.at(0)); - WidgetBounds const second = geometry.of(*made.cells.at(1)); - WidgetBounds const third = geometry.of(*made.cells.at(2)); + WidgetBounds const first = geometry.of(made.cells.at(0)); + WidgetBounds const second = geometry.of(made.cells.at(1)); + WidgetBounds const third = geometry.of(made.cells.at(2)); geometry.near("the third cell's top, on the first's row", first.y, third.y); checks.that(second.x > first.x + 1.0 && third.x > second.x + 1.0, "the cells are in three columns"); } @@ -3510,9 +3535,9 @@ struct MinColumnGridSpec { Geometry geometry{probe, checks}; checks.that(made.cells.size() == 3, "the grid holds three cells"); if (made.cells.size() == 3) { - WidgetBounds const first = geometry.of(*made.cells.at(0)); - WidgetBounds const second = geometry.of(*made.cells.at(1)); - WidgetBounds const third = geometry.of(*made.cells.at(2)); + WidgetBounds const first = geometry.of(made.cells.at(0)); + WidgetBounds const second = geometry.of(made.cells.at(1)); + WidgetBounds const third = geometry.of(made.cells.at(2)); geometry.near("the second cell's left edge, under the first", first.x, second.x); geometry.near("the third cell's left edge, under the first", first.x, third.x); checks.that(first.y + 0.5 < second.y && second.y + 0.5 < third.y, "the rows go down in order"); @@ -3532,8 +3557,8 @@ struct MinColumnGridSpec { Geometry geometry{probe, checks}; checks.that(made.cells.size() == 3, "the grid holds three cells"); if (made.cells.size() == 3) { - WidgetBounds const first = geometry.of(*made.cells.at(0)); - WidgetBounds const third = geometry.of(*made.cells.at(2)); + WidgetBounds const first = geometry.of(made.cells.at(0)); + WidgetBounds const third = geometry.of(made.cells.at(2)); geometry.near("the third cell's left edge, under the first (two columns)", first.x, third.x); checks.that(third.y > first.y + 0.5, "the third cell starts the next row"); } @@ -3549,9 +3574,9 @@ struct MinColumnGridSpec { Geometry geometry{probe, checks}; checks.that(made.cells.size() == 3 && made.after != nullptr, "the grid holds three cells and a text follows it"); if (made.cells.size() == 3 && made.after != nullptr) { - WidgetBounds const first = geometry.of(*made.cells.at(0)); - WidgetBounds const last = geometry.of(*made.cells.at(2)); - WidgetBounds const after = geometry.of(*made.after); + WidgetBounds const first = geometry.of(made.cells.at(0)); + WidgetBounds const last = geometry.of(made.cells.at(2)); + WidgetBounds const after = geometry.of(made.after); checks.that(last.y > first.y + 0.5, "the third cell starts a second row"); checks.that(after.y + 0.5 >= last.y + last.height, "the text after the grid is below its last row"); } @@ -3581,15 +3606,15 @@ struct MinColumnGridSpec { checks.that(found.container != nullptr && found.children.size() == 2 && cell != nullptr, "the grid holds two cells"); if (found.container != nullptr && found.children.size() == 2 && cell != nullptr) { - double const width = geometry.of(*found.container).width; - double const natural = geometry.of(*cell).width; + double const width = geometry.of(found.container).width; + double const natural = geometry.of(cell).width; checks.that(natural >= 8, "ten characters are " + std::to_string(natural) + " units wide on their own"); // The columns are as wide as the widest cell, rounded up to a whole pixel at most, so the grid is two of it; // the sum of the columns' naturals would be about one. checks.that(width >= (2 * natural) - 0.5 && width <= (2 * natural) + 1, "the grid is " + std::to_string(width) + " units wide, not twice its ten-character cell (" + std::to_string(natural) + " units)"); - double const second = geometry.of(*found.children.at(1)).width; + double const second = geometry.of(found.children.at(1)).width; checks.that(second >= 8, "the second cell keeps its ten characters: it is " + std::to_string(second) + " units wide"); } @@ -3610,7 +3635,7 @@ struct MinColumnGridSpec { std::vector const children = measured(probe, view).children; checks.that(children.size() == 1, "the column holds the key-value"); if (children.size() == 1) { - geometry.near("the key-value's width", 23, geometry.of(*children.front()).width); + geometry.near("the key-value's width", 23, geometry.of(children.front()).width); } return checks.result(); } @@ -3629,8 +3654,8 @@ struct MinColumnGridSpec { Measured const found = measured(probe, view); checks.that(found.container != nullptr && found.children.size() == 1, "the grid holds one cell"); if (found.container != nullptr && found.children.size() == 1) { - WidgetBounds const outer = geometry.of(*found.container); - WidgetBounds const badge = geometry.of(*found.children.front()); + WidgetBounds const outer = geometry.of(found.container); + WidgetBounds const badge = geometry.of(found.children.front()); double const before = badge.x - outer.x; double const after = outer.x + 12 - (badge.x + badge.width); checks.that(badge.width < 10, "the badge fills its track: it is " + std::to_string(badge.width) + @@ -3654,7 +3679,7 @@ struct MinColumnGridSpec { std::vector const children = measured(probe, view).children; checks.that(children.size() == 1, "the column holds one child"); if (children.size() == 1) { - WidgetBounds const bounds = geometry.of(*children.at(0)); + WidgetBounds const bounds = geometry.of(children.at(0)); geometry.near("a content-sized chart's width", 40, bounds.width); geometry.near("a content-sized chart's height", 8, bounds.height); } @@ -3829,8 +3854,8 @@ struct MinColumnGridSpec { overlay != nullptr && probe.childCount(*overlay) > 0 ? probe.childAt(*overlay, 0) : nullptr; checks.that(beside != nullptr && inside != nullptr, "the root holds a text, and the open sheet holds one"); if (beside != nullptr && inside != nullptr) { - double const full = geometry.of(*beside).width; - double const within = geometry.of(*inside).width; + double const full = geometry.of(beside).width; + double const within = geometry.of(inside).width; checks.that(within >= full - kSheetPadding, "a sheet's stretching text is " + std::to_string(within) + " wide, beside a root " + std::to_string(full) + " wide"); } @@ -3851,8 +3876,8 @@ struct MinColumnGridSpec { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the row holds two buttons"); if (children.size() == 2) { - double const small = geometry.of(*children.at(0)).width; - double const normal = geometry.of(*children.at(1)).width; + double const small = geometry.of(children.at(0)).width; + double const normal = geometry.of(children.at(1)).width; checks.that(small > 0 && small < normal, "a small button is " + std::to_string(small) + " wide, beside a normal one " + std::to_string(normal) + " wide"); } @@ -3873,8 +3898,8 @@ struct MinColumnGridSpec { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the row holds two buttons"); if (children.size() == 2) { - double const square = geometry.of(*children.at(0)).width; - double const normal = geometry.of(*children.at(1)).width; + double const square = geometry.of(children.at(0)).width; + double const normal = geometry.of(children.at(1)).width; checks.that(square > 0 && square < normal, "a square button is " + std::to_string(square) + " wide, beside a normal one " + std::to_string(normal) + " wide"); @@ -3912,9 +3937,9 @@ struct MinColumnGridSpec { narrow != nullptr && natural != nullptr && probe.childCount(*narrow) == 2 && probe.childCount(*natural) == 2, "the column holds two rows of a badge and a text"); if (narrow != nullptr && natural != nullptr && probe.childCount(*narrow) == 2 && probe.childCount(*natural) == 2) { - WidgetBounds const badge = geometry.of(*probe.childAt(*narrow, 0)); - WidgetBounds const reference = geometry.of(*probe.childAt(*natural, 0)); - WidgetBounds const after = geometry.of(*probe.childAt(*narrow, 1)); + WidgetBounds const badge = geometry.of(probe.childAt(*narrow, 0)); + WidgetBounds const reference = geometry.of(probe.childAt(*natural, 0)); + WidgetBounds const after = geometry.of(probe.childAt(*narrow, 1)); geometry.near("the sized badge's width, against its content width", reference.width, badge.width); checks.that(after.x >= badge.x + badge.width - 1.0, "the text after the badge starts at " + std::to_string(after.x) + @@ -3957,8 +3982,8 @@ struct MinColumnGridSpec { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the row holds two children"); if (children.size() == 2) { - geometry.near("the first stretch child's width", first, geometry.of(*children.at(0)).width); - geometry.near("the second stretch child's width", second, geometry.of(*children.at(1)).width); + geometry.near("the first stretch child's width", first, geometry.of(children.at(0)).width); + geometry.near("the second stretch child's width", second, geometry.of(children.at(1)).width); } return checks.result(); } @@ -4007,13 +4032,13 @@ struct MinColumnGridSpec { bool const ready = allHold({found.container != nullptr, found.children.size() == 2, text != nullptr}); checks.that(ready, "the row holds two texts"); if (ready) { - double const width = geometry.of(*found.container).width; - double const natural = geometry.of(*text).width; + double const width = geometry.of(found.container).width; + double const natural = geometry.of(text).width; checks.that(natural >= 8, "ten characters are " + std::to_string(natural) + " units wide on their own"); checks.that(width >= (2 * natural) - 0.5 && width <= (2 * natural) + 1, "the row is " + std::to_string(width) + " units wide, not twice its ten-character text (" + std::to_string(natural) + " units)"); - double const second = geometry.of(*found.children.at(1)).width; + double const second = geometry.of(found.children.at(1)).width; checks.that(second >= natural - 0.5, "the second text keeps its ten characters: it is " + std::to_string(second) + " units wide, " + std::to_string(natural) + " on its own"); @@ -4045,8 +4070,8 @@ struct MinColumnGridSpec { bool const ready = allHold({nestedCount == 2, text != nullptr}); checks.that(ready, "the outer row holds the nested row of two texts"); if (ready) { - double const second = geometry.of(*probe.childAt(*nested, 1)).width; - double const natural = geometry.of(*text).width; + double const second = geometry.of(probe.childAt(*nested, 1)).width; + double const natural = geometry.of(text).width; checks.that(natural >= 8, "ten characters are " + std::to_string(natural) + " units wide on their own"); checks.that(second >= natural - 0.5, "the nested ten-character text is " + std::to_string(second) + " units wide, " + @@ -4072,9 +4097,9 @@ struct MinColumnGridSpec { std::vector const children = measured(probe, view).children; checks.that(children.size() == 3, "the row holds three children"); if (children.size() == 3) { - geometry.near("the child held at its minimum", 30, geometry.of(*children.at(0)).width); - geometry.near("the second child's width", 15, geometry.of(*children.at(1)).width); - geometry.near("the third child's width", 15, geometry.of(*children.at(2)).width); + geometry.near("the child held at its minimum", 30, geometry.of(children.at(0)).width); + geometry.near("the second child's width", 15, geometry.of(children.at(1)).width); + geometry.near("the third child's width", 15, geometry.of(children.at(2)).width); } return checks.result(); } @@ -4093,7 +4118,7 @@ struct MinColumnGridSpec { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the row holds a text and a spacer"); if (children.size() == 2) { - geometry.near("the stretch text's width, beside a spacer", 20, geometry.of(*children.at(0)).width); + geometry.near("the stretch text's width, beside a spacer", 20, geometry.of(children.at(0)).width); } return checks.result(); } @@ -4116,8 +4141,8 @@ struct MinColumnGridSpec { std::vector const children = measured(probe, view).children; checks.that(children.size() == 2, "the column holds two children"); if (children.size() == 2) { - geometry.near("the short child's height", 10, geometry.of(*children.at(0)).height); - geometry.near("the tall child's height", 10, geometry.of(*children.at(1)).height); + geometry.near("the short child's height", 10, geometry.of(children.at(0)).height); + geometry.near("the tall child's height", 10, geometry.of(children.at(1)).height); } return checks.result(); } @@ -4337,8 +4362,8 @@ struct MinColumnGridSpec { shared != nullptr && natural != nullptr && probe.childCount(*shared) == 2 && probe.childCount(*natural) == 2, "the column holds two rows of two buttons"); if (shared != nullptr && natural != nullptr && probe.childCount(*shared) == 2 && probe.childCount(*natural) == 2) { - double const wide = geometry.of(*probe.childAt(*shared, 1)).width; - double const reference = geometry.of(*probe.childAt(*natural, 1)).width; + double const wide = geometry.of(probe.childAt(*shared, 1)).width; + double const reference = geometry.of(probe.childAt(*natural, 1)).width; checks.that(wide >= reference - 1.0, "the stretch button is " + std::to_string(wide) + " wide, below its label's " + std::to_string(reference)); } From 82317718c81fadd5963d0fcbee8db60569e48dfd Mon Sep 17 00:00:00 2001 From: Yaraslau Tamashevich Date: Sun, 29 Nov 2026 01:00:53 +0100 Subject: [PATCH 8/8] test: a server hold outlives the tasks it parked ServerHold's destructor released the parked server tasks and returned, but a woken task reads _released once more, so under ASan it read a hold already gone (stack-use-after-scope in the dropped-check controller test). The destructor now waits until every parked task has left. Both copies of the helper had it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01No1NzndCGtpCccptcyk6Tb --- tests/test_ui_cov_j_controller.cpp | 9 ++++++++- tests/test_ui_custom_screen_chrome.cpp | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/test_ui_cov_j_controller.cpp b/tests/test_ui_cov_j_controller.cpp index 7af4bec6d..0ce9d4dcc 100644 --- a/tests/test_ui_cov_j_controller.cpp +++ b/tests/test_ui_cov_j_controller.cpp @@ -182,11 +182,17 @@ class ServerHold { rig.server.pool.post([this, &started] { started.count_down(); _released.wait(false); + _left.count_down(); }); } started.wait(); } - ~ServerHold() { release(); } + // Waits for every held task to leave, not only to be told: a woken task reads _released once more, and the hold + // must still be alive when it does. + ~ServerHold() { + release(); + _left.wait(); + } ServerHold(ServerHold const&) = delete; ServerHold& operator=(ServerHold const&) = delete; ServerHold(ServerHold&&) = delete; @@ -200,6 +206,7 @@ class ServerHold { private: static constexpr std::ptrdiff_t kThreads = 2; std::atomic _released{false}; + std::latch _left{kThreads}; }; using Answer = std::optional>; diff --git a/tests/test_ui_custom_screen_chrome.cpp b/tests/test_ui_custom_screen_chrome.cpp index 1c6d64e17..5b61c1285 100644 --- a/tests/test_ui_custom_screen_chrome.cpp +++ b/tests/test_ui_custom_screen_chrome.cpp @@ -44,11 +44,17 @@ class ServerHold { rig.server->pool.post([this, &started] { started.count_down(); _released.wait(false); + _left.count_down(); }); } started.wait(); } - ~ServerHold() { release(); } + // Waits for every held task to leave, not only to be told: a woken task reads _released once more, and the hold + // must still be alive when it does. + ~ServerHold() { + release(); + _left.wait(); + } ServerHold(ServerHold const&) = delete; ServerHold& operator=(ServerHold const&) = delete; ServerHold(ServerHold&&) = delete; @@ -63,6 +69,7 @@ class ServerHold { // The size of the test server's pool. static constexpr std::ptrdiff_t kThreads = 2; std::atomic _released{false}; + std::latch _left{kThreads}; }; } // namespace