aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorsalmonik <salmon@2137697.xyz>2026-11-23 20:36:22 +0100
committersalmonik <salmon@2137697.xyz>2026-11-23 20:36:22 +0100
commite803aa488c3a95193d3e3ae358b640c299f8f121 (patch)
tree0af80401445159ca40a8ab3d7bbf39094ab5db77 /tests
parent0.12.1: accept `command` as an alias for `cmd` in bash (diff)
downloadagent686-e803aa488c3a95193d3e3ae358b640c299f8f121.tar.gz
agent686-e803aa488c3a95193d3e3ae358b640c299f8f121.zip
License
Diffstat (limited to 'tests')
-rw-r--r--tests/cli.rs18
-rw-r--r--tests/config.rs13
-rw-r--r--tests/doctor.rs7
-rw-r--r--tests/git.rs22
-rw-r--r--tests/loop.rs50
-rw-r--r--tests/mock.rs12
-rw-r--r--tests/prompt.rs7
-rw-r--r--tests/sessions.rs27
-rw-r--r--tests/sse.rs17
-rw-r--r--tests/tools.rs68
10 files changed, 180 insertions, 61 deletions
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 @@
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
1use std::fs; 8use std::fs;
2use std::path::PathBuf; 9use std::path::PathBuf;
3use std::process::Command; 10use std::process::Command;
@@ -52,10 +59,7 @@ fn session_ids_cannot_escape_the_sessions_directory() {
52 59
53#[test] 60#[test]
54fn conflicting_flags_are_rejected() { 61fn conflicting_flags_are_rejected() {
55 let output = agent() 62 let output = agent().args(["-c", "--session", "abc"]).output().unwrap();
56 .args(["-c", "--session", "abc"])
57 .output()
58 .unwrap();
59 assert_eq!(output.status.code(), Some(2)); 63 assert_eq!(output.status.code(), Some(2));
60 assert!(String::from_utf8_lossy(&output.stderr).contains("cannot be combined")); 64 assert!(String::from_utf8_lossy(&output.stderr).contains("cannot be combined"));
61 65
@@ -238,7 +242,11 @@ fn list_and_show_and_doctor_support_json() {
238 let body: String = lines.iter().map(|line| format!("{line}\n")).collect(); 242 let body: String = lines.iter().map(|line| format!("{line}\n")).collect();
239 fs::write(sessions.join("demo.jsonl"), body).unwrap(); 243 fs::write(sessions.join("demo.jsonl"), body).unwrap();
240 244
241 let list = agent().env("HOME", &home).args(["--list", "--json"]).output().unwrap(); 245 let list = agent()
246 .env("HOME", &home)
247 .args(["--list", "--json"])
248 .output()
249 .unwrap();
242 assert!(list.status.success(), "{list:?}"); 250 assert!(list.status.success(), "{list:?}");
243 let list_json: serde_json::Value = serde_json::from_slice(&list.stdout).unwrap(); 251 let list_json: serde_json::Value = serde_json::from_slice(&list.stdout).unwrap();
244 assert!(list_json.is_array()); 252 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 @@
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
1use std::fs; 8use std::fs;
2 9
3use agent686::config::{Cli, Config, Provider}; 10use agent686::config::{Cli, Config, Provider};
@@ -43,7 +50,11 @@ fn provider_type_selects_url_and_session_header() {
43 50
44 let opencode = Config::resolve_lenient(&cli(Some("opencode"), None)); 51 let opencode = Config::resolve_lenient(&cli(Some("opencode"), None));
45 assert_eq!(opencode.provider, Provider::OpenCode); 52 assert_eq!(opencode.provider, Provider::OpenCode);
46 assert!(opencode.base_url.contains("opencode.ai"), "{}", opencode.base_url); 53 assert!(
54 opencode.base_url.contains("opencode.ai"),
55 "{}",
56 opencode.base_url
57 );
47 assert!(opencode.provider.needs_session_header()); 58 assert!(opencode.provider.needs_session_header());
48 59
49 let compatible = Config::resolve_lenient(&cli( 60 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 @@
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
1use std::fs; 8use std::fs;
2use std::io::{BufRead, BufReader, Write}; 9use std::io::{BufRead, BufReader, Write};
3use std::net::TcpListener; 10use 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 @@
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
1use std::fs; 8use std::fs;
2use std::path::PathBuf; 9use std::path::PathBuf;
3use std::process::Command; 10use std::process::Command;
@@ -18,9 +25,13 @@ fn repo(tag: &str) -> PathBuf {
18 &["config", "user.email", "agent686@test"][..], 25 &["config", "user.email", "agent686@test"][..],
19 &["config", "user.name", "agent686"][..], 26 &["config", "user.name", "agent686"][..],
20 ] { 27 ] {
21 assert!( 28 assert!(Command::new("git")
22 Command::new("git").arg("-C").arg(&dir).args(args).status().unwrap().success() 29 .arg("-C")
23 ); 30 .arg(&dir)
31 .args(args)
32 .status()
33 .unwrap()
34 .success());
24 } 35 }
25 dir 36 dir
26} 37}
@@ -40,7 +51,10 @@ fn checkpoint_then_undo_restores_the_tree() {
40 git::undo(&dir, &sha); 51 git::undo(&dir, &sha);
41 52
42 assert_eq!(fs::read_to_string(dir.join("a.txt")).unwrap(), "original\n"); 53 assert_eq!(fs::read_to_string(dir.join("a.txt")).unwrap(), "original\n");
43 assert!(!dir.join("b.txt").exists(), "untracked files must be removed"); 54 assert!(
55 !dir.join("b.txt").exists(),
56 "untracked files must be removed"
57 );
44} 58}
45 59
46#[test] 60#[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 @@
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
1use std::fs; 8use std::fs;
2use std::io::{BufRead, BufReader, Read, Write}; 9use std::io::{BufRead, BufReader, Read, Write};
3use std::net::TcpListener; 10use std::net::TcpListener;
@@ -16,9 +23,7 @@ use agent686::session::Session;
16use agent686::ui::Approver; 23use agent686::ui::Approver;
17 24
18fn sse(body: &str) -> String { 25fn 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
209fn tool_call(index: usize, id: &str, name: &str, arguments: serde_json::Value) -> serde_json::Value { 212fn 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
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 @@
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
1use std::io::{BufRead, BufReader, Read, Write}; 8use std::io::{BufRead, BufReader, Read, Write};
2use std::net::TcpListener; 9use std::net::TcpListener;
3use std::sync::atomic::AtomicBool; 10use std::sync::atomic::AtomicBool;
@@ -272,7 +279,10 @@ fn retries_a_rate_limit_and_keeps_the_same_session_header() {
272 let first = rx.recv().expect("first request").to_ascii_lowercase(); 279 let first = rx.recv().expect("first request").to_ascii_lowercase();
273 let second = rx.recv().expect("second request").to_ascii_lowercase(); 280 let second = rx.recv().expect("second request").to_ascii_lowercase();
274 assert!(first.contains("x-opencode-session: testsession"), "{first}"); 281 assert!(first.contains("x-opencode-session: testsession"), "{first}");
275 assert!(second.contains("x-opencode-session: testsession"), "{second}"); 282 assert!(
283 second.contains("x-opencode-session: testsession"),
284 "{second}"
285 );
276} 286}
277 287
278#[test] 288#[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 @@
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
1use std::fs; 8use std::fs;
2use std::path::PathBuf; 9use std::path::PathBuf;
3 10
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 @@
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
1use std::fs; 8use std::fs;
2use std::path::PathBuf; 9use std::path::PathBuf;
3use std::process::Command; 10use std::process::Command;
@@ -92,7 +99,9 @@ fn a_session_cannot_be_open_twice() {
92 let system = json!({ "role": "system", "content": "x" }); 99 let system = json!({ "role": "system", "content": "x" });
93 let first = Session::create_as("locked".into(), "m", &system).unwrap(); 100 let first = Session::create_as("locked".into(), "m", &system).unwrap();
94 101
95 let error = Session::open("locked").err().expect("second open must fail"); 102 let error = Session::open("locked")
103 .err()
104 .expect("second open must fail");
96 assert!(error.contains("already open"), "{error}"); 105 assert!(error.contains("already open"), "{error}");
97 106
98 drop(first); 107 drop(first);
@@ -127,8 +136,10 @@ fn a_torn_utf8_line_does_not_brick_a_session() {
127 br#"{"t":"header","session":"torn","model":"m","cwd":"/tmp","system":{"role":"system","content":"s"}} 136 br#"{"t":"header","session":"torn","model":"m","cwd":"/tmp","system":{"role":"system","content":"s"}}
128"#, 137"#,
129 ); 138 );
130 raw.extend_from_slice(br#"{"t":"msg","role":"user","content":"hello"} 139 raw.extend_from_slice(
131"#); 140 br#"{"t":"msg","role":"user","content":"hello"}
141"#,
142 );
132 // A killed write that split a multi-byte character. 143 // A killed write that split a multi-byte character.
133 raw.extend_from_slice(b"{\"t\":\"msg\",\"role\":\"user\",\"content\":\"caf\xc3\"}\n"); 144 raw.extend_from_slice(b"{\"t\":\"msg\",\"role\":\"user\",\"content\":\"caf\xc3\"}\n");
134 fs::write(sessions.join("torn.jsonl"), raw).unwrap(); 145 fs::write(sessions.join("torn.jsonl"), raw).unwrap();
@@ -156,7 +167,10 @@ fn last_reply_prefers_content_and_falls_back_to_reasoning() {
156 ) 167 )
157 .unwrap(); 168 .unwrap();
158 session 169 session
159 .append(&json!({ "role": "assistant", "content": null }), Some("only thinking")) 170 .append(
171 &json!({ "role": "assistant", "content": null }),
172 Some("only thinking"),
173 )
160 .unwrap(); 174 .unwrap();
161 175
162 drop(session); 176 drop(session);
@@ -168,7 +182,10 @@ fn last_reply_prefers_content_and_falls_back_to_reasoning() {
168 // With no content anywhere, reasoning is the fallback. 182 // With no content anywhere, reasoning is the fallback.
169 let mut session = Session::create_as("reasoning-only".into(), "m", &system).unwrap(); 183 let mut session = Session::create_as("reasoning-only".into(), "m", &system).unwrap();
170 session 184 session
171 .append(&json!({ "role": "assistant", "content": null }), Some("thoughts")) 185 .append(
186 &json!({ "role": "assistant", "content": null }),
187 Some("thoughts"),
188 )
172 .unwrap(); 189 .unwrap();
173 drop(session); 190 drop(session);
174 let (opened, _system, _messages) = Session::open("reasoning-only").unwrap(); 191 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 @@
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
1use agent686::provider::SseDecoder; 8use agent686::provider::SseDecoder;
2 9
3#[test] 10#[test]
@@ -10,7 +17,10 @@ fn reassembles_lines_split_at_every_byte() {
10 for byte in wire.as_bytes() { 17 for byte in wire.as_bytes() {
11 got.extend(decoder.feed(std::slice::from_ref(byte))); 18 got.extend(decoder.feed(std::slice::from_ref(byte)));
12 } 19 }
13 assert_eq!(got, vec!["{\"a\":\"café ✓\"}".to_string(), "[DONE]".to_string()]); 20 assert_eq!(
21 got,
22 vec!["{\"a\":\"café ✓\"}".to_string(), "[DONE]".to_string()]
23 );
14} 24}
15 25
16#[test] 26#[test]
@@ -26,10 +36,7 @@ fn keeps_incomplete_line_until_finished() {
26 let mut decoder = SseDecoder::new(); 36 let mut decoder = SseDecoder::new();
27 assert!(decoder.feed(b"data: {\"x\"").is_empty()); 37 assert!(decoder.feed(b"data: {\"x\"").is_empty());
28 assert!(decoder.feed(b":1}").is_empty()); 38 assert!(decoder.feed(b":1}").is_empty());
29 assert_eq!( 39 assert_eq!(decoder.feed(b"\n"), vec!["{\"x\":1}".to_string()]);
30 decoder.feed(b"\n"),
31 vec!["{\"x\":1}".to_string()]
32 );
33} 40}
34 41
35#[test] 42#[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 @@
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
1use std::fs; 8use std::fs;
2use std::path::PathBuf; 9use std::path::PathBuf;
3use std::time::Duration; 10use std::time::Duration;
@@ -24,9 +31,12 @@ fn edit_refuses_ambiguous_and_missing_text() {
24 let path = dir.join("a.txt"); 31 let path = dir.join("a.txt");
25 fs::write(&path, "alpha\nbeta\nalpha\n").unwrap(); 32 fs::write(&path, "alpha\nbeta\nalpha\n").unwrap();
26 33
27 let error = tools::plan("edit", &json!({ "path": path, "old": "alpha", "new": "gamma" })) 34 let error = tools::plan(
28 .err() 35 "edit",
29 .expect("ambiguous edit must fail"); 36 &json!({ "path": path, "old": "alpha", "new": "gamma" }),
37 )
38 .err()
39 .expect("ambiguous edit must fail");
30 assert!(error.contains("appears 2 times"), "{error}"); 40 assert!(error.contains("appears 2 times"), "{error}");
31 assert!(error.contains("lines 1, 3"), "{error}"); 41 assert!(error.contains("lines 1, 3"), "{error}");
32 42
@@ -128,15 +138,23 @@ fn bash_reports_exit_code_and_times_out() {
128 assert!(text.contains("hi"), "{text}"); 138 assert!(text.contains("hi"), "{text}");
129 assert!(text.contains("[exit 3]"), "{text}"); 139 assert!(text.contains("[exit 3]"), "{text}");
130 140
131 let text = shell::bash(&json!({ "cmd": "sleep 5" }), Duration::from_millis(150), &AtomicBool::new(false)).unwrap(); 141 let text = shell::bash(
142 &json!({ "cmd": "sleep 5" }),
143 Duration::from_millis(150),
144 &AtomicBool::new(false),
145 )
146 .unwrap();
132 assert!(text.contains("timed out after"), "{text}"); 147 assert!(text.contains("timed out after"), "{text}");
133} 148}
134 149
135#[test] 150#[test]
136fn bash_rejects_a_missing_cwd() { 151fn bash_rejects_a_missing_cwd() {
137 let error = run("bash", &json!({ "cmd": "true", "cwd": "/nonexistent-dir-xyz" })) 152 let error = run(
138 .err() 153 "bash",
139 .expect("missing cwd must fail"); 154 &json!({ "cmd": "true", "cwd": "/nonexistent-dir-xyz" }),
155 )
156 .err()
157 .expect("missing cwd must fail");
140 assert!(error.contains("cwd is not a directory"), "{error}"); 158 assert!(error.contains("cwd is not a directory"), "{error}");
141} 159}
142 160
@@ -210,11 +228,7 @@ fn read_handles_a_missing_trailing_newline() {
210#[test] 228#[test]
211fn grep_uses_regular_expressions_by_default() { 229fn grep_uses_regular_expressions_by_default() {
212 let dir = temp_dir("grep-regex"); 230 let dir = temp_dir("grep-regex");
213 fs::write( 231 fs::write(dir.join("f.rs"), "fn main() {\n fn other() {\n}\n").unwrap();
214 dir.join("f.rs"),
215 "fn main() {\n fn other() {\n}\n",
216 )
217 .unwrap();
218 232
219 let text = run("grep", &json!({ "pattern": r"fn\s+main", "path": dir })).unwrap(); 233 let text = run("grep", &json!({ "pattern": r"fn\s+main", "path": dir })).unwrap();
220 assert_eq!(text.lines().count(), 1, "{text}"); 234 assert_eq!(text.lines().count(), 1, "{text}");
@@ -283,7 +297,11 @@ fn bash_timeout_kills_the_whole_process_group() {
283 assert!(text.contains("timed out"), "{text}"); 297 assert!(text.contains("timed out"), "{text}");
284 298
285 std::thread::sleep(Duration::from_millis(300)); 299 std::thread::sleep(Duration::from_millis(300));
286 let pid: i32 = fs::read_to_string(&pidfile).unwrap().trim().parse().unwrap(); 300 let pid: i32 = fs::read_to_string(&pidfile)
301 .unwrap()
302 .trim()
303 .parse()
304 .unwrap();
287 assert!(!running(pid), "grandchild {pid} survived the timeout"); 305 assert!(!running(pid), "grandchild {pid} survived the timeout");
288} 306}
289 307
@@ -309,7 +327,10 @@ fn bash_does_not_inherit_the_api_key() {
309 ) 327 )
310 .unwrap(); 328 .unwrap();
311 std::env::remove_var("OPENCODE_API_KEY"); 329 std::env::remove_var("OPENCODE_API_KEY");
312 assert!(text.contains('0'), "the key was visible to the child: {text}"); 330 assert!(
331 text.contains('0'),
332 "the key was visible to the child: {text}"
333 );
313} 334}
314 335
315#[test] 336#[test]
@@ -342,8 +363,11 @@ fn edit_refuses_when_the_file_changed_while_waiting_for_approval() {
342 let path = dir.join("f.txt"); 363 let path = dir.join("f.txt");
343 fs::write(&path, "alpha\n").unwrap(); 364 fs::write(&path, "alpha\n").unwrap();
344 365
345 let change = tools::plan("edit", &json!({ "path": path, "old": "alpha", "new": "beta" })) 366 let change = tools::plan(
346 .unwrap(); 367 "edit",
368 &json!({ "path": path, "old": "alpha", "new": "beta" }),
369 )
370 .unwrap();
347 // Something else (cargo fmt, the user's editor) ran before approval. 371 // Something else (cargo fmt, the user's editor) ran before approval.
348 fs::write(&path, "alpha\nalpha\n").unwrap(); 372 fs::write(&path, "alpha\nalpha\n").unwrap();
349 373
@@ -470,11 +494,7 @@ fn bash_stderr_alone_is_labelled() {
470#[test] 494#[test]
471fn bash_honours_a_per_call_timeout() { 495fn bash_honours_a_per_call_timeout() {
472 let started = std::time::Instant::now(); 496 let started = std::time::Instant::now();
473 let text = run( 497 let text = run("bash", &json!({ "cmd": "sleep 5", "timeout_seconds": 1 })).unwrap();
474 "bash",
475 &json!({ "cmd": "sleep 5", "timeout_seconds": 1 }),
476 )
477 .unwrap();
478 assert!(text.contains("timed out after 1.0s"), "{text}"); 498 assert!(text.contains("timed out after 1.0s"), "{text}");
479 assert!(started.elapsed() < std::time::Duration::from_secs(4)); 499 assert!(started.elapsed() < std::time::Duration::from_secs(4));
480} 500}
@@ -507,11 +527,7 @@ fn validate_requires_content_and_new_but_allows_empty() {
507fn a_pipeline_that_exceeds_the_file_limit_is_reported() { 527fn a_pipeline_that_exceeds_the_file_limit_is_reported() {
508 // 70 MiB through a pipeline: the grandchild (head) is the writer, so only the 528 // 70 MiB through a pipeline: the grandchild (head) is the writer, so only the
509 // file-length check can detect the limit. 529 // file-length check can detect the limit.
510 let text = run( 530 let text = run("bash", &json!({ "cmd": "yes | head -c 70000000" })).unwrap();
511 "bash",
512 &json!({ "cmd": "yes | head -c 70000000" }),
513 )
514 .unwrap();
515 assert!( 531 assert!(
516 text.contains("output exceeded 64 MiB"), 532 text.contains("output exceeded 64 MiB"),
517 "should report the file limit: {text}" 533 "should report the file limit: {text}"