Skip to content

Withhold a hosted NuGet pin that a rules_csharp hub would not take - #2189

Open
Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
bazel-guard/nuget-hosted-config
Open

Mikola Lysenko (mikolalysenko) wants to merge 4 commits into
mainfrom
bazel-guard/nuget-hosted-config

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

In a Bazel workspace whose rules_csharp nuget.from_lock hub would not take a hosted NuGet pin, scan --mode hosted and get --mode hosted now write nothing for the package and say how to get it patched, where they used to exit 0 and leave a build that fails.

Based on main: two commits, a merge of main, and one commit with the fixes of a code review (see the end). The first commit is tests only and records what main does today; the second is the change, with the expectations of the first changed to match.

Decisions to confirm

  1. A tag that is not written out withholds; an unreadable part elsewhere does not. When a nuget.from_lock is in a comprehension or a condition, passes ** or has a computed nuget_config, hosted mode writes nothing and says so. The other choice is to write as before, which keeps a patch for a workspace that names the right file through a constant and leaves the broken build for one that does not. A part of MODULE.bazel that the reader cannot read, beside tags that plainly show the config, does not withhold: such a workspace builds patched today, and the unread part can only hide another tag, which is a miss this change accepts everywhere else.
  2. local_package_dirs are not opened. A bare tag with them is withheld with a note; a tag that names the config is pinned as today, which fails the build when a directory holds the upstream package. Looking for the package file in those directories would close that, at the price of reading paths outside the checkout that MODULE.bazel names.
  3. Exit 0 with a warning, as for every other package hosted mode does not pin, rather than a failing exit.
  4. The warnings name hosted mode's own remedies only. They do not send the user to vendored mode, which no Bazel build of NuGet packages is known to take.
  5. Size. The implementation is 314 code lines, about two and a half times the first, smaller version of this change (126). The growth is the second warning (reading the locks of the other tags and judging each package against them), the ways on for feeds, a config above the project and the directory's spelling, and the three cases the code review added. Each answers a workspace in which a smaller version ended in a failed build or took a working patch away.

What the code does today

rules_csharp's nuget.from_lock downloads every 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 (rules_csharp 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 socket-patch scan --mode hosted --yes exits 0 and reports the patch applied, and the next bazel build fails with the downloaded package does not match its contentHash in packages.lock.json (Bazel 9.3.2):

  1. A tag that names no nuget_config, which is the shape of the examples in 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 creates a nuget.config that nothing of the build reads.
  2. Two tags whose locks both hold the package, the scan run in the project of the second. The hub reads that project's config, downloads the patched package and holds it to the lock of the first project, which the scan did not re-pin.

The first commit adds nuget::hosted_no_config and records the first case on Bazel 9.3.2, asserting the failed build by its message. The second commit has to change that expectation.

What changes

Hosted mode reads the nuget.from_lock tags of the Bazel workspace the project is in (the root MODULE.bazel and the files it includes, through the existing reader in bazel/workspace.rs) and the locks they name. Nothing is evaluated and no Bazel is run.

When a tag reads one of the project's locks, 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. They show it when every nuget.from_lock is a plain 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. Where the tags are in more than one file their order is not known, and every tag that has either must name it.

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 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 (one nuget.config for several projects): run the command in that directory (--cwd), which writes the file the tag reads. Otherwise: the attribute, and the package sources of the other file to name in the project's config, because the hub takes its sources from one file.
  • 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 has feeds, the tags show the project's config, and that config names no package source: the hub takes a config's sources in place of its feeds only once the config has any, so the Socket source would drop the feeds. Nothing is written for any NuGet package of the run, and the warning says to name the feeds in the config.
  • A tag is not a call of its own, passes **, or has a nuget_config that is no plain string: write it out.
  • 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.

