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
aien-sovereign-core-mv / crates / aien-switchboard / tests / cli.rs
| 1 | //! The `switchboard` command surface, driven in-process with fakes. |
| 2 | |
| 3 | mod common; |
| 4 | |
| 5 | use aien_switchboard::cli::run; |
| 6 | use aien_switchboard::*; |
| 7 | use common::*; |
| 8 | use std::fs; |
| 9 | |
| 10 | struct Out { |
| 11 | code: i32, |
| 12 | out: String, |
| 13 | err: String, |
| 14 | } |
| 15 | |
| 16 | fn call(f: &Fixture, args: &[&str], sp: &mut FakeSpawner) -> Out { |
| 17 | let rules = f.home().join(".switchboard").join("rules.toml"); |
| 18 | fs::create_dir_all(rules.parent().unwrap()).unwrap(); |
| 19 | if !rules.exists() { |
| 20 | fs::write(&rules, f.rules_toml("")).unwrap(); |
| 21 | } |
| 22 | let args: Vec<String> = args.iter().map(|s| s.to_string()).collect(); |
| 23 | let mut probe = FakeProbe { |
| 24 | answer: Ok("2.1.301 (Claude Code)".into()), |
| 25 | calls: Vec::new(), |
| 26 | }; |
| 27 | let (mut o, mut e) = (Vec::new(), Vec::new()); |
| 28 | let code = run( |
| 29 | &args, |
| 30 | &f.base_env(), |
| 31 | f.tmp.path(), |
| 32 | sp, |
| 33 | &mut probe, |
| 34 | &mut o, |
| 35 | &mut e, |
| 36 | ); |
| 37 | Out { |
| 38 | code, |
| 39 | out: String::from_utf8(o).unwrap(), |
| 40 | err: String::from_utf8(e).unwrap(), |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | #[test] |
| 45 | fn accounts_lists_profiles_from_the_default_rule_file_in_home() { |
| 46 | let f = Fixture::new(); |
| 47 | let o = call(&f, &["accounts"], &mut FakeSpawner::default()); |
| 48 | assert_eq!(o.code, 0, "{}", o.err); |
| 49 | for a in ["anthropic-1", "anthropic-2", "openrouter-1", "local"] { |
| 50 | assert!(o.out.contains(a), "{}", o.out); |
| 51 | } |
| 52 | assert!(o |
| 53 | .out |
| 54 | .contains(f.profile_dir("anthropic-1").to_str().unwrap())); |
| 55 | } |
| 56 | |
| 57 | #[test] |
| 58 | fn launch_runs_through_the_spawner_and_returns_its_exit_code() { |
| 59 | let f = Fixture::new(); |
| 60 | f.install_fake_claude(); |
| 61 | let mut sp = FakeSpawner { |
| 62 | exit_code: 3, |
| 63 | ..FakeSpawner::default() |
| 64 | }; |
| 65 | let o = call(&f, &["launch", "anthropic-2"], &mut sp); |
| 66 | assert_eq!(o.code, 3, "{}", o.err); |
| 67 | assert_eq!(sp.plans.len(), 1); |
| 68 | assert_eq!(sp.plans[0].config_dir, f.profile_dir("anthropic-2")); |
| 69 | } |
| 70 | |
| 71 | #[test] |
| 72 | fn unknown_alias_exits_nonzero_with_known_names() { |
| 73 | let f = Fixture::new(); |
| 74 | f.install_fake_claude(); |
| 75 | let mut sp = FakeSpawner::default(); |
| 76 | let o = call(&f, &["launch", "nobody"], &mut sp); |
| 77 | assert_eq!(o.code, 1); |
| 78 | assert!( |
| 79 | o.err.contains("nobody") && o.err.contains("anthropic-1"), |
| 80 | "{}", |
| 81 | o.err |
| 82 | ); |
| 83 | assert!(sp.plans.is_empty()); |
| 84 | } |
| 85 | |
| 86 | #[test] |
| 87 | fn doctor_exit_code_follows_failures() { |
| 88 | let f = Fixture::new(); |
| 89 | f.install_fake_claude(); |
| 90 | let ok = call(&f, &["doctor"], &mut FakeSpawner::default()); |
| 91 | assert_eq!(ok.code, 0, "{}{}", ok.out, ok.err); |
| 92 | fs::remove_file(f.bin().join("claude")).unwrap(); |
| 93 | let bad = call(&f, &["doctor"], &mut FakeSpawner::default()); |
| 94 | assert_eq!(bad.code, 1, "{}", bad.out); |
| 95 | } |
| 96 | |
| 97 | #[test] |
| 98 | fn usage_errors_exit_2() { |
| 99 | let f = Fixture::new(); |
| 100 | assert_eq!(call(&f, &[], &mut FakeSpawner::default()).code, 2); |
| 101 | assert_eq!(call(&f, &["launch"], &mut FakeSpawner::default()).code, 2); |
| 102 | assert_eq!( |
| 103 | call(&f, &["frobnicate"], &mut FakeSpawner::default()).code, |
| 104 | 2 |
| 105 | ); |
| 106 | assert_eq!( |
| 107 | call(&f, &["launch", "a", "b"], &mut FakeSpawner::default()).code, |
| 108 | 2 |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | #[test] |
| 113 | fn rules_flag_points_at_another_file() { |
| 114 | let f = Fixture::new(); |
| 115 | let other = f.tmp.path().join("other.toml"); |
| 116 | fs::write(&other, f.rules_toml("")).unwrap(); |
| 117 | let o = call( |
| 118 | &f, |
| 119 | &["--rules", other.to_str().unwrap(), "accounts"], |
| 120 | &mut FakeSpawner::default(), |
| 121 | ); |
| 122 | assert_eq!(o.code, 0, "{}", o.err); |
| 123 | } |