Skip to content

Commit a27fe16

Browse files
committed
cleanup pass, wip
1 parent 8ad9b90 commit a27fe16

80 files changed

Lines changed: 955 additions & 1821 deletions

Some content is hidden

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

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ npm-debug.log*
55
yarn-debug.log*
66
yarn-error.log*
77
lerna-debug.log*
8+
*.DS_Store
89

910
# Diagnostic reports (https://nodejs.org/api/report.html)
1011
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
@@ -151,3 +152,4 @@ pypi/socket-patch/README.md
151152

152153
# Generated by scripts/study-crates.ts
153154
study-output/
155+
simplify-output/

crates/.DS_Store

0 Bytes
Binary file not shown.

crates/socket-patch-cli/.DS_Store

0 Bytes
Binary file not shown.

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! names are still read at runtime (via `socket_patch_core::env_compat`) with
1414
//! a one-shot deprecation warning; they will be removed in the next major.
1515
16-
use std::path::PathBuf;
16+
use std::path::{Path, PathBuf};
1717

1818
use clap::Args;
1919

@@ -305,13 +305,14 @@ pub struct GlobalArgs {
305305
}
306306

307307
impl GlobalArgs {
308-
/// Resolve `manifest_path` against `cwd`. See
309-
/// `socket_patch_core::manifest::operations::resolve_manifest_path`.
308+
/// Resolve `manifest_path` against `cwd`: absolute paths are returned
309+
/// as-is, relative paths are joined to `cwd`.
310310
pub(crate) fn resolved_manifest_path(&self) -> PathBuf {
311-
socket_patch_core::manifest::operations::resolve_manifest_path(
312-
&self.cwd,
313-
&self.manifest_path,
314-
)
311+
if Path::new(&self.manifest_path).is_absolute() {
312+
PathBuf::from(&self.manifest_path)
313+
} else {
314+
self.cwd.join(&self.manifest_path)
315+
}
315316
}
316317

317318
/// Build [`ApiClientEnvOverrides`] from the CLI flags.
@@ -902,14 +903,30 @@ mod tests {
902903
/// An absolute `manifest_path` ignores `cwd` and passes through unchanged.
903904
#[test]
904905
fn resolved_manifest_path_passes_absolute_through() {
906+
let absolute = if cfg!(windows) {
907+
r"C:\etc\socket\manifest.json"
908+
} else {
909+
"/etc/socket/manifest.json"
910+
};
911+
let args = GlobalArgs {
912+
cwd: PathBuf::from("/work/project"),
913+
manifest_path: absolute.to_string(),
914+
..GlobalArgs::default()
915+
};
916+
assert_eq!(args.resolved_manifest_path(), PathBuf::from(absolute));
917+
}
918+
919+
/// A dotted relative `manifest_path` is joined verbatim, not normalized.
920+
#[test]
921+
fn resolved_manifest_path_joins_dotted_relative_verbatim() {
905922
let args = GlobalArgs {
906923
cwd: PathBuf::from("/work/project"),
907-
manifest_path: "/etc/socket/manifest.json".to_string(),
924+
manifest_path: "../manifest.json".to_string(),
908925
..GlobalArgs::default()
909926
};
910927
assert_eq!(
911928
args.resolved_manifest_path(),
912-
PathBuf::from("/etc/socket/manifest.json"),
929+
PathBuf::from("/work/project/../manifest.json"),
913930
);
914931
}
915932

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,9 @@ pub(crate) fn result_to_event(result: &ApplyResult, dry_run: bool) -> PatchEvent
508508
.collect();
509509
// Sidecar data is NOT attached here — it's surfaced at the
510510
// envelope level under `Envelope.sidecars[]` by the run loop.
511-
// See `Envelope::record_sidecar`. Keeping events clean of
512-
// sidecar info means each event describes only the apply
513-
// action; sidecar reporting is a separate, JOIN-able list.
511+
// Keeping events clean of sidecar info means each event describes
512+
// only the apply action; sidecar reporting is a separate,
513+
// JOIN-able list.
514514
PatchEvent::new(PatchAction::Applied, purl).with_files(files)
515515
}
516516

@@ -660,7 +660,7 @@ pub async fn run(args: ApplyArgs) -> i32 {
660660
// `envelope.sidecars[]` and JOIN against
661661
// `events[]` by `purl` for per-package context.
662662
if let Some(ref sidecar) = result.sidecar {
663-
env.record_sidecar(sidecar.clone());
663+
env.sidecars.push(sidecar.clone());
664664
}
665665
}
666666
// Manifest entries that targeted in-scope ecosystems but
@@ -957,7 +957,6 @@ async fn apply_patches_inner(
957957
cwd: args.common.cwd.clone(),
958958
global: args.common.global,
959959
global_prefix: args.common.global_prefix.clone(),
960-
batch_size: 100,
961960
};
962961

963962
let all_packages = find_packages_for_purls(

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ async fn filter_to_installed_releases(
720720
cwd: params.cwd.clone(),
721721
global: params.global,
722722
global_prefix: params.global_prefix.clone(),
723-
batch_size: 100,
724723
};
725724
let paths = find_packages_for_rollback(&partitioned, &crawler_options, true).await;
726725

@@ -844,16 +843,11 @@ pub(crate) async fn download_patch_records(
844843
for search_result in &selected {
845844
// Idempotency: a detached entry already at this uuid carries its
846845
// own record — no view fetch needed.
847-
let existing = vendor_state
848-
.entries
849-
.get(&search_result.purl)
850-
.or_else(|| {
851-
vendor_state
852-
.entries
853-
.values()
854-
.find(|e| e.base_purl == search_result.purl)
855-
})
856-
.filter(|e| e.detached && e.uuid == search_result.uuid);
846+
let existing = socket_patch_core::patch::vendor::lookup_entry(
847+
&vendor_state.entries,
848+
&search_result.purl,
849+
)
850+
.filter(|e| e.detached && e.uuid == search_result.uuid);
857851
if let Some(record) = existing.and_then(|e| e.record.clone()) {
858852
if !params.json && !params.silent {
859853
eprintln!(" [skip] {} (already vendored)", search_result.purl);
@@ -967,10 +961,7 @@ async fn warn_on_vendored_uuid_drift(
967961
if !matches!(rec["action"].as_str(), Some("added" | "updated")) {
968962
continue;
969963
}
970-
let entry = vendor_state
971-
.entries
972-
.get(purl)
973-
.or_else(|| vendor_state.entries.values().find(|e| e.base_purl == purl));
964+
let entry = socket_patch_core::patch::vendor::lookup_entry(&vendor_state.entries, purl);
974965
if let Some(entry) = entry.filter(|e| e.uuid != uuid) {
975966
let w = format!(
976967
"{purl} is vendored at patch {} but the manifest now records {uuid}; \
@@ -1507,7 +1498,6 @@ pub async fn run(args: GetArgs) -> i32 {
15071498
cwd: args.common.cwd.clone(),
15081499
global: args.common.global,
15091500
global_prefix: args.common.global_prefix.clone(),
1510-
batch_size: 100,
15111501
};
15121502
let (all_packages, _) = crawl_all_ecosystems(&crawler_options).await;
15131503

crates/socket-patch-cli/src/commands/repair.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,7 @@ async fn repair_inner(
265265
.iter()
266266
.filter(|(purl, rec)| {
267267
!referenced_uuids.contains(&rec.uuid)
268-
&& vendor_state
269-
.entries
270-
.get(*purl)
271-
.or_else(|| {
272-
vendor_state
273-
.entries
274-
.values()
275-
.find(|e| &e.base_purl == *purl)
276-
})
268+
&& socket_patch_core::patch::vendor::lookup_entry(&vendor_state.entries, purl)
277269
.is_none_or(|e| e.uuid != rec.uuid)
278270
})
279271
.map(|(k, v)| (k.clone(), v.clone()))

crates/socket-patch-cli/src/commands/repair_vendor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ pub(crate) async fn repair_vendored_artifacts(
457457
cwd: common.cwd.clone(),
458458
global: common.global,
459459
global_prefix: common.global_prefix.clone(),
460-
batch_size: 100,
461460
};
462461
let mut all_packages = find_packages_for_purls(&partitioned, &crawler_options, quiet).await;
463462
let inventory = lock_inventory::inventory_project(&common.cwd).await;

crates/socket-patch-cli/src/commands/rollback.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,6 @@ async fn rollback_patches_inner(
662662
cwd: args.common.cwd.clone(),
663663
global: args.common.global,
664664
global_prefix: args.common.global_prefix.clone(),
665-
batch_size: 100,
666665
};
667666

668667
let all_packages = find_packages_for_rollback(

crates/socket-patch-cli/src/commands/scan/hosted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ pub(super) async fn run_redirect(
130130
let mut integrity = reference
131131
.artifacts
132132
.iter()
133+
.flatten()
133134
.find(|a| a.kind == "tarball")
134135
.map(|a| a.integrity.clone())
135136
.unwrap_or_default();
@@ -139,6 +140,7 @@ pub(super) async fn run_redirect(
139140
let berry_zip = reference
140141
.artifacts
141142
.iter()
143+
.flatten()
142144
.find(|a| a.kind == "yarn-berry-zip");
143145
if let Some(c) = berry_zip.and_then(|a| a.integrity.yarn_berry10c0.clone()) {
144146
integrity.yarn_berry10c0 = Some(c);

0 commit comments

Comments
 (0)