wai doctor (toolchain.doctor, also the tool toolchain_doctor of wai mcp) prints one line per check, each pass, FAIL with its fix, not checked with the reason, or n/a. With --json, the envelope carries each check's state and facts, and a result: passed, failed, or passed-with-not-checked. A check that could not be run is never a pass. It exits 1 when a check failed, as the exit-code table says, and 0 otherwise. It looks at this wai's version and path, and at whether wai at a prompt reaches it: each wai earlier on PATH is asked --version --json, and one that does not answer as WAI's does, or that hangs, is a finding. One reached through a relative entry of PATH is named and not run. It finds the relay and the room service as wai dev finds them, and checks that each is of this wai's toolchain. It also finds the room client's files and Studio's. Each row of the quickstart README's port table, compiled in, is checked: free, or held by what the system will name to this account. On Linux that comes from /proc, on macOS from lsof, and on Windows from the system's own socket tables. It finds browsers for Studio and for the harnesses, and starts none. It reports where wai key keeps keys, and whether the directory and each file are this account's alone: by mode and owner on Unix, by SID through win_acl.rs on Windows, with the command that fixes each. A seed is never opened. On macOS it asks the keychain tool for its search list alone, and whether the login keychain is unlocked always reads not checked, since asking can raise a prompt. Nothing is sent and nothing is written. Each program asked has 3 s and is then stopped with its process group. Each group of checks runs on its own thread, and the run ends at 6 s: what has not finished by then reads as not checked. wai-relay and wai-room gain --version [--json], naming their own version and the toolchain they belong to (wai-rs's version in the tree they were built from), which is what wai doctor reads. build.sh runs both before it packs them. doctor joins the closed verb list (catalogue, door check). The catalogue export and Studio's generated actions are regenerated. tests/cli_doctor.rs drives the real binary on a made-up machine: its own PATH, home and temp directory, with wai hard-linked into a bin of its own. It is added to the conformance workflow's quickstart step, and wai/quickstart/README.md to that workflow's paths. Co-Authored-By: Claude Opus 5.5 <[email protected]>
33 lines
1.7 KiB
Rust
33 lines
1.7 KiB
Rust
//! `wai-relay --version`: this program's own version and the toolchain it belongs to, in the form
|
|
//! `wai doctor` reads to tell whether it and a `wai` agree. The toolchain's version is
|
|
//! `wai/wai-rs/Cargo.toml`'s, as this tree states it.
|
|
|
|
use std::path::Path;
|
|
use std::process::Command;
|
|
|
|
fn run(args: &[&str]) -> (bool, String) {
|
|
let o = Command::new(env!("CARGO_BIN_EXE_wai-relay")).args(args).output().expect("wai-relay runs");
|
|
(o.status.success(), String::from_utf8(o.stdout).unwrap())
|
|
}
|
|
|
|
fn toolchain() -> String {
|
|
let manifest = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../../wai/wai-rs/Cargo.toml");
|
|
let text = std::fs::read_to_string(&manifest).unwrap_or_else(|e| panic!("{}: {e}", manifest.display()));
|
|
text.lines().find_map(|l| l.strip_prefix("version = \"")?.strip_suffix('"')).expect("a version").to_string()
|
|
}
|
|
|
|
#[test]
|
|
fn it_names_itself_and_the_toolchain_it_belongs_to() {
|
|
let (ok, text) = run(&["--version"]);
|
|
assert!(ok, "{text}");
|
|
assert_eq!(text.trim(), format!("wai-relay {}, of the WAI toolchain {}", env!("CARGO_PKG_VERSION"), toolchain()));
|
|
for args in [&["--version", "--json"][..], &["--json", "--version"]] {
|
|
let (ok, text) = run(args);
|
|
assert!(ok, "{text}");
|
|
let v: serde_json::Value = serde_json::from_str(&text).unwrap_or_else(|e| panic!("{args:?}: {e}: {text}"));
|
|
assert_eq!((v["wai"].as_str(), v["op"].as_str(), v["ok"].as_bool()), (Some("envelope/1"), Some("toolchain.show"), Some(true)), "{v}");
|
|
assert_eq!(v["data"]["program"], "wai-relay");
|
|
assert_eq!(v["data"]["version"], env!("CARGO_PKG_VERSION"));
|
|
assert_eq!(v["data"]["toolchain"].as_str(), Some(toolchain().as_str()));
|
|
}
|
|
}
|