| 1 | use std::path::PathBuf; |
| 2 | |
| 3 | use deepseek_state::{SessionSource, StateStore, ThreadListFilters, ThreadMetadata, ThreadStatus}; |
| 4 | |
| 5 | fn temp_state_path(label: &str) -> PathBuf { |
| 6 | std::env::temp_dir().join(format!( |
| 7 | "deepseek_state_test_{}_{}_{}.db", |
| 8 | label, |
| 9 | std::process::id(), |
| 10 | chrono::Utc::now().timestamp_nanos_opt().unwrap_or(0) |
| 11 | )) |
| 12 | } |
| 13 | |
| 14 | #[test] |
| 15 | fn upsert_and_resume_thread_metadata() { |
| 16 | let path = temp_state_path("upsert_resume"); |
| 17 | let store = StateStore::open(Some(path.clone())).expect("open state store"); |
| 18 | let now = chrono::Utc::now().timestamp(); |
| 19 | let thread = ThreadMetadata { |
| 20 | id: "thread-test-1".to_string(), |
| 21 | rollout_path: Some(PathBuf::from("/tmp/rollout.jsonl")), |
| 22 | preview: "hello".to_string(), |
| 23 | ephemeral: false, |
| 24 | model_provider: "deepseek".to_string(), |
| 25 | created_at: now, |
| 26 | updated_at: now, |
| 27 | status: ThreadStatus::Running, |
| 28 | path: Some(PathBuf::from("/tmp/project")), |
| 29 | cwd: PathBuf::from("/tmp/project"), |
| 30 | cli_version: "0.0.0-test".to_string(), |
| 31 | source: SessionSource::Interactive, |
| 32 | name: Some("Test Thread".to_string()), |
| 33 | sandbox_policy: Some("workspace-write".to_string()), |
| 34 | approval_mode: Some("on-request".to_string()), |
| 35 | archived: false, |
| 36 | archived_at: None, |
| 37 | git_sha: None, |
| 38 | git_branch: None, |
| 39 | git_origin_url: None, |
| 40 | memory_mode: Some("extended".to_string()), |
| 41 | }; |
| 42 | store.upsert_thread(&thread).expect("upsert thread"); |
| 43 | |
| 44 | let loaded = store |
| 45 | .get_thread("thread-test-1") |
| 46 | .expect("read thread") |
| 47 | .expect("thread must exist"); |
| 48 | assert_eq!(loaded.id, "thread-test-1"); |
| 49 | assert_eq!(loaded.name.as_deref(), Some("Test Thread")); |
| 50 | assert_eq!(loaded.memory_mode.as_deref(), Some("extended")); |
| 51 | assert_eq!( |
| 52 | loaded.rollout_path, |
| 53 | Some(PathBuf::from("/tmp/rollout.jsonl")) |
| 54 | ); |
| 55 | |
| 56 | store |
| 57 | .mark_archived("thread-test-1") |
| 58 | .expect("archive thread"); |
| 59 | let archived = store |
| 60 | .get_thread("thread-test-1") |
| 61 | .expect("read archived thread") |
| 62 | .expect("thread exists after archive"); |
| 63 | assert!(archived.archived); |
| 64 | |
| 65 | let listed = store |
| 66 | .list_threads(ThreadListFilters { |
| 67 | include_archived: true, |
| 68 | limit: Some(10), |
| 69 | }) |
| 70 | .expect("list threads"); |
| 71 | assert!(!listed.is_empty()); |
| 72 | } |
| 73 |