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/tools/aien-test/src/cli.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 / tools / aien-test / src / cli.rs` 802 lines ยท 30179 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 //! Argument parsing for the `aien-test` commands (ADR 0028 Decision 1 and 8, 17 //! ADR 0033 Decisions 10 and 12). Hand-written; the surface is small. 18 //! 19 //! ```text 20 //! aien-test run GATE_FILE_OR_NAME [flags] [-- ARGS...] 21 //! aien-test test ./... | gate:NAME | changed | crate:NAME [flags] 22 //! aien-test why GATE_FILE_OR_NAME [flags] 23 //! aien-test list [flags] 24 //! aien-test identity GATE_FILE_OR_NAME [--compiler-identity S] [--flag F]... [--hardware-identity S] 25 //! aien-test plan [--base REF] [--repo NAME] [--operator] [--allow-dirty] [--full] 26 //! aien-test status [--state-dir DIR] 27 //! aien-test verify COMMIT [--repo NAME] [--base REF] [--state-dir DIR] [--release] 28 //! aien-test worker [--once REPO SHA | --batch REPO SHA...] [--full] [--batch-host N] [--batch-heads N] [--poll SECS] [--repos LIST] [--github] [--iterations N] 29 //! [--state-dir DIR] [--key FILE] [--clones DIR] [--wt-root DIR] [--wt-tool FILE] [--siblings FILE] [--sandbox user|none --dev-unsandboxed] 30 //! ``` 31 //! 32 //! `--full` (plan, worker): full scope, an Alpha qualification. Every gate at 33 //! HEAD is selected whatever changed and the bundle signs `plan.scope: full`. 34 //! 35 //! `--host/--qemu/--gb10` and `--mutants` are later slices and are refused. 36 37 use crate::resources::{parse_jobs, GpuWait, JobsSpec}; 38 use crate::sandbox::Sandbox; 39 use std::path::PathBuf; 40 41 pub const USAGE: &str = "usage: 42 aien-test run GATE_FILE_OR_NAME [flags] [-- ARGS...] 43 aien-test test ./... | gate:NAME | changed | crate:NAME [flags] 44 aien-test why GATE_FILE_OR_NAME [flags] 45 aien-test list [flags] 46 aien-test identity GATE_FILE_OR_NAME [--compiler-identity S] [--flag F]... [--hardware-identity S] 47 aien-test plan [--base REF] [--repo NAME] [--operator] [--allow-dirty] [--full] 48 aien-test status [--state-dir DIR] 49 aien-test verify COMMIT [--repo NAME] [--base REF] [--state-dir DIR] [--release] 50 aien-test worker [--once REPO SHA | --batch REPO SHA...] [--full] [--batch-host N] [--batch-heads N] [--poll SECS] [--repos A,B] [--github] [--iterations N] 51 [--state-dir DIR] [--key FILE] [--clones DIR] [--wt-root DIR] [--wt-tool FILE] [--siblings FILE] [--sandbox user|none --dev-unsandboxed] 52 flags: --evidence-dir DIR --allow-dirty --no-cache --release --jobs host=N,qemu=M --gpu-wait 0|DURATION --wait-gpu 53 --sandbox none|user --base REF --operator --shared-cache DIR (run) 54 --full (plan, worker): full scope, every gate at HEAD (an Alpha qualification)"; 55 56 /// Which gates `test` runs. 57 #[derive(Debug, Clone, PartialEq, Eq)] 58 pub enum Selection { 59 /// `./...`: every gate in the repository. 60 All, 61 /// `gate:NAME`: that gate and everything it depends on. 62 Gate(String), 63 /// `changed`: what the planner selects for BASE..HEAD. 64 Changed, 65 /// `crate:NAME`: the gates covering a workspace crate and its dependents. 66 Crate(String), 67 } 68 69 #[derive(Debug, Clone, PartialEq, Eq)] 70 pub enum Command { 71 Run { gate: String }, 72 Test(Selection), 73 Why { gate: String }, 74 List, 75 Identity { gate: String }, 76 Plan, 77 Status, 78 Verify { commit: String }, 79 Worker, 80 } 81 82 #[derive(Debug, Clone, PartialEq, Eq)] 83 pub struct Cli { 84 pub command: Command, 85 pub evidence_dir: Option, 86 pub allow_dirty: bool, 87 /// `--no-cache`: never reuse an earlier result; run every gate fresh. 88 pub no_cache: bool, 89 /// `--release`: qualification mode (no cache, clean tree, no 90 /// hardware-scoped cache entries accepted by `verify`). 91 pub release: bool, 92 /// Arguments after `--`; they replace `run.args` (CR-061). `run` only. 93 pub args: Option>, 94 /// `--jobs host=N,qemu=M`: the pool sizes that were named. 95 pub jobs: JobsSpec, 96 /// `--gpu-wait 0|DURATION` (refuse at once, or wait up to DURATION) or 97 /// `--wait-gpu` (no bound) for a held GPU lock; None: the default bound 98 /// (`resources::DEFAULT_GPU_WAIT`). 99 pub gpu_wait: Option, 100 /// `identity` only: the compiler identity string (default empty: nothing 101 /// here builds yet). 102 pub compiler_identity: String, 103 /// `--shared-cache DIR` (run only): the cross-head store the worker keeps 104 /// in `/gate-cache/`, for one gate judged by hand. 105 pub shared_cache: Option, 106 /// `identity` only: `--flag F`, repeatable, order kept. 107 pub flags: Vec, 108 /// `identity` only: needed for `cache_scope: hardware`. 109 pub hardware_identity: Option, 110 /// `--sandbox none|user` (C8), default none. 111 pub sandbox: Sandbox, 112 /// Whether `--sandbox` was given (the worker defaults to `user`). 113 pub sandbox_given: bool, 114 /// worker: `--dev-unsandboxed`: allow `--sandbox none` (development only). 115 pub dev_unsandboxed: bool, 116 /// `--base REF` for plan, test changed, verify. 117 pub base: Option, 118 /// `--repo NAME`: the repository name for bundles. 119 pub repo: Option, 120 /// `--operator`: allow a pipeline configuration change. 121 pub operator: bool, 122 /// `--full` (plan, worker): full scope, every gate at HEAD whatever 123 /// changed (an Alpha qualification). 124 pub full: bool, 125 /// `--state-dir DIR`: the local CI state (default `~/.local/state/aien-local-ci`). 126 pub state_dir: Option, 127 /// worker: `--key FILE` (default `~/.aien/verify.key`). 128 pub key: Option, 129 /// worker: `--clones DIR` where the trusted clones live (default `~/workspace`). 130 pub clones: Option, 131 /// worker: `--wt-root DIR` where detached worktrees go (default `/var/lib/aien-run/wt`). 132 pub wt_root: Option, 133 /// worker: `--wt-tool FILE` INFRA's worktree tool (default 134 /// `/aien-sovereign-core/tools/aien-local-ci/wt.sh`). 135 pub wt_tool: Option, 136 /// `--siblings FILE`: the operator's sibling map (default 137 /// `/aien-sovereign-core/tools/aien-local-ci/siblings`). 138 pub siblings: Option, 139 /// worker: `--once REPO SHA`. 140 pub once: Option<(String, String)>, 141 /// worker: `--batch REPO SHA SHA...` (judge these heads together). 142 pub batch: Option<(String, Vec)>, 143 /// worker: `--batch-host N` (host slots a batch shares). 144 pub batch_host: Option, 145 /// worker: `--batch-heads N` (heads per batch in the loop). 146 pub batch_heads: Option, 147 /// worker: `--poll SECS` (default 30). 148 pub poll: Option, 149 /// worker: `--repos A,B`. 150 pub repos: Vec, 151 /// worker: `--github`: poll GitHub and post commit statuses. 152 pub github: bool, 153 /// worker: `--iterations N`: stop the loop after N rounds (0: forever). 154 pub iterations: Option, 155 } 156 157 fn parse_selection(s: &str) -> Result { 158 if s == "./..." { 159 return Ok(Selection::All); 160 } 161 if s == "changed" { 162 return Ok(Selection::Changed); 163 } 164 if let Some(name) = s.strip_prefix("crate:") { 165 if name.is_empty() { 166 return Err("crate: needs a crate name".to_string()); 167 } 168 return Ok(Selection::Crate(name.to_string())); 169 } 170 match s.strip_prefix("gate:") { 171 Some(name) if !name.is_empty() => Ok(Selection::Gate(name.to_string())), 172 _ => Err(format!( 173 "unsupported test selection {s:?}: use ./..., gate:NAME, changed or crate:NAME" 174 )), 175 } 176 } 177 178 const COMMANDS: [&str; 9] = [ 179 "run", "test", "why", "list", "identity", "plan", "status", "verify", "worker", 180 ]; 181 const WORKER_FLAGS: [&str; 16] = [ 182 "--batch", 183 "--batch-host", 184 "--batch-heads", 185 "--dev-unsandboxed", 186 "--key", 187 "--clones", 188 "--wt-root", 189 "--wt-tool", 190 "--siblings", 191 "--once", 192 "--poll", 193 "--repos", 194 "--github", 195 "--iterations", 196 "--state-dir", 197 "--sandbox", 198 ]; 199 200 pub fn parse_args(argv: &[String]) -> Result { 201 let name = argv 202 .first() 203 .map(|s| s.as_str()) 204 .ok_or_else(|| "no command".to_string())?; 205 if !COMMANDS.contains(&name) { 206 return Err(format!("unknown command {name:?}")); 207 } 208 let mut positional: Option = None; 209 let mut evidence_dir: Option = None; 210 let mut allow_dirty = false; 211 let mut no_cache = false; 212 let mut release = false; 213 let mut args: Option> = None; 214 let mut jobs = JobsSpec::default(); 215 let mut gpu_wait: Option = None; 216 let mut compiler_identity = String::new(); 217 let mut flags: Vec = Vec::new(); 218 let mut hardware_identity: Option = None; 219 let mut identity_flags = false; 220 let mut sandbox = Sandbox::None; 221 let mut sandbox_given = false; 222 let mut dev_unsandboxed = false; 223 let mut base: Option = None; 224 let mut repo: Option = None; 225 let mut operator = false; 226 let mut full = false; 227 let mut state_dir: Option = None; 228 let mut key: Option = None; 229 let mut clones: Option = None; 230 let mut wt_root: Option = None; 231 let mut wt_tool: Option = None; 232 let mut siblings: Option = None; 233 let mut once: Option<(String, String)> = None; 234 let mut batch: Option<(String, Vec)> = None; 235 let mut batch_host: Option = None; 236 let mut batch_heads: Option = None; 237 let mut poll: Option = None; 238 let mut repos: Vec = Vec::new(); 239 let mut github = false; 240 let mut iterations: Option = None; 241 let mut shared_cache: Option = None; 242 let mut worker_flags: Vec<&str> = Vec::new(); 243 let mut i = 1; 244 let value = |i: &mut usize, a: &str| -> Result { 245 *i += 1; 246 argv.get(*i) 247 .cloned() 248 .ok_or_else(|| format!("{a} needs a value")) 249 }; 250 while i < argv.len() { 251 let a = argv[i].as_str(); 252 if a == "--" { 253 args = Some(argv[i + 1..].to_vec()); 254 break; 255 } else if a == "--evidence-dir" { 256 evidence_dir = Some(PathBuf::from(value(&mut i, a)?)); 257 } else if a == "--shared-cache" { 258 shared_cache = Some(PathBuf::from(value(&mut i, a)?)); 259 } else if a == "--jobs" { 260 jobs = parse_jobs(&value(&mut i, a)?)?; 261 } else if a == "--compiler-identity" || a == "--flag" || a == "--hardware-identity" { 262 identity_flags = true; 263 let v = value(&mut i, a)?; 264 match a { 265 "--compiler-identity" => compiler_identity = v, 266 "--flag" => flags.push(v), 267 _ => hardware_identity = Some(v), 268 } 269 } else if a == "--allow-dirty" { 270 allow_dirty = true; 271 } else if a == "--no-cache" { 272 no_cache = true; 273 } else if a == "--release" { 274 release = true; 275 } else if a == "--wait-gpu" { 276 gpu_wait = Some(GpuWait::Forever); 277 } else if a == "--gpu-wait" { 278 let d = value(&mut i, a)?; 279 gpu_wait = Some(if d == "0" { 280 GpuWait::Refuse 281 } else { 282 let ms = crate::manifest::parse_duration_ms(&d).ok_or_else(|| { 283 format!("--gpu-wait needs 0 or a duration like 90s or 30m, not {d:?}") 284 })?; 285 GpuWait::Bounded(std::time::Duration::from_millis(ms)) 286 }); 287 } else if a == "--operator" { 288 operator = true; 289 } else if a == "--full" { 290 full = true; 291 } else if a == "--base" { 292 base = Some(value(&mut i, a)?); 293 } else if a == "--repo" { 294 repo = Some(value(&mut i, a)?); 295 } else if a == "--sandbox" { 296 sandbox = Sandbox::parse(&value(&mut i, a)?)?; 297 sandbox_given = true; 298 } else if a == "--state-dir" { 299 state_dir = Some(PathBuf::from(value(&mut i, a)?)); 300 } else if a == "--key" { 301 worker_flags.push("--key"); 302 key = Some(PathBuf::from(value(&mut i, a)?)); 303 } else if a == "--clones" { 304 worker_flags.push("--clones"); 305 clones = Some(PathBuf::from(value(&mut i, a)?)); 306 } else if a == "--wt-root" { 307 worker_flags.push("--wt-root"); 308 wt_root = Some(PathBuf::from(value(&mut i, a)?)); 309 } else if a == "--wt-tool" { 310 worker_flags.push("--wt-tool"); 311 wt_tool = Some(PathBuf::from(value(&mut i, a)?)); 312 } else if a == "--siblings" { 313 worker_flags.push("--siblings"); 314 siblings = Some(PathBuf::from(value(&mut i, a)?)); 315 } else if a == "--once" { 316 worker_flags.push("--once"); 317 let r = value(&mut i, a)?; 318 let s = value(&mut i, a)?; 319 if s.len() != 40 || !s.bytes().all(|b| b.is_ascii_hexdigit()) { 320 return Err("--once needs REPO and a 40-hex SHA".to_string()); 321 } 322 once = Some((r, s.to_ascii_lowercase())); 323 } else if a == "--batch" { 324 worker_flags.push("--batch"); 325 let r = value(&mut i, a)?; 326 let mut shas = Vec::new(); 327 while argv.get(i + 1).is_some_and(|s| !s.starts_with("--")) { 328 let s = value(&mut i, a)?; 329 if s.len() != 40 || !s.bytes().all(|b| b.is_ascii_hexdigit()) { 330 return Err(format!("--batch needs REPO and 40-hex SHAs, not {s:?}")); 331 } 332 shas.push(s.to_ascii_lowercase()); 333 } 334 if shas.is_empty() { 335 return Err("--batch needs REPO and at least one 40-hex SHA".to_string()); 336 } 337 batch = Some((r, shas)); 338 } else if a == "--batch-host" || a == "--batch-heads" { 339 worker_flags.push(if a == "--batch-host" { 340 "--batch-host" 341 } else { 342 "--batch-heads" 343 }); 344 let v = value(&mut i, a)?; 345 let n = v 346 .parse::() 347 .ok() 348 .filter(|n| *n > 0) 349 .ok_or_else(|| format!("{a} needs a positive number, not {v:?}"))?; 350 if a == "--batch-host" { 351 batch_host = Some(n); 352 } else { 353 batch_heads = Some(n); 354 } 355 } else if a == "--poll" { 356 worker_flags.push("--poll"); 357 let v = value(&mut i, a)?; 358 poll = Some( 359 v.parse::() 360 .map_err(|_| format!("--poll needs seconds, not {v:?}"))?, 361 ); 362 } else if a == "--iterations" { 363 worker_flags.push("--iterations"); 364 let v = value(&mut i, a)?; 365 iterations = Some( 366 v.parse::() 367 .map_err(|_| format!("--iterations needs a number, not {v:?}"))?, 368 ); 369 } else if a == "--repos" { 370 worker_flags.push("--repos"); 371 repos = value(&mut i, a)? 372 .split(',') 373 .filter(|s| !s.is_empty()) 374 .map(|s| s.to_string()) 375 .collect(); 376 } else if a == "--dev-unsandboxed" { 377 worker_flags.push("--dev-unsandboxed"); 378 dev_unsandboxed = true; 379 } else if a == "--github" { 380 worker_flags.push("--github"); 381 github = true; 382 } else if a.starts_with('-') { 383 return Err(format!("unknown argument {a:?}")); 384 } else if positional.is_none() { 385 positional = Some(a.to_string()); 386 } else { 387 return Err(format!("unexpected argument {a:?}")); 388 } 389 i += 1; 390 } 391 if args.is_some() && name != "run" { 392 return Err("-- ARGS only apply to the run command".to_string()); 393 } 394 if identity_flags && !["identity", "plan", "verify", "worker"].contains(&name) { 395 return Err( 396 "--compiler-identity, --flag and --hardware-identity only apply to identity, plan, verify and worker" 397 .to_string(), 398 ); 399 } 400 if name != "worker" { 401 if let Some(f) = worker_flags 402 .iter() 403 .find(|f| WORKER_FLAGS.contains(f) && !["--state-dir", "--sandbox"].contains(f)) 404 { 405 return Err(format!("{f} only applies to worker")); 406 } 407 } 408 if sandbox != Sandbox::None && !["run", "test", "worker"].contains(&name) { 409 return Err("--sandbox only applies to run, test and worker".to_string()); 410 } 411 if base.is_some() && !["plan", "test", "verify", "worker"].contains(&name) { 412 return Err("--base only applies to plan, test, verify and worker".to_string()); 413 } 414 if operator && !["plan", "test", "worker"].contains(&name) { 415 return Err("--operator only applies to plan, test and worker".to_string()); 416 } 417 if full && !["plan", "worker"].contains(&name) { 418 return Err("--full only applies to plan and worker".to_string()); 419 } 420 if repo.is_some() && !["plan", "verify", "worker"].contains(&name) { 421 return Err("--repo only applies to plan, verify and worker".to_string()); 422 } 423 if shared_cache.is_some() && name != "run" { 424 return Err("--shared-cache only applies to run".to_string()); 425 } 426 if state_dir.is_some() && !["status", "verify", "worker"].contains(&name) { 427 return Err("--state-dir only applies to status, verify and worker".to_string()); 428 } 429 let command = match name { 430 "identity" => Command::Identity { 431 gate: positional.ok_or("missing GATE_FILE_OR_NAME")?, 432 }, 433 "run" => Command::Run { 434 gate: positional.ok_or("missing GATE_FILE_OR_NAME")?, 435 }, 436 "why" => Command::Why { 437 gate: positional.ok_or("missing GATE_FILE_OR_NAME")?, 438 }, 439 "test" => { 440 let selection = positional.ok_or("missing ./..., gate:NAME, changed or crate:NAME")?; 441 Command::Test(parse_selection(&selection)?) 442 } 443 "verify" => { 444 let commit = positional.ok_or("missing COMMIT")?; 445 Command::Verify { commit } 446 } 447 _ => { 448 if let Some(p) = positional { 449 return Err(format!("unexpected argument {p:?}")); 450 } 451 match name { 452 "plan" => Command::Plan, 453 "status" => Command::Status, 454 "worker" => Command::Worker, 455 _ => Command::List, 456 } 457 } 458 }; 459 Ok(Cli { 460 command, 461 evidence_dir, 462 allow_dirty, 463 no_cache, 464 release, 465 args, 466 jobs, 467 gpu_wait, 468 compiler_identity, 469 flags, 470 hardware_identity, 471 sandbox, 472 sandbox_given, 473 dev_unsandboxed, 474 base, 475 repo, 476 operator, 477 full, 478 state_dir, 479 key, 480 clones, 481 wt_root, 482 wt_tool, 483 siblings, 484 once, 485 batch, 486 batch_host, 487 batch_heads, 488 poll, 489 repos, 490 github, 491 iterations, 492 shared_cache, 493 }) 494 } 495 496 #[cfg(test)] 497 mod tests { 498 use super::*; 499 500 fn v(a: &[&str]) -> Vec { 501 a.iter().map(|s| s.to_string()).collect() 502 } 503 504 fn run_gate(c: &Cli) -> &str { 505 match &c.command { 506 Command::Run { gate } => gate, 507 other => panic!("expected run, got {other:?}"), 508 } 509 } 510 511 #[test] 512 fn minimal() { 513 let c = parse_args(&v(&["run", "G"])).unwrap(); 514 assert_eq!(run_gate(&c), "G"); 515 assert!(!c.allow_dirty); 516 assert!(!c.no_cache); 517 assert!(!c.release); 518 assert_eq!(c.gpu_wait, None); 519 assert_eq!(c.args, None); 520 assert_eq!(c.evidence_dir, None); 521 assert_eq!(c.jobs, JobsSpec::default()); 522 assert_eq!(c.sandbox, Sandbox::None); 523 assert_eq!(c.base, None); 524 assert!(!c.operator); 525 } 526 527 #[test] 528 fn full() { 529 let c = parse_args(&v(&[ 530 "run", 531 "--allow-dirty", 532 "G", 533 "--evidence-dir", 534 "/e", 535 "--", 536 "-x", 537 "y", 538 ])) 539 .unwrap(); 540 assert_eq!(run_gate(&c), "G"); 541 assert!(c.allow_dirty); 542 assert_eq!(c.evidence_dir, Some(PathBuf::from("/e"))); 543 assert_eq!(c.args, Some(v(&["-x", "y"]))); 544 } 545 546 #[test] 547 fn no_cache_and_release_flags() { 548 let c = parse_args(&v(&["run", "G", "--no-cache"])).unwrap(); 549 assert!(c.no_cache); 550 let c = parse_args(&v(&["test", "--no-cache", "./..."])).unwrap(); 551 assert!(c.no_cache); 552 assert_eq!(c.command, Command::Test(Selection::All)); 553 let c = parse_args(&v(&["run", "G", "--release"])).unwrap(); 554 assert!(c.release && !c.no_cache); 555 let c = parse_args(&v(&["verify", "a".repeat(40).as_str(), "--release"])).unwrap(); 556 assert!(c.release); 557 } 558 559 #[test] 560 fn empty_override_args_are_kept() { 561 let c = parse_args(&v(&["run", "G", "--"])).unwrap(); 562 assert_eq!(c.args, Some(Vec::new())); 563 } 564 565 #[test] 566 fn test_selections() { 567 let c = parse_args(&v(&["test", "./..."])).unwrap(); 568 assert_eq!(c.command, Command::Test(Selection::All)); 569 let c = parse_args(&v(&["test", "gate:G-1"])).unwrap(); 570 assert_eq!(c.command, Command::Test(Selection::Gate("G-1".to_string()))); 571 let c = parse_args(&v(&["test", "changed", "--base", "origin/main"])).unwrap(); 572 assert_eq!(c.command, Command::Test(Selection::Changed)); 573 assert_eq!(c.base.as_deref(), Some("origin/main")); 574 let c = parse_args(&v(&["test", "crate:aien-runtime"])).unwrap(); 575 assert_eq!( 576 c.command, 577 Command::Test(Selection::Crate("aien-runtime".into())) 578 ); 579 } 580 581 #[test] 582 fn unsupported_selections_are_refused() { 583 for bad in ["crate:", "gate:", "G", "./", ".", "changed:x"] { 584 assert!(parse_args(&v(&["test", bad])).is_err(), "{bad}"); 585 } 586 assert!(parse_args(&v(&["test"])).is_err()); 587 } 588 589 #[test] 590 fn gpu_wait_takes_zero_or_a_duration() { 591 let c = parse_args(&v(&["worker", "--gpu-wait", "0"])).unwrap(); 592 assert_eq!(c.gpu_wait, Some(GpuWait::Refuse)); 593 let c = parse_args(&v(&["run", "g", "--gpu-wait", "90s"])).unwrap(); 594 assert_eq!( 595 c.gpu_wait, 596 Some(GpuWait::Bounded(std::time::Duration::from_secs(90))) 597 ); 598 assert!(parse_args(&v(&["run", "g", "--gpu-wait", "soon"])).is_err()); 599 assert!(parse_args(&v(&["run", "g", "--gpu-wait"])).is_err()); 600 } 601 602 #[test] 603 fn jobs_and_wait_gpu() { 604 let c = parse_args(&v(&[ 605 "test", 606 "./...", 607 "--jobs", 608 "host=3,qemu=2", 609 "--wait-gpu", 610 ])) 611 .unwrap(); 612 assert_eq!(c.jobs.host, Some(3)); 613 assert_eq!(c.jobs.qemu, Some(2)); 614 assert_eq!(c.gpu_wait, Some(GpuWait::Forever)); 615 let c = parse_args(&v(&["test", "./...", "--jobs", "qemu=1"])).unwrap(); 616 assert_eq!(c.jobs.host, None); 617 assert_eq!(c.jobs.qemu, Some(1)); 618 } 619 620 #[test] 621 fn bad_jobs_are_refused() { 622 for bad in ["host=0", "gb10=2", "host", "host=x", "disk=1", ""] { 623 assert!( 624 parse_args(&v(&["test", "./...", "--jobs", bad])).is_err(), 625 "{bad}" 626 ); 627 } 628 assert!(parse_args(&v(&["test", "./...", "--jobs"])).is_err()); 629 } 630 631 #[test] 632 fn why_and_list() { 633 let c = parse_args(&v(&["why", "G-1"])).unwrap(); 634 assert_eq!( 635 c.command, 636 Command::Why { 637 gate: "G-1".to_string() 638 } 639 ); 640 let c = parse_args(&v(&["list"])).unwrap(); 641 assert_eq!(c.command, Command::List); 642 assert!(parse_args(&v(&["why"])).is_err()); 643 assert!(parse_args(&v(&["list", "extra"])).is_err()); 644 } 645 646 #[test] 647 fn identity_command_and_its_flags() { 648 let c = parse_args(&v(&[ 649 "identity", 650 "G", 651 "--compiler-identity", 652 "rustc 1", 653 "--flag", 654 "-O", 655 "--flag", 656 "-C", 657 "--hardware-identity", 658 "gb10-1", 659 ])) 660 .unwrap(); 661 assert_eq!(c.command, Command::Identity { gate: "G".into() }); 662 assert_eq!(c.compiler_identity, "rustc 1"); 663 assert_eq!(c.flags, v(&["-O", "-C"])); 664 assert_eq!(c.hardware_identity.as_deref(), Some("gb10-1")); 665 assert!(parse_args(&v(&["identity"])).is_err()); 666 assert!(parse_args(&v(&["identity", "G", "--flag"])).is_err()); 667 assert!(parse_args(&v(&["run", "G", "--flag", "x"])).is_err()); 668 assert!(parse_args(&v(&["list", "--compiler-identity", "x"])).is_err()); 669 } 670 671 #[test] 672 fn override_args_only_for_run() { 673 assert!(parse_args(&v(&["test", "./...", "--", "x"])).is_err()); 674 assert!(parse_args(&v(&["why", "G", "--", "x"])).is_err()); 675 } 676 677 #[test] 678 fn sandbox_flag() { 679 let c = parse_args(&v(&["run", "G", "--sandbox", "user"])).unwrap(); 680 assert_eq!(c.sandbox, Sandbox::User); 681 let c = parse_args(&v(&["test", "changed", "--sandbox", "none"])).unwrap(); 682 assert_eq!(c.sandbox, Sandbox::None); 683 assert!(parse_args(&v(&["run", "G", "--sandbox", "root"])).is_err()); 684 assert!(parse_args(&v(&["run", "G", "--sandbox"])).is_err()); 685 assert!(parse_args(&v(&["list", "--sandbox", "user"])).is_err()); 686 } 687 688 #[test] 689 fn plan_status_verify() { 690 let c = parse_args(&v(&[ 691 "plan", 692 "--base", 693 "main", 694 "--repo", 695 "github.com/a/b", 696 "--operator", 697 "--allow-dirty", 698 ])) 699 .unwrap(); 700 assert_eq!(c.command, Command::Plan); 701 assert_eq!(c.base.as_deref(), Some("main")); 702 assert_eq!(c.repo.as_deref(), Some("github.com/a/b")); 703 assert!(c.operator && c.allow_dirty); 704 assert!(parse_args(&v(&["plan", "extra"])).is_err()); 705 let c = parse_args(&v(&["status", "--state-dir", "/s"])).unwrap(); 706 assert_eq!(c.command, Command::Status); 707 assert_eq!(c.state_dir, Some(PathBuf::from("/s"))); 708 let sha = "b".repeat(40); 709 let c = parse_args(&v(&["verify", &sha, "--repo", "x", "--base", "main"])).unwrap(); 710 assert_eq!( 711 c.command, 712 Command::Verify { 713 commit: sha.clone() 714 } 715 ); 716 assert!(parse_args(&v(&["verify"])).is_err()); 717 assert!(parse_args(&v(&["run", "G", "--base", "x"])).is_err()); 718 assert!(parse_args(&v(&["run", "G", "--operator"])).is_err()); 719 assert!(parse_args(&v(&["run", "G", "--state-dir", "/s"])).is_err()); 720 assert!(parse_args(&v(&["list", "--repo", "x"])).is_err()); 721 } 722 723 #[test] 724 fn worker_flags() { 725 let sha = "c".repeat(40); 726 let c = parse_args(&v(&[ 727 "worker", 728 "--once", 729 "repo", 730 &sha, 731 "--poll", 732 "5", 733 "--repos", 734 "a,b", 735 "--github", 736 "--iterations", 737 "3", 738 "--state-dir", 739 "/s", 740 "--key", 741 "/k", 742 "--clones", 743 "/c", 744 "--wt-root", 745 "/w", 746 "--wt-tool", 747 "/t/wt.sh", 748 "--siblings", 749 "/t/siblings", 750 "--sandbox", 751 "user", 752 ])) 753 .unwrap(); 754 assert_eq!(c.command, Command::Worker); 755 assert_eq!(c.once, Some(("repo".to_string(), sha.clone()))); 756 assert_eq!(c.poll, Some(5)); 757 assert_eq!(c.repos, v(&["a", "b"])); 758 assert!(c.github); 759 assert_eq!(c.iterations, Some(3)); 760 assert_eq!(c.key, Some(PathBuf::from("/k"))); 761 assert_eq!(c.clones, Some(PathBuf::from("/c"))); 762 assert_eq!(c.wt_root, Some(PathBuf::from("/w"))); 763 assert_eq!(c.wt_tool, Some(PathBuf::from("/t/wt.sh"))); 764 assert_eq!(c.siblings, Some(PathBuf::from("/t/siblings"))); 765 assert_eq!(c.sandbox, Sandbox::User); 766 assert!(parse_args(&v(&["worker", "--once", "repo", "short"])).is_err()); 767 assert!(parse_args(&v(&["worker", "--poll", "x"])).is_err()); 768 assert!(parse_args(&v(&["run", "G", "--poll", "5"])).is_err()); 769 assert!(parse_args(&v(&["plan", "--github"])).is_err()); 770 assert!(parse_args(&v(&["worker", "extra"])).is_err()); 771 } 772 773 #[test] 774 fn full_scope_flag_is_for_plan_and_worker_only() { 775 let sha = "d".repeat(40); 776 let c = parse_args(&v(&["worker", "--once", "repo", &sha, "--full"])).unwrap(); 777 assert!(c.full); 778 assert_eq!(c.once, Some(("repo".to_string(), sha.clone()))); 779 let c = parse_args(&v(&["plan", "--full"])).unwrap(); 780 assert_eq!(c.command, Command::Plan); 781 assert!(c.full); 782 assert!(!parse_args(&v(&["plan"])).unwrap().full); 783 for bad in [ 784 v(&["test", "./...", "--full"]), 785 v(&["verify", &sha, "--full"]), 786 v(&["run", "G", "--full"]), 787 ] { 788 assert!(parse_args(&bad).is_err(), "{bad:?}"); 789 } 790 } 791 792 #[test] 793 fn errors() { 794 assert!(parse_args(&[]).is_err()); 795 assert!(parse_args(&v(&["test", "G"])).is_err()); 796 assert!(parse_args(&v(&["bogus", "G"])).is_err()); 797 assert!(parse_args(&v(&["run"])).is_err()); 798 assert!(parse_args(&v(&["run", "G", "H"])).is_err()); 799 assert!(parse_args(&v(&["run", "G", "--bogus"])).is_err()); 800 assert!(parse_args(&v(&["run", "G", "--evidence-dir"])).is_err()); 801 } 802 }