Skip to content

ci: portable test bundles from ctest json-v1 + serial runner (#277 phase A) - #279

Merged
zackees merged 7 commits into
mainfrom
ci/277-phase-a-test-bundles
Sep 2, 2026
Merged

zackees merged 7 commits into
mainfrom
ci/277-phase-a-test-bundles

Conversation

@zackees

@zackees zackees commented Sep 2, 2026 •

Copy link
Copy Markdown
Owner

Phase A of #277: the portable test-bundle format, the two scripts, and the gate that
proves a bundle runs exactly what ctest runs.

Stacked on #278. Both branches are rebased onto main as of #276. Against main this
PR's diff shows #278's two commits first; everything titled "(#277 phase A)" is this PR.
Merge #278 first and this collapses to the phase-A commits alone.

What a bundle is

A directory a macOS or Windows runner can execute with no CMake and no repo checkout:
every test executable, every libmimalloc* / mimalloc*.dll / mimalloc-redirect*.dll,
and a tests.json manifest.

uv run ci/bundle_tests.py <build-dir> <out-dir> [--config Debug]
uv run ci/run_test_bundle.py <bundle> [--only NAME…] [--env K=V…]
                                      [--timeout-scale F] [--junit out.xml]
                                      [--compare-junit ctest.xml]

One entry per test: name, argv, env, cwd, timeout, expect_nonzero,
expect_text, labels.

Lowering rules

ctest --show-only=json-v1 does not emit a list of plain executables. Both cmake
shapes are lowered into manifest fields so the runner needs no CMake:

ctest command lowered to
cmake -E env K=V … <exe> [args] env + the real argv; K=V tokens consumed up to the first token that is not one
cmake -D TEST_EXE=… -D TEST_ARG=… -D EXPECTED_TEXT=… -P test/run-negative.cmake argv = [TEST_EXE, TEST_ARG?], expect_nonzero: true, expect_text: EXPECTED_TEXT, timeout: 10

The negative-control semantics come straight from test/run-negative.cmake, including the
two that are easy to get backwards:

  • A timeout is a failure, not the expected non-zero exit. The script's own words are
    "negative control timed out instead of failing fast". A hung control proves nothing.
  • The expected text is searched in the combined stdout+stderr, so a control that fails
    for the wrong reason stays red ("failed for the wrong reason (result=…)" upstream).

TEST_ARG is optional; the effective timeout is the cmake script's 10 s, not the test's
TIMEOUT 15.

Failing loudly

Everything the bundler cannot lower is a hard error naming the test, and all problems
are reported in one message rather than one per run:

  • an unknown cmake argv shape (cmake -E rm, an unrecognised -P script)
  • a cmake -E env option (--unset=, --modify) rather than a plain assignment
  • an unrecognised run-negative.cmake variable
  • a test property outside the allowlist — ENVIRONMENT, TIMEOUT, WORKING_DIRECTORY,
    LABELS, WILL_FAIL, DISABLED. PASS_REGULAR_EXPRESSION, SKIP_RETURN_CODE,
    RESOURCE_LOCK and friends are refused, not silently dropped.
  • an executable outside the build tree, a basename collision, or an empty suite

The reason is the one docs/ci-gates.md is built around: a bundle that quietly carries
fewer tests than ctest ran reports green while verifying less. That is precisely the shape
of all seven dead gates this repo has already found.

Path handling

Absolute build-tree paths appear in argv and in env values (LD_PRELOAD=/abs/build/…,
DYLD_INSERT_LIBRARIES=/abs/build/…); both are rewritten to a ${BUNDLE} placeholder the
runner expands. Files are flattened into the bundle root, because a Windows DLL must
sit beside the exe that loads it and a flat directory is what lets
LD_LIBRARY_PATH/DYLD_LIBRARY_PATH override the build-tree RPATH baked into the
executables. Symlinks are recreated as symlinks so the libmimalloc-debug.so → .so.3 → .so.3.4 SONAME chain survives.

The bundle-roundtrip job (c-unit.yml, ubuntu)

MI_PPROF=ON MI_DEBUG_FULL=ON, mirroring the existing ctest-debug-full ubuntu row:
configure → build → ctest --output-junit ctest.xml (the reference) → bundle → mv build build.moved-away → replay with --compare-junit. The bundle and both JUnit files upload
as an artifact.

The mv is the load-bearing step. The executables carry an RPATH into the build tree, so
without it a broken bundle passes on the build machine by loading the original libraries
and the portability claim goes untested on the only machine that can check it.

--compare-junit compares against ctest --output-junit rather than parsing
LastTest.log: it is a stable documented format, so the comparison is deterministic and
testable from fixtures. It asserts the same name set and the same pass/fail per test.

Local verification (this machine, Linux x86-64)

Both runs had the build tree renamed away before replaying:

# Debug, MI_PPROF=ON MI_DEBUG_FULL=ON
bundled 31 tests and 26 files into out/bundle-a-out
  6 negative control(s) lowered from run-negative.cmake
  5 test(s) carry environment overrides
100% tests passed, 0 tests failed out of 31
Total Test time (real) =    19.86 sec
bundle matches out/ctest-debug.xml: same 31 test names, same results

# Release, MI_PPROF=ON
bundled 24 tests and 24 files into out/bundle-rel-out
  5 test(s) carry environment overrides
100% tests passed, 0 tests failed out of 24
Total Test time (real) =    26.63 sec
bundle matches out/ctest-rel.xml: same 24 test names, same results

Corrections to #277

  • §1 says "verified on the MI_DEBUG_FULL tree, 12 of 32 tests invoke cmake: 6 are
    cmake -E env and 6 are cmake -P run-negative.cmake"
    . Actual: 31 tests, 7 of which
    invoke cmake — 6 negative controls plus exactly one cmake -E env
    (test-stress-dynamic).
    The Release tree has 24 tests and none. The lowering rules the
    issue asks for are all still needed; only the counts were off.
  • The rest of §1 held up: no WILL_FAIL and no PASS_REGULAR_EXPRESSION in use; the live
    properties are ENVIRONMENT, TIMEOUT, WORKING_DIRECTORY; absolute paths really do
    appear in env values. WILL_FAIL and DISABLED are implemented anyway, since they are
    one line each and the alternative is a future add_test breaking the bundler.

Tests and checks

  • ci/tests/test_test_bundles.py, 42 tests: the two lowering rules, every refusal path,
    path relativisation in argv and in env (LD_PRELOAD and DYLD_INSERT_LIBRARIES),
    basename collisions, the negative-control semantics end to end (wrong reason → red, zero
    exit → red, timeout → red even with expect_nonzero), loader-path injection,
    --only/--env/--timeout-scale/--junit/--compare-junit, and a roundtrip on a tiny
    fake bundle whose build tree is deleted before replay.
  • pytest ci/tests: 139 passed, 0 failed.
  • ruff check ci/ + ruff format --check ci/ clean on the CI pin (0.12.10).
  • pyright --strict is clean. It initially could not run here (no system Node); uv run --with 'pyright[nodejs]==1.1.411' pyright ships its own Node and works, which caught four
    real strict errors that are fixed in the last commit. That command is worth knowing for
    anyone else hacking on ci/ from a Node-less box.
  • uv run ci/verify_local.py --list — ci/verify_local.py did not exist on main when
    this work started; feat: bump upstream overlay pin to 6def7be9 (Bun merge-base) + glibc 2.44 free(NULL) fix #276 landed it mid-flight, along with a drift gate that fails when a
    Linux CI job references a ci/*.py the local mirror does not. So bundle-roundtrip now
    has a matching bundle config, and the gate is reproducible locally:
$ uv run ci/verify_local.py --only bundle
[  103.6s] bundle       PASS
…
100% tests passed, 0 tests failed out of 32          # ctest reference
bundled 32 tests and 27 files into …/verify/bundle/bundle
100% tests passed, 0 tests failed out of 32          # the bundle, build tree removed
bundle matches …/verify/bundle/ctest.xml: same 32 test names, same results
  • CI uses python3, matching every existing workflow here; the scripts are stdlib-only, so
    uv run behaves identically.

One CI-only bug this caught

The first CI run failed and it was worth having: ctest --output-junit resolves a
relative path against the build directory, not the working directory, so the
reference ctest.xml landed in build/ and the mv carried it away. Locally the roundtrip
had always been run with an absolute path, so it never showed. The workflow now passes
$GITHUB_WORKSPACE/ctest.xml, run_test_bundle.py names the gotcha instead of leaking an
ElementTree stack trace, ctest_run() in verify_local.py resolves the path so no caller
can repeat it, and there is a test. The bundle itself ran 31/31 green with the build tree
gone
on that failing run — the thing the job exists to prove.

Not in scope

No toolchain work: the cross lanes are phase B/C/D (soldr lanes, #277 §2). Nothing outside
ci/, .github/workflows/c-unit.yml and docs/ci-gates.md is touched, so rule 2 holds.

Refs #277.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S

@zackees
zackees force-pushed the ci/277-phase-a-test-bundles branch from 14f88f1 to 8bd70e4 Compare September 2, 2026 04:24
@zackees

zackees commented Sep 2, 2026

Copy link
Copy Markdown
Owner Author

Heads-up on the red python-lint: it is not this PR.

python-lint runs pytest ci/tests, and test_readme_embeds_only_real_charts_and_clicks_through_to_pages asserts the README still embeds a chart linking to .../#throughput. That embed was removed by a README-only PR, and python-lint's paths: filter (ci/**, pyproject.toml, workflows) means a README-only PR never runs it — so main has been red here invisibly. Reproduced on a clean origin/main checkout with this branch stashed.

The fix already exists, unmerged, on bun-parity/p1-pin-bump (238218d5, "update stale README anchor test"). Duplicating it here would just conflict with that branch, so it is deliberately left alone. ruff check, ruff format --check and pyright --strict (0 errors) all pass on this branch.

Worth noting for #277 or a follow-up: a gate whose path filter excludes the files that can break it is the same shape as the seven dead gates in docs/ci-gates.md.

zackees and others added 7 commits September 1, 2026 21:43
No workflow in this repo had a `concurrency` group, so every push to a PR
branch left the previous push's jobs queued and competing for the same
runners. Measured over the last 20 runs, `cross.yml`'s Apple rows executed
in 8-9 seconds and waited up to 5h26m (arm64) and 6h13m (Intel).

Every workflow now declares one. `cancel-in-progress` is true only where a
cancelled run costs nothing but the answer it would have given:

  true  amalgamation-drift, asan, benchmark-sentinel, c-unit, cross,
        doc-snippets, fuzz, python-lint, rust-native, zero-tracking
  false auto-release (already), release, stale, star-history (already),
        and the four benchmark-* producers (already, and they deliberately
        share one `benchmark-stats-production` group to serialise against
        each other -- left untouched)

Three of those deserve a note:

  * release.yaml arrived from upstream with cancel-in-progress: true while
    uploading release assets. Flipped: a cancelled run leaves the release
    half-populated.
  * stale.yaml closes and labels issues and PRs; a half-run leaves the repo
    partly swept.
  * fuzz.yml has a `schedule:` trigger, and a scheduled run carries
    ref=refs/heads/main. Its group includes github.event_name so the nightly
    2,000,000-iteration run and a main push cannot cancel each other.

docs/ci-gates.md gains the policy and the measured numbers behind it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
`ci/ci_queue_wait.py` is the before/after instrument for the concurrency
change: for the last N runs of the given workflows it reads the Actions API
through `gh` and prints, grouped by the job's `labels` (what `runs-on:`
resolved to), p50/p90/max of `started_at - created_at` (queue wait) and
`completed_at - started_at` (execution), plus the job count.

Fetching is separated from arithmetic so the unit tests drive `parse_jobs`,
`percentile` and `summarise` from a fixture in the real
`/actions/runs/<id>/jobs` shape; `--jobs-json` replays that same fixture
through the CLI, so nothing in the test suite touches the network.

One caveat is documented in the tool and in docs/ci-gates.md rather than
papered over: a job with `needs:` is created when the run is created, so a
`cross.yml` `test (*)` row measures pool wait plus upstream build time.
`c-unit.yml` and `rust-native.yml` have no `needs:` edges and measure pool
wait alone.

Cancelled and skipped jobs are excluded -- a cancelled job's completed_at is
when the cancellation landed, not when work finished -- while failed jobs are
kept, because a red job still occupied a runner for its whole execution.

ruff, `ruff format --check` and `pyright --strict` (0 errors) all pass. pyright
needed `uv run --with 'pyright[nodejs]==1.1.411' pyright`: the `[nodejs]` extra
ships its own Node, which is what makes it runnable on a box with none.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
…ase A)

#277 wants the macOS and Windows test binaries built once on Linux and executed
on one runner per OS. That needs a *test bundle*: a directory a runner can
execute with no CMake and no repo checkout. This is the format and the two
scripts that produce and replay it.

`ci/bundle_tests.py <build-dir> <out-dir> [--config C]` runs
`ctest --show-only=json-v1` and writes `tests.json` (name, argv, env, cwd,
timeout, expect_nonzero, expect_text, labels) plus every referenced executable
and every `libmimalloc*` / `mimalloc*.dll` / `mimalloc-redirect*.dll`.

ctest does not emit a list of plain executables. On the MI_DEBUG_FULL tree 7 of
31 tests invoke `cmake` itself, and both shapes are lowered into manifest fields
so the runner needs no CMake:

  * `cmake -E env K=V ... <exe>`  -> `env` + the real argv (test-stress-dynamic
    sets MIMALLOC_VERBOSE and LD_PRELOAD this way)
  * `cmake -D... -P test/run-negative.cmake` -> argv, expect_nonzero,
    expect_text, timeout 10 -- the 6 negative controls

The negative-control semantics are copied from test/run-negative.cmake exactly,
including the part that is easy to get backwards: a timeout is a FAILURE, not
the expected non-zero exit ("negative control timed out instead of failing
fast"), and the expected substring is searched in the combined stdout+stderr so
a control that fails for the wrong reason stays red.

Absolute build-tree paths appear in argv AND in env values, so both are
rewritten to a `${BUNDLE}` placeholder the runner expands, and the files are
flattened into the bundle root -- a Windows DLL must sit beside its exe, and a
flat directory is what lets LD_LIBRARY_PATH/DYLD_LIBRARY_PATH override the
build-tree RPATH baked into the executables. A basename collision is a hard
error, never a silent overwrite.

Everything the bundler cannot lower is a hard error naming the test: an unknown
`cmake` argv shape, a `cmake -E env` option, an unrecognised run-negative
variable, a test property outside the allowlist (ENVIRONMENT, TIMEOUT,
WORKING_DIRECTORY, LABELS, WILL_FAIL, DISABLED), an executable outside the build
tree, and an empty suite. A bundle that quietly carries fewer tests than ctest
ran would report green while verifying less, which is exactly the failure mode
docs/ci-gates.md exists to prevent.

`ci/run_test_bundle.py <bundle>` replays serially with a ctest-shaped summary,
`--only`, `--env`, `--timeout-scale`, `--junit`, and `--compare-junit`, which
asserts the same test names and the same pass/fail as a `ctest --output-junit`
run. Comparing JUnit rather than parsing LastTest.log keeps the comparison
deterministic and testable from fixtures.

Verified locally, in both cases with the build tree renamed away first so the
RPATH cannot rescue a broken bundle:

  Debug MI_PPROF=ON MI_DEBUG_FULL=ON  31/31 passed, same 31 names as ctest
  Release MI_PPROF=ON                 24/24 passed, same 24 names as ctest

Correction to #277 for the record: the issue says "12 of 32 tests invoke cmake:
6 `cmake -E env` and 6 `-P run-negative.cmake`". The MI_DEBUG_FULL tree has 31
tests of which 7 invoke cmake -- 6 negative controls and 1 `cmake -E env`. The
Release tree has 24 tests and none.

pyright --strict could not be run locally (no Node); python-lint is the check.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
The bundle format is only worth anything if the bundle runs exactly the tests
ctest runs and gets exactly the same results. This job proves it on the config
where every awkward command shape lives -- MI_DEBUG_FULL is the only one that
emits `cmake -P run-negative.cmake` controls and the `cmake -E env` LD_PRELOAD
wrapper.

Sequence: configure/build, `ctest --output-junit ctest.xml` as the reference,
bundle, **move the build tree away**, replay with `--compare-junit`. The `mv` is
load-bearing: the executables carry an RPATH into the build tree, so without it
a broken bundle would pass on the build machine by loading the original
libraries and the portability claim would go untested on the only machine that
can check it.

The bundle and both JUnit files are uploaded as an artifact.

Uses `python3` like every other workflow here; the scripts are stdlib-only, so
`uv run ci/run_test_bundle.py` behaves identically.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
`field(default_factory=dict)` hands strict mode a `dict[Unknown, Unknown]`
factory even when the field is annotated `dict[str, str]`. PEP 585 generics are
callable at runtime on the oldest Python this repo targets, so
`default_factory=dict[str, str]` is both correct and checkable.

Verified with `uv run --with 'pyright[nodejs]==1.1.411' pyright` (0 errors) --
the `[nodejs]` extra ships its own Node, which is what made pyright runnable on
a machine with none.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
`ctest --output-junit` resolves a relative path against the **build directory**,
not the working directory. The bundle-roundtrip job wrote `ctest.xml`, which
landed in `build/`, and then `mv build build.moved-away` carried the reference
off with it -- so the comparison step died on a bare FileNotFoundError from
inside ElementTree. The bundle itself was fine: it ran 31/31 green with the
build tree gone, which is the thing the job exists to prove.

Two changes: the workflow passes `$GITHUB_WORKSPACE/ctest.xml`, and
`run_test_bundle.py` now names the gotcha instead of letting a stack trace out.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
`ci/verify_local.py` landed on main (#276) with a drift gate that fails when a
Linux CI job references a `ci/*.py` script the local mirror does not, so the new
`bundle-roundtrip` job needs a matching config -- which is the useful outcome
anyway: `uv run ci/verify_local.py --only bundle` now reproduces the whole gate
locally.

The runner mirrors the job 1:1: configure, build, reference `ctest
--output-junit` (absolute path -- ctest resolves a relative one against the
build directory), bundle, move the build tree away, replay with
`--compare-junit`, move it back. `exclude_slow=False` regardless of `--slow`,
because a comparison against a partial reference proves nothing.

`ctest_run` gains a `junit=` parameter; it resolves the path so no caller can
hit the relative-path trap.

Measured here: `bundle PASS 103.6s`, 32/32 in both the reference and the bundle,
"same 32 test names, same results".

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
@zackees
zackees force-pushed the ci/277-phase-a-test-bundles branch from aff4dfb to efd5522 Compare September 2, 2026 04:48
@zackees

zackees commented Sep 2, 2026

Copy link
Copy Markdown
Owner Author

Opus review: APPROVE. Roundtrip re-run by the reviewer: Debug FULL 32/32 and Release 25/25, bundle matches ctest by name and result both ways; zero absolute paths in the produced tests.json; lowering semantics match run-negative.cmake and cmake -E env (values with = preserved); unrecognised argv shapes refuse loudly; junit relative-path fix correct; pyright strict/ruff/pytest clean.

Follow-ups filed on #277 (Phase A polish, before Phase B ships bundles cross-host):

  • Medium: only argv[0] is checked for the bundle placeholder; an absolute source-tree path in argv[1:], an env value, or cwd passes through verbatim. Add a final scan of argv/env/cwd for any os.path.isabs string not under the placeholder → problems.
  • Low: _lower_run_negative uses if arg: (empty TEST_ARG dropped; use "TEST_ARG" in defines); negative timeout should be min(10, TIMEOUT); copy_into should assert symlink targets are bare basenames; os.pathsep-joined build paths in env die with FileNotFoundError instead of BundleError; generated_from.build_dir is the one absolute host path left in the manifest; docs show the spaced -D TEST_EXE= form the bundler refuses; test counts hard-coded in docs; no tests for spaced -D refusal or empty TEST_ARG; Windows drive-letter case in _normalise.

Merging with macOS jobs still queued for the same reason as #278.

@zackees
zackees merged commit d65bc28 into main Sep 2, 2026
48 checks passed
@zackees
zackees deleted the ci/277-phase-a-test-bundles branch September 2, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant