From b7b01494926a134f39daf8102281889702ddf62b Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 15 Nov 2026 17:13:24 +0100 Subject: 0.5.3: session locking, UTF-8 and size guards for edit, correct character widths - exclusive flock on session files - edit refuses non-UTF-8 and >64 MiB files with actionable messages - editor uses unicode-width, expands tabs, handles resize --- tests/sessions.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/sessions.rs') diff --git a/tests/sessions.rs b/tests/sessions.rs index b445242..f21be24 100644 --- a/tests/sessions.rs +++ b/tests/sessions.rs @@ -4,6 +4,9 @@ use std::process::Command; use serde_json::json; +/// Tests in this binary share process-wide environment variables. +static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); + use agent686::session::{self, Session}; fn temp_dir(tag: &str) -> PathBuf { @@ -15,6 +18,7 @@ fn temp_dir(tag: &str) -> PathBuf { #[test] fn sessions_create_list_and_replay() { + let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); let dir = temp_dir("roundtrip"); std::env::set_var("AGENT686_DATA", &dir); @@ -50,6 +54,8 @@ fn sessions_create_list_and_replay() { assert_eq!(listed[0].model, "model-a"); assert_eq!(listed[0].messages, 2); + // A session holds an exclusive lock while open. + drop(alpha); let (reopened, system_back, messages) = Session::open("alpha").unwrap(); assert_eq!(reopened.id, "alpha"); assert_eq!(system_back["content"], "frozen"); @@ -73,3 +79,19 @@ fn cli_lists_sessions_without_a_key() { let stdout = String::from_utf8_lossy(&output.stdout); assert!(stdout.contains("no sessions"), "{stdout}"); } + +#[test] +fn a_session_cannot_be_open_twice() { + let _env = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + let dir = temp_dir("lock"); + std::env::set_var("AGENT686_DATA", &dir); + + let system = json!({ "role": "system", "content": "x" }); + let first = Session::create_as("locked".into(), "m", &system).unwrap(); + + let error = Session::open("locked").err().expect("second open must fail"); + assert!(error.contains("already open"), "{error}"); + + drop(first); + Session::open("locked").expect("after the first handle closes it is available"); +} -- cgit v1.2.3