Skip to content

Commit 9264da9

Browse files
committed
Merge main into fix/hosted-memory-go-pathspace
Resolve engine.rs: main's #2025 linked-read test and this PR's in-memory Go workspace test were added at the same spot; keep both. Co-Authored-By: Claude <noreply@anthropic.com>
2 parents 04a1a9d + bb17e0d commit 9264da9

148 files changed

Lines changed: 14919 additions & 1423 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ jobs:
208208
- name: Python — test native installer harnesses
209209
run: python3 -B -m unittest discover -s scripts/tests -v
210210

211+
- name: Rust — lock model size budget
212+
# Annotates, never fails: a bug fix elsewhere may add lines to these
213+
# files. The lock-model PRs lower the budget as they delete code
214+
# (docs/design/lock-model-unification.md#size-budget).
215+
run: python3 -B scripts/loc-budget.py --warn
216+
211217
- name: Shell — shellcheck the curl|sh installer
212218
# shellcheck is pre-installed on ubuntu-latest.
213219
run: shellcheck --shell=sh scripts/install.sh

‎CHANGELOG.md‎

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ a version without a non-empty section in this file.
6262
`=begin`/`=end` blocks, heredoc bodies and `__END__` data are skipped, so
6363
a commented-out dev dependency no longer adds a bogus requirement and a
6464
heredoc no longer refuses the Gemfile (#1932, #1936).
65+
- A gem declared inside nested `source … do` blocks is attributed to the
66+
innermost block, as Bundler reads it, so hosted `rollback` and `remove`
67+
of a pin inside the user's own source block no longer refuse with
68+
`hosted_wiring_contested` on Bundler 2.1 and older (#1997, #1999).
6569
- **npm family.**
6670
- pnpm workspace globs with brace sets and character classes
6771
(`packages/{a,b}`, `packages/[ab]*`) are read the way pnpm reads them in
@@ -88,6 +92,14 @@ a version without a non-empty section in this file.
8892
npm config layer sets `omit-lockfile-registry-resolved`, which makes the
8993
next `npm install` drop the hosted URL and fail with `EINTEGRITY`, and
9094
names where it is set and the remedies (#1871, #1872).
95+
- Hosted vlt scans no longer download every granted patch archive to
96+
check its encoding, and no longer withhold dependencies with
97+
`redirect_vlt_artifact_unverifiable`; a mirror that re-encodes archives
98+
makes `vlt ci` fail closed with `EINTEGRITY`. The in-memory hosted
99+
engine (the Node addon and `hosted-bundle`) now pins vlt dependencies
100+
instead of withholding them as offline (#2013).
101+
- The lock inventory skips Rush subspace locks with unsafe names, as
102+
lockfile discovery already did (#2003).
91103
- **PyPI.**
92104
- A requirements line pinned through an environment variable
93105
(`six==${SIXV}`) is refused by `vendor` with
@@ -106,16 +118,52 @@ a version without a non-empty section in this file.
106118
- A `poetry.lock` in an old format (0, 1.0, 1.1) keeps its "written by
107119
Poetry < 1.4" warnings and refusals even when a hand-merged header claims
108120
a newer Poetry (#1847, #1865).
109-
- **Go.** In a go 1.16 (unpruned) module where a dependency imports a fork
110-
that the root `go.mod` replaces with the patched module, `apply`,
111-
`apply --check`, hosted mode and `vex` read the module graph to tell
112-
whether the patch is really built, instead of reporting it applied while
113-
`go build` linked the unpatched code (#1840, #1843).
114-
- **Maven.** A Maven 4 root that builds its subdirectories implicitly
115-
(model 4.1.0, `pom` packaging, no `<subprojects>`) is treated as a reactor
116-
by hosted mode, `vex` and the Maven cache scope, not only by vendored mode,
117-
so a root-only pin is no longer attested while a module keeps its own
118-
version (#1809, #1886).
121+
- Hosted `rollback`, `remove` and `scan` restore the pins hosted mode
122+
writes into uv 0.2 `[[distribution]]` locks (uv < 0.2.35) instead of
123+
refusing them (#2014).
124+
- **Go.**
125+
- In a go 1.16 (unpruned) module where a dependency imports a fork that
126+
the root `go.mod` replaces with the patched module, `apply`,
127+
`apply --check`, hosted mode and `vex` read the module graph to tell
128+
whether the patch is really built, instead of reporting it applied
129+
while `go build` linked the unpatched code (#1840, #1843).
130+
- `vex` reads the `go.work` that governs the project (`GOWORK`, else the
131+
nearest one at or above it, with members anywhere), as hosted and
132+
vendored modes already did, and no longer attests a Socket replace the
133+
workspace keeps out of the build (`go_workspace_override`) (#2011).
134+
- **JVM.**
135+
- A Maven 4 root that builds its subdirectories implicitly (model 4.1.0,
136+
`pom` packaging, no `<subprojects>`) is treated as a reactor by hosted
137+
mode, `vex` and the Maven cache scope, not only by vendored mode, so a
138+
root-only pin is no longer attested while a module keeps its own
139+
version (#1809, #1886).
140+
- Hosted Maven keeps every line of `.mvn/checksums/checksums.sha256` it
141+
doesn't own (single-space or `*` sha256sum lines, tabs, comments) and
142+
the file's line endings, instead of silently dropping them (#2016).
143+
- Vendored Maven `vex` no longer attests a build that may still use the
144+
unpatched jar: an executable classifier copy of the patched artifact,
145+
or a suffixed version left only in a plugin, profile or unused property,
146+
now withholds attestation (#2006).
147+
- Vendored Gradle withholds attestation when a `gradle.lockfile` locks
148+
the patched artifact at another version
149+
(`gradle_lock_overrides_vendored`) or a custom `lockFile` location is
150+
used (`gradle_custom_lock_file`) (#2004).
151+
- sbt: `vex` no longer attests a hosted pin that a build reassignment of
152+
`dependencyOverrides` or `resolvers`, `sbt.override.build.repos=true`,
153+
or newer resolution evidence shows the build doesn't apply
154+
(`vex_sbt_pin_bypassed`) (#2030), nor a vendored pin without current
155+
sbt resolution evidence or with its vendored tree missing
156+
(`vex_sbt_resolution_unverified`, `vex_sbt_vendored_tree_missing`)
157+
(#2008).
158+
- **NuGet.** When a `packages.lock.json` locks a patched package at a
159+
version the writers refuse to wire (another target framework or
160+
project), `vex` no longer attests that version
161+
(`vex_nuget_lock_other_version`); `1.0` and `1.0.0` count as one version
162+
(#2007).
163+
- **Composer.** A `composer.lock` with a UTF-8 BOM is read everywhere,
164+
and vendor then `--revert` keeps the BOM byte for byte; a revert no
165+
longer deletes a vendored artifact such a lock still installs from
166+
(#2017).
119167
- **Vendoring.**
120168
- Vendored dry runs leave already-vendored patches out of the "Would
121169
download and vendor" headline and list them as skipped, matching the wet
@@ -129,6 +177,17 @@ a version without a non-empty section in this file.
129177
slot (#1976, #1977).
130178
- In a vlt project, `vendor` no longer requests service downloads for
131179
packages it then refuses (#1909, #1947).
180+
- Every vendored entry point (`scan` previews and rollout plans, the
181+
download phase, `get`, and `vendor`) applies the same refusals before
182+
any download: a v1 `package-lock.json` project, or a hosted pnpm pin
183+
whose takeover would be refused, is refused before its patch is
184+
fetched; `get <uuid> --mode vendored` reports every such refusal and
185+
writes nothing; and `vendor` refuses before restoring a hosted pin
186+
instead of restoring it and rolling back. Codes and details are
187+
unchanged (#2015).
188+
- A vendored revert keeps an artifact the lock still references through
189+
an escaped path spelling (`\/` in an older `composer.lock`, Windows
190+
backslashes) instead of deleting it (#2022).
132191
- **General.**
133192
- The nested-project remedy quotes its path for the shell it prints for,
134193
including Windows and `%` (#1859, #1884).
@@ -146,7 +205,10 @@ a version without a non-empty section in this file.
146205
runner, `copy_tree` and apply fixtures; hermetic children scrub color
147206
variables; failing tests are annotated in CI; offline bun.lockb rollback
148207
mock and a Windows venv layout in the PyPI fixture (#1891, #1890, #1905,
149-
#1944, #1955, #1964, #1972, #1978, #1988, #1994).
208+
#1944, #1955, #1964, #1972, #1978, #1988, #1994, #2000); release
209+
workflow artifact steps move off Node 20 actions (#2027). A design doc
210+
and line-count budget plan one lock model for every lockfile reader
211+
(#2001).
150212

151213
## [5.0.1] — 2026-10-13
152214

‎crates/socket-patch-cli/CLI_CONTRACT.md‎

Lines changed: 59 additions & 12 deletions
Large diffs are not rendered by default.

‎crates/socket-patch-cli/src/args.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,14 @@ impl GlobalArgs {
447447
self.global || self.global_prefix.is_some()
448448
}
449449

450+
/// The read scope this run's mode fixes for every bounded read: a
451+
/// global run (`--global` / `--global-prefix`) reads anywhere on the
452+
/// system; a project run never reads a project file outside the
453+
/// repository root (see `socket_patch_core::utils::repo_root`).
454+
pub(crate) fn read_scope(&self) -> socket_patch_core::utils::repo_root::ReadScope {
455+
socket_patch_core::utils::repo_root::ReadScope::of_global(self.is_global())
456+
}
457+
450458
/// Whether `--ecosystems` selects `eco` (every ecosystem when unset or
451459
/// empty). The names are validated at parse time, so this is an exact
452460
/// match.

‎crates/socket-patch-cli/src/commands/apply.rs‎

Lines changed: 121 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,17 @@ async fn run_check(args: &ApplyArgs, manifest_path: &Path) -> i32 {
471471
// The same PnP gate `apply` runs: a PnP tree hides every npm copy, so
472472
// without it each npm patch would read as not installed and pass calm.
473473
if matches!(
474-
detect_npm_pkg_manager(&args.common.cwd),
474+
detect_npm_pkg_manager(args.common.read_scope(), &args.common.cwd),
475475
NpmPkgManager::YarnBerryPnP
476476
) && eco_in_local_scope(&args.common, Ecosystem::Npm)
477477
&& manifest_targets_npm(&tree)
478478
{
479479
return refuse_yarn_pnp(args);
480480
}
481+
// The same cargo gate `apply` runs (see [`cargo_config_outside_root`]).
482+
if let Some(why) = cargo_config_outside_root(args, &tree) {
483+
return refuse_cargo_config_outside_root(args, &why, &[]);
484+
}
481485
let mut in_sync: Vec<String> = Vec::new();
482486
let mut not_installed: Vec<String> = Vec::new();
483487
if !tree.patches.is_empty() {
@@ -948,6 +952,52 @@ pub(crate) fn result_to_event(result: &ApplyResult, dry_run: bool) -> PatchEvent
948952
/// True when the manifest records at least one npm patch — the only kind a
949953
/// PnP layout can block (a polyglot repo's pypi/gem/go patches live outside
950954
/// `node_modules` and apply fine).
955+
/// The refusal code of [`cargo_config_outside_root`].
956+
const CARGO_CONFIG_OUTSIDE_ROOT: &str = "cargo_config_outside_root";
957+
958+
/// Why a workspace apply cannot patch this project's Cargo crates: a
959+
/// `.cargo/config` / `config.toml` sits above the repository root (stat
960+
/// only; it is never read), and cargo merges it into the build, so it may
961+
/// replace crates.io with another source while apply patches the shared
962+
/// registry cache. `None` for a global run, a run without Cargo patches
963+
/// or a project that is no Cargo project.
964+
fn cargo_config_outside_root(args: &ApplyArgs, manifest: &PatchManifest) -> Option<String> {
965+
let cwd = &args.common.cwd;
966+
if !eco_in_local_scope(&args.common, Ecosystem::Cargo)
967+
|| !manifest
968+
.patches
969+
.keys()
970+
.any(|p| Ecosystem::from_purl(p) == Some(Ecosystem::Cargo))
971+
|| !(cwd.join("Cargo.toml").is_file() || cwd.join("Cargo.lock").is_file())
972+
{
973+
return None;
974+
}
975+
socket_patch_core::vendor::cargo_config::config_above_repo(cwd).map(|why| {
976+
format!(
977+
"{why}: it may replace crates.io with another source, so the registry copy apply \
978+
patches may not be what cargo builds; move the settings into the repository's \
979+
.cargo/config.toml (or run with --global to patch the registry cache anyway)"
980+
)
981+
})
982+
}
983+
984+
/// Print the [`cargo_config_outside_root`] refusal and return the exit
985+
/// code.
986+
fn refuse_cargo_config_outside_root(args: &ApplyArgs, why: &str, skipped: &[PatchEvent]) -> i32 {
987+
if args.common.json {
988+
let mut env = Envelope::new(Command::Apply);
989+
env.dry_run = args.common.dry_run;
990+
for skip in skipped {
991+
env.record(skip.clone());
992+
}
993+
env.mark_error(EnvelopeError::new(CARGO_CONFIG_OUTSIDE_ROOT, why));
994+
println!("{}", env.to_pretty_json());
995+
} else {
996+
eprintln!("Error: {why}");
997+
}
998+
1
999+
}
1000+
9511001
fn manifest_targets_npm(manifest: &PatchManifest) -> bool {
9521002
manifest
9531003
.patches
@@ -1061,7 +1111,7 @@ pub async fn run(args: ApplyArgs) -> i32 {
10611111
// filter excluding npm never touches it.
10621112
if eco_in_local_scope(&args.common, Ecosystem::Npm)
10631113
&& matches!(
1064-
detect_npm_pkg_manager(&args.common.cwd),
1114+
detect_npm_pkg_manager(args.common.read_scope(), &args.common.cwd),
10651115
NpmPkgManager::YarnBerryPnP
10661116
)
10671117
{
@@ -1388,7 +1438,17 @@ pub(crate) async fn run_locked(
13881438
// informational note; the substantive safety is core's rename-over
13891439
// write (`utils::fs::atomic_write_bytes` never touches the store's
13901440
// shared inode).
1391-
match detect_npm_pkg_manager(&args.common.cwd) {
1441+
// A cargo config above the repository root is never read in a
1442+
// workspace run; it may move crates.io elsewhere, so the Cargo patches
1443+
// refuse instead of patching the registry cache blind.
1444+
if let Some(why) = cargo_config_outside_root(&args, &manifest) {
1445+
let code = refuse_cargo_config_outside_root(&args, &why, &user_patch_skips);
1446+
return ApplyRunReport {
1447+
skipped: user_patch_skips,
1448+
..ApplyRunReport::run_failure(code, CARGO_CONFIG_OUTSIDE_ROOT, why)
1449+
};
1450+
}
1451+
match detect_npm_pkg_manager(args.common.read_scope(), &args.common.cwd) {
13921452
NpmPkgManager::YarnBerryPnP => {
13931453
if eco_in_local_scope(&args.common, Ecosystem::Npm) && manifest_targets_npm(&manifest) {
13941454
let code = refuse_yarn_pnp_with_skips(&args, &user_patch_skips);
@@ -1512,6 +1572,7 @@ pub(crate) async fn run_locked(
15121572
});
15131573
cache_warnings.extend(
15141574
socket_patch_core::utils::cargo_build_cache::invalidate_project(
1575+
args.common.read_scope(),
15151576
&args.common.cwd,
15161577
rewritten.map(|r| r.package_key.as_str()),
15171578
)
@@ -2712,6 +2773,7 @@ async fn apply_patches_inner(
27122773
// extension, or is refused with nothing written (#1996).
27132774
let result = if Ecosystem::from_purl(purl) == Some(Ecosystem::Gem) {
27142775
let applied = gem_ext::apply_gem_package_patch(
2776+
args.common.read_scope(),
27152777
variant_purl,
27162778
pkg_path,
27172779
&patch.files,
@@ -2735,6 +2797,7 @@ async fn apply_patches_inner(
27352797
applied.result
27362798
} else {
27372799
apply_package_patch(
2800+
args.common.read_scope(),
27382801
variant_purl,
27392802
pkg_path,
27402803
&patch.files,
@@ -2892,6 +2955,7 @@ async fn apply_patches_inner(
28922955
}
28932956
None => {
28942957
apply_package_patch(
2958+
args.common.read_scope(),
28952959
purl,
28962960
pkg_path,
28972961
&patch.files,
@@ -3423,6 +3487,7 @@ async fn apply_maven_base(m: &MavenBase<'_>) -> MavenApplied {
34233487
}
34243488
attempted = true;
34253489
let mut result = apply_package_patch(
3490+
args.common.read_scope(),
34263491
variant,
34273492
&dir,
34283493
&files,
@@ -3443,6 +3508,7 @@ async fn apply_maven_base(m: &MavenBase<'_>) -> MavenApplied {
34433508
if copy_attempted && !absent.is_empty() {
34443509
attempted = true;
34453510
let result = apply_package_patch(
3511+
args.common.read_scope(),
34463512
variant,
34473513
copy,
34483514
&absent,
@@ -3743,6 +3809,58 @@ mod tests {
37433809
AppliedVia as CoreAppliedVia, ApplyResult, VerifyResult, VerifyStatus,
37443810
};
37453811

3812+
/// Review finding 3: a workspace apply of Cargo patches refuses when a
3813+
/// `.cargo/config.toml` above the repository root (never read) may
3814+
/// replace crates.io; a global run, or one without it, does not.
3815+
#[test]
3816+
fn cargo_patches_refuse_under_a_cargo_config_above_the_repository() {
3817+
#[derive(clap::Parser)]
3818+
struct Wrap {
3819+
#[command(flatten)]
3820+
args: ApplyArgs,
3821+
}
3822+
let tmp = tempfile::tempdir().unwrap();
3823+
let outer = std::fs::canonicalize(tmp.path()).unwrap();
3824+
let app = outer.join("repo");
3825+
std::fs::create_dir_all(app.join(".git")).unwrap();
3826+
std::fs::write(app.join("Cargo.toml"), "[package]\nname = \"app\"\n").unwrap();
3827+
let record: socket_patch_core::manifest::schema::PatchRecord =
3828+
serde_json::from_value(serde_json::json!({
3829+
"uuid": "11111111-1111-4111-8111-111111111111",
3830+
"exportedAt": "",
3831+
"files": {},
3832+
"vulnerabilities": {},
3833+
"description": "",
3834+
"license": "",
3835+
"tier": "free",
3836+
}))
3837+
.unwrap();
3838+
let mut manifest = PatchManifest::default();
3839+
manifest
3840+
.patches
3841+
.insert("pkg:cargo/serde@1.0.0".to_string(), record);
3842+
let parse = |extra: &[&str]| {
3843+
let cwd = app.display().to_string();
3844+
let mut argv = vec!["t", "--cwd", cwd.as_str()];
3845+
argv.extend_from_slice(extra);
3846+
<Wrap as clap::Parser>::try_parse_from(argv).unwrap().args
3847+
};
3848+
assert_eq!(cargo_config_outside_root(&parse(&[]), &manifest), None);
3849+
std::fs::create_dir_all(outer.join(".cargo")).unwrap();
3850+
std::fs::write(
3851+
outer.join(".cargo/config.toml"),
3852+
"[source.crates-io]\nreplace-with = \"v\"\n[source.v]\ndirectory = \"vendor\"\n",
3853+
)
3854+
.unwrap();
3855+
let why = cargo_config_outside_root(&parse(&[]), &manifest).unwrap();
3856+
assert!(why.contains(".cargo/config.toml"), "{why}");
3857+
assert!(why.contains("outside the repository"), "{why}");
3858+
assert_eq!(
3859+
cargo_config_outside_root(&parse(&["--global"]), &manifest),
3860+
None
3861+
);
3862+
}
3863+
37463864
/// A new-file collision's empty expected hash reads `(new file)` in the
37473865
/// verbose summary; a real hash is shown as is.
37483866
#[test]

‎crates/socket-patch-cli/src/commands/composer_hints.rs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ const VENDOR_PREFIX: &str = ".socket/vendor/composer/";
4646

4747
/// The `<vendor>/<name>` of every composer.lock package (`packages` and
4848
/// `packages-dev`) whose dist is a vendored `path` copy, sorted and
49-
/// de-duplicated. An unparseable lock yields nothing.
49+
/// de-duplicated. An unparseable lock yields nothing; one leading BOM is
50+
/// read past, as the vendored backend reads the lock.
5051
pub(crate) fn vendored_composer_packages(lock_text: &str) -> Vec<String> {
52+
let lock_text = socket_patch_core::formats::text::strip_bom(lock_text);
5153
let Ok(lock) = serde_json::from_str::<Value>(lock_text) else {
5254
return Vec::new();
5355
};
@@ -182,6 +184,13 @@ mod tests {
182184
);
183185
assert!(vendored_composer_packages("not json").is_empty());
184186
assert!(vendored_composer_packages("{}").is_empty());
187+
// One leading BOM is encoding (the backend reads past it); a second
188+
// is content.
189+
assert_eq!(
190+
vendored_composer_packages(&format!("\u{feff}{}", lock())),
191+
vendored_composer_packages(&lock())
192+
);
193+
assert!(vendored_composer_packages(&format!("\u{feff}\u{feff}{}", lock())).is_empty());
185194
}
186195

187196
#[test]

0 commit comments

Comments
 (0)