summaryrefslogtreecommitdiffstats
path: root/tests/sessions.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-15 18:00:12 +0100
committersalmonik <salmonik@tuta.io>2026-11-15 18:00:12 +0100
commit8ae5bd48cf233315b5f36a7a6b39002a5e77f74b (patch)
tree71c9b71f90f3cc64544dd506041468ee9bcbcda1 /tests/sessions.rs
parent0.6.2: resizing no longer duplicates the prompt (diff)
downloadagent686-8ae5bd48cf233315b5f36a7a6b39002a5e77f74b.tar.gz
agent686-8ae5bd48cf233315b5f36a7a6b39002a5e77f74b.zip
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
Diffstat (limited to '')
-rw-r--r--tests/sessions.rs59
1 files changed, 59 insertions, 0 deletions
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() {
110 assert_eq!(listed.len(), 1); 110 assert_eq!(listed.len(), 1);
111 assert_eq!(listed[0].model, "model-b"); 111 assert_eq!(listed[0].model, "model-b");
112} 112}
113
114#[test]
115fn a_torn_utf8_line_does_not_brick_a_session() {
116 let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
117 let dir = temp_dir("torn");
118 std::env::set_var("AGENT686_DATA", &dir);
119 let sessions = dir.join("sessions");
120 fs::create_dir_all(&sessions).unwrap();
121
122 let mut raw = Vec::new();
123 raw.extend_from_slice(
124 br#"{"t":"header","session":"torn","model":"m","cwd":"/tmp","system":{"role":"system","content":"s"}}
125"#,
126 );
127 raw.extend_from_slice(br#"{"t":"msg","role":"user","content":"hello"}
128"#);
129 // A killed write that split a multi-byte character.
130 raw.extend_from_slice(b"{\"t\":\"msg\",\"role\":\"user\",\"content\":\"caf\xc3\"}\n");
131 fs::write(sessions.join("torn.jsonl"), raw).unwrap();
132
133 let (_session, _system, messages) = Session::open("torn").expect("torn line must not fail");
134 // Lossy decoding keeps the message (with a replacement character) rather
135 // than dropping a valid JSON line; what matters is that open succeeds.
136 assert_eq!(messages.len(), 2);
137 assert_eq!(messages[0]["content"], "hello");
138 assert!(messages[1]["content"].as_str().unwrap().starts_with("caf"));
139}
140
141#[test]
142fn last_reply_prefers_content_and_falls_back_to_reasoning() {
143 let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
144 let dir = temp_dir("last-reply");
145 std::env::set_var("AGENT686_DATA", &dir);
146
147 let system = json!({ "role": "system", "content": "x" });
148 let mut session = Session::create_as("reply".into(), "m", &system).unwrap();
149 session
150 .append(
151 &json!({ "role": "assistant", "content": "the answer" }),
152 Some("the thinking"),
153 )
154 .unwrap();
155 session
156 .append(&json!({ "role": "assistant", "content": null }), Some("only thinking"))
157 .unwrap();
158
159 let reply = session::last_reply("reply").expect("there is a reply");
160 assert_eq!(reply.content, "the answer", "prefers a real block");
161 assert_eq!(reply.reasoning, "the thinking", "and its own reasoning");
162
163 // With no content anywhere, reasoning is the fallback.
164 let mut session = Session::create_as("reasoning-only".into(), "m", &system).unwrap();
165 session
166 .append(&json!({ "role": "assistant", "content": null }), Some("thoughts"))
167 .unwrap();
168 let reply = session::last_reply("reasoning-only").unwrap();
169 assert!(reply.content.is_empty());
170 assert_eq!(reply.reasoning, "thoughts");
171}