diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-15 17:16:08 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-15 17:16:08 +0100 |
| commit | 14e56289391ea95b493c2a20c87f8d88047aa051 (patch) | |
| tree | d0acf1cc35369688d92c781e31fb7afc30c38b7a /tests | |
| parent | 0.5.3: session locking, UTF-8 and size guards for edit, correct character widths (diff) | |
| download | agent686-14e56289391ea95b493c2a20c87f8d88047aa051.tar.gz agent686-14e56289391ea95b493c2a20c87f8d88047aa051.zip | |
0.6.0: transcript viewer, turn summary, yolo floor, model/version records
- --show renders a session without locking it
- status line summarises writes, commands and denials per turn
- sessions record harness version; model switches are appended and listed
- --yolo refuses $HOME and / unless AGENT686_ALLOW_HOME=1
Diffstat (limited to '')
| -rw-r--r-- | tests/cli.rs | 69 | ||||
| -rw-r--r-- | tests/loop.rs | 2 | ||||
| -rw-r--r-- | tests/sessions.rs | 15 |
3 files changed, 86 insertions, 0 deletions
diff --git a/tests/cli.rs b/tests/cli.rs index 04fd637..6c041fb 100644 --- a/tests/cli.rs +++ b/tests/cli.rs | |||
| @@ -76,3 +76,72 @@ fn unknown_flags_go_to_stderr_with_usage() { | |||
| 76 | assert!(stderr.contains("unknown flag"), "{stderr}"); | 76 | assert!(stderr.contains("unknown flag"), "{stderr}"); |
| 77 | assert!(stderr.contains("USAGE"), "{stderr}"); | 77 | assert!(stderr.contains("USAGE"), "{stderr}"); |
| 78 | } | 78 | } |
| 79 | |||
| 80 | #[test] | ||
| 81 | fn yolo_is_refused_in_the_home_directory() { | ||
| 82 | let home = temp_home("yolo"); | ||
| 83 | let output = agent() | ||
| 84 | .current_dir(&home) | ||
| 85 | .env("HOME", &home) | ||
| 86 | .env("OPENCODE_API_KEY", "test") | ||
| 87 | .arg("--yolo") | ||
| 88 | .stdin(std::process::Stdio::null()) | ||
| 89 | .output() | ||
| 90 | .unwrap(); | ||
| 91 | |||
| 92 | assert_eq!(output.status.code(), Some(2), "{output:?}"); | ||
| 93 | let stderr = String::from_utf8_lossy(&output.stderr); | ||
| 94 | assert!(stderr.contains("refusing --yolo"), "{stderr}"); | ||
| 95 | assert!(stderr.contains("AGENT686_ALLOW_HOME"), "{stderr}"); | ||
| 96 | } | ||
| 97 | |||
| 98 | #[test] | ||
| 99 | fn yolo_in_home_can_be_forced() { | ||
| 100 | let home = temp_home("yolo-force"); | ||
| 101 | let output = agent() | ||
| 102 | .current_dir(&home) | ||
| 103 | .env("HOME", &home) | ||
| 104 | .env("OPENCODE_API_KEY", "test") | ||
| 105 | .env("AGENT686_ALLOW_HOME", "1") | ||
| 106 | .args(["--yolo", "--session", "forced"]) | ||
| 107 | .stdin(std::process::Stdio::null()) | ||
| 108 | .output() | ||
| 109 | .unwrap(); | ||
| 110 | |||
| 111 | assert_eq!(output.status.code(), Some(0), "{output:?}"); | ||
| 112 | } | ||
| 113 | |||
| 114 | #[test] | ||
| 115 | fn show_renders_a_transcript() { | ||
| 116 | use serde_json::json; | ||
| 117 | |||
| 118 | let home = temp_home("show"); | ||
| 119 | let sessions = home.join(".local/share/agent686/sessions"); | ||
| 120 | fs::create_dir_all(&sessions).unwrap(); | ||
| 121 | |||
| 122 | let lines = [ | ||
| 123 | json!({"t":"header","session":"demo","model":"m","cwd":"/tmp","version":"0.0.0", | ||
| 124 | "system":{"role":"system","content":"sys"}}), | ||
| 125 | json!({"t":"msg","role":"user","content":"do the thing"}), | ||
| 126 | json!({"t":"msg","role":"assistant","content":"on it","_reasoning":"thinking about it", | ||
| 127 | "tool_calls":[{"id":"c1","type":"function", | ||
| 128 | "function":{"name":"read","arguments":"{\"path\":\"a\"}"}}]}), | ||
| 129 | json!({"t":"msg","role":"tool","tool_call_id":"c1","content":"line one\nline two"}), | ||
| 130 | ]; | ||
| 131 | let body: String = lines.iter().map(|line| format!("{line}\n")).collect(); | ||
| 132 | fs::write(sessions.join("demo.jsonl"), body).unwrap(); | ||
| 133 | |||
| 134 | let output = agent() | ||
| 135 | .env("HOME", &home) | ||
| 136 | .args(["--show", "demo"]) | ||
| 137 | .output() | ||
| 138 | .unwrap(); | ||
| 139 | |||
| 140 | assert!(output.status.success(), "{output:?}"); | ||
| 141 | let stdout = String::from_utf8_lossy(&output.stdout); | ||
| 142 | assert!(stdout.contains("do the thing"), "{stdout}"); | ||
| 143 | assert!(stdout.contains("● read"), "{stdout}"); | ||
| 144 | assert!(stdout.contains("line one"), "{stdout}"); | ||
| 145 | assert!(stdout.contains("on it"), "{stdout}"); | ||
| 146 | assert!(stdout.contains("thinking about it"), "{stdout}"); | ||
| 147 | } | ||
diff --git a/tests/loop.rs b/tests/loop.rs index d6df43c..b7e56f9 100644 --- a/tests/loop.rs +++ b/tests/loop.rs | |||
| @@ -260,6 +260,8 @@ fn aborting_between_tool_calls_answers_every_call() { | |||
| 260 | .expect("an abort is not an error"); | 260 | .expect("an abort is not an error"); |
| 261 | 261 | ||
| 262 | assert!(report.aborted); | 262 | assert!(report.aborted); |
| 263 | assert_eq!(report.writes, 0, "aborted calls must not count as writes"); | ||
| 264 | assert_eq!(report.commands, 1); | ||
| 263 | 265 | ||
| 264 | // Every announced tool call must have exactly one result, or the provider | 266 | // Every announced tool call must have exactly one result, or the provider |
| 265 | // rejects the session forever and the transcript cannot be rewritten. | 267 | // rejects the session forever and the transcript cannot be rewritten. |
diff --git a/tests/sessions.rs b/tests/sessions.rs index f21be24..1d40f64 100644 --- a/tests/sessions.rs +++ b/tests/sessions.rs | |||
| @@ -95,3 +95,18 @@ fn a_session_cannot_be_open_twice() { | |||
| 95 | drop(first); | 95 | drop(first); |
| 96 | Session::open("locked").expect("after the first handle closes it is available"); | 96 | Session::open("locked").expect("after the first handle closes it is available"); |
| 97 | } | 97 | } |
| 98 | |||
| 99 | #[test] | ||
| 100 | fn listing_reports_the_model_in_use_after_a_switch() { | ||
| 101 | let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); | ||
| 102 | let dir = temp_dir("model-switch"); | ||
| 103 | std::env::set_var("AGENT686_DATA", &dir); | ||
| 104 | |||
| 105 | let system = json!({ "role": "system", "content": "x" }); | ||
| 106 | let mut session = Session::create_as("switch".into(), "model-a", &system).unwrap(); | ||
| 107 | session.record_model("model-b").unwrap(); | ||
| 108 | |||
| 109 | let listed = session::list().unwrap(); | ||
| 110 | assert_eq!(listed.len(), 1); | ||
| 111 | assert_eq!(listed[0].model, "model-b"); | ||
| 112 | } | ||