The config is named as the project directory spells it (//:NuGet.Config for a file of that name), so that the label also names the file on a disk that does not fold case. Where the tag does not name its lock in a plain string, or the config lies outside the package of the lock's label, the warning names the file and not a label, whose package would be a guess.

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. A tag that does not name its lock in a plain string, beside one that names a lock of the project, counts as such a lock, and its warning says to write the label out. Where the tags are in one file, only a lock that the hub reads before the project's own stands against the pin. 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 following the other warning cannot end in the failed build.

Nothing changes:

  • for a project in no Bazel workspace;
  • for a project whose locks no nuget.from_lock call names, which Bazel does not build;
  • for a project that restores into no lock file;
  • for a package that no lock of the project which a tag reads holds;
  • where the tags show that the hub reads the config, also beside a part of MODULE.bazel that cannot be read (a bazel_dep whose repo_name is an expression): such a part can only hide a tag;
  • in the in-memory engine, which finds no NuGet package and never reaches the NuGet rewriter.

The first three and the fifth were held to a binary built from the base, byte for byte (see below).

Contents

Two commits, a merge of main and the review's commit.

Lines
Implementation: bazel/nuget.rs (new), the call in hosted/engine.rs, the withhold in rewrite_nuget, one pub mod line +499 -6, of which 314 are code by scripts/loc-budget.py (279 in bazel/nuget.rs)
Tests: the flow and two hermetic tests in tests/e2e_bazel_build/nuget.rs, unit tests in bazel/nuget.rs and patch/redirect/mod.rs +1123 -2
Fixtures none changed or added; the tests edit their own checkouts
Docs: the section Bazel workspaces: NuGet in docs/ecosystems.md, a note in the NuGet row of the mode matrix, two rows in CLI_CONTRACT.md +124 -1
.github/workflows/bazel-nuget.yml: the NuGet legs now also start for the workspace reader and bazel/nuget.rs +17 -5
scripts/loc-budget.json: the bazel group follows the code, 2486 to 2766 1 line

How it is built: 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 already 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; a package it refuses for another reason keeps that reason's code.

What it proves, and where

  • Real Bazel, rules_csharp 0.5.0, Bazel 9.3.2, 8.8.2 and 7.7.2 (nuget::hosted_no_config, in the legs of bazel-nuget.yml): the scan writes nothing and warns, bazel build and bazel run still pass on the upstream package with no file changed; then the attribute and the same scan, and the build prints the patched marker with the package fetched from the stand-in patch host. nuget::hosted_from_lock, the existing flow for a tag that names the config, is unchanged. Both together take 13 to 22 seconds per release locally. No leg asks a public registry.
  • Without the fix the same test fails: with the product change reverted, on Bazel 9.3.2, it fails at the first new expectation (applied is 1), and so do the two hermetic tests.
  • Through the binary, without Bazel (the ordinary test job). nuget::only_a_tag_that_reads_the_lock_without_its_config_is_withheld: what the command prints for a person, its JSON, its exit code and the files it leaves are the same in a checkout that is no Bazel workspace, in one whose tag names the config, and in one whose tag reads another project's lock; only the tag that reads this lock without a config is withheld. nuget::the_pin_is_written_where_the_hub_takes_it: nine workspaces of a hub with more than one tag or another kind of tag, each either pinned with the files named or withheld with the code and the words of its row.
  • By hand on Bazel 9.3.2 (a temporary test, not in CI): each of those nine workspaces was built. Every pinned one ended in the patched build, every withheld one left the build passing on the upstream package, and each way on a warning names was followed to 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. With a binary of the base, the two-lock workspace and a bare tag with local_package_dirs ended in the failed build.
  • Against a binary built from the base, byte for byte (run locally, not in CI): human output, JSON output, exit code and every file are identical in nine checkouts, among them a NuGet project in no Bazel workspace, in a workspace without a rules_csharp hub, beside a hub that reads another lock, below the root with a lock no tag reads, and under the fixture's own tag.
  • Unit tests for the rules: which tag decides and in which order, the labels that count as the project's config, each way on with its whole text, the tags that are not written out, the locks of the other tags and what each state of such a lock means for a package, the spelling taken from the directory, and the rewriter writing nothing.
  • The three cases of the code review (a config without a source beside feeds, a tag whose lock is not named, a spelling that is not NuGet's) are held by unit tests and were read in the ruleset's source at 0.5.0. None was built on Bazel.
  • Each new assertion was checked against a mutation of the product: 25 mutations, of which 24 fail a test. The 25th switches off the exact comparison for a directory that holds two spellings of the config, which only a case-sensitive disk can hold, so its test branch runs on Linux and not on the machine the mutations ran on.

Local gate, after the merge of main and again after the review's commit: clippy for the workspace and for the test target with -D warnings, cargo check --workspace --all-targets --all-features, the NuGet unit tests of the core, the existing test targets that exercise hosted NuGet (no existing expectation changed), e2e_bazel_build without Bazel, cli, spawn_env_hygiene, the line budget, and the two NuGet flows on real Bazel 9.3.2. Before the merge, on the second commit: the whole core unit suite (8296 passed), the scripts' unit tests, actionlint and the tool pin check on the workflow, and the flows on Bazel 8.8.2 and 7.7.2 as well. One run of e2e_vex_lockfile after the merge failed in a test helper that this change does not touch (a rename of a temporary Maven settings file); the same target passed on the next run.

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 or an rc file 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 does today (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 a 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.
  • Withheld although the build would take the pin: tags in more than one file that name two configs, or two locks that hold the package, whatever their order (it is not known there); a tag that is not written out, also when a later plain tag decides; a tag that decides and names a config without package sources, or has feeds = [], neither of which replaces the hub's sources; a lock of another tag that cannot be read (over 16 MiB, or no JSON).
  • 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 pin that an earlier release wrote in such a workspace stays in the two files. socket-patch 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.
  • A release of rules_csharp after 0.5.0. The ruleset's main branch gives each name of nuget.from_lock a hub of its own; no release has that yet, and the tags are read as the one hub of 0.5.0.
  • Only macOS was run locally; the real-Bazel legs in CI are Linux. After the merge of main the flows ran on Bazel 9.3.2 only.

Code review

A review of the whole diff gave nine findings. Five are fixed in the last commit; four are not, for the reasons below.

Fixed:

  1. A config without a package source, beside feeds. The tags showed the config, so hosted mode wrote; the Socket source would have been the file's first source and taken the place of the feeds. Now withheld for every NuGet package of the run, with the feeds to name.
  2. A tag whose lock is not named in a plain string, beside the project's own tag. It was taken for the project's lock; it reads another, which may hold the package first. Now a lock that cannot be read, with the label to write out.
  3. A spelling that is not NuGet's on a disk that does not fold case (Nuget.Config). A tag naming it passed as naming the config, while the rewriter writes a nuget.config beside it. The directory's spelling is now taken only where the rewriter's own name finds the file. Its test branch runs on Linux.
  4. The locks of the other tags were parsed once for each package. Now once for a run.
  5. A label whose package was a guess. Where the tag does not name its lock plainly, the remedy named //<directory>:<config>, which is no label when that directory is not a package. It now names the file.

Not fixed:

  • The lock warning is given also where the hub does not read the config and no lock it reads holds the package. This is meant. The run names the package's source in the config that the other warning tells the user to put on a tag; once that is done the hub takes the patched package against the other lock. Writing in that case is the sequence that ended in a failed build before the second warning existed. The comment on the check now says so.
  • The tags are read as one hub whatever their name. True of 0.5.0, the newest release. The ruleset's main branch separates hubs by name; there is no release to tell apart yet, so it is in the docs and under "Not covered" instead of behind a version check.
  • The engine asks for the raw project root, which makes a recording of reads give up. Also meant: which workspace files and locks are read is not known beforehand, so they cannot be listed for a recording, and a cached answer must not outlive a change to MODULE.bazel. No caller records today. A comment says so.
  • The project's directory from the Bazel root is computed by the same expression in three files. Left: the other two copies are in files this change does not touch, and folding them belongs in a change of its own.

🤖 Generated with Claude Code

… 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>
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>
…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>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 20, 2026 19:02
@cursor

cursor Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes hosted NuGet rewrite behavior for Bazel/rules_csharp layouts; incorrect hub inference could withhold valid pins or still allow broken builds, though coverage is extensive.

Overview
Hosted NuGet in Bazel workspaces no longer writes nuget.config / packages.lock.json pins when rules_csharp’s single nuget.from_lock hub would ignore them or bind packages from another lock first—preventing exit-0 scans that still break the next bazel build on contentHash.

Adds bazel/nuget.rs, which reads MODULE.bazel (no Bazel eval) to build a hub model, and wires it through the hosted engine and NuGet rewriter so affected packages are skipped / redirect_unconfirmed with redirect_bazel_nuget_config_undeclared or redirect_bazel_nuget_lock_not_repinned warnings that spell fixes (e.g. add nuget_config, repin from --cwd above locks).

Tests and CI: new real-Bazel and hermetic flows, unit coverage, docs/CLI contract, and bazel-nuget.yml path filters for the workspace reader.

Reviewed by Cursor Bugbot for commit 0b29a0b. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 0b29a0b. Configure here.

}
Some(doc) => {
first |= nuget_lock_entries(doc).any(|e| e.id.eq_ignore_ascii_case(id));
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier other-version lock skips later mismatch

Medium Severity

Hub::against treats an other tag's lock as establishing the hub pin when it merely names the same package id at any version. That sets first and, when tags are ordered, skips a later lock that holds the patched version with another contentHash. Hosted mode then writes the pin. The project's own locks set first only via version-aware pinned, and the lock warning is defined as firing when another lock holds that same version with a different hash. A workspace with one project on another version ahead of two projects on the patched version can therefore re-pin only the scanned lock; the hub still holds that version to the unre-pinned lock and the Bazel build fails on contentHash.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0b29a0b. Configure here.

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant