Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/crates/aien-switchboard/tests/common/mod.rs # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 6 use aien_switchboard::{Env, RuleTable}; 7 use std::ffi::OsString; 8 use std::fs; 9 use std::os::unix::fs::PermissionsExt; 10 use std::path::{Path, PathBuf}; 11 12 pub struct Fixture { 13 pub tmp: tempfile::TempDir, 14 } 15 16 impl 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]] 52 id = "anthropic-1" 53 provider = "anthropic" 54 program = "claude" 55 settings_dir = "{a1}" 56 57 [[accounts]] 58 id = "anthropic-2" 59 provider = "anthropic" 60 program = "claude" 61 settings_dir = "{a2}" 62 63 [[accounts]] 64 id = "openrouter-1" 65 provider = "openrouter" 66 program = "http" 67 key_ref = "openrouter-key" 68 69 [[accounts]] 70 id = "local" 71 provider = "local" 72 program = "aien" 73 74 [routes] 75 code = ["anthropic-1", "openrouter-1"] 76 review = ["anthropic-2", "openrouter-1"] 77 default = ["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 96 pub fn env(pairs: &[(&str, &str)]) -> Env { 97 pairs 98 .iter() 99 .map(|(k, v)| (OsString::from(k), OsString::from(v))) 100 .collect() 101 } 102 103 pub fn has(env: &Env, name: &str) -> bool { 104 env.contains_key(&OsString::from(name)) 105 }