From 84e70c0e73460e5db1297c47d02d9b76802bfdf7 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 18 Nov 2026 12:28:29 +0100 Subject: 0.9.1: correctness fixes from the audit - 64 MiB limit detected by file length, so pipelines and redirects are reported - bash temp files removed on every path via a scope guard - validate requires content/new as the schemas declare (present, may be empty) - Session::open folds in model-switch records; resume matches --list - combining mark at a wrap boundary no longer counts as a new row - --flag=value accepted; flag-shaped values rejected - dead code removed; last_reply folded into open (one read per resume) --- tests/cli.rs | 25 +++++++++++++++++++++++++ tests/sessions.rs | 8 ++++++-- tests/tools.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) (limited to 'tests') 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() { assert!(stdout.contains("on it"), "{stdout}"); assert!(stdout.contains("thinking about it"), "{stdout}"); } + +#[test] +fn a_flag_shaped_value_is_rejected_unless_attached() { + let output = agent().args(["--session", "--list"]).output().unwrap(); + assert_eq!(output.status.code(), Some(2)); + assert!( + String::from_utf8_lossy(&output.stderr).contains("needs a value"), + "{:?}", + String::from_utf8_lossy(&output.stderr) + ); + + // The attached form works and creates a session whose id starts with `-`. + let home = temp_home("dash-session"); + let output = agent() + .env("HOME", &home) + .env("OPENCODE_API_KEY", "test") + .args(["--session=-abc", "--base-url", "http://127.0.0.1:9/v1"]) + .stdin(std::process::Stdio::null()) + .output() + .unwrap(); + assert_eq!(output.status.code(), Some(0), "{output:?}"); + assert!(home + .join(".local/share/agent686/sessions/-abc.jsonl") + .exists()); +} 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() { .append(&json!({ "role": "assistant", "content": null }), Some("only thinking")) .unwrap(); - let reply = session::last_reply("reply").expect("there is a reply"); + drop(session); + let (opened, _system, _messages) = Session::open("reply").expect("open"); + let reply = opened.last_reply.expect("there is a reply"); assert_eq!(reply.content, "the answer", "prefers a real block"); assert_eq!(reply.reasoning, "the thinking", "and its own reasoning"); @@ -168,7 +170,9 @@ fn last_reply_prefers_content_and_falls_back_to_reasoning() { session .append(&json!({ "role": "assistant", "content": null }), Some("thoughts")) .unwrap(); - let reply = session::last_reply("reasoning-only").unwrap(); + drop(session); + let (opened, _system, _messages) = Session::open("reasoning-only").unwrap(); + let reply = opened.last_reply.unwrap(); assert!(reply.content.is_empty()); assert_eq!(reply.reasoning, "thoughts"); } 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() { assert!(text.contains("output truncated"), "{text}"); assert!(text.len() < 10_000, "output was {} bytes", text.len()); } + +#[test] +fn validate_requires_content_and_new_but_allows_empty() { + use agent686::tools::validate; + + // Missing, not empty. + assert!(validate("write", &json!({ "path": "a" })).is_err()); + assert!(validate("edit", &json!({ "path": "a", "old": "b" })).is_err()); + // Present but empty is legitimate (empty file, deletion). + assert!(validate("write", &json!({ "path": "a", "content": "" })).is_ok()); + assert!(validate("edit", &json!({ "path": "a", "old": "b", "new": "" })).is_ok()); +} + +#[test] +fn a_pipeline_that_exceeds_the_file_limit_is_reported() { + // 70 MiB through a pipeline: the grandchild (head) is the writer, so only the + // file-length check can detect the limit. + let text = run( + "bash", + &json!({ "cmd": "yes | head -c 70000000" }), + ) + .unwrap(); + assert!( + text.contains("output exceeded 64 MiB"), + "should report the file limit: {text}" + ); +} -- cgit v1.2.3