aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/loop.rs74
-rw-r--r--tests/tools.rs56
2 files changed, 121 insertions, 9 deletions
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() {
384 .expect("the turn should survive a malformed call"); 384 .expect("the turn should survive a malformed call");
385 385
386 let result = history[3]["content"].as_str().unwrap(); 386 let result = history[3]["content"].as_str().unwrap();
387 assert!(result.contains("`cmd` is required"), "{result}"); 387 assert!(result.contains("`cmd` is present but empty"), "{result}");
388 assert!(!result.contains("denied"), "must not reach an approval prompt: {result}"); 388 assert!(!result.contains("denied"), "must not reach an approval prompt: {result}");
389} 389}
390 390
391#[test] 391#[test]
392fn a_tool_call_with_no_arguments_is_dropped_silently() { 392fn a_tool_call_with_no_arguments_is_reported_to_the_model() {
393 let dir = temp_dir("placeholder"); 393 let dir = temp_dir("placeholder");
394 let placeholder = sse(&format!( 394 let placeholder = sse(&format!(
395 "data: {}\n\ndata: [DONE]\n\n", 395 "data: {}\n\ndata: [DONE]\n\n",
@@ -405,7 +405,12 @@ fn a_tool_call_with_no_arguments_is_dropped_silently() {
405 }) 405 })
406 )); 406 ));
407 407
408 let base = serve_sequence(vec![placeholder]); 408 let final_round = sse(
409 "data: {\"choices\":[{\"delta\":{\"content\":\"ok\"},\"finish_reason\":\"stop\"}]}\n\n\
410 data: [DONE]\n\n",
411 );
412
413 let base = serve_sequence(vec![placeholder, final_round]);
409 std::env::set_var("AGENT686_DATA", dir.join("data")); 414 std::env::set_var("AGENT686_DATA", dir.join("data"));
410 415
411 let system = agent::system_prompt(); 416 let system = agent::system_prompt();
@@ -430,11 +435,62 @@ fn a_tool_call_with_no_arguments_is_dropped_silently() {
430 ) 435 )
431 .expect("a placeholder must not fail the turn"); 436 .expect("a placeholder must not fail the turn");
432 437
433 // system, user, assistant with the call removed: no tool message, no prompt. 438 // The named call is kept and answered, so the model can retry instead of
434 assert_eq!(history.len(), 3, "{history:#?}"); 439 // silently losing it: system, user, assistant, tool, assistant.
435 let assistant = history.last().unwrap(); 440 assert_eq!(history.len(), 5, "{history:#?}");
436 assert!( 441 let result = history[3]["content"].as_str().unwrap();
437 assistant.get("tool_calls").is_none(), 442 assert!(result.contains("no arguments at all"), "{result}");
438 "the placeholder must not be recorded: {assistant}" 443 assert!(result.contains("retry"), "{result}");
444}
445
446#[test]
447fn a_wrong_argument_key_names_both_keys() {
448 let dir = temp_dir("wrong-key");
449 let call = sse(&format!(
450 "data: {}\n\ndata: [DONE]\n\n",
451 json!({
452 "choices": [{
453 "delta": { "tool_calls": [{
454 "index": 0,
455 "id": "call_wrong",
456 "function": { "name": "bash", "arguments": "{\"command\":\"ls\"}" }
457 }]},
458 "finish_reason": "tool_calls"
459 }]
460 })
461 ));
462 let final_round = sse(
463 "data: {\"choices\":[{\"delta\":{\"content\":\"ok\"},\"finish_reason\":\"stop\"}]}\n\n\
464 data: [DONE]\n\n",
439 ); 465 );
466
467 let base = serve_sequence(vec![call, final_round]);
468 std::env::set_var("AGENT686_DATA", dir.join("data"));
469
470 let system = agent::system_prompt();
471 let mut session = Session::create("test-model", &system).unwrap();
472 let cfg = Config {
473 base_url: base,
474 api_key: "test-key".into(),
475 model: "test-model".into(),
476 session: session.id.clone(),
477 yolo: false,
478 };
479 let mut history = agent::new_history(system);
480 let mut approver = Approver::new(false);
481
482 agent::run_turn(
483 &cfg,
484 &mut session,
485 &mut history,
486 "run it",
487 &AtomicBool::new(false),
488 &mut approver,
489 )
490 .expect("the turn should survive a wrong key");
491
492 let result = history[3]["content"].as_str().unwrap();
493 assert!(result.contains("`command`"), "should name what arrived: {result}");
494 assert!(result.contains("`cmd`"), "should name what was expected: {result}");
495 assert!(!result.contains("denied"), "{result}");
440} 496}
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() {
434 // Empty content is how you create an empty file. 434 // Empty content is how you create an empty file.
435 assert!(validate("write", &json!({ "path": "a", "content": "" })).is_ok()); 435 assert!(validate("write", &json!({ "path": "a", "content": "" })).is_ok());
436} 436}
437
438#[test]
439fn bash_keeps_stderr_separate_from_stdout() {
440 let text = run(
441 "bash",
442 &json!({ "cmd": "printf 'out\\n'; printf 'err\\n' >&2; exit 2" }),
443 )
444 .unwrap();
445
446 assert!(text.contains("[stdout]"), "{text}");
447 assert!(text.contains("[stderr]"), "{text}");
448 assert!(text.contains("[exit 2]"), "{text}");
449 let stdout_at = text.find("[stdout]").unwrap();
450 let stderr_at = text.find("[stderr]").unwrap();
451 assert!(stdout_at < stderr_at, "{text}");
452 assert!(text.contains("out"), "{text}");
453 assert!(text.contains("err"), "{text}");
454}
455
456#[test]
457fn bash_stdout_alone_is_not_labelled() {
458 let text = run("bash", &json!({ "cmd": "echo hello" })).unwrap();
459 assert!(!text.contains("[stdout]"), "no label needed: {text}");
460 assert!(text.contains("hello"), "{text}");
461}
462
463#[test]
464fn bash_stderr_alone_is_labelled() {
465 let text = run("bash", &json!({ "cmd": "echo problem >&2" })).unwrap();
466 assert!(text.contains("[stderr]"), "{text}");
467 assert!(text.contains("problem"), "{text}");
468}
469
470#[test]
471fn bash_honours_a_per_call_timeout() {
472 let started = std::time::Instant::now();
473 let text = run(
474 "bash",
475 &json!({ "cmd": "sleep 5", "timeout_seconds": 1 }),
476 )
477 .unwrap();
478 assert!(text.contains("timed out after 1.0s"), "{text}");
479 assert!(started.elapsed() < std::time::Duration::from_secs(4));
480}
481
482#[test]
483fn bash_honours_a_per_call_output_budget() {
484 let text = run(
485 "bash",
486 &json!({ "cmd": "yes | head -c 200000", "max_bytes": 4096 }),
487 )
488 .unwrap();
489 assert!(text.contains("bytes omitted"), "{text}");
490 assert!(text.contains("output truncated"), "{text}");
491 assert!(text.len() < 10_000, "output was {} bytes", text.len());
492}