crates/monetize-server/tests/run_args.rs
//! ★ **G6 (one monetize, 2026-10-10): the server is a role of another binary.**
//! The solo monetize box runs monetize-server and the console as two
//! PROCESSES of one multi-call binary (`monetize-admin server …` /
//! `monetize-admin ui …`), so the server's command line must come from the
//! caller, not from `std::env::args()` — under `monetize-admin server` the
//! first word is the role, which the server would refuse as an unknown flag.
use monetize_server::registry::Linked;
#[test]
fn the_server_reads_the_words_it_is_given_not_the_process_arguments() {
// The test harness's own arguments are not monetize's: `--help` alone is.
monetize_server::cli::run_args(Linked::open(), ["--help".to_string()]).expect("--help answers");
let e = monetize_server::cli::run_args(Linked::open(), ["--no-such-flag".to_string()]).unwrap_err();
assert!(format!("{e:#}").contains("unknown argument \"--no-such-flag\""), "{e:#}");
}
#[test]
fn check_judges_the_config_the_words_name() {
let dir = std::path::Path::new(env!("CARGO_TARGET_TMPDIR")).join(format!("run_args-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let good = dir.join("good.toml");
std::fs::write(&good, format!("grpc_addr = \"127.0.0.1:50061\"\ndata_dir = \"{}\"\n", dir.join("data").display())).unwrap();
monetize_server::cli::run_args(Linked::open(), ["--config".into(), good.display().to_string(), "--check".into()]).expect("a bare config checks");
let bad = dir.join("bad.toml");
std::fs::write(&bad, "[products.gunnar]\nendpoint = \"x\"\n[prices.gunnar.SE]\ndisk_gib_month = 100\n").unwrap();
let e = monetize_server::cli::run_args(Linked::open(), ["--config".into(), bad.display().to_string(), "--check".into()]).unwrap_err();
assert!(format!("{e:#}").contains("vendor"), "a priced product with no vendor is refused at load: {e:#}");
let _ = std::fs::remove_dir_all(&dir);
}