Skip to content

Commit 540f008

Browse files
committed
Merge remote-tracking branch 'origin/main' into release/v5.1.0
2 parents 600182d + e0916be commit 540f008

9 files changed

Lines changed: 570 additions & 58 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,20 @@ jobs:
218218
# shellcheck is pre-installed on ubuntu-latest.
219219
run: shellcheck --shell=sh scripts/install.sh
220220

221+
- name: Shell — retry the installer's release downloads
222+
# The three installer steps below fetch real release assets from
223+
# github.com, and install.sh's `curl -fsSL` makes one attempt, so
224+
# any release-CDN 504 failed this job (and ci-ok with it): twice on
225+
# 2026-11-09 alone. curl reads $CURL_HOME/.curlrc, so the steps
226+
# that run install.sh point CURL_HOME here and retry transient
227+
# errors (timeouts, 408/429/5xx) with exponential backoff, ~2 min
228+
# in all; a 404 or a checksum mismatch still fails at once. This
229+
# stays out of install.sh itself: install.socket.dev serves a
230+
# byte-for-byte copy of it (installer-drift.yml).
231+
run: |
232+
mkdir -p "$RUNNER_TEMP/curl-retry"
233+
printf 'retry = 7\n' > "$RUNNER_TEMP/curl-retry/.curlrc"
234+
221235
- name: Shell — run the installer end to end
222236
# shellcheck proves the script parses; this proves it installs. The
223237
# script is what install.socket.dev/patch serves and what the README
@@ -227,7 +241,7 @@ jobs:
227241
# Installs the LATEST RELEASE, not this checkout — on a version-bump PR
228242
# that is deliberately the previous version.
229243
run: |
230-
sh scripts/install.sh
244+
CURL_HOME="$RUNNER_TEMP/curl-retry" sh scripts/install.sh
231245
command -v socket-patch
232246
socket-patch --version
233247
@@ -240,6 +254,7 @@ jobs:
240254
run: |
241255
SOCKET_PATCH_BASE_URL=https://github.com/SocketDev/socket-patch/releases \
242256
SOCKET_PATCH_INSTALL_DIR="$RUNNER_TEMP/alt-origin" \
257+
CURL_HOME="$RUNNER_TEMP/curl-retry" \
243258
sh scripts/install.sh
244259
"$RUNNER_TEMP/alt-origin/socket-patch" --version
245260
@@ -257,6 +272,7 @@ jobs:
257272
echo "install.socket.dev reports latest=$latest"
258273
SOCKET_PATCH_BASE_URL=https://install.socket.dev/patch/SocketDev/socket-patch/releases \
259274
SOCKET_PATCH_INSTALL_DIR="$RUNNER_TEMP/socket-origin" \
275+
CURL_HOME="$RUNNER_TEMP/curl-retry" \
260276
sh scripts/install.sh
261277
installed=$("$RUNNER_TEMP/socket-origin/socket-patch" --version | awk '{print $NF}')
262278
if [ "$installed" != "$latest" ]; then
@@ -461,16 +477,21 @@ jobs:
461477
go-version: '1.24.13' # exact: bump deliberately (#1645)
462478
cache: false
463479

