Skip to content

Commit dcdc104

Browse files
refactor: remove obsolete vendoring machinery and duplicate crate code (#1279)
* refactor: remove obsolete crate machinery and duplicate helpers * refactor: collapse obsolete vendor policies and repeated ledger setup Replace service-only result wrappers with Result, remove dead local-build parameters and impossible branches, and share ledger construction and vendoring fixtures. Preserve public entry-point signatures, refusal diagnostics, extraction checks, and independent test oracles. --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 24888e8 commit dcdc104

72 files changed

Lines changed: 1400 additions & 3539 deletions

Some content is hidden

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

‎crates/socket-patch-bench/src/fixtures/mod.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ pub struct Fixture {
8080
pub expect: Expect,
8181
}
8282

83+
fn fixture(
84+
scanned: usize,
85+
patches: Vec<PatchSpec>,
86+
rewritten: &[&str],
87+
warnings: &[&'static str],
88+
) -> Fixture {
89+
Fixture {
90+
project: "project",
91+
expect: Expect {
92+
scanned,
93+
redirected: patches.len(),
94+
rewritten: rewritten.iter().map(|s| s.to_string()).collect(),
95+
allowed_warnings: warnings.to_vec(),
96+
..Expect::default()
97+
},
98+
patches,
99+
files: Vec::new(),
100+
env_paths: Vec::new(),
101+
env: Vec::new(),
102+
}
103+
}
104+
83105
/// The artifact host's base URL inside fixtures. The CLI is pointed at the
84106
/// mock with `SOCKET_PATCH_SERVER_URL`; references carry absolute URLs, so
85107
/// a fixture writes this placeholder and the engine rewrites it to the

‎crates/socket-patch-bench/src/fixtures/npm.rs‎

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::fmt::Write as _;
88
use serde_json::{json, Value};
99

1010
use super::gen::{self, Rng, Tree};
11-
use super::{Expect, Fixture, Size, PATCH_HOST};
11+
use super::{fixture, Fixture, Size, PATCH_HOST};
1212
use crate::mock::PatchSpec;
1313

1414
/// One installed npm package.
@@ -318,30 +318,6 @@ pub fn view_json(uuid: &str, purl: &str, file: &str) -> Value {
318318
})
319319
}
320320

