From e803aa488c3a95193d3e3ae358b640c299f8f121 Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 23 Nov 2026 20:36:22 +0100 Subject: License --- tests/cli.rs | 18 +++++++++++---- tests/config.rs | 13 ++++++++++- tests/doctor.rs | 7 ++++++ tests/git.rs | 22 ++++++++++++++---- tests/loop.rs | 50 ++++++++++++++++++++++++++++------------ tests/mock.rs | 12 +++++++++- tests/prompt.rs | 7 ++++++ tests/sessions.rs | 27 ++++++++++++++++++---- tests/sse.rs | 17 ++++++++++---- tests/tools.rs | 68 ++++++++++++++++++++++++++++++++++--------------------- 10 files changed, 180 insertions(+), 61 deletions(-) (limited to 'tests') diff --git a/tests/cli.rs b/tests/cli.rs index 37546b1..faedb61 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,3 +1,10 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + use std::fs; use std::path::PathBuf; use std::process::Command; @@ -52,10 +59,7 @@ fn session_ids_cannot_escape_the_sessions_directory() { #[test] fn conflicting_flags_are_rejected() { - let output = agent() - .args(["-c", "--session", "abc"]) - .output() - .unwrap(); + let output = agent().args(["-c", "--session", "abc"]).output().unwrap(); assert_eq!(output.status.code(), Some(2)); assert!(String::from_utf8_lossy(&output.stderr).contains("cannot be combined")); @@ -238,7 +242,11 @@ fn list_and_show_and_doctor_support_json() { let body: String = lines.iter().map(|line| format!("{line}\n")).collect(); fs::write(sessions.join("demo.jsonl"), body).unwrap(); - let list = agent().env("HOME", &home).args(["--list", "--json"]).output().unwrap(); + let list = agent() + .env("HOME", &home) + .args(["--list", "--json"]) + .output() + .unwrap(); assert!(list.status.success(), "{list:?}"); let list_json: serde_json::Value = serde_json::from_slice(&list.stdout).unwrap(); assert!(list_json.is_array()); diff --git a/tests/config.rs b/tests/config.rs index c090fbf..7c9bdfd 100644 --- a/tests/config.rs +++ b/tests/config.rs @@ -1,3 +1,10 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + use std::fs; use agent686::config::{Cli, Config, Provider}; @@ -43,7 +50,11 @@ fn provider_type_selects_url_and_session_header() { let opencode = Config::resolve_lenient(&cli(Some("opencode"), None)); assert_eq!(opencode.provider, Provider::OpenCode); - assert!(opencode.base_url.contains("opencode.ai"), "{}", opencode.base_url); + assert!( + opencode.base_url.contains("opencode.ai"), + "{}", + opencode.base_url + ); assert!(opencode.provider.needs_session_header()); let compatible = Config::resolve_lenient(&cli( diff --git a/tests/doctor.rs b/tests/doctor.rs index d42773f..516d8a1 100644 --- a/tests/doctor.rs +++ b/tests/doctor.rs @@ -1,3 +1,10 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + use std::fs; use std::io::{BufRead, BufReader, Write}; use std::net::TcpListener; diff --git a/tests/git.rs b/tests/git.rs index 19eced1..7a28076 100644 --- a/tests/git.rs +++ b/tests/git.rs @@ -1,3 +1,10 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + use std::fs; use std::path::PathBuf; use std::process::Command; @@ -18,9 +25,13 @@ fn repo(tag: &str) -> PathBuf { &["config", "user.email", "agent686@test"][..], &["config", "user.name", "agent686"][..], ] { - assert!( - Command::new("git").arg("-C").arg(&dir).args(args).status().unwrap().success() - ); + assert!(Command::new("git") + .arg("-C") + .arg(&dir) + .args(args) + .status() + .unwrap() + .success()); } dir } @@ -40,7 +51,10 @@ fn checkpoint_then_undo_restores_the_tree() { git::undo(&dir, &sha); assert_eq!(fs::read_to_string(dir.join("a.txt")).unwrap(), "original\n"); - assert!(!dir.join("b.txt").exists(), "untracked files must be removed"); + assert!( + !dir.join("b.txt").exists(), + "untracked files must be removed" + ); } #[test] 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 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + use std::fs; use std::io::{BufRead, BufReader, Read, Write}; use std::net::TcpListener; @@ -16,9 +23,7 @@ use agent686::session::Session; use agent686::ui::Approver; fn sse(body: &str) -> String { - format!( - "HTTP/1.1 200 OK\r\nContent-Type: text/event-stream\r\nConnection: close\r\n\r\n{body}" - ) + format!("HTTP/1.1 200 OK\r\nContent-Type: text/event-stream\r\nConnection: close\r\n\r\n{body}") } /// Serves one canned SSE response per connection, in order. @@ -197,16 +202,19 @@ fn a_denied_tool_call_is_returned_as_data() { assert!(!target.exists()); assert_eq!(history[3]["role"], "tool"); - assert!( - history[3]["content"] - .as_str() - .unwrap() - .contains("denied by the user") - ); + assert!(history[3]["content"] + .as_str() + .unwrap() + .contains("denied by the user")); assert_eq!(history[4]["content"], "understood"); } -fn tool_call(index: usize, id: &str, name: &str, arguments: serde_json::Value) -> serde_json::Value { +fn tool_call( + index: usize, + id: &str, + name: &str, + arguments: serde_json::Value, +) -> serde_json::Value { json!({ "index": index, "id": id, @@ -283,7 +291,12 @@ fn aborting_between_tool_calls_answers_every_call() { let answered: Vec = history .iter() .filter(|message| message.get("role").and_then(|r| r.as_str()) == Some("tool")) - .filter_map(|message| message.get("tool_call_id").and_then(|id| id.as_str()).map(|s| s.to_string())) + .filter_map(|message| { + message + .get("tool_call_id") + .and_then(|id| id.as_str()) + .map(|s| s.to_string()) + }) .collect(); assert_eq!(answered, vec!["call_a", "call_b", "call_c"], "{answered:?}"); @@ -410,7 +423,10 @@ fn an_empty_bash_call_is_never_approved() { let result = history[3]["content"].as_str().unwrap(); assert!(result.contains("`cmd` is present but empty"), "{result}"); - assert!(!result.contains("denied"), "must not reach an approval prompt: {result}"); + assert!( + !result.contains("denied"), + "must not reach an approval prompt: {result}" + ); } #[test] @@ -525,8 +541,14 @@ fn a_wrong_argument_key_names_both_keys() { .expect("the turn should survive a wrong key"); let result = history[3]["content"].as_str().unwrap(); - assert!(result.contains("`shell`"), "should name what arrived: {result}"); - assert!(result.contains("`cmd`"), "should name what was expected: {result}"); + assert!( + result.contains("`shell`"), + "should name what arrived: {result}" + ); + assert!( + result.contains("`cmd`"), + "should name what was expected: {result}" + ); assert!(!result.contains("denied"), "{result}"); } diff --git a/tests/mock.rs b/tests/mock.rs index 3b2abdd..10f3b76 100644 --- a/tests/mock.rs +++ b/tests/mock.rs @@ -1,3 +1,10 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + use std::io::{BufRead, BufReader, Read, Write}; use std::net::TcpListener; use std::sync::atomic::AtomicBool; @@ -272,7 +279,10 @@ fn retries_a_rate_limit_and_keeps_the_same_session_header() { let first = rx.recv().expect("first request").to_ascii_lowercase(); let second = rx.recv().expect("second request").to_ascii_lowercase(); assert!(first.contains("x-opencode-session: testsession"), "{first}"); - assert!(second.contains("x-opencode-session: testsession"), "{second}"); + assert!( + second.contains("x-opencode-session: testsession"), + "{second}" + ); } #[test] diff --git a/tests/prompt.rs b/tests/prompt.rs index 38fbe40..97a3fa9 100644 --- a/tests/prompt.rs +++ b/tests/prompt.rs @@ -1,3 +1,10 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + use std::fs; use std::path::PathBuf; diff --git a/tests/sessions.rs b/tests/sessions.rs index 4f8ebd5..e382673 100644 --- a/tests/sessions.rs +++ b/tests/sessions.rs @@ -1,3 +1,10 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + use std::fs; use std::path::PathBuf; use std::process::Command; @@ -92,7 +99,9 @@ fn a_session_cannot_be_open_twice() { let system = json!({ "role": "system", "content": "x" }); let first = Session::create_as("locked".into(), "m", &system).unwrap(); - let error = Session::open("locked").err().expect("second open must fail"); + let error = Session::open("locked") + .err() + .expect("second open must fail"); assert!(error.contains("already open"), "{error}"); drop(first); @@ -127,8 +136,10 @@ fn a_torn_utf8_line_does_not_brick_a_session() { br#"{"t":"header","session":"torn","model":"m","cwd":"/tmp","system":{"role":"system","content":"s"}} "#, ); - raw.extend_from_slice(br#"{"t":"msg","role":"user","content":"hello"} -"#); + raw.extend_from_slice( + br#"{"t":"msg","role":"user","content":"hello"} +"#, + ); // A killed write that split a multi-byte character. raw.extend_from_slice(b"{\"t\":\"msg\",\"role\":\"user\",\"content\":\"caf\xc3\"}\n"); fs::write(sessions.join("torn.jsonl"), raw).unwrap(); @@ -156,7 +167,10 @@ fn last_reply_prefers_content_and_falls_back_to_reasoning() { ) .unwrap(); session - .append(&json!({ "role": "assistant", "content": null }), Some("only thinking")) + .append( + &json!({ "role": "assistant", "content": null }), + Some("only thinking"), + ) .unwrap(); drop(session); @@ -168,7 +182,10 @@ fn last_reply_prefers_content_and_falls_back_to_reasoning() { // With no content anywhere, reasoning is the fallback. let mut session = Session::create_as("reasoning-only".into(), "m", &system).unwrap(); session - .append(&json!({ "role": "assistant", "content": null }), Some("thoughts")) + .append( + &json!({ "role": "assistant", "content": null }), + Some("thoughts"), + ) .unwrap(); drop(session); let (opened, _system, _messages) = Session::open("reasoning-only").unwrap(); diff --git a/tests/sse.rs b/tests/sse.rs index 7994a0a..37915d3 100644 --- a/tests/sse.rs +++ b/tests/sse.rs @@ -1,3 +1,10 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + use agent686::provider::SseDecoder; #[test] @@ -10,7 +17,10 @@ fn reassembles_lines_split_at_every_byte() { for byte in wire.as_bytes() { got.extend(decoder.feed(std::slice::from_ref(byte))); } - assert_eq!(got, vec!["{\"a\":\"café ✓\"}".to_string(), "[DONE]".to_string()]); + assert_eq!( + got, + vec!["{\"a\":\"café ✓\"}".to_string(), "[DONE]".to_string()] + ); } #[test] @@ -26,10 +36,7 @@ fn keeps_incomplete_line_until_finished() { let mut decoder = SseDecoder::new(); assert!(decoder.feed(b"data: {\"x\"").is_empty()); assert!(decoder.feed(b":1}").is_empty()); - assert_eq!( - decoder.feed(b"\n"), - vec!["{\"x\":1}".to_string()] - ); + assert_eq!(decoder.feed(b"\n"), vec!["{\"x\":1}".to_string()]); } #[test] diff --git a/tests/tools.rs b/tests/tools.rs index 0321bf8..a5099e8 100644 --- a/tests/tools.rs +++ b/tests/tools.rs @@ -1,3 +1,10 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + use std::fs; use std::path::PathBuf; use std::time::Duration; @@ -24,9 +31,12 @@ fn edit_refuses_ambiguous_and_missing_text() { let path = dir.join("a.txt"); fs::write(&path, "alpha\nbeta\nalpha\n").unwrap(); - let error = tools::plan("edit", &json!({ "path": path, "old": "alpha", "new": "gamma" })) - .err() - .expect("ambiguous edit must fail"); + let error = tools::plan( + "edit", + &json!({ "path": path, "old": "alpha", "new": "gamma" }), + ) + .err() + .expect("ambiguous edit must fail"); assert!(error.contains("appears 2 times"), "{error}"); assert!(error.contains("lines 1, 3"), "{error}"); @@ -128,15 +138,23 @@ fn bash_reports_exit_code_and_times_out() { assert!(text.contains("hi"), "{text}"); assert!(text.contains("[exit 3]"), "{text}"); - let text = shell::bash(&json!({ "cmd": "sleep 5" }), Duration::from_millis(150), &AtomicBool::new(false)).unwrap(); + let text = shell::bash( + &json!({ "cmd": "sleep 5" }), + Duration::from_millis(150), + &AtomicBool::new(false), + ) + .unwrap(); assert!(text.contains("timed out after"), "{text}"); } #[test] fn bash_rejects_a_missing_cwd() { - let error = run("bash", &json!({ "cmd": "true", "cwd": "/nonexistent-dir-xyz" })) - .err() - .expect("missing cwd must fail"); + let error = run( + "bash", + &json!({ "cmd": "true", "cwd": "/nonexistent-dir-xyz" }), + ) + .err() + .expect("missing cwd must fail"); assert!(error.contains("cwd is not a directory"), "{error}"); } @@ -210,11 +228,7 @@ fn read_handles_a_missing_trailing_newline() { #[test] fn grep_uses_regular_expressions_by_default() { let dir = temp_dir("grep-regex"); - fs::write( - dir.join("f.rs"), - "fn main() {\n fn other() {\n}\n", - ) - .unwrap(); + fs::write(dir.join("f.rs"), "fn main() {\n fn other() {\n}\n").unwrap(); let text = run("grep", &json!({ "pattern": r"fn\s+main", "path": dir })).unwrap(); assert_eq!(text.lines().count(), 1, "{text}"); @@ -283,7 +297,11 @@ fn bash_timeout_kills_the_whole_process_group() { assert!(text.contains("timed out"), "{text}"); std::thread::sleep(Duration::from_millis(300)); - let pid: i32 = fs::read_to_string(&pidfile).unwrap().trim().parse().unwrap(); + let pid: i32 = fs::read_to_string(&pidfile) + .unwrap() + .trim() + .parse() + .unwrap(); assert!(!running(pid), "grandchild {pid} survived the timeout"); } @@ -309,7 +327,10 @@ fn bash_does_not_inherit_the_api_key() { ) .unwrap(); std::env::remove_var("OPENCODE_API_KEY"); - assert!(text.contains('0'), "the key was visible to the child: {text}"); + assert!( + text.contains('0'), + "the key was visible to the child: {text}" + ); } #[test] @@ -342,8 +363,11 @@ fn edit_refuses_when_the_file_changed_while_waiting_for_approval() { let path = dir.join("f.txt"); fs::write(&path, "alpha\n").unwrap(); - let change = tools::plan("edit", &json!({ "path": path, "old": "alpha", "new": "beta" })) - .unwrap(); + let change = tools::plan( + "edit", + &json!({ "path": path, "old": "alpha", "new": "beta" }), + ) + .unwrap(); // Something else (cargo fmt, the user's editor) ran before approval. fs::write(&path, "alpha\nalpha\n").unwrap(); @@ -470,11 +494,7 @@ fn bash_stderr_alone_is_labelled() { #[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(); + 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)); } @@ -507,11 +527,7 @@ fn validate_requires_content_and_new_but_allows_empty() { fn a_pipeline_that_exceeds_the_file_limit_is_reported() { // 70 MiB through a pipeline: the grandchild (head) is the writer, so only the // file-length check can detect the limit. - let text = run( - "bash", - &json!({ "cmd": "yes | head -c 70000000" }), - ) - .unwrap(); + let text = run("bash", &json!({ "cmd": "yes | head -c 70000000" })).unwrap(); assert!( text.contains("output exceeded 64 MiB"), "should report the file limit: {text}" -- cgit v1.2.3