464-
- name: Restore vexctl (macOS)
480+
- name: Restore vexctl
465481
# The macOS compile below took a median 110s (max 168s) of every
466482
# macOS `test` job and is the step's only network flake source
467-
# (sum.golang.org resets). Its output depends only on the vexctl
468-
# version, the Go toolchain and the runner, so it is cached under
469-
# exactly those. Saved from main only, like the cargo cache.
483+
# (sum.golang.org resets). On Linux and Windows the release
484+
# download is the only network step, and github.com release
485+
# downloads return 504 for minutes at a time (2026-11-09 05:43 and
486+
# 06:11 UTC), longer than curl's retries wait. The binary depends
487+
# only on the vexctl version, the Go toolchain and the runner, so
488+
# it is cached under exactly those. Saved from main only, like the
489+
# cargo cache.
470490
id: vexctl-cache
471-
if: needs.release-readiness.outputs.reuse != 'true' && runner.os == 'macOS'
491+
if: needs.release-readiness.outputs.reuse != 'true'
472492
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
473-
# Capped like `Cache cargo`: a miss only means compiling vexctl.
493+
# Capped like `Cache cargo`: a miss only means fetching or
494+
# compiling vexctl.
474495
timeout-minutes: 5
475496
continue-on-error: true
476497
with:
@@ -516,8 +537,11 @@ jobs:
516537
*) asset='' ;;
517538
esac
518539
if [ -n "$asset" ]; then
519-
curl -fsSL --retry 5 --retry-all-errors --ssl-revoke-best-effort -o "$dir/$bin" \
520-
"https://github.com/openvex/vexctl/releases/download/$VEXCTL_VERSION/$asset"
540+
# A restored binary is checked against the same sha256.
541+
if [ "$CACHE_HIT" != true ] || [ ! -f "$dir/$bin" ]; then
542+
curl -fsSL --retry 5 --retry-all-errors --ssl-revoke-best-effort -o "$dir/$bin" \
543+
"https://github.com/openvex/vexctl/releases/download/$VEXCTL_VERSION/$asset"
544+
fi
521545
echo "$sha $dir/$bin" | sha256sum -c -
522546
chmod +x "$dir/$bin"
523547
"$dir/$bin" version
@@ -540,10 +564,9 @@ jobs:
540564
"$dir/vexctl" version
541565
echo "$dir" >> "$GITHUB_PATH"
542566
543-
- name: Save vexctl (macOS)
567+
- name: Save vexctl
544568
if: >-
545569
needs.release-readiness.outputs.reuse != 'true'
546-
&& runner.os == 'macOS'
547570
&& github.ref == 'refs/heads/main'
548571
&& steps.vexctl-cache.outputs.cache-hit != 'true'
549572
&& steps.vexctl-cache.outcome == 'success'
@@ -667,6 +690,8 @@ jobs:
667690
timeout-minutes: 35
668691
permissions:
669692
contents: read
693+
env:
694+
VEXCTL_VERSION: v0.3.0
670695
steps:
671696
- name: Checkout
672697
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -714,23 +739,50 @@ jobs:
714739
go-version: '1.24.13' # exact: bump deliberately (#1645)
715740
cache: false
716741

