From 6df7a6403d88a4492ab6ea1c519dcae3a202be96 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 18 Nov 2026 12:01:38 +0100 Subject: 0.9.0: distinguishable tool errors, separated stderr, configurable limits From a field report porting a Neovim config to Helix: - validate() now separates 'empty value', 'wrong key (here is what you sent)' and 'no arguments at all, retry' instead of one false message for all four causes - named calls with no arguments are answered rather than dropped silently - bash keeps stdout and stderr in labelled sections when both produce output - bash gains timeout_seconds (1-600) and max_bytes, and says when output was cut - tool lines/results carry [step.call] labels when a step has several calls - invalid JSON errors include a preview of what arrived --- tests/tools.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'tests/tools.rs') diff --git a/tests/tools.rs b/tests/tools.rs index a400df0..e54b5ff 100644 --- a/tests/tools.rs +++ b/tests/tools.rs @@ -434,3 +434,59 @@ fn validate_rejects_calls_that_cannot_run() { // Empty content is how you create an empty file. assert!(validate("write", &json!({ "path": "a", "content": "" })).is_ok()); } + +#[test] +fn bash_keeps_stderr_separate_from_stdout() { + let text = run( + "bash", + &json!({ "cmd": "printf 'out\\n'; printf 'err\\n' >&2; exit 2" }), + ) + .unwrap(); + + assert!(text.contains("[stdout]"), "{text}"); + assert!(text.contains("[stderr]"), "{text}"); + assert!(text.contains("[exit 2]"), "{text}"); + let stdout_at = text.find("[stdout]").unwrap(); + let stderr_at = text.find("[stderr]").unwrap(); + assert!(stdout_at < stderr_at, "{text}"); + assert!(text.contains("out"), "{text}"); + assert!(text.contains("err"), "{text}"); +} + +#[test] +fn bash_stdout_alone_is_not_labelled() { + let text = run("bash", &json!({ "cmd": "echo hello" })).unwrap(); + assert!(!text.contains("[stdout]"), "no label needed: {text}"); + assert!(text.contains("hello"), "{text}"); +} + +#[test] +fn bash_stderr_alone_is_labelled() { + let text = run("bash", &json!({ "cmd": "echo problem >&2" })).unwrap(); + assert!(text.contains("[stderr]"), "{text}"); + assert!(text.contains("problem"), "{text}"); +} + +#[test] +fn bash_honours_a_per_call_timeout() { + let started = std::time::Instant::now(); + let text = run( + "bash", + &json!({ "cmd": "sleep 5", "timeout_seconds": 1 }), + ) + .unwrap(); + assert!(text.contains("timed out after 1.0s"), "{text}"); + assert!(started.elapsed() < std::time::Duration::from_secs(4)); +} + +#[test] +fn bash_honours_a_per_call_output_budget() { + let text = run( + "bash", + &json!({ "cmd": "yes | head -c 200000", "max_bytes": 4096 }), + ) + .unwrap(); + assert!(text.contains("bytes omitted"), "{text}"); + assert!(text.contains("output truncated"), "{text}"); + assert!(text.len() < 10_000, "output was {} bytes", text.len()); +} -- cgit v1.2.3