Craft Anything: understand how any software works, and craft your own.
Rust
The CLI's capabilities list keeps Clean room's refusal of target tools (#323)
BFlata9121b3cf3f6
diff --git a/apps/craft-anything-cli/src/main.rs b/apps/craft-anything-cli/src/main.rsindex 4570ea2b..696cdab5 100644--- a/apps/craft-anything-cli/src/main.rs+++ b/apps/craft-anything-cli/src/main.rs@@ -332,7 +332,11 @@ fn capabilities(cli: &Cli, f: Format) -> u8 {.in_toolset(*t).map(|s| {let a = engine.availability(s, &session);- json!({"tool": s.id, "available": a.available || s.requires == Requires::Target, "needs_target": s.requires == Requires::Target, "reason": if s.requires == Requires::Target { None } else { a.reason }})+ // Before anything is open a target tool is still offered (needs_target says what+ // it waits for), but not one the mode refuses (#249).+ let refused = session.clean_room() && !craft_anything_engine::clean_room::allows(s.id);+ let waived = s.requires == Requires::Target && !refused;+ json!({"tool": s.id, "available": a.available || waived, "needs_target": s.requires == Requires::Target, "reason": if waived { None } else { a.reason }})}).collect();json!({"id": t.id(), "title": t.title(), "tools": tools})diff --git a/apps/craft-anything-cli/tests/cli.rs b/apps/craft-anything-cli/tests/cli.rsindex cda37c94..2d833679 100644--- a/apps/craft-anything-cli/tests/cli.rs+++ b/apps/craft-anything-cli/tests/cli.rs@@ -23,6 +23,24 @@ fn commands_and_exit_codes() {assert_eq!(e["error"]["code"], "bad_input");}+/// #249: in Clean room a target tool the mode refuses was listed as available, because nothing+/// being open yet was waived for every target tool.+#[test]+fn capabilities_keep_the_clean_room_refusal() {+ let cfg = tempfile::tempdir().unwrap();+ let tool = |args: &[&str], id: &str| {+ let out = cli(args, cfg.path());+ let v: Value = serde_json::from_slice(&out.stdout).unwrap();+ let tools = v["toolsets"].as_array().unwrap().iter().flat_map(|t| t["tools"].as_array().unwrap().clone());+ tools.into_iter().find(|t| t["tool"] == id).unwrap_or_else(|| panic!("{id} not in {v}"))+ };+ let clean = tool(&["--format", "json", "capabilities"], "native_function_pseudocode");+ assert_eq!((clean["available"].as_bool(), clean["needs_target"].as_bool()), (Some(false), Some(true)), "{clean}");+ assert!(clean["reason"].as_str().is_some_and(|r| !r.is_empty()), "{clean}");+ let deep = tool(&["--deep", "--format", "json", "capabilities"], "native_function_pseudocode");+ assert_eq!((deep["available"].as_bool(), deep["reason"].is_null()), (Some(true), true), "{deep}");+}+/// After the tool name, `--project` is the tool's own option when it has one (it used to be taken/// as the global investigation folder, which was then created there).#[test]