Files
texturecraft/apps/texturecraft-cli/tests/it/main.rs
T
FredApps bd03a0411f texturecraft-cli: follow RFC-0018 (clap, thiserror, run(args, out, err), packaged completions and man pages) (#875)
* texturecraft-cli: follow RFC-0018 (clap, thiserror, run(args, out, err), packaged completions and man pages)

Closes #866. Part of storytold/craft-contrib#95.

* fix(cli): enable clap env, and close replacement and token gaps

- Enable clap's `env` feature so TEXTURECRAFT_CONTROL_TOKEN compiles in a
  standalone `-p texturecraft-cli` release build (the FreeBSD package job).
- An inherited token no longer implies --bridge; only a command-line
  --token does.
- Compare run/bake/new outputs to the path Headless::save actually writes
  (it appends .tcraft when the extension is missing).
- Apply the same replacement rule to batch (save vs open), with --in-place.
- Build man-and-completions for the host when CARGO_BUILD_TARGET is set.
- Don't panic in the blank-token test when the environment already has a
  token.

* fix(cli): require both roots for headless mcp

AGENTS.md rule 18 says an agent entry point must refuse to start without
--automation-read-root and --automation-write-root (the --read-root /
--write-root aliases here). Headless mcp now exits 2 unless both are
set; --bridge is unchanged. The missing-CLI_DOCS diagnostic also names
the host-example env -u CARGO_BUILD_TARGET prefix already used to build it.
2026-11-28 01:01:49 +01:00

49 lines
1.5 KiB
Rust

//! Integration tests, built as one test binary: each file is a module. They call `run` in-process,
//! except where a test needs the real binary (a protocol on stdio, the environment).
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod cli;
mod man_and_completions;
mod protocol;
use std::ffi::{OsStr, OsString};
use std::path::{Path, PathBuf};
/// What `run` returned and wrote.
pub struct Outcome {
pub code: i32,
pub out: String,
pub err: String,
}
pub fn invoke<I, T>(args: I) -> Outcome
where
I: IntoIterator<Item = T>,
T: Into<OsString>,
{
let (mut out, mut err) = (Vec::new(), Vec::new());
let code = texturecraft_cli::run(args, &mut out, &mut err);
Outcome { code, out: String::from_utf8_lossy(&out).into_owned(), err: String::from_utf8_lossy(&err).into_owned() }
}
/// A new, empty folder for one test.
pub fn workdir(name: &str) -> PathBuf {
let dir = std::env::temp_dir().join(format!("texturecraft-cli-{}-{name}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
dir
}
/// A small project made by `new`.
pub fn project(dir: &Path, name: &str) -> PathBuf {
let path = dir.join(name);
let made = invoke(argv(&[&"new", &"builtin:cube", &path, &"--resolution", &"128"]));
assert_eq!(made.code, 0, "{}", made.err);
path
}
/// An argument vector from parts of different types (strings, paths).
pub fn argv(parts: &[&dyn AsRef<OsStr>]) -> Vec<OsString> {
parts.iter().map(|p| p.as_ref().to_os_string()).collect()
}