054392abbe
39 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. These commits sit on several merged branches, so the wave holds their combined result. - 1b17dd7f5 brett19: Merge fixes: every crate and test target compiles on the merged tree, but for crates/geom's hlr - 8f2c11da2 brett19: Drawings hidden lines: read develop's B-rep records - c30ca0216 brett19: Hidden-line fixtures: build develop's records from the fixtures' data - 5dd2509ae brett19: Hidden lines: tests of the bounded edges, face charts and placed revolutions - 1642df0ea brett19: drawing-hlr doc: what is drawn and refused on develop's records - ddcb80c8e brett19: hlr tests: a placed revolution is refused when its placement is not rigid - e4977721f brett19: Hidden lines: a traced intersection is drawn only where its spline lies on both surfaces - b3ef6ae52 brett19: Hidden lines: kernel bodies through the production prepare against closed forms - 4cd2ae062 brett19: Tests from main: the world state is a Result here - 51d7ad09e brett19: A blend's pick measures close edges on their curves, not their polylines - 11a89713c brett19: Merge fixes from the first SMLib test pass - 48fcb7aac brett19: Merge fixes from the ui test pass and the gates - abd739855 brett19: A silhouette takes its facing from the surface's normals - 85114c5a2 brett19: Clippy and rustfmt on the merged tree - 55a46569f brett19: Stepwise open checks every feature under the session's mode - 4627402e4 brett19: Clippy without SMLib: the planar-sheet edge reader is built only with it - 5fbece0ac brett19: STEP import: a ball's halves whose seams are off each other's quarter lines each form within one turn - eb78d20b0 brett19: Lid ring sketch test: find the ring under the pick, not by main's kernel's name - 3048d8c49 brett19: Viewport culling test: each box's triangles from its mesh, not 12 - dc88b80e2 brett19: Timeline chip test: a fillet that really reduces - 876203621 brett19: Edge names: a seam names its one face once; the curve-id test reads every edge kernel-neutrally - 900635710 brett19: rustfmt on the merged tree - b7e83cd7c brett19: Known failing on SMLib: two of main's new tests assume truck's box mesh and fillet torus - 63bde053a jyviko: Locales: Vietnamese for the setback-too-short refusal, now that vi is a complete catalog - 967a1caa6 brett19: Kernel rig: exact volumes for 1213's bent-tube round and 4782's bar round, rel 1e-6 - 82c821d2a brett19: After the merge: clippy's auto-deref, and the mesh-decisions list for the merged tree - 5862ee223 brett19: After the merge: main's new tests on the SMLib kernel - be78372b2 brett19: Twisted sweep: circles about a straight path are exact cylinders (solidcore#2184) - 312d14500 jyviko: After the merge: a hole that misses is found by exact boxes; a face is a one-face patch; main's mesh-box helpers gone - 6f7e51acb jyviko: After the merge: split_move's Result reaches its callers; to_local's duplicated move check goes - 8f0c79b20 jyviko: After the merge: main's two new tests take world_state's Result, as the rest of their files do - 5f4d70061 jyviko: After the merge with main: its new code on develop's exact bounds, types and thread fields - 2b2ab6627 jyviko: Cargo.lock: develop's profile, smlib and step crates at main's 0.30.1 - e6a4b0a9a jyviko: Kernel rig: main's six new sketch-only commands are exempt from a kernel case - 5acbd2e71 jyviko: Cuts leave the bodies their tools can't reach, by exact boxes (#10225 on exact geometry) - d2b202307 jyviko: Kernel rig: main's new view, rendering, appearance and settings commands are exempt from a case - 21db090ba jyviko: Kernel rig: construct.plane.axis_point gets construction cases - c1f45cae2 jyviko: Kernel rig: assembly cases for mass properties, align, find limits and moving items between parts - 084695416 jyviko: Kernel rig: export and print face cases in the import area Co-authored-by: jyviko <2501648+jyviko@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
191 lines
8.1 KiB
Rust
191 lines
8.1 KiB
Rust
//! An explicit help request prints usage to stdout and succeeds; an unknown command still fails.
|
|
|
|
use std::process::{Command, Stdio};
|
|
use std::time::{Duration, Instant};
|
|
|
|
/// Every command the CLI takes, with the name its own usage names: `inspect` is `eval`, and
|
|
/// `licenses` is `licences`.
|
|
const COMMANDS: &[(&str, &str)] = &[
|
|
("run", "run"),
|
|
("eval", "eval"),
|
|
("inspect", "eval"),
|
|
("script", "script"),
|
|
("bench-open", "bench-open"),
|
|
("bench-agent", "bench-agent"),
|
|
("snapshot", "snapshot"),
|
|
("render", "render"),
|
|
("exec", "exec"),
|
|
("commands", "commands"),
|
|
("recipe", "recipe"),
|
|
("oracle", "oracle"),
|
|
("fuzz", "fuzz"),
|
|
("fuzz-one", "fuzz-one"),
|
|
("mcp", "mcp"),
|
|
("crashes", "crashes"),
|
|
("licences", "licences"),
|
|
("licenses", "licences"),
|
|
("gpu", "gpu"),
|
|
("icon", "icon"),
|
|
("bench-edit", "bench-edit"),
|
|
("save-stress", "save-stress"),
|
|
];
|
|
|
|
/// The commands the usage lists: the aliases answer to another command's name.
|
|
const LISTED: &[&str] = &[
|
|
"run",
|
|
"eval",
|
|
"script",
|
|
"bench-open",
|
|
"bench-agent",
|
|
"snapshot",
|
|
"render",
|
|
"exec",
|
|
"commands",
|
|
"recipe",
|
|
"oracle",
|
|
"fuzz",
|
|
"mcp",
|
|
"crashes",
|
|
"licences",
|
|
"gpu",
|
|
"icon",
|
|
];
|
|
|
|
/// The command names a text mentions after `solidcraft-cli `, each one only once.
|
|
fn mentioned(text: &str) -> Vec<&str> {
|
|
let mut names: Vec<&str> = text.split("solidcraft-cli ").skip(1).filter_map(|rest| rest.split_whitespace().next()).collect();
|
|
names.sort_unstable();
|
|
names.dedup();
|
|
names
|
|
}
|
|
|
|
/// Runs the binary and waits at most `limit` for it to finish. `None` means it was still
|
|
/// running and was killed: the fuzz run `fuzz --help` used to start goes on for minutes.
|
|
fn run_within(limit: Duration, args: &[&str]) -> Option<(Option<i32>, String, String)> {
|
|
let mut child = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli")).args(args).stdout(Stdio::piped()).stderr(Stdio::piped()).spawn().unwrap();
|
|
let started = Instant::now();
|
|
loop {
|
|
match child.try_wait().unwrap() {
|
|
Some(status) => {
|
|
let out = child.wait_with_output().unwrap();
|
|
return Some((status.code(), String::from_utf8_lossy(&out.stdout).into_owned(), String::from_utf8_lossy(&out.stderr).into_owned()));
|
|
}
|
|
None if started.elapsed() >= limit => {
|
|
let _ = child.kill();
|
|
let _ = child.wait();
|
|
return None;
|
|
}
|
|
None => std::thread::sleep(Duration::from_millis(25)),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn help_prints_usage_and_succeeds() {
|
|
for arg in ["--help", "-h", "help"] {
|
|
let output = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli")).arg(arg).output().unwrap();
|
|
assert!(output.status.success(), "{arg}: {}", String::from_utf8_lossy(&output.stderr));
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
assert!(stdout.starts_with("usage:"), "{arg}: {stdout}");
|
|
assert!(stdout.contains("solidcraft-cli run"), "{arg}: {stdout}");
|
|
assert!(output.stderr.is_empty(), "{arg}: {}", String::from_utf8_lossy(&output.stderr));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn unknown_command_still_fails_with_usage() {
|
|
let output = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli")).arg("--not-a-command").output().unwrap();
|
|
assert!(!output.status.success());
|
|
assert!(output.stdout.is_empty());
|
|
assert!(String::from_utf8_lossy(&output.stderr).starts_with("error: usage:"));
|
|
}
|
|
|
|
#[test]
|
|
fn every_command_prints_its_own_usage() {
|
|
for (cmd, named) in COMMANDS {
|
|
for flag in ["--help", "-h"] {
|
|
let output = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli")).args([*cmd, flag]).output().unwrap();
|
|
assert!(output.status.success(), "{cmd} {flag}: {}", String::from_utf8_lossy(&output.stderr));
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
assert!(stdout.starts_with("usage:"), "{cmd} {flag}: {stdout}");
|
|
assert_eq!(mentioned(&stdout), vec![*named], "{cmd} {flag} printed another command's usage: {stdout}");
|
|
assert!(output.stderr.is_empty(), "{cmd} {flag}: {}", String::from_utf8_lossy(&output.stderr));
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn the_top_level_usage_still_lists_every_command() {
|
|
let output = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli")).arg("--help").output().unwrap();
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
for cmd in LISTED {
|
|
assert!(stdout.contains(&format!("solidcraft-cli {cmd}")), "{cmd}: {stdout}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn fuzz_help_does_not_start_a_fuzz_run() {
|
|
let Some((code, stdout, stderr)) = run_within(Duration::from_secs(20), &["fuzz", "--help"]) else {
|
|
panic!("`fuzz --help` kept running: it started a fuzz run instead of printing the usage");
|
|
};
|
|
assert_eq!(code, Some(0), "{stderr}");
|
|
assert!(stdout.starts_with("usage:"), "{stdout}");
|
|
assert_eq!(mentioned(&stdout), vec!["fuzz"], "{stdout}");
|
|
assert!(stderr.is_empty(), "{stderr}");
|
|
}
|
|
|
|
#[test]
|
|
fn fuzz_refuses_an_argument_it_does_not_take() {
|
|
for arg in ["--not-a-flag", "stray"] {
|
|
let Some((code, _stdout, stderr)) = run_within(Duration::from_secs(20), &["fuzz", arg]) else {
|
|
panic!("`fuzz {arg}` kept running: it started a fuzz run instead of refusing the argument");
|
|
};
|
|
assert_ne!(code, Some(0), "`fuzz {arg}` succeeded");
|
|
assert!(stderr.contains(arg), "`fuzz {arg}`: {stderr}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn render_help_keeps_the_registered_gpu_request_controls() {
|
|
for args in [vec!["--help"], vec!["render", "--help"]] {
|
|
let output = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli")).args(&args).output().unwrap();
|
|
assert!(output.status.success(), "{args:?}: {}", String::from_utf8_lossy(&output.stderr));
|
|
assert!(output.stderr.is_empty());
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
for flag in ["--progressive", "--samples", "--max-depth", "--seed", "--exposure", "--lighting", "--environment", "--tone-map"] {
|
|
assert!(stdout.contains(flag), "{args:?} lost {flag}: {stdout}");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// `--max-file-size` (#4086), with any command: the usage names it, a bad size stops the run
|
|
/// with the reason, and a design over the default limit opens once the flag raises it.
|
|
#[test]
|
|
fn max_file_size_raises_the_limit_and_refuses_bad_sizes() {
|
|
let output = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli")).arg("--help").output().unwrap();
|
|
assert!(String::from_utf8_lossy(&output.stdout).contains("--max-file-size"));
|
|
for size in ["17GB", "2", "lots"] {
|
|
let output = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli")).args(["--max-file-size", size, "exec", "file.new"]).output().unwrap();
|
|
assert!(!output.status.success(), "{size} was accepted");
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
assert!(stderr.starts_with("error: --max-file-size"), "{size}: {stderr}");
|
|
}
|
|
let output = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli")).args(["exec", "file.new", "--max-file-size=2GB"]).output().unwrap();
|
|
assert!(output.status.success(), "{}", String::from_utf8_lossy(&output.stderr));
|
|
|
|
// A sparse design file just over the default 256 MB: refused unread, then read with the flag
|
|
// (and refused for what it holds, which is no design).
|
|
let dir = std::env::temp_dir().join(format!("solidcraft-cli-4086-{}", std::process::id()));
|
|
std::fs::create_dir_all(&dir).unwrap();
|
|
let path = dir.join("big.solidcraft");
|
|
std::fs::File::create(&path).unwrap().set_len((256 << 20) + 1).unwrap();
|
|
let path = path.to_string_lossy().to_string();
|
|
let output = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli")).args(["eval", &path]).output().unwrap();
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
assert!(!output.status.success() && stderr.contains("too large") && stderr.contains("--max-file-size"), "{stderr}");
|
|
let output = Command::new(env!("CARGO_BIN_EXE_solidcraft-cli")).args(["--max-file-size", "1GB", "eval", &path]).output().unwrap();
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
assert!(!output.status.success() && !stderr.contains("too large"), "{stderr}");
|
|
let _ = std::fs::remove_dir_all(&dir);
|
|
}
|