Repository navigation
Test Composer hosted and agent modes under Bazel on real Bazel - #2146
Conversation
No Bazel ruleset builds PHP or takes Composer packages, and the Bazel registry holds none, so a PHP project under Bazel brings its packages into the build with a few lines of its own. socket-patch has no Bazel code for Composer, and no test held what it does in such a workspace. This adds the `composer::` module of e2e_bazel_build: three flows on a real Bazel, each read from what Bazel builds. The fixture is one workspace with three projects below its root, as a monorepo has them, one per hand-written shape: - services/api: a repository rule (composer.bzl) runs `composer install` from the committed lock, which it takes with rctx.read, so Bazel fetches the repository again when the lock changes. Hosted mode. - services/worker: a genrule runs `composer install` from the lock in a build action. Hosted mode. - services/legacy: the project commits vendor/, and Bazel reads the packages as source files. Agent mode. A flow builds the unpatched marker, runs the one command of its mode and holds it to the exact files it may write, builds the patched marker, which carries an id of the run, and has `vex` attest the package. It undoes the patch: `rollback` restores the lock byte for byte from the registry's metadata, and in agent mode restores the file and leaves a manifest that lists no patch. Then a second machine gets other bytes: Composer refuses the archive on the sha1 of the lock and the build fails without a fetch of the upstream archive, or `scan --mode agent` refuses the blob, writes nothing, and the build stays unpatched. The flows also record what a user meets today: - `scan --json` at the workspace root of a monorepo patches nothing and names the directory to scan. - A relock (`composer update --lock`) puts the upstream entry back over a hosted pin without a word. The next build is unpatched and `vex` attests nothing until the next scan. - The second-machine check is one of an empty Composer cache. With a cache that holds the patched archive, Composer does not ask the host and builds the patch while the host serves other bytes. Vendored mode is in no flow: it breaks the first two builds today. PHP and Composer are the machine's own, from PATH, since no ruleset brings them. A test prints SKIP without one of them, or with one older than the flows take (PHP 7.2.5, Composer 2.0.0), and fails under SOCKET_PATCH_BAZEL_E2E_REQUIRED. At its start it prints the two releases it found beside the two the flows were run on. Every Composer of a flow reads one home that knows the loopback stand-in as its only repository and is the one place that allows plain http, so a Composer on its defaults cannot fetch the package. The Composer that resolves the lock runs behind a proxy that counts connections, and a test fails when it sent a request beyond loopback. A flow does the same in every shell. A repository rule's Composer reads the environment of the Bazel client, so with COMPOSER_AUTH or COMPOSER_DISABLE_NETWORK set in the shell the repository rule flow failed. The harness now removes `COMPOSER` and every `COMPOSER_*` variable from every Bazel child, as it does for pip and uv, and the hermetic test that guards its lists has the names. A flow then sets the five names its Composers need. One of them is COMPOSER_ROOT_VERSION: the Composer that makes the committed vendor/ tree runs under the target directory, inside this repository's checkout, and without a version it asked git for one and wrote the branch and the commit of that checkout into the tree. The agent flow now asserts that the tree names no commit but the package's. In Bazel's Linux sandbox a build action has a /tmp of its own, so the genrule flow fails at its start, with the remedy, when the Composer home is under /tmp. bazel-composer.yml runs the legs on Bazel 9.3.2, 8.8.2 and 7.7.2 for pull requests and pushes to main that touch the Composer files, every night and on demand. The legs take the PHP and the Composer of their runner, and nothing pins them. GitHub's description of its ubuntu-24.04 image lists PHP 8.3.6 and Composer 2.11.2; what the runner of the legs holds is not confirmed before their first run. There is no macOS leg: GitHub's description of the macOS image lists neither tool. A caller says so with an empty `macos` list, and bazel-compatibility.yml now skips its macOS job for an empty list instead of failing on an empty matrix. Two shared files change: bazel-compatibility.yml by that one condition, and harness.rs by the Composer names in its removal lists. On macOS arm64 with PHP 8.4.23 and Composer 2.11.2 the three flows pass on the three releases. With an empty repository cache a flow takes 11 to 19 seconds on an idle machine, and took up to 56 while other builds ran. A leg downloads nothing but what Bazel resolves for its own modules: 1.7 MB on 9.3.2, 26 MB on 8.8.2 and 0.7 MB on 7.7.2. Because the harness changed, the Go, npm, PyPI and RubyGems flows ran once on Bazel 9.3.2, and pass. Nothing ran on Linux yet. No file under crates/*/src changes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryLow Risk Overview Introduces The shared harness strips Reviewed by Cursor Bugbot for commit 9a374f6. Configure here. |
|
[agent] PR shepherd: review brief for the approver What it does. Adds three real-Bazel Composer flows: hosted mode, and agent mode with a genrule. They show that a patched package is pinned in Risk: low. No product code changes. The real-Bazel flows are Look here
Verified
Changes I made: none. Open questions (minor, none blocking):
Generated by Claude Code |
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Reviewed at 9a374f6. Tests, fixture and workflow only, plus the harness scrubbing COMPOSER and COMPOSER_*. All three flows ran and passed on 7.7.2, 8.8.2 and 9.3.2, asserting the exact composer.lock rewrite, the patched marker from the build, no upstream fetch and a checksum refusal. The bazel-compatibility.yml change only lets a caller passing an empty macOS list skip that job. Non-blocking: PHP and Composer come unpinned from the runner image, so an image update could break these legs; the mod composer; line in main.rs will conflict with #2147.
Keep both test modules: main added `mod cargo;`, this branch `mod composer;`. Assisted-by: Claude Code:claude-opus-5-5
No user-visible change.
What this is
Tests only. No Bazel ruleset builds PHP or takes Composer packages, and the Bazel Central Registry has none, so a PHP project under Bazel brings its packages into the build with a few lines of its own. socket-patch has no Bazel-specific code for Composer, and until now no test held what it does in such a workspace. This pull request adds the
composer::module ofe2e_bazel_build: three flows on a real Bazel, for the two modes that put a patch into such a build today, each read from what Bazel builds.Contents
crates/*/src)crates/socket-patch-cli/tests/e2e_bazel_build/composer.rs(1,302) and onemodline inmain.rscrates/socket-patch-cli/tests/fixtures/bazel/composer/bzlmod, 12 files.github/workflows/bazel-composer.ymle2e_bazel_build/harness.rs.github/workflows/bazel-compatibility.ymlTwo shared files change, each by one edit:
bazel-compatibility.ymlgains one condition: its macOS job is skipped when a caller passes an emptymacoslist. GitHub fails a job whose matrix is empty, so until now a caller could not leave the macOS leg out.harness.rsnow removesCOMPOSERand everyCOMPOSER_*variable of the shell from every Bazel child, in the lists that already do this for pip, uv and bazelisk. The hermetic test that guards those lists has the new names. The Composer that a repository rule starts reads the environment of the Bazel client, so without this a developer's Composer settings changed what a flow did.The other ecosystems' modules, fixtures and workflows are untouched.
The fixture is one workspace with three PHP projects below its root, as a monorepo has them. Each stands for one shape a project writes by hand:
services/api: a repository rule (composer.bzl, 50 lines) runscomposer installfrom the committedcomposer.lock. It takes the lock withrctx.read, so Bazel fetches the repository again when the lock changes.services/worker: a genrule runscomposer installfrom the lock in a build action.services/legacy: the project commits itsvendor/tree, and Bazel reads the packages as source files.The harness builds
//:consumer, so each test writes a rootBUILD.bazelthat points that label at its project. The fixture commits no lock and novendor/tree: a test has real Composer make them for the run, against the loopback stand-in.What it proves, and where
composer::hosted_repository_rulecomposer::hosted_genrulecomposer::agent_committed_vendorvendor/Each flow is one
#[ignore]d test:scan --mode hosted --yesrewritescomposer.lockand nothing else: the package'sdistbecomes the patched archive with its sha1, and its gitsourcegoes.scan --mode agent --yespatches the one file undervendor/and writes.socket/manifest.jsonand two blobs.--lockfile_mode=errorbuild passes, andvexattests the package.rollback --yesrestores the lock byte for byte from the registry's metadata, and the build is the unpatched one again. In agent mode it restores the file byte for byte.scanrefuses it and writes nothing, and the build stays unpatched.A flow does the same in every shell and in every checkout. Its Composers get their settings from the test and none from the shell: five for the developer's Composer and the repository rule's, and the Composer home alone for the build action's. One of the five is a fixed version for the project itself: without it Composer asks git, and the committed
vendor/tree would name the branch and the commit of this repository's checkout. The agent flow asserts that the tree names no commit but the package's.Results at this commit, on macOS arm64 with PHP 8.4.23 and Composer 2.11.2, each release with a fresh output root and an empty repository cache. Seconds per test:
composer::hosted_repository_rulecomposer::hosted_genrulecomposer::agent_committed_vendorAll nine pass. Earlier rounds on the same machine took up to 56 seconds per test while other builds ran.
The three flows also pass on 9.3.2 with
COMPOSER_DISABLE_NETWORK=1,COMPOSER_AUTH=not-jsonandCOMPOSER=/nonexistent/composer.jsonexported in the shell.Because the shared harness changed, the flows of the other ecosystems ran once on Bazel 9.3.2 at this commit, and pass:
go::hosted_go_deps(72 s),npm::hosted_npm_translate_lock(19 s),npm::vendored_npm_translate_lock(19 s),pypi::hosted_pip_parse(21 s) andruby::hosted_bundle_fetch(35 s).Before the code review, each assertion was checked by breaking it: 17 changes to the test, one at a time on Bazel 9.3.2, and every one failed the flows it should. Among them: the scan left out, upstream bytes served under the patched name, a patched archive that holds no patched file, and the other-bytes step left out. Those 17 were not run again after the review. What the review added was checked the same way at this commit:
a child sees COMPOSER), and with the three variables above exported the repository rule flow fails on the malformedCOMPOSER_AUTH.SKIPand pass, and fail underSOCKET_PATCH_BAZEL_E2E_REQUIRED./tmpapplies on Linux only. Pointed at this machine's paths instead, it stops the genrule flow at its start with its message.On Linux, on GitHub's runners, the three Composer legs of this pull request pass at its head on Bazel 9.3.2, 8.8.2 and 7.7.2 (158 to 171 seconds per leg; the three flows together take 32 seconds on 9.3.2). The runner had PHP 8.3.6 and Composer 2.10.3, so the flows have now run on two Composer releases. The Go, npm, PyPI and RubyGems legs, which the harness edit starts, pass too, with the other checks (69 in all). The macOS job shows as skipped, as it does for every caller on a pull request; the first nightly evaluates the empty list.
What starts on main
bazel-composer.ymlcallsbazel-compatibility.ymlfor three Linux legs: Bazel 9.3.2, 8.8.2 and 7.7.2.composerin its name, orpatch/user_patches.rs.patch/redirect, the apply and rollback engines,manifest,hosted,vex,commands), the shared test helpers and the toolchain files.17 5 * * *) and on demand (workflow_dispatch), so a main change outside the push list gets a run within a day.macoslist, andbazel-compatibility.ymlskips its macOS job for an empty list.PATH. Nothing installs or pins them. The legs run on the runner thatbazel-compatibility.ymlnames:depot-ubuntu-24.04-4, orubuntu-latestwhen the repository variableDISABLE_DEPOT_RUNNERSistrue. This pull request's run shows what that runner holds today: PHP 8.3.6 and Composer 2.10.3. GitHub's description of its own ubuntu-24.04 image lists PHP 8.3.6 and Composer 2.11.2. A test prints the two releases it found at its start, so the first run of this pull request shows them. Without one of the tools, or with one older than the flows take (PHP 7.2.5, Composer 2.0.0), a test fails underSOCKET_PATCH_BAZEL_E2E_REQUIRED, which the legs set, and printsSKIPotherwise.bcr.bazel.build,github.comandrelease-assets.githubusercontent.com, for what Bazel resolves for its own modules. That is 1.7 MB on 9.3.2, 26 MB on 8.8.2 and 0.7 MB on 7.7.2. There is no ruleset archive and no toolchain. The package under test, the Socket API, the patch host and Packagist are one loopback server.merge_grouptrigger, and no job is aneedsofci-ok.Known behaviour
What a user with PHP under Bazel meets today. The first three are not tested here.
rctx.symlinkinstead ofrctx.readkeeps the old tree on a developer's warm output base, on Bazel 9.3.2 and 8.8.2, after a scan and after a rollback alike.composer updateorcomposer update --lock. The test asserts the second: Composer puts the upstream entry back without a word, the next build is unpatched, andvexattests nothing until the next scan.scan --jsonat the workspace root patches nothing and names the directory to scan (asserted).vexandrollbackat the root exit non-zero and name--cwd <project>.vendor/tree to a sum. In agent mode the check is the command's own refusal of a blob that does not match the patch.rollbackin agent mode,.socket/manifest.jsonstays, listing no patch.PATH. A project whose genrule runs the machine'sphpandcomposerneeds--action_env=PATHand a Composer home for the action, as the fixture's.bazelrchas.vexneeds--productin a checkout with no git remote whosecomposer.jsonhas no name and version.Not claimed
actionlintaccepts the expression.vendor/.Left open
SKIPrule and the loopback host list repeat helpers that are private to the harness. They belong to one harness change for all modules.Decisions for the owner
composer updateexits 2 unless--no-security-blocking), whilecomposer installfrom a lock still installs. The relock caveat above was seen with a registry that lists no advisory. On real Packagist a relock of a package Socket has patched may fail instead of dropping the pin. Worth one run against production.socketsecurity/bazel-fixture-upstreamfollows the npm fixture. On Packagist a vendor name belongs to whoever publishes under it first, and I did not check who holds this one. The tests do not depend on it: every Composer of a flow reads a home that knows only the stand-in, and the one that resolves by name runs behind a proxy that counts connections and fails the test on any.Code review
A code review of this pull request made nine findings. Four are fixed, one led to a corrected comment and is otherwise left open, and four are left open for the reasons given.
executeinherits the environment of the Bazel client, and the harness removed no Composer name, soCOMPOSER_DISABLE_NETWORK=1or a malformedCOMPOSER_AUTHin the shell failedcomposer::hosted_repository_rule. Fixed in the harness, for every ecosystem:COMPOSERand everyCOMPOSER_*name are removed from every Bazel child, and the hermetic test of the removal lists has the names. A flow sets the names it needs after the removal. To see that they still arrive, the fixture's rule and action were made to print the Composer variables they see, on Bazel 9.3.2 withCOMPOSER_DISABLE_NETWORK,COMPOSER_AUTHandCOMPOSERexported as above: the rule saw the test's five and none of the shell's, and the action saw the test'sCOMPOSER_HOMEandCOMPOSER_CACHE_DIR=/dev/null.SKIPand passes. Fixed: a release below the floor counts as a tool that is not there. TheSKIPline names the release found, the floor and the releases the flows were run on, and the test fails only underSOCKET_PATCH_BAZEL_E2E_REQUIRED. Each flow now prints the releases it found beside the ones it was run on, so a failure on an untested release has a first hint. One hermetic test holds the decision.vendor/tree wrote this checkout's branch and commit into the tree. It runs under the target directory, inside the checkout, and had no version for the project, so it asked git. Confirmed by a run:vendor/composer/installed.phpnameddev-mainand the head commit. Fixed: the flows give Composer a fixed project version. With it Composer starts no git at all: a trial ofcomposer updatein the same place, with a logginggitfirst onPATH, counted three git commands without the version and none with it. The agent flow asserts that the tree names no commit but the package's./tmp. It is under the target directory because a build action in Bazel's Linux sandbox has a/tmpof its own. Fixed: on Linux the genrule flow fails at its start when the home is under/tmp, and says to give cargo a target directory outside it.SKIPrule and the loopback host list repeat private helpers of the harness. Not changed here (see "Left open").Generated by Claude Code