Skip to content

Commit 123e56f

Browse files
committed
Judge the ruby archive beside platform builds
Review follow-ups to the vendored unwind's cache dir check: - A gem whose lock names platform builds alone still has its <name>-<version>.gem judged, as the hosted restore judges it. A gem none of whose builds can be judged stays silent. - The takeover e2e leg counts the stale-cache warnings and asserts the archive was judged patched, not unchecked. - CLI_CONTRACT.md states the archive shapes once for the whole upstream_gem_stale_cache row. Refs #2174 Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeQwRPCRjnzyQ3rqcZr
1 parent a01cba6 commit 123e56f

3 files changed

Lines changed: 46 additions & 12 deletions

File tree

‎crates/socket-patch-cli/CLI_CONTRACT.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2351,7 +2351,7 @@ command's integration tests check its output.
23512351
| `hosted_resolution_orphaned` | rollback/remove `warnings[]`; list `warnings[]` (human: `Warning: …` on stderr) | yarn berry (#1203): the root `package.json` keeps a Socket-hosted `resolutions` selector that no live `yarn.lock` entry resolves and no lock descriptor matches (left behind by `yarn remove` / `yarn up`). `rollback` / `remove` removed it (the lock is untouched; an emptied `resolutions` object is dropped). uv (#1445): `pyproject.toml` (or a script's PEP 723 block) keeps a hosted `override-dependencies` pin and its `[tool.uv.sources]` URL for a transitive package the lock no longer holds (left behind by `uv remove <parent>` / `uv lock --upgrade-package <parent>`). `rollback` / `remove` removed both lines and the lock's `[manifest]` record of them (emptied tables are dropped). `list` only reports either and names the scoped `remove <purl>` that retires it alone. Never flips the exit. |
23522352
| `upstream_registry_fallback` | rollback/remove `warnings[]`; vendor advisory event (takeover) | upstream restore: a yarn berry, pnpm or vlt entry is restored from the version document of the registry the project resolves it against (yarn berry: `npmScopes` / `YARN_NPM_REGISTRY_SERVER` / `npmRegistryServer` from the `.yarnrc.yml` chain, as above, the pnpm lock's sibling `.npmrc` `registry` / `@scope:registry` or pnpm-workspace.yaml `registry` / `registries`, vlt's node registry); that registry could not be read (e.g. it needs credentials) or, for yarn berry, could not be determined (an rc value referencing an environment variable that is set, or an unset one with no default; a flow-style `npmScopes`), so the default registry's document was used and the restored tarball URL may not be the mirror's. |
23532353
| `upstream_gem_declaration_pinned` | rollback/remove `warnings[]`; vendor advisory event (takeover) | upstream restore (gem): a pin socket-patch 5.0 / 5.1 wrote as a `source "<patch registry>" do … end` block was undone. That block does not hold the declaration it replaced, so the gem came back as the exact pin `gem "<name>", "<version>"`. Reported once per manifest; the detail names each declaration and says that a version range (for example `~> 2.2`), the original quoting and the comment have to be put back by hand, followed by `bundle lock`. A pin in the `source:` option form is restored byte for byte and never warns. |
2354-
| `upstream_gem_stale_cache` | rollback/remove `warnings[]`; a vendored unwind's rollback `warnings[]`, remove / `vendor --revert` / `vendor` (manifest reconcile) advisory events and `scan --prune` `gc.warnings[]`; vendor advisory event (takeover) | upstream restore (#1260), or a wet vendored gem unwind (`remove`, `rollback`, `vendor --revert`, `scan --prune`, `vendor`'s reconcile) that puts the gem back on its upstream entry (#1594; a gem locked from a remote other than rubygems.org with no `CHECKSUMS` sha is not judged): a restored gem's `<name>-<version>.gem` is still in Bundler's cache dir (`cache_path`, default `vendor/cache`, resolved as for the Gem stale-install guard) and its sha256 is not the upstream one (the restored `CHECKSUMS` entry, else the rubygems.org compact index), or it could not be checked (`--offline`, a registry error). Bundler installs from that dir first, so a `bundle cache` taken while the hosted pin was live makes every later install fail on the upstream checksum (exit 37) or, on bundler < 2.6 frozen installs, keep installing the patched bytes. The detail names the file. Remedy: delete it, then run `bundle cache` to cache the upstream gem in its place (or `bundle install` if the project does not commit its cache; with the cache dir committed, a frozen install reads only the cache). A hosted unwind replaces the archive with the verified upstream gem when it can (the "Gem stale-install guard" section, unwind direction) and then raises nothing; from it, this warning is for an archive it left: the upstream gem could not be fetched or verified, the archive is outside the project, or `--no-gem-install-refresh` is set. A vendored unwind and a hosted → vendored takeover never replace the archive and always name it, the archive of each platform build the lock names included (`<name>-<version>-<platform>.gem`, #2174). Nothing ever deletes it. Not raised for an archive whose sha256 matches upstream. The takeover's copy adds that the vendored copy is installed instead while the gem stays vendored, and that the vendored unwind names the archive again. |
2354+
| `upstream_gem_stale_cache` | rollback/remove `warnings[]`; a vendored unwind's rollback `warnings[]`, remove / `vendor --revert` / `vendor` (manifest reconcile) advisory events and `scan --prune` `gc.warnings[]`; vendor advisory event (takeover) | upstream restore (#1260), or a wet vendored gem unwind (`remove`, `rollback`, `vendor --revert`, `scan --prune`, `vendor`'s reconcile) that puts the gem back on its upstream entry (#1594; a gem locked from a remote other than rubygems.org with no `CHECKSUMS` sha is not judged): a restored gem's `<name>-<version>.gem`, or the `<name>-<version>-<platform>.gem` of a platform build the restored lock names (one warning per archive; from a vendored unwind since #2174), is still in Bundler's cache dir (`cache_path`, default `vendor/cache`, resolved as for the Gem stale-install guard) and its sha256 is not the upstream one (the restored `CHECKSUMS` entry, else the rubygems.org compact index), or it could not be checked (`--offline`, a registry error). Bundler installs from that dir first, so a `bundle cache` taken while the hosted pin was live makes every later install fail on the upstream checksum (exit 37) or, on bundler < 2.6 frozen installs, keep installing the patched bytes. The detail names the file. Remedy: delete it, then run `bundle cache` to cache the upstream gem in its place (or `bundle install` if the project does not commit its cache; with the cache dir committed, a frozen install reads only the cache). A hosted unwind replaces the archive with the verified upstream gem when it can (the "Gem stale-install guard" section, unwind direction) and then raises nothing; from it, this warning is for an archive it left: the upstream gem could not be fetched or verified, the archive is outside the project, or `--no-gem-install-refresh` is set. A vendored unwind and a hosted → vendored takeover never replace the archive and always name it. Nothing ever deletes it. Not raised for an archive whose sha256 matches upstream. The takeover's copy adds that the vendored copy is installed instead while the gem stays vendored, and that the vendored unwind names the archive again. |
23552355
| `upstream_uv_entry_rebuilt` | rollback/remove `warnings[]`; vendor advisory event (takeover) | upstream restore: every registry package of a `uv.lock` / script lock was hosted, so no other entry showed the registry or the artifact fields uv records, and the restored entries were rebuilt from PyPI on the default index with the fields uv writes at the lock's `revision` (see "Hosted unwind coverage"). The detail names the lock, the entries, the fields and the check to run (`uv lock --check`, for a script lock `uv lock --check --script <script>`). The result is the entry `uv lock` writes for a project on PyPI's default index; a project locked against another index through a command-line flag or an environment variable the restore cannot see needs `uv lock` to put its own registry back. Never flips the exit. |
23562356
| `upstream_pnpm_tarball_setting_guessed` | rollback/remove `warnings[]`; vendor advisory event (takeover) | upstream restore (#902): nothing showed which pnpm wrote a hosted `pnpm-lock.yaml` (no unpinned registry entry that shows the setting, no `node_modules/.modules.yaml` install record, no package.json `packageManager` pin; for a Rush lock, no rush.json `pnpmVersion`), so its entries were restored with or without `tarball:` by pnpm 10's reading of `lockfileIncludeTarballUrl` (pnpm-workspace.yaml, else `.npmrc` `lockfile-include-tarball-url`), and pnpm 9 (which reads only `.npmrc`) or pnpm >= 11 (which reads only pnpm-workspace.yaml) would have read it the other way. The detail names the lock, the setting followed, the pnpm that disagrees and the entries. Remedy: pin the pnpm (package.json `packageManager`, or reinstall so the install record names it; rush.json `pnpmVersion` for Rush), or give the two files the same value so every pnpm reads it alike; a rollback or remove can then be redone by restoring the lock from version control and re-running. Not raised when evidence decided, when both files read the same on every pnpm, or when the tarball is one pnpm records regardless. |
23572357
| `yarn_berry_node_gyp_unresolved` | rollback/remove `warnings[]`; vendor advisory event (takeover) | upstream restore (#737): yarn's npm resolver gives the restored registry entry an implicit `node-gyp: "npm:latest"` dependency (the version document runs `node-gyp` in a script without declaring it), which the hosted pin dropped because yarn never gives a tarball-locator entry one, and the lock no longer has a `node-gyp@npm:latest` entry (the pin dropped the subtree only node-gyp reached). The entry is restored without it; a plain `yarn install --immutable` accepts that, a hardened or `--refresh-lockfile` install reports the lock modified. Remedy: run `yarn install` once. Not raised while another entry keeps `node-gyp@npm:latest` in the lock: the dependency is then restored too. |

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7239,10 +7239,22 @@ async fn platform_prebuilds_install_frozen_and_roll_back(
72397239
&& !stdout.contains("upstream_gem_stale_install"),
72407240
"{command}: the copy is refreshed, and nothing is left patched:\n{stdout}"
72417241
);
7242+
// Both commands report a vendored unwind's advisories as events.
7243+
let env: serde_json::Value = serde_json::from_str(&stdout)
7244+
.unwrap_or_else(|e| panic!("{command}: not JSON: {e}\nstdout:\n{stdout}"));
7245+
let named: Vec<String> = env["events"]
7246+
.as_array()
7247+
.into_iter()
7248+
.flatten()
7249+
.filter(|e| e["errorCode"] == "upstream_gem_stale_cache")
7250+
.map(|e| e.to_string())
7251+
.collect();
7252+
assert_eq!(named.len(), 1, "{command}: one stale-cache warning: {env}");
72427253
assert!(
7243-
stdout.contains("upstream_gem_stale_cache")
7244-
&& stdout.contains(&cached.display().to_string()),
7245-
"{command}: the patched platform archive in the cache dir is named:\n{stdout}"
7254+
named[0].contains(&cached.display().to_string())
7255+
&& named[0].contains("non-upstream"),
7256+
"{command}: the patched platform archive in the cache dir is named: {}",
7257+
named[0]
72467258
);
72477259
}
72487260
}

‎crates/socket-patch-core/src/patch/redirect/upstream/gem.rs‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ async fn stale_cache_warning(
11141114
/// archive, and that of each platform build the lock names (a gem vendored
11151115
/// from prebuilt platform gems is back on its platform entries, #2174),
11161116
/// against the lock's `CHECKSUMS` entry, else the rubygems.org compact
1117-
/// index (unless `offline`). A build locked from another remote with no
1117+
/// index (unless `offline`). A gem locked from another remote with no
11181118
/// `CHECKSUMS` sha can't be judged, and is most likely a private gem cached
11191119
/// on purpose: no warning.
11201120
pub(super) async fn unwound_stale_cache(
@@ -1145,15 +1145,22 @@ pub(super) async fn unwound_stale_cache(
11451145
.map(GemId::token),
11461146
);
11471147
}
1148+
// A gem none of whose builds the lock pins a sha256 for or resolves
1149+
// from rubygems.org is not judged. One that is has its ruby-platform
1150+
// archive judged too, whether or not the lock names that build: the
1151+
// hosted restore does the same, and bundler takes the archive as soon
1152+
// as the `ruby` platform is added back.
1153+
if let Some(text) = &lock {
1154+
let judged = |token: &String| {
1155+
lock_checksum(text, &name, token).is_some() || rubygems_locked(text, &name, token)
1156+
};
1157+
if !tokens.iter().any(judged) {
1158+
return Vec::new();
1159+
}
1160+
}
11481161
let client = UpstreamClient::new(offline);
11491162
let mut warnings = Vec::new();
11501163
for token in tokens {
1151-
if let Some(text) = &lock {
1152-
if lock_checksum(text, &name, &token).is_none() && !rubygems_locked(text, &name, &token)
1153-
{
1154-
continue;
1155-
}
1156-
}
11571164
warnings
11581165
.extend(stale_cache_warning(root, purl, &name, &token, lock.as_deref(), &client).await);
11591166
}
@@ -3090,7 +3097,8 @@ mod tests {
30903097
/// platform entries, and `bundle cache` keeps each build under
30913098
/// `<name>-<version>-<platform>.gem`. The patched archive of a locked
30923099
/// platform build is named; an upstream one, and the archive of a
3093-
/// build the lock does not name, are not.
3100+
/// platform build the lock does not name, are not. A ruby-platform
3101+
/// archive is judged beside them, as the hosted restore judges it.
30943102
#[tokio::test]
30953103
async fn vendored_unwind_names_a_patched_platform_archive() {
30963104
let tmp = tempfile::tempdir().unwrap();
@@ -3126,6 +3134,20 @@ mod tests {
31263134
"{hits:?}"
31273135
);
31283136
assert!(hits[0].1.contains("non-upstream"), "{hits:?}");
3137+
3138+
// The lock pins no sha256 for the ruby-platform gem, and the run is
3139+
// offline: its archive is named as unchecked, beside the platform's.
3140+
let ruby = cache.join("nokogiri-1.18.10.gem");
3141+
std::fs::write(&ruby, b"patched gem").unwrap();
3142+
let hits = unwound_stale_cache(tmp.path(), "pkg:gem/nokogiri@1.18.10", true).await;
3143+
assert_eq!(hits.len(), 2, "{hits:?}");
3144+
assert!(
3145+
hits.iter().any(|(_, detail)| {
3146+
detail.contains(&format!("{},", ruby.display()))
3147+
&& detail.contains("could not be checked")
3148+
}),
3149+
"{hits:?}"
3150+
);
31293151
}
31303152

31313153
/// #1594: an upstream archive, or none at all, is healthy.

0 commit comments

Comments
 (0)