Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 64 additions & 13 deletions crates/socket-patch-cli/src/commands/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,19 @@ async fn try_local_go_apply(

/// After the apply loop: prune local-go redirects whose patches were dropped
/// from the manifest. No-op unless local go is in scope.
async fn reconcile_local_go(common: &GlobalArgs, target_manifest_purls: &HashSet<String>) {
async fn reconcile_local_go(
common: &GlobalArgs,
target_manifest_purls: &HashSet<String>,
) -> Result<(), String> {
if !eco_in_local_scope(common, Ecosystem::Golang) {
return;
return Ok(());
}
let desired: HashSet<String> = target_manifest_purls
.iter()
.filter(|p| Ecosystem::from_purl(p) == Some(Ecosystem::Golang))
.cloned()
.collect();
let removed = reconcile_go_redirects(&common.cwd, &desired, common.dry_run).await;
let removed = reconcile_go_redirects(&common.cwd, &desired, common.dry_run).await?;
if !removed.is_empty() && !common.silent && !common.json {
let verb = if common.dry_run {
"Would remove"
Expand All @@ -284,6 +287,7 @@ async fn reconcile_local_go(common: &GlobalArgs, target_manifest_purls: &HashSet
println!(" {purl}");
}
}
Ok(())
}

/// Read-only verification that the manifest's patches are in place, for CI
Expand Down Expand Up @@ -383,6 +387,20 @@ async fn run_check(args: &ApplyArgs, manifest_path: &Path) -> i32 {
drifts.push((id, "go_redirect_drift".to_string(), d.to_string()));
}
}
for (purl, record) in &manifest.patches {
if in_scope.contains(purl) {
if let Err(detail) =
socket_patch_core::vendor::go_consumer_sync::verify_native_vendor(
&args.common.cwd,
purl,
record,
)
.await
{
drifts.push((purl.clone(), "go_vendor_content_mismatch".into(), detail));
}
}
}
// The redirects can be intact while the project no longer
// builds: a committed vendor/modules.txt or the go.mod
// requirements out of step with them (#343, #618).
Expand Down Expand Up @@ -1358,11 +1376,6 @@ pub(crate) async fn run_locked(
.map(|(code, detail)| RunWarning { code, detail })
.collect();
run_warnings.extend(user_patch_warnings.iter().cloned());
let nested_skip_warnings = if args.nested.is_some() {
user_patch_warnings
} else {
Vec::new()
};
run_warnings.extend(results.iter().filter_map(|r| {
let note = r.error.as_deref().filter(|_| r.success)?;
note.contains(socket_patch_core::patch::apply::OWNERSHIP_NOT_RESTORED_MARKER)
Expand Down Expand Up @@ -1632,8 +1645,7 @@ pub(crate) async fn run_locked(
// The mismatch overwrites, for a nested caller's envelope (the
// JSON events above are the standalone apply's copy).
let mut warnings = mismatch_overwrite_warnings(&results, args.common.dry_run);
warnings.extend(cache_warnings);
warnings.extend(nested_skip_warnings);
warnings.extend(run_warnings.iter().cloned());
let (applied, skipped) = collect_apply_outcomes(
&results,
&unmatched,
Expand Down Expand Up @@ -2151,7 +2163,7 @@ async fn apply_patches_inner(
.chain(user_patched)
.cloned()
.collect();
reconcile_local_go(&args.common, &recorded).await;
reconcile_local_go(&args.common, &recorded).await?;

if partitioned.is_empty() {
// Nothing in scope: the manifest lists no patches (or every patch was
Expand Down Expand Up @@ -2262,7 +2274,46 @@ async fn apply_patches_inner(
// the root store is the same copy the root walk found (#633).
distinct_npm_copies(&mut all_packages).await;

let mut reused_go = false;
for (purl, record) in &manifest.patches {
if is_local_go(purl, &args.common) && !is_vendored(purl) && !all_packages.contains_key(purl)
{
if let Some(result) =
socket_patch_core::patch::redirect::golang_local::reuse_go_redirect(
purl,
&args.common.cwd,
&record.files,
)
.await
{
if !result.success && args.prints_errors() {
eprintln!(
"{}",
format_patch_failure(
purl,
result.error.as_deref().unwrap_or("invalid Go redirect")
)
);
}
matched_manifest_purls.insert(purl.clone());
results.push(result);
reused_go = true;
}
}
}

if all_packages.is_empty() {
if reused_go && !args.common.dry_run {
run_warnings.extend(
socket_patch_core::vendor::go_consumer_sync::audit_warnings(
&args.common.cwd,
&go_pristine_mods,
)
.await
.into_iter()
.map(|(code, detail)| RunWarning { code, detail }),
);
}
// Vendored purls are already accounted for (synthesized Skipped/
// vendored results above); only the remainder is genuinely
// unmatched. An all-vendored manifest with an absent installed
Expand All @@ -2288,7 +2339,7 @@ async fn apply_patches_inner(
}
print_lockfile_only_note(args, &unmatched, &lockfile_only);
return Ok(ApplyOutcome {
success: unresolved.is_empty(),
success: unresolved.is_empty() && results.iter().all(|r| r.success),
results,
unmatched,
lockfile_only,
Expand All @@ -2306,7 +2357,7 @@ async fn apply_patches_inner(
args.common.strict,
args.common.allow_patch_conflicts,
);
let mut has_errors = false;
let mut has_errors = results.iter().any(|r| !r.success);

// Group release-variant PURLs by base. PyPI (`?artifact_id=`),
// RubyGems (`?platform=`), and Maven (`?classifier=&ext=`) carry
Expand Down
7 changes: 7 additions & 0 deletions crates/socket-patch-cli/src/commands/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,13 @@ async fn run_check(args: &VendorArgs) -> i32 {
// project no longer builds: vendor/modules.txt or the go.mod
// requirements out of step with the `replace` (#343, #618).
if failure.is_none() && entry.ecosystem == "golang" {
if let Some(record) = record {
failure = socket_patch_core::vendor::go_consumer_sync::verify_native_vendor(
root, key, record,
)
.await
.err();
}
if let Some((module, _)) = socket_patch_core::utils::purl::parse_golang_purl(key) {
let issues: Vec<String> = go_sync_issues
.get_or_init(|| async {
Expand Down
1 change: 1 addition & 0 deletions crates/socket-patch-cli/src/commands/vex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,7 @@ fn omission_phrase(reason: &str) -> &'static str {
"file_not_found" => "a patched file is missing",
"no_files" => "the patch record lists no files",
"vendor_hash_mismatch" => "the vendored artifact does not match the patch",
"go_vendor_content_mismatch" => "the native Go vendor tree does not contain the patch; run go mod vendor (or go work vendor for a workspace)",
"vendor_artifact_missing" => "the vendored artifact is missing",
"vendor_artifact_unreadable" => "the vendored artifact cannot be read",
"vendor_path_unsafe" => "the vendored artifact path is unsafe",
Expand Down
Loading
Loading