742+
- name: Restore vexctl
743+
# Cached like `test`'s vexctl so a github.com release outage
744+
# doesn't fail this required job. Saved from main by shard 1.
745+
id: vexctl-cache
746+
if: needs.release-readiness.outputs.reuse != 'true'
747+
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
748+
timeout-minutes: 5
749+
continue-on-error: true
750+
with:
751+
path: ${{ runner.temp }}/vexctl-bin
752+
key: vexctl-${{ env.VEXCTL_VERSION }}-${{ runner.os }}-${{ runner.arch }}-coverage
753+
717754
- name: Install vexctl
718755
if: needs.release-readiness.outputs.reuse != 'true'
719756
# The v0.3.0 Linux release binary, as in `test`'s vexctl step.
720757
env:
721-
VEXCTL_VERSION: v0.3.0
722758
VEXCTL_SHA256_LINUX_AMD64: cd7f8b57d20642166ed4eb3dd1fd849bbb30bbd7c5b9f5b0316b6003b57ceaba
759+
CACHE_HIT: ${{ steps.vexctl-cache.outputs.cache-hit }}
723760
run: |
724761
set -euo pipefail
725762
dir="$RUNNER_TEMP/vexctl-bin"
726763
mkdir -p "$dir"
727-
curl -fsSL --retry 5 --retry-all-errors -o "$dir/vexctl" \
728-
"https://github.com/openvex/vexctl/releases/download/$VEXCTL_VERSION/vexctl-linux-amd64"
764+
# A restored binary is checked against the same sha256.
765+
if [ "$CACHE_HIT" != true ] || [ ! -f "$dir/vexctl" ]; then
766+
curl -fsSL --retry 5 --retry-all-errors -o "$dir/vexctl" \
767+
"https://github.com/openvex/vexctl/releases/download/$VEXCTL_VERSION/vexctl-linux-amd64"
768+
fi
729769
echo "$VEXCTL_SHA256_LINUX_AMD64 $dir/vexctl" | sha256sum -c -
730770
chmod +x "$dir/vexctl"
731771
"$dir/vexctl" version
732772
echo "$dir" >> "$GITHUB_PATH"
733773
774+
- name: Save vexctl
775+
if: >-
776+
needs.release-readiness.outputs.reuse != 'true'
777+
&& github.ref == 'refs/heads/main'
778+
&& matrix.shard == 1
779+
&& steps.vexctl-cache.outputs.cache-hit != 'true'
780+
&& steps.vexctl-cache.outcome == 'success'
781+
uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
782+
with:
783+
path: ${{ runner.temp }}/vexctl-bin
784+
key: ${{ steps.vexctl-cache.outputs.cache-primary-key }}
785+
734786
- name: Run tests with coverage
735787
if: needs.release-readiness.outputs.reuse != 'true'
736788
# Two-step pattern: `--no-report` runs instrumented tests and

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ async fn run_check(args: &ApplyArgs, manifest_path: &Path) -> i32 {
403403
| GoDrift::WrongReplacePath { purl, .. }
404404
| GoDrift::ResolvedVersionMismatch { purl, .. }
405405
| GoDrift::UnprovenSelection { purl, .. }
406+
| GoDrift::UnprovenStaleSum { purl, .. }
406407
| GoDrift::ReplaceTargetOnly { purl, .. } => purl.clone(),
407408
GoDrift::OrphanReplace { module } => module.clone(),
408409
};

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,11 @@ async fn generate_vex(
10441044
{version} is ignored and the build links the unpatched module",
10451045
entry.module
10461046
),
1047+
Some(Selection::Unproven) => format!(
1048+
"nothing shows the build selects {} {version}: {}",
1049+
entry.module,
1050+
socket_patch_core::vendor::go_build_list::UNPROVEN_REASON
1051+
),
10471052
Some(Selection::Unknown)
10481053
if socket_patch_core::vendor::go_workspace::resolve(&root)
10491054
!= socket_patch_core::vendor::go_workspace::GoWork::None =>

