Skip to content

Commit dfe7bbc

Browse files
mikolalysenkoclaude
andcommitted
fix(ci): green the test/clippy jobs broken by the sweep
Three CI-blocking fixes surfaced by the failing checks (clippy + test on all OSes + coverage + test-release): - clippy: `map_or(true, ..)` -> `is_none_or(..)` in manifest/schema.rs (clippy 1.93 `unnecessary_map_or`, denied via `-D warnings`). - rollback_dispatch_branch_golang: the sweep added a project-local go redirect rollback backend. In local mode go rolls back by dropping the `replace` redirect and leaves the module cache pristine, so it never restores cache bytes (verified: local mode reports success without touching the file; global mode genuinely restores). The dispatch test's byte-restore contract only holds on the in-place/global path — the go analog of the cargo test's `vendor/` in-place layout — so drive that one fixture in `--global` mode. - output_helpers_e2e: the sweep's severity-colour-inversion fix flipped critical->bright-red(91)/high->red(31) and updated the in-crate unit tests, but this integration file still asserted the old swapped codes. cargo test is fail-fast, so it aborted on the golang failure before ever reaching this binary in CI; surfaced via a local `--no-fail-fast` run. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6cceb9a commit dfe7bbc

3 files changed

Lines changed: 45 additions & 16 deletions

File tree

crates/socket-patch-cli/tests/ecosystem_dispatch_e2e.rs

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,22 @@ struct RollbackFixture {
428428
verify_file: PathBuf,
429429
/// Extra env vars the crawler needs (cache locations, experimental gates).
430430
envs: Vec<(String, String)>,
431-
}
432-
433-
fn run_rollback(cwd: &Path, ecosystem: &str, envs: &[(String, String)]) -> (i32, Value) {
431+
/// Run the rollback in `--global` mode. Required for ecosystems whose
432+
/// project-local backend is a *redirect* (golang): in local mode the
433+
/// patched bytes live in a project-local copy and the module cache is left
434+
/// pristine, so rollback drops the redirect rather than restoring the cache
435+
/// file in place. Byte-restore — the contract `assert_rollback_restored`
436+
/// verifies — only happens on the global/in-place path (the analog of
437+
/// cargo's `vendor/` in-place layout). Defaults to local mode.
438+
global: bool,
439+
}
440+
441+
fn run_rollback(
442+
cwd: &Path,
443+
ecosystem: &str,
444+
global: bool,
445+
envs: &[(String, String)],
446+
) -> (i32, Value) {
434447
let mut cmd = Command::new(binary());
435448
cmd.args([
436449
"rollback",
@@ -439,9 +452,11 @@ fn run_rollback(cwd: &Path, ecosystem: &str, envs: &[(String, String)]) -> (i32,
439452
"--ecosystems",
440453
ecosystem,
441454
"--silent",
442-
])
443-
.current_dir(cwd)
444-
.env_remove("SOCKET_API_TOKEN");
455+
]);
456+
if global {
457+
cmd.arg("--global");
458+
}
459+
cmd.current_dir(cwd).env_remove("SOCKET_API_TOKEN");
445460
for (k, v) in envs {
446461
cmd.env(k, v);
447462
}
@@ -455,7 +470,7 @@ fn run_rollback(cwd: &Path, ecosystem: &str, envs: &[(String, String)]) -> (i32,
455470
/// Drive a genuine rollback for `fixture` and assert it discovered the
456471
/// package, restored the file, and reported success for the exact PURL.
457472
fn assert_rollback_restored(cwd: &Path, ecosystem: &str, fixture: &RollbackFixture) {
458-
let (code, env) = run_rollback(cwd, ecosystem, &fixture.envs);
473+
let (code, env) = run_rollback(cwd, ecosystem, fixture.global, &fixture.envs);
459474
assert_eq!(
460475
code, 0,
461476
"rollback --ecosystems={ecosystem}: expected exit 0; env={env}"
@@ -524,7 +539,7 @@ fn assert_rollback_restored(cwd: &Path, ecosystem: &str, fixture: &RollbackFixtu
524539
/// file is left untouched (still PATCHED). Mirrors `assert_apply_not_dispatched`
525540
/// for the separate `find_packages_for_rollback` code path.
526541
fn assert_rollback_not_dispatched(cwd: &Path, ecosystem: &str, fixture: &RollbackFixture) {
527-
let (code, env) = run_rollback(cwd, ecosystem, &fixture.envs);
542+
let (code, env) = run_rollback(cwd, ecosystem, fixture.global, &fixture.envs);
528543
assert_eq!(
529544
code, 0,
530545
"rollback --ecosystems={ecosystem}: out-of-scope rollback should be a clean no-op (exit 0); env={env}"
@@ -575,6 +590,7 @@ fn fixture_npm(root: &Path) -> RollbackFixture {
575590
purl: purl.to_string(),
576591
verify_file,
577592
envs: vec![],
593+
global: false,
578594
}
579595
}
580596

@@ -605,6 +621,7 @@ fn fixture_pypi(root: &Path) -> RollbackFixture {
605621
purl: purl.to_string(),
606622
verify_file,
607623
envs: vec![],
624+
global: false,
608625
}
609626
}
610627

@@ -626,6 +643,7 @@ fn fixture_gem(root: &Path) -> RollbackFixture {
626643
purl: purl.to_string(),
627644
verify_file,
628645
envs: vec![],
646+
global: false,
629647
}
630648
}
631649

@@ -694,6 +712,7 @@ fn rollback_dispatch_branch_cargo() {
694712
purl: purl.to_string(),
695713
verify_file,
696714
envs: vec![],
715+
global: false,
697716
};
698717
assert_rollback_restored(root, "cargo", &fixture);
699718
}
@@ -716,6 +735,11 @@ fn rollback_dispatch_branch_golang() {
716735
purl: purl.to_string(),
717736
verify_file,
718737
envs: vec![("GOMODCACHE".to_string(), cache.display().to_string())],
738+
// Local-go rolls back by dropping the project-local `replace` redirect
739+
// and leaves the module cache pristine, so it never restores cache
740+
// bytes. Drive the global/in-place path to exercise byte-restore — the
741+
// go analog of the cargo test's `vendor/` in-place layout.
742+
global: true,
719743
};
720744
assert_rollback_restored(root, "golang", &fixture);
721745
}
@@ -750,6 +774,7 @@ fn rollback_dispatch_branch_maven() {
750774
("MAVEN_REPO_LOCAL".to_string(), repo.display().to_string()),
751775
("SOCKET_EXPERIMENTAL_MAVEN".to_string(), "1".to_string()),
752776
],
777+
global: false,
753778
};
754779
assert_rollback_restored(root, "maven", &fixture);
755780
}
@@ -778,6 +803,7 @@ fn rollback_dispatch_branch_composer() {
778803
purl: purl.to_string(),
779804
verify_file,
780805
envs: vec![],
806+
global: false,
781807
};
782808
assert_rollback_restored(root, "composer", &fixture);
783809
}
@@ -805,6 +831,7 @@ fn rollback_dispatch_branch_nuget() {
805831
purl: purl.to_string(),
806832
verify_file,
807833
envs: vec![("SOCKET_EXPERIMENTAL_NUGET".to_string(), "1".to_string())],
834+
global: false,
808835
};
809836
assert_rollback_restored(root, "nuget", &fixture);
810837
}

