diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-18 12:39:38 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-18 12:39:38 +0100 |
| commit | 8c8f93e598644f6af5538e9ea28463f126f9abcb (patch) | |
| tree | 47fd5e49724a5e9ba175f0c232360ddda591e7ab /tests | |
| parent | 0.9.2: doc accuracy and UX fixes from the review (diff) | |
| download | agent686-8c8f93e598644f6af5538e9ea28463f126f9abcb.tar.gz agent686-8c8f93e598644f6af5538e9ea28463f126f9abcb.zip | |
0.10.0: --json, /models /model /forget, git-repo gate for --yolo
- --list/--show/--doctor gain --json for scripts
- /models lists provider models, /model switches mid-session, /forget prunes sessions
- --yolo refused outside a git repo (AGENT686_ALLOW_NOGIT=1 opts out)
Diffstat (limited to '')
| -rw-r--r-- | tests/cli.rs | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/tests/cli.rs b/tests/cli.rs index 80eb96d..72edbd1 100644 --- a/tests/cli.rs +++ b/tests/cli.rs | |||
| @@ -103,6 +103,7 @@ fn yolo_in_home_can_be_forced() { | |||
| 103 | .env("HOME", &home) | 103 | .env("HOME", &home) |
| 104 | .env("OPENCODE_API_KEY", "test") | 104 | .env("OPENCODE_API_KEY", "test") |
| 105 | .env("AGENT686_ALLOW_HOME", "1") | 105 | .env("AGENT686_ALLOW_HOME", "1") |
| 106 | .env("AGENT686_ALLOW_NOGIT", "1") | ||
| 106 | .args(["--yolo", "--session", "forced"]) | 107 | .args(["--yolo", "--session", "forced"]) |
| 107 | .stdin(std::process::Stdio::null()) | 108 | .stdin(std::process::Stdio::null()) |
| 108 | .output() | 109 | .output() |
| @@ -170,3 +171,101 @@ fn a_flag_shaped_value_is_rejected_unless_attached() { | |||
| 170 | .join(".local/share/agent686/sessions/-abc.jsonl") | 171 | .join(".local/share/agent686/sessions/-abc.jsonl") |
| 171 | .exists()); | 172 | .exists()); |
| 172 | } | 173 | } |
| 174 | |||
| 175 | #[test] | ||
| 176 | fn yolo_is_refused_outside_a_git_repo() { | ||
| 177 | let home = temp_home("nogit"); | ||
| 178 | let dir = home.join("proj"); | ||
| 179 | fs::create_dir_all(&dir).unwrap(); | ||
| 180 | |||
| 181 | let output = agent() | ||
| 182 | .current_dir(&dir) | ||
| 183 | .env("HOME", &home) | ||
| 184 | .env("OPENCODE_API_KEY", "test") | ||
| 185 | .arg("--yolo") | ||
| 186 | .stdin(std::process::Stdio::null()) | ||
| 187 | .output() | ||
| 188 | .unwrap(); | ||
| 189 | assert_eq!(output.status.code(), Some(2), "{output:?}"); | ||
| 190 | assert!( | ||
| 191 | String::from_utf8_lossy(&output.stderr).contains("git repository"), | ||
| 192 | "{:?}", | ||
| 193 | String::from_utf8_lossy(&output.stderr) | ||
| 194 | ); | ||
| 195 | |||
| 196 | let output = agent() | ||
| 197 | .current_dir(&dir) | ||
| 198 | .env("HOME", &home) | ||
| 199 | .env("OPENCODE_API_KEY", "test") | ||
| 200 | .env("AGENT686_ALLOW_NOGIT", "1") | ||
| 201 | .args(["--yolo", "--session", "ok"]) | ||
| 202 | .stdin(std::process::Stdio::null()) | ||
| 203 | .output() | ||
| 204 | .unwrap(); | ||
| 205 | assert_eq!(output.status.code(), Some(0), "{output:?}"); | ||
| 206 | } | ||
| 207 | |||
| 208 | #[test] | ||
| 209 | fn yolo_is_allowed_inside_a_git_repo() { | ||
| 210 | let home = temp_home("git-repo"); | ||
| 211 | let dir = home.join("repo"); | ||
| 212 | fs::create_dir_all(dir.join(".git")).unwrap(); | ||
| 213 | |||
| 214 | let output = agent() | ||
| 215 | .current_dir(&dir) | ||
| 216 | .env("HOME", &home) | ||
| 217 | .env("OPENCODE_API_KEY", "test") | ||
| 218 | .args(["--yolo", "--session", "inside"]) | ||
| 219 | .stdin(std::process::Stdio::null()) | ||
| 220 | .output() | ||
| 221 | .unwrap(); | ||
| 222 | assert_eq!(output.status.code(), Some(0), "{output:?}"); | ||
| 223 | } | ||
| 224 | |||
| 225 | #[test] | ||
| 226 | fn list_and_show_and_doctor_support_json() { | ||
| 227 | use serde_json::json; | ||
| 228 | |||
| 229 | let home = temp_home("json"); | ||
| 230 | let sessions = home.join(".local/share/agent686/sessions"); | ||
| 231 | fs::create_dir_all(&sessions).unwrap(); | ||
| 232 | let lines = [ | ||
| 233 | json!({"t":"header","session":"demo","model":"m","cwd":"/tmp","version":"0.0.0", | ||
| 234 | "system":{"role":"system","content":"s"}}), | ||
| 235 | json!({"t":"msg","role":"user","content":"hi"}), | ||
| 236 | json!({"t":"msg","role":"assistant","content":"yo","_reasoning":"r"}), | ||
| 237 | ]; | ||
| 238 | let body: String = lines.iter().map(|line| format!("{line}\n")).collect(); | ||
| 239 | fs::write(sessions.join("demo.jsonl"), body).unwrap(); | ||
| 240 | |||
| 241 | let list = agent().env("HOME", &home).args(["--list", "--json"]).output().unwrap(); | ||
| 242 | assert!(list.status.success(), "{list:?}"); | ||
| 243 | let list_json: serde_json::Value = serde_json::from_slice(&list.stdout).unwrap(); | ||
| 244 | assert!(list_json.is_array()); | ||
| 245 | assert_eq!(list_json[0]["id"], "demo"); | ||
| 246 | |||
| 247 | let show = agent() | ||
| 248 | .env("HOME", &home) | ||
| 249 | .args(["--show", "demo", "--json"]) | ||
| 250 | .output() | ||
| 251 | .unwrap(); | ||
| 252 | assert!(show.status.success(), "{show:?}"); | ||
| 253 | let show_json: serde_json::Value = serde_json::from_slice(&show.stdout).unwrap(); | ||
| 254 | assert_eq!(show_json["id"], "demo"); | ||
| 255 | assert_eq!(show_json["messages"].as_array().unwrap().len(), 2); | ||
| 256 | assert_eq!(show_json["messages"][1]["_reasoning"], "r"); | ||
| 257 | |||
| 258 | let doctor = agent() | ||
| 259 | .env("HOME", &home) | ||
| 260 | .env_remove("OPENCODE_API_KEY") | ||
| 261 | .args(["--doctor", "--json"]) | ||
| 262 | .output() | ||
| 263 | .unwrap(); | ||
| 264 | assert_eq!(doctor.status.code(), Some(1), "{doctor:?}"); | ||
| 265 | let doctor_json: serde_json::Value = serde_json::from_slice(&doctor.stdout).unwrap(); | ||
| 266 | assert_eq!(doctor_json["ok"], false); | ||
| 267 | assert!(doctor_json["checks"]["key"]["detail"] | ||
| 268 | .as_str() | ||
| 269 | .unwrap() | ||
| 270 | .contains("missing")); | ||
| 271 | } | ||
