aboutsummaryrefslogtreecommitdiffstats
path: root/tests/loop.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/loop.rs')
-rw-r--r--tests/loop.rs74
1 files changed, 65 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}