diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-19 11:30:47 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-19 11:30:47 +0100 |
| commit | 4d5b584e39cf90a4afaab8af46be2f69dcd914b6 (patch) | |
| tree | 567bd18d2c7ea52129aaca6d3af0e8e8e0e84802 /tests | |
| parent | docs: refresh KNOWN-ISSUES for 0.11.0; note the yolo git gate (diff) | |
| download | agent686-4d5b584e39cf90a4afaab8af46be2f69dcd914b6.tar.gz agent686-4d5b584e39cf90a4afaab8af46be2f69dcd914b6.zip | |
0.12.0: provider is a type + URL, plus a config file
- --provider opencode|openai-compatible; opencode keeps the session header,
openai-compatible needs a base URL and sends none
- config file at ~/.config/agent686/config.toml (provider, url, model, flags)
- fix the doubled-dash --provider help message
Diffstat (limited to '')
| -rw-r--r-- | tests/cli.rs | 2 | ||||
| -rw-r--r-- | tests/config.rs | 128 | ||||
| -rw-r--r-- | tests/loop.rs | 21 | ||||
| -rw-r--r-- | tests/mock.rs | 3 |
4 files changed, 128 insertions, 26 deletions
diff --git a/tests/cli.rs b/tests/cli.rs index 72edbd1..37546b1 100644 --- a/tests/cli.rs +++ b/tests/cli.rs | |||
| @@ -92,7 +92,7 @@ fn yolo_is_refused_in_the_home_directory() { | |||
| 92 | assert_eq!(output.status.code(), Some(2), "{output:?}"); | 92 | assert_eq!(output.status.code(), Some(2), "{output:?}"); |
| 93 | let stderr = String::from_utf8_lossy(&output.stderr); | 93 | let stderr = String::from_utf8_lossy(&output.stderr); |
| 94 | assert!(stderr.contains("refusing --yolo"), "{stderr}"); | 94 | assert!(stderr.contains("refusing --yolo"), "{stderr}"); |
| 95 | assert!(stderr.contains("AGENT686_ALLOW_HOME"), "{stderr}"); | 95 | assert!(stderr.contains("allow_home"), "{stderr}"); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | #[test] | 98 | #[test] |
diff --git a/tests/config.rs b/tests/config.rs index 05361d3..c090fbf 100644 --- a/tests/config.rs +++ b/tests/config.rs | |||
| @@ -1,28 +1,106 @@ | |||
| 1 | use agent686::config::Config; | 1 | use std::fs; |
| 2 | |||
| 3 | use agent686::config::{Cli, Config, Provider}; | ||
| 4 | |||
| 5 | static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); | ||
| 6 | |||
| 7 | fn clear_env() { | ||
| 8 | for key in [ | ||
| 9 | "AGENT686_CONFIG", | ||
| 10 | "AGENT686_PROVIDER", | ||
| 11 | "AGENT686_BASE_URL", | ||
| 12 | "AGENT686_MODEL", | ||
| 13 | "AGENT686_ALLOW_HOME", | ||
| 14 | "AGENT686_ALLOW_NOGIT", | ||
| 15 | "AGENT686_SYSTEM_CA", | ||
| 16 | ] { | ||
| 17 | std::env::remove_var(key); | ||
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | fn cli(provider: Option<&str>, base_url: Option<&str>) -> Cli { | ||
| 22 | Cli { | ||
| 23 | model: None, | ||
| 24 | base_url: base_url.map(String::from), | ||
| 25 | provider: provider.map(String::from), | ||
| 26 | yolo: false, | ||
| 27 | lenient: false, | ||
| 28 | system_ca: false, | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | fn temp_dir(tag: &str) -> std::path::PathBuf { | ||
| 33 | let dir = std::env::temp_dir().join(format!("agent686-config-{tag}-{}", std::process::id())); | ||
| 34 | let _ = fs::remove_dir_all(&dir); | ||
| 35 | fs::create_dir_all(&dir).unwrap(); | ||
| 36 | dir | ||
| 37 | } | ||
| 38 | |||
| 39 | #[test] | ||
| 40 | fn provider_type_selects_url_and_session_header() { | ||
| 41 | let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); | ||
| 42 | clear_env(); | ||
| 43 | |||
| 44 | let opencode = Config::resolve_lenient(&cli(Some("opencode"), None)); | ||
| 45 | assert_eq!(opencode.provider, Provider::OpenCode); | ||
| 46 | assert!(opencode.base_url.contains("opencode.ai"), "{}", opencode.base_url); | ||
| 47 | assert!(opencode.provider.needs_session_header()); | ||
| 48 | |||
| 49 | let compatible = Config::resolve_lenient(&cli( | ||
| 50 | Some("openai-compatible"), | ||
| 51 | Some("http://localhost:11434/v1"), | ||
| 52 | )); | ||
| 53 | assert_eq!(compatible.provider, Provider::OpenAICompatible); | ||
| 54 | assert_eq!(compatible.base_url, "http://localhost:11434/v1"); | ||
| 55 | assert!(!compatible.provider.needs_session_header()); | ||
| 56 | } | ||
| 57 | |||
| 58 | #[test] | ||
| 59 | fn openai_compatible_without_a_url_is_rejected() { | ||
| 60 | let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); | ||
| 61 | clear_env(); | ||
| 62 | std::env::set_var("OPENCODE_API_KEY", "test"); | ||
| 63 | |||
| 64 | let error = Config::resolve(&cli(Some("openai-compatible"), None)) | ||
| 65 | .err() | ||
| 66 | .expect("openai-compatible needs a URL"); | ||
| 67 | assert!(error.contains("base URL"), "{error}"); | ||
| 68 | } | ||
| 69 | |||
| 70 | #[test] | ||
| 71 | fn config_file_supplies_provider_model_and_flags() { | ||
| 72 | let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); | ||
| 73 | clear_env(); | ||
| 74 | |||
| 75 | let dir = temp_dir("file"); | ||
| 76 | let path = dir.join("config.toml"); | ||
| 77 | fs::write( | ||
| 78 | &path, | ||
| 79 | "provider = \"openai-compatible\"\nurl = \"http://localhost:8080/v1\"\nmodel = \"local\"\nallow_nogit = true\n", | ||
| 80 | ) | ||
| 81 | .unwrap(); | ||
| 82 | std::env::set_var("AGENT686_CONFIG", &path); | ||
| 83 | |||
| 84 | let cfg = Config::resolve_lenient(&Cli::default()); | ||
| 85 | assert_eq!(cfg.provider, Provider::OpenAICompatible); | ||
| 86 | assert_eq!(cfg.base_url, "http://localhost:8080/v1"); | ||
| 87 | assert_eq!(cfg.model, "local"); | ||
| 88 | assert!(cfg.allow_nogit); | ||
| 89 | } | ||
| 2 | 90 | ||
| 3 | #[test] | 91 | #[test] |
| 4 | fn presets_fill_base_url_model_and_leniency() { | 92 | fn cli_beats_the_config_file() { |
| 5 | let ollama = Config::resolve_lenient(None, None, false, Some("ollama".into()), false, false); | 93 | let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); |
| 6 | assert_eq!(ollama.base_url, "http://localhost:11434/v1"); | 94 | clear_env(); |
| 7 | assert!(ollama.lenient, "local gateways default to lenient"); | 95 | |
| 8 | 96 | let dir = temp_dir("precedence"); | |
| 9 | let opencode = | 97 | let path = dir.join("config.toml"); |
| 10 | Config::resolve_lenient(None, None, false, Some("opencode-go".into()), false, false); | 98 | fs::write(&path, "model = \"from-file\"\n").unwrap(); |
| 11 | assert!(!opencode.lenient); | 99 | std::env::set_var("AGENT686_CONFIG", &path); |
| 12 | assert!(opencode.base_url.contains("opencode.ai")); | 100 | |
| 13 | 101 | let cfg = Config::resolve_lenient(&Cli { | |
| 14 | // An explicit --base-url beats the preset. | 102 | model: Some("from-cli".into()), |
| 15 | let explicit = Config::resolve_lenient( | 103 | ..Cli::default() |
| 16 | None, | 104 | }); |
| 17 | Some("http://127.0.0.1:9/v1".into()), | 105 | assert_eq!(cfg.model, "from-cli"); |
| 18 | false, | ||
| 19 | Some("ollama".into()), | ||
| 20 | false, | ||
| 21 | false, | ||
| 22 | ); | ||
| 23 | assert_eq!(explicit.base_url, "http://127.0.0.1:9/v1"); | ||
| 24 | |||
| 25 | // Unknown preset falls back to the default endpoint. | ||
| 26 | let unknown = Config::resolve_lenient(None, None, false, Some("nope".into()), false, false); | ||
| 27 | assert!(unknown.base_url.contains("opencode.ai")); | ||
| 28 | } | 106 | } |
diff --git a/tests/loop.rs b/tests/loop.rs index 8c913cd..7e6086f 100644 --- a/tests/loop.rs +++ b/tests/loop.rs | |||
| @@ -101,6 +101,9 @@ fn runs_a_tool_call_then_finishes_and_records_every_message() { | |||
| 101 | yolo: true, | 101 | yolo: true, |
| 102 | lenient: false, | 102 | lenient: false, |
| 103 | system_ca: false, | 103 | system_ca: false, |
| 104 | provider: agent686::config::Provider::OpenCode, | ||
| 105 | allow_home: false, | ||
| 106 | allow_nogit: false, | ||
| 104 | }; | 107 | }; |
| 105 | let mut history = agent::new_history(system); | 108 | let mut history = agent::new_history(system); |
| 106 | let mut approver = Approver::new(true); | 109 | let mut approver = Approver::new(true); |
| @@ -174,6 +177,9 @@ fn a_denied_tool_call_is_returned_as_data() { | |||
| 174 | yolo: false, | 177 | yolo: false, |
| 175 | lenient: false, | 178 | lenient: false, |
| 176 | system_ca: false, | 179 | system_ca: false, |
| 180 | provider: agent686::config::Provider::OpenCode, | ||
| 181 | allow_home: false, | ||
| 182 | allow_nogit: false, | ||
| 177 | }; | 183 | }; |
| 178 | let mut history = agent::new_history(system); | 184 | let mut history = agent::new_history(system); |
| 179 | // Not a terminal, so the approver must deny rather than block. | 185 | // Not a terminal, so the approver must deny rather than block. |
| @@ -244,6 +250,9 @@ fn aborting_between_tool_calls_answers_every_call() { | |||
| 244 | yolo: true, | 250 | yolo: true, |
| 245 | lenient: false, | 251 | lenient: false, |
| 246 | system_ca: false, | 252 | system_ca: false, |
| 253 | provider: agent686::config::Provider::OpenCode, | ||
| 254 | allow_home: false, | ||
| 255 | allow_nogit: false, | ||
| 247 | }; | 256 | }; |
| 248 | let mut history = agent::new_history(system); | 257 | let mut history = agent::new_history(system); |
| 249 | let mut approver = Approver::new(true); | 258 | let mut approver = Approver::new(true); |
| @@ -321,6 +330,9 @@ fn opening_a_session_with_unanswered_calls_repairs_it() { | |||
| 321 | yolo: true, | 330 | yolo: true, |
| 322 | lenient: false, | 331 | lenient: false, |
| 323 | system_ca: false, | 332 | system_ca: false, |
| 333 | provider: agent686::config::Provider::OpenCode, | ||
| 334 | allow_home: false, | ||
| 335 | allow_nogit: false, | ||
| 324 | }; | 336 | }; |
| 325 | let mut approver = Approver::new(true); | 337 | let mut approver = Approver::new(true); |
| 326 | agent::run_turn( | 338 | agent::run_turn( |
| @@ -377,6 +389,9 @@ fn an_empty_bash_call_is_never_approved() { | |||
| 377 | yolo: false, | 389 | yolo: false, |
| 378 | lenient: false, | 390 | lenient: false, |
| 379 | system_ca: false, | 391 | system_ca: false, |
| 392 | provider: agent686::config::Provider::OpenCode, | ||
| 393 | allow_home: false, | ||
| 394 | allow_nogit: false, | ||
| 380 | }; | 395 | }; |
| 381 | let mut history = agent::new_history(system); | 396 | let mut history = agent::new_history(system); |
| 382 | // Not a terminal: if this reaches the approval path it is denied, which the | 397 | // Not a terminal: if this reaches the approval path it is denied, which the |
| @@ -433,6 +448,9 @@ fn a_tool_call_with_no_arguments_is_reported_to_the_model() { | |||
| 433 | yolo: false, | 448 | yolo: false, |
| 434 | lenient: false, | 449 | lenient: false, |
| 435 | system_ca: false, | 450 | system_ca: false, |
| 451 | provider: agent686::config::Provider::OpenCode, | ||
| 452 | allow_home: false, | ||
| 453 | allow_nogit: false, | ||
| 436 | }; | 454 | }; |
| 437 | let mut history = agent::new_history(system); | 455 | let mut history = agent::new_history(system); |
| 438 | let mut approver = Approver::new(false); | 456 | let mut approver = Approver::new(false); |
| @@ -489,6 +507,9 @@ fn a_wrong_argument_key_names_both_keys() { | |||
| 489 | yolo: false, | 507 | yolo: false, |
| 490 | lenient: false, | 508 | lenient: false, |
| 491 | system_ca: false, | 509 | system_ca: false, |
| 510 | provider: agent686::config::Provider::OpenCode, | ||
| 511 | allow_home: false, | ||
| 512 | allow_nogit: false, | ||
| 492 | }; | 513 | }; |
| 493 | let mut history = agent::new_history(system); | 514 | let mut history = agent::new_history(system); |
| 494 | let mut approver = Approver::new(false); | 515 | let mut approver = Approver::new(false); |
diff --git a/tests/mock.rs b/tests/mock.rs index fdbaca4..3b2abdd 100644 --- a/tests/mock.rs +++ b/tests/mock.rs | |||
| @@ -76,6 +76,9 @@ fn config(base_url: String) -> Config { | |||
| 76 | yolo: true, | 76 | yolo: true, |
| 77 | lenient: false, | 77 | lenient: false, |
| 78 | system_ca: false, | 78 | system_ca: false, |
| 79 | provider: agent686::config::Provider::OpenCode, | ||
| 80 | allow_home: false, | ||
| 81 | allow_nogit: false, | ||
| 79 | } | 82 | } |
| 80 | } | 83 | } |
| 81 | 84 | ||
