Skip to content

Commit 2c08e4d

Browse files
branchseerclaude
andcommitted
fix(tests): strip Windows extensions before shell redaction
Move extension stripping to happen before shell path/name comparison so that "cmd.exe" becomes "cmd" before we check if it matches the shell name. Also update os_shell_path to not include .exe since the extension is already stripped. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4301d3e commit 2c08e4d

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

  • crates/vite_task_plan/tests/plan_snapshots

crates/vite_task_plan/tests/plan_snapshots/redact.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,25 @@ pub fn redact_snapshot(value: &impl Serialize, workspace_root: &str) -> serde_js
9393
}
9494
});
9595

96+
// Normalize Windows program names and paths by stripping common extensions for cross-platform consistency
97+
// This must happen BEFORE shell redaction so that "cmd.exe" becomes "cmd" before comparison
98+
visit_json(&mut json_value, &mut |v| {
99+
let serde_json::Value::Object(map) = v else {
100+
return;
101+
};
102+
// Normalize program_name field
103+
if let Some(serde_json::Value::String(program_name)) = map.get_mut("program_name") {
104+
strip_windows_executable_extension(program_name);
105+
}
106+
// Normalize program_path field
107+
if let Some(serde_json::Value::String(program_path)) = map.get_mut("program_path") {
108+
strip_windows_executable_extension(program_path);
109+
}
110+
});
111+
96112
// Redact shell program and arguments for cross-platform consistency
97-
let os_shell_path = if cfg!(windows) { "C:\\Windows\\System32\\cmd.exe" } else { "/bin/sh" };
113+
// Note: os_shell_path still includes .exe because we compare against program_path before extension stripping
114+
let os_shell_path = if cfg!(windows) { "C:\\Windows\\System32\\cmd" } else { "/bin/sh" };
98115
let os_shell_name = if cfg!(windows) { "cmd" } else { "sh" };
99116
let os_shell_args: &[&str] = if cfg!(windows) { &["/d", "/s", "/c"] } else { &["-c"] };
100117
visit_json(&mut json_value, &mut |v| {
@@ -123,21 +140,6 @@ pub fn redact_snapshot(value: &impl Serialize, workspace_root: &str) -> serde_js
123140
}
124141
});
125142

126-
// Normalize Windows program names and paths by stripping common extensions for cross-platform consistency
127-
visit_json(&mut json_value, &mut |v| {
128-
let serde_json::Value::Object(map) = v else {
129-
return;
130-
};
131-
// Normalize program_name field
132-
if let Some(serde_json::Value::String(program_name)) = map.get_mut("program_name") {
133-
strip_windows_executable_extension(program_name);
134-
}
135-
// Normalize program_path field
136-
if let Some(serde_json::Value::String(program_path)) = map.get_mut("program_path") {
137-
strip_windows_executable_extension(program_path);
138-
}
139-
});
140-
141143
visit_json(&mut json_value, &mut |v| {
142144
let serde_json::Value::Array(array) = v else {
143145
return;

0 commit comments

Comments
 (0)