Skip to content

Commit 1e90def

Browse files
committed
Merge main into bazel-small/04-rubygems-rules-ruby
Resolve the add/add conflict in tests/e2e_bazel_build/main.rs by keeping both the npm module from #2109 and this PR's ruby module. Assisted-by: Claude Code:claude-opus-5-5
2 parents fa284e1 + b827e25 commit 1e90def

22 files changed

Lines changed: 2859 additions & 214 deletions

File tree

‎.github/workflows/bazel-npm.yml‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Bazel patch compatibility (npm)
2+
3+
# The npm flows of the real-Bazel tests (`npm::` in `e2e_bazel_build`):
4+
# hosted and vendored mode for a package that aspect_rules_js links from a
5+
# pnpm lock, on each Bazel release below. bazel-compatibility.yml holds the
6+
# legs and what every ecosystem shares; this file says when the npm legs run
7+
# and on which releases.
8+
#
9+
# Beyond what every leg needs, an npm leg downloads Node from nodejs.org and
10+
# ruleset archives from codeload.github.com; its repository cache holds them
11+
# and comes to about 100 MB. An npm tarball under test passes through that
12+
# cache as well: Bazel's downloader fetches it and keeps it under its
13+
# sha512. So a test builds the upstream tarball and each patched one anew,
14+
# with an id of the run in the entry file, and writes the upstream sum into
15+
# the lock of its workspace copy. No cache holds a tarball of the run, and
16+
# the test counts the requests for the upstream one.
17+
#
18+
# Not required for merge: no `merge_group` trigger, and no job here is a
19+
# `needs` of ci.yml's `ci-ok`.
20+
21+
on:
22+
pull_request:
23+
types: [opened, synchronize, reopened, ready_for_review]
24+
# What a pull request run covers: the npm flows and their fixture, the
25+
# harness and the workflows that run it, the Bazel installer and its
26+
# pins, and the npm-family files of socket-patch-core that the two
27+
# flows run through (a coverage build of the binary showed which): the
28+
# pnpm lock's model and hosted planner (formats/pnpm/), the pnpm
29+
# vendored backend with the npm code beside it (vendor/pnpm_*,
30+
# vendor/npm_*, the lock inventory), the `pnpm-workspace.yaml` lookup,
31+
# the npm-family lock and config readers (vex/discover/npm.rs,
32+
# patch/redirect/npmrc.rs), the upstream restore of `rollback`, the
33+
# crawler every `scan` starts, and the `package.json` reader. The
34+
# globs name that one crate, so no bench fixture is here, and nothing
35+
# another ecosystem's flow owns: a change to one ecosystem starts that
36+
# ecosystem's legs only.
37+
#
38+
# What it does not cover: shared engine code (patch/redirect/mod.rs,
39+
# the rest of vendor/, hosted/, commands/), the shared test helpers and
40+
# the toolchain files. A change there gets its run on the push to main
41+
# (when the file is in the list below) or in the nightly run, not on the
42+
# pull request: that is the price of not running every ecosystem's legs
43+
# on every shared change. On demand, workflow_dispatch runs the legs on
44+
# any branch.
45+
paths:
46+
- '.github/workflows/bazel-npm.yml'
47+
- '.github/workflows/bazel-compatibility.yml'
48+
- 'scripts/install-bazel.sh'
49+
- 'scripts/bazel-pins.txt'
50+
- 'crates/socket-patch-cli/tests/e2e_bazel_build/npm.rs'
51+
- 'crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs'
52+
- 'crates/socket-patch-cli/tests/fixtures/bazel/rules_js/**'
53+
- 'crates/socket-patch-core/src/**/*pnpm*'
54+
- 'crates/socket-patch-core/src/**/*pnpm*/**'
55+
- 'crates/socket-patch-core/src/vendor/npm_*'
56+
- 'crates/socket-patch-core/src/vendor/lock_inventory/npm_family.rs'
57+
- 'crates/socket-patch-core/src/patch/redirect/npmrc.rs'
58+
- 'crates/socket-patch-core/src/patch/redirect/upstream/npm.rs'
59+
- 'crates/socket-patch-core/src/vex/discover/npm.rs'
60+
- 'crates/socket-patch-core/src/crawlers/npm_crawler.rs'
61+
- 'crates/socket-patch-core/src/formats/package_json.rs'
62+
push:
63+
branches: [main]
64+
# The pull request paths, and what only a push to main covers: the
65+
# root of the test target (it changes when an ecosystem's module is
66+
# added; ci.yml builds the target and runs its hermetic tests on every
67+
# pull request), the shared engine code and test helpers the flows run
68+
# through, and the toolchain files. A main push outside this list waits
69+
# for the nightly run below.
70+
paths:
71+
- '.github/workflows/bazel-npm.yml'
72+
- '.github/workflows/bazel-compatibility.yml'
73+
- 'scripts/install-bazel.sh'
74+
- 'scripts/bazel-pins.txt'
75+
- 'crates/socket-patch-cli/tests/e2e_bazel_build/npm.rs'
76+
- 'crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs'
77+
- 'crates/socket-patch-cli/tests/fixtures/bazel/rules_js/**'
78+
- 'crates/socket-patch-core/src/**/*pnpm*'
79+
- 'crates/socket-patch-core/src/**/*pnpm*/**'
80+
- 'crates/socket-patch-core/src/vendor/npm_*'
81+
- 'crates/socket-patch-core/src/vendor/lock_inventory/npm_family.rs'
82+
- 'crates/socket-patch-core/src/patch/redirect/npmrc.rs'
83+
- 'crates/socket-patch-core/src/patch/redirect/upstream/npm.rs'
84+
- 'crates/socket-patch-core/src/vex/discover/npm.rs'
85+
- 'crates/socket-patch-core/src/crawlers/npm_crawler.rs'
86+
- 'crates/socket-patch-core/src/formats/package_json.rs'
87+
- 'crates/socket-patch-cli/tests/e2e_bazel_build/main.rs'
88+
- 'crates/socket-patch-core/src/patch/redirect/**'
89+
- 'crates/socket-patch-core/src/vendor/**'
90+
- 'crates/socket-patch-core/src/hosted/**'
91+
- 'crates/socket-patch-cli/src/commands/**'
92+
- 'crates/socket-patch-cli/tests/common/**'
93+
- 'crates/socket-patch-cli/tests/hosted_memory_common/**'
94+
- 'Cargo.lock'
95+
- 'Cargo.toml'
96+
- 'crates/*/Cargo.toml'
97+
- 'rust-toolchain.toml'
98+
- '.cargo/**'
99+
schedule:
100+
# Nightly, so a main change outside the push list still gets a run
101+
# within a day. The macOS leg runs here and on demand only.
102+
- cron: '27 4 * * *'
103+
workflow_dispatch:
104+
105+
permissions:
106+
contents: read
107+
108+
# The nightly run has a group of its own. A group holds one pending run, so
109+
# in the group of main's pushes a second push would replace a nightly that
110+
# waits behind the first, and the nightly is the only run with the macOS leg.
111+
concurrency:
112+
group: bazel-npm-${{ github.event.pull_request.number || github.ref }}${{ github.event_name == 'schedule' && '-nightly' || '' }}
113+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
114+
115+
jobs:
116+
npm:
117+
uses: ./.github/workflows/bazel-compatibility.yml
118+
with:
119+
eco: npm
120+
fixtures: rules_js/bzlmod
121+
# One leg per line: a Bazel release, and the era of the fixture that
122+
# `npm::FIXTURE` gives it.
123+
releases: >-
124+
[
125+
{"bazel": "9.3.2", "era": "e9"},
126+
{"bazel": "8.8.2", "era": "e9"},
127+
{"bazel": "7.7.2", "era": "e9"}
128+
]
129+
macos: >-
130+
[
131+
{"bazel": "9.3.2", "era": "e9"}
132+
]

