Repository navigation
Commit fab1270
Find the Maven artifacts a pinned rules_jvm_external hub builds in scan (#2191)
* Test a hosted scan of a tree that only Bazel builds on real Bazel
`socket-patch scan` takes its Maven packages from the JVM caches of a
project that has a pom.xml, a Gradle build or a Scala-tool build. A
checkout whose jars only a rules_jvm_external hub fetches has none of
those, so a hosted scan there knows no package and never asks the API,
although `get <purl> --mode hosted` in the same directory pins the same
jar in MODULE.bazel.
Two flows of tests/e2e_bazel_build/maven.rs now hold that on real Bazel,
so that a change which makes scan read the hub's lock has expectations to
turn over:
- a_hosted_scan_of_a_tree_only_bazel_builds (new): after the ruleset's
pin and a build, `scan --mode hosted --yes` exits 0 with
scannedPackages 0, no package and no event, sends no batch request and
changes no file, and the build prints the upstream marker as before.
The stand-in's API holds a patch for the victim the whole time.
- a_version_bump_of_the_patched_artifact: the build stops at the stale
entry and `rollback <purl>` takes it out, as before. The flow then puts
the stale entry back, as the file is for a user who has not run the
rollback. The same scan finds no package there either and leaves the
entry at which Bazel stops, although the API also grants a patch for
the release the lock now pins (1.11.0).
For that the stand-in grants two patches of the victim, one per release:
grant() takes the version and hands the patch back, and the caller mounts
the API once with both, because a second mount does not replace the
answers of the first.
Measured with Bazel 9.3.2 on macOS arm64, two flows at a time: the five
Maven flows pass in 21.5, 24.3, 24.9, 30.9 and 22.1 seconds, and none of
the 166 requests behind a logging proxy went to a public Maven
repository (from a cold repository cache: 64.0, 71.6, 34.2, 60.5 and
29.8 seconds, 208 requests). No product code changes.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* Find the Maven artifacts a pinned rules_jvm_external hub builds in scan
`socket-patch scan` takes its Maven packages from the JVM caches of a
project that has a pom.xml, a Gradle build or a Scala-tool build. In a
tree that only Bazel builds it said "No packages found. Run your package
manager's install first.", although `get <purl> --mode hosted` in the
same directory pins that jar in MODULE.bazel: a user had to name every
purl. The lock of a pinned hub (maven_install.json) names each jar that
Bazel fetches, at the version it builds.
What changes:
- A hosted scan at the root of a Bazel workspace takes the jars that the
pinned hubs fetch for packages of the project, beside the ones it
finds installed (bazel::maven::hub_jars, through scan's lockfile
supplement). A hub's jar is the one without a classifier of an
artifact that the hub's lock has a sha256 for, does not skip, and
lists under a repository (or takes from the Maven local repository);
its version is the lock's. It counts in scannedPackages, and in
lockfileOnlyPackages with notInstalled unless a crawl found that
version installed. A patch found for it is pinned as `get` pins it:
one block in MODULE.bazel. A jar whose repository has no known name
is a package too: a patch found for it gets maven_bazel_artifact.
- The scan takes a stale entry out of the block. When the lock of a hub
moves on (a version bump, an artifact that was removed), Bazel stops
at the entry of the release it held ("does not generate repository").
A scan that only pinned the new release beside it would report
`applied` and leave a build that fails. So the scan restores such an
entry before the rewrite, through the sweep that restores a withdrawn
pin (scan/withdrawn.rs, whose messages for a withdrawn pin are the
ones they were): the entry alone, under the apply lock, previewed by
--dry-run, one rolledBack event with the reason
maven_bazel_entry_stale, also on a scan that finds no package. An
entry is stale only when every hub was read and none fetches its jar
at that version; a pin of the same patch in a pom.xml stays.
- `get <advisory> --mode hosted` keeps the releases that a pinned hub
fetches, by the same supplement.
- No jar is guessed for a hub that was not read with certainty (no
lock_file, a lock or a tag that cannot be read, a maven_install of a
WORKSPACE file). The run gives one warning, maven_bazel_hub_not_read,
with the file, the line and the reason, and still looks up the jars of
the hubs it read. With no package at all a person reads "No packages
found (see the warning)." in the place of the advice to install. The
warning is for a workspace that has to do with the ruleset: a call
names rules_jvm_external, the WORKSPACE file calls maven_install, or a
maven_install.json lies at the root. A Bazel workspace of other
rulesets with a file that cannot be read scans as it did.
- A bare scan covers the project directories below --cwd, and --cwd when
it is a project. The root of a Bazel workspace needs no lockfile or
build file of its own, so a bare hosted scan from a root above other
projects scanned those and never the root, while the same scan with
--json scanned the root. The root is now a project of a hosted scan
when its hubs have jars, something of them was not read, or the block
has a stale entry.
- Every hosted scan at a Bazel root now reads the hubs, so Hubs::read
reads each lock once for all the hubs that name it and at most 64 MiB
of locks for one workspace (the lock past that is a doubt), and the
scan walks each lock once. With a debug build, a checkout of a
hundred hubs on one 12.8 MiB lock of 80,000 artifacts scans in 1.5 s
with 175 MB, as one hub does (1.0 s), and twenty hubs with twenty
such locks in 1.7 s with 426 MB.
- No other run reads a hub for packages: a scan in vendored or agent
mode, one whose --ecosystems leaves Maven out, a --global one, one of
a project below the Bazel root, and every run of a project in no Bazel
workspace are the runs they were.
A hub's jar with a patch is a patch of the run like any other, so the
scan writes for it what `get <purl> --mode hosted` writes in that
checkout: beside a Gradle build the hosted Gradle pin too
(settings.gradle and three files under .socket/gradle), and beside a
pom.xml what the pom lane pins or says of that pom.
Not in this change: `get <purl>` leaves a stale entry where it is (a
hosted scan, rollback and remove take it out), hubs that other Bazel
modules declare or fill are not read, and the in-memory engine reads no
hub.
Tests:
- bazel::maven: one table of nineteen workspaces for what counts as a
jar of a hub (a lock over 1 MiB among them), what is said of a hub
that was not read and where nothing is said, and which entry is stale;
nothing for a project below the root or without a workspace. One test
for the locks: read once, and within the bound.
- tests/e2e_bazel_maven_beside.rs, nine tests without a Bazel: the scan
as a program and as a person, as a dry run and a second time; a root
with a lockfile of its own, alone and above another project; a stale
entry, with and without a patch of the new release, with no package
at all, while a hub is in doubt, and beside a pom that keeps its pin;
a Gradle build and a pom beside the hub, each compared with what `get
<purl>` writes and says there; a pom that selects another release;
each way a hub is not read; the scans that read no hub, each compared
byte for byte with the same scan without the Bazel files; a root
above another project; `get` by advisory.
- tests/e2e_bazel_build/maven.rs: the two flows of the commit before
this one, turned over. After the ruleset's pin, `scan --mode hosted
--yes` reports the two jars of the lock and appends the block that
`get` writes; the build prints the patched marker, a second scan
writes nothing and `rollback` restores every file. After a version
bump, with the stale entry in the file, the scan takes it out, pins
the patch of the new release, and the build takes that jar.
Measured on macOS arm64: the five Maven flows pass on Bazel 9.3.2,
8.8.2, 7.7.2 and 7.4.0 at this tree, a flow in 17 to 56 seconds, and
none of the 498 requests behind a logging proxy went to a public Maven
repository. With the four source files as they were, both flows fail on
9.3.2 at the count of scanned packages (0, not 2), and eight of the nine
tests without a Bazel fail; the ninth holds what does not change. With
the stale entries kept from the sweep alone, the version bump flow fails
on 9.3.2: the scan reports `applied` and no rolledBack. Twenty single
changes to the new code each fail a test; a twenty-first, the root of a
bare scan taken as a discovered directory, changes nothing that a run
can show, because a directory that the built-in ignores would drop has
no project below it that they keep. In sixteen checkouts without a hub
of the ruleset (ten without a Bazel workspace file, six in a workspace
of other rulesets), fourteen scan and get commands print the same bytes,
exit with the same code and write the same files as a binary of the
commit before (224 runs). Over the root MODULE.bazel of 22 open-source
Bazel workspaces, the 18 without a hub of the ruleset give no jar and no
warning.
The line budget of the Bazel group follows the code, 2486 to 2568.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* Hold a stale Bazel entry to the policy, and keep the scan's lock bound to the scan
Six fixes from a review of the hub scan, each with a test that fails
without it.
- The socket.yml policy now holds a stale entry of the block as it holds
a package of the run. A scan of a root that `patches.ignorePaths`
filters took the entry out of that root's MODULE.bazel, and so did a
scan whose policy ignores the package: the sweep got the stale pins
whatever the policy said. They are filtered first
(`ScanPolicy::admits_restore`).
- A scan with no package at all ran the sweep and never looked at a
restore that left a file half written; it went on to "No packages
found" and exit 0, where the same failure on the path with packages
stops the run with `lockfile_write_failed` and exit 1. Both paths now
share that stop (`stop_half_restored`).
- A pin that is stale and whose patch is withdrawn too was handed to the
restore twice and reported as two `rolledBack` events. It is taken
once, as the withdrawn pin, with every file that holds it.
- The bound of 64 MiB of hub locks for one workspace was added for the
scan, which now reads the hubs on every hosted run at a Bazel root, but
it sat in `Hubs::read` and so also changed `get`, `list`, `vex`,
`rollback` and the notices: in a workspace with more locks than that,
a `get <purl>` that pinned before declined with
`maven_bazel_unreadable`. The bound is the scan's alone now; every
other reader takes each lock up to 16 MiB as before.
- Past the bound each further lock was still read from disk and then
dropped. Now the first lock that does not fit is the last one read.
- `get <advisory> --mode hosted` named a Maven hub that was not read for
an advisory with no Maven artifact at all. The warning is given only
when the advisory has a patch of a Maven artifact.
Also held by a test and said in the docs, with no change in behaviour:
when a stale entry goes beside a Gradle build, the hosted Gradle pin that
the first scan wrote for the same patch stays, as a pin in a pom.xml
does. `list` shows it, `rollback <purl>` takes it out, and while it stays
the Gradle lane declines a patch of another release of the artifact.
The line budget of the Bazel group follows the code, 2568 to 2583.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>1 parent 8ffea64 commit fab1270
12 files changed
Lines changed: 1621 additions & 146 deletions
File tree
- .github/workflows
- crates
- socket-patch-cli
- src/commands
- scan
- tests
- e2e_bazel_build
- socket-patch-core/src/bazel
- docs
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1062 | 1062 | | |
1063 | 1063 | | |
1064 | 1064 | | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
1065 | 1070 | | |
1066 | 1071 | | |
1067 | 1072 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
16 | | - | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
51 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
52 | 62 | | |
53 | 63 | | |
54 | 64 | | |
| |||
68 | 78 | | |
69 | 79 | | |
70 | 80 | | |
71 | | - | |
| 81 | + | |
| 82 | + | |
72 | 83 | | |
73 | 84 | | |
74 | 85 | | |
| |||
84 | 95 | | |
85 | 96 | | |
86 | 97 | | |
87 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
88 | 113 | | |
89 | 114 | | |
90 | 115 | | |
91 | 116 | | |
92 | 117 | | |
93 | 118 | | |
94 | 119 | | |
95 | | - | |
| 120 | + | |
| 121 | + | |
96 | 122 | | |
97 | 123 | | |
98 | 124 | | |
99 | 125 | | |
100 | 126 | | |
101 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
102 | 141 | | |
103 | 142 | | |
104 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1630 | 1630 | | |
1631 | 1631 | | |
1632 | 1632 | | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
1633 | 1665 | | |
1634 | 1666 | | |
1635 | 1667 | | |
| |||
2292 | 2324 | | |
2293 | 2325 | | |
2294 | 2326 | | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
2295 | 2339 | | |
2296 | 2340 | | |
2297 | 2341 | | |
2298 | 2342 | | |
2299 | | - | |
| 2343 | + | |
2300 | 2344 | | |
2301 | 2345 | | |
2302 | 2346 | | |
| |||
2937 | 2981 | | |
2938 | 2982 | | |
2939 | 2983 | | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
2940 | 2992 | | |
2941 | 2993 | | |
2942 | 2994 | | |
| |||
2968 | 3020 | | |
2969 | 3021 | | |
2970 | 3022 | | |
| 3023 | + | |
| 3024 | + | |
| 3025 | + | |
| 3026 | + | |
| 3027 | + | |
| 3028 | + | |
| 3029 | + | |
| 3030 | + | |
| 3031 | + | |
| 3032 | + | |
| 3033 | + | |
| 3034 | + | |
| 3035 | + | |
| 3036 | + | |
| 3037 | + | |
2971 | 3038 | | |
2972 | 3039 | | |
2973 | 3040 | | |
| |||
3034 | 3101 | | |
3035 | 3102 | | |
3036 | 3103 | | |
| 3104 | + | |
| 3105 | + | |
| 3106 | + | |
3037 | 3107 | | |
3038 | 3108 | | |
3039 | 3109 | | |
| |||
3413 | 3483 | | |
3414 | 3484 | | |
3415 | 3485 | | |
3416 | | - | |
| 3486 | + | |
3417 | 3487 | | |
3418 | | - | |
| 3488 | + | |
3419 | 3489 | | |
3420 | 3490 | | |
3421 | 3491 | | |
3422 | | - | |
3423 | | - | |
3424 | | - | |
3425 | | - | |
3426 | | - | |
3427 | | - | |
3428 | | - | |
3429 | | - | |
3430 | | - | |
3431 | | - | |
3432 | | - | |
3433 | | - | |
3434 | | - | |
3435 | | - | |
3436 | | - | |
3437 | | - | |
3438 | | - | |
3439 | | - | |
3440 | | - | |
3441 | | - | |
3442 | | - | |
3443 | | - | |
3444 | | - | |
3445 | | - | |
3446 | | - | |
3447 | | - | |
3448 | | - | |
3449 | | - | |
3450 | | - | |
3451 | | - | |
3452 | | - | |
| 3492 | + | |
| 3493 | + | |
| 3494 | + | |
| 3495 | + | |
| 3496 | + | |
| 3497 | + | |
| 3498 | + | |
| 3499 | + | |
| 3500 | + | |
| 3501 | + | |
| 3502 | + | |
| 3503 | + | |
| 3504 | + | |
| 3505 | + | |
3453 | 3506 | | |
3454 | 3507 | | |
3455 | 3508 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
475 | 483 | | |
476 | 484 | | |
477 | 485 | | |
| |||
0 commit comments