Skip to content
Merged
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
21 changes: 21 additions & 0 deletions .github/workflows/nokogiri-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ name: nokogiri patch compatibility
# binary, and every x86_64 Linux leg runs it, on the runner too: one build
# instead of one per leg. The macOS, Windows and ARM legs build their own.
#
# The `hosted` legs run the script's hosted scenario instead: a hosted scan
# of a lock that pins nokogiri as platform gems, against a stand-in for the
# patch service (tests/nokogiri/patch_service.rb) that serves a patched build
# of each real platform gem; then a frozen install from a fresh checkout,
# `vex` and a byte-identical `rollback`. On JRuby the platform is `java`.
#
# Every leg downloads gems from rubygems.org, and a rebuild of a precompiled
# install downloads the source gem and `mini_portile2` from it too.
#
Expand All @@ -62,6 +68,12 @@ on:
- 'crates/socket-patch-core/src/patch/gem_ext.rs'
- 'crates/socket-patch-core/src/patch/gem_source.rs'
- 'crates/socket-patch-core/src/crawlers/ruby_crawler.rs'
# Hosted mode's gem lock rewrite and restore.
- 'crates/socket-patch-core/src/formats/gem/**'
- 'crates/socket-patch-core/src/patch/redirect/mod.rs'
- 'crates/socket-patch-core/src/patch/redirect/grant.rs'
- 'crates/socket-patch-core/src/patch/redirect/upstream/gem.rs'
- 'crates/socket-patch-cli/src/commands/gem_refresh.rs'
push:
branches: [main]
paths:
Expand Down Expand Up @@ -140,6 +152,15 @@ jobs:
# A short project path: the MinGW tools stop at 260 characters,
# and a build in the stage is some 60 deeper than one in place.
- {os: windows-latest, ruby: '3.4', nokogiri: '1.18.10', install: precompiled, cli: build, args: '--work "$RUNNER_TEMP/n"'}
# Hosted mode on a lock that pins nokogiri as platform gems: the
# scan moves every platform entry to a stand-in for the patch
# registry, which serves a patched build of each real platform
# gem, and a fresh checkout installs it with the lock frozen. On
# JRuby the platform is `java`.
- {os: ubuntu-latest, ruby: '3.4', nokogiri: '1.18.10', install: precompiled, args: '--scenarios hosted', note: hosted}
- {os: ubuntu-latest, ruby: '3.1', nokogiri: '1.15.7', install: precompiled, args: '--scenarios hosted', note: hosted}
- {os: macos-latest, ruby: '3.4', nokogiri: '1.18.10', install: precompiled, cli: build, args: '--scenarios hosted', note: hosted}
- {os: ubuntu-latest, ruby: 'jruby-9.4', nokogiri: '1.18.10', install: java, args: '--scenarios hosted', note: hosted}
needs: static-cli
runs-on: ${{ vars.DISABLE_DEPOT_RUNNERS != 'true' && matrix.os == 'ubuntu-latest' && 'depot-ubuntu-24.04-4' || matrix.os }}
timeout-minutes: 60
Expand Down
18 changes: 10 additions & 8 deletions crates/socket-patch-cli/CLI_CONTRACT.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions crates/socket-patch-cli/src/commands/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ impl<'a> ProjectContext<'a> {
.await
}

/// The gems the project's Bundler lock resolves only as precompiled
/// platform builds, which [`Self::locks`] leaves out (see
/// `gem_platform_only_purls_in`): read through the same snapshot, so
/// the lock is the one the inventory saw.
pub(crate) async fn gem_platform_only_purls(&self) -> Vec<String> {
socket_patch_core::vendor::lock_inventory::gem_platform_only_purls_in(
&ProjectView::Snapshot(&self.snapshot),
)
.await
}

