@@ -3,7 +3,8 @@ import * as fs from "node:fs";
33import * as path from "node:path" ;
44import * as os from "node:os" ;
55import { TaskService } from "./task-service.js" ;
6- import { GitHubSyncService } from "./github/index.js" ;
6+ import { SyncRegistry } from "./sync/index.js" ;
7+ import type { RegisterableSyncService } from "./sync/index.js" ;
78import { ValidationError } from "../errors.js" ;
89
910describe ( "TaskService" , ( ) => {
@@ -886,21 +887,24 @@ describe("TaskService", () => {
886887 } ) ;
887888
888889 describe ( "autosync" , ( ) => {
889- let mockSyncService : {
890- syncTask : ReturnType < typeof vi . fn > ;
891- getRepo : ReturnType < typeof vi . fn > ;
892- } ;
890+ let mockSyncTask : ReturnType < typeof vi . fn > ;
891+ let mockRegistry : SyncRegistry ;
893892
894893 beforeEach ( ( ) => {
895- mockSyncService = {
896- syncTask : vi . fn ( ) ,
897- getRepo : vi . fn ( ( ) => ( { owner : "test" , repo : "test" } ) ) ,
898- } ;
894+ mockSyncTask = vi . fn ( ) ;
895+ const mockSyncService = {
896+ id : "github" as const ,
897+ displayName : "GitHub" ,
898+ syncTask : mockSyncTask ,
899+ syncAll : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
900+ } as unknown as RegisterableSyncService ;
901+ mockRegistry = new SyncRegistry ( ) ;
902+ mockRegistry . register ( mockSyncService ) ;
899903 } ) ;
900904
901905 it ( "saves GitHub metadata when autosync creates an issue" , async ( ) => {
902906 // Mock syncTask to return the task ID it was called with
903- mockSyncService . syncTask . mockImplementation ( async ( task ) => ( {
907+ mockSyncTask . mockImplementation ( async ( task ) => ( {
904908 taskId : task . id ,
905909 github : {
906910 issueNumber : 42 ,
@@ -913,16 +917,16 @@ describe("TaskService", () => {
913917
914918 const syncService = new TaskService ( {
915919 storage : storagePath ,
916- syncService : mockSyncService as unknown as GitHubSyncService ,
917- syncConfig : { enabled : true , auto : { on_change : true } } ,
920+ syncRegistry : mockRegistry ,
921+ syncConfig : { github : { enabled : true , auto : { on_change : true } } } ,
918922 } ) ;
919923
920924 const task = await syncService . create ( {
921925 name : "Test task" ,
922926 description : "Test" ,
923927 } ) ;
924928
925- expect ( mockSyncService . syncTask ) . toHaveBeenCalled ( ) ;
929+ expect ( mockSyncTask ) . toHaveBeenCalled ( ) ;
926930
927931 // Fetch the task from storage to verify metadata was saved
928932 const savedTask = await syncService . get ( task . id ) ;
@@ -943,7 +947,7 @@ describe("TaskService", () => {
943947 } ) ;
944948
945949 // Now create a service with sync enabled
946- mockSyncService . syncTask . mockResolvedValue ( {
950+ mockSyncTask . mockResolvedValue ( {
947951 taskId : task . id ,
948952 github : {
949953 issueNumber : 99 ,
@@ -956,8 +960,8 @@ describe("TaskService", () => {
956960
957961 const syncService = new TaskService ( {
958962 storage : storagePath ,
959- syncService : mockSyncService as unknown as GitHubSyncService ,
960- syncConfig : { enabled : true , auto : { on_change : true } } ,
963+ syncRegistry : mockRegistry ,
964+ syncConfig : { github : { enabled : true , auto : { on_change : true } } } ,
961965 } ) ;
962966
963967 await syncService . update ( {
@@ -984,7 +988,7 @@ describe("TaskService", () => {
984988 } ) ;
985989
986990 // Now update with sync enabled
987- mockSyncService . syncTask . mockResolvedValue ( {
991+ mockSyncTask . mockResolvedValue ( {
988992 taskId : task . id ,
989993 github : {
990994 issueNumber : 55 ,
@@ -997,8 +1001,8 @@ describe("TaskService", () => {
9971001
9981002 const syncService = new TaskService ( {
9991003 storage : storagePath ,
1000- syncService : mockSyncService as unknown as GitHubSyncService ,
1001- syncConfig : { enabled : true , auto : { on_change : true } } ,
1004+ syncRegistry : mockRegistry ,
1005+ syncConfig : { github : { enabled : true , auto : { on_change : true } } } ,
10021006 } ) ;
10031007
10041008 await syncService . update ( {
@@ -1026,7 +1030,7 @@ describe("TaskService", () => {
10261030 await new Promise ( ( resolve ) => setTimeout ( resolve , 10 ) ) ;
10271031
10281032 // Sync returns skipped: true
1029- mockSyncService . syncTask . mockResolvedValue ( {
1033+ mockSyncTask . mockResolvedValue ( {
10301034 taskId : task . id ,
10311035 github : {
10321036 issueNumber : 77 ,
@@ -1040,8 +1044,8 @@ describe("TaskService", () => {
10401044
10411045 const syncService = new TaskService ( {
10421046 storage : storagePath ,
1043- syncService : mockSyncService as unknown as GitHubSyncService ,
1044- syncConfig : { enabled : true , auto : { on_change : true } } ,
1047+ syncRegistry : mockRegistry ,
1048+ syncConfig : { github : { enabled : true , auto : { on_change : true } } } ,
10451049 } ) ;
10461050
10471051 await syncService . update ( {
@@ -1068,7 +1072,7 @@ describe("TaskService", () => {
10681072 } ) ;
10691073
10701074 // Sync service returns parent's ID (subtasks sync their parent)
1071- mockSyncService . syncTask . mockResolvedValue ( {
1075+ mockSyncTask . mockResolvedValue ( {
10721076 taskId : parent . id , // Parent gets the GitHub issue, not subtask
10731077 github : {
10741078 issueNumber : 88 ,
@@ -1081,8 +1085,8 @@ describe("TaskService", () => {
10811085
10821086 const syncService = new TaskService ( {
10831087 storage : storagePath ,
1084- syncService : mockSyncService as unknown as GitHubSyncService ,
1085- syncConfig : { enabled : true , auto : { on_change : true } } ,
1088+ syncRegistry : mockRegistry ,
1089+ syncConfig : { github : { enabled : true , auto : { on_change : true } } } ,
10861090 } ) ;
10871091
10881092 // Update subtask triggers sync
0 commit comments