‎crates/socket-patch-cli/tests/e2e_golang_build.rs‎

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,3 +2215,170 @@ fn goflags_modfile_keeps_the_go_mod_replace_from_the_build() {
22152215

22162216
chmod_writable(tmp.path());
22172217
}
2218+
2219+
// ── a go.sum line a downgrade left behind (#1862) ──
2220+
2221+
/// A go 1.16 consumer of the upstream at `from`, downgraded to `to` by
2222+
/// `go get`, which lowers the require but keeps `from`'s go.sum lines
2223+
/// until `go mod tidy`.
2224+
fn downgraded_consumer(consumer: &Path, from: &str, to: &str, env: &[(&str, &str)]) {
2225+
std::fs::write(
2226+
consumer.join("go.mod"),
2227+
format!("module example.com/consumer\n\ngo 1.16\n\nrequire {UMOD} {from}\n"),
2228+
)
2229+
.unwrap();
2230+
for args in [vec!["mod", "tidy"], vec!["get", &format!("{UMOD}@{to}")]] {
2231+
let out = go(consumer, &args, env);
2232+
assert!(
2233+
out.status.success(),
2234+
"go {args:?}: {}",
2235+
String::from_utf8_lossy(&out.stderr)
2236+
);
2237+
}
2238+
let go_mod = std::fs::read_to_string(consumer.join("go.mod")).unwrap();
2239+
assert!(go_mod.contains(&format!("{UMOD} {to}")), "{go_mod}");
2240+
let sum = std::fs::read_to_string(consumer.join("go.sum")).unwrap();
2241+
assert!(
2242+
sum.contains(&format!("{UMOD} {from} h1:")),
2243+
"go get must keep the stale zip line:\n{sum}"
2244+
);
2245+
}
2246+
2247+
/// Publish the upstream at `version` with a greeting of `greeting`.
2248+
fn publish_upstream(tmp: &Path, version: &str, greeting: &str) {
2249+
publish(
2250+
tmp,
2251+
UMOD,
2252+
version,
2253+
&[
2254+
("go.mod", &format!("module {UMOD}\n\ngo 1.16\n")),
2255+
(
2256+
"lib.go",
2257+
&format!(
2258+
"package upstream\n\nfunc Greeting() string {{ return \"{greeting}\" }}\n"
2259+
),
2260+
),
2261+
],
2262+
);
2263+
}
2264+
2265+
/// #1862 case 1: downgraded below the patched version, the build links
2266+
/// the older module. The stale zip line at the patched version must not
2267+
/// pass for proof it is built: apply refuses, and a replace written
2268+
/// before the downgrade fails `apply --check` (with or without the module
2269+
/// cache to read the graph from) and is left out of VEX.
2270+
#[test]
2271+
fn downgrade_below_the_patch_leaves_its_replace_unattested() {
2272+
if !golang_e2e_matrix::toolchain_ready("e2e_golang_build(downgrade-below)") {
2273+
return;
2274+
}
2275+
let tmp = tempfile::tempdir().unwrap();
2276+
let (consumer, modcache, proxy_url) = stage_with(tmp.path(), "1.16");
2277+
publish_upstream(tmp.path(), "v0.9.0", "OLDER");
2278+
let env = go_env(modcache.to_str().unwrap(), &proxy_url);
2279+
let readonly = readonly_env(&env);
2280+
let empty_cache = tmp.path().join("empty-modcache");
2281+
std::fs::create_dir_all(&empty_cache).unwrap();
2282+
2283+
// A fresh apply after the downgrade refuses and writes nothing.
2284+
downgraded_consumer(&consumer, UVER, "v0.9.0", &env);
2285+
write_patch(&consumer);
2286+
let (code, so, se) = apply_json(&consumer, &modcache);
2287+
assert_ne!(code, 0, "apply must refuse the inert replace:\n{so}\n{se}");
2288+
assert!(
2289+
so.contains(&format!("the build selects {UMOD} v0.9.0")),
2290+
"{so}\n{se}"
2291+
);
2292+
assert!(replace_lines(&consumer.join("go.mod")).is_empty());
2293+
// Applied before the downgrade: the replace is inert afterwards.
2294+
std::fs::write(
2295+
consumer.join("go.mod"),
2296+
format!("module example.com/consumer\n\ngo 1.16\n\nrequire {UMOD} {UVER}\n"),
2297+
)
2298+
.unwrap();
2299+
let tidy = go(&consumer, &["mod", "tidy"], &env);
2300+
assert!(tidy.status.success());
2301+
let (code, so, se) = apply_json(&consumer, &modcache);
2302+
assert_eq!(code, 0, "apply at the required version:\n{so}\n{se}");
2303+
assert!(go_out(&consumer, &readonly).contains("OUT: PATCHED"));
2304+
let socket_replace = replace_lines(&consumer.join("go.mod"));
2305+
assert_eq!(socket_replace.len(), 1, "{socket_replace:?}");
2306+
let get = go(&consumer, &["get", &format!("{UMOD}@v0.9.0")], &env);
2307+
assert!(
2308+
get.status.success(),
2309+
"{}",
2310+
String::from_utf8_lossy(&get.stderr)
2311+
);
2312+
// The directory replace dropped the original's go.sum lines; an
2313+
// untidied go.sum from before the apply still carries them.
2314+
let mut sum = std::fs::read_to_string(consumer.join("go.sum")).unwrap();
2315+
if !sum.contains(&format!("{UMOD} {UVER} h1:")) {
2316+
let pristine = tmp.path().join("pristine");
2317+
consumer_module(
2318+
&pristine,
2319+
"example.com/pristine",
2320+
modcache.to_str().unwrap(),
2321+
&proxy_url,
2322+
);
2323+
sum.push_str(&std::fs::read_to_string(pristine.join("go.sum")).unwrap());
2324+
std::fs::write(consumer.join("go.sum"), sum).unwrap();
2325+
}
2326+
assert_eq!(replace_lines(&consumer.join("go.mod")), socket_replace);
2327+
assert!(go_out(&consumer, &readonly).contains("OUT: OLDER"));
2328+
2329+
let (code, so, se) = check(&consumer, &modcache);
2330+
assert_eq!(
2331+
code, 1,
2332+
"apply --check must flag the inert replace:\n{so}\n{se}"
2333+
);
2334+
assert!(
2335+
format!("{so}{se}").contains("is not the version the build selects (v0.9.0)"),
2336+
"{so}\n{se}"
2337+
);
2338+
let (code, so, se) = check(&consumer, &empty_cache);
2339+
assert_eq!(code, 1, "without the cache too:\n{so}\n{se}");
2340+
assert!(
2341+
format!("{so}{se}").contains("nothing shows the build selects the patched version"),
2342+
"{so}\n{se}"
2343+
);
2344+
let r = VexRun {
2345+
offline: true,
2346+
product: Some("pkg:golang/example.com/consumer".into()),
2347+
..VexRun::default()
2348+
}
2349+
.env("GOMODCACHE", &modcache)
2350+
.env("GOFLAGS", "");
2351+
let out = run_vex(&vex_e2e_common::binary(), &consumer, &r);
2352+
assert_absent(out.doc.as_ref(), UPURL);
2353+
vex_e2e_common::assert_not_attested(&out.envelope, UPURL, "go_version_not_selected");
2354+
2355+
chmod_writable(tmp.path());
2356+
}
2357+
2358+
/// #1862 case 2: downgraded to the patched version, the build links it.
2359+
/// The stale zip line above it must not refuse the patch.
2360+
#[test]
2361+
fn downgrade_to_the_patch_applies_and_checks_in_sync() {
2362+
if !golang_e2e_matrix::toolchain_ready("e2e_golang_build(downgrade-to)") {
2363+
return;
2364+
}
2365+
let tmp = tempfile::tempdir().unwrap();
2366+
let (consumer, modcache, proxy_url) = stage_with(tmp.path(), "1.16");
2367+
publish_upstream(tmp.path(), "v1.1.0", "NEWER");
2368+
let env = go_env(modcache.to_str().unwrap(), &proxy_url);
2369+
let readonly = readonly_env(&env);
2370+
2371+
downgraded_consumer(&consumer, "v1.1.0", UVER, &env);
2372+
assert!(go_out(&consumer, &readonly).contains("OUT: PRISTINE"));
2373+
write_patch(&consumer);
2374+
let (code, so, se) = apply_json(&consumer, &modcache);
2375+
assert_eq!(
2376+
code, 0,
2377+
"apply must patch the selected version:\n{so}\n{se}"
2378+
);
2379+
assert!(go_out(&consumer, &readonly).contains("OUT: PATCHED"));
2380+
let (code, so, se) = check(&consumer, &modcache);
2381+
assert_eq!(code, 0, "apply --check:\n{so}\n{se}");
2382+
2383+
chmod_writable(tmp.path());
2384+
}

