Skip to content

Commit f4e13b2

Browse files
committed
fix(walltime): ensure working directory is used when running the cmd
1 parent 7bae2d4 commit f4e13b2

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/run/runner/helpers/command.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ impl CommandBuilder {
5555
self.cwd = Some(dir.as_ref().to_owned());
5656
}
5757

58+
pub fn get_current_dir(&self) -> Option<&OsStr> {
59+
self.cwd.as_deref()
60+
}
61+
5862
pub fn wrap<S, I, T>(&mut self, wrapper: S, wrapper_args: I) -> &mut Self
5963
where
6064
S: AsRef<OsStr>,

src/run/runner/tests.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,35 @@ mod walltime {
254254
})
255255
.await;
256256
}
257+
258+
// Ensure that the working directory is used correctly
259+
#[rstest::rstest]
260+
#[tokio::test]
261+
async fn test_walltime_executor_in_working_dir(#[values(false, true)] enable_perf: bool) {
262+
let (system_info, run_data, _temp_dir) = create_test_setup().await;
263+
let (_permit, executor) = get_walltime_executor().await;
264+
265+
let cmd = r#"
266+
if [ "$(basename "$(pwd)")" != "within_sub_directory" ]; then
267+
echo "FAIL: Working directory is not 'within_sub_directory'"
268+
exit 1
269+
fi
270+
"#;
271+
272+
let mut config = walltime_config(cmd, enable_perf);
273+
274+
let dir = TempDir::new().unwrap();
275+
config.working_directory = Some(
276+
dir.path()
277+
.join("within_sub_directory")
278+
.to_string_lossy()
279+
.to_string(),
280+
);
281+
std::fs::create_dir_all(config.working_directory.as_ref().unwrap()).unwrap();
282+
283+
executor
284+
.run(&config, &system_info, &run_data, &None)
285+
.await
286+
.unwrap();
287+
}
257288
}

src/run/runner/wall_time/perf/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ impl PerfRunner {
156156
);
157157
let mut wrapped_builder = CommandBuilder::new("sh");
158158
wrapped_builder.args(["-c", &raw_command]);
159+
160+
// IMPORTANT: Preserve the working directory from the original command
161+
if let Some(cwd) = cmd_builder.get_current_dir() {
162+
wrapped_builder.current_dir(cwd);
163+
}
164+
159165
let cmd = wrap_with_sudo(wrapped_builder)?.build();
160166
debug!("cmd: {cmd:?}");
161167

0 commit comments

Comments
 (0)