Skip to content
Open
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
15 changes: 8 additions & 7 deletions crates/socket-patch-cli/CLI_CONTRACT.md

Large diffs are not rendered by default.

57 changes: 39 additions & 18 deletions crates/socket-patch-cli/src/commands/agent_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ pub struct DownloadParams {
/// gate holds (`scan`), so the nested apply need not repeat the
/// manifest entries it skips for them. `get` checks only its selection.
pub user_patch_skips_reported: bool,
/// The caller prunes the manifest right after the nested apply
/// (`scan --prune` / `--sync`), so the apply does not ask the user to
/// prune the stale records it skips: they are about to be removed.
pub prune_follows: bool,
/// `--ecosystems` forwarded to the nested apply, so it never touches
/// other ecosystems' packages the user filtered out.
pub ecosystems: Option<Vec<String>>,
Expand Down Expand Up @@ -2036,33 +2040,30 @@ pub(crate) fn telemetry_command(env: &Envelope) -> &'static str {
/// apply (a same-process re-acquire would contend), released by apply once
/// its last mutation is done. Returns apply's report: its exit code and
/// what failed, for the caller's envelope (see [`fold_apply_failures`]).
/// Callers print their own "Applying patches..." line. `json` is the
/// caller's flag: a JSON caller gets no human error lines, from this
/// Callers print their own "Applying patches..." line. `nested` says what
/// the apply knows of its caller; its `caller_json` is the caller's
/// flag: a JSON caller gets no human error lines, from this
/// function or from the nested apply (`common` itself is never JSON). The
/// read-only `--check` redirect verifier stays off and embedded VEX is
/// opt-in on the top-level command only, never on this internal
/// invocation.
pub(crate) async fn run_nested_apply(
command: &'static str,
nested: super::apply::NestedApply,
common: GlobalArgs,
json: bool,
report_user_patch_skips: bool,
recorded: &[(String, String)],
client: &ApiClient,
lock: LockGuard,
) -> ApplyRunReport {
let json = nested.caller_json;
let report_user_patch_skips = nested.report_user_patch_skips;
let quiet = common.silent || json;
let manifest_path = common.resolved_manifest_path();
let apply_args = super::apply::ApplyArgs {
common,
force: false,
check: false,
vex: Default::default(),
nested: Some(super::apply::NestedApply {
caller_json: json,
report_user_patch_skips,
command,
}),
nested: Some(nested),
};
// The nested apply runs on the host's client: seeded, never rebuilt.
let client = crate::args::RunApiClient::new_with(Some(client.clone()));
Expand Down Expand Up @@ -2123,8 +2124,9 @@ pub(crate) fn apply_key_covers(key: &str, record: &str) -> bool {
/// leaves a `failed` event and the envelope's `partialFailure` agrees with
/// exit 1. The apply's non-fatal warnings (`content_mismatch_overwritten`,
/// #1004) join `env.warnings`: a JSON caller's nested apply is silent, so
/// the envelope is their only channel. `None` (no apply ran) records
/// nothing.
/// the envelope is their only channel, except a `patch_stale` warning for
/// a patch this run selected, which its `skipped` event already says.
/// `None` (no apply ran) records nothing.
pub(crate) fn record_apply_outcome(
env: &mut Envelope,
recorded: &[(String, String)],
Expand All @@ -2137,10 +2139,26 @@ pub(crate) fn record_apply_outcome(
// The caller may already carry the same run-level advisory (scan reports
// the gem `.bundle/config` / stale-plugin warnings from its own crawl).
let reported = env.warnings.len();
// A stale patch this run selected is recorded below as its own
// `skipped` event, reason included: the warning would say it twice.
let said_as_event = |warning: &RunWarning| {
warning.code == super::stale_patch::PATCH_STALE
&& report.skipped.iter().any(|skip| {
skip.error_code.as_deref() == Some(super::stale_patch::PATCH_STALE)
&& skip.purl.as_deref().is_some_and(|key| {
recorded.iter().any(|(purl, _)| apply_key_covers(key, purl))
&& super::stale_patch::warning_detail(
key,
skip.reason.as_deref().unwrap_or_default(),
) == warning.detail
})
})
};
for warning in &report.warnings {
if !env.warnings[..reported]
.iter()
.any(|w| w.code == warning.code && w.detail == warning.detail)
if !said_as_event(warning)
&& !env.warnings[..reported]
.iter()
.any(|w| w.code == warning.code && w.detail == warning.detail)
{
env.warnings.push(warning.clone());
}
Expand Down Expand Up @@ -2592,10 +2610,13 @@ pub async fn download_and_apply_patches_into(
apply_report = Some(
crate::ecosystem_dispatch::boxed(|| {
run_nested_apply(
command,
super::apply::NestedApply {
caller_json: params.json,
report_user_patch_skips: !params.user_patch_skips_reported,
command,
prune_follows: params.prune_follows,
},
nested_apply_args_from_params(params, run, &manifest_path),
params.json,
!params.user_patch_skips_reported,
&recorded,
run.api_client,
lock,
Expand Down
Loading
Loading