From 8ae5bd48cf233315b5f36a7a6b39002a5e77f74b Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 15 Nov 2026 18:00:12 +0100 Subject: 0.7.0: resume shows where you left off; no approval for unparsable calls - --continue prints the last answer, or the last reasoning block if there was none - tool arguments are validated before prompting, so an empty bash call becomes an error for the model instead of a blank approval - empty placeholder tool calls are dropped and reported - sessions tolerate invalid UTF-8 lines from a torn write - AGENT686_DEBUG_STREAM=1 dumps SSE frames --- tests/sessions.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'tests/sessions.rs') diff --git a/tests/sessions.rs b/tests/sessions.rs index 1d40f64..df2f3b2 100644 --- a/tests/sessions.rs +++ b/tests/sessions.rs @@ -110,3 +110,62 @@ fn listing_reports_the_model_in_use_after_a_switch() { assert_eq!(listed.len(), 1); assert_eq!(listed[0].model, "model-b"); } + +#[test] +fn a_torn_utf8_line_does_not_brick_a_session() { + let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + let dir = temp_dir("torn"); + std::env::set_var("AGENT686_DATA", &dir); + let sessions = dir.join("sessions"); + fs::create_dir_all(&sessions).unwrap(); + + let mut raw = Vec::new(); + raw.extend_from_slice( + br#"{"t":"header","session":"torn","model":"m","cwd":"/tmp","system":{"role":"system","content":"s"}} +"#, + ); + raw.extend_from_slice(br#"{"t":"msg","role":"user","content":"hello"} +"#); + // A killed write that split a multi-byte character. + raw.extend_from_slice(b"{\"t\":\"msg\",\"role\":\"user\",\"content\":\"caf\xc3\"}\n"); + fs::write(sessions.join("torn.jsonl"), raw).unwrap(); + + let (_session, _system, messages) = Session::open("torn").expect("torn line must not fail"); + // Lossy decoding keeps the message (with a replacement character) rather + // than dropping a valid JSON line; what matters is that open succeeds. + assert_eq!(messages.len(), 2); + assert_eq!(messages[0]["content"], "hello"); + assert!(messages[1]["content"].as_str().unwrap().starts_with("caf")); +} + +#[test] +fn last_reply_prefers_content_and_falls_back_to_reasoning() { + let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + let dir = temp_dir("last-reply"); + std::env::set_var("AGENT686_DATA", &dir); + + let system = json!({ "role": "system", "content": "x" }); + let mut session = Session::create_as("reply".into(), "m", &system).unwrap(); + session + .append( + &json!({ "role": "assistant", "content": "the answer" }), + Some("the thinking"), + ) + .unwrap(); + session + .append(&json!({ "role": "assistant", "content": null }), Some("only thinking")) + .unwrap(); + + let reply = session::last_reply("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"); + + // With no content anywhere, reasoning is the fallback. + let mut session = Session::create_as("reasoning-only".into(), "m", &system).unwrap(); + session + .append(&json!({ "role": "assistant", "content": null }), Some("thoughts")) + .unwrap(); + let reply = session::last_reply("reasoning-only").unwrap(); + assert!(reply.content.is_empty()); + assert_eq!(reply.reasoning, "thoughts"); +} -- cgit v1.2.3