321-
fn fixture(
322-
g: &Graph,
323-
patches: Vec<PatchSpec>,
324-
rewritten: &[&str],
325-
warnings: &[&'static str],
326-
) -> Fixture {
327-
Fixture {
328-
project: "project",
329-
expect: Expect {
330-
scanned: g.pkgs.len(),
331-
lockfile_only: 0,
332-
redirected: patches.len(),
333-
rewritten: rewritten.iter().map(|s| s.to_string()).collect(),
334-
allowed_warnings: warnings.to_vec(),
335-
rescan_lockfile_only: 0,
336-
rescan_extra_scanned: 0,
337-
},
338-
patches,
339-
files: Vec::new(),
340-
env_paths: Vec::new(),
341-
env: Vec::new(),
342-
}
343-
}
344-
345321
// ── npm ────────────────────────────────────────────────────────────────
346322

347323
/// `package-lock.json` (lockfileVersion 3).
@@ -389,7 +365,7 @@ pub fn build_npm(t: &mut Tree, size: Size) -> std::io::Result<Fixture> {
389365
g.install_hoisted(t, "project/")?;
390366
t.mkdir("home")?;
391367
Ok(fixture(
392-
&g,
368+
g.pkgs.len(),
393369
g.patches(false),
394370
&["package-lock.json", ".npmrc"],
395371
&["redirect_npm_allow_remote"],
@@ -487,7 +463,7 @@ pub fn build_pnpm(t: &mut Tree, size: Size) -> std::io::Result<Fixture> {
487463
t.write("project/node_modules/.pnpm/lock.yaml", pnpm_lock(&g))?;
488464
t.mkdir("home")?;
489465
Ok(fixture(
490-
&g,
466+
g.pkgs.len(),
491467
g.patches(false),
492468
&["pnpm-lock.yaml", "pnpm-workspace.yaml"],
493469
&["redirect_pnpm_trust_lockfile"],
@@ -557,7 +533,7 @@ pub fn build_yarn_classic(t: &mut Tree, size: Size) -> std::io::Result<Fixture>
557533
)?;
558534
g.install_hoisted(t, "project/")?;
559535
t.mkdir("home")?;
560-
Ok(fixture(&g, g.patches(false), &["yarn.lock"], &[]))
536+
Ok(fixture(g.pkgs.len(), g.patches(false), &["yarn.lock"], &[]))
561537
}
562538

563539
// ── yarn berry ─────────────────────────────────────────────────────────
@@ -637,7 +613,7 @@ pub fn build_yarn_berry(t: &mut Tree, size: Size) -> std::io::Result<Fixture> {
637613
t.mkdir("home")?;
638614
// Hosted Berry pins both descriptor resolutions and their lock entries.
639615
Ok(fixture(
640-
&g,
616+
g.pkgs.len(),
641617
g.patches(true),
642618
&["package.json", "yarn.lock"],
643619
&[],
@@ -698,7 +674,7 @@ pub fn build_bun(t: &mut Tree, size: Size) -> std::io::Result<Fixture> {
698674
t.write("project/bun.lock", bun_lock(&g))?;
699675
g.install_hoisted(t, "project/")?;
700676
t.mkdir("home")?;
701-
Ok(fixture(&g, g.patches(false), &["bun.lock"], &[]))
677+
Ok(fixture(g.pkgs.len(), g.patches(false), &["bun.lock"], &[]))
702678
}
703679

704680
/// Bun's isolated linker (the default since Bun 1.3.2): the same text
@@ -739,7 +715,7 @@ pub fn build_bun_isolated(t: &mut Tree, size: Size) -> std::io::Result<Fixture>
739715
)?;
740716
}
741717
t.mkdir("home")?;
742-
Ok(fixture(&g, g.patches(false), &["bun.lock"], &[]))
718+
Ok(fixture(g.pkgs.len(), g.patches(false), &["bun.lock"], &[]))
743719
}
744720

745721
// ── vlt ────────────────────────────────────────────────────────────────
@@ -829,7 +805,7 @@ pub fn build_vlt(t: &mut Tree, size: Size) -> std::io::Result<Fixture> {
829805
t.mkdir("home")?;
830806
let patches = g.patches(false);
831807
let mut f = fixture(
832-
&g,
808+
g.pkgs.len(),
833809
patches,
834810
&["vlt-lock.json"],
835811
&["redirect_vlt_reinstall_required"],

‎crates/socket-patch-bench/src/fixtures/other.rs‎

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use serde_json::json;
1212
use super::gen::{self, Rng, Tree};
1313
use super::npm::view_json;
1414
use super::pypi::pretty4;
15-
use super::{Expect, Fixture, Size, PATCH_HOST};
15+
use super::{fixture, Fixture, Size, PATCH_HOST};
1616
use crate::mock::PatchSpec;
1717

1818
/// A generic package of a non-npm ecosystem.
@@ -86,30 +86,6 @@ fn spec(purl: String, uuid: String, view_file: &str, reference: serde_json::Valu
8686
}
8787
}
8888

89-
fn fixture(
90-
scanned: usize,
91-
patches: Vec<PatchSpec>,
92-
rewritten: &[&str],
93-
warnings: &[&'static str],
94-
) -> Fixture {
95-
Fixture {
96-
project: "project",
97-
expect: Expect {
98-
scanned,
99-
lockfile_only: 0,
100-
redirected: patches.len(),
101-
rewritten: rewritten.iter().map(|s| s.to_string()).collect(),
102-
allowed_warnings: warnings.to_vec(),
103-
rescan_lockfile_only: 0,
104-
rescan_extra_scanned: 0,
105-
},
106-
patches,
107-
files: Vec::new(),
108-
env_paths: Vec::new(),
109-
env: Vec::new(),
110-
}
111-
}
112-
11389
// ── RubyGems (bundler) ─────────────────────────────────────────────────
11490

11591
pub fn build_gem(t: &mut Tree, size: Size) -> std::io::Result<Fixture> {

‎crates/socket-patch-bench/src/fixtures/pypi.rs‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::io::Write as _;
1212
use serde_json::json;
1313

1414
use super::gen::{self, Rng, Tree};
15-
use super::{Expect, Fixture, Served, Size, PATCH_HOST};
15+
use super::{Fixture, Served, Size, PATCH_HOST};
1616
use crate::mock::PatchSpec;
1717

1818
const SITE: &str = "project/.venv/lib/python3.12/site-packages";
@@ -197,23 +197,14 @@ pub fn patches(ds: &[Dist]) -> (Vec<PatchSpec>, Served) {
197197

198198
fn fixture(ds: &[Dist], rewritten: &[&str], warnings: &[&'static str]) -> Fixture {
199199
let (patches, files) = patches(ds);
200-
Fixture {
201-
project: "project",
202-
expect: Expect {
203-
scanned: ds.len(),
204-
lockfile_only: 0,
205-
redirected: patches.len(),
206-
rewritten: rewritten.iter().map(|s| s.to_string()).collect(),
207-
// The venv still holds the unpatched files after a hosted scan
208-
// (a reinstall picks the patch up), and the wet run says so.
209-
allowed_warnings: [&["redirect_pypi_stale_install"][..], warnings].concat(),
210-
..Expect::default()
211-
},
212-
patches,
213-
files,
214-
env_paths: Vec::new(),
215-
env: Vec::new(),
216-
}
200+
let mut fixture = super::fixture(ds.len(), patches, rewritten, warnings);
201+
fixture.files = files;
202+
// The venv still holds the unpatched files until the next install.
203+
fixture
204+
.expect
205+
.allowed_warnings
206+
.insert(0, "redirect_pypi_stale_install");
207+
fixture
217208
}
218209

219210
fn pyproject(ds: &[Dist], extra: &str) -> String {

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

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,33 +1654,35 @@ pub async fn run(args: GetArgs) -> i32 {
16541654
print!("{}", format_selected_patches(&selected, color));
16551655
}
16561656

1657-
// Agent-mode dry run: preview against the manifest, write nothing.
1658-
// (Hosted/vendored dry runs are handled inside their engines.) The
1659-
// per-release variant narrowing the wet run applies inside the
1660-
// download engine runs here too, so the preview names only the
1661-
// variants a wet run would fetch.
1662-
if args.common.dry_run && mode == super::scan::ScanMode::Agent {
1663-
let (selected, variant_warnings, _views) = filter_to_installed_releases(
1657+
// Agent wet runs and vendored runs narrow variants in their download
1658+
// engines. Hosted runs and agent previews need the same narrowing here.
1659+
let agent_preview = args.common.dry_run && mode == super::scan::ScanMode::Agent;
1660+
let selected = if agent_preview || mode == super::scan::ScanMode::Hosted {
1661+
let (selected, variant_warnings, _) = filter_to_installed_releases(
16641662
&selected,
16651663
args.all_releases,
16661664
&args.common.crawler_options(),
16671665
quiet,
16681666
&api_client,
16691667
)
16701668
.await;
1671-
let mut narrow_warnings = narrow_warnings;
16721669
narrow_warnings.extend(
16731670
variant_warnings
16741671
.into_iter()
16751672
.map(|w| ("release_narrowing".to_string(), w)),
16761673
);
1674+
selected
1675+
} else {
1676+
selected
1677+
};
1678+
if agent_preview {
16771679
return agent_dry_run(&args, &selected, &narrow_skips, &narrow_warnings).await;
16781680
}
16791681

16801682
// Agent mode confirms before acting (default YES). Dry runs skip the
16811683
// prompt: nothing mutates, so nothing to confirm. Hosted and vendored
16821684
// runs never prompt (v5.0), like `scan`.
1683-
if mode == super::scan::ScanMode::Agent && !args.common.dry_run {
1685+
if mode == super::scan::ScanMode::Agent {
16841686
let prompt = format_confirm_prompt(args.save_only, selected.len());
16851687
if !crate::ui::confirm(&prompt, true, &args.common) {
16861688
if !quiet {
@@ -1692,30 +1694,6 @@ pub async fn run(args: GetArgs) -> i32 {
16921694

16931695
match mode {
16941696
super::scan::ScanMode::Hosted => {
1695-
// Per-release VARIANT narrowing (the finer layer under the
1696-
// coarse version narrowing above). Agent/vendored runs get it
1697-
// inside the download engines; hosted never downloads, so run
1698-
// it here — otherwise every PyPI wheel/sdist, gem platform, and
1699-
// Maven classifier variant of the installed version would be
1700-
// granted and rewritten, not just the installed distribution.
1701-
// Same fallbacks as everywhere else: uninstalled/unmatched
1702-
// bases keep all variants with a warning; --all-releases
1703-
// passes through. (The views it fetched are not needed here:
1704-
// hosted never downloads.)
1705-
let (selected, variant_warnings, _views) = filter_to_installed_releases(
1706-
&selected,
1707-
args.all_releases,
1708-
&args.common.crawler_options(),
1709-
quiet,
1710-
&api_client,
1711-
)
1712-
.await;
1713-
let mut narrow_warnings = narrow_warnings;
1714-
narrow_warnings.extend(
1715-
variant_warnings
1716-
.into_iter()
1717-
.map(|w| ("release_narrowing".to_string(), w)),
1718-
);
17191697
return run_get_hosted(
17201698
&args,
17211699
&api_client,

‎crates/socket-patch-cli/src/commands/scan/discovery.rs‎

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,28 +2146,22 @@ mod tests {
21462146
tier: "free".into(),
21472147
};
21482148
let entry = |uuid: &str, detached: bool| VendorEntry {
2149-
ecosystem: "npm".into(),
2150-
base_purl: "pkg:npm/insync@1.0.0".into(),
2151-
uuid: uuid.into(),
2152-
artifact: VendorArtifact {
2153-
yarn_berry10c0: None,
2154-
path: format!(".socket/vendor/npm/{uuid}/insync-1.0.0.tgz"),
2155-
sha256: String::new(),
2156-
size: None,
2157-
platform_locked: None,
2158-
file_inventory: None,
2159-
},
2160-
wiring: Vec::new(),
2161-
lock: None,
2162-
took_over_go_patches: false,
21632149
detached,
21642150
record: Some(record.clone()),
2165-
flavor: None,
2166-
uv: None,
2167-
pnpm: None,
2168-
poetry: None,
2169-
pdm: None,
2170-
pipenv: None,
2151+
..VendorEntry::new(
2152+
"npm".into(),
2153+
"pkg:npm/insync@1.0.0".into(),
2154+
uuid.into(),
2155+
VendorArtifact {
2156+
yarn_berry10c0: None,
2157+
path: format!(".socket/vendor/npm/{uuid}/insync-1.0.0.tgz"),
2158+
sha256: String::new(),
2159+
size: None,
2160+
platform_locked: None,
2161+
file_inventory: None,
2162+
},
2163+
Vec::new(),
2164+
)
21712165
};
21722166

21732167
// In sync: judged from the record, zero fetches, nothing cached.
@@ -2299,20 +2293,6 @@ mod tests {
22992293
let ledger = HashMap::from([(
23002294
"pkg:npm/embedded@1.0.0".to_string(),
23012295
VendorEntry {
2302-
ecosystem: "npm".into(),
2303-
base_purl: "pkg:npm/embedded@1.0.0".into(),
2304-
uuid: "u-embedded".into(),
2305-
artifact: VendorArtifact {
2306-
yarn_berry10c0: None,
2307-
path: ".socket/vendor/npm/u-embedded/embedded-1.0.0.tgz".into(),
2308-
sha256: String::new(),
2309-
size: None,
2310-
platform_locked: None,
2311-
file_inventory: None,
2312-
},
2313-
wiring: Vec::new(),
2314-
lock: None,
2315-
took_over_go_patches: false,
23162296
detached: true,
23172297
record: Some(PatchRecord {
23182298
uuid: "u-embedded".into(),
@@ -2329,12 +2309,20 @@ mod tests {
23292309
license: "MIT".into(),
23302310
tier: "free".into(),
23312311
}),
2332-
flavor: None,
2333-
uv: None,
2334-
pnpm: None,
2335-
poetry: None,
2336-
pdm: None,
2337-
pipenv: None,
2312+
..VendorEntry::new(
2313+
"npm".into(),
2314+
"pkg:npm/embedded@1.0.0".into(),
2315+
"u-embedded".into(),
2316+
VendorArtifact {
2317+
yarn_berry10c0: None,
2318+
path: ".socket/vendor/npm/u-embedded/embedded-1.0.0.tgz".into(),
2319+
sha256: String::new(),
2320+
size: None,
2321+
platform_locked: None,
2322+
file_inventory: None,
2323+
},
2324+
Vec::new(),
2325+
)
23382326
},
23392327
)]);
23402328

0 commit comments

Comments
 (0)