Skip to content

tests: read the whole pipe instead of head under pipefail - #907

Open
only21mil wants to merge 1 commit into
derekross:mainfrom
only21mil:build/tests-head-pipes-lint
Open

only21mil wants to merge 1 commit into
derekross:mainfrom
only21mil:build/tests-head-pipes-lint

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

What and why

This is the lint invited on #884: a check beside tests/grep-q-pipes for a pipe into head in a script that sets pipefail. head with a count can exit before its writer is done; the writer gets SIGPIPE and pipefail fails the pipeline, so a set -e assignment ends the script, a || fail check fails at random, or an if ...; then fail check passes.

tests/rootfs-smoke's last check is that last case: in grep -rIl omandroid ... | grep -v ... | head -5 | grep ., with many leftover files, the pipeline ends 141 and the check prints five of them, then ok.

This is step 1 of 2, as #575 was for grep -q. tests/head-pipes scans tests and packages/*/test with the same nv-overlay exclusion as tests/grep-q-pipes. I changed 35 pipes into head on 33 lines at d0028d0 by one rule: head -n N becomes sed -n '1,Np', head -c N becomes { head -c N; cat >/dev/null; }. Both read all their input, with the same bytes and exit status. One line of tests/nv-backup is allowed by its whole text: that test closes stdout early on purpose. bin, tools, tools/lib and rootfs (59 lines in 18 files at d0028d0) are for step 2, as #587 was. tests/all runs the lint; AGENTS.md's grep -q gotcha now names head.

I had AI agents make every run here. Reproduction (in the block): green main 143f2ce's and this commit's tests/rootfs-smoke on a made-up root image with 3000 leftover files. Regression test: tests/head-pipes, which fails on d0028d0's tree and on #884's head -c 64 "$tmp" | head -1.

Device and build

  • Phone: none: test scripts only
  • Kernel release (uname -r): no phone
  • Packages changed, with versions: none (only the test/ scripts of eleven packages)

Checks (no phone needed)

  • tools/pr-check origin/main passes (AI agent)
  • tests/all passes (AI agent, in a no-network sandbox; below)
  • tests/packages passes (or the packages I touched: all eleven, AI agent, in a no-network sandbox; below)
  • Each changed package has its version bumped, and the new version is in the commit subject: test scripts only, as in tests: read the whole pipe instead of grep -q under pipefail #575
  • Commits have area prefixes and bodies that say why; any AI help is a Co-Authored-By: or Assisted-by: trailer, never a Signed-off-by:

On the phone

  • I ran this on my own phone, booted into this build: no: test scripts only
  • Runbook steps passed (plan, step, result): none, no plan step
  • What I did not test: CI; the Docker and container suites; anything on a phone
  • Nothing in this change writes outside slot B and userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1)
tools/phone-smoke report

Not applicable: test scripts that never run on a phone (CONTRIBUTING.md §6.5).

I had AI agents make every run in this description, on an x86_64 desktop running Ubuntu 26.04. Each transcript below names its own commit.

Setup: Ubuntu 26.04 on x86_64, bash 5.3.9, uutils coreutils 0.10.0, e2fsprogs 1.47.2; a fresh git archive of each commit, run in a sandbox with no network.

Steps: build a made-up ext4 root image with mkfs.ext4 -d that passes every earlier check of tests/rootfs-smoke, with 3000 files under /usr/share/omamobile that contain omandroid → tests/rootfs-smoke standin-root.img

Before, on green main 143f2ce7:

+ tests/rootfs-smoke standin-root.img   (3000 files, run 1)
ok - ext4, label omamobile-root
ok - no account but root, and root is locked
ok - keyrings: Arch Linux ARM, Omarchy, Omarchy Mobile
ok - [omamobile] first in pacman.conf, channel stable, its repository in the image
ok - first boot unit, sshd, NetworkManager, networkd and SDDM enabled
ok - MANIFEST, device package, modules for 7.0.0-standin
ok - no modem unit enabled at boot
ok - no install-link marker (an image from before the link)
ok - no per-machine state: keyring, host keys, machine id, SSH keys, Wi-Fi
ok - no Google firmware, vendor trees or per-phone data
/mnt/.rootfs-smoke.l2k2OP/dump/omamobile/leftover/old-project-name-left-in-this-file-number-1.conf
/mnt/.rootfs-smoke.l2k2OP/dump/omamobile/leftover/old-project-name-left-in-this-file-number-10.conf
/mnt/.rootfs-smoke.l2k2OP/dump/omamobile/leftover/old-project-name-left-in-this-file-number-100.conf
/mnt/.rootfs-smoke.l2k2OP/dump/omamobile/leftover/old-project-name-left-in-this-file-number-1000.conf
/mnt/.rootfs-smoke.l2k2OP/dump/omamobile/leftover/old-project-name-left-in-this-file-number-1001.conf
ok - no old project name in /etc, /usr/lib/systemd, /usr/share/omamobile
exit status: 0

After, on 7c3c1255:

+ tests/rootfs-smoke standin-root.img   (3000 files, run 1)
ok - ext4, label omamobile-root
ok - no account but root, and root is locked
ok - keyrings: Arch Linux ARM, Omarchy, Omarchy Mobile
ok - [omamobile] first in pacman.conf, channel stable, its repository in the image
ok - first boot unit, sshd, NetworkManager, networkd and SDDM enabled
ok - MANIFEST, device package, modules for 7.0.0-standin
ok - no modem unit enabled at boot
ok - no install-link marker (an image from before the link)
ok - no per-machine state: keyring, host keys, machine id, SSH keys, Wi-Fi
ok - no Google firmware, vendor trees or per-phone data
/mnt/.rootfs-smoke.xnP1U5/dump/omamobile/leftover/old-project-name-left-in-this-file-number-1.conf
/mnt/.rootfs-smoke.xnP1U5/dump/omamobile/leftover/old-project-name-left-in-this-file-number-10.conf
/mnt/.rootfs-smoke.xnP1U5/dump/omamobile/leftover/old-project-name-left-in-this-file-number-100.conf
/mnt/.rootfs-smoke.xnP1U5/dump/omamobile/leftover/old-project-name-left-in-this-file-number-1000.conf
/mnt/.rootfs-smoke.xnP1U5/dump/omamobile/leftover/old-project-name-left-in-this-file-number-1001.conf
not ok - no 'omandroid' left in /etc, /usr/lib/systemd, /usr/share/omamobile
exit status: 1

The candidate branches from d0028d00. Three runs each: 143f2ce ended ok and exit 0 in 3 of 3, 7c3c125 not ok and exit 1 in 3 of 3, and so did the clean git merge-tree of 7c3c125 with 143f2ce (tree 4e1ea6a5). With 3 such files every tree fails the check, and with none every tree passes.

tests/head-pipes on 7c3c125 passes (149 scripts; 150 on the merge with 143f2ce). Run on d0028d0's tree it lists 34 lines in 20 files: those 33, and the old check name in tests/nv-backup. With first=$(head -c 64 "$tmp" | head -1) added to tests/pr-check, or an edit to the allowed line, it fails and lists that line. Each replacement form, against empty input, one line, fewer and more lines than N, no final newline, NULs and long input, gives the same bytes and exit status as the head it replaces. Fed a long input under pipefail, every old form exits 141, and every new one exits 0.

AI agents ran the host checks on 7c3c125 with Docker and fastboot stubs, in a sandbox with no network. tests/all, whole and unchanged, exits 0 (823 ok) with the user mapped to root in the sandbox's own user namespace. As the ordinary user there, debugfs rdump reports "Invalid argument" instead of "Operation not permitted" when it can't change a file's owner, tools/extract-vendor-firmware lets only the second through, and two real-ext4 cases fail, on d0028d0 too. The two permission checks omitted from the mapped-root run pass in the ordinary user's runs. tests/packages for the eleven touched packages exits 0 as the ordinary user, on 7c3c125 and d0028d0, with the host's UCM files and AppArmor hidden from the sandbox, as in a container: with them, omamobile-audio's UCM check counts an extra alsa-lib error line, and omamobile-shell's D-Bus check can't query AppArmor.