‎crates/socket-patch-cli/CLI_CONTRACT.md‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ The rewriter reads a fixed set of candidate files from the project root: the npm
431431

432432
- An installed dir is judged by the archive RubyGems installed it from, `<home>/cache/<leaf>.gem`: an archive whose sha256 is a patched artifact's (the grant's `gemChecksumSha256`, else its tarball sha256) is already patched and never warns, any other readable archive is stale, and a missing or unreadable one is never evidence by itself.
433433
- When there is no readable archive (a pruned `cache/`, `gem cleanup`) or no patched sha to compare it with, and no agent-mode record (below), the scan fetches that patch's record (`…/patches/view/<uuid>`, for that purl only) and judges the dir by its `afterHash` map; if that fetch fails too, the dir is unjudged: no warning, but the same run's `--vex` withholds the purl (`stale_install_unverified`) instead of assuming it patched. Otherwise hosted mode fetches no patch record.
434-
- An agent-mode manifest record of the same patch judges the dir by its `afterHash` file map instead (an in-place patch keeps the upstream archive), so an agent→hosted migration stays quiet.
434+
- An agent-mode manifest record of the same patch judges the dir's files by its `afterHash` file map instead. An in-place patch keeps the upstream archive in `<home>/cache/`, and that archive is what `bundle pristine` and `bundle install --redownload` reinstall from (#2089): with a `CHECKSUMS` section in the lock Bundler removes the gem and fails on the pinned checksum (exit 37, and every later `bundle install` fails too), without one it reinstalls the unpatched gem. So files the record proves patched beside a readable archive that is not a patched artifact's are stale as well, by that archive alone: the refresh replaces the archive with the verified patched one under the same rules as an installed copy (project-local by default, a shared gem home only with `--gem-refresh-shared`) and never touches the gem dir, where agent mode keeps a native gem's original build; left alone, the warning says that the files are patched in place and names the archive as the one file to remove. With the patched archive beside them, with no readable archive, or with no patched sha256 to compare it with, the record's verdict stands and an agent→hosted migration stays quiet.
435435
- When several confirmed variant purls resolve to one installed dir, ANY of them judging it patched keeps it quiet.
436436
- Staleness needs **positive evidence** — bytes actually read that are not the patched state — so missing or unreadable files never mark a copy stale.
437437
- A committed cache-dir archive whose sha256 is readable and differs from the patched artifact's is stale by itself, even with no installed dir at all (a fresh checkout with a committed stale cache).
@@ -452,8 +452,8 @@ The rewriter reads a fixed set of candidate files from the project root: the npm
452452
*What is reported.*
453453

