Skip to content

ci(qemu): make the runtime-bundle build prove its own closure - #1927

Merged
zackees merged 1 commit into
mainfrom
agent/test-build-qemu-linux-runtime
Nov 6, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/test-build-qemu-linux-runtime

Conversation

@zackees

@zackees zackees commented Nov 6, 2026

Copy link
Copy Markdown
Member

ci/build_qemu_linux_runtime.py is the last untested workflow-invoked gate in
the ci/gate_script_tests.toml ratchet. It builds the tar.zst bundle that
every Linux host downloads when it cannot start Espressif's QEMU itself, and
esp_qemu_runtime.rs names that asset by composing
qemu-esp-linux-runtime-<arch>-<RUNTIME_VERSION>.tar.zst.

Three of its "proofs" were not proofs, and the tag/libraries it shares with Rust
were joined to the consumer by a comment asking the next person to keep them in
sync.

The defects

  1. The closure walk ended silently when it did not converge.
    for _round in 1 2 3 4 5 6 7 8 ... done left a still-unexpanded frontier on
    the floor. A graph deeper than the cap produced a short archive and every
    later check only looked for the same five names, so it shipped green.

  2. The completeness check could not see the gap it was written to catch.
    Five hand-typed names were checked, and the --version selftest that was
    supposed to prove the closure removes only three of the five apt packages.
    libgcrypt20 and zlib1g necessarily stay installed (zlib1g is
    priority: required), so a missing transitively-reachable library behind
    either one was invisible: the binary starts, the archive publishes, and the
    failure lands on a user's machine.

  3. A truncated tar czf-equivalent published as success. docker cp
    returns 0 for a zero-byte or half-written file, so a tar | zstd killed mid
    flight was hashed and handed out as an install candidate.

  4. The bridge to Rust was a comment. QEMU_RELEASE_TAG lived in three
    places (esp_qemu.rs, esp_qemu_runtime.rs, this script) and the five
    required libraries in two, with no test comparing them. Drift in the tag
    makes the published asset name not match the URL the consumer fetches --
    and nothing in the builder would notice.

The fix

  • collect_closure() is now a while walk whose frontier contains only
    non-glibc libraries, so convergence is "frontier empty" and hitting
    MAX_CLOSURE_ROUNDS is a FATAL naming what was left unexpanded.
  • verify_closure() proves the bundle is a complete closure: every
    DT_NEEDED of every bundled library is either the glibc family / loader or
    present in lib/. It uses a separate needed() reader because deps() drops
    => not found lines (right for copying, wrong for judging completeness).
    No apt packages have to be removed for this one, so it has no blind spot.
  • The archive is inspected before it leaves the container: MANIFEST.txt must be
    in it and the lib/ entry count must be at least the number of required
    libraries. zstd -dc | tar -t rather than tar --zstd, because the build
    image's tar is 1.30 and --zstd arrived in 1.31.
  • _assert_payload() rejects a missing or empty archive/manifest, and the
    container is removed in a finally even when a copy fails.
  • The tag, archive version, required libraries and glibc family are declared
    once in Python and injected into the payload; render_script() raises if
    any __PLACEHOLDER__ survives, and a test compares the tag and the library
    list against their esp_qemu*.rs counterparts.

Tests

ci/test_build_qemu_linux_runtime.py (31 tests) covers the fix three ways:

  • the Python half end to end through a fake docker on PATH -- argv
    (--platform linux/arm64 for aarch64), the payload that actually reaches the
    container, container cleanup, a failed run, a missing artifact, an empty
    archive, an empty manifest, and main()'s printed SHA-256 checked against
    the bytes on disk;
  • the bash logic executed, not grepped: the block between the
    closure-logic markers in the rendered payload is extracted and run under
    set -euo pipefail against a stubbed ldd, covering a complete closure,
    glibc/loader exclusion, a gap behind a bundled library, an unsettled walk, a
    walk exactly at the cap (every real library links libc), and an unreadable
    ELF;
  • constant parity parsed out of the Rust sources, plus bash -n on the
    rendered payload and a check that the README does not document a different
    build image than the code uses.

