Repository navigation
Decline Composer vendored mode in a Bazel workspace - #2186
Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
Conversation
Tests only. No Bazel ruleset builds PHP, so a PHP project under Bazel brings its Composer packages into the build with a few lines of its own: a repository rule or a genrule that runs `composer install` from the committed lock, or a committed `vendor/` tree. The real-Bazel Composer flows ran hosted mode and agent mode in those projects, and vendored mode in none. Two flows record what vendored mode does there today: - composer::vendored_repository_rule, in the project whose packages a repository rule installs. `scan --mode vendored --yes` exits 0 with status `success` and reports the package vendored. It keeps the patched package under the project's `.socket/vendor` and rewrites the lock entry to a path dist, `.socket/vendor/composer/<uuid>/<vendor>/<name>@<version>`, which Composer reads from the directory it runs in. The next `bazel build` fails: the rule runs Composer in a repository of Bazel's that holds the two Composer files and nothing else, and Composer says `Source path "<that path>" is not found for package <vendor>/<name>`. `vex` attests the package all the same. `vendor --revert` puts every file back, and the build with them. - composer::vendored_committed_vendor, in the project that commits its `vendor/` tree. The command vendors the package, and the build passes and stays the unpatched one, because Bazel reads the committed tree. After the developer's `composer install` in the project's directory, which copies the package from `.socket/vendor` without a request to any host, the build is the patched one. `vendor --revert` restores the lock and removes the copy. The first flow records a defect: a command that exits 0 leaves a build broken. It is here so that the change which removes the defect shows as a change of this test's expectations. `Machine::composer` now creates the directories of the files it is given: the committed tree and the vendored copy are nested. The workflow's comments name the two flows. Run on Bazel 9.3.2 with PHP 8.4.23 and Composer 2.11.2 on macOS arm64: the five `composer::` flows pass, the two new ones in about fifteen seconds each. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Vendored mode makes composer.lock name the patched copy by a path dist, `.socket/vendor/composer/<uuid>/<vendor>/<name>@<version>`, which Composer reads from the directory it runs in. No Bazel ruleset builds PHP, so a PHP project under Bazel brings its packages into the build with a few lines of its own: a repository rule or a genrule that runs `composer install` from the committed lock, in a directory of Bazel's that holds the two Composer files and nothing else. There the path names nothing. The command exited 0 with status `success`, `vex` attested the package, and the next `bazel build` failed with Composer's `Source path "..." is not found for package ...`. Measured on Bazel 9.3.2, 8.8.2 and 7.7.2 over the shapes such a project is written in: of sixteen vendored runs eight left the build broken, and the other eight built the unpatched package. What a workspace's rules do with the lock cannot be read from its files. A rule may take the lock through a glob, or live in another module. A committed `vendor/` tree does not settle it either: it shows that Composer has run in the project's directory, not that no rule runs it somewhere else as well, and a workspace with both a committed tree and a repository rule that installs from the lock fails the same way (Bazel 9.3.2). So the refusal reads none of that. Every Composer project in a Bazel workspace is declined, and the user's word is the one thing that lifts it. When the project's directory, or one above it up to the root of its git checkout, holds MODULE.bazel, REPO.bazel, WORKSPACE or WORKSPACE.bazel (`bazel::bazel_root`), every command that would vendor a Composer package refuses it with `vendor_composer_bazel_workspace`: `scan --mode vendored`, `get --mode vendored`, `vendor` for a patch the manifest records, the takeover of a hosted pin by a vendored scan and the eject of one by `vendor`. A `scan` or `get` that names no mode runs in vendored mode in a project that is already vendored, and is refused there too. The package is a `failed` event and the run exits 1 (`partialFailure`; for the eject `eject_refused`). A dry run of `scan` or `get` lists the package as one the run would refuse and exits 0; `vendor --dry-run` reports the refusal and exits 1, as it does for any package it could not vendor. Nothing is written, no patch is downloaded, and a hosted pin stays. The refusal itself only looks for the workspace file: it starts no program. The detail names the Bazel root and the mode that writes no such path, `--mode hosted`, and promises no more of it than that: hosted mode names the patched archive by a URL, which Composer fetches from any directory. It patches the build when Bazel runs Composer on the rewritten lock. Where Bazel does not, the hosted run exits 0 and the build stays the unpatched one, as before this change: a repository rule that links the lock with `rctx.symlink` is not run again on Bazel 8 and 9 until its repository is fetched again, and an `http_archive` of the package never reads the lock. The docs' limits now say so. The user lifts the refusal with the new global flag `--allow-vendored-in-bazel` or SOCKET_ALLOW_VENDORED_IN_BAZEL=1: for a project that Bazel does not build, for one that commits its `vendor/` tree where no rule installs from the lock as well, or for one whose rule brings `.socket` to where it runs Composer. The switch is not Composer's alone: it lets vendored mode write for a package although the project is in a Bazel workspace, where the build may not find the vendored copy, so that a refusal of another ecosystem that rests on the workspace can read the same one. Its binding is `vendor::refusals::ALLOW_IN_BAZEL_ENV`, beside the dispatch; the code of a refusal keeps its ecosystem. The flag is shaped like `--gem-refresh-shared`: a boolean global with an environment binding, off by default. The CLI mirrors it into the environment, where core reads it, as it does for `--offline`. A socket.yml key was not used: that file's policy only narrows what a run patches and names no safety switch. `vendor --revert` is not refused: it takes the path out of the lock. A project vendored with the flag, or by an earlier release, is refused again by a later vendored run without the flag, which changes nothing. Outside a Bazel workspace a vendored run with a Composer package looks for the Bazel root and does what it did; other ecosystems, hosted mode and agent mode are not touched. The answer has one home, `vendor::composer_lock::bazel::refusal`. `vendor_refusals`, which every vendored entry point reads before it downloads anything, hands it to each Composer candidate, and the eject asks it in its preflight, before it restores a pin. No line a person reads is new. The refusal prints where every refused vendored package does: `[error] <purl> (<code>): <detail>` from `scan` and `get`, `[would-refuse] ...` in their dry runs, and `Error: Cannot vendor <purl>: <detail>` from `vendor` (`kept hosted: <detail>` for the eject). The scan's closing totals count the package's advisories among those in packages the run did not patch. Tests: - composer::vendored_repository_rule (real Bazel) now holds the command to the refusal: exit 1, the code, a detail that names `--mode hosted` and the flag, no file changed and no request for the patched archive. The same build passes on the upstream package. Hosted mode then patches the build and `rollback` restores it. With the flag the expectations of the previous commit are back: the package is vendored and the build fails with Composer's message. - composer::vendored_committed_vendor (real Bazel) holds it to the refusal in the project that commits its tree too. With the flag the expectations of the previous commit are back: the package is vendored, the build stays the unpatched one, and after the developer's `composer install` it is the patched one. - Two tests of the same file need no Bazel, PHP or Composer. Every command that would vendor refuses and writes nothing, the dry runs of `vendor` and of its eject among them, and the eject's detail starts `kept hosted: `. Vendored mode goes on in no Bazel workspace, with the flag and with the variable; a later run without them is refused again, a scan that names no mode included; and `vendor --revert` needs neither. - Unit tests of the refusal (each workspace file name, in the project and at the root of its checkout; the detail names that root, hosted mode and the flag; a workspace beside the project is not the project's) and of its dispatch (every Composer candidate, no other ecosystem, not a benign skip). - cli_global_args and clap_parse have the rows of the flag. Docs: docs/ecosystems.md "Bazel workspaces: Composer", and the rows of the flag, its variable, the code and the Composer line of the vendored table in CLI_CONTRACT.md. bazel-composer.yml starts its legs for a change to `bazel/` and to vendor/refusals.rs too. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…e eject's refusal first Follow-ups to the refusal of Composer vendored mode in a Bazel workspace. An in-sync run passes. The refusal hit every Composer package of the project, whatever the lock said. A project that was vendored before (by an earlier release, or with the flag) then failed its next routine run with exit 1, a plain `scan` or `get` included, although that run would have written nothing. What the refusal is for is the write of the path into composer.lock, so a package whose lock entry already names the copy of the same patch is now let through. A new patch for that package, and any other package, is refused as before. The eject asks first. `vendor` over hosted pins asked the refusal per pin, after it had fetched every pin's record from the service and planned the upstream restore. An offline run, or one the service could not answer, reported `patch_fetch_failed` first and met the refusal only on the retry. It is now asked once, before any record is fetched, and the report of a refused eject is one function for both places. The test holds that a refused eject sends the service no request. One dispatch. `vendor::refusals::bazel_workspace_refusals` is the answer every vendored entry point takes, the eject included, so a refusal of this kind for another ecosystem has one place to go. Smaller things: - the message names the Bazel root without the verbatim prefix that a canonical path has on Windows, as the `.bazelignore` messages do; - the unit test of the dispatch holds the switch unset instead of reading the developer's environment; - the Composer legs start for bazel/mod.rs and utils/repo_root.rs, the two files the lookup of the root is in, not for every file under bazel/; - the docs list every case in which the lookup does not reach a Bazel root, and say that agent mode is not supported in a Bazel workspace. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview The change adds refusal code Opt-in is global Reviewed by Cursor Bugbot for commit bbff7dd. Configure here. |
…flow `composer::vendored_repository_rule` asserts that the build under the flag fails with Composer's "Source path ... is not found for package ..." message. Composer prints that message in a box as wide as its console and breaks it inside a word where it does not fit: on the CI runners (Composer 2.10.3, no terminal) the path and the package name are each split over two lines, so the one-line search found nothing and the flow failed on all three Bazel releases although the build failed exactly as expected. The flow now compares the message and the build's stderr with white space removed. Tests only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main (#2178) gave track_outcomes_for_vendor the patch uuids of each run and changed its inline eject-refused block; this branch had moved that block into eject_refused(). Keep the helper and pass it the pins' uuids, so both of its callers, the hosted-pin refusals and the Bazel declines, send the new event. Assisted-by: Claude Code:claude-opus-5-5
Vendored mode now declines a Composer package of a project in a Bazel workspace, where it used to exit 0 and could leave the Bazel build broken;
--mode hostedwrites no such path, and the new--allow-vendored-in-bazelflag brings the old behaviour back.Based on main, in three commits. The first is tests only and records what main does today. The second is the change, with the expectations of the first changed to match. The third applies a review of the first two (see "Code review").
What the code does today
No Bazel ruleset builds PHP or takes Composer packages. A PHP project under Bazel brings its packages into the build with a few lines of its own: a repository rule or a genrule that runs
composer installfrom the committedcomposer.lock, or a committedvendor/tree.Vendored mode rewrites the lock entry to a path dist,
.socket/vendor/composer/<uuid>/<vendor>/<name>@<version>. Composer reads that path from the directory it runs in. A repository rule or a build action runs Composer in a directory of Bazel's that holdscomposer.jsonandcomposer.lockand nothing else, so the path names nothing.The first commit records this on real Bazel (
composer::vendored_repository_rule):socket-patch scan --mode vendored --yesexits 0 with statussuccessand reports the package vendored.bazel buildfails:Source path ".socket/vendor/composer/<uuid>/<vendor>/<name>@<version>" is not found for package <vendor>/<name>.vexattests the package all the same.vendor --revertputs every file back, and the build with them.Measured on Bazel 9.3.2, 8.8.2 and 7.7.2: of sixteen vendored runs over the shapes such a project is written in, eight left the build broken and the other eight built the unpatched package.
What changes
What a workspace's rules do with the lock cannot be read from its files. A rule may take the lock through a glob, or live in another module. A committed
vendor/tree does not settle it either: it shows that Composer has run in the project's directory, not that no rule runs it somewhere else as well. A workspace with both a committed tree and a repository rule that installs from the lock fails the same way (Bazel 9.3.2). So the refusal reads none of that. Every Composer project in a Bazel workspace is declined for a package the run would newly vendor, and the user's word is the one thing that lifts it.The condition. The project's directory, or one above it up to the root of its git checkout, holds
MODULE.bazel,REPO.bazel,WORKSPACEorWORKSPACE.bazel(bazel::bazel_root). Then every command that would vendor a Composer package refuses it withvendor_composer_bazel_workspace:scan --mode vendored,get --mode vendored,vendorfor a patch the manifest recordsfailedevent, statuspartialFailure, exit 1scanorgetwith no--modeincludedvendorthat would eject a hosted pinstatus: error,eject_refused, the pin stays; the detail startskept hosted:scanorgetwith--dry-runvendor --dry-runfailed, exit 1, as that command does for any package it could not vendorNothing is written and no patch is downloaded. The refusal looks for the workspace file and reads
composer.lock: it starts no program and asks no service.The message names the Bazel root and the mode that writes no such path,
--mode hosted, which names the patched archive by a URL that Composer fetches from any directory. It does not promise that hosted mode patches every Bazel build. Hosted mode patches the build when Bazel runs Composer on the rewritten lock. Where Bazel does not, the hosted run exits 0 and the build stays the unpatched one, as before this change: a repository rule that links the lock withrctx.symlinkis not run again on Bazel 8 and 9 until its repository is fetched again, and anhttp_archiveof the package never reads the lock. The docs now list this as a limit.The exception is the user's word:
--allow-vendored-in-bazel, orSOCKET_ALLOW_VENDORED_IN_BAZEL=1. It is for a project where Composer only runs in the project's directory, or where the build finds the copy all the same:composer install;vendor/tree, when no rule installs from the lock as well. The build is the patched one after the nextcomposer installin the project, as without Bazel;.socketdirectory to where it runs Composer.socket-patch checks none of these.
The switch is shared. It is not Composer's alone. It lets vendored mode write for a package although the project is in a Bazel workspace, where the build may not find the vendored copy. A refusal of the same kind for another ecosystem is to read the same switch; its binding sits beside the dispatch of the refusals (
vendor::refusals::ALLOW_IN_BAZEL_ENV, read byvendor::refusals::bazel_workspace_refusals, the one answer every vendored command takes, the eject included). The Composer refusal is the only one it lifts today, and a refusal's code keeps its ecosystem.vendor --revertis never refused. Neither is a package that is already vendored: wherecomposer.lockalready names the copy of the same patch, the run leaves the lock as it is, so a project that was vendored before (by an earlier release, or with the flag) keeps passing its runs. What is refused is the write of the path: a new patch for that package, or another package.What a person reads. No line is new. The refusal prints where every refused vendored package does:
scan:[error] <purl> (vendor_composer_bazel_workspace): <detail>, thenNothing was vendored: 1 patch failed (see above).The closing totals count the package's advisories as left in packages the run did not patch.scan --dry-run,get --dry-run:[dry-run] Would download and vendor 0 of 1 patch (1 would be refused). No changes made.and[would-refuse] <purl> (<code>): <detail>.get: the[error]line andNo vendorable patches in scope.vendor:Error: Cannot vendor <purl>: <detail>andVendored 0 packages; 1 failed.For the eject the detail startskept hosted:.Nothing changes outside a Bazel workspace, for another ecosystem, or for hosted and agent mode.
Contents
vendor/composer_lock/bazel.rs(new)vendor/refusals.rscommands/vendor.rsargs.rs, and one row each inutils/process.rs,utils/env_compat.rs,composer_lock.rstests/e2e_bazel_build/composer.rstests/cli_global_args.rs,tests/common/clap_parse.rsdocs/ecosystems.md("Bazel workspaces: Composer"),CLI_CONTRACT.md(four rows)bazel-composer.yml: comments, and its legs now start for a change tobazel/mod.rs,utils/repo_root.rsandvendor/refusals.rs13 files, +832 / -54 in three commits. No fixture changed. The
bazelbudget group ofscripts/loc-budget.pyis unchanged at 2486 of 2486.lock-writersgrows by 77 code lines to 101455; it was over its cap before, and the cap is not raised here.What it proves and where
Everything below ran on one macOS arm64 machine, with PHP 8.4.23 and Composer 2.11.2. Nothing here has run in GitHub Actions yet.
Real Bazel 9.3.2, 8.8.2 and 7.7.2, the five
composer::flows on each, run the way the reusable workflow's step runs them. All pass; the legs took 38, 50 and 35 seconds.composer::vendored_repository_rule:--mode hostedand the flag), no file differs and the patched archive is not requested;rollbackrestores every file;composer::vendored_committed_vendor: the project that commits its tree is declined too, and nothing is written. With the flag the package is vendored; the build stays the unpatched one until the developer'scomposer install, then it is the patched one.The first commit on main's product code: all five flows pass on 9.3.2.
With the product change reverted, both vendored flows fail on 9.3.2 at the exit-code assertion, and the two new tests that need no Bazel fail.
Thirteen mutations, one at a time, each caught by a test:
Outside a Bazel workspace, compared with a binary built from main: 14 runs (vendored scan, check, rescan, revert, dry run,
get, eject and takeover, in JSON and human output, with and without a.gitdirectory). Exit codes, both output streams and the file tree after every command are byte for byte the same; only timestamps were normalised. With aMODULE.bazeladded, all 14 differ and no file is written.A project whose
vendor/tree git tracks, in a Bazel workspace, run by hand outside the test suite: declined, nothing written. The vendored scan, its dry run and the dry run ofgetstart no git process there. In a checkout whosevendor/composerdirectory is laid out as a git repository with a configuration that names a program, none of the three ran that program.Without Bazel, PHP or Composer (these run in every plain
cargo test):vendorand of its eject among them; the eject's detail startskept hosted:, and a refused eject sends the service no request;scanwith no--modeamong them: the lock already names the copy of that patch;vendor --revertneeds neither.The rest of the gate, on the final head:
e2e_bazel_buildwithout Bazel: 51 passed; thecliandspawn_env_hygieneratchets: 130 passed;-D warnings,cargo checkon all targets and features,rustfmt --checkon the changed files, the script tests, actionlint and the tool-pin check onbazel-composer.yml: all pass.Not covered
rctx.symlink. The refusal reads the workspace file and nothing else, so it is the same code path..socketto where it runs Composer. The docs name that use; no test here builds it.vexafter a refusal, the uuid form ofget --mode vendored,--silentoutput, andrepairorrollbackof a vendored Composer package under Bazel..gitbelongs to another user, and the home directory for a project below it. This is the limit of the lookup that the.bazelignorecode on main uses as well, and the docs list the cases.Code review
A review of the first two commits gave nine findings. The third commit settles them:
patch_fetch_failedfirst. It now asks once, before any record is fetched; a test holds that a refused eject sends the service no request.vendor::refusals::bazel_workspace_refusalsis the one dispatch, called byvendor_refusalsand by the eject..bazelignoremessages do. Not run on Windows here.SOCKET_ALLOW_VENDORED_IN_BAZEL=1exported. It holds the variable unset.bazel/, which the Maven work changes often, and not forutils/repo_root.rs, where the walk of the lookup is. They start forbazel/mod.rsandutils/repo_root.rs.is_composerhelper and by building the test tree in place..gitof another user, above a project in no checkout, or into the home directory. There vendored mode goes on as on main. The lookup is the one main already uses to write.bazelignore; widening it changes what that code reads too, so it belongs in a change of its own. The docs now list the four cases.SOCKET_ALLOW_VENDORED_IN_BAZEL, as--offlineand--debugare mirrored into theirs), not as a parameter. A parameter would add a field to the download parameters and an argument to the dry-run preview, about fifteen construction sites, most of them tests. The mirror is sticky only in a process that runs the CLI more than once, which the released binary never does.Also in the third commit: the docs of this section no longer say that agent mode patches a committed
vendor/tree under Bazel. Agent mode is listed as not supported in a Bazel workspace.Run on the third commit, on the same machine:
cargo checkon all targets and features and clippy with-D warnings(workspace, and thee2e_bazel_buildtarget);rustfmt --checkon the changed files; the unit tests of the changed modules;e2e_bazel_buildwithout Bazel (51 passed),cli(109),cli_global_args(13),spawn_env_hygiene(21); the suites that run the eject and vendored Composer (vendor_eject14,vendor_eject_fresh_checkout12,vendor145,in_process_vendor157,mode_migration_composer9, all passed); actionlint and the tool-pin check on the workflow. Two mutations, each caught: the exemption dropped (the unit test and the in-sync test fail), and the eject's question moved behind the fetch (the request count fails). The real-Bazel flows were not run again on the third commit: no flow changed, and the legs run in CI once the pull request leaves draft.Decisions for the owner
vendor/tree is declined too. Vendored mode works there today after the developer'scomposer install; with this change it exits 1 until the project has the flag. An exemption for a tree that git tracks was built and dropped, for two reasons. A workspace that has such a tree and also a rule that installs from the lock passed the exemption: exit 0, then a failed build, which is the defect this change is for. And the question needs a git call in a directory of the project, which in a clone that holds a directory laid out as a git repository runs a program that the clone names, on dry runs too. If you want the exemption back, it comes with that workspace shape as a stated limit, a hardened git call and about 20 more lines of code.--allow-vendored-in-bazelwithSOCKET_ALLOW_VENDORED_IN_BAZEL, shaped like--gem-refresh-shared(a global boolean with an environment binding, off by default), so a repository can set it once in CI. The alternatives:--allow-patch-conflicts, which makes the consent per run;socket.ymlkey, which is not used because that file's policy is documented as only narrowing what a run patches.MODULE.bazelat its root, built by a Dockerfile, is refused like any other until it sets the flag. Nothing in the files tells it apart safely. Should it have to opt in, or is there a signal you would accept?failedevent, as for the other shapes vendored mode cannot serve. A pipeline that ranscan --mode vendoredon such a project now fails at the scan where it used to fail at the build. The alternative is askippedevent with exit 0, at the price of a quiet miss.scanorgetwith no--modeincluded: a package whose lock entry already names the copy of the same patch is not refused, because the run leaves the lock as it is. A pipeline that was green stays green after the upgrade. A new patch for that package is refused until the run has the flag. The alternative is to refuse every vendored run there, which makes such a pipeline exit 1 on a run that would write nothing; say if you want that.Generated by Claude Code