454454
- Each refreshed materialization is a `redirect_gem_install_refreshed` note in the JSON `warnings[]`; a human run prints one progress line per kind instead (`Replaced the installed copy of 2 gems with the patched build: …`). A replaced cache-dir archive is listed with the files to commit.
455-
- Each materialization that is still stale is a `redirect_gem_stale_install` warning in the JSON `warnings[]`, in three flavors: an installed copy in a SHARED gem home (left alone; the remedy is the project-local bundle path, `bundle config set --local path vendor/bundle && bundle install`, which installs every gem of the project from the lock's sources and leaves the shared home untouched, or `--gem-refresh-shared`; never a delete list); a PROJECT-LOCAL installed copy the refresh did not fix (the reason — the archive could not be downloaded or verified, a native build failed, the path is outside the project, the refresh is turned off — and the files to remove by hand, including the project's stale cache-dir archive when there is one); and a cache-dir archive alone. The warning re-fires on every re-scan until the stale materialization is gone.
456-
- A human run prints ONE warning for all of them: how many gems, which gems in which gem home (or why they were not refreshed), why in one sentence, and the remedy as a command.
455+
- Each materialization that is still stale is a `redirect_gem_stale_install` warning in the JSON `warnings[]`, in three flavors: an installed copy in a SHARED gem home (left alone; the remedy is the project-local bundle path, `bundle config set --local path vendor/bundle && bundle install`, which installs every gem of the project from the lock's sources and leaves the shared home untouched, or `--gem-refresh-shared`; never a delete list); a PROJECT-LOCAL installed copy the refresh did not fix (the reason — the archive could not be downloaded or verified, a native build failed, the path is outside the project, the refresh is turned off — and the files to remove by hand, including the project's stale cache-dir archive when there is one); and a cache-dir archive alone. An installed copy that agent mode patched in place (stale by its upstream archive only, see above) gets the first two flavors in its own words: the detail names the archive and what a reinstall from it does, the delete list is that archive alone (never the `specifications` entry), and it never calls the install unpatched. Its refresh note reads `replaced the upstream archive of the install patched in place at …`, and the human progress line `Replaced the upstream archive beside 1 gem patched in place with the patched gem: …`; that archive is not a file to commit. The warning re-fires on every re-scan until the stale materialization is gone.
456+
- A human run prints ONE warning for all of them: how many gems, which gems in which gem home (or why they were not refreshed), why in one sentence, and the remedy as a command. Its headline is `N gems are still unpatched on disk after the switch to hosted patches` when none of the gems it covers was patched in place; when every one was, `N gems patched in place still have their upstream archives on disk after the switch to hosted patches`; and with both kinds, `N gems still have unpatched files or archives on disk after the switch to hosted patches`.
457457
- A stale-flagged purl is additionally **excluded from the same run's `--vex` `assume_applied` set** — the envelope must never attest a CVE its own warning says is live; the purl falls back to normal installed-tree verification (a patched install still attests, a stale one is omitted). A same-run `--vex` may still fail on "nothing to attest" per the embedded-VEX contract.
458458