Real output

$ uv run --no-project python -m unittest ci.test_build_qemu_linux_runtime
Ran 31 tests in 2.4s
OK

$ <hosted self-test set from ci-workflow-drift.yml>
Ran 366 tests in 12.2s
OK            # 337 -> 366

$ uv run --no-project python -m ci.gate_script_coverage --budget 0
Every workflow-invoked gate script is accounted for

$ uv run --no-project python -m ci.check_python_complexity
All checks passed!
$ ruff check ci/            -> All checks passed!
$ ruff format --check <both files> -> 2 files already formatted
$ uv run --no-project python ci/check_test_layout.py
ok: 8 integration-test categories, no stray test binaries

RED proven by five in-place mutations, each restored afterwards: the silent
round cap (1 failure), needed() reading not found as a soname (1), dropping
_assert_payload (2), letting verify_closure count glibc deps (3), and
dropping the glibc filter from the walk frontier (1 -- the cap test, because a
real library's libc dependency would otherwise eat a round).

Verified against the real container

Not just the fakes: the hardened builder was run for real
(docker run ubuntu:20.04, real Espressif QEMU tarballs, real ldd):

=== bundle ===
libraries: 43
archive:   4425952 bytes
selftest: both QEMU binaries start with LD_LIBRARY_PATH=<bundle>/lib
sha256:  a0d757cb6aa9a19723e2187510cb7c6a2c66d4ee01eedc73af9697c12f4cebfc
size:    4425952 bytes

43 libraries, verify_closure() clean, archive inspection clean, both
emulators starting from the bundle after the three removable apt packages were
stripped. The tightening does not false-RED the published path.

Ratchet

[scripts.build_qemu_linux_runtime].tests declared, untested emptied,
MAX_UNTESTED 1 -> 0 in ci/test_gate_script_coverage.py, registered in both
entry points (ci/local_suites.py and the ci-workflow-drift.yml unittest
command). The README bullet also said the bundle is built on ubuntu:22.04;
the code has always used ubuntu:20.04 (and must, for the 2.30 glibc floor),
so the doc is corrected and a test now asserts the two agree.

`ci/build_qemu_linux_runtime.py` was the last untested workflow-invoked gate.
It builds the tar.zst that `esp_qemu_runtime.rs` downloads, and three of its
checks could not fail:

* the breadth-first closure walk was a fixed `for _round in 1..8` loop that
  simply ENDED with a non-empty frontier, so a deeper graph produced a short
  archive and the five-name required check still passed;
* completeness was five hand-typed names while the `--version` selftest
  removed only three of the five apt packages -- libgcrypt20 and zlib1g stay
  installed (zlib1g is priority:required), so a gap behind either was
  unobservable;
* a truncated `tar | zstd` copies out of the container with exit code 0 and
  was hashed and published.

Now: the walk converges or is FATAL; `verify_closure()` proves every DT_NEEDED
of every bundled library is glibc or present (via a separate `needed()` reader
that keeps `=> not found` entries, which `deps()` rightly drops); the archive
must contain MANIFEST.txt and at least the required number of lib/ entries
(`zstd -dc | tar -t`, since the image's tar 1.30 has no `--zstd`); and
`_assert_payload()` refuses a missing or empty artifact, with the container
removed in a `finally`.

The tag, archive version, required libraries and glibc family are declared once
and injected into the payload, and tests compare them against the constants in
`esp_qemu.rs` / `esp_qemu_runtime.rs` instead of a "keep in sync" comment.

ci/test_build_qemu_linux_runtime.py: 31 tests -- the Python half through a fake
`docker` on PATH, and the bash closure logic executed against a stubbed `ldd`
straight from the rendered payload between marker lines.
@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@zackees
zackees added this pull request to the merge queue Nov 6, 2026
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 6, 2026
Merged via the queue into main with commit 5fbf982 Nov 6, 2026
31 checks passed
@zackees
zackees deleted the agent/test-build-qemu-linux-runtime branch November 6, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant