mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-01 18:24:54 -06:00
* #7124: mcp refuses to start without both automation roots, and refuses --connect Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * #7124: control protocol says --connect is refused; test folder comment matches Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * #7124: refuse --connect without a value; test folders removed by Drop guards Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * #7124: scratch folders retry only a name that exists Scratch::new and Folders::new retried every create_dir failure, so a missing or read-only temp folder looped forever instead of failing the test (CodeRabbit). Retry only AlreadyExists; any other error panics with the path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * #7124: mcp's headless session is built by a function the unit tests reach SonarCloud's new-code coverage was 57%: the session set-up after the root checks ran only in the subprocess integration tests, which coverage does not see. headless_mcp builds the confined session and applies --author; mcp_headless_session_takes_the_author_flag covers it without confining the test process. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
50 lines
1.9 KiB
Rust
50 lines
1.9 KiB
Rust
//! A reader that closes stdout early (`wordcraft-cli commands --json | head`) must end the CLI
|
|
//! quietly with exit 0, never with a panic (#508).
|
|
|
|
use std::io::{Read, Write};
|
|
use std::process::{Command, Stdio};
|
|
|
|
fn cli() -> Command {
|
|
Command::new(env!("CARGO_BIN_EXE_wordcraft-cli"))
|
|
}
|
|
|
|
#[test]
|
|
fn commands_json_into_a_closed_pipe_exits_quietly() {
|
|
let mut child = cli().args(["commands", "--json"]).stdout(Stdio::piped()).stderr(Stdio::piped()).spawn().unwrap();
|
|
// The listing is far larger than a pipe buffer: read a little, then hang up like `head -c`.
|
|
let mut stdout = child.stdout.take().unwrap();
|
|
let mut first = [0u8; 16];
|
|
stdout.read_exact(&mut first).unwrap();
|
|
drop(stdout);
|
|
let out = child.wait_with_output().unwrap();
|
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
|
assert!(out.status.success(), "status {:?}, stderr: {stderr}", out.status);
|
|
assert!(!stderr.contains("panicked"), "stderr: {stderr}");
|
|
}
|
|
|
|
#[test]
|
|
fn mcp_server_ends_cleanly_when_its_client_closes_stdout() {
|
|
// The server starts only with both roots (#7124); the temporary folder serves as both.
|
|
let root = std::env::temp_dir();
|
|
let mut child = cli()
|
|
.arg("mcp")
|
|
.arg("--automation-read-root")
|
|
.arg(&root)
|
|
.arg("--automation-write-root")
|
|
.arg(&root)
|
|
.stdin(Stdio::piped())
|
|
.stdout(Stdio::piped())
|
|
.stderr(Stdio::piped())
|
|
.spawn()
|
|
.unwrap();
|
|
drop(child.stdout.take());
|
|
let mut stdin = child.stdin.take().unwrap();
|
|
// The reply to this request has nowhere to go.
|
|
let _ = stdin.write_all(b"{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"ping\"}\n");
|
|
drop(stdin);
|
|
let out = child.wait_with_output().unwrap();
|
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
|
assert!(out.status.success(), "status {:?}, stderr: {stderr}", out.status);
|
|
assert!(!stderr.contains("panicked"), "stderr: {stderr}");
|
|
}
|