isothrum_machine/
selftest.rs1pub mod engine;
12pub mod hypervisor;
13pub mod server;
14
15use std::path::{Path, PathBuf};
16
17use isothrum_runner::{Event, RunName, Runner, RunnerConfig};
18
19use crate::Context;
20
21#[derive(Debug, Clone, PartialEq, Eq)]
23#[non_exhaustive]
24pub enum Progress<S, F, E> {
25 Running(S),
27 Passed(S, F),
29 Failed(S, E),
31 Skipped(S, F),
33}
34
35const PROMPT_LIMIT: std::time::Duration = std::time::Duration::from_secs(300);
37
38struct Steps<'a, S, F, E>(&'a (dyn Fn(Progress<S, F, E>) + Send + Sync));
40
41impl<S: Copy, F, E: Clone> Steps<'_, S, F, E> {
42 async fn run(&self, step: S, work: impl Future<Output = Result<F, E>>) -> Result<(), E> {
44 (self.0)(Progress::Running(step));
45 match work.await {
46 Ok(found) => {
47 (self.0)(Progress::Passed(step, found));
48 Ok(())
49 }
50 Err(why) => {
51 (self.0)(Progress::Failed(step, why.clone()));
52 Err(why)
53 }
54 }
55 }
56}
57
58fn throwaway(cx: &Context, dir: &Path, file: &str, text: &str) -> Result<(Runner, PathBuf), String> {
61 let project = dir.join("project");
62 let written = std::fs::create_dir_all(&project).and_then(|()| std::fs::write(project.join(file), text));
63 written.map_err(|e| format!("{} couldn't be written: {e}", project.display()))?;
64 let mut config = RunnerConfig::new(dir.join("home"));
65 config.processes = std::sync::Arc::clone(&cx.runner);
66 let runner = Runner::new(config).map_err(|e| e.to_string())?;
67 Ok((runner, project))
68}
69
70fn open<'a>(runner: &'a Runner, project: &Path, name: &str) -> Result<isothrum_runner::Running<'a>, String> {
72 let name = RunName::new(name).map_err(|e| e.to_string())?;
73 runner.open(project, Some(name)).map_err(|e| e.to_string())
74}
75
76fn quiet(_: &Event) {}