Skip to content

Commit ec87efa

Browse files
committed
Keep inert Go member replaces as refs; recognize stale sums
Second review round on Go workspace discovery. - A Socket replace of a module that is itself a `use` member (every replace of it is inert, and the writers refuse it with `WorkspaceConflict::MainModule`, which a re-run never clears) was dropped with a diagnostic, so rollback, remove and list lost wiring still in the file. It stays a ref, marked `GoWorkspaceOverride` with the same "is inert" detail (owner decision 4). - go.sum / member sums / go.work.sum were read only when a hosted ref existed, so a sum left by a reverted patch was no longer recognized and a dead ledger claim could be re-derived from its raw text (rule 11). They are recognized either way. - The plan both attested a purl (the live go.work patch) and reported it skipped for a lockfile-only candidate whose only ref is a stale, bypassed leftover pin of another patch. That candidate is now dropped with a note when another candidate attests the purl. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1529210 commit ec87efa

2 files changed

Lines changed: 72 additions & 36 deletions

File tree

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,15 @@ pub(crate) async fn plan(
435435
// A file-scoped mark (a Go replace the workspace keeps from the build)
436436
// bypasses only its own file's ref: another file's live ref of the
437437
// same patch attests on its own basis, without the bypassed one.
438+
// Purls some candidate attests through a ref no mark bypasses: a
439+
// lockfile-only candidate left with nothing but file-scoped bypassed
440+
// refs of the same purl (a stale pin the workspace keeps from the
441+
// build) is then dropped, never both attested and reported skipped.
442+
let live_purls: Vec<String> = cands
443+
.iter()
444+
.filter(|c| c.discovered.iter().any(|r| !bypassed_ref(&discovery, r)))
445+
.map(|c| canonical_base_purl(&c.key))
446+
.collect();
438447
cands.retain_mut(|c| {
439448
let pkg = canonical_base_purl(&c.key);
440449
let marks: Vec<&Unattested> = discovery
@@ -452,6 +461,17 @@ pub(crate) async fn plan(
452461
if !c.discovered.is_empty() {
453462
return true;
454463
}
464+
if c.lockfile_only && live_purls.iter().any(|p| PurlKey::same(p, &pkg)) {
465+
notes.push(PlanNote {
466+
code: unattested_note(first.kind).0,
467+
detail: format!(
468+
"{}: patch {}'s wiring is bypassed ({}); another patch's live \
469+
wiring of the same package is attested",
470+
c.key, c.uuid, first.detail
471+
),
472+
});
473+
return false;
474+
}
455475
first
456476
}
457477
};
@@ -1897,8 +1917,10 @@ mod tests {
18971917
};
18981918
let plan = plan(&common(tmp.path()), sources, &[], &RunApiClient::new()).await;
18991919
assert_eq!(plan.hosted[PURL].uuid, U1);
1920+
// Review on #2011 (round 2): the attested purl is never also
1921+
// reported skipped for its stale, bypassed leftover pin.
19001922
assert!(
1901-
!plan.gated.iter().any(|f| f.reason == WIRING_CONFLICT),
1923+
!plan.gated.iter().any(|f| PurlKey::same(&f.purl, PURL)),
19021924
"{:?}",
19031925
plan.gated
19041926
);

‎crates/socket-patch-core/src/vex/discover/golang.rs‎

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,18 @@ async fn extract_with(ctx: &DiscoverCtx<'_>, out: &mut Discovery, governing: Gov
367367
module_graph.as_ref(),
368368
);
369369
let mut sums = SumPins::default();
370+
let sum_files = match &workspace {
371+
Some(ws) => ws.sum_files.clone(),
372+
None => vec![GO_SUM.to_string()],
373+
};
374+
if !any_hosted {
375+
// Still recognized (rule 11): a sum file's Socket identity with no
376+
// wiring left must read as dead, never fall back to raw text.
377+
for rel in &sum_files {
378+
ctx.recognize_ignored(rel).await;
379+
}
380+
}
370381
if any_hosted {
371-
let sum_files = match &workspace {
372-
Some(ws) => ws.sum_files.clone(),
373-
None => vec![GO_SUM.to_string()],
374-
};
375382
sums = SumPins::read(ctx, out, &sum_files).await;
376383
for (text, selects) in workspace.iter().flat_map(|ws| &ws.outside_sums) {
377384
sums.add(text, *selects);
@@ -725,24 +732,19 @@ fn extract_file(
725732
};
726733
// A module that is itself a `use` member is built from its directory:
727734
// every replace of it is inert, which says more than any workspace
728-
// conflict (go.work names it first too), so it is diagnosed, never a
729-
// ref, before the bypass is asked.
730-
let main_module_inert = |out: &mut Discovery, entry: &ReplaceEntry| {
731-
let Some(dir) = workspace.and_then(|ws| ws.main_module_dir(&entry.module)) else {
732-
return false;
733-
};
735+
// conflict (go.work names it first too). The writers refuse such a
736+
// replace (`WorkspaceConflict::MainModule`) and re-running scan or
737+
// vendor never clears it, so it stays a ref (list, rollback and remove
738+
// find the wiring) that is never attested, like a bypass.
739+
let main_module = |entry: &ReplaceEntry| {
740+
let dir = workspace.and_then(|ws| ws.main_module_dir(&entry.module))?;
734741
let req = required.get(&entry.module).map(String::as_str);
735742
let version = entry.version.as_deref().or(req).unwrap_or_default();
736-
out.diag(
737-
DIAG_REF_INVALID,
738-
file,
739-
format!(
740-
"{file}: replace {} {version} is inert: the build selects (the workspace \
741-
module in {dir}), so it uses the unpatched module",
742-
entry.module
743-
),
744-
);
745-
true
743+
Some(format!(
744+
"{file}: replace {} {version} is inert: the build selects (the workspace module \
745+
in {dir}), so it uses the unpatched module",
746+
entry.module
747+
))
746748
};
747749
let mark_bypassed = |out: &mut Discovery, purl: &str, uuid: &str, bypassed: Option<String>| {
748750
if let Some(detail) = bypassed {
@@ -794,10 +796,7 @@ fn extract_file(
794796
);
795797
continue;
796798
};
797-
if main_module_inert(out, entry) {
798-
continue;
799-
}
800-
let bypassed = bypass_of(entry);
799+
let bypassed = main_module(entry).or_else(|| bypass_of(entry));
801800
let Some(purl) =
802801
replaced_purl(entry, graph, &versioned, file, out, bypassed.is_some())
803802
else {
@@ -887,10 +886,7 @@ fn extract_file(
887886
);
888887
continue;
889888
};
890-
if main_module_inert(out, entry) {
891-
continue;
892-
}
893-
let bypassed = bypass_of(entry);
889+
let bypassed = main_module(entry).or_else(|| bypass_of(entry));
894890
let Some(purl) =
895891
replaced_purl(entry, graph, &versioned, file, out, bypassed.is_some())
896892
else {
@@ -1945,6 +1941,20 @@ mod tests {
19451941
}
19461942
}
19471943

1944+
/// Review on #2011 (round 2): a go.sum still holding a reverted hosted
1945+
/// patch's lines, with no hosted replace left, is still READ for its
1946+
/// identity, so a ledger claim on that patch is dead (rule 11), not
1947+
/// re-derived from the raw sum text.
1948+
#[tokio::test]
1949+
async fn a_sum_left_from_a_reverted_patch_is_recognized() {
1950+
let p = Project::new();
1951+
p.write("go.mod", BASE_GO_MOD)
1952+
.write("go.sum", go_sum_for(UUID_A, "v1.4.2-socketpatch.1"));
1953+
let out = run(&p).await;
1954+
assert_refs(&out, &[]);
1955+
assert_eq!(out.hosted_claim(PURL, UUID_A), Some(false));
1956+
}
1957+
19481958
#[tokio::test]
19491959
async fn module_missing_from_require_is_still_emitted() {
19501960
let go_mod = format!(
@@ -2746,15 +2756,19 @@ mod tests {
27462756
format!("replace {MODULE} {VERSION} => ./{}\n", vendored_rel(UUID_A)),
27472757
] {
27482758
let go_mod = format!("{BASE_GO_MOD}\n{replace}");
2759+
// Review on #2011 (round 2): the writers refuse such a replace
2760+
// and a re-run never clears it, so it stays a ref (rollback,
2761+
// remove and list find the wiring) that is never attested.
27492762
let inert = |out: &Discovery| {
2750-
assert_refs(out, &[]);
2751-
assert!(out.unattested.is_empty(), "{:?}", out.unattested);
2763+
assert_eq!(out.refs.len(), 1, "{replace}: {:?}", out.refs);
2764+
let [u] = out.unattested.as_slice() else {
2765+
panic!("{replace}: {:?}", out.unattested);
2766+
};
2767+
assert_eq!(u.kind, UnattestedKind::GoWorkspaceOverride);
27522768
assert!(
2753-
out.diagnostics.iter().any(|d| d.code == DIAG_REF_INVALID
2754-
&& d.detail.contains("is inert")
2755-
&& d.detail.contains("workspace module in bar")),
2756-
"{replace}: {:?}",
2757-
out.diagnostics
2769+
u.detail.contains("is inert") && u.detail.contains("workspace module in bar"),
2770+
"{replace}: {}",
2771+
u.detail
27582772
);
27592773
};
27602774
let p = Project::new();

0 commit comments

Comments
 (0)