From 241037c69bb626fea8645a31b9a9b7a13f752701 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 17:02:45 +0000 Subject: [PATCH 1/4] Start gowork-sum-file Assisted-by: Claude Code From 64f5e752e821c96f59dba0b7f877fb25ff217b65 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 18:20:55 +0000 Subject: [PATCH 2/4] Read the sum file of the work file GOWORK names go keeps a workspace's checksums in the work file's name with `.sum` appended: `go.work.sum` for `go.work`, `ci.work.sum` under `GOWORK=/repo/ci.work`. The workspace loader read `go.work.sum` beside the work file whatever the file was called, and `vex` took a workspace's sums from it. So under a `GOWORK` that names another file `vex` judged a hosted Go pin by a file go does not read and never read the one go does: a `go.work.sum` go ignores could refuse a pin go builds, and a zip line in it could stand as the pin with none in a file go reads. The crawler had its own copy of the rule, which followed go. There is one now, `go_workspace::sum_file`, and the loader, the crawler and the hosted engine's list of files read all go by it. Nothing changes for a work file named `go.work`. Fixes #2439. Assisted-by: Claude Code --- .../tests/e2e_vex_lockfile/golang.rs | 90 ++++++++++++++++++- .../src/crawlers/go_crawler.rs | 4 +- crates/socket-patch-core/src/hosted/engine.rs | 2 +- .../src/vendor/go_workspace.rs | 20 +++-- .../src/vex/discover/golang.rs | 86 ++++++++++++++++-- 5 files changed, 186 insertions(+), 16 deletions(-) diff --git a/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs b/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs index bc3ca83757..cc776ebaec 100644 --- a/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs +++ b/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs @@ -160,6 +160,11 @@ impl Fx { /// [`Self::vex`] with `--cwd ` (a workspace member, say). fn vex_in(&self, dir: &Path, extra: &[&str]) -> Run { + self.vex_with(dir, extra, None) + } + + /// [`Self::vex_in`] under `GOWORK=` when one is given. + fn vex_with(&self, dir: &Path, extra: &[&str], gowork: Option<&Path>) -> Run { let out_path = dir.join("out.vex.json"); let _ = std::fs::remove_file(&out_path); let mut args: Vec = [ @@ -176,7 +181,11 @@ impl Fx { .map(|s| s.to_string()) .collect(); args.extend(extra.iter().map(|s| s.to_string())); - let out = self.command().args(&args).output().expect("invoke vex"); + let mut cmd = self.command(); + if let Some(gowork) = gowork { + cmd.env("GOWORK", gowork); + } + let out = cmd.args(&args).output().expect("invoke vex"); let env: Value = serde_json::from_slice(&out.stdout).unwrap_or_else(|e| { panic!( "envelope JSON on stdout ({e}). stdout:\n{}\nstderr:\n{}", @@ -1091,6 +1100,85 @@ fn golang_go_work_replace_pinned_by_root_go_sum_attests() { assert_attested(&fx, &run, GO_PURL, U, "redirected", "go.work + go.sum pin"); } +/// Under a `GOWORK` that names another work file (`ci.work`) go keeps the +/// workspace's checksums in that file's name with `.sum` appended +/// (`ci.work.sum`), and neither reads nor writes a `go.work.sum` beside it +/// (#2439). `vex` judges the hosted pin by the same file, with the work +/// file in the project root and one directory above it: +/// +/// - a `go.work.sum` go cannot parse is not read, so the pin in `go.sum` +/// still attests; +/// - a `ci.work.sum` go cannot parse stops the build, so nothing attests; +/// - the zip line in `ci.work.sum` (where go writes it) is the pin; +/// - the zip line in `go.work.sum` alone pins nothing: `go.sum` holds only +/// the `/go.mod` line, which is never the basis in a workspace. +#[test] +fn golang_named_gowork_reads_its_own_sum_file() { + let m = go_socket_module(U); + let zip_line = format!("{m} {GO_SVER} {GO_H1_ZIP}\n"); + let mod_line = format!("{m} {GO_SVER}/go.mod {GO_H1_MOD}\n"); + let both = go_sum_lines(U); + let broken = "github.com/x/y v1.0.0\n"; + // (case, go.sum, go.work.sum, ci.work.sum, the skip reason or attested) + let rows: [(&str, &str, Option<&str>, Option<&str>, Option<&str>); 5] = [ + ("both lines in go.sum", &both, None, None, None), + ( + "a go.work.sum go cannot parse", + &both, + Some(broken), + None, + None, + ), + ( + "a ci.work.sum go cannot parse", + &both, + None, + Some(broken), + Some("package_not_found"), + ), + ( + "the zip line in ci.work.sum", + &mod_line, + None, + Some(&zip_line), + None, + ), + ( + "the zip line in go.work.sum", + &mod_line, + Some(&zip_line), + None, + Some("package_not_found"), + ), + ]; + for (case, go_sum, work_sum, ci_sum, omitted) in rows { + for (work, use_dir, dir) in [("ci.work", ".", ""), ("../ci.work", "./app", "../")] { + let what = format!("{case}, GOWORK={work}"); + let fx = Fx::new(); + // The project lies in a checkout at its parent, so a work file + // one directory up is inside the repository. + fx.put("../.git/HEAD", "ref: refs/heads/main\n"); + write_go_hosted(&fx, U, GoFile::GoMod); + fx.put("go.sum", go_sum); + fx.put(work, format!("go 1.21\n\nuse {use_dir}\n")); + if let Some(text) = work_sum { + fx.put(&format!("{dir}go.work.sum"), text); + } + if let Some(text) = ci_sum { + fx.put(&format!("{dir}ci.work.sum"), text); + } + fx.cache_go_mod(GO_MODULE, GO_VERSION); + write_redirect_ledger(&fx, GO_PURL, go_record(U), GO_HOSTED_EDITS); + let gowork = fx.cwd.join(work); + let run = fx.vex_with(&fx.cwd, &["--offline"], Some(&gowork)); + match omitted { + None => assert_attested(&fx, &run, GO_PURL, U, "redirected", &what), + Some(reason) => assert_omitted(&run, GO_PURL, reason, &what), + } + } + } +} + /// LIMITATION (documented, root-only discovery): a Socket replace in a /// workspace MEMBER's go.mod (e.g. `get --mode hosted --cwd tools`) is not /// read from the workspace root — vex there finds nothing (exit 2, no false diff --git a/crates/socket-patch-core/src/crawlers/go_crawler.rs b/crates/socket-patch-core/src/crawlers/go_crawler.rs index c37b225e02..9ac4b25649 100644 --- a/crates/socket-patch-core/src/crawlers/go_crawler.rs +++ b/crates/socket-patch-core/src/crawlers/go_crawler.rs @@ -369,9 +369,7 @@ async fn go_sum_scope(cwd: &Path) -> Option> { } replaces.extend(go_mod_edit::parse_replace_entries(go_mod)); } - let mut work_sum = ws.work_file.clone().into_os_string(); - work_sum.push(".sum"); - match read_sum(Path::new(&work_sum)).await { + match read_sum(&go_workspace::sum_file(&ws.work_file)).await { SumFile::Text(text) => scope.extend(zip_lines(&text)), SumFile::Absent => listed = false, SumFile::Unreadable => return None, diff --git a/crates/socket-patch-core/src/hosted/engine.rs b/crates/socket-patch-core/src/hosted/engine.rs index 524e2edf43..0b660b4bd8 100644 --- a/crates/socket-patch-core/src/hosted/engine.rs +++ b/crates/socket-patch-core/src/hosted/engine.rs @@ -1499,7 +1499,7 @@ async fn read_go_workspace( let mut touched: Vec = root.ancestors().map(|dir| dir.join("go.work")).collect(); if let Loaded::Workspace(ws) = &loaded { - touched.push(ws.work_dir().join("go.work.sum")); + touched.push(go_workspace::sum_file(&ws.work_file)); for member in &ws.members { touched.push(member.dir.join("go.mod")); touched.push(member.dir.join("go.sum")); diff --git a/crates/socket-patch-core/src/vendor/go_workspace.rs b/crates/socket-patch-core/src/vendor/go_workspace.rs index a5bdce7625..841b4fa5ae 100644 --- a/crates/socket-patch-core/src/vendor/go_workspace.rs +++ b/crates/socket-patch-core/src/vendor/go_workspace.rs @@ -186,7 +186,7 @@ pub struct GoWorkspace { pub work_file: PathBuf, /// Its text, normalized for reading. pub work: String, - /// `go.work.sum`, when readable. + /// The workspace's sum file ([`sum_file`]), when readable. pub work_sum: Option, /// The `use` members, in go.work order. pub members: Vec, @@ -258,8 +258,8 @@ pub enum Loaded { Invalid(String), } -/// Load the workspace in effect for `project_root` from disk: go.work, -/// go.work.sum, and every member's go.mod and go.sum. +/// Load the workspace in effect for `project_root` from disk: the work +/// file, its sum file ([`sum_file`]), and every member's go.mod and go.sum. pub async fn load(project_root: &Path) -> Loaded { load_with( project_root, @@ -286,6 +286,16 @@ pub async fn load_with(project_root: &Path, gowork: Option<&str>) -> Loaded { } } +/// The sum file of the workspace `work_file` governs, as go names it: the +/// work file's name with `.sum` appended. That is `go.work.sum` for a +/// `go.work`, and `ci.work.sum` under `GOWORK=/repo/ci.work`, where go +/// neither reads nor writes a `go.work.sum` beside it. +pub fn sum_file(work_file: &Path) -> PathBuf { + let mut name = work_file.as_os_str().to_os_string(); + name.push(".sum"); + PathBuf::from(name) +} + /// Read `work_file` and what it names. A `use` member outside `bound` /// reads as one without a go.mod or go.sum (missing). async fn load_file(work_file: PathBuf, bound: &crate::utils::repo_root::ReadBoundary) -> Loaded { @@ -325,9 +335,7 @@ async fn load_file(work_file: PathBuf, bound: &crate::utils::repo_root::ReadBoun go_sum, }); } - let work_sum = read_regular_to_string(&work_dir.join("go.work.sum")) - .await - .ok(); + let work_sum = read_regular_to_string(&sum_file(&work_file)).await.ok(); Loaded::Workspace(GoWorkspace { work_file, work: text, diff --git a/crates/socket-patch-core/src/vex/discover/golang.rs b/crates/socket-patch-core/src/vex/discover/golang.rs index cc249f1fcd..28547268b5 100644 --- a/crates/socket-patch-core/src/vex/discover/golang.rs +++ b/crates/socket-patch-core/src/vex/discover/golang.rs @@ -630,8 +630,8 @@ async fn read_workspace( /// The workspace go resolves for the project at `root` on disk /// ([`go_workspace::load_with`]), with every member wherever it lies. /// -/// The loader already read go.work, go.work.sum and every member's go.mod -/// and go.sum; of those, only the in-root members' go.mod is read again, +/// The loader already read the work file, its sum file and every member's +/// go.mod and go.sum; of those, only the in-root members' go.mod is read again, /// through the view: its Socket identities must be recognized (rule 11) /// and a go.mod go cannot parse diagnosed, and a member's replaces become /// refs when the root has no go.mod. The project's sum files are read @@ -665,9 +665,11 @@ async fn read_loaded_workspace( sum_files.push(sum); } } - // Sum files outside the project but inside the repository: the - // governing go.work.sum when the go.work is not the root's, and each - // out-of-root member's go.sum. Nothing outside the repository counts. + // Sum files the view's list above does not name, inside the + // repository: the governing work file's sum file when that file is not + // the root's go.work (an ancestor's go.work.sum, or `ci.work.sum` for a + // `GOWORK` naming `ci.work`, in the root or not), and each out-of-root + // member's go.sum. Nothing outside the repository counts. let repo = crate::utils::repo_root::find_git_repo(root).map_or_else(|| root.into(), |r| r.root); let repo = same_dir_key(&repo); let inside = |path: &Path| same_dir_key(path).starts_with(&repo); @@ -3041,4 +3043,78 @@ mod tests { assert_overridden(&out, Some("never this directory's go.work"), "malformed"); assert_eq!(out.refs[0].source_file, std::path::PathBuf::from("go.work")); } + + /// Under a `GOWORK` that names `ci.work` the workspace's sum file is + /// `ci.work.sum`, as for go: it decides the pin, and a `go.work.sum` + /// beside it is not read. + #[tokio::test] + async fn a_named_gowork_reads_its_own_sum_file() { + let m = gopatch(UUID_A); + let sver = "v1.4.2-socketpatch.1"; + let broken = "github.com/x/y v1.0.0\n"; + let zip_line = format!("{m} {sver} {ZIP_H1}\n"); + let mod_line = format!("{m} {sver}/go.mod {MOD_H1}\n"); + let both = go_sum_for(UUID_A, sver); + let mut wrong = Vec::new(); + // (case, go.sum, go.work.sum, ci.work.sum, pinned) + for (case, sum, work_sum, ci_sum, pinned) in [ + ("both lines in go.sum", &both, None, None, true), + ( + "a go.work.sum go cannot parse", + &both, + Some(broken), + None, + true, + ), + ( + "a ci.work.sum go cannot parse", + &both, + None, + Some(broken), + false, + ), + ( + "the zip line in ci.work.sum", + &mod_line, + None, + Some(zip_line.as_str()), + true, + ), + ( + "the zip line in go.work.sum", + &mod_line, + Some(zip_line.as_str()), + None, + false, + ), + ] { + for (work, use_dir, dir) in [("ci.work", ".", ""), ("../ci.work", "./app", "../")] { + let p = project_in_repo(); + p.write( + "go.mod", + format!("{BASE_GO_MOD}\nreplace {MODULE} {VERSION} => {m} {sver}\n"), + ) + .write("go.sum", sum) + .write(work, format!("go 1.21\n\nuse {use_dir}\n")); + if let Some(text) = work_sum { + p.write(&format!("{dir}go.work.sum"), text); + } + if let Some(text) = ci_sum { + p.write(&format!("{dir}ci.work.sum"), text); + } + let gowork = p.root().join(work).to_string_lossy().into_owned(); + let ctx = p.ctx(); + let mut out = Discovery::default(); + super::extract_gowork(&ctx, &mut out, Some(&gowork)).await; + assert_eq!(out.refs.len(), 1, "{case}, GOWORK={work}"); + let got = out.refs[0].locked_integrity.is_some(); + if got != pinned { + wrong.push(format!( + "{case}, GOWORK={work}: pinned {got}, go says {pinned}" + )); + } + } + } + assert!(wrong.is_empty(), "{wrong:#?}"); + } } From 53b6aa329ef95922b1b2e45e1b8238904dc1ee2b Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 18:32:01 +0000 Subject: [PATCH 3/4] Name every wrong row of the named-GOWORK vex test The CLI test stopped at the first row that went the wrong way. It now collects each row whose outcome (attested or not) differs from go's, and fails once with all of them; a row that goes the right way is still held to its whole shape. Against the loader that read `go.work.sum` it names eight of the ten rows. Refs #2439. Assisted-by: Claude Code --- .../tests/e2e_vex_lockfile/golang.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs b/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs index cc776ebaec..08235639de 100644 --- a/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs +++ b/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs @@ -1151,6 +1151,7 @@ fn golang_named_gowork_reads_its_own_sum_file() { Some("package_not_found"), ), ]; + let mut wrong = Vec::new(); for (case, go_sum, work_sum, ci_sum, omitted) in rows { for (work, use_dir, dir) in [("ci.work", ".", ""), ("../ci.work", "./app", "../")] { let what = format!("{case}, GOWORK={work}"); @@ -1171,12 +1172,23 @@ fn golang_named_gowork_reads_its_own_sum_file() { write_redirect_ledger(&fx, GO_PURL, go_record(U), GO_HOSTED_EDITS); let gowork = fx.cwd.join(work); let run = fx.vex_with(&fx.cwd, &["--offline"], Some(&gowork)); + // Every row that goes the wrong way is named at once; a row + // that goes the right way is then held to its whole shape. + let attested = run.code == Some(0); + if attested != omitted.is_none() { + wrong.push(format!( + "{what}: attested {attested}, go builds the pin {}", + omitted.is_none() + )); + continue; + } match omitted { None => assert_attested(&fx, &run, GO_PURL, U, "redirected", &what), Some(reason) => assert_omitted(&run, GO_PURL, reason, &what), } } } + assert!(wrong.is_empty(), "{wrong:#?}"); } /// LIMITATION (documented, root-only discovery): a Socket replace in a From 014ef719d2b35c70f25600d34e8ddc6a495e17a3 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 18:46:39 +0000 Subject: [PATCH 4/4] Take the review's wording points on the sum file - The doc of the discovery's `outside_sums` still said "the governing `go.work.sum`"; it names the work file's sum file now. - The CLI test's row for a zip line in `go.work.sum` alone said go does not build the pin. go builds: it takes what the proxy serves and records it in `ci.work.sum` (run with go 1.24.7 and a stand-in replacement module). The row's point is that no file go reads pins the zip, and the message and the doc say so. No production code changes. Refs #2439. Assisted-by: Claude Code --- .../socket-patch-cli/tests/e2e_vex_lockfile/golang.rs | 10 ++++++---- crates/socket-patch-core/src/vex/discover/golang.rs | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs b/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs index 08235639de..93cfe4bf4f 100644 --- a/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs +++ b/crates/socket-patch-cli/tests/e2e_vex_lockfile/golang.rs @@ -1109,9 +1109,11 @@ fn golang_go_work_replace_pinned_by_root_go_sum_attests() { /// - a `go.work.sum` go cannot parse is not read, so the pin in `go.sum` /// still attests; /// - a `ci.work.sum` go cannot parse stops the build, so nothing attests; -/// - the zip line in `ci.work.sum` (where go writes it) is the pin; -/// - the zip line in `go.work.sum` alone pins nothing: `go.sum` holds only -/// the `/go.mod` line, which is never the basis in a workspace. +/// - the zip line in `ci.work.sum` (where go writes it, and checks the +/// download against it) is the pin; +/// - the zip line in `go.work.sum` alone pins nothing (go builds whatever +/// the proxy serves and records it in `ci.work.sum`): `go.sum` holds +/// only the `/go.mod` line, which is never the basis in a workspace. #[test] fn golang_named_gowork_reads_its_own_sum_file() { let m = go_socket_module(U); @@ -1177,7 +1179,7 @@ fn golang_named_gowork_reads_its_own_sum_file() { let attested = run.code == Some(0); if attested != omitted.is_none() { wrong.push(format!( - "{what}: attested {attested}, go builds the pin {}", + "{what}: attested {attested}, want {}", omitted.is_none() )); continue; diff --git a/crates/socket-patch-core/src/vex/discover/golang.rs b/crates/socket-patch-core/src/vex/discover/golang.rs index 28547268b5..bcc2fc0aee 100644 --- a/crates/socket-patch-core/src/vex/discover/golang.rs +++ b/crates/socket-patch-core/src/vex/discover/golang.rs @@ -494,9 +494,10 @@ struct Workspace { /// is a member). sum_files: Vec, /// The other sum files go verifies against, as the loader read them: - /// the governing `go.work.sum` and out-of-root members' `go.sum`, when - /// they lie inside the repository. `(text, whether its zip lines show - /// the selection)`. + /// the governing work file's sum file ([`go_workspace::sum_file`]: an + /// ancestor's `go.work.sum`, or `ci.work.sum` for a `GOWORK` naming + /// `ci.work`) and out-of-root members' `go.sum`, when they lie inside + /// the repository. `(text, whether its zip lines show the selection)`. outside_sums: Vec<(String, bool)>, /// The project root the model's paths are matched against (empty in /// memory, where the model's paths are root-relative).