Repository navigation
Commit 85bbd4a
Withhold a hosted NuGet pin that a rules_csharp hub would not take (#2189)
* Test hosted NuGet mode on a rules_csharp tag without nuget_config, on real Bazel
rules_csharp's `nuget.from_lock` downloads each package of
`packages.lock.json` and holds it to the lock's `contentHash`. It asks
the package sources of the `nuget.config` that the tag names with
`nuget_config`; a tag without that attribute, as in the examples of the
ruleset's own repository, asks nuget.org alone.
`scan --mode hosted` re-pins the `contentHash` of a patched package in
the lock and names the Socket source of the patch in `nuget.config`. The
one flow on real Bazel so far (`nuget::hosted_from_lock`) has the tag
name that file, and there the next build is patched.
This adds `nuget::hosted_no_config`: the same fixture with the
`nuget_config` line taken out of the tag and no `nuget.config` in the
checkout. It records what the code does today, on Bazel 9.3.2:
- `scan --mode hosted --yes` exits 0 and reports the patch applied. It
creates `nuget.config`, which nothing of the build reads, and re-pins
the lock, which the hub reads.
- The next `bazel build` fails. The hub fetches the upstream package
from nuget.org, never asks the Socket source, and refuses the package:
`the downloaded package does not match its contentHash in
packages.lock.json`.
The test asserts that failure by its message, so that the commit that
fixes it has to change the expectation. The fixture's files are
unchanged: the flow edits its own checkout, and the hermetic test of the
fixture holds that each era's MODULE.bazel has the one line the flow
takes out. Like the other NuGet flow it asks no public registry: Bazel's
downloader config sends nuget.org to the loopback stand-in.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* Withhold a hosted NuGet pin that a rules_csharp hub would not take
rules_csharp's `nuget.from_lock` downloads each package of
`packages.lock.json` and fails the build on a file that does not match
the lock's `contentHash`. All the `nuget.from_lock` tags of a workspace
make one hub (`_nuget_impl` in csharp/extensions.bzl at 0.5.0):
- It has one list of package sources, which it asks before nuget.org.
Each tag in turn puts its `feeds` in the place of that list, and then
the sources of the `nuget.config` it names with `nuget_config`. So
the last tag that has either decides.
- It holds a package to the `contentHash` of the first lock that names
it.
Hosted mode re-pins the `contentHash` of a patched package in the
project's locks and names the Socket source of the patch in the
project's `nuget.config`. In each of these workspaces `scan --mode
hosted` exited 0 with the patch applied, and the next `bazel build`
failed with "the downloaded package does not match its contentHash in
packages.lock.json" (Bazel 9.3.2):
- A tag that names no `nuget_config`, as in the examples of the
ruleset's own repository, with or without `feeds` or
`local_package_dirs`: the hub reads the re-pinned lock and not the
config, and downloads the upstream package. The scan had created a
`nuget.config` that nothing of the build read. This is the flow of
the previous commit.
- Two tags whose locks both hold the package, both naming the config of
the second project, the scan run in that project: the hub downloads
the patched package and holds it to the lock of the first project,
which the scan did not re-pin.
What changes
Hosted mode reads the `nuget.from_lock` tags of the Bazel workspace the
project is in (`MODULE.bazel` and the files it includes, through the
reader in `bazel/workspace.rs`), and the locks they name. When a tag
reads a lock of the project, it writes nothing for a NuGet package that
the hub would not take: no `nuget.config`, no re-pinned lock entry. The
package is a `skipped` / `redirect_unconfirmed` event, the run exits 0
like any other package that hosted mode does not pin, and one warning
per package names the tag by its file and line and the way on.
`redirect_bazel_nuget_config_undeclared`: the tags do not show that the
hub takes its sources from the project's config.
Warning: newtonsoft.json@13.0.3: MODULE.bazel:9: this
`nuget.from_lock` names no `nuget_config`, so rules_csharp does not
read nuget.config, where hosted mode names the Socket source of a
patch; without that source rules_csharp downloads the upstream
package, and the Bazel build fails on the `contentHash` that hosted
mode re-pins in the lock. So hosted mode wrote nothing for it. Put
`nuget_config = "//:nuget.config"` on that tag and run this command
again: it then names the source in nuget.config, which it creates
where there is none, and the Bazel build takes the patched package
With that attribute on the tag and no other step, the same command
creates the file, re-pins the lock, and the next build takes the patched
package from the Socket source. The file needs no `exports_files` entry:
the hub reads it by its label. `nuget::hosted_no_config` now asserts
both halves on Bazel 9.3.2, 8.8.2 and 7.7.2 where it asserted the
failed build: nothing written and the build still passing on the
upstream package, then the attribute, the same scan and the patched
build.
The warning has another way on where the attribute alone would not do:
- The tag that decides names another file. Where that is a NuGet config
in a directory above the project, as with one `nuget.config` for
several projects: run the command in that directory (`--cwd`), which
writes the file the tag reads. Re-pointing the tag at a config of the
project would take the other sources of that file from the hub, and
failed a build that needed one of them. Otherwise: the attribute, and
the sources of the other file to name in the project's config.
- The tag that decides has `feeds`: the attribute, and those feeds to
name in the config, whose sources stand in the place of `feeds`.
- A tag is not a call of its own, passes `**`, or has a `nuget_config`
that is no plain string: write it out. Nothing is evaluated, so which
file the hub reads cannot be told, and a build that may break
outranks a patch that is missed and explained.
- A tag has `local_package_dirs`: the warning adds that the hub asks
those directories before every source, so the upstream package must
not lie in one.
`redirect_bazel_nuget_lock_not_repinned`: another tag reads a lock that
the run does not re-pin, and that lock holds the package at the patched
version with another `contentHash`, or cannot be read. Where the tags
are in one file, only a lock that the hub reads before the project's
own stands against the pin; in more than one file their order is not
known. The way on: run the command in a directory above both locks that
holds a solution file or a `nuget.config`, where it re-pins the lock of
every project. This is checked first, also where the hub does not read
the config yet, so that the attribute of the other warning cannot lead
to that failed build.
Each way on was followed on Bazel 9.3.2 and ended in the patched build:
the attribute with the feed named in the config; a config spelled
`NuGet.Config`; the run in the directory of a root config that holds a
private source; and, for two locks, the run at the root beside a
solution file, then the attribute its warning names.
When it writes and when it does not
- Nothing changes for a project in no Bazel workspace, for one that
restores into no lock file, and for one whose locks no
`nuget.from_lock` call names. A tag whose `packages_lock_json` is not
a label in a plain string may name any lock and counts as naming the
project's.
- Nothing changes for a package that no lock of the project which a tag
reads holds: its pin changes no file the hub builds it from.
- Hosted mode writes when every `nuget.from_lock` is a call of its own
and the last one that has a `nuget_config` or `feeds` names the
project's config as a label in a plain string. So two tags that name
two configs, the project's last, are pinned as before and build
patched. Where the tags are in more than one file, every tag that has
either must name the config.
- A part of `MODULE.bazel` that the reader cannot read, such as a
`bazel_dep` whose `repo_name` is an expression, can hide a tag and
changes nothing else: where the tags that are read show that the hub
reads the config, hosted mode writes, and that build is patched.
The config is the one the rewriter writes, named as the project
directory spells it: a disk that folds case answers to every spelling,
and the label has to name the file as a disk that does not would. A
label that differs from it only in case counts as the same file, unless
the directory holds both spellings. The label in the warning is in the
package of the lock's own label.
How
`bazel/nuget.rs` reads what the hub makes of the project: why it does
not read the config, if so, and the lock of each tag in the order of
the tags. The disk engine asks it where it lists the locks a NuGet
rewrite would re-pin, and hands the answer to the rewriter under a
synthetic key, as it hands NuGet's inherited sources. `rewrite_nuget`
asks it about each package it would otherwise pin, with the package's
version and patched `contentHash`, and writes nothing for one the hub
would not take. A package it refuses for another reason keeps that
reason's code. The in-memory engine is unchanged: it finds NuGet
packages in no installed tree, raises `ecosystem_unsupported_in_memory`
for their files and never reaches the rewriter.
Not covered
- A tag of another Bazel module, whose sources and locks the hub takes
as well; a lock in another repository; a tag that an unreadable part
of `MODULE.bazel` hides; and what the command line tells Bazel.
- What a directory of `local_package_dirs` holds. With the upstream
package in one and a tag that names the config, the scan pins and the
build fails as it did (Bazel 9.3.2): the directories are named by
paths outside the checkout and are not opened.
- Three shapes that are as they were, and by the ruleset's source fail
the same way (none was built): a Bazel workspace below the directory
of the run, whose tags are not read while the locks of its projects
are re-pinned with the others; a project below the root of a
workspace that is in no git checkout, because the workspace is looked
for only up to the root of the checkout; and a project whose own
locks no tag reads, while a tag names its `nuget.config` and reads
another lock that holds the package.
- A lock beside no project file is re-pinned only by a run in its own
directory, so a package it holds first stays withheld for a run above
it.
- A tag whose config has no package source of its own does not replace
the hub's sources, and a tag with `feeds = []` does not either: both
count as tags that decide.
- A pin that an earlier release wrote in such a workspace stays in the
two files, and the scan reports it as applied beside the warning:
`rollback` takes it out, and the attribute makes the build read it.
- `rollback` still leaves a `nuget.config` that hosted mode created,
holding nuget.org alone, and says so (`nuget_default_config_left`).
The contract and docs/ecosystems.md describe the two codes and the
rules; the NuGet workflow now also runs for the reader and
`bazel/nuget.rs`, and the bazel group of the line budget follows the
code (2486 to 2709).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* Close three ways a hosted NuGet pin could still break a rules_csharp build
A review of the withhold found three workspaces in which `scan --mode
hosted` still exited 0 with the pin written although the hub would not take
it. Each is read from the ruleset's source at 0.5.0 (`_nuget_impl` in
`csharp/extensions.bzl`) and held by unit tests; none was built on Bazel.
- A tag has `feeds`, the tag that decides names the project's config, and
that config has no package source. The hub takes a config's sources in
place of its feeds only when the config has any (`if parsed_sources:
feeds = parsed_sources`), so until then it downloads from the feeds. The
Socket source would be the first source in the file and take their
place, and a package that only the feeds hold could no longer be
downloaded. Hosted mode now writes nothing for any NuGet package of the
run and says to name the feeds in the config
(`redirect_bazel_nuget_config_undeclared`).
- A tag whose `packages_lock_json` is not a label in a plain string, beside
a tag that names a lock of the project. It was taken for the project's
own lock. It reads another one, which may hold the package first, and
the hub holds a package to the first lock that names it. It now counts
as a lock that cannot be read (`redirect_bazel_nuget_lock_not_repinned`),
and the warning says to write the label out.
- A config spelled in a way that is not one of NuGet's (`Nuget.Config`) on
a disk that does not fold case. The rewriter writes a `nuget.config` of
its own beside it, but a tag that names the other file passed as naming
the project's config. The directory's spelling is now taken only where
the rewriter's own name finds that file.
Also:
- The locks of the other tags are parsed once for a run, not once for
each package.
- Where the tag does not name its lock in a plain string, or the config
lies outside the package of that label, the warning names the file
instead of a label whose package would be a guess.
- The comment on the lock check says why it is asked for every package,
also where the hub does not read the config yet.
- The docs say that the hub's rules are those of rules_csharp 0.5.0: a
later release that gives each `name` a hub of its own is not told apart.
The `bazel` group of the line budget follows the code, 2709 to 2766.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>1 parent 447e822 commit 85bbd4a
9 files changed
Lines changed: 1763 additions & 15 deletions
File tree
- .github/workflows
- crates
- socket-patch-cli
- tests/e2e_bazel_build
- socket-patch-core/src
- bazel
- hosted
- patch/redirect
- docs
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
39 | 43 | | |
40 | 44 | | |
41 | | - | |
42 | | - | |
| 45 | + | |
| 46 | + | |
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
| |||
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
69 | 77 | | |
70 | 78 | | |
71 | 79 | | |
| |||
89 | 97 | | |
90 | 98 | | |
91 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
92 | 104 | | |
93 | 105 | | |
94 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2572 | 2572 | | |
2573 | 2573 | | |
2574 | 2574 | | |
| 2575 | + | |
| 2576 | + | |
2575 | 2577 | | |
2576 | 2578 | | |
2577 | 2579 | | |
| |||
0 commit comments