summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cli.rs25
-rw-r--r--tests/sessions.rs8
-rw-r--r--tests/tools.rs27
3 files changed, 58 insertions, 2 deletions
diff --git a/tests/cli.rs b/tests/cli.rs
index 6c041fb..5a4c03f 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -145,3 +145,28 @@ fn show_renders_a_transcript() {
145 assert!(stdout.contains("on it"), "{stdout}"); 145 assert!(stdout.contains("on it"), "{stdout}");
146 assert!(stdout.contains("thinking about it"), "{stdout}"); 146 assert!(stdout.contains("thinking about it"), "{stdout}");
147} 147}
148
149#[test]
150fn a_flag_shaped_value_is_rejected_unless_attached() {
151 let output = agent().args(["--session", "--list"]).output().unwrap();
152 assert_eq!(output.status.code(), Some(2));
153 assert!(
154 String::from_utf8_lossy(&output.stderr).contains("needs a value"),
155 "{:?}",
156 String::from_utf8_lossy(&output.stderr)
157 );
158
159 // The attached form works and creates a session whose id starts with `-`.
160 let home = temp_home("dash-session");
161 let output = agent()
162 .env("HOME", &home)
163 .env("OPENCODE_API_KEY", "test")
164 .args(["--session=-abc", "--base-url", "http://127.0.0.1:9/v1"])
165 .stdin(std::process::Stdio::null())
166 .output()
167 .unwrap();
168 assert_eq!(output.status.code(), Some(0), "{output:?}");
169 assert!(home
170 .join(".local/share/agent686/sessions/-abc.jsonl")
171 .exists());
172}
diff --git a/tests/sessions.rs b/tests/sessions.rs
index 748b689..b381888 100644
--- a/tests/sessions.rs
+++ b/tests/sessions.rs
@@ -159,7 +159,9 @@ fn last_reply_prefers_content_and_falls_back_to_reasoning() {
159 .append(&json!({ "role": "assistant", "content": null }), Some("only thinking")) 159 .append(&json!({ "role": "assistant", "content": null }), Some("only thinking"))
160 .unwrap(); 160 .unwrap();
161 161
162 let reply = session::last_reply("reply").expect("there is a reply"); 162 drop(session);
163 let (opened, _system, _messages) = Session::open("reply").expect("open");
164 let reply = opened.last_reply.expect("there is a reply");
163 assert_eq!(reply.content, "the answer", "prefers a real block"); 165 assert_eq!(reply.content, "the answer", "prefers a real block");
164 assert_eq!(reply.reasoning, "the thinking", "and its own reasoning"); 166 assert_eq!(reply.reasoning, "the thinking", "and its own reasoning");
165 167
@@ -168,7 +170,9 @@ fn last_reply_prefers_content_and_falls_back_to_reasoning() {
168 session 170 session
169 .append(&json!({ "role": "assistant", "content": null }), Some("thoughts")) 171 .append(&json!({ "role": "assistant", "content": null }), Some("thoughts"))
170 .unwrap(); 172 .unwrap();
171 let reply = session::last_reply("reasoning-only").unwrap(); 173 drop(session);
174 let (opened, _system, _messages) = Session::open("reasoning-only").unwrap();
175 let reply = opened.last_reply.unwrap();
172 assert!(reply.content.is_empty()); 176 assert!(reply.content.is_empty());
173 assert_eq!(reply.reasoning, "thoughts"); 177 assert_eq!(reply.reasoning, "thoughts");
174} 178}
diff --git a/tests/tools.rs b/tests/tools.rs
index e54b5ff..4a8176e 100644
--- a/tests/tools.rs
+++ b/tests/tools.rs
@@ -490,3 +490,30 @@ fn bash_honours_a_per_call_output_budget() {
490 assert!(text.contains("output truncated"), "{text}"); 490 assert!(text.contains("output truncated"), "{text}");
491 assert!(text.len() < 10_000, "output was {} bytes", text.len()); 491 assert!(text.len() < 10_000, "output was {} bytes", text.len());
492} 492}
493
494#[test]
495fn validate_requires_content_and_new_but_allows_empty() {
496 use agent686::tools::validate;
497
498 // Missing, not empty.
499 assert!(validate("write", &json!({ "path": "a" })).is_err());
500 assert!(validate("edit", &json!({ "path": "a", "old": "b" })).is_err());
501 // Present but empty is legitimate (empty file, deletion).
502 assert!(validate("write", &json!({ "path": "a", "content": "" })).is_ok());
503 assert!(validate("edit", &json!({ "path": "a", "old": "b", "new": "" })).is_ok());
504}
505
506#[test]
507fn a_pipeline_that_exceeds_the_file_limit_is_reported() {
508 // 70 MiB through a pipeline: the grandchild (head) is the writer, so only the
509 // file-length check can detect the limit.
510 let text = run(
511 "bash",
512 &json!({ "cmd": "yes | head -c 70000000" }),
513 )
514 .unwrap();
515 assert!(
516 text.contains("output exceeded 64 MiB"),
517 "should report the file limit: {text}"
518 );
519}