459459
*The unwind direction.* After a hosted unwind — `rollback` / `remove` of a hosted pin, scan's withdrawn-patch restore, `vendor --revert` of a package vendored over hosted wiring before v5 — put a gem back on its upstream registry entry, its installed copies and archives hold the PATCHED gem, with the same consequences in reverse: the patched code keeps running, and on bundler ≥ 2.6 `bundle pristine` fails on the restored upstream checksum. The unwind applies the same refresh with the upstream gem: the sha256 is the restored lock's `CHECKSUMS` entry, else the rubygems.org compact index; the archive is taken from disk, else downloaded from rubygems.org when the lock resolves the gem from it (a gem from another remote is refreshed only from an archive already on disk). An installed copy is stale when its `<home>/cache/<leaf>.gem` is readable and is not the upstream archive (ruby-platform gems only: the lock's checksum names that archive). Notes are `upstream_gem_install_refreshed` / `upstream_gem_install_would_refresh`; an installed copy left on the patched build is `upstream_gem_stale_install` (one consolidated warning in a human run), and an archive left in bundler's cache dir keeps its `upstream_gem_stale_cache` warning. A gem whose installed copies were refreshed is not counted in rollback's "keep their patched bytes" note.
@@ -1022,11 +1022,13 @@ Ruby inside the project is never run, and every run goes without the Socket cred
10221022

10231023
The first rebuild of a copy backs up the original compiled code to `.socket-patch-native-orig/` in
10241024
the gem directory (the install-time extension directory and `lib/` copies; a precompiled gem's
1025-
prebuilt binaries, each when it is first replaced), and every rebuild records
1025+
prebuilt binaries, each when it is first replaced; every file of the gem's own tree an in-place
1026+
rebuild replaced, with the names of those it added), and every rebuild records
10261027
`.socket-patch-native-build.json` there: the source hashes it was built from and the hash of every
10271028
artifact it put in place (`"grafted": true` for a precompiled gem's replaced binaries, whose paths
1028-
name the Ruby minors they were built for). A record whose sources are patched and whose marker
1029-
matches is `already_patched`; sources an earlier release patched without a rebuild are rebuilt,
1029+
name the Ruby minors they were built for; for an in-place rebuild, `libArtifacts` also lists what
1030+
the build left in the gem's own tree for Ruby to load). A record whose sources are patched and
1031+
whose marker matches is `already_patched`; sources an earlier release patched without a rebuild are rebuilt,
10301032
with a `native_extension_rebuilt` warning. `rollback` (and `remove`) puts the backed-up build back
10311033
with the sources, bytes and file mode; without a backup it rebuilds a gem RubyGems built from the
10321034
restored sources, and fails a precompiled gem with `native_extension_restore_failed` (`gem
@@ -1067,7 +1069,7 @@ a file the copy does not hold is not written: the record fails on it as on any m
10671069
| Code | Run result | Meaning |
10681070
|---|---|---|
10691071
| `native_extensions_unsupported` | refused, exit 1 | The record changes build inputs that cannot be rebuilt here: the copy is not a RubyGems install with a `specifications/` entry (a Bundler git checkout); the gem neither declares extensions nor is a platform gem; it is the JRuby (`java`) build; no Ruby that owns the install was found; a precompiled gem cannot be built from its source gem (the archive is neither in the home's `cache/` nor downloadable, is not the copy's own source, the record does not apply to it, a gem its build needs could not be staged, its build leaves a library in the gem's own tree, or the build has no counterpart among the gem's prebuilt binaries); a record changes an input a build removed and the source gem cannot be built. Nothing is written. Also: another run is rebuilding the same gem right now, or an interrupted rebuild could not be undone (the error says which). |
1070-
| `native_extension_build_failed` | refused, exit 1 | The extension did not build from the patched sources (no compiler or Ruby headers, a build error), or the finished build could not be moved into place. The installed copy is as it was before the run; the error carries the build output's tail (of the build from the source gem and of the in-place one, when both ran). |
1072+
| `native_extension_build_failed` | refused, exit 1 | The extension did not build from the patched sources (no compiler or Ruby headers, a build error, an in-place build that exited cleanly without compiling anything), or the finished build could not be moved into place. The installed copy is as it was before the run; the error carries the build output's tail (of the build from the source gem and of the in-place one, when both ran). |
10711073
| `native_extension_rebuilt` | warning | The sources were already patched (by a release before #1996, with `--no-gem-native-rebuild`, or by `apply` under another Ruby version of a precompiled gem) and the extension was rebuilt from them. Under `--dry-run`: the rebuild a real `apply` would run; no Ruby is started and nothing is downloaded to check that it can. |
10721074
| `native_extension_not_rebuilt` | warning | `--no-gem-native-rebuild`: the sources were written without a rebuild; Ruby loads the old build until the caller compiles it. |
10731075
| `native_extension_restore_failed` | rollback: that copy fails | The sources were restored, but the original compiled extension could not be put back. Run `gem pristine <gem> --extensions` (a precompiled gem: `gem pristine <gem>`). |

0 commit comments

Comments
 (0)