Repository navigation
Description
[agent] Filed by the scheduled architecture refactor routine. main at d987721 (5.2.0).
Problem
vendor --revert, rollback and remove of two or more vendored NuGet packages exit 0 with status: success and no warning. They restore packages.lock.json, delete the artifacts and the ledger, and leave in nuget.config what vendoring created there:
- a
<packageSourceMapping>section with a*pattern for every source the vendoring machine had, when the config had no such section; - the whole
nuget.config, when the project had none.
With one vendored package the file comes back byte for byte. With two it comes back only when the packages are removed in the reverse of the order they were vendored. So what an undo leaves depends on how many packages there were and on the order they go.
NuGet reads the leftover section as source mapping switched on: a source the section does not name serves no package. The project's other sources are named, so the next restore passes. A source added later, or one that another machine's user-level config holds, is ignored (NU1101).
Evidence
All on d987721. The project is the NuGet project of tests/vendor_ecosystem_fixtures (two packages, a nuget.config with one source and no mapping), vendored by vendor and then undone.
nuget.config before vendoring |
Vendored | Undo | Exit | nuget.config after the undo |
|---|---|---|---|---|
| one source, no mapping | 2 | vendor --revert |
0, success |
+ <packageSourceMapping>: nuget.org → * |
| one source, no mapping | 2 | rollback --yes |
0, success |
the same block |
| one source, no mapping | 2 | rollback <purl>, first package then second |
0, 0 | the same block |
| one source, no mapping | 2 | remove <purl>, first package then second |
0, 0 | the same block |
| one source, no mapping | 2 | remove <purl>, second package then first |
0, 0 | byte for byte |
| one source, no mapping | 1 | vendor --revert |
0 | byte for byte |
| two sources, no mapping | 2 | vendor --revert |
0 | + the section, * for both sources |
| two sources, no mapping | 1 | vendor --revert |
0 | byte for byte |
one source and the user's own nuget.org → * mapping |
2 | vendor --revert |
0 | byte for byte |
no nuget.config |
2 | vendor --revert |
0 | a new nuget.config stays: the nuget.org source and the section |
no nuget.config |
1 | vendor --revert |
0 | absent, as before |
no nuget.config; the user-level config holds a source ci-private |
2 | vendor --revert |
0 | a new nuget.config stays, and its section names nuget.org and ci-private |
In every row the lock is restored and the ledger and artifacts are gone. No row prints a warning about the config. The last row also leaves the name of a source from the user's own machine in a project file.
The other nine projects of that fixture set (npm, pnpm, Cargo, Go, requirements.txt, pylock.toml, gem, Composer, Maven) come back to their pre-vendor tree under all five undo orders above.
What the leftover does, with the real SDK (.NET SDK 8.0.428, mcr.microsoft.com/dotnet/sdk:8.0-noble, no network; a folder feed stands in for each URL, put there by the same sed in both copies, so the two projects differ by the leftover alone):
| Step | Project as it was before vendoring | The same project after vendor and vendor --revert |
|---|---|---|
dotnet restore |
Restored | Restored |
dotnet nuget add source <feed> -n internal --configfile nuget.config, then dotnet add package Fx.Internal --version 1.0.0 |
added, Restored | error: NU1101: Unable to find package Fx.Internal. No packages exist with this id in source(s): nuget.org. PackageSourceMapping is enabled, the following source(s) were not considered: internal. (exit 1) |
A project that never had a nuget.config, on a machine whose user-level config holds the feed ci-private for one of its packages: dotnet restore |
Restored | error NU1101: Unable to find package Fx.Internal. No packages exist with this id in source(s): nuget.org. PackageSourceMapping is enabled, the following source(s) were not considered: ci-private. (exit 1) |
For the third row the leftover file was written on a machine without that user-level feed. On a machine that has it, the section names it (the last row of the first table), and the restore fails on any machine that calls its feed something else.
The test that should catch it exempts NuGet. new_ledgers_compact_whole_file_snapshots_and_revert asserts a byte-exact restore for every ecosystem but this one ([vendor_ledger_schema_e2e.rs#L204-L215](https://github.com/SocketDev/socket-patch/blob/d98772148e4fffb56fa53e9f867e10e1286bb089/crates/socket-patch-cli/tests/vendor_ledger_schema_e2e.rs#L204-L215)). It holds NuGet to a checked-in [reverted/nuget.config](https://github.com/SocketDev/socket-patch/blob/d98772148e4fffb56fa53e9f867e10e1286bb089/crates/socket-patch-cli/tests/fixtures/legacy-ledgers/nuget/reverted/nuget.config#L48-L52), which contains the leftover section. With the if *eco != "nuget" exemption removed the test fails on main:
thread 'new_ledgers_compact_whole_file_snapshots_and_revert' panicked at crates/socket-patch-cli/tests/vendor_ledger_schema_e2e.rs:205:13:
assertion `left == right` failed: nuget: byte-exact restore
Cause
revert_config_record has two ways to undo a package's config edit ([nuget_feed.rs#L1802-L1893](https://github.com/SocketDev/socket-patch/blob/d98772148e4fffb56fa53e9f867e10e1286bb089/crates/socket-patch-core/src/vendor/nuget_feed.rs#L1802-L1893)):
- (a) The live file is the snapshot this package's record took after its own edit: put the whole original back, or delete a file vendoring created.
- (b) Anything else: cut out this package's own source and mapping, and nothing more.
With two packages, the one undone first finds its sibling's lines in the file and takes (b). Its doc comment says why the catch-all stays there: "when a sibling is present they are load-bearing for it" ([#L1766-L1769](https://github.com/SocketDev/socket-patch/blob/d98772148e4fffb56fa53e9f867e10e1286bb089/crates/socket-patch-core/src/vendor/nuget_feed.rs#L1766-L1769)). The one undone last finds a file that is no longer its snapshot, since that snapshot held the first package's lines, so it takes (b) as well. No step removes the section, the seeded source or the created file once the last sibling is gone. Only the reverse order reaches (a) twice.
The same defect was fixed for pnpm and uv, and not here. #636 and #670 were fixed by #672 (b0a11c0, "Fix vendored revert leaving created scaffold behind"). Its message: "only the first ledger entry remembered that vendoring created the shared pnpm.overrides / pnpm table, pnpm-workspace.yaml or [tool.uv.sources] table. A full vendor --revert, rollback or remove then left that scaffolding behind unless the first package happened to be reverted last". That fix shares the "created by vendoring" flags across the entries (share_scaffold_flags, state.rs#L568-L586) and replaced the pnpm golden that had recorded the residue. The NuGet config has no such flag, and its golden still records the residue.
The contract speaks of this restore as exact ("so the restore stays byte-exact", CLI_CONTRACT.md#L2130-L2139) and names a leftover <packageSourceMapping> only as what an older 5.x CLI does with a redacted snapshot.
Planned fix
- The entry whose undo removes the last vendored source of a config also removes what vendoring created there: the catch-all mappings and their section, a
<packageSources>section andnuget.orgseed that vendoring added, and a file that vendoring created. A section that holds anything else stays, as Fix vendored revert leaving created scaffold behind (#636, #670) #672 keeps a pnpm or uv table that holds a user's key. - Remove the NuGet exemption from
new_ledgers_compact_whole_file_snapshots_and_revert, replace the golden, and add the two-package project under each undo order above through the CLI. - The contract's NuGet paragraph gets one sentence for the rule.
One thing a maintainer may want to say, which does not block the fix: a project that an earlier undo already left with the section has no ledger entry any more to say the section was vendoring's. The plan leaves such a file alone.
Not run
- Hosted mode. A hosted scan writes the same source and mapping; its undo needs the upstream registry, which this sandbox does not reach.
- Three or more packages, a config in a parent directory, a CRLF config, Windows and macOS.
Generated by Claude Code
Activity
refactor: L184 filed as #2501 (NuGet undo), L185 on #2498