Repository navigation
Never take a native gem build that compiled nothing of a patch for a patched build; test agent mode on real nokogiri - #2136
Conversation
tests/nokogiri/nokogiri_e2e.rb installs one nokogiri release with the real Bundler, applies a Ruby-only record, a C source record and a vendored-libxml2 patch record with the real binary, and checks what the install's Ruby loads, apply --check, vex and a byte-identical rollback. nokogiri-compatibility.yml runs it on the runner (Ruby 2.3 to 3.4 and JRuby, the precompiled gem of each line, source and system-library builds, macOS, Windows, ARM) and inside official Ruby images (Alpine, slim, the Debian releases old Rubies shipped on) with a static binary. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
libxml2's configure script reads INSTALL from the environment as the install program, so a step that set INSTALL=precompiled broke every build. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Each precompiled and source leg now installs the Rails of its years and checks that a booted application sanitizes HTML through the patched nokogiri. The ruby:2.3 leg names the image's manifest list, which Docker can pull, and ruby:2.1 covers the oldest RubyGems a rebuild supports. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two defects found with real nokogiri installs: A precompiled gem was rebuilt with the build arguments RubyGems recorded for it, which were never used to build it. Bundler's build.nokogiri --use-system-libraries, a setting many projects kept from before nokogiri shipped precompiled gems, is recorded for the platform gem too, so apply replaced the libxml2 2.13 the gem ships with the system's 2.9. A precompiled copy is now rebuilt as its publisher built it: no recorded arguments, and NOKOGIRI_USE_SYSTEM_LIBRARIES removed from the build. A gem built against the system's libraries compiles nothing of the library it packs. A record that only changes the packed library (a new patches/libxml2/*.patch, a third of the published nokogiri patches) was written, rebuilt against the same system library and attested by vex as patched. It is now refused from files alone (recorded build arguments, the build log, or the environment) with nothing written, and never attested. The nokogiri matrix covers both, and its Rails legs hold the loofah of their nokogiri's years. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A precompiled gem whose lock names a private gem server is refused with "put the source gem in cache/". Most such servers are mirrors of rubygems.org, and naming one in SOCKET_RUBYGEMS_URL is all it takes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review of the previous commit found the system-library handling covered precompiled copies only and guessed at mkmf's rules: - A gem RubyGems built is rebuilt against what its installed build linked, read from that build's log, else from the recorded build arguments. A nokogiri installed with NOKOGIRI_USE_SYSTEM_LIBRARIES set for the install alone was rebuilt with the packed libxml2, and one built from the packed libraries was rebuilt against the system's when the variable was set at apply time. - Build arguments are read as mkmf reads them (--enable, then --disable, then --use, any value a yes), word by word, since Bundler 1 recorded a whole setting on one line. - The variable alone counts only for nokogiri, and only when neither the log nor the arguments say what the copy links. - apply --check and vex do not attest a packed-library record on a system-library build, whatever marker the copy holds. - The refusal message had lost its line continuations. - A lock's gem server and SOCKET_RUBYGEMS_URL name one server with or without credentials, and the mirror hint is given only where it can work. The x86_64 Linux legs of the nokogiri matrix run the one static binary instead of building the CLI fourteen times, a leg covers the variable-only install, and the workflow's development trigger is gone. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryHigh Risk Overview Patches that only touch vendored library inputs ( Adds Reviewed by Cursor Bugbot for commit 95b54a1. Configure here. |
The system-library handling knew nokogiri: its environment variable, the wording of its build log, mini_portile's directories and a check on the gem's name. It is replaced by what holds for every gem. A compiler reads what it compiles, and a build script reads the patch files it applies. The record's build inputs are given an access time in the past before the build, staged or in place, and a build that exits cleanly having read none of them is not a build of the patch: the copy is left as it was and is never attested. That is the case of a gem built against the system's copy of a library it packs, without the CLI knowing any gem's switches. One read is enough, since a record also carries files no build opens, and nothing is concluded where the filesystem records no reads. What stays is the rule about RubyGems' own record: a copy RubyGems built is rebuilt with the arguments recorded for it, and a precompiled copy, which its publisher built, with none. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Access times say whether a build read a file only where the filesystem records reads. This repo's own CI runners are mounted noatime, and so are many container hosts, so there the check concluded nothing and a patch that was compiled into nothing was still attested. On Linux the kernel says which of the watched files were opened, whatever the mount options; access times stay as the way to tell elsewhere. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Without a kernel watch, an input whose access time could not be set may be the one the build read. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A gem's build does not always compile what a patch changes. One built against the system's copy of a library it packs never opens the packed copy, and one whose extension script downloads the binary it runs (passenger's agent) compiles nothing at all. apply reported such a patch as applied, and vex attested it, while the code the gem runs was unchanged (#2144). Since the read check it was refused with nothing written, which also kept the patch's Ruby files out. apply now writes the record's files, leaves the compiled code as it was installed, and warns with native_extension_not_rebuilt when a clean build read none of the record's build inputs or left no compiled file. No build marker is written, so apply --check reports the package as not in sync and vex does not attest it. A record that changes a build input the installed copy no longer holds is still refused: only a build from the source gem accounts for a file added that way. An in-place build that kept the library it found is still a failed build: that reason is reported ahead of the read check, which the real-toolchain test of it expects. A build can run for many minutes with nothing printed. Each one now says on stderr when it starts and how it ended (not under --json or --silent). Fixes #2144 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- vex told the user to run apply to rebuild a copy whose build compiles nothing of the patch, which changes nothing there. It now says that apply rebuilds it or says why it cannot. - The staged install of a patched gem (the hosted stale-install refresh) and of a gem a build needs printed nothing while they ran. Both now say what they are doing. - The registry test that ignores credentials lived in gem_source alone, so the lock restore still took a mirror named with credentials for a different server. The shared is_rubygems_remote now does it, with the shared URL stripper in place of a second one. - The warning listed the patch's files twice in one sentence. - Comments in the nokogiri harness and in apply still described the refusal the previous commit replaced. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
LLM Description written by Claude Code:claude-fable-5-2
Summary
Adds an end-to-end test of agent-mode patches on real nokogiri installs, run
over 25 combinations of Ruby, nokogiri release, install shape and platform,
and fixes the defects it found, plus the ones reported in #2144 (passenger).
They share one cause: a native gem's build exits cleanly without compiling
what the patch changes, and
applytook that for a build of the patch.applyreplaced the libxml2 a precompiled nokogiri ships with thesystem's. A project that still carries Bundler's
build.nokogiri --use-system-librariesgets that argument recorded for the precompiledplatform gem too, and the rebuild followed it.
A patch to the packed libxml2 was attested on an install that never
compiles it. On a nokogiri built against the system's libxml2, a record
that only adds
patches/libxml2/*.patch(the shape of about a third of thelive nokogiri patches) was written, "rebuilt" against the same system
library, and reported by
vexas patched.A gem whose extension script downloads the binary it runs was reported
as patched (apply reports a passenger gem patch as applied while the downloaded agent it runs is unchanged; on main the rebuild runs 16 minutes and its product is discarded silently #2144). passenger's only extension fetches a prebuilt agent.
A patch to the agent's C++ was "applied" and would be attested while the
agent was byte-for-byte unchanged, and on
maina 16-minute staged buildran with nothing printed and its product was discarded.
The first two are not in a release: the rebuild from the source gem landed on
mainafter 5.1.0.Fixes #2144
What was measured
On nokogiri 1.18.10, macOS arm64, Ruby 3.4.10 (system libxml2 2.9.13, packed
libxml2 2.13.9):
mainbuild.nokogiri --use-system-libraries--use-system-librariespatches/libxml2/…apply --checkin sync,vexnot_affected; libxml2 2.9.13 with no patchnative_extension_not_rebuiltwarning,apply --checknot in sync, not attested--use-system-librariespatches/libxml2/…The fix
Both rules are about RubyGems builds in general. Nothing in the CLI names
nokogiri, its switches, its log or its directories.
compiler reads what it compiles, and a build script reads the patch files
it applies.
applywatches the record's build inputs during the build,staged or in place: on Linux with a kernel watch on those files being
opened (inotify), elsewhere by giving them an access time in the past and
looking at it right after. A build that exited cleanly having read NONE of
them did not build the patch. Neither did one that left no compiled file
(nothing in RubyGems' extension directory, nothing Ruby loads in the gem's
tree). One read is enough to pass, because a record also carries files no
build opens. Where a read leaves no trace (
noatimeor Windows, offLinux), which
applytests with a file of its own, nothing is concludedfrom the reads.
files go into the installed copy, the compiled code stays as it was
installed, the package's event is
appliedwith exit 0, and the runcarries a
native_extension_not_rebuiltwarning that names the files andthe reason. No build marker is written, so
apply --checkreports thepackage as not in sync and
vexdoes not attest it. This keeps thepatch's Ruby files in effect, and a source the gem compiles later on its
own (passenger builds its agent the first time it starts without one) is
the patched one. An earlier version of this branch refused instead; apply reports a passenger gem patch as applied while the downloaded agent it runs is unchanged; on main the rebuild runs 16 minutes and its product is discarded silently #2144
showed why that is wrong for a patch that relies on its Ruby half. The one
refusal left: a record that changes a build input the installed copy no
longer holds, which only a build from the source gem accounts for.
(
Rebuilding the native extension of <gem> from <what>; this can take several minutes./The build of <gem> finished after 4m 12s.), notunder
--jsonor--silent.RubyGems records the arguments a gem was installed with, and Bundler
records its
build.<gem>setting for a platform gem too, although nothingwas built with them. A copy RubyGems built is given its recorded
arguments again, as
gem pristinegives them; a precompiled copy, whichits publisher built, takes none.
SOCKET_RUBYGEMS_URLwhen that server is a mirror, and a server named withcredentials there matches the same server named without them in the lock.
CLI_CONTRACT.mdanddocs/ecosystems.mddescribe the rules.The nokogiri test
tests/nokogiri/nokogiri_e2e.rbis one Ruby file with no gem dependencies(Ruby 2.1 syntax), so it runs wherever the install under test runs. It
installs one nokogiri release with the real Bundler, lays three hand-built
records over it with the real binary, and checks what a fresh Ruby loads
through
bundle exec:ext/nokogiri/nokogiri.c),extension).
Each scenario runs
apply --check,apply, the load,apply --check,applyagain,vexandrollback, then compares every file of the installwith what it started from. With
--railsit also boots a Rails applicationand sanitizes HTML through the patched nokogiri.
.github/workflows/nokogiri-compatibility.ymlruns it (not required formerge; path-filtered on PRs, on pushes to
mainthat touch the rebuild, andnightly):
x86_64-linuxand-gnugems--use-system-libraries(the libxml2 record is written and not attested); the legacy setting on a precompiled gem; no compiler onPATHubuntu-24.04-arm, macOS, Windowsaarch64-linux-gnu,arm64-darwinandx64-mingw-ucrtgems; a source build on macOSruby:3.4-alpine,ruby:3.4-slim(with and without a compiler),ruby:2.7,2.5,2.3,2.1The x86_64 Linux legs share one static musl binary; macOS, Windows and ARM
build their own.
What a reviewer should weigh
first read after an access time older than the modification time, which is
what the check sets up. On a
noatimemount off Linux and on Windows itcannot tell, and says nothing. The CI runners for the x86_64 Linux legs
are mounted
noatime, which is why Linux uses inotify. A build thatcopies its whole source tree before compiling reads every file, so it
always passes.
warning from
apply, and a failingapply --checkfor as long as thatpatch is in the manifest. That is deliberate: the files are written and
the compiled code is not patched, and
--checkanswers the second.scanpicks one patch per package version by severity, not by whether itcan take effect on this install.
applyruns that build again before it says so: about 10 to 20 secondsfor a system-library nokogiri, as long as the gem's build takes otherwise. A
memo beside the build marker would save it; the marker file is
special-cased in enough places that I left it out of this change.
compiles nothing on this platform by design. Nothing tells the two apart,
and withholding is the side that cannot be wrong.
applywas started in, asgem installdoes. A gem installed with a build switch given only in the environment of
that one install (nothing records it) is rebuilt without it, as
gem pristinewould rebuild it.about 57 characters to every build path, and MinGW's
arstops at 260. Arebuild there takes about 8 minutes.
Code review
/code-review highran twice.The first run, on the first version of the fix (which read nokogiri's
switches), raised ten findings. Its main one, that the rule was specific to
one gem's layout and left others (rugged, ffi) attested, is what the read
check answers: it holds for any gem. Also fixed then: a refusal message that
had lost its line continuations; the mirror hint offered where it could not
work; the leftover development trigger; fourteen redundant CLI builds; and a
retry filter that matched every Bundler failure.
The second run, on this version, raised ten more. Fixed:
vextold the user to runapplyto rebuild a copy whose build compilesnothing of the patch.
and of a gem a build needs printed nothing while they ran.
restore disagreed with it; it is in the shared
is_rubygems_remotenow,with the shared URL stripper instead of a second one.
refusal.
Not fixed, and why:
classification is broad on purpose (anything that is not clearly plain
counts, because a build script reads whatever the gem packs). A record
whose only inputs are files no build opens (a runtime data file, a source
compiled only on another platform) beside Ruby files is now written and
not attested, where
mainrebuilt and attested it. Reads cannot tell thatcase from a system-library nokogiri, where the patch really is in nothing
that runs, so the rule withholds in both.
apply --checkthen stays outof sync for that package.
appliedevent for a patch whose compiled part is not ineffect. A pipeline that gates only on the exit code proceeds. apply reports a passenger gem patch as applied while the downloaded agent it runs is unchanged; on main the rebuild runs 16 minutes and its product is discarded silently #2144 asks
for a qualified apply, not a failure, because the patch's Ruby half is
what makes passenger build its patched agent. The qualification is the
native_extension_not_rebuiltwarning, a failingapply --checkand noVEX statement. A failing exit code is the alternative if you prefer it.
applyrepeats the build before it reaches the same conclusion(see above). A memo is a follow-up.
no inotify on a
noatimemount the two hermetic tests would fail insteadof skipping. CI has inotify.
Testing
file or listing its directory is not a read, one read passes, nothing
marked concludes nothing. Unit tests for credentials in a server URL.
e2e_gem_native_ext_build, hermetic tests with the stand-in Ruby: aprecompiled copy built without recorded arguments and a built one with
them; a staged build that reads nothing of the patch writes it, warns, is
not attested, says the same on a second run, rolls back to the same tree,
and the same record is built by a build that reads it; an in-place build
that reads nothing keeps the previous build; a build that leaves no
compiled file (the passenger shape) writes the patch and attests nothing;
the start and end lines are printed, and not under
--jsonor--silent.30 pass locally.
a_build_that_compiles_nothing_is_refused_and_not_attested, which failedon the previous head because the read check answered before the
stale-build check. So do
e2e_redirect_gem_build(47) ande2e_vendor_gem_build(11), 191 unit tests in the gem modules, and CI'sclippy command.
--use-system-libraries, locally withthe final code (40 checks pass): the Ruby record applies, the C record is
rebuilt against the same system libxml2 and attested, and the libxml2
record is written in 8 s with the warning, loads the same binary, is not
in sync for
apply --check, is not attested, and rolls back to abyte-identical tree. The other install shapes run in CI.
branch: the 51 live catalog patches for nokogiri 1.10.10, 1.11.7, 1.13.10,
1.17.2, 1.18.3 and 1.19.3, on precompiled and source installs (59 runs on
Ruby 2.6 and 3.4, macOS arm64), each applied, loaded, checked, attested and
rolled back to a byte-identical tree.
clean exit, an empty extension dir, a binary outside what Ruby loads).
🤖 Generated with Claude Code