Repository navigation
Commit 83d2b95
Test NuGet hosted mode under rules_csharp on real Bazel (#2140)
socket-patch has no Bazel-specific code for NuGet, and no test ran its
NuGet rewrite in a Bazel workspace. This adds the NuGet module of the
real-Bazel tests, its fixture and its workflow, and makes one edit to
the shared harness: NETRC is removed from every Bazel child (below).
No file under crates/*/src changes.
The flow holds hosted mode for a package that rules_csharp 0.5.0 reads
through `nuget.from_lock(packages_lock_json, nuget_config)` under
Bzlmod, on Bazel 9.3.2, 8.8.2 and 7.7.2. One test,
`nuget::hosted_from_lock`, in a fresh output base:
- builds the workspace and reads the unpatched marker from
`bazel run //:consumer`; the upstream package came from the stand-in;
- runs `scan --mode hosted --yes`, which rewrites nuget.config (the
Socket source of the patch, ahead of nuget.org) and
packages.lock.json (the contentHash of the patched package), and
nothing else;
- runs the same two Bazel commands and reads the patched marker, which
holds an id made for the run: the package came from the stand-in
patch host, and Bazel rewrote MODULE.bazel.lock and no other file;
- runs `rollback --yes`: the two files are the ones of before at once,
and after the next build so is every file of the checkout, and the
build prints the unpatched marker again;
- on a second machine, where the patch host serves other bytes than
the grant pins, the build fails in both states of the checkout: over
the contentHash of packages.lock.json while Bazel's lock is stale,
and over the sha256 in MODULE.bazel.lock once that lock pins the
granted package. There Bazel also refuses the copy on nuget.org,
which the hub tries next.
Three outcomes the flow asserts are gaps of the product, not its
contract. They are asserted as the release has them, so that the
measurement does not drift; the module docs name them under one
heading, and each is marked KNOWN GAP where it is asserted, with what
a fix would change in the test:
- Under Bazel alone socket-patch does not find NuGet packages from
packages.lock.json. `scan` finds a NuGet package only where a restore
unpacked it: a folder that `obj/project.assets.json` records, the
`packages/` folder of a packages.config project, or NuGet's global
packages folder. In a checkout without a restore record, on a
machine whose global packages folder does not hold the package (a
runner that only ever ran Bazel), `scan --mode hosted --yes` exits
0, finds no package and writes no file: hosted mode does nothing.
The flow asserts that case. Its patched path exists only because the
test then stages the global folder by hand, as a restore leaves it;
no dotnet runs.
- `vex` on the machine that ran the scan exits 1 and writes no
document (`not_applied`) while Bazel builds the patched package: it
reads the unpatched copy in NuGet's folder. Where the folder holds
nothing, `vex` attests the package from the pin in the two files.
- rules_csharp asks the Socket source for every package of the lock.
For the package the source does not hold, the stand-in answers 404,
and Bazel prints a warning with the URL it asked, which holds the
access token of the grant. The package then comes from nuget.org as
before.
What the flow asserts beside that, because a user meets it:
- The scan warns `redirect_nuget_stale_global_package`: the folder
still holds the unpatched copy. That copy is what `dotnet restore`
would go on using; no Bazel build reads it.
- The scan leaves MODULE.bazel.lock stale, and so does the rollback: a
`--lockfile_mode=error` build fails ("MODULE.bazel.lock is no longer
up-to-date") until a build that may update the lock has run.
- A second `scan` reports the patch applied again and rewrites no file.
The names of the two fixture packages end in an id made for the run.
nuget.org has no scopes, so an id that is committed here could be
pushed there by anyone; an id that is new for every run cannot. The
committed project, BUILD file and lock hold `@RUN@` where a checkout
holds that id, and NuGet takes no `@` in a package id, so those files
name no package that could exist either: a hermetic test reads every
id the three files name and holds it to that. The downloader config of
the test sends every URL of api.nuget.org and of patch.socket.dev to
the loopback stand-in and blocks both hosts, so no build asks either.
The lock of a checkout pins bytes that the run made, so no cache holds
a package under test.
The consumer is a genrule over the assembly that the hub's label
(`@nuget//:<package>`, what a C# rule names in deps) hands out. The
fixture's assembly is a line of text, no C# rule is built, and no .NET
SDK is downloaded. With an empty repository cache a run fetched 0.7 MB
on Bazel 9.3.2, 0.4 MB on 7.7.2 and 13.0 MB on 8.8.2, from
bcr.bazel.build, github.com and release-assets.githubusercontent.com
(macOS arm64). The rules_csharp archive is 142 kB of that; Bazel 8.8.2
fetches protobuf 29.0, rules_python, rules_java and rules_cc for its
own modules, as it does in a workspace without rules_csharp.
The fixture has one era, for Bazel 7.1.0 and later: the hub of
rules_csharp 0.5.0 downloads with `block = False`, which Bazel has
from 7.1.0. Only the three releases above ran.
The harness edit. Bazel's `http_archive` and its downloader read the
credentials file that NETRC names, and rules_csharp reads it for every
package it downloads; the harness passed the variable of the caller's
shell on to every Bazel child. With NETRC naming a file that does not
exist, the NuGet flow failed at its first fetch, in Bazel's own
`http_archive` (FileNotFoundException). With a file that holds a login
for 127.0.0.1, the stand-in received that login with each package
download; a login for api.nuget.org in the same file did not reach it.
NETRC now joins the variables removed from every Bazel child, for
every ecosystem's flow, and the hermetic test that guards that list
holds the name.
- crates/socket-patch-cli/tests/e2e_bazel_build/nuget.rs: the packages,
the stand-in (the Socket API, nuget.org's flat container, the Socket
source of a patch), the staged packages folder and the flow; two
hermetic tests hold the fixture, the downloader config and the path
lists of the workflow.
- crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs: NETRC, in
the list of what every Bazel child loses and in the list of the test
that guards it.
- crates/socket-patch-cli/tests/fixtures/bazel/rules_csharp/bzlmod: the
workspace, with a placeholder where a checkout holds the id of its
run and the contentHash of its packages.
- .github/workflows/bazel-nuget.yml: three Linux legs on a pull request
that touches these files or a NuGet file the flow runs through, on a
main push that also touches the shared engine code, nightly and on
dispatch; one macOS leg nightly and on dispatch. Not required for
merge.
Not covered: what the real patch host answers for a package it does
not hold (the stand-in answers 404), signed packages, a real
`dotnet restore`, a C# compile, vendored and agent mode, rules_dotnet,
and a hub without a nuget.config.
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>1 parent 3f92b8b commit 83d2b95
9 files changed
Lines changed: 1156 additions & 0 deletions
File tree
- .github/workflows
- crates/socket-patch-cli/tests
- e2e_bazel_build
- fixtures/bazel/rules_csharp/bzlmod
- common
- e9
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
48 | 53 | | |
49 | 54 | | |
50 | 55 | | |
| |||
1051 | 1056 | | |
1052 | 1057 | | |
1053 | 1058 | | |
| 1059 | + | |
1054 | 1060 | | |
1055 | 1061 | | |
1056 | 1062 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
0 commit comments