Skip to content

Commit 858b57b

Browse files
branchseerclaude
andcommitted
fix: also normalize program_path for Windows in snapshots
The program_path field in spawn_command also includes the Windows executable extension (.CMD) which needs to be stripped for cross- platform snapshot consistency. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9423d40 commit 858b57b

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

  • crates/vite_task_bin/tests/test_snapshots

crates/vite_task_bin/tests/test_snapshots/redact.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ fn redact_string_in_json(value: &mut serde_json::Value, redactions: &[(&str, &st
2828
});
2929
}
3030

31+
/// Strip Windows executable extensions (case-insensitive) for cross-platform consistency
32+
fn strip_windows_executable_extension(s: &mut String) {
33+
let lower = s.to_lowercase();
34+
for ext in [".cmd", ".bat", ".exe", ".com"] {
35+
if lower.ends_with(ext) {
36+
s.truncate(s.len() - ext.len());
37+
break;
38+
}
39+
}
40+
}
41+
3142
fn redact_string(s: &mut String, redactions: &[(&str, &str)]) {
3243
use cow_utils::CowUtils as _;
3344
for (from, to) in redactions {
@@ -67,20 +78,18 @@ pub fn redact_snapshot(value: &impl Serialize, workspace_root: &str) -> serde_js
6778
&[(workspace_root, "<workspace>"), (manifest_dir.as_str(), "<manifest_dir>")],
6879
);
6980

70-
// Normalize Windows program names by stripping common extensions for cross-platform consistency
81+
// Normalize Windows program names and paths by stripping common extensions for cross-platform consistency
7182
visit_json(&mut json_value, &mut |v| {
7283
let serde_json::Value::Object(map) = v else {
7384
return;
7485
};
86+
// Normalize program_name field
7587
if let Some(serde_json::Value::String(program_name)) = map.get_mut("program_name") {
76-
// Strip Windows executable extensions (case-insensitive)
77-
let lower = program_name.to_lowercase();
78-
for ext in [".cmd", ".bat", ".exe", ".com"] {
79-
if lower.ends_with(ext) {
80-
program_name.truncate(program_name.len() - ext.len());
81-
break;
82-
}
83-
}
88+
strip_windows_executable_extension(program_name);
89+
}
90+
// Normalize program_path field
91+
if let Some(serde_json::Value::String(program_path)) = map.get_mut("program_path") {
92+
strip_windows_executable_extension(program_path);
8493
}
8594
});
8695

0 commit comments

Comments
 (0)