diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/loop.rs | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/tests/loop.rs b/tests/loop.rs index 73592f0..06e477c 100644 --- a/tests/loop.rs +++ b/tests/loop.rs | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | /* | ||
| 2 | * This file is part of agent686 | ||
| 3 | * Copyright (C) 2026 Salmonik <salmon@2137697.xyz> | ||
| 4 | * SPDX-License-Identifier: GPL-3.0-or-later | ||
| 5 | * https://git.2137697.xyz/agent686 | ||
| 6 | */ | ||
| 7 | |||
| 1 | use std::fs; | 8 | use std::fs; |
| 2 | use std::io::{BufRead, BufReader, Read, Write}; | 9 | use std::io::{BufRead, BufReader, Read, Write}; |
| 3 | use std::net::TcpListener; | 10 | use std::net::TcpListener; |
| @@ -16,9 +23,7 @@ use agent686::session::Session; | |||
| 16 | use agent686::ui::Approver; | 23 | use agent686::ui::Approver; |
| 17 | 24 | ||
| 18 | fn sse(body: &str) -> String { | 25 | fn sse(body: &str) -> String { |
| 19 | format!( | 26 | format!("HTTP/1.1 200 OK\r\nContent-Type: text/event-stream\r\nConnection: close\r\n\r\n{body}") |
| 20 | "HTTP/1.1 200 OK\r\nContent-Type: text/event-stream\r\nConnection: close\r\n\r\n{body}" | ||
| 21 | ) | ||
| 22 | } | 27 | } |
| 23 | 28 | ||
| 24 | /// Serves one canned SSE response per connection, in order. | 29 | /// Serves one canned SSE response per connection, in order. |
| @@ -197,16 +202,19 @@ fn a_denied_tool_call_is_returned_as_data() { | |||
| 197 | 202 | ||
| 198 | assert!(!target.exists()); | 203 | assert!(!target.exists()); |
| 199 | assert_eq!(history[3]["role"], "tool"); | 204 | assert_eq!(history[3]["role"], "tool"); |
| 200 | assert!( | 205 | assert!(history[3]["content"] |
| 201 | history[3]["content"] | 206 | .as_str() |
| 202 | .as_str() | 207 | .unwrap() |
| 203 | .unwrap() | 208 | .contains("denied by the user")); |
| 204 | .contains("denied by the user") | ||
| 205 | ); | ||
| 206 | assert_eq!(history[4]["content"], "understood"); | 209 | assert_eq!(history[4]["content"], "understood"); |
| 207 | } | 210 | } |
| 208 | 211 | ||
| 209 | fn tool_call(index: usize, id: &str, name: &str, arguments: serde_json::Value) -> serde_json::Value { | 212 | fn tool_call( |
| 213 | index: usize, | ||
| 214 | id: &str, | ||
| 215 | name: &str, | ||
| 216 | arguments: serde_json::Value, | ||
| 217 | ) -> serde_json::Value { | ||
| 210 | json!({ | 218 | json!({ |
| 211 | "index": index, | 219 | "index": index, |
| 212 | "id": id, | 220 | "id": id, |
| @@ -283,7 +291,12 @@ fn aborting_between_tool_calls_answers_every_call() { | |||
| 283 | let answered: Vec<String> = history | 291 | let answered: Vec<String> = history |
| 284 | .iter() | 292 | .iter() |
| 285 | .filter(|message| message.get("role").and_then(|r| r.as_str()) == Some("tool")) | 293 | .filter(|message| message.get("role").and_then(|r| r.as_str()) == Some("tool")) |
| 286 | .filter_map(|message| message.get("tool_call_id").and_then(|id| id.as_str()).map(|s| s.to_string())) | 294 | .filter_map(|message| { |
| 295 | message | ||
| 296 | .get("tool_call_id") | ||
| 297 | .and_then(|id| id.as_str()) | ||
| 298 | .map(|s| s.to_string()) | ||
| 299 | }) | ||
| 287 | .collect(); | 300 | .collect(); |
| 288 | assert_eq!(answered, vec!["call_a", "call_b", "call_c"], "{answered:?}"); | 301 | assert_eq!(answered, vec!["call_a", "call_b", "call_c"], "{answered:?}"); |
| 289 | 302 | ||
| @@ -410,7 +423,10 @@ fn an_empty_bash_call_is_never_approved() { | |||
| 410 | 423 | ||
| 411 | let result = history[3]["content"].as_str().unwrap(); | 424 | let result = history[3]["content"].as_str().unwrap(); |
| 412 | assert!(result.contains("`cmd` is present but empty"), "{result}"); | 425 | assert!(result.contains("`cmd` is present but empty"), "{result}"); |
| 413 | assert!(!result.contains("denied"), "must not reach an approval prompt: {result}"); | 426 | assert!( |
| 427 | !result.contains("denied"), | ||
| 428 | "must not reach an approval prompt: {result}" | ||
| 429 | ); | ||
| 414 | } | 430 | } |
| 415 | 431 | ||
| 416 | #[test] | 432 | #[test] |
| @@ -525,8 +541,14 @@ fn a_wrong_argument_key_names_both_keys() { | |||
| 525 | .expect("the turn should survive a wrong key"); | 541 | .expect("the turn should survive a wrong key"); |
| 526 | 542 | ||
| 527 | let result = history[3]["content"].as_str().unwrap(); | 543 | let result = history[3]["content"].as_str().unwrap(); |
| 528 | assert!(result.contains("`shell`"), "should name what arrived: {result}"); | 544 | assert!( |
| 529 | assert!(result.contains("`cmd`"), "should name what was expected: {result}"); | 545 | result.contains("`shell`"), |
| 546 | "should name what arrived: {result}" | ||
| 547 | ); | ||
| 548 | assert!( | ||
| 549 | result.contains("`cmd`"), | ||
| 550 | "should name what was expected: {result}" | ||
| 551 | ); | ||
| 530 | assert!(!result.contains("denied"), "{result}"); | 552 | assert!(!result.contains("denied"), "{result}"); |
| 531 | } | 553 | } |
| 532 | 554 | ||
