diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/loop.rs | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/tests/loop.rs b/tests/loop.rs index f90d19d..4fc1da5 100644 --- a/tests/loop.rs +++ b/tests/loop.rs | |||
| @@ -345,7 +345,7 @@ fn an_empty_bash_call_is_never_approved() { | |||
| 345 | "delta": { "tool_calls": [{ | 345 | "delta": { "tool_calls": [{ |
| 346 | "index": 0, | 346 | "index": 0, |
| 347 | "id": "call_empty", | 347 | "id": "call_empty", |
| 348 | "function": { "name": "bash", "arguments": "{}" } | 348 | "function": { "name": "bash", "arguments": "{\"cmd\":\"\"}" } |
| 349 | }]}, | 349 | }]}, |
| 350 | "finish_reason": "tool_calls" | 350 | "finish_reason": "tool_calls" |
| 351 | }] | 351 | }] |
| @@ -387,3 +387,54 @@ fn an_empty_bash_call_is_never_approved() { | |||
| 387 | assert!(result.contains("`cmd` is required"), "{result}"); | 387 | assert!(result.contains("`cmd` is required"), "{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 | |||
| 391 | #[test] | ||
| 392 | fn a_tool_call_with_no_arguments_is_dropped_silently() { | ||
| 393 | let dir = temp_dir("placeholder"); | ||
| 394 | let placeholder = sse(&format!( | ||
| 395 | "data: {}\n\ndata: [DONE]\n\n", | ||
| 396 | json!({ | ||
| 397 | "choices": [{ | ||
| 398 | "delta": { "tool_calls": [{ | ||
| 399 | "index": 0, | ||
| 400 | "id": "call_ph", | ||
| 401 | "function": { "name": "bash", "arguments": "{}" } | ||
| 402 | }]}, | ||
| 403 | "finish_reason": "tool_calls" | ||
| 404 | }] | ||
| 405 | }) | ||
| 406 | )); | ||
| 407 | |||
| 408 | let base = serve_sequence(vec![placeholder]); | ||
| 409 | std::env::set_var("AGENT686_DATA", dir.join("data")); | ||
| 410 | |||
| 411 | let system = agent::system_prompt(); | ||
| 412 | let mut session = Session::create("test-model", &system).unwrap(); | ||
| 413 | let cfg = Config { | ||
| 414 | base_url: base, | ||
| 415 | api_key: "test-key".into(), | ||
| 416 | model: "test-model".into(), | ||
| 417 | session: session.id.clone(), | ||
| 418 | yolo: false, | ||
| 419 | }; | ||
| 420 | let mut history = agent::new_history(system); | ||
| 421 | let mut approver = Approver::new(false); | ||
| 422 | |||
| 423 | agent::run_turn( | ||
| 424 | &cfg, | ||
| 425 | &mut session, | ||
| 426 | &mut history, | ||
| 427 | "run something", | ||
| 428 | &AtomicBool::new(false), | ||
| 429 | &mut approver, | ||
| 430 | ) | ||
| 431 | .expect("a placeholder must not fail the turn"); | ||
| 432 | |||
| 433 | // system, user, assistant with the call removed: no tool message, no prompt. | ||
| 434 | assert_eq!(history.len(), 3, "{history:#?}"); | ||
| 435 | let assistant = history.last().unwrap(); | ||
| 436 | assert!( | ||
| 437 | assistant.get("tool_calls").is_none(), | ||
| 438 | "the placeholder must not be recorded: {assistant}" | ||
| 439 | ); | ||
| 440 | } | ||
