|
| 1 | +#[path = "common/goal.rs"] |
| 2 | +mod goal_fixture; |
| 3 | + |
1 | 4 | use claurst_commands::{CommandContext, CommandResult, CovenCommand, GoalCommand, SlashCommand}; |
2 | 5 | use claurst_core::{config::Config, cost::CostTracker, GoalError, GoalStatus, GoalStore}; |
3 | | -use std::process::{Command, Stdio}; |
4 | | -use std::time::{Duration, Instant}; |
| 6 | +use goal_fixture::run_cases; |
5 | 7 |
|
6 | 8 | #[test] |
7 | 9 | fn corrupt_goal_reads_are_errors_without_mutation() { |
8 | | - run_cases(&["status", "counter"]); |
| 10 | + run_cases("goal_read_worker", &["status", "counter"]); |
9 | 11 | } |
10 | 12 |
|
11 | 13 | #[test] |
12 | 14 | fn missing_and_valid_goal_reads_keep_existing_behavior() { |
13 | | - run_cases(&["missing", "valid"]); |
14 | | -} |
15 | | - |
16 | | -fn run_cases(cases: &[&str]) { |
17 | | - let mut failures = Vec::new(); |
18 | | - for case in cases { |
19 | | - let temp = tempfile::tempdir().unwrap(); |
20 | | - let home = temp.path().join("home"); |
21 | | - let project = temp.path().join("project"); |
22 | | - std::fs::create_dir(&home).unwrap(); |
23 | | - std::fs::create_dir(&project).unwrap(); |
24 | | - let log = temp.path().join("stderr"); |
25 | | - let mut child = Command::new(std::env::current_exe().unwrap()) |
26 | | - .args(["--exact", "goal_read_worker", "--ignored", "--nocapture"]) |
27 | | - .env_clear() |
28 | | - .env("HOME", &home) |
29 | | - .env("USERPROFILE", &home) |
30 | | - .env("COVEN_CODE_HOME", &home) |
31 | | - .env("COVEN_HOME", temp.path().join("coven")) |
32 | | - .env("COVEN_CAVE_HOME", temp.path().join("cave")) |
33 | | - .env("GOAL_FIXTURE_PROJECT", &project) |
34 | | - .env("GOAL_FIXTURE_CASE", case) |
35 | | - .env("GOAL_FIXTURE_DONE", temp.path().join("done")) |
36 | | - .stdin(Stdio::null()) |
37 | | - .stdout(Stdio::null()) |
38 | | - .stderr(std::fs::File::create(&log).unwrap()) |
39 | | - .spawn() |
40 | | - .unwrap(); |
41 | | - let deadline = Instant::now() + Duration::from_secs(10); |
42 | | - let outcome = loop { |
43 | | - match child.try_wait() { |
44 | | - Ok(Some(status)) => break status, |
45 | | - Ok(None) if Instant::now() < deadline => { |
46 | | - std::thread::sleep(Duration::from_millis(10)) |
47 | | - } |
48 | | - result => { |
49 | | - let _ = child.kill(); |
50 | | - let _ = child.wait(); |
51 | | - panic!("{case}: child wait failed: {result:?}"); |
52 | | - } |
53 | | - } |
54 | | - }; |
55 | | - if outcome.success() { |
56 | | - assert_eq!(std::fs::read(temp.path().join("done")).unwrap(), b"checked"); |
57 | | - } else { |
58 | | - failures.push(format!("{case}: {}", std::fs::read_to_string(log).unwrap())); |
59 | | - } |
60 | | - } |
61 | | - assert!(failures.is_empty(), "{}", failures.join("\n")); |
| 15 | + run_cases("goal_read_worker", &["missing", "valid"]); |
62 | 16 | } |
63 | 17 |
|
64 | 18 | #[derive(Debug, Clone, PartialEq, Eq)] |
|
0 commit comments