interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-switchboard / tests / common / mod.rs

105 lines · 3016 bytes Raw Blame History
1//! Shared fixtures: every test works inside its own temp folder that stands
2//! in for HOME. No test touches the real home folder, the real `claude`, or
3//! any real login.
4#![allow(dead_code)]
5
6use aien_switchboard::{Env, RuleTable};
7use std::ffi::OsString;
8use std::fs;
9use std::os::unix::fs::PermissionsExt;
10use std::path::{Path, PathBuf};
11
12pub struct Fixture {
13 pub tmp: tempfile::TempDir,
14}
15
16impl Fixture {
17 pub fn new() -> Self {
18 Fixture {
19 tmp: tempfile::tempdir().unwrap(),
20 }
21 }
22 pub fn home(&self) -> PathBuf {
23 self.tmp.path().join("home")
24 }
25 pub fn bin(&self) -> PathBuf {
26 self.tmp.path().join("bin")
27 }
28 /// Profile folder for an alias, inside the temp HOME.
29 pub fn profile_dir(&self, alias: &str) -> PathBuf {
30 self.home().join(".switchboard").join(alias)
31 }
32 /// A stand-in `claude` executable. Tests never run it; the fake spawner
33 /// and fake probe only record what would have been started.
34 pub fn install_fake_claude(&self) -> PathBuf {
35 fs::create_dir_all(self.bin()).unwrap();
36 let p = self.bin().join("claude");
37 fs::write(&p, "#!/bin/sh\nexit 0\n").unwrap();
38 fs::set_permissions(&p, fs::Permissions::from_mode(0o755)).unwrap();
39 p
40 }
41 pub fn make_private_dir(&self, p: &Path) {
42 fs::create_dir_all(p).unwrap();
43 fs::set_permissions(p, fs::Permissions::from_mode(0o700)).unwrap();
44 }
45 /// Rule file with two Claude profiles of different providers' routes kept
46 /// apart, an OpenRouter key name and the local model. `extra` is appended
47 /// verbatim (for a `[launch]` table).
48 pub fn rules_toml(&self, extra: &str) -> String {
49 format!(
50 r#"{extra}
51[[accounts]]
52id = "anthropic-1"
53provider = "anthropic"
54program = "claude"
55settings_dir = "{a1}"
56
57[[accounts]]
58id = "anthropic-2"
59provider = "anthropic"
60program = "claude"
61settings_dir = "{a2}"
62
63[[accounts]]
64id = "openrouter-1"
65provider = "openrouter"
66program = "http"
67key_ref = "openrouter-key"
68
69[[accounts]]
70id = "local"
71provider = "local"
72program = "aien"
73
74[routes]
75code = ["anthropic-1", "openrouter-1"]
76review = ["anthropic-2", "openrouter-1"]
77default = ["local"]
78"#,
79 a1 = self.profile_dir("anthropic-1").display(),
80 a2 = self.profile_dir("anthropic-2").display(),
81 )
82 }
83 pub fn rules(&self, extra: &str) -> RuleTable {
84 RuleTable::from_toml_str(&self.rules_toml(extra)).unwrap()
85 }
86 /// A minimal clean environment: PATH points only at the fake bin folder
87 /// and HOME at the temp home.
88 pub fn base_env(&self) -> Env {
89 env(&[
90 ("PATH", self.bin().to_str().unwrap()),
91 ("HOME", self.home().to_str().unwrap()),
92 ])
93 }
94}
95
96pub fn env(pairs: &[(&str, &str)]) -> Env {
97 pairs
98 .iter()
99 .map(|(k, v)| (OsString::from(k), OsString::from(v)))
100 .collect()
101}
102
103pub fn has(env: &Env, name: &str) -> bool {
104 env.contains_key(&OsString::from(name))
105}