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/loop.rs | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++------- tests/tools.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/loop.rs b/tests/loop.rs index 4fc1da5..e913302 100644 --- a/tests/loop.rs +++ b/tests/loop.rs @@ -384,12 +384,12 @@ fn an_empty_bash_call_is_never_approved() { .expect("the turn should survive a malformed call"); let result = history[3]["content"].as_str().unwrap(); - assert!(result.contains("`cmd` is required"), "{result}"); + assert!(result.contains("`cmd` is present but empty"), "{result}"); assert!(!result.contains("denied"), "must not reach an approval prompt: {result}"); } #[test] -fn a_tool_call_with_no_arguments_is_dropped_silently() { +fn a_tool_call_with_no_arguments_is_reported_to_the_model() { let dir = temp_dir("placeholder"); let placeholder = sse(&format!( "data: {}\n\ndata: [DONE]\n\n", @@ -405,7 +405,12 @@ fn a_tool_call_with_no_arguments_is_dropped_silently() { }) )); - let base = serve_sequence(vec![placeholder]); + let final_round = sse( + "data: {\"choices\":[{\"delta\":{\"content\":\"ok\"},\"finish_reason\":\"stop\"}]}\n\n\ + data: [DONE]\n\n", + ); + + let base = serve_sequence(vec![placeholder, final_round]); std::env::set_var("AGENT686_DATA", dir.join("data")); let system = agent::system_prompt(); @@ -430,11 +435,62 @@ fn a_tool_call_with_no_arguments_is_dropped_silently() { ) .expect("a placeholder must not fail the turn"); - // system, user, assistant with the call removed: no tool message, no prompt. - assert_eq!(history.len(), 3, "{history:#?}"); - let assistant = history.last().unwrap(); - assert!( - assistant.get("tool_calls").is_none(), - "the placeholder must not be recorded: {assistant}" + // The named call is kept and answered, so the model can retry instead of + // silently losing it: system, user, assistant, tool, assistant. + assert_eq!(history.len(), 5, "{history:#?}"); + let result = history[3]["content"].as_str().unwrap(); + assert!(result.contains("no arguments at all"), "{result}"); + assert!(result.contains("retry"), "{result}"); +} + +#[test] +fn a_wrong_argument_key_names_both_keys() { + let dir = temp_dir("wrong-key"); + let call = sse(&format!( + "data: {}\n\ndata: [DONE]\n\n", + json!({ + "choices": [{ + "delta": { "tool_calls": [{ + "index": 0, + "id": "call_wrong", + "function": { "name": "bash", "arguments": "{\"command\":\"ls\"}" } + }]}, + "finish_reason": "tool_calls" + }] + }) + )); + let final_round = sse( + "data: {\"choices\":[{\"delta\":{\"content\":\"ok\"},\"finish_reason\":\"stop\"}]}\n\n\ + data: [DONE]\n\n", ); + + let base = serve_sequence(vec![call, final_round]); + std::env::set_var("AGENT686_DATA", dir.join("data")); + + let system = agent::system_prompt(); + let mut session = Session::create("test-model", &system).unwrap(); + let cfg = Config { + base_url: base, + api_key: "test-key".into(), + model: "test-model".into(), + session: session.id.clone(), + yolo: false, + }; + let mut history = agent::new_history(system); + let mut approver = Approver::new(false); + + agent::run_turn( + &cfg, + &mut session, + &mut history, + "run it", + &AtomicBool::new(false), + &mut approver, + ) + .expect("the turn should survive a wrong key"); + + let result = history[3]["content"].as_str().unwrap(); + assert!(result.contains("`command`"), "should name what arrived: {result}"); + assert!(result.contains("`cmd`"), "should name what was expected: {result}"); + assert!(!result.contains("denied"), "{result}"); } 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