intent_engine/
session_restore.rs

1use crate::db::models::{TaskSortBy, WorkspaceStats};
2use crate::error::Result;
3use crate::events::EventManager;
4use crate::tasks::TaskManager;
5use crate::workspace::WorkspaceManager;
6use serde::{Deserialize, Serialize};
7use sqlx::SqlitePool;
8
9/// Session restoration status
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11#[serde(rename_all = "lowercase")]
12pub enum SessionStatus {
13    /// Successfully restored focus
14    Success,
15    /// No active focus (workspace exists but no current task)
16    NoFocus,
17    /// Error occurred
18    Error,
19}
20
21/// Error types for session restoration
22#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
23#[serde(rename_all = "snake_case")]
24pub enum ErrorType {
25    WorkspaceNotFound,
26    DatabaseCorrupted,
27    PermissionDenied,
28}
29
30/// Simplified task info for session restoration
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct TaskInfo {
33    pub id: i64,
34    pub name: String,
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub status: Option<String>,
37}
38
39/// Detailed current task info
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct CurrentTaskInfo {
42    pub id: i64,
43    pub name: String,
44    pub status: String,
45    /// Full spec
46    pub spec: Option<String>,
47    /// Truncated spec (first 100 chars)
48    pub spec_preview: Option<String>,
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub created_at: Option<String>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub first_doing_at: Option<String>,
53}
54
55/// Siblings information
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct SiblingsInfo {
58    pub total: usize,
59    pub done: usize,
60    pub doing: usize,
61    pub todo: usize,
62    pub done_list: Vec<TaskInfo>,
63}
64
65/// Children information
66#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct ChildrenInfo {
68    pub total: usize,
69    pub todo: usize,
70    pub list: Vec<TaskInfo>,
71}
72
73/// Event information
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct EventInfo {
76    #[serde(rename = "type")]
77    pub event_type: String,
78    pub data: String,
79    pub timestamp: String,
80}
81
82// WorkspaceStats is imported from crate::db::models
83
84/// Complete session restoration result
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct SessionRestoreResult {
87    pub status: SessionStatus,
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub workspace_path: Option<String>,
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub current_task: Option<CurrentTaskInfo>,
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub parent_task: Option<TaskInfo>,
94    #[serde(skip_serializing_if = "Option::is_none")]
95    pub siblings: Option<SiblingsInfo>,
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub children: Option<ChildrenInfo>,
98    #[serde(skip_serializing_if = "Option::is_none")]
99    pub recent_events: Option<Vec<EventInfo>>,
100    #[serde(skip_serializing_if = "Option::is_none")]
101    pub suggested_commands: Option<Vec<String>>,
102    #[serde(skip_serializing_if = "Option::is_none")]
103    pub stats: Option<WorkspaceStats>,
104    /// Recommended next task (from pick_next) - used when no focus
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub recommended_task: Option<TaskInfo>,
107    /// Top pending tasks by priority - used when no focus
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub top_pending_tasks: Option<Vec<TaskInfo>>,
110    #[serde(skip_serializing_if = "Option::is_none")]
111    pub error_type: Option<ErrorType>,
112    #[serde(skip_serializing_if = "Option::is_none")]
113    pub message: Option<String>,
114    #[serde(skip_serializing_if = "Option::is_none")]
115    pub recovery_suggestion: Option<String>,
116}
117
118/// Session restoration manager
119pub struct SessionRestoreManager<'a> {
120    pool: &'a SqlitePool,
121}
122
123impl<'a> SessionRestoreManager<'a> {
124    pub fn new(pool: &'a SqlitePool) -> Self {
125        Self { pool }
126    }
127
128    /// Restore session with full context
129    pub async fn restore(&self, include_events: usize) -> Result<SessionRestoreResult> {
130        let workspace_mgr = WorkspaceManager::new(self.pool);
131        let task_mgr = TaskManager::new(self.pool);
132        let event_mgr = EventManager::new(self.pool);
133
134        // Get current workspace path (for display purposes)
135        let workspace_path = std::env::current_dir()
136            .ok()
137            .and_then(|p| p.to_str().map(String::from));
138
139        // Get current task
140        let current_task_id = match workspace_mgr.get_current_task(None).await {
141            Ok(response) => {
142                if let Some(id) = response.current_task_id {
143                    id
144                } else {
145                    // No focus - return stats
146                    return self.restore_no_focus(workspace_path).await;
147                }
148            },
149            Err(_) => {
150                // Error getting current task
151                return Ok(Self::error_result(
152                    workspace_path,
153                    ErrorType::DatabaseCorrupted,
154                    "Unable to query workspace state",
155                    "Run 'ie workspace init' or check database integrity",
156                ));
157            },
158        };
159
160        // Get current task details
161        let task = match task_mgr.get_task(current_task_id).await {
162            Ok(t) => t,
163            Err(_) => {
164                return Ok(Self::error_result(
165                    workspace_path,
166                    ErrorType::DatabaseCorrupted,
167                    "Current task not found in database",
168                    "Run 'ie current --set <task_id>' to set a valid task",
169                ));
170            },
171        };
172
173        let spec_preview = task.spec.as_ref().map(|s| Self::truncate_spec(s, 100));
174
175        let current_task = CurrentTaskInfo {
176            id: task.id,
177            name: task.name.clone(),
178            status: task.status.clone(),
179            spec: task.spec.clone(),
180            spec_preview,
181            created_at: task.first_todo_at.map(|dt| dt.to_rfc3339()),
182            first_doing_at: task.first_doing_at.map(|dt| dt.to_rfc3339()),
183        };
184
185        // Get parent task
186        let parent_task = if let Some(parent_id) = task.parent_id {
187            task_mgr.get_task(parent_id).await.ok().map(|p| TaskInfo {
188                id: p.id,
189                name: p.name,
190                status: Some(p.status),
191            })
192        } else {
193            None
194        };
195
196        // Get siblings info
197        let siblings = if let Some(parent_id) = task.parent_id {
198            let result = task_mgr
199                .find_tasks(None, Some(Some(parent_id)), None, None, None)
200                .await?;
201            Self::build_siblings_info(&result.tasks)
202        } else {
203            None
204        };
205
206        // Get children info
207        let children = {
208            let result = task_mgr
209                .find_tasks(None, Some(Some(current_task_id)), None, None, None)
210                .await?;
211            Self::build_children_info(&result.tasks)
212        };
213
214        // Get recent events
215        let events = event_mgr
216            .list_events(Some(current_task_id), None, None, None)
217            .await?;
218        let recent_events: Vec<EventInfo> = events
219            .into_iter()
220            .take(include_events)
221            .map(|e| EventInfo {
222                event_type: e.log_type,
223                data: e.discussion_data,
224                timestamp: e.timestamp.to_rfc3339(),
225            })
226            .collect();
227
228        // Suggest next commands based on context
229        let suggested_commands = Self::suggest_commands(&current_task, children.as_ref());
230
231        Ok(SessionRestoreResult {
232            status: SessionStatus::Success,
233            workspace_path,
234            current_task: Some(current_task),
235            parent_task,
236            siblings,
237            children,
238            recent_events: Some(recent_events),
239            suggested_commands: Some(suggested_commands),
240            stats: None,
241            recommended_task: None,
242            top_pending_tasks: None,
243            error_type: None,
244            message: None,
245            recovery_suggestion: None,
246        })
247    }
248
249    /// Restore when no focus exists
250    ///
251    /// Uses efficient SQL aggregation for stats and limited queries for task lists.
252    /// Does NOT load all tasks into memory.
253    async fn restore_no_focus(
254        &self,
255        workspace_path: Option<String>,
256    ) -> Result<SessionRestoreResult> {
257        let task_mgr = TaskManager::new(self.pool);
258
259        // 1. Get stats using SQL aggregation (no data loading)
260        let stats = task_mgr.get_stats().await?;
261
262        // 2. Get recommended next task via pick_next
263        let recommendation = task_mgr.pick_next().await?;
264        let recommended_task = recommendation.task.map(|t| TaskInfo {
265            id: t.id,
266            name: t.name,
267            status: Some(t.status),
268        });
269
270        // 3. Get top 5 pending tasks by priority (limited query)
271        let top_pending_result = task_mgr
272            .find_tasks(
273                Some("todo"),
274                None,
275                Some(TaskSortBy::Priority),
276                Some(5),
277                None,
278            )
279            .await?;
280        let top_pending_tasks: Vec<TaskInfo> = top_pending_result
281            .tasks
282            .into_iter()
283            .map(|t| TaskInfo {
284                id: t.id,
285                name: t.name,
286                status: Some(t.status),
287            })
288            .collect();
289
290        let suggested_commands = vec![
291            "ie pick-next".to_string(),
292            "ie task list --status todo".to_string(),
293        ];
294
295        Ok(SessionRestoreResult {
296            status: SessionStatus::NoFocus,
297            workspace_path,
298            current_task: None,
299            parent_task: None,
300            siblings: None,
301            children: None,
302            recent_events: None,
303            suggested_commands: Some(suggested_commands),
304            stats: Some(stats),
305            recommended_task,
306            top_pending_tasks: if top_pending_tasks.is_empty() {
307                None
308            } else {
309                Some(top_pending_tasks)
310            },
311            error_type: None,
312            message: None,
313            recovery_suggestion: None,
314        })
315    }
316
317    /// Build siblings information
318    fn build_siblings_info(siblings: &[crate::db::models::Task]) -> Option<SiblingsInfo> {
319        if siblings.is_empty() {
320            return None;
321        }
322
323        let done_list: Vec<TaskInfo> = siblings
324            .iter()
325            .filter(|s| s.status == "done")
326            .map(|s| TaskInfo {
327                id: s.id,
328                name: s.name.clone(),
329                status: Some(s.status.clone()),
330            })
331            .collect();
332
333        Some(SiblingsInfo {
334            total: siblings.len(),
335            done: siblings.iter().filter(|s| s.status == "done").count(),
336            doing: siblings.iter().filter(|s| s.status == "doing").count(),
337            todo: siblings.iter().filter(|s| s.status == "todo").count(),
338            done_list,
339        })
340    }
341
342    /// Build children information
343    fn build_children_info(children: &[crate::db::models::Task]) -> Option<ChildrenInfo> {
344        if children.is_empty() {
345            return None;
346        }
347
348        let list: Vec<TaskInfo> = children
349            .iter()
350            .map(|c| TaskInfo {
351                id: c.id,
352                name: c.name.clone(),
353                status: Some(c.status.clone()),
354            })
355            .collect();
356
357        Some(ChildrenInfo {
358            total: children.len(),
359            todo: children.iter().filter(|c| c.status == "todo").count(),
360            list,
361        })
362    }
363
364    /// Suggest next commands based on context
365    fn suggest_commands(
366        _current_task: &CurrentTaskInfo,
367        children: Option<&ChildrenInfo>,
368    ) -> Vec<String> {
369        let mut commands = vec![];
370
371        // If there are blockers, suggest viewing them
372        commands.push("ie event list --type blocker".to_string());
373
374        // Suggest completion or spawning subtasks
375        if let Some(children) = children {
376            if children.todo > 0 {
377                commands.push("ie task done".to_string());
378            }
379        } else {
380            commands.push("ie task done".to_string());
381        }
382
383        commands.push("ie task spawn-subtask".to_string());
384
385        commands
386    }
387
388    /// Truncate spec to specified length
389    fn truncate_spec(spec: &str, max_len: usize) -> String {
390        if spec.len() <= max_len {
391            spec.to_string()
392        } else {
393            format!("{}...", &spec[..max_len])
394        }
395    }
396
397    /// Create error result
398    fn error_result(
399        workspace_path: Option<String>,
400        error_type: ErrorType,
401        message: &str,
402        recovery: &str,
403    ) -> SessionRestoreResult {
404        let suggested_commands = match error_type {
405            ErrorType::WorkspaceNotFound => {
406                vec!["ie workspace init".to_string(), "ie help".to_string()]
407            },
408            ErrorType::DatabaseCorrupted => {
409                vec!["ie workspace init".to_string(), "ie doctor".to_string()]
410            },
411            ErrorType::PermissionDenied => {
412                vec!["chmod 644 .intent-engine/workspace.db".to_string()]
413            },
414        };
415
416        SessionRestoreResult {
417            status: SessionStatus::Error,
418            workspace_path,
419            current_task: None,
420            parent_task: None,
421            siblings: None,
422            children: None,
423            recent_events: None,
424            suggested_commands: Some(suggested_commands),
425            stats: None,
426            recommended_task: None,
427            top_pending_tasks: None,
428            error_type: Some(error_type),
429            message: Some(message.to_string()),
430            recovery_suggestion: Some(recovery.to_string()),
431        }
432    }
433}
434
435#[cfg(test)]
436mod tests {
437    use super::*;
438    use crate::events::EventManager;
439    use crate::tasks::TaskManager;
440    use crate::test_utils::test_helpers::TestContext;
441    use crate::workspace::WorkspaceManager;
442
443    #[test]
444    fn test_truncate_spec() {
445        let spec = "a".repeat(200);
446        let truncated = SessionRestoreManager::truncate_spec(&spec, 100);
447        assert_eq!(truncated.len(), 103); // 100 + "..."
448        assert!(truncated.ends_with("..."));
449    }
450
451    #[test]
452    fn test_truncate_spec_short() {
453        let spec = "Short spec";
454        let truncated = SessionRestoreManager::truncate_spec(spec, 100);
455        assert_eq!(truncated, spec);
456        assert!(!truncated.ends_with("..."));
457    }
458
459    #[tokio::test]
460    async fn test_restore_with_focus_minimal() {
461        let ctx = TestContext::new().await;
462        let pool = ctx.pool();
463
464        // Create a task and set it as current
465        let task_mgr = TaskManager::new(pool);
466        let task = task_mgr
467            .add_task("Test task", None, None, None)
468            .await
469            .unwrap();
470
471        let workspace_mgr = WorkspaceManager::new(pool);
472        workspace_mgr.set_current_task(task.id, None).await.unwrap();
473
474        // Restore session
475        let restore_mgr = SessionRestoreManager::new(pool);
476        let result = restore_mgr.restore(3).await.unwrap();
477
478        // Verify
479        assert_eq!(result.status, SessionStatus::Success);
480        assert!(result.current_task.is_some());
481        let current_task = result.current_task.unwrap();
482        assert_eq!(current_task.id, task.id);
483        assert_eq!(current_task.name, "Test task");
484    }
485
486    #[tokio::test]
487    async fn test_restore_with_focus_rich_context() {
488        let ctx = TestContext::new().await;
489        let pool = ctx.pool();
490
491        let task_mgr = TaskManager::new(pool);
492        let event_mgr = EventManager::new(pool);
493        let workspace_mgr = WorkspaceManager::new(pool);
494
495        // Create parent task
496        let parent = task_mgr
497            .add_task("Parent task", Some("Parent spec"), None, None)
498            .await
499            .unwrap();
500
501        // Create 3 siblings (1 done, 1 doing, 1 todo)
502        let sibling1 = task_mgr
503            .add_task("Sibling 1", None, Some(parent.id), None)
504            .await
505            .unwrap();
506        task_mgr
507            .update_task(sibling1.id, None, None, None, Some("done"), None, None)
508            .await
509            .unwrap();
510
511        let current = task_mgr
512            .add_task("Current task", Some("Current spec"), Some(parent.id), None)
513            .await
514            .unwrap();
515        task_mgr
516            .update_task(current.id, None, None, None, Some("doing"), None, None)
517            .await
518            .unwrap();
519        workspace_mgr
520            .set_current_task(current.id, None)
521            .await
522            .unwrap();
523
524        let _sibling3 = task_mgr
525            .add_task("Sibling 3", None, Some(parent.id), None)
526            .await
527            .unwrap();
528
529        // Add children to current task
530        let _child1 = task_mgr
531            .add_task("Child 1", None, Some(current.id), None)
532            .await
533            .unwrap();
534        let _child2 = task_mgr
535            .add_task("Child 2", None, Some(current.id), None)
536            .await
537            .unwrap();
538
539        // Add events
540        event_mgr
541            .add_event(current.id, "decision", "Decision 1")
542            .await
543            .unwrap();
544        event_mgr
545            .add_event(current.id, "blocker", "Blocker 1")
546            .await
547            .unwrap();
548        event_mgr
549            .add_event(current.id, "note", "Note 1")
550            .await
551            .unwrap();
552
553        // Restore session
554        let restore_mgr = SessionRestoreManager::new(pool);
555        let result = restore_mgr.restore(3).await.unwrap();
556
557        // Verify complete context
558        assert_eq!(result.status, SessionStatus::Success);
559
560        let task = result.current_task.unwrap();
561        assert_eq!(task.id, current.id);
562        assert_eq!(task.spec, Some("Current spec".to_string()));
563
564        // Verify parent
565        assert!(result.parent_task.is_some());
566        let parent_info = result.parent_task.unwrap();
567        assert_eq!(parent_info.id, parent.id);
568
569        // Verify siblings
570        assert!(result.siblings.is_some());
571        let siblings = result.siblings.unwrap();
572        assert_eq!(siblings.total, 3);
573        assert_eq!(siblings.done, 1);
574        assert_eq!(siblings.doing, 1);
575        assert_eq!(siblings.todo, 1);
576        assert_eq!(siblings.done_list.len(), 1);
577
578        // Verify children
579        assert!(result.children.is_some());
580        let children = result.children.unwrap();
581        assert_eq!(children.total, 2);
582        assert_eq!(children.todo, 2);
583
584        // Verify events
585        assert!(result.recent_events.is_some());
586        let events = result.recent_events.unwrap();
587        assert_eq!(events.len(), 3);
588
589        // Check event types
590        let event_types: Vec<&str> = events.iter().map(|e| e.event_type.as_str()).collect();
591        assert!(event_types.contains(&"decision"));
592        assert!(event_types.contains(&"blocker"));
593        assert!(event_types.contains(&"note"));
594    }
595
596    #[tokio::test]
597    async fn test_restore_with_spec_preview() {
598        let ctx = TestContext::new().await;
599        let pool = ctx.pool();
600
601        let task_mgr = TaskManager::new(pool);
602        let workspace_mgr = WorkspaceManager::new(pool);
603
604        // Create task with long spec
605        let long_spec = "a".repeat(200);
606        let task = task_mgr
607            .add_task("Test task", Some(&long_spec), None, None)
608            .await
609            .unwrap();
610        workspace_mgr.set_current_task(task.id, None).await.unwrap();
611
612        // Restore
613        let restore_mgr = SessionRestoreManager::new(pool);
614        let result = restore_mgr.restore(3).await.unwrap();
615
616        // Verify spec preview is truncated
617        let current_task = result.current_task.unwrap();
618        assert_eq!(current_task.spec, Some(long_spec));
619        assert!(current_task.spec_preview.is_some());
620        let preview = current_task.spec_preview.unwrap();
621        assert_eq!(preview.len(), 103); // 100 + "..."
622        assert!(preview.ends_with("..."));
623    }
624
625    #[tokio::test]
626    async fn test_restore_no_focus() {
627        let ctx = TestContext::new().await;
628        let pool = ctx.pool();
629
630        let task_mgr = TaskManager::new(pool);
631
632        // Create some tasks but no current task
633        task_mgr.add_task("Task 1", None, None, None).await.unwrap();
634        task_mgr.add_task("Task 2", None, None, None).await.unwrap();
635
636        // Restore
637        let restore_mgr = SessionRestoreManager::new(pool);
638        let result = restore_mgr.restore(3).await.unwrap();
639
640        // Verify no focus status
641        assert_eq!(result.status, SessionStatus::NoFocus);
642        assert!(result.current_task.is_none());
643        assert!(result.stats.is_some());
644
645        let stats = result.stats.unwrap();
646        assert_eq!(stats.total_tasks, 2);
647        assert_eq!(stats.todo, 2);
648
649        // Verify new fields: recommended_task and top_pending_tasks
650        // pick_next should recommend one of the tasks
651        assert!(result.recommended_task.is_some());
652
653        // top_pending_tasks should contain the 2 todo tasks
654        assert!(result.top_pending_tasks.is_some());
655        let top_pending = result.top_pending_tasks.unwrap();
656        assert_eq!(top_pending.len(), 2);
657    }
658
659    #[tokio::test]
660    async fn test_restore_recent_events_limit() {
661        let ctx = TestContext::new().await;
662        let pool = ctx.pool();
663
664        let task_mgr = TaskManager::new(pool);
665        let event_mgr = EventManager::new(pool);
666        let workspace_mgr = WorkspaceManager::new(pool);
667
668        // Create task
669        let task = task_mgr
670            .add_task("Test task", None, None, None)
671            .await
672            .unwrap();
673        workspace_mgr.set_current_task(task.id, None).await.unwrap();
674
675        // Add 10 events
676        for i in 0..10 {
677            event_mgr
678                .add_event(task.id, "note", &format!("Event {}", i))
679                .await
680                .unwrap();
681        }
682
683        // Restore with default limit (3)
684        let restore_mgr = SessionRestoreManager::new(pool);
685        let result = restore_mgr.restore(3).await.unwrap();
686
687        // Should only return 3 events (most recent)
688        let events = result.recent_events.unwrap();
689        assert_eq!(events.len(), 3);
690    }
691
692    #[tokio::test]
693    async fn test_restore_custom_events_limit() {
694        let ctx = TestContext::new().await;
695        let pool = ctx.pool();
696
697        let task_mgr = TaskManager::new(pool);
698        let event_mgr = EventManager::new(pool);
699        let workspace_mgr = WorkspaceManager::new(pool);
700
701        // Create task
702        let task = task_mgr
703            .add_task("Test task", None, None, None)
704            .await
705            .unwrap();
706        workspace_mgr.set_current_task(task.id, None).await.unwrap();
707
708        // Add 10 events
709        for i in 0..10 {
710            event_mgr
711                .add_event(task.id, "note", &format!("Event {}", i))
712                .await
713                .unwrap();
714        }
715
716        // Restore with custom limit (5)
717        let restore_mgr = SessionRestoreManager::new(pool);
718        let result = restore_mgr.restore(5).await.unwrap();
719
720        // Should return 5 events
721        let events = result.recent_events.unwrap();
722        assert_eq!(events.len(), 5);
723    }
724
725    #[test]
726    fn test_suggest_commands_with_children() {
727        let current_task = CurrentTaskInfo {
728            id: 1,
729            name: "Test".to_string(),
730            status: "doing".to_string(),
731            spec: None,
732            spec_preview: None,
733            created_at: None,
734            first_doing_at: None,
735        };
736
737        let children = Some(ChildrenInfo {
738            total: 2,
739            todo: 1,
740            list: vec![],
741        });
742
743        let commands = SessionRestoreManager::suggest_commands(&current_task, children.as_ref());
744
745        assert!(!commands.is_empty());
746        assert!(commands.iter().any(|c| c.contains("blocker")));
747    }
748
749    #[test]
750    fn test_error_result_workspace_not_found() {
751        let result = SessionRestoreManager::error_result(
752            Some("/test/path".to_string()),
753            ErrorType::WorkspaceNotFound,
754            "Test message",
755            "Test recovery",
756        );
757
758        assert_eq!(result.status, SessionStatus::Error);
759        assert_eq!(result.error_type, Some(ErrorType::WorkspaceNotFound));
760        assert_eq!(result.message, Some("Test message".to_string()));
761        assert_eq!(
762            result.recovery_suggestion,
763            Some("Test recovery".to_string())
764        );
765        assert!(result.suggested_commands.is_some());
766
767        let commands = result.suggested_commands.unwrap();
768        assert!(commands.iter().any(|c| c.contains("init")));
769    }
770
771    #[test]
772    fn test_build_siblings_info_empty() {
773        let siblings: Vec<crate::db::models::Task> = vec![];
774        let result = SessionRestoreManager::build_siblings_info(&siblings);
775        assert!(result.is_none());
776    }
777
778    #[test]
779    fn test_build_children_info_empty() {
780        let children: Vec<crate::db::models::Task> = vec![];
781        let result = SessionRestoreManager::build_children_info(&children);
782        assert!(result.is_none());
783    }
784}