Skip to main content

overbrainer/
lib.rs

1//! overbrainer: distill a parent LLM into a smaller child model.
2
3pub mod cli;
4pub mod compare;
5pub mod config;
6pub mod dataset;
7pub mod dedup;
8pub mod events;
9pub mod exec;
10pub mod export;
11pub mod history;
12pub mod hub;
13pub mod llm;
14pub mod logging;
15pub mod metrics;
16pub mod pipeline;
17pub mod pricing;
18pub mod project_format;
19pub mod project_lock;
20pub mod prompts;
21pub mod retry;
22pub mod runpod;
23pub mod runs;
24pub mod secrets;
25pub mod system;
26pub mod train;
27pub mod tui;
28pub mod update;
29
30/// What the unit tests share across modules.
31#[cfg(test)]
32pub(crate) mod test_support {
33    /// Held by every test that sends a real signal to the test process. All unit
34    /// tests run in one process, so a signal one test raises reaches the
35    /// listeners of another running at the same time and breaks its timing.
36    /// Bind it to a name (`let _signals = SIGNALS.lock().await;`): `_` would
37    /// release it at once.
38    pub(crate) static SIGNALS: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());
39
40    /// Makes `path` executable.
41    pub(crate) fn make_executable(path: &std::path::Path) -> std::io::Result<()> {
42        use std::os::unix::fs::PermissionsExt as _;
43        std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o755))
44    }
45
46    /// Whether `sh` runs here.
47    pub(crate) fn sh_available() -> bool {
48        std::process::Command::new("sh")
49            .arg("-c")
50            .arg(":")
51            .status()
52            .is_ok_and(|status| status.success())
53    }
54
55    /// Whether `sh`, `python3` and `tar` run here: what the job scripts need.
56    pub(crate) fn tools_available() -> bool {
57        sh_available()
58            && ["python3", "tar"].iter().all(|program| {
59                std::process::Command::new(program)
60                    .arg("--version")
61                    .output()
62                    .is_ok_and(|output| output.status.success())
63            })
64    }
65
66    /// `tar -czf archive -C dir top`.
67    pub(crate) fn tar(
68        dir: &std::path::Path,
69        archive: &std::path::Path,
70        top: &str,
71    ) -> Result<(), Box<dyn std::error::Error>> {
72        let status = std::process::Command::new("tar")
73            .arg("-czf")
74            .arg(archive)
75            .arg("-C")
76            .arg(dir)
77            .arg(top)
78            .status()?;
79        if status.success() {
80            Ok(())
81        } else {
82            Err(format!("tar failed: {status}").into())
83        }
84    }
85
86    /// The stdout then the stderr of `output`, as text.
87    pub(crate) fn text(output: &std::process::Output) -> String {
88        format!(
89            "{}{}",
90            String::from_utf8_lossy(&output.stdout),
91            String::from_utf8_lossy(&output.stderr)
92        )
93    }
94}