Skip to content

Commit fab1270

Browse files
Find the Maven artifacts a pinned rules_jvm_external hub builds in scan (#2191)
* Test a hosted scan of a tree that only Bazel builds on real Bazel `socket-patch scan` takes its Maven packages from the JVM caches of a project that has a pom.xml, a Gradle build or a Scala-tool build. A checkout whose jars only a rules_jvm_external hub fetches has none of those, so a hosted scan there knows no package and never asks the API, although `get <purl> --mode hosted` in the same directory pins the same jar in MODULE.bazel. Two flows of tests/e2e_bazel_build/maven.rs now hold that on real Bazel, so that a change which makes scan read the hub's lock has expectations to turn over: - a_hosted_scan_of_a_tree_only_bazel_builds (new): after the ruleset's pin and a build, `scan --mode hosted --yes` exits 0 with scannedPackages 0, no package and no event, sends no batch request and changes no file, and the build prints the upstream marker as before. The stand-in's API holds a patch for the victim the whole time. - a_version_bump_of_the_patched_artifact: the build stops at the stale entry and `rollback <purl>` takes it out, as before. The flow then puts the stale entry back, as the file is for a user who has not run the rollback. The same scan finds no package there either and leaves the entry at which Bazel stops, although the API also grants a patch for the release the lock now pins (1.11.0). For that the stand-in grants two patches of the victim, one per release: grant() takes the version and hands the patch back, and the caller mounts the API once with both, because a second mount does not replace the answers of the first. Measured with Bazel 9.3.2 on macOS arm64, two flows at a time: the five Maven flows pass in 21.5, 24.3, 24.9, 30.9 and 22.1 seconds, and none of the 166 requests behind a logging proxy went to a public Maven repository (from a cold repository cache: 64.0, 71.6, 34.2, 60.5 and 29.8 seconds, 208 requests). No product code changes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Find the Maven artifacts a pinned rules_jvm_external hub builds in scan `socket-patch scan` takes its Maven packages from the JVM caches of a project that has a pom.xml, a Gradle build or a Scala-tool build. In a tree that only Bazel builds it said "No packages found. Run your package manager's install first.", although `get <purl> --mode hosted` in the same directory pins that jar in MODULE.bazel: a user had to name every purl. The lock of a pinned hub (maven_install.json) names each jar that Bazel fetches, at the version it builds. What changes: - A hosted scan at the root of a Bazel workspace takes the jars that the pinned hubs fetch for packages of the project, beside the ones it finds installed (bazel::maven::hub_jars, through scan's lockfile supplement). A hub's jar is the one without a classifier of an artifact that the hub's lock has a sha256 for, does not skip, and lists under a repository (or takes from the Maven local repository); its version is the lock's. It counts in scannedPackages, and in lockfileOnlyPackages with notInstalled unless a crawl found that version installed. A patch found for it is pinned as `get` pins it: one block in MODULE.bazel. A jar whose repository has no known name is a package too: a patch found for it gets maven_bazel_artifact. - The scan takes a stale entry out of the block. When the lock of a hub moves on (a version bump, an artifact that was removed), Bazel stops at the entry of the release it held ("does not generate repository"). A scan that only pinned the new release beside it would report `applied` and leave a build that fails. So the scan restores such an entry before the rewrite, through the sweep that restores a withdrawn pin (scan/withdrawn.rs, whose messages for a withdrawn pin are the ones they were): the entry alone, under the apply lock, previewed by --dry-run, one rolledBack event with the reason maven_bazel_entry_stale, also on a scan that finds no package. An entry is stale only when every hub was read and none fetches its jar at that version; a pin of the same patch in a pom.xml stays. - `get <advisory> --mode hosted` keeps the releases that a pinned hub fetches, by the same supplement. - No jar is guessed for a hub that was not read with certainty (no lock_file, a lock or a tag that cannot be read, a maven_install of a WORKSPACE file). The run gives one warning, maven_bazel_hub_not_read, with the file, the line and the reason, and still looks up the jars of the hubs it read. With no package at all a person reads "No packages found (see the warning)." in the place of the advice to install. The warning is for a workspace that has to do with the ruleset: a call names rules_jvm_external, the WORKSPACE file calls maven_install, or a maven_install.json lies at the root. A Bazel workspace of other rulesets with a file that cannot be read scans as it did. - A bare scan covers the project directories below --cwd, and --cwd when it is a project. The root of a Bazel workspace needs no lockfile or build file of its own, so a bare hosted scan from a root above other projects scanned those and never the root, while the same scan with --json scanned the root. The root is now a project of a hosted scan when its hubs have jars, something of them was not read, or the block has a stale entry. - Every hosted scan at a Bazel root now reads the hubs, so Hubs::read reads each lock once for all the hubs that name it and at most 64 MiB of locks for one workspace (the lock past that is a doubt), and the scan walks each lock once. With a debug build, a checkout of a hundred hubs on one 12.8 MiB lock of 80,000 artifacts scans in 1.5 s with 175 MB, as one hub does (1.0 s), and twenty hubs with twenty such locks in 1.7 s with 426 MB. - No other run reads a hub for packages: a scan in vendored or agent mode, one whose --ecosystems leaves Maven out, a --global one, one of a project below the Bazel root, and every run of a project in no Bazel workspace are the runs they were. A hub's jar with a patch is a patch of the run like any other, so the scan writes for it what `get <purl> --mode hosted` writes in that checkout: beside a Gradle build the hosted Gradle pin too (settings.gradle and three files under .socket/gradle), and beside a pom.xml what the pom lane pins or says of that pom. Not in this change: `get <purl>` leaves a stale entry where it is (a hosted scan, rollback and remove take it out), hubs that other Bazel modules declare or fill are not read, and the in-memory engine reads no hub. Tests: - bazel::maven: one table of nineteen workspaces for what counts as a jar of a hub (a lock over 1 MiB among them), what is said of a hub that was not read and where nothing is said, and which entry is stale; nothing for a project below the root or without a workspace. One test for the locks: read once, and within the bound. - tests/e2e_bazel_maven_beside.rs, nine tests without a Bazel: the scan as a program and as a person, as a dry run and a second time; a root with a lockfile of its own, alone and above another project; a stale entry, with and without a patch of the new release, with no package at all, while a hub is in doubt, and beside a pom that keeps its pin; a Gradle build and a pom beside the hub, each compared with what `get <purl>` writes and says there; a pom that selects another release; each way a hub is not read; the scans that read no hub, each compared byte for byte with the same scan without the Bazel files; a root above another project; `get` by advisory. - tests/e2e_bazel_build/maven.rs: the two flows of the commit before this one, turned over. After the ruleset's pin, `scan --mode hosted --yes` reports the two jars of the lock and appends the block that `get` writes; the build prints the patched marker, a second scan writes nothing and `rollback` restores every file. After a version bump, with the stale entry in the file, the scan takes it out, pins the patch of the new release, and the build takes that jar. Measured on macOS arm64: the five Maven flows pass on Bazel 9.3.2, 8.8.2, 7.7.2 and 7.4.0 at this tree, a flow in 17 to 56 seconds, and none of the 498 requests behind a logging proxy went to a public Maven repository. With the four source files as they were, both flows fail on 9.3.2 at the count of scanned packages (0, not 2), and eight of the nine tests without a Bazel fail; the ninth holds what does not change. With the stale entries kept from the sweep alone, the version bump flow fails on 9.3.2: the scan reports `applied` and no rolledBack. Twenty single changes to the new code each fail a test; a twenty-first, the root of a bare scan taken as a discovered directory, changes nothing that a run can show, because a directory that the built-in ignores would drop has no project below it that they keep. In sixteen checkouts without a hub of the ruleset (ten without a Bazel workspace file, six in a workspace of other rulesets), fourteen scan and get commands print the same bytes, exit with the same code and write the same files as a binary of the commit before (224 runs). Over the root MODULE.bazel of 22 open-source Bazel workspaces, the 18 without a hub of the ruleset give no jar and no warning. The line budget of the Bazel group follows the code, 2486 to 2568. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * Hold a stale Bazel entry to the policy, and keep the scan's lock bound to the scan Six fixes from a review of the hub scan, each with a test that fails without it. - The socket.yml policy now holds a stale entry of the block as it holds a package of the run. A scan of a root that `patches.ignorePaths` filters took the entry out of that root's MODULE.bazel, and so did a scan whose policy ignores the package: the sweep got the stale pins whatever the policy said. They are filtered first (`ScanPolicy::admits_restore`). - A scan with no package at all ran the sweep and never looked at a restore that left a file half written; it went on to "No packages found" and exit 0, where the same failure on the path with packages stops the run with `lockfile_write_failed` and exit 1. Both paths now share that stop (`stop_half_restored`). - A pin that is stale and whose patch is withdrawn too was handed to the restore twice and reported as two `rolledBack` events. It is taken once, as the withdrawn pin, with every file that holds it. - The bound of 64 MiB of hub locks for one workspace was added for the scan, which now reads the hubs on every hosted run at a Bazel root, but it sat in `Hubs::read` and so also changed `get`, `list`, `vex`, `rollback` and the notices: in a workspace with more locks than that, a `get <purl>` that pinned before declined with `maven_bazel_unreadable`. The bound is the scan's alone now; every other reader takes each lock up to 16 MiB as before. - Past the bound each further lock was still read from disk and then dropped. Now the first lock that does not fit is the last one read. - `get <advisory> --mode hosted` named a Maven hub that was not read for an advisory with no Maven artifact at all. The warning is given only when the advisory has a patch of a Maven artifact. Also held by a test and said in the docs, with no change in behaviour: when a stale entry goes beside a Gradle build, the hosted Gradle pin that the first scan wrote for the same patch stays, as a pin in a pom.xml does. `list` shows it, `rollback <purl>` takes it out, and while it stays the Gradle lane declines a patch of another release of the artifact. The line budget of the Bazel group follows the code, 2568 to 2583. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 8ffea64 commit fab1270

12 files changed

Lines changed: 1621 additions & 146 deletions

File tree

‎.github/workflows/bazel-maven.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ name: Bazel patch compatibility (Maven)
66
# patch is one block in MODULE.bazel that puts a repository with the
77
# patched jar in the place of the hub's own (`override_repo`): the flows
88
# hold the block's text, the patched build and its sha256 check, the undo,
9-
# a version bump of the patched artifact, and a hub the block cannot
10-
# patch. bazel-compatibility.yml holds the legs and what every ecosystem
9+
# a hosted scan that finds the artifact in the hub's lock, a version bump
10+
# of the patched artifact, and a hub the block cannot patch.
11+
# bazel-compatibility.yml holds the legs and what every ecosystem
1112
# shares; this file says when the Maven legs run and on which releases.
1213
#
1314
# Each major release has an era of its own, because the ruleset decides

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

Lines changed: 7 additions & 5 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,11 @@ async fn filter_to_installed_purls(
10621062
let hosted = mode == super::scan::ScanMode::Hosted;
10631063
let supplement = super::scan::project_lockfile_supplement(&ctx, &[], None, hosted).await;
10641064
pnp_diags = supplement.unsupported;
1065+
// What was not read of a Bazel workspace's Maven hubs says nothing
1066+
// of patches that are for no Maven artifact.
1067+
let maven = accessible.iter().any(|p| p.purl.starts_with("pkg:maven/"));
1068+
let hub = socket_patch_core::bazel::maven::HUB_NOT_READ;
1069+
pnp_diags.retain(|diag| maven || diag.code != hub);
10651070
if mode != super::scan::ScanMode::Agent {
10661071
present.extend(supplement.entries.iter().map(|e| PurlKey::new(&e.purl)));
10671072
// A hosted run's supplement also names the gems the lock

‎crates/socket-patch-cli/src/commands/scan/discovery.rs‎

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ use socket_patch_core::api::ranking::{batch_supersedes, cmp_batch_infos, severit
99
use socket_patch_core::api::types::{
1010
BatchPackagePatches, BatchPatchInfo, PatchResponse, PatchSearchResult,
1111
};
12+
use socket_patch_core::bazel::maven::HubJars;
13+
use socket_patch_core::crawlers::Ecosystem;
1214
use socket_patch_core::manifest::schema::{PatchManifest, PatchRecord};
15+
use socket_patch_core::patch::redirect::upstream::HostedPin;
1316
use socket_patch_core::utils::concurrent::{api_concurrency_for, ordered_concurrent};
1417
use socket_patch_core::utils::purl::{normalize_purl, strip_purl_qualifiers};
1518
use socket_patch_core::utils::purl_key::PurlKey;
16-
use socket_patch_core::vendor::lock_inventory::LockfileEntry;
19+
use socket_patch_core::vendor::lock_inventory::{LockfileEntry, UnsupportedNpmLayout};
1720
use socket_patch_core::vendor::VendorState;
1821
use std::collections::{BTreeSet, HashMap, HashSet};
1922

@@ -48,7 +51,14 @@ pub(crate) struct LockfileSupplement {
4851
/// npm layouts the lockfile inventory REFUSED (Plug'n'Play loaders).
4952
/// Scan surfaces these as refusal warnings: under PnP the installed-tree
5053
/// crawl is empty too, so otherwise the project scans as a silent no-op.
51-
pub(crate) unsupported: Vec<socket_patch_core::vendor::lock_inventory::UnsupportedNpmLayout>,
54+
/// Also what a hosted run did not read of the hubs of a Bazel workspace
55+
/// ([`hub_jars`]).
56+
pub(crate) unsupported: Vec<UnsupportedNpmLayout>,
57+
/// The entries of the block in `MODULE.bazel` whose jar no hub of the
58+
/// Bazel workspace fetches any more ([`hub_jars`]), as hosted pins of
59+
/// that file alone: Bazel stops at each, so a hosted scan takes them
60+
/// out (`withdrawn::sweep`).
61+
pub(crate) stale_hub_pins: Vec<HostedPin>,
5262
}
5363

5464
/// Inventory the project's lockfile(s) and fabricate crawl entries for
@@ -68,7 +78,8 @@ pub(crate) struct LockfileSupplement {
6878
/// (1.18.10-arm64-darwin)`: no one `.gem` stands for it, so it cannot be
6979
/// vendored from the lock, and an in-place patch needs the installed copy).
7080
/// Hosted mode redirects such a gem to its per-platform prebuilds from the
71-
/// lock alone, so a hosted supplement names it too.
81+
/// lock alone, so a hosted supplement names it too. It also names the jars
82+
/// of [`hub_jars`], and what was not read of the hubs joins `unsupported`.
7283
pub(crate) async fn lockfile_supplement(
7384
ctx: &crate::commands::context::ProjectContext<'_>,
7485
crawled: &[socket_patch_core::crawlers::types::CrawledPackage],
@@ -84,21 +95,49 @@ pub(crate) async fn lockfile_supplement(
8495
out.unsupported = locks.unsupported.clone();
8596
let entries = &locks.entries;
8697
let platform_gems = ctx.gem_platform_only_purls().await;
87-
if entries.is_empty() && platform_gems.is_empty() {
98+
let HubJars {
99+
jars,
100+
unread,
101+
stale,
102+
} = hub_jars(common, hosted).await;
103+
out.unsupported
104+
.extend(unread.map(|(code, detail)| UnsupportedNpmLayout { code, detail }));
105+
let files = vec![socket_patch_core::bazel::maven::FILE.to_string()];
106+
let pin = |(purl, uuid)| HostedPin {
107+
purl,
108+
uuid,
109+
files: files.clone(),
110+
};
111+
out.stale_hub_pins = stale.into_iter().map(pin).collect();
112+
if entries.is_empty() && platform_gems.is_empty() && jars.is_empty() {
88113
return out;
89114
}
90115
// Only a hosted supplement names a platform-only gem that has no
91116
// installed copy (see above).
92117
let resolved = entries
93118
.iter()
94119
.map(|entry| entry.purl.as_str())
95-
.chain(platform_gems.iter().filter(|_| hosted).map(String::as_str));
120+
.chain(platform_gems.iter().filter(|_| hosted).map(String::as_str))
121+
.chain(jars.iter().map(String::as_str));
96122
(out.packages, out.purls) = lockfile_only_packages(resolved, crawled, only, &common.cwd);
97123
out.entries = entries.clone();
98124
out.platform_gems = platform_gems;
99125
out
100126
}
101127

128+
/// The purls of the jars that the pinned rules_jvm_external hubs of a Bazel
129+
/// workspace fetch when `--cwd` is its root, what was not read of its hubs
130+
/// and the entries of its block that are stale
131+
/// ([`socket_patch_core::bazel::maven::hub_jars`]). Only for a hosted run
132+
/// with Maven in scope: no other mode patches a hub. The callers are runs
133+
/// of a project, never of the global installs.
134+
pub(crate) async fn hub_jars(common: &GlobalArgs, hosted: bool) -> HubJars {
135+
if !hosted || !common.ecosystem_selected(Ecosystem::Maven) {
136+
return HubJars::default();
137+
}
138+
socket_patch_core::bazel::maven::hub_jars(&common.cwd).await
139+
}
140+
102141
/// The packages `resolved` (the purls the project's lockfiles resolve) with
103142
/// no crawled counterpart, fabricated as crawl entries, plus their
104143
/// [`PurlKey`]s. "Crawled" is by [`PurlKey`], the same relation

‎crates/socket-patch-cli/src/commands/scan/mod.rs‎

Lines changed: 87 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,38 @@ fn emit_scan_error(common: &GlobalArgs, error: EnvelopeError) {
16301630
emit_scan(&env);
16311631
}
16321632

1633+
/// A restore of `sweep` that failed part-way and could not put its files
1634+
/// back leaves the lockfiles half restored: the run stops there with exit
1635+
/// 1 (`Err`), rather than write over them. The restore printed the
1636+
/// failure as it happened; `counts` are the scanned and the lockfile-only
1637+
/// packages of the envelope, and the last argument is what the failed
1638+
/// scan's telemetry takes. Otherwise `sweep` goes on.
1639+
async fn stop_half_restored(
1640+
common: &GlobalArgs,
1641+
sweep: Option<withdrawn::WithdrawnSweep>,
1642+
counts: (usize, usize),
1643+
paths: &crate::path_scope::PathScope,
1644+
(fallback_to_proxy, mode, auth): (bool, &str, &TelemetryAuth),
1645+
) -> Result<Option<withdrawn::WithdrawnSweep>, i32> {
1646+
let half = |sweep: &withdrawn::WithdrawnSweep| sweep.half_restored().map(str::to_string);
1647+
let Some(why) = sweep.as_ref().and_then(half) else {
1648+
return Ok(sweep);
1649+
};
1650+
track_patch_scan_failed("lockfile_write_failed", &why, fallback_to_proxy, mode, auth).await;
1651+
if common.json {
1652+
let mut env = scan_envelope(common);
1653+
env.set_extra("scannedPackages", serde_json::json!(counts.0));
1654+
env.set_extra("lockfileOnlyPackages", serde_json::json!(counts.1));
1655+
env.set_extra("paths", serde_json::json!(paths.raw()));
1656+
if let Some(sweep) = sweep {
1657+
sweep.record_into(&mut env);
1658+
}
1659+
env.mark_error(EnvelopeError::new("lockfile_write_failed", why));
1660+
emit_scan(&env);
1661+
}
1662+
Err(1)
1663+
}
1664+
16331665
/// `(purl, n)` pairs summed per ecosystem, by CLI name: how many packages
16341666
/// (or patches) of each ecosystem a scan found. An ecosystem with nothing
16351667
/// has no entry; a purl of no known ecosystem is not counted.
@@ -2292,11 +2324,23 @@ async fn scan_project(
22922324
if args.common.json || args.vex.vex.is_some() {
22932325
unscanned_projects = Some(others);
22942326
} else {
2327+
// The root of a Bazel workspace can be without a file
2328+
// that makes `--cwd` a project, and a hosted scan has work
2329+
// there all the same: the jars that its pinned
2330+
// rules_jvm_external hubs fetch, a hub to name as not
2331+
// read, or a stale entry of the block to take out.
2332+
let mut dirs = found.dirs;
2333+
if !dirs.iter().any(|(_, explicit)| *explicit) {
2334+
let hosted = args.mode == Some(ScanMode::Hosted);
2335+
if discovery::hub_jars(&args.common, hosted).await != Default::default() {
2336+
dirs.insert(0, (args.common.cwd.clone(), true));
2337+
}
2338+
}
22952339
return Box::pin(run_project_dirs(
22962340
args,
22972341
invocation,
22982342
mode_inferred,
2299-
found.dirs,
2343+
dirs,
23002344
report,
23012345
))
23022346
.await;
@@ -2937,6 +2981,14 @@ async fn scan_project(
29372981

29382982
let all_purls: Vec<String> = filtered_crawled.iter().map(|p| p.purl.clone()).collect();
29392983
let package_count = all_purls.len();
2984+
// The stale entries of a Bazel workspace's block that this run may
2985+
// take out: the policy holds them as it holds the run's packages.
2986+
let stale_hub_pins: Vec<_> = lockfile_only
2987+
.stale_hub_pins
2988+
.iter()
2989+
.filter(|pin| policy.admits_restore(&pin.purl))
2990+
.cloned()
2991+
.collect();
29402992

29412993
if package_count == 0 {
29422994
// An empty crawl is where the projects below matter most: they
@@ -2968,6 +3020,21 @@ async fn scan_project(
29683020
);
29693021
}
29703022
status.finish();
3023+
// Bazel stops at an entry of the block whose jar no hub fetches
3024+
// any more, whatever the project holds: such an entry is taken
3025+
// out here too (`withdrawn::sweep`, which asks nothing for it).
3026+
let stale_sweep = if hosted && policy.writes_allowed() {
3027+
Some(withdrawn::sweep(&args.common, &api_client, &[], &stale_hub_pins).await)
3028+
} else {
3029+
None
3030+
};
3031+
let telemetry = (false, requested_mode, &telemetry_auth);
3032+
let stopped =
3033+
stop_half_restored(&args.common, stale_sweep, (0, 0), &path_scope, telemetry).await;
3034+
let stale_sweep = match stopped {
3035+
Ok(sweep) => sweep,
3036+
Err(code) => return code,
3037+
};
29713038
if human {
29723039
print_layout_refusals(&layout_refusals, &project_patch_notice, args.common.silent);
29733040
policy.print_warnings(args.common.silent);
@@ -3034,6 +3101,9 @@ async fn scan_project(
30343101
if prune {
30353102
env.warnings.push(hosted::prune_ignored_warning());
30363103
}
3104+
if let Some(sweep) = stale_sweep {
3105+
sweep.record_into(&mut env);
3106+
}
30373107
env.set_extra("redirect", hosted::redirect_block(Vec::new()));
30383108
} else if !vendor {
30393109
// `redirectState` rides the empty-discovery envelope too
@@ -3413,43 +3483,26 @@ async fn scan_project(
34133483
// longer serves, before the rewrite below re-pins any replacement.
34143484
// Runs ahead of every "nothing found" exit: a package whose only patch
34153485
// was withdrawn has no search results at all.
3416-
let mut withdrawn_sweep = if hosted && !args.common.is_global() && policy.writes_allowed() {
3486+
let withdrawn_sweep = if hosted && !args.common.is_global() && policy.writes_allowed() {
34173487
let pins = withdrawn::pins_in_scope(&hosted_pin_list, &all_purls);
3418-
Some(withdrawn::sweep(&args.common, &api_client, &pins).await)
3488+
Some(withdrawn::sweep(&args.common, &api_client, &pins, &stale_hub_pins).await)
34193489
} else {
34203490
None
34213491
};
3422-
// A restore that failed part-way and could not put its files back
3423-
// leaves the lockfiles half restored: stop, rather than rewrite over
3424-
// them. (The restore printed the failure as it happened.)
3425-
if let Some(why) = withdrawn_sweep
3426-
.as_ref()
3427-
.and_then(|sweep| sweep.half_restored().map(str::to_string))
3428-
{
3429-
track_patch_scan_failed(
3430-
"lockfile_write_failed",
3431-
&why,
3432-
fallback_to_proxy,
3433-
requested_mode,
3434-
&telemetry_auth,
3435-
)
3436-
.await;
3437-
if args.common.json {
3438-
let mut env = scan_envelope(&args.common);
3439-
env.set_extra("scannedPackages", serde_json::json!(package_count));
3440-
env.set_extra(
3441-
"lockfileOnlyPackages",
3442-
serde_json::json!(lockfile_only_count),
3443-
);
3444-
env.set_extra("paths", serde_json::json!(path_scope.raw()));
3445-
if let Some(sweep) = withdrawn_sweep {
3446-
sweep.record_into(&mut env);
3447-
}
3448-
env.mark_error(EnvelopeError::new("lockfile_write_failed", why));
3449-
emit_scan(&env);
3450-
}
3451-
return 1;
3452-
}
3492+
let counts = (package_count, lockfile_only_count);
3493+
let telemetry = (fallback_to_proxy, requested_mode, &telemetry_auth);
3494+
let stopped = stop_half_restored(
3495+
&args.common,
3496+
withdrawn_sweep,
3497+
counts,
3498+
&path_scope,
3499+
telemetry,
3500+
)
3501+
.await;
3502+
let mut withdrawn_sweep = match stopped {
3503+
Ok(sweep) => sweep,
3504+
Err(code) => return code,
3505+
};
34533506
// The sweep's reference answers, reused by the hosted redirect.
34543507
let sweep_references = withdrawn_sweep
34553508
.as_mut()

‎crates/socket-patch-cli/src/commands/scan/policy.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,14 @@ impl ScanPolicy {
472472
self.policy.enabled()
473473
}
474474

475+
/// Whether the run may take out a pin of `purl` that none of its
476+
/// packages stands for (a stale entry of a Bazel workspace's block):
477+
/// not in a root the policy filtered, and not for a package it
478+
/// filters, as for a pin of a package the run covers.
479+
pub(crate) fn admits_restore(&self, purl: &str) -> bool {
480+
self.root_verdict.is_ok() && self.policy.admits_purl(purl).is_ok()
481+
}
482+
475483
/// Set the merged recorded view (manifest > hosted pins > vendor ledger).
476484
pub(crate) fn set_recorded(&mut self, merged: Option<&PatchManifest>) {
477485
self.recorded = merged

0 commit comments

Comments
 (0)