Repository navigation
Description
[agent] Found by the architecture refactor routine on main at cfc870f. Low priority: the input is rare, and the outcome is a weaker mode with a wrong reason, not a broken project.
Problem
The repository has two readers of one rule, "does this npm range admit this version", and they disagree on a caret range of a 0.0.x release:
^0.0.3 admits 0.0.5 |
|
|---|---|
utils::npm_range::npm_range_admits (core utils/npm_range.rs, line 6) |
no |
formats::pnpm::range_admits (core formats/pnpm/version.rs, line 296) |
yes |
node-semver 7.7.4, satisfies and intersects |
no |
pnpm 10.28.0, an override keyed <name>@0.0.3 against a dependency that asks ^0.0.2 |
not applied |
npm's caret keeps the leftmost non-zero part, so ^0.0.3 is 0.0.3 alone. The pnpm reader gives every caret below 1.0.0 the whole minor (version_bounds, the same file, lines 93 to 97: the ^ arm requires major > 0, and the fall-through arm is the tilde's).
The pnpm reader decides the importer rule of the hosted pnpm registry route (CLI_CONTRACT.md line 336, point 6: "no importer locks another version of the package through a range that admits the patched one"). So in a workspace where one importer asks for leaf through ^0.0.3 and is locked on 0.0.3, and the patched release is leaf@0.0.5, the route is refused, the run ends on trustLockfile for the whole lock, and the warning says the specifier "may admit 0.0.5". It cannot: pnpm would never move that importer.
Evidence
1. The same input to both readers, and the refusal. Two tests in mod tests of core formats/pnpm/registry_alias.rs, beside shapes_outside_the_fixtures_are_refused (the second is that test's "is no obstacle" case with the release at 0.0.5):
#[test]
fn a_caret_range_of_a_zero_zero_release_admits_that_release_alone() {
use crate::formats::pnpm::range_admits;
use crate::utils::npm_range::npm_range_admits;
for (range, version) in [("^0.0.3", "0.0.5"), ("^0.0.51", "0.0.52")] {
assert_eq!(npm_range_admits(range, version), Some(false), "{range}");
assert_eq!(range_admits(range, version), Some(false), "{range}");
}
}
#[test]
fn an_importer_on_another_zero_zero_release_is_no_obstacle() {
let case = "workspace-importers";
let mut patch = fixtures::patches(case).remove(0);
let before = fixtures::read(case, "project/pnpm-lock.yaml").unwrap();
let owned = fixtures::owned(case);
// The fixture's lock with the patched release at 0.0.5 and the
// importer packages/b on leaf 0.0.3.
patch.version = "0.0.5".into();
let lock_with = |spec_b: &str| {
before
.replace("leaf@1.0.0", "leaf@0.0.5")
.replace("leaf: 1.0.0", "leaf: 0.0.5")
.replace(
"specifier: ^1.0.0\n version: 1.0.0\n\n packages/a",
"specifier: ^0.0.5\n version: 0.0.5\n\n packages/a",
)
.replace(
" leaf:\n specifier: 1.0.0\n version: 1.0.0",
" leaf:\n specifier: 0.0.5\n version: 0.0.5",
)
.replace(
"specifier: ~1.0.0\n version: 1.0.0",
&format!("specifier: {spec_b}\n version: 0.0.3"),
)
.replace(
" leaf@0.0.5:\n resolution:",
" leaf@0.0.3:\n resolution: {integrity: sha512-oL6hZqb1cvnQNlY6vRNq1H5zdvNUMWfaGHq4lTfS3joFocAn9PVwApkhq1TghDd1lg0ZW0xAhfMu010YANbLjA==}\n\n leaf@0.0.5:\n resolution:",
)
.replace(" leaf@0.0.5: {}", " leaf@0.0.3: {}\n\n leaf@0.0.5: {}")
};
let pin = |spec_b: &str| {
let mut lock = OverrideLock::parse(&lock_with(spec_b), &owned).unwrap();
lock.pin(&pin_of(&patch, "socket-11111111")).map(|_| ())
};
// A tilde range does admit 0.0.5: refused, as it should be.
assert!(pin("~0.0.3").unwrap_err().contains("which may admit 0.0.5"));
// The exact version and the caret range admit 0.0.3 alone.
assert_eq!(pin("0.0.3"), Ok(()));
assert_eq!(pin("^0.0.3"), Ok(()));
}On main:
$ cargo test -p socket-patch-core --lib -- zero_zero_release
test formats::pnpm::registry_alias::tests::a_caret_range_of_a_zero_zero_release_admits_that_release_alone ... FAILED
test formats::pnpm::registry_alias::tests::an_importer_on_another_zero_zero_release_is_no_obstacle ... FAILED
assertion `left == right` failed: ^0.0.3
left: Some(true)
right: Some(false)
assertion `left == right` failed
left: Err("locks leaf for importer `packages/b` at another version through the specifier `^0.0.3`, which may admit 0.0.5")
right: Ok(())
In the first test the npm_range_admits assertion passes and the range_admits one fails. In the second the ~0.0.3 and 0.0.3 assertions pass and the ^0.0.3 one fails.
2. What pnpm does. A workspace with a asking wordwrap ^0.0.2, b asking wordwrap 0.0.3, and the override wordwrap@0.0.3: 1.0.0 in pnpm-workspace.yaml, locked with pnpm install --lockfile-only (pnpm 10.28.0, older than the releases the route is for):
a:
dependencies:
wordwrap:
specifier: ^0.0.2
version: 0.0.2 # the override did not apply
b:
dependencies:
wordwrap:
specifier: 1.0.0
version: 1.0.0
With a asking ~0.0.2 instead, a moves to 1.0.0 too. node-semver 7.7.4 gives satisfies('0.0.5', '^0.0.3') = false and intersects('0.0.5', '^0.0.3') = false.
3. How far the two readers differ. Both were run over 28,101 pairs of a range and a version: 663 distinct ranges taken from the package.json files of npm's own dependency tree plus hand-written forms, each against versions derived from its numbers. Where both readers decide, they disagree on four ranges and nowhere else: ^0.0.0, ^0.0.3, ^0.0.4 and ^0.0.6. Three of those are real declarations in that tree (socksv5@^0.0.6, @types/mute-stream@^0.0.4, @sigstore/jest@^0.0.0). npm_range_admits agrees with node-semver's satisfies on every pair it decides.
The pnpm reader arrived with the registry route (5d8378e, #2167, 2026-11-24). npm_range_admits had been there since 2026-10-13 (4353a7c).
Planned fix
One reader of the rule:
override_applies(coreformats/pnpm/version.rs, line 350) asksnpm_range_admitsfor a release and a range with no prerelease on either side, and keeps answeringNonefor a prerelease. ThatNoneis right and has to stay: pnpm intersects the two ranges, and for a prerelease that is notsatisfies(intersects('19.0.0-rc.0', '^19.0.0-rc.0')is false wheresatisfiesis true; 40 such pairs in the run above).range_admitsis deleted. Its other caller,also_locked_in_range(corehosted/engine.rs, line 5274), builds^<version>to mean "the same major, or the same minor below 1.0", which is how the contract defines the note (line 340). It should state that comparison directly, so the note does not change.version_boundsandrange_floorstay: they read the pins of pnpm's own version, where no0.0.xrelease exists.- The two tests above.
#2264 is about the same function (catalog: specifiers), so the two fixes touch neighbouring lines.
Not checked
- An end-to-end hosted scan. This sandbox has pnpm 10.28.0, so it has no lock that pnpm 11.20 or later wrote. The evidence is the lock code the scan calls, over the repository's own fixture with its versions replaced.
- How many packages with a Socket patch are at
0.0.x. The harm needs one, locked at two versions in one workspace, with the lower one asked directly through a caret.
Generated by Claude Code
Activity
refactor: #2324 filed; the version readers ran