crates/socket-patch-cli/tests/output_helpers_e2e.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ fn format_severity_no_color_returns_input_verbatim() {
1818
}
1919

2020
#[test]
21-
fn format_severity_critical_wraps_in_red() {
22-
// Exact envelope: red open + verbatim text + reset, nothing else.
23-
assert_eq!(format_severity("critical", true), "\x1b[31mcritical\x1b[0m");
21+
fn format_severity_critical_wraps_in_bright_red() {
22+
// Exact envelope: bright-red open + verbatim text + reset, nothing else.
23+
// Critical is the most prominent colour (bright red, 91) — strictly more
24+
// prominent than high (plain red, 31).
25+
assert_eq!(format_severity("critical", true), "\x1b[91mcritical\x1b[0m");
2426
}
2527

2628
#[test]
27-
fn format_severity_high_wraps_in_bright_red() {
28-
assert_eq!(format_severity("high", true), "\x1b[91mhigh\x1b[0m");
29+
fn format_severity_high_wraps_in_red() {
30+
assert_eq!(format_severity("high", true), "\x1b[31mhigh\x1b[0m");
2931
}
3032

3133
#[test]
@@ -52,8 +54,8 @@ fn format_severity_case_insensitive() {
5254
// text must be the caller's verbatim, original-case string (production
5355
// wraps `{s}`, not the lowercased key). Exact-equality catches both a
5456
// miscoloured branch and any impl that lowercases the rendered text.
55-
assert_eq!(format_severity("CRITICAL", true), "\x1b[31mCRITICAL\x1b[0m");
56-
assert_eq!(format_severity("High", true), "\x1b[91mHigh\x1b[0m");
57+
assert_eq!(format_severity("CRITICAL", true), "\x1b[91mCRITICAL\x1b[0m");
58+
assert_eq!(format_severity("High", true), "\x1b[31mHigh\x1b[0m");
5759
assert_eq!(format_severity("MEDIUM", true), "\x1b[33mMEDIUM\x1b[0m");
5860
assert_eq!(format_severity("Low", true), "\x1b[36mLow\x1b[0m");
5961
}

crates/socket-patch-core/src/manifest/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl SetupConfig {
8383
/// on-disk `.socket/manifest.json` byte-stable regardless of which in-memory
8484
/// representation produced it.
8585
fn setup_is_absent(setup: &Option<SetupConfig>) -> bool {
86-
setup.as_ref().map_or(true, SetupConfig::is_empty)
86+
setup.as_ref().is_none_or(SetupConfig::is_empty)
8787
}
8888

8989
/// The top-level patch manifest structure.

0 commit comments

Comments
 (0)