diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-15 15:41:46 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-15 15:41:46 +0100 |
| commit | 3b1351018d3184caa5b5ca25cc13e5da1fc02229 (patch) | |
| tree | 99bdc95ba444a5c4d2d3f09c4e5c04ff16108f8f /tests/doctor.rs | |
| parent | 0.4.4: file-tool correctness (diff) | |
| download | agent686-3b1351018d3184caa5b5ca25cc13e5da1fc02229.tar.gz agent686-3b1351018d3184caa5b5ca25cc13e5da1fc02229.zip | |
0.4.5: CLI validation, instruction scope, resume context, prompt hygiene
- session ids validated; missing flag values and conflicting flags are usage errors
- -- terminator; usage goes to stderr
- doctor sends a real session header
- sessions record their starting cwd and warn when resumed elsewhere
- AGENTS.md stops at the git root; no parent-directory injection
- typeahead flush, Ctrl-C during prompts, NO_COLOR/TERM=dumb
Diffstat (limited to 'tests/doctor.rs')
| -rw-r--r-- | tests/doctor.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/tests/doctor.rs b/tests/doctor.rs index 8a4f3f7..d42773f 100644 --- a/tests/doctor.rs +++ b/tests/doctor.rs | |||
| @@ -3,6 +3,7 @@ use std::io::{BufRead, BufReader, Write}; | |||
| 3 | use std::net::TcpListener; | 3 | use std::net::TcpListener; |
| 4 | use std::path::PathBuf; | 4 | use std::path::PathBuf; |
| 5 | use std::process::{Command, Output}; | 5 | use std::process::{Command, Output}; |
| 6 | use std::sync::mpsc; | ||
| 6 | use std::thread; | 7 | use std::thread; |
| 7 | 8 | ||
| 8 | fn temp_home(tag: &str) -> PathBuf { | 9 | fn temp_home(tag: &str) -> PathBuf { |
| @@ -12,8 +13,8 @@ fn temp_home(tag: &str) -> PathBuf { | |||
| 12 | dir | 13 | dir |
| 13 | } | 14 | } |
| 14 | 15 | ||
| 15 | /// Serves one `GET /models` response on a random port. | 16 | /// Serves one `GET /models` response on a random port, and returns the request. |
| 16 | fn serve_models(ids: &[&str]) -> String { | 17 | fn serve_models(ids: &[&str]) -> (String, mpsc::Receiver<String>) { |
| 17 | let listener = TcpListener::bind("127.0.0.1:0").unwrap(); | 18 | let listener = TcpListener::bind("127.0.0.1:0").unwrap(); |
| 18 | let addr = listener.local_addr().unwrap(); | 19 | let addr = listener.local_addr().unwrap(); |
| 19 | let body = format!( | 20 | let body = format!( |
| @@ -23,15 +24,19 @@ fn serve_models(ids: &[&str]) -> String { | |||
| 23 | .collect::<Vec<_>>() | 24 | .collect::<Vec<_>>() |
| 24 | .join(",") | 25 | .join(",") |
| 25 | ); | 26 | ); |
| 27 | let (tx, rx) = mpsc::channel(); | ||
| 26 | thread::spawn(move || { | 28 | thread::spawn(move || { |
| 27 | let (mut stream, _) = listener.accept().unwrap(); | 29 | let (mut stream, _) = listener.accept().unwrap(); |
| 28 | let mut reader = BufReader::new(stream.try_clone().unwrap()); | 30 | let mut reader = BufReader::new(stream.try_clone().unwrap()); |
| 31 | let mut request = String::new(); | ||
| 29 | loop { | 32 | loop { |
| 30 | let mut line = String::new(); | 33 | let mut line = String::new(); |
| 31 | if reader.read_line(&mut line).unwrap_or(0) == 0 || line == "\r\n" { | 34 | if reader.read_line(&mut line).unwrap_or(0) == 0 || line == "\r\n" { |
| 32 | break; | 35 | break; |
| 33 | } | 36 | } |
| 37 | request.push_str(&line); | ||
| 34 | } | 38 | } |
| 39 | let _ = tx.send(request); | ||
| 35 | let response = format!( | 40 | let response = format!( |
| 36 | "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", | 41 | "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", |
| 37 | body.len() | 42 | body.len() |
| @@ -39,7 +44,7 @@ fn serve_models(ids: &[&str]) -> String { | |||
| 39 | let _ = stream.write_all(response.as_bytes()); | 44 | let _ = stream.write_all(response.as_bytes()); |
| 40 | let _ = stream.flush(); | 45 | let _ = stream.flush(); |
| 41 | }); | 46 | }); |
| 42 | format!("http://{addr}") | 47 | (format!("http://{addr}"), rx) |
| 43 | } | 48 | } |
| 44 | 49 | ||
| 45 | fn run(home: &PathBuf, args: &[&str], key: Option<&str>) -> Output { | 50 | fn run(home: &PathBuf, args: &[&str], key: Option<&str>) -> Output { |
| @@ -78,18 +83,29 @@ fn doctor_fails_without_a_key() { | |||
| 78 | #[test] | 83 | #[test] |
| 79 | fn doctor_passes_against_a_reachable_provider() { | 84 | fn doctor_passes_against_a_reachable_provider() { |
| 80 | let home = temp_home("ok"); | 85 | let home = temp_home("ok"); |
| 81 | let base = serve_models(&["deepseek-v4.1-flash", "other-model"]); | 86 | let (base, requests) = serve_models(&["deepseek-v4.1-flash", "other-model"]); |
| 82 | let output = run(&home, &["--doctor", "--base-url", &base], Some("test")); | 87 | let output = run(&home, &["--doctor", "--base-url", &base], Some("test")); |
| 83 | let stdout = String::from_utf8_lossy(&output.stdout); | 88 | let stdout = String::from_utf8_lossy(&output.stdout); |
| 84 | assert_eq!(output.status.code(), Some(0), "{stdout}"); | 89 | assert_eq!(output.status.code(), Some(0), "{stdout}"); |
| 85 | assert!(stdout.contains("2 models visible"), "{stdout}"); | 90 | assert!(stdout.contains("2 models visible"), "{stdout}"); |
| 86 | assert!(stdout.contains("all checks passed"), "{stdout}"); | 91 | assert!(stdout.contains("all checks passed"), "{stdout}"); |
| 92 | |||
| 93 | // The gateway rejects requests without a session header, including /models. | ||
| 94 | let request = requests.recv().unwrap().to_ascii_lowercase(); | ||
| 95 | let header = request | ||
| 96 | .lines() | ||
| 97 | .find(|line| line.starts_with("x-opencode-session:")) | ||
| 98 | .unwrap_or(""); | ||
| 99 | assert!( | ||
| 100 | header.len() > "x-opencode-session:".len() + 1, | ||
| 101 | "empty session header: {header:?}" | ||
| 102 | ); | ||
| 87 | } | 103 | } |
| 88 | 104 | ||
| 89 | #[test] | 105 | #[test] |
| 90 | fn doctor_flags_a_model_the_provider_does_not_list() { | 106 | fn doctor_flags_a_model_the_provider_does_not_list() { |
| 91 | let home = temp_home("unknown-model"); | 107 | let home = temp_home("unknown-model"); |
| 92 | let base = serve_models(&["some-other-model"]); | 108 | let (base, _requests) = serve_models(&["some-other-model"]); |
| 93 | let output = run(&home, &["--doctor", "--base-url", &base], Some("test")); | 109 | let output = run(&home, &["--doctor", "--base-url", &base], Some("test")); |
| 94 | let stdout = String::from_utf8_lossy(&output.stdout); | 110 | let stdout = String::from_utf8_lossy(&output.stdout); |
| 95 | assert_eq!(output.status.code(), Some(1), "{stdout}"); | 111 | assert_eq!(output.status.code(), Some(1), "{stdout}"); |