/// The lockfile wiring discovery of `--cwd` ([`super::discover_wiring_in`]).
pub(crate) async fn discovery(&self) -> &Discovery {
&self.recorded_discovery().await.0
Expand Down
310 changes: 212 additions & 98 deletions crates/socket-patch-cli/src/commands/gem_refresh.rs

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion crates/socket-patch-cli/src/commands/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,10 +896,14 @@ async fn filter_to_installed_purls(
// project).
let mut pnp_diags: Vec<lock_inventory::UnsupportedNpmLayout> = Vec::new();
if !common.is_global() {
let supplement = super::scan::project_lockfile_supplement(&ctx, &[], None).await;
let hosted = mode == super::scan::ScanMode::Hosted;
let supplement = super::scan::project_lockfile_supplement(&ctx, &[], None, hosted).await;
pnp_diags = supplement.unsupported;
if mode != super::scan::ScanMode::Agent {
present.extend(supplement.entries.iter().map(|e| PurlKey::new(&e.purl)));
// A hosted run's supplement also names the gems the lock
// resolves only as precompiled platform builds.
present.extend(supplement.purls.iter().cloned());
let vendored =
super::scan::project_vendored_supplement(&ctx, &[], &ctx.loaded().await.vendor)
.await;
Expand Down
54 changes: 38 additions & 16 deletions crates/socket-patch-cli/src/commands/scan/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ pub(crate) struct LockfileSupplement {
/// crawled): an entry of an ecosystem the crawl skipped is never counted
/// lockfile-only, since there is no crawl to tell whether it is installed.
/// `entries` still holds the full inventory.
///
/// `hosted`: the run is a hosted scan. The inventory leaves out a gem the
/// Bundler lock resolves only as precompiled platform builds (`nokogiri
/// (1.18.10-arm64-darwin)`: no one `.gem` stands for it, so it cannot be
/// vendored from the lock, and an in-place patch needs the installed copy).
/// Hosted mode redirects such a gem to its per-platform prebuilds from the
/// lock alone, so a hosted supplement names it too.
pub(crate) async fn lockfile_supplement(
ctx: &crate::commands::context::ProjectContext<'_>,
crawled: &[socket_patch_core::crawlers::types::CrawledPackage],
only: Option<&[String]>,
hosted: bool,
) -> LockfileSupplement {
let common = ctx.common;
let mut out = LockfileSupplement::default();
Expand All @@ -67,22 +75,32 @@ pub(crate) async fn lockfile_supplement(
let locks = ctx.locks().await;
out.unsupported = locks.unsupported.clone();
let entries = &locks.entries;
if entries.is_empty() {
let platform_gems = if hosted {
ctx.gem_platform_only_purls().await
} else {
Vec::new()
};
if entries.is_empty() && platform_gems.is_empty() {
return out;
}
(out.packages, out.purls) = lockfile_only_packages(entries, crawled, only, &common.cwd);
let resolved = entries
.iter()
.map(|entry| entry.purl.as_str())
.chain(platform_gems.iter().map(String::as_str));
(out.packages, out.purls) = lockfile_only_packages(resolved, crawled, only, &common.cwd);
out.entries = entries.clone();
out
}

/// The lockfile entries with no crawled counterpart, fabricated as crawl
/// entries, plus their [`PurlKey`]s. "Crawled" is by [`PurlKey`], the same
/// relation [`lockfile_only_contains`] answers by: a lock spelling that
/// differs from the installed crawl's only in encoding, NuGet case, PEP 503
/// form or composer padding is the installed package, not a lockfile-only
/// one — keyed in, its every spelling would read as not installed.
fn lockfile_only_packages(
entries: &[LockfileEntry],
/// The packages `resolved` (the purls the project's lockfiles resolve) with
/// no crawled counterpart, fabricated as crawl entries, plus their
/// [`PurlKey`]s. "Crawled" is by [`PurlKey`], the same relation
/// [`lockfile_only_contains`] answers by: a lock spelling that differs from
/// the installed crawl's only in encoding, NuGet case, PEP 503 form or
/// composer padding is the installed package, not a lockfile-only one —
/// keyed in, its every spelling would read as not installed.
fn lockfile_only_packages<'a>(
resolved: impl Iterator<Item = &'a str>,
crawled: &[socket_patch_core::crawlers::types::CrawledPackage],
only: Option<&[String]>,
cwd: &std::path::Path,
Expand All @@ -99,12 +117,12 @@ fn lockfile_only_packages(
.is_some_and(|eco| list.iter().any(|name| name == eco.cli_name()))
})
};
for entry in entries {
let key = PurlKey::new(&entry.purl);
if crawled_keys.contains(&key) || !in_scope(&entry.purl) {
for purl in resolved {
let key = PurlKey::new(purl);
if crawled_keys.contains(&key) || !in_scope(purl) {
continue;
}
let Some(pkg) = crawled_from_purl(&entry.purl, cwd) else {
let Some(pkg) = crawled_from_purl(purl, cwd) else {
continue;
};
purls.insert(key);
Expand Down Expand Up @@ -908,8 +926,12 @@ mod tests {
crawled_from("pkg:pypi/typing-extensions@4.12.2"),
crawled_from("pkg:composer/psr/log@3.0.2.0"),
];
let (packages, purls) =
lockfile_only_packages(&entries, &crawled, None, std::path::Path::new("/p"));
let (packages, purls) = lockfile_only_packages(
entries.iter().map(|entry| entry.purl.as_str()),
&crawled,
None,
std::path::Path::new("/p"),
);
let got: Vec<&str> = packages.iter().map(|p| p.purl.as_str()).collect();
assert_eq!(got, vec!["pkg:npm/lockonly@1.0.0"]);
assert!(lockfile_only_contains(&purls, "pkg:npm/lockonly@1.0.0"));
Expand Down
Loading
Loading