Skip to content
Merged
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
19 changes: 10 additions & 9 deletions crates/webcodex-runner/src/main_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::webcodex_runner::shell::ShellExecutionContext;
#[test]
fn check_config_is_a_separate_non_runtime_action() {
assert_eq!(
Expand Down Expand Up @@ -78,7 +79,7 @@ use crate::webcodex_runner::transport::registration::*;
use crate::webcodex_runner::config::validate_shell_config;
use crate::webcodex_runner::job_manager::job_manager_tests::{shell_job_request, ws_sink};
use crate::webcodex_runner::projects::{project_root_fingerprint, RunnerProjectFile};
use crate::webcodex_runner::run_shell_with_profiles;

use crate::webcodex_runner::{
handle_prepare_managed_worktree, handle_project_lifecycle_op, handle_project_op,
handle_resolve_or_register_project,
Expand Down Expand Up @@ -415,18 +416,18 @@ fn run_profile_shell(
command: &str,
) -> CommandResult {
let cwd = cwd.to_string_lossy().to_string();
run_shell_with_profiles(
1,
(ShellExecutionContext {
generation: 1,
policy,
shell,
project_registry_dir,
cache,
Some(&cwd),
command,
None,
10,
None,
)
cwd: Some(&cwd),
timeout_secs: 10,
stop_requested: None,
})
.run_shell(command, None, false, None)
.result
}

fn line_edit_json(result: CommandResult) -> serde_json::Value {
Expand Down
73 changes: 37 additions & 36 deletions crates/webcodex-runner/src/main_tests/profile_process_lifecycle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use crate::webcodex_runner::shell::ShellExecutionContext;

#[cfg(unix)]
#[test]
Expand Down Expand Up @@ -33,18 +34,18 @@ fn shell_job_profile_prepare_stop_reaps_whole_tree() {
written
});

let result = run_shell_with_profiles(
1,
&policy,
&shell,
tmp.path(),
&cache,
Some(&cwd),
"true",
None,
10,
Some(stop_requested.as_ref()),
);
let result = (ShellExecutionContext {
generation: 1,
policy: &policy,
shell: &shell,
project_registry_dir: tmp.path(),
cache: &cache,
cwd: Some(&cwd),
timeout_secs: 10,
stop_requested: Some(stop_requested.as_ref()),
})
.run_shell("true", None, false, None)
.result;

assert!(stopper.join().expect("stopper thread panicked"));
assert!(
Expand Down Expand Up @@ -90,18 +91,18 @@ fn shell_profile_prepare_timeout_cleans_up_whole_tree() {
)],
);
let start = Instant::now();
let result = run_shell_with_profiles(
1,
&unrestricted_test_policy(),
&shell,
tmp.path(),
&PreparedShellProfileCache::default(),
Some(tmp.path().to_string_lossy().as_ref()),
"true",
None,
10,
None,
);
let result = (ShellExecutionContext {
generation: 1,
policy: &unrestricted_test_policy(),
shell: &shell,
project_registry_dir: tmp.path(),
cache: &PreparedShellProfileCache::default(),
cwd: Some(tmp.path().to_string_lossy().as_ref()),
timeout_secs: 10,
stop_requested: None,
})
.run_shell("true", None, false, None)
.result;
assert!(
wait_until_file(&markers.parent, Duration::from_secs(15)),
"prepare tree markers were never written: {result:?}"
Expand Down Expand Up @@ -158,18 +159,18 @@ fn shell_profile_prepare_stop_cleans_up_whole_tree() {
written
});

let result = run_shell_with_profiles(
1,
&unrestricted_test_policy(),
&shell,
tmp.path(),
&PreparedShellProfileCache::default(),
Some(tmp.path().to_string_lossy().as_ref()),
"true",
None,
10,
Some(stop_requested.as_ref()),
);
let result = (ShellExecutionContext {
generation: 1,
policy: &unrestricted_test_policy(),
shell: &shell,
project_registry_dir: tmp.path(),
cache: &PreparedShellProfileCache::default(),
cwd: Some(tmp.path().to_string_lossy().as_ref()),
timeout_secs: 10,
stop_requested: Some(stop_requested.as_ref()),
})
.run_shell("true", None, false, None)
.result;

assert!(stopper.join().expect("stopper thread panicked"));
assert!(
Expand Down
24 changes: 12 additions & 12 deletions crates/webcodex-runner/src/main_tests/shell_job_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,18 @@ fn runner_real_process_shell_job_timeout_profile_reaps_descendant_process_group(

// Exercise the production request path directly rather than the
// test-only `run_shell` wrapper.
let result = run_shell_with_profiles(
1,
&policy,
&shell,
tmp.path(),
&cache,
Some(&cwd),
&long_lived_descendant_command(&pid_file),
None,
1,
None,
);
let result = (ShellExecutionContext {
generation: 1,
policy: &policy,
shell: &shell,
project_registry_dir: tmp.path(),
cache: &cache,
cwd: Some(&cwd),
timeout_secs: 1,
stop_requested: None,
})
.run_shell(&long_lived_descendant_command(&pid_file), None, false, None)
.result;

assert_eq!(cache.len(), 1, "prepared profile path was not used");
assert_eq!(result.exit_code, Some(-1), "{result:?}");
Expand Down
97 changes: 49 additions & 48 deletions crates/webcodex-runner/src/main_tests/shell_profiles.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use crate::webcodex_runner::shell::ShellExecutionContext;

#[test]
fn prepared_profile_env_is_available_to_run_shell() {
Expand Down Expand Up @@ -295,50 +296,50 @@ fn prepared_profile_init_script_runs_once_per_project_profile_generation() {
}
assert_eq!(std::fs::read_to_string(&counter).unwrap().trim(), "1");
let cwd = tmp.path().to_string_lossy().to_string();
let result = run_shell_with_profiles(
2,
&unrestricted_test_policy(),
&shell,
tmp.path(),
&cache,
Some(&cwd),
&shell_env_var("WEBCODEX_TEST_PROFILE"),
None,
10,
None,
);
let result = (ShellExecutionContext {
generation: 2,
policy: &unrestricted_test_policy(),
shell: &shell,
project_registry_dir: tmp.path(),
cache: &cache,
cwd: Some(&cwd),
timeout_secs: 10,
stop_requested: None,
})
.run_shell(&shell_env_var("WEBCODEX_TEST_PROFILE"), None, false, None)
.result;
assert_eq!(result.stdout.as_deref(), Some("counted"));
assert_eq!(std::fs::read_to_string(&counter).unwrap().trim(), "2");

// A late request that still holds generation 1 may prepare its own
// snapshot, but it must not evict the already-cached active generation.
let stale = run_shell_with_profiles(
1,
&unrestricted_test_policy(),
&shell,
tmp.path(),
&cache,
Some(&cwd),
&shell_env_var("WEBCODEX_TEST_PROFILE"),
None,
10,
None,
);
let stale = (ShellExecutionContext {
generation: 1,
policy: &unrestricted_test_policy(),
shell: &shell,
project_registry_dir: tmp.path(),
cache: &cache,
cwd: Some(&cwd),
timeout_secs: 10,
stop_requested: None,
})
.run_shell(&shell_env_var("WEBCODEX_TEST_PROFILE"), None, false, None)
.result;
assert_eq!(stale.stdout.as_deref(), Some("counted"));
assert_eq!(std::fs::read_to_string(&counter).unwrap().trim(), "3");

let current = run_shell_with_profiles(
2,
&unrestricted_test_policy(),
&shell,
tmp.path(),
&cache,
Some(&cwd),
&shell_env_var("WEBCODEX_TEST_PROFILE"),
None,
10,
None,
);
let current = (ShellExecutionContext {
generation: 2,
policy: &unrestricted_test_policy(),
shell: &shell,
project_registry_dir: tmp.path(),
cache: &cache,
cwd: Some(&cwd),
timeout_secs: 10,
stop_requested: None,
})
.run_shell(&shell_env_var("WEBCODEX_TEST_PROFILE"), None, false, None)
.result;
assert_eq!(current.stdout.as_deref(), Some("counted"));
assert_eq!(std::fs::read_to_string(counter).unwrap().trim(), "3");
assert_eq!(cache.len(), 1);
Expand Down Expand Up @@ -406,18 +407,18 @@ fn prepared_profile_prepare_reaps_background_pipe_holder() {
let worker_cwd = cwd.clone();
let (result_tx, result_rx) = std::sync::mpsc::channel();
let worker = std::thread::spawn(move || {
let result = run_shell_with_profiles(
1,
&worker_policy,
&worker_shell,
&worker_project_registry_dir,
&worker_cache,
Some(&worker_cwd),
&shell_env_var("WEBCODEX_TEST_PROFILE"),
None,
10,
None,
);
let result = (ShellExecutionContext {
generation: 1,
policy: &worker_policy,
shell: &worker_shell,
project_registry_dir: &worker_project_registry_dir,
cache: &worker_cache,
cwd: Some(&worker_cwd),
timeout_secs: 10,
stop_requested: None,
})
.run_shell(&shell_env_var("WEBCODEX_TEST_PROFILE"), None, false, None)
.result;
let _ = result_tx.send(result);
});

Expand Down
Loading
Loading