‎crates/socket-patch-core/src/hosted/engine.rs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,14 +575,23 @@ async fn read_go_workspace(
575575
}
576576
}
577577
// Module mode: whether a module-to-module replace is in effect
578-
// can turn on modules only the dependencies require (#1840).
578+
// can turn on modules only the dependencies require (#1840),
579+
// and which version the build selects on a go.sum zip line a
580+
// downgrade may have left behind (#1862).
579581
let mut module_graph = None;
580582
if loaded == Loaded::None {
581583
touched.push(root.join("go.mod"));
584+
touched.push(root.join("go.sum"));
582585
let go_mod = crate::utils::fs::read_regular_to_string(&root.join("go.mod")).await;
586+
let go_sum = crate::utils::fs::read_regular_to_string(&root.join("go.sum"))
587+
.await
588+
.ok();
583589
if let Ok(go_mod) = go_mod {
584590
let go_mod = crate::vendor::go_mod_edit::normalize_for_read(&go_mod);
585-
if crate::vendor::go_build_list::may_need_module_graph(&go_mod) {
591+
if crate::vendor::go_build_list::may_need_module_graph(
592+
&go_mod,
593+
go_sum.as_deref(),
594+
) {
586595
touched.extend(
587596
crate::vendor::go_build_list::module_graph_reads(&go_mod)
588597
.into_iter()

0 commit comments

Comments
 (0)