()
| 857 | |
| 858 | #[tokio::test] |
| 859 | async fn test_migration_from_json() { |
| 860 | let ctx = AppContext::builder().build(); |
| 861 | let tsk_env = ctx.tsk_env(); |
| 862 | tsk_env.ensure_directories().unwrap(); |
| 863 | |
| 864 | let data_dir = tsk_env.data_dir(); |
| 865 | let json_path = data_dir.join("tasks.json"); |
| 866 | let bak_path = data_dir.join("tasks.json.bak"); |
| 867 | let db_path = data_dir.join("migration_test.db"); |
| 868 | |
| 869 | // Create a tasks.json with known tasks |
| 870 | let task = Task { |
| 871 | id: "migrate1234".to_string(), |
| 872 | repo_root: data_dir.to_path_buf(), |
| 873 | name: "migrate-task".to_string(), |
| 874 | branch_name: "tsk/feat/migrate-task/migrate1234".to_string(), |
| 875 | copied_repo_path: Some(data_dir.to_path_buf()), |
| 876 | ..Task::test_default() |
| 877 | }; |
| 878 | let tasks = vec![task]; |
| 879 | let json = serde_json::to_string_pretty(&tasks).unwrap(); |
| 880 | fs::write(&json_path, &json).unwrap(); |
| 881 | |
| 882 | // Construct TaskStorage -- migration should run automatically |
| 883 | let storage = TaskStorage::new(db_path).unwrap(); |
| 884 | |
| 885 | // Verify tasks are in SQLite |
| 886 | let stored_tasks = storage.list_tasks().await.unwrap(); |
| 887 | assert_eq!(stored_tasks.len(), 1); |
| 888 | assert_eq!(stored_tasks[0].id, "migrate1234"); |
| 889 | assert_eq!(stored_tasks[0].name, "migrate-task"); |
| 890 | |
| 891 | // Verify tasks.json was renamed |
| 892 | assert!(!json_path.exists()); |
| 893 | assert!(bak_path.exists()); |
| 894 | |
| 895 | // Clean up |
| 896 | let _ = fs::remove_file(&bak_path); |
| 897 | } |
| 898 | |
| 899 | #[tokio::test] |
| 900 | async fn test_migration_skipped_when_bak_exists() { |
nothing calls this directly
no test coverage detected