Links: the commit 7c3c1255; the lint tests/head-pipes; the invite on #884; the precedent #575 and #587.

Prior PRs: #575, #587 and #597, my grep -q lint, which this one copies (its pathspec check is #597's).

Not shown:

  • CI.
  • packages/omamobile-omarchy/test/notifications-reply and the two tests/owl container scripts (they need Docker or their container), and omamobile-voice's server check (network).
  • The bin, tools, tools/lib and rootfs pipes, left for step 2.
  • The lint can miss a head on the line after a pipe, | head>file, | { head -1; }, and scripts that set pipefail with set -e -o pipefail. No scanned script has any of these at d0028d0. It can also mistake a Git scan error for no matches.
  • The AOSP image-layout comparisons and the smoke test of an image from tools/build-rootfs. The sandbox runs had neither the AOSP image tools nor a built root image.

Generated with Claude Opus 5.5 in T3 Code Nightly

On derekross#884 the maintainer invited a lint beside tests/grep-q-pipes for
a head that can exit before its writer. Every head form (-1, -n N,
-c N, bare) stops reading once it has its lines or bytes; a writer
that writes again gets SIGPIPE, and pipefail fails the pipeline. A
"|| fail" check then fails at random, a "set -e" assignment ends the
script, and an "if ...; then fail" check passes.

tests/rootfs-smoke's last check is that case: with more than five
files in the image that still name the old project, head -5 exits
while grep -v is still writing, the pipeline ends 141, and the check
prints five of the files and then "ok". On a made-up ext4 image with
3000 such files it passed 3 of 3 runs on main; it now fails 3 of 3,
and still passes on a clean image.

Each pipe into head in a pipefail test script changes by one rule:
head -n N (and -1, -N) becomes sed -n '1,Np' (sed -n 1p for one
line), and head -c N becomes { head -c N; cat >/dev/null; }. Both
read all their input and give the same bytes and status as the head
they replace: checked for every form used against empty input, one
line, fewer and more lines than N, no trailing newline, NUL bytes
and long input. Lines that couldn't race change too, so that no test
pipes into head. One line in tests/nv-backup stays: that test closes
nv-backup's stdout early on purpose (its check's name no longer says
"| head").

tests/head-pipes keeps it that way, in grep-q-pipes' style: it checks
its pattern on lines it must and must not match (derekross#884's head -c 64 |
head -1 among them), fails by name when a pathspec matches no pipefail
script, and allows the one nv-backup line only by its whole text.
It scans tests and packages/*/test, without nv-overlay (left for
derekross#457, as grep-q-pipes leaves it). bin, tools, tools/lib and rootfs
(59 lines in 18 files) are left for a follow-up. AGENTS.md's grep -q
gotcha now names head.

Tested: the lint fails on main's tree with 34 lines in 20 files (the 33
lines that pipe into head, and nv-backup's old check name) and passes
here; a weakened pattern, a pathspec typo or an edit to the allowed line
each make it fail. tools/pr-check origin/main passes. In a sandbox with
no network, tests/all passes up to tests/extract-vendor-firmware, whose
two real-ext4 cases fail there on main too and pass outside it on both;
the suites after it pass one by one. The touched packages' test/all (via
tests/packages) end as on main in that sandbox: omamobile-audio's check
against the host's UCM files and omamobile-shell's portal check fail the
same way on both; omamobile-audio passes with the host's UCM files
hidden, and the shell's sleepd.sh, which that suite runs after the
portal check, passes on its own. Not run: notifications-reply and the
owl scripts (they need their container), and omamobile-voice's server
check (network). Test-only, so no package versions change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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