Skip to content

Commit d5a7cc6

Browse files
committed
fix(#160): add regression test for SessionStore lifecycle (list_sessions, delete_session, session_exists)
Adds session_store_lifecycle_regression_160 test that verifies the full SessionStore CRUD lifecycle. Also fixes pre-existing non-exhaustive match errors in trident.rs for the ContentBlock::Thinking variant.
1 parent 499125c commit d5a7cc6

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

rust/crates/runtime/src/session_control.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,4 +1230,35 @@ mod tests {
12301230
);
12311231
fs::remove_dir_all(base).expect("temp dir should clean up");
12321232
}
1233+
1234+
/// #160 regression: store-level list_sessions/session_exists/delete_session
1235+
/// lifecycle works end-to-end.
1236+
#[test]
1237+
fn session_store_lifecycle_regression_160() {
1238+
// given
1239+
let base = temp_dir();
1240+
fs::create_dir_all(&base).expect("base dir should exist");
1241+
let store = SessionStore::from_cwd(&base).expect("store should build");
1242+
let session = persist_session_via_store(&store, "160 regression test");
1243+
1244+
// when/then — session exists and is listed before deletion
1245+
assert!(!store.list_sessions().expect("list").is_empty(),
1246+
"store should have at least one session");
1247+
assert!(store.session_exists(&session.session_id),
1248+
"session should exist before deletion");
1249+
1250+
// when — delete the session
1251+
let deleted = store.delete_session(&session.session_id)
1252+
.expect("delete should succeed");
1253+
1254+
// then — session is gone
1255+
assert_eq!(deleted.id, session.session_id);
1256+
assert!(!deleted.path.exists(), "session file should be removed");
1257+
assert!(!store.session_exists(&session.session_id),
1258+
"session should not exist after deletion");
1259+
assert!(store.list_sessions().expect("list").is_empty(),
1260+
"store should have no sessions after deletion");
1261+
1262+
fs::remove_dir_all(base).expect("temp dir should clean up");
1263+
}
12331264
}

rust/crates/runtime/src/trident.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ fn extract_file_operation(block: &ContentBlock) -> Option<(String, FileOp)> {
246246
Some((path, op_type))
247247
}
248248
ContentBlock::Text { .. } => None,
249+
ContentBlock::Thinking { .. } => None,
249250
}
250251
}
251252

@@ -344,6 +345,7 @@ fn is_chatty_message(msg: &ConversationMessage) -> bool {
344345
ContentBlock::Text { text } => text.len(),
345346
ContentBlock::ToolUse { input, .. } => input.len(),
346347
ContentBlock::ToolResult { output, .. } => output.len(),
348+
ContentBlock::Thinking { thinking, .. } => thinking.len(),
347349
}).sum();
348350

349351
let has_tool_use = msg.blocks.iter().any(|b| matches!(b, ContentBlock::ToolUse { .. }));
@@ -528,6 +530,9 @@ fn fingerprint_message(index: usize, msg: &ConversationMessage) -> Option<Messag
528530
ContentBlock::Text { text } => {
529531
text_length += text.len();
530532
}
533+
ContentBlock::Thinking { thinking, .. } => {
534+
text_length += thinking.len();
535+
}
531536
}
532537
}
533538

@@ -598,6 +603,7 @@ fn generate_cluster_summary(messages: &[&ConversationMessage]) -> String {
598603
}
599604
}
600605
ContentBlock::Text { .. } => {}
606+
ContentBlock::Thinking { .. } => {}
601607
}
602608
}
603609
}
@@ -633,8 +639,9 @@ fn estimate_message_tokens(message: &ConversationMessage) -> usize {
633639
ContentBlock::ToolResult {
634640
tool_name, output, ..
635641
} => (tool_name.len() + output.len()) / 4 + 1,
642+
ContentBlock::Thinking { thinking, .. } => thinking.len() / 4 + 1,
636643
})
637-
.sum()
644+
.sum()
638645
}
639646

640647
fn truncate_text(text: &str, max_chars: usize) -> String {

0 commit comments

Comments
 (0)