@taskforcehq/taskforce 0.3.303 → 0.3.305
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -247
- package/dist/Taskforce.module.css +102 -5
- package/dist/TaskforceCore.js +635 -238
- package/dist/TaskforceCore.test.js +2243 -495
- package/dist/annotatedAttachments/service.d.ts +1 -1
- package/dist/annotatedAttachments/types.d.ts +1 -1
- package/dist/compat/workspaceSyncCompat.js +6 -0
- package/dist/components/features/AgentsModule.js +1 -1
- package/dist/components/features/AgentsModule.test.js +1 -1
- package/dist/components/features/DocumentIndex.d.ts +1 -1
- package/dist/components/features/DocumentIndex.js +1 -1
- package/dist/components/features/DocumentViewer.d.ts +1 -1
- package/dist/components/features/DocumentViewer.js +32 -9
- package/dist/components/features/DocumentWorkspace.d.ts +5 -22
- package/dist/components/features/DocumentWorkspace.js +12 -155
- package/dist/components/features/DocumentWorkspace.test.js +193 -6
- package/dist/components/features/TaskSettings.js +87 -41
- package/dist/components/features/TaskSettings.test.js +180 -40
- package/dist/components/features/documentWorkspaceModel.d.ts +24 -0
- package/dist/components/features/documentWorkspaceModel.js +57 -0
- package/dist/components/features/useDocumentWorkspaceController.d.ts +34 -0
- package/dist/components/features/useDocumentWorkspaceController.js +113 -0
- package/dist/components/task/TaskActionHeader.d.ts +2 -1
- package/dist/components/task/TaskActionHeader.js +3 -3
- package/dist/components/task/TaskActionHeader.test.js +8 -0
- package/dist/components/task/TaskCard.js +16 -1
- package/dist/components/task/TaskCard.test.js +31 -0
- package/dist/components/task/TaskForm.d.ts +9 -8
- package/dist/components/task/TaskForm.js +374 -219
- package/dist/components/task/TaskForm.test.js +482 -361
- package/dist/components/task/TaskKanban.d.ts +1 -1
- package/dist/components/task/TaskKanban.js +33 -161
- package/dist/components/task/TaskStatusActions.d.ts +6 -1
- package/dist/components/task/TaskStatusActions.js +8 -3
- package/dist/components/task/TaskStatusActions.test.js +9 -0
- package/dist/components/task/taskKanbanDropRules.d.ts +58 -0
- package/dist/components/task/taskKanbanDropRules.js +187 -0
- package/dist/components/task/taskKanbanDropRules.test.d.ts +1 -0
- package/dist/components/task/taskKanbanDropRules.test.js +114 -0
- package/dist/components/ui/Modal.d.ts +1 -1
- package/dist/components/ui/Modal.js +1 -0
- package/dist/components/views/AppShellHeader.js +5 -1
- package/dist/components/views/AppShellHeader.test.js +4 -0
- package/dist/components/views/PlanComparisonPage.d.ts +3 -2
- package/dist/components/views/PlanComparisonPage.js +9 -10
- package/dist/components/views/PlanComparisonPage.test.js +55 -41
- package/dist/components/views/PlansPage.d.ts +5 -1
- package/dist/components/views/PlansPage.js +150 -81
- package/dist/components/views/PlansPage.test.js +367 -41
- package/dist/components/views/StandaloneLayout.js +135 -54
- package/dist/components/views/WidgetView.js +11 -2
- package/dist/components/views/panels/FilterToolbar.test.js +6 -4
- package/dist/components/views/standalone/modals/AccountHubModal.d.ts +2 -14
- package/dist/components/views/standalone/modals/AccountHubModal.js +12 -14
- package/dist/components/views/standalone/modals/AccountHubModal.test.js +24 -1
- package/dist/components/views/standalone/modals/SyncStatusModal.js +1 -1
- package/dist/config/envSchema.js +1 -1
- package/dist/core/AiProfileService.d.ts +6 -1
- package/dist/core/AiProfileService.js +161 -16
- package/dist/core/AiProfileService.test.js +3 -1
- package/dist/core/AiProfiles.test.js +200 -0
- package/dist/core/AuthTokenService.test.d.ts +1 -0
- package/dist/core/AuthTokenService.test.js +78 -0
- package/dist/core/DeletedTaskLifecycleService.d.ts +2 -1
- package/dist/core/EntitlementsPolicy.test.js +75 -13
- package/dist/core/PlanEntitlementService.d.ts +9 -1
- package/dist/core/PlanEntitlementService.js +144 -19
- package/dist/core/PlanVersionPolicy.test.js +19 -26
- package/dist/core/SignupMonetizationSettings.test.js +75 -15
- package/dist/core/SystemAdmin.test.js +212 -56
- package/dist/core/TaskActivityService.d.ts +4 -1
- package/dist/core/TaskActivityService.js +45 -0
- package/dist/core/TaskAuditTimeline.test.js +52 -1
- package/dist/core/TaskTaxonomyValidation.test.js +53 -0
- package/dist/core/Taskforce.d.ts +18 -11
- package/dist/core/Taskforce.js +93 -12
- package/dist/core/WorkspacePlanMode.test.js +73 -8
- package/dist/core/shared.d.ts +2 -0
- package/dist/core/shared.js +11 -0
- package/dist/documentReviews/service.d.ts +1 -1
- package/dist/documentReviews/types.d.ts +1 -1
- package/dist/hooks/auth/useTaskforceAuthBootstrap.d.ts +48 -0
- package/dist/hooks/auth/useTaskforceAuthBootstrap.js +219 -0
- package/dist/hooks/sync/auth.d.ts +37 -0
- package/dist/hooks/sync/auth.js +63 -0
- package/dist/hooks/sync/bootstrap.d.ts +34 -0
- package/dist/hooks/sync/bootstrap.js +52 -0
- package/dist/hooks/sync/orchestratorShared.d.ts +36 -0
- package/dist/hooks/sync/orchestratorShared.js +209 -0
- package/dist/hooks/sync/orchestratorShared.test.d.ts +1 -0
- package/dist/hooks/sync/orchestratorShared.test.js +49 -0
- package/dist/hooks/sync/realtime.d.ts +25 -0
- package/dist/hooks/sync/realtime.js +60 -0
- package/dist/hooks/sync/recovery.d.ts +69 -0
- package/dist/hooks/sync/recovery.js +118 -0
- package/dist/hooks/sync/transfers.d.ts +123 -0
- package/dist/hooks/sync/transfers.js +435 -0
- package/dist/hooks/sync/useDataVersionRefresh.d.ts +16 -0
- package/dist/hooks/sync/useDataVersionRefresh.js +73 -0
- package/dist/hooks/ui/useResourceExport.d.ts +3 -1
- package/dist/hooks/ui/useResourceExport.js +5 -2
- package/dist/hooks/ui/useWorkflowTemplates.js +11 -6
- package/dist/hooks/useRealtimeSync.js +2 -1
- package/dist/hooks/useSyncOrchestrator.aiProfiles.test.js +8 -0
- package/dist/hooks/useSyncOrchestrator.context-assets.test.d.ts +1 -0
- package/dist/hooks/useSyncOrchestrator.context-assets.test.js +228 -0
- package/dist/hooks/useSyncOrchestrator.d.ts +12 -8
- package/dist/hooks/useSyncOrchestrator.js +388 -879
- package/dist/hooks/useSyncOrchestrator.retry-closure.test.js +641 -6
- package/dist/hooks/useTaskMutations.d.ts +2 -1
- package/dist/hooks/useTaskMutations.js +57 -7
- package/dist/hooks/useTaskMutations.test.js +176 -0
- package/dist/hooks/useTaskforce.d.ts +13 -4
- package/dist/hooks/useTaskforce.js +302 -817
- package/dist/hooks/useTaskforce.sync-behavior.test.js +78 -0
- package/dist/hooks/useWorkspaceSyncController.d.ts +4 -1
- package/dist/hooks/useWorkspaceSyncController.js +33 -11
- package/dist/hooks/useWorkspaceSyncController.test.js +1 -0
- package/dist/hooks/workspace/useTaskforceApiRouting.test.js +17 -0
- package/dist/hooks/workspace/useTaskforceWorkspaceBootstrap.d.ts +166 -0
- package/dist/hooks/workspace/useTaskforceWorkspaceBootstrap.js +434 -0
- package/dist/hooks/workspace/workspaceLocalState.d.ts +19 -0
- package/dist/hooks/workspace/workspaceLocalState.js +100 -0
- package/dist/hooks/workspace/workspaceLocalState.test.d.ts +1 -0
- package/dist/hooks/workspace/workspaceLocalState.test.js +59 -0
- package/dist/localization/locales/en-US.js +2 -2
- package/dist/mcp/adminWorkspaceRegistrar.d.ts +2 -0
- package/dist/mcp/adminWorkspaceRegistrar.js +154 -0
- package/dist/mcp/canonicalAssetHelpers.d.ts +70 -0
- package/dist/mcp/canonicalAssetHelpers.js +259 -0
- package/dist/mcp/clientIntegrations.d.ts +12 -1
- package/dist/mcp/clientIntegrations.js +161 -6
- package/dist/mcp/clientIntegrations.test.js +76 -4
- package/dist/mcp/collaborationRegistrar.d.ts +2 -0
- package/dist/mcp/collaborationRegistrar.js +71 -0
- package/dist/mcp/documentAssetRegistrar.d.ts +2 -0
- package/dist/mcp/documentAssetRegistrar.js +346 -0
- package/dist/mcp/documentHelpers.d.ts +100 -0
- package/dist/mcp/documentHelpers.js +161 -0
- package/dist/mcp/runtime.js +2455 -3925
- package/dist/mcp/runtime.test.js +240 -8
- package/dist/mcp/taskAttachmentHelpers.d.ts +41 -0
- package/dist/mcp/taskAttachmentHelpers.js +60 -0
- package/dist/mcp/taskAttachmentTypes.d.ts +37 -0
- package/dist/mcp/taskAttachmentTypes.js +1 -0
- package/dist/mcp/taskPlanningRegistrar.d.ts +2 -0
- package/dist/mcp/taskPlanningRegistrar.js +418 -0
- package/dist/mcp/toolCatalog.d.ts +35 -0
- package/dist/mcp/toolCatalog.js +3 -0
- package/dist/plugins/vite.js +1 -1
- package/dist/runtime/appGateDefinitions.d.ts +1 -1
- package/dist/runtime/appGateDefinitions.js +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +46 -3
- package/dist/server/index.test.js +12 -1
- package/dist/server/routes/admin.d.ts +1 -5
- package/dist/server/routes/admin.js +151 -80
- package/dist/server/routes/annotatedAttachments.d.ts +1 -1
- package/dist/server/routes/annotatedAttachments.js +1 -1
- package/dist/server/routes/auth.d.ts +1 -4
- package/dist/server/routes/auth.js +59 -64
- package/dist/server/routes/authSupport.d.ts +30 -0
- package/dist/server/routes/authSupport.js +81 -0
- package/dist/server/routes/billing.d.ts +1 -1
- package/dist/server/routes/billing.js +122 -255
- package/dist/server/routes/billing.test.js +257 -86
- package/dist/server/routes/documentReviews.d.ts +1 -1
- package/dist/server/routes/documentReviews.js +1 -1
- package/dist/server/routes/documents.d.ts +4 -2
- package/dist/server/routes/documents.js +73 -7
- package/dist/server/routes/primitives.d.ts +11 -0
- package/dist/server/routes/primitives.js +73 -0
- package/dist/server/routes/resources.d.ts +1 -1
- package/dist/server/routes/resources.js +1 -1
- package/dist/server/routes/shared.d.ts +31 -1
- package/dist/server/routes/shared.js +26 -0
- package/dist/server/routes/sync.d.ts +1 -1
- package/dist/server/routes/sync.integration.test.js +20 -0
- package/dist/server/routes/sync.js +111 -238
- package/dist/server/routes/tasks.d.ts +1 -1
- package/dist/server/routes/tasks.js +50 -8
- package/dist/server/routes/workspaces.d.ts +1 -1
- package/dist/server/routes/workspaces.js +1 -1
- package/dist/server/routes.d.ts +2 -9
- package/dist/server/routes.js +84 -181
- package/dist/server/routes.test.js +912 -32
- package/dist/shared/taskActor.d.ts +10 -0
- package/dist/shared/taskActor.js +1 -0
- package/dist/sync/collaborationSyncPayload.js +4 -0
- package/dist/sync/collaborationSyncPayload.test.js +8 -0
- package/dist/sync/collaborationSyncState.d.ts +3 -1
- package/dist/sync/collaborationSyncState.js +19 -0
- package/dist/sync/contentSyncState.js +28 -17
- package/dist/sync/syncApplyHandlers.d.ts +87 -1
- package/dist/sync/syncApplyHandlers.js +370 -8
- package/dist/sync/syncApplyHandlers.test.d.ts +1 -0
- package/dist/sync/syncApplyHandlers.test.js +379 -0
- package/dist/sync/syncService.d.ts +9 -1
- package/dist/sync/syncService.js +44 -2
- package/dist/sync/syncService.test.js +62 -0
- package/dist/sync/workspacePullFeed.d.ts +1 -0
- package/dist/sync/workspacePullFeed.js +66 -59
- package/dist/sync/workspacePullFeed.test.js +72 -4
- package/dist/sync/workspaceSyncModel.d.ts +25 -1
- package/dist/sync/workspaceSyncModel.js +77 -3
- package/dist/sync/workspaceSyncModel.test.js +153 -0
- package/dist/sync/workspaceSyncState.d.ts +2 -0
- package/dist/sync/workspaceSyncState.js +1 -0
- package/dist/types.d.ts +2 -10
- package/dist/ui/assets/AgentsModule-N2MnQBZk.js +1 -0
- package/dist/ui/assets/{AnnotatedAttachmentWorkspace-C_TmXZwA.js → AnnotatedAttachmentWorkspace-BG6P_GVW.js} +1 -1
- package/dist/ui/assets/DocumentWorkspace-B3nV_Gc5.css +1 -0
- package/dist/ui/assets/DocumentWorkspace-DRbDMwh8.js +252 -0
- package/dist/ui/assets/{InitiativesModule-4-Rh2K2n.js → InitiativesModule-Dhm7M8e7.js} +1 -1
- package/dist/ui/assets/{PlansPage-BlVC_lRq.css → PlansPage-C2dd2n1X.css} +1 -1
- package/dist/ui/assets/PlansPage-Cq0zXj3I.js +1 -0
- package/dist/ui/assets/TaskSettings-ln0aF7xc.js +9 -0
- package/dist/ui/assets/{WorkflowsModule-CGk9s3NJ.js → WorkflowsModule-BcS4afRn.js} +1 -1
- package/dist/ui/assets/index-C2-OXZV7.css +1 -0
- package/dist/ui/assets/index-DcSI5F86.js +6 -0
- package/dist/ui/assets/{vendor-icons-pWocEipT.js → vendor-icons-BSUaRwF8.js} +1 -1
- package/dist/ui/index.html +4 -4
- package/dist/utils/commercialLifecyclePresentation.d.ts +19 -0
- package/dist/utils/commercialLifecyclePresentation.js +196 -0
- package/dist/utils/taskActivity.js +4 -0
- package/dist/utils/taskActivity.test.js +25 -1
- package/package.json +10 -1
- package/scripts/check-cloud-mcp.mjs +83 -0
- package/scripts/playwright-auth.sh +9 -1
- package/scripts/run-billing-performance-smoke.sh +24 -0
- package/dist/ui/assets/AgentsModule-CpsTmrIW.js +0 -1
- package/dist/ui/assets/DocumentWorkspace-C3GyzrWm.js +0 -250
- package/dist/ui/assets/DocumentWorkspace-C_8T8oz-.css +0 -1
- package/dist/ui/assets/PlansPage-BP7AYOqr.js +0 -1
- package/dist/ui/assets/TaskSettings-BOC5F6Ag.js +0 -8
- package/dist/ui/assets/index-CLIMgR6g.js +0 -6
- package/dist/ui/assets/index-DneETxcu.css +0 -1
|
@@ -99,7 +99,52 @@ function buildInput(overrides) {
|
|
|
99
99
|
describe('useSyncOrchestrator', () => {
|
|
100
100
|
beforeEach(() => {
|
|
101
101
|
localStorage.clear();
|
|
102
|
+
ensureCloudWorkspaceReadyForSyncServiceMock.mockReset();
|
|
103
|
+
runWorkspacePullSyncServiceMock.mockReset();
|
|
104
|
+
runWorkspacePushSyncServiceMock.mockReset();
|
|
105
|
+
syncUserGlobalSettingsServiceMock.mockReset();
|
|
102
106
|
ensureCloudWorkspaceReadyForSyncServiceMock.mockResolvedValue({ success: true });
|
|
107
|
+
runWorkspacePullSyncServiceMock.mockResolvedValue({
|
|
108
|
+
success: true,
|
|
109
|
+
syncedAt: '2026-03-15T18:00:00.000Z',
|
|
110
|
+
cursor: null,
|
|
111
|
+
pages: 0,
|
|
112
|
+
appliedChanges: 0,
|
|
113
|
+
pullRequestMs: 1,
|
|
114
|
+
applyMs: 0,
|
|
115
|
+
pulledDeleteTaskIds: new Set(),
|
|
116
|
+
pulledActiveUpserts: false,
|
|
117
|
+
pulledArchivedUpserts: false,
|
|
118
|
+
documentDecryptFailures: []
|
|
119
|
+
});
|
|
120
|
+
runWorkspacePushSyncServiceMock.mockResolvedValue({
|
|
121
|
+
success: true,
|
|
122
|
+
syncedAt: '2026-03-15T18:00:00.000Z',
|
|
123
|
+
requestMs: 1,
|
|
124
|
+
changeCount: 0,
|
|
125
|
+
deleteCount: 0,
|
|
126
|
+
currentTaskIds: new Set(),
|
|
127
|
+
currentInitiativeIds: new Set(),
|
|
128
|
+
currentInitiativeWatermarks: new Map(),
|
|
129
|
+
currentWorkstreamIds: new Set(),
|
|
130
|
+
currentWorkstreamWatermarks: new Map(),
|
|
131
|
+
currentAiProfileIds: new Set(),
|
|
132
|
+
currentAiProfileWatermarks: new Map(),
|
|
133
|
+
currentDocumentPaths: new Set(),
|
|
134
|
+
currentDocumentWatermarks: new Map(),
|
|
135
|
+
currentAssetPaths: new Set(),
|
|
136
|
+
currentAssetWatermarks: new Map(),
|
|
137
|
+
currentDocumentReviewSessionIds: new Set(),
|
|
138
|
+
currentDocumentReviewSessionWatermarks: new Map(),
|
|
139
|
+
currentDocumentReviewCommentIds: new Set(),
|
|
140
|
+
currentDocumentReviewCommentWatermarks: new Map(),
|
|
141
|
+
currentAnnotatedAttachmentSessionIds: new Set(),
|
|
142
|
+
currentAnnotatedAttachmentSessionWatermarks: new Map(),
|
|
143
|
+
currentTaskEventWatermarks: new Map(),
|
|
144
|
+
deleteTaskIds: new Set(),
|
|
145
|
+
pushedWatermarks: new Map(),
|
|
146
|
+
emittedEventIds: []
|
|
147
|
+
});
|
|
103
148
|
syncUserGlobalSettingsServiceMock.mockResolvedValue({
|
|
104
149
|
success: true,
|
|
105
150
|
mode: 'pulled',
|
|
@@ -298,6 +343,226 @@ describe('useSyncOrchestrator', () => {
|
|
|
298
343
|
expect(result.current.workspaceLastPullAt).toBe('2026-03-15T18:05:00.000Z');
|
|
299
344
|
unmount();
|
|
300
345
|
});
|
|
346
|
+
it('refreshes local task collections after event-only task activity pulls', async () => {
|
|
347
|
+
const fetchSpy = vi.fn((url, init) => {
|
|
348
|
+
if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
|
|
349
|
+
return Promise.resolve({
|
|
350
|
+
ok: true,
|
|
351
|
+
json: () => Promise.resolve({
|
|
352
|
+
success: true,
|
|
353
|
+
state: {
|
|
354
|
+
version: 2,
|
|
355
|
+
enabled: true,
|
|
356
|
+
phase: 'active',
|
|
357
|
+
pullCursor: null,
|
|
358
|
+
lastPullAt: null,
|
|
359
|
+
lastPushAt: null,
|
|
360
|
+
lastSyncedAt: null
|
|
361
|
+
}
|
|
362
|
+
})
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
if (url.includes('/api/taskforce/ui-state') && String(init?.method || '').toUpperCase() === 'POST') {
|
|
366
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ success: true }) });
|
|
367
|
+
}
|
|
368
|
+
if (url.includes('/api/taskforce/sync/workspace/documents')) {
|
|
369
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ documents: [] }) });
|
|
370
|
+
}
|
|
371
|
+
if (url.includes('/api/taskforce/sync/workspace/annotated-attachments')) {
|
|
372
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ sessions: [] }) });
|
|
373
|
+
}
|
|
374
|
+
if (url.includes('/api/taskforce/sync/events')) {
|
|
375
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ success: true }) });
|
|
376
|
+
}
|
|
377
|
+
if (url.includes('/api/taskforce/tasks')) {
|
|
378
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ tasks: [] }) });
|
|
379
|
+
}
|
|
380
|
+
if (url.includes('/api/taskforce/archive')) {
|
|
381
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ archived: [] }) });
|
|
382
|
+
}
|
|
383
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ success: true }) });
|
|
384
|
+
});
|
|
385
|
+
vi.stubGlobal('fetch', fetchSpy);
|
|
386
|
+
runWorkspacePullSyncServiceMock.mockResolvedValueOnce({
|
|
387
|
+
success: true,
|
|
388
|
+
syncedAt: '2026-03-15T18:06:00.000Z',
|
|
389
|
+
cursor: null,
|
|
390
|
+
pages: 1,
|
|
391
|
+
appliedChanges: 1,
|
|
392
|
+
pullRequestMs: 1,
|
|
393
|
+
applyMs: 0,
|
|
394
|
+
pulledDeleteTaskIds: new Set(),
|
|
395
|
+
pulledActiveUpserts: false,
|
|
396
|
+
pulledArchivedUpserts: false,
|
|
397
|
+
pulledTaskEventUpserts: true,
|
|
398
|
+
documentDecryptFailures: []
|
|
399
|
+
});
|
|
400
|
+
const { result, unmount } = renderHook((props) => useSyncOrchestrator(props), {
|
|
401
|
+
initialProps: buildInput()
|
|
402
|
+
});
|
|
403
|
+
act(() => {
|
|
404
|
+
result.current.applyWorkspaceSyncStateSnapshot({
|
|
405
|
+
enabled: true,
|
|
406
|
+
phase: 'active',
|
|
407
|
+
pullCursor: null
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
await waitFor(() => {
|
|
411
|
+
expect(runWorkspacePullSyncServiceMock).toHaveBeenCalledTimes(1);
|
|
412
|
+
});
|
|
413
|
+
await waitFor(() => {
|
|
414
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).includes('/api/taskforce/tasks'))).toBe(true);
|
|
415
|
+
expect(fetchSpy.mock.calls.some(([url]) => String(url).includes('/api/taskforce/archive'))).toBe(true);
|
|
416
|
+
});
|
|
417
|
+
unmount();
|
|
418
|
+
});
|
|
419
|
+
it('marks sync auth as blocked on explicit 401 pull failures', async () => {
|
|
420
|
+
const setAuthBlocked = vi.fn();
|
|
421
|
+
const setIsAuthenticated = vi.fn();
|
|
422
|
+
const checkAuthSession = vi.fn(async () => false);
|
|
423
|
+
runWorkspacePullSyncServiceMock.mockResolvedValueOnce({
|
|
424
|
+
success: false,
|
|
425
|
+
kind: 'pull_http',
|
|
426
|
+
status: 401,
|
|
427
|
+
transient: false,
|
|
428
|
+
retryAfterMs: null,
|
|
429
|
+
cursor: null,
|
|
430
|
+
pages: 0,
|
|
431
|
+
appliedChanges: 0,
|
|
432
|
+
pullRequestMs: 1,
|
|
433
|
+
applyMs: 0,
|
|
434
|
+
pulledDeleteTaskIds: new Set(),
|
|
435
|
+
pulledActiveUpserts: false,
|
|
436
|
+
pulledArchivedUpserts: false,
|
|
437
|
+
documentDecryptFailures: []
|
|
438
|
+
});
|
|
439
|
+
const { result, unmount } = renderHook((props) => useSyncOrchestrator(props), {
|
|
440
|
+
initialProps: buildInput({
|
|
441
|
+
setAuthBlocked,
|
|
442
|
+
setIsAuthenticated,
|
|
443
|
+
checkAuthSession
|
|
444
|
+
})
|
|
445
|
+
});
|
|
446
|
+
act(() => {
|
|
447
|
+
result.current.applyWorkspaceSyncStateSnapshot({
|
|
448
|
+
enabled: true,
|
|
449
|
+
phase: 'active',
|
|
450
|
+
pullCursor: null
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
await waitFor(() => {
|
|
454
|
+
expect(setAuthBlocked).toHaveBeenCalledWith(true);
|
|
455
|
+
expect(setIsAuthenticated).toHaveBeenCalledWith(false);
|
|
456
|
+
expect(checkAuthSession).toHaveBeenCalled();
|
|
457
|
+
expect(result.current.workspaceLastErrorMessage).toBe('Session expired. Sign in again to resume cloud sync.');
|
|
458
|
+
});
|
|
459
|
+
unmount();
|
|
460
|
+
});
|
|
461
|
+
it('suppresses self-emitted realtime event ids but still pulls on later replay signals', async () => {
|
|
462
|
+
vi.useFakeTimers();
|
|
463
|
+
vi.stubGlobal('WebSocket', MockWebSocket);
|
|
464
|
+
runWorkspacePushSyncServiceMock.mockResolvedValue({
|
|
465
|
+
success: true,
|
|
466
|
+
syncedAt: '2026-03-15T15:00:00.000Z',
|
|
467
|
+
requestMs: 1,
|
|
468
|
+
changeCount: 1,
|
|
469
|
+
deleteCount: 0,
|
|
470
|
+
currentTaskIds: new Set(['task-1']),
|
|
471
|
+
currentInitiativeIds: new Set(),
|
|
472
|
+
currentInitiativeWatermarks: new Map(),
|
|
473
|
+
currentWorkstreamIds: new Set(),
|
|
474
|
+
currentWorkstreamWatermarks: new Map(),
|
|
475
|
+
currentAiProfileIds: new Set(),
|
|
476
|
+
currentAiProfileWatermarks: new Map(),
|
|
477
|
+
currentDocumentPaths: new Set(),
|
|
478
|
+
currentDocumentWatermarks: new Map(),
|
|
479
|
+
currentAssetPaths: new Set(),
|
|
480
|
+
currentAssetWatermarks: new Map(),
|
|
481
|
+
currentDocumentReviewSessionIds: new Set(),
|
|
482
|
+
currentDocumentReviewSessionWatermarks: new Map(),
|
|
483
|
+
currentDocumentReviewCommentIds: new Set(),
|
|
484
|
+
currentDocumentReviewCommentWatermarks: new Map(),
|
|
485
|
+
currentAnnotatedAttachmentSessionIds: new Set(),
|
|
486
|
+
currentAnnotatedAttachmentSessionWatermarks: new Map(),
|
|
487
|
+
currentTaskEventWatermarks: new Map(),
|
|
488
|
+
deleteTaskIds: new Set(),
|
|
489
|
+
pushedWatermarks: new Map([['task-1', '2026-03-14T12:00:00.000Z']]),
|
|
490
|
+
emittedEventIds: ['evt-self-1']
|
|
491
|
+
});
|
|
492
|
+
runWorkspacePullSyncServiceMock.mockResolvedValue({
|
|
493
|
+
success: true,
|
|
494
|
+
syncedAt: '2026-03-15T18:05:00.000Z',
|
|
495
|
+
cursor: null,
|
|
496
|
+
pages: 1,
|
|
497
|
+
appliedChanges: 0,
|
|
498
|
+
pullRequestMs: 1,
|
|
499
|
+
applyMs: 0,
|
|
500
|
+
pulledDeleteTaskIds: new Set(),
|
|
501
|
+
pulledActiveUpserts: false,
|
|
502
|
+
pulledArchivedUpserts: false,
|
|
503
|
+
documentDecryptFailures: []
|
|
504
|
+
});
|
|
505
|
+
const task = {
|
|
506
|
+
id: 'task-1',
|
|
507
|
+
status: 'task',
|
|
508
|
+
title: 'Realtime suppression',
|
|
509
|
+
createdAt: '2026-03-14T12:00:00.000Z',
|
|
510
|
+
updatedAt: '2026-03-14T12:00:00.000Z'
|
|
511
|
+
};
|
|
512
|
+
const { result, unmount } = renderHook((props) => useSyncOrchestrator(props), {
|
|
513
|
+
initialProps: buildInput({
|
|
514
|
+
realtimeSyncEnabled: true,
|
|
515
|
+
tasks: [task]
|
|
516
|
+
})
|
|
517
|
+
});
|
|
518
|
+
act(() => {
|
|
519
|
+
result.current.applyWorkspaceSyncStateSnapshot({
|
|
520
|
+
enabled: true,
|
|
521
|
+
phase: 'active',
|
|
522
|
+
pullCursor: null
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
await act(async () => {
|
|
526
|
+
await Promise.resolve();
|
|
527
|
+
await Promise.resolve();
|
|
528
|
+
await vi.advanceTimersByTimeAsync(400);
|
|
529
|
+
});
|
|
530
|
+
expect(MockWebSocket.instances).toHaveLength(1);
|
|
531
|
+
const stabilizedPullCalls = runWorkspacePullSyncServiceMock.mock.calls.length;
|
|
532
|
+
await act(async () => {
|
|
533
|
+
await result.current.pushWorkspaceChangesToCloud('sig-self-event');
|
|
534
|
+
await vi.advanceTimersByTimeAsync(200);
|
|
535
|
+
});
|
|
536
|
+
const pullCallsAfterPush = runWorkspacePullSyncServiceMock.mock.calls.length;
|
|
537
|
+
expect(pullCallsAfterPush).toBeGreaterThanOrEqual(stabilizedPullCalls);
|
|
538
|
+
act(() => {
|
|
539
|
+
MockWebSocket.instances[0]?.open();
|
|
540
|
+
MockWebSocket.instances[0]?.message({
|
|
541
|
+
type: 'taskforce:update',
|
|
542
|
+
workspaceId: 'workspace-local-active',
|
|
543
|
+
eventId: 'evt-self-1'
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
await act(async () => {
|
|
547
|
+
await vi.advanceTimersByTimeAsync(300);
|
|
548
|
+
});
|
|
549
|
+
expect(runWorkspacePullSyncServiceMock).toHaveBeenCalledTimes(pullCallsAfterPush);
|
|
550
|
+
act(() => {
|
|
551
|
+
MockWebSocket.instances[0]?.message({
|
|
552
|
+
type: 'taskforce:update',
|
|
553
|
+
workspaceId: 'workspace-local-active',
|
|
554
|
+
eventId: 'evt-replay-2'
|
|
555
|
+
});
|
|
556
|
+
});
|
|
557
|
+
await act(async () => {
|
|
558
|
+
await vi.advanceTimersByTimeAsync(300);
|
|
559
|
+
});
|
|
560
|
+
expect(runWorkspacePullSyncServiceMock).toHaveBeenCalledTimes(pullCallsAfterPush + 1);
|
|
561
|
+
await act(async () => {
|
|
562
|
+
unmount();
|
|
563
|
+
await vi.runOnlyPendingTimersAsync();
|
|
564
|
+
});
|
|
565
|
+
});
|
|
301
566
|
it('retries transient push failures automatically', async () => {
|
|
302
567
|
runWorkspacePushSyncServiceMock
|
|
303
568
|
.mockResolvedValueOnce({
|
|
@@ -349,19 +614,20 @@ describe('useSyncOrchestrator', () => {
|
|
|
349
614
|
});
|
|
350
615
|
expect(result.current.workspaceCloudSyncEnabled).toBe(true);
|
|
351
616
|
expect(result.current.workspaceSyncPhase).toBe('provision-local');
|
|
617
|
+
runWorkspacePushSyncServiceMock.mockClear();
|
|
352
618
|
await act(async () => {
|
|
353
619
|
await result.current.pushWorkspaceChangesToCloud('sig-push-retry');
|
|
354
620
|
});
|
|
355
|
-
expect(runWorkspacePushSyncServiceMock).
|
|
621
|
+
expect(runWorkspacePushSyncServiceMock.mock.calls.length).toBeGreaterThanOrEqual(1);
|
|
356
622
|
expect(result.current.isWorkspaceRetryPending()).toBe(true);
|
|
357
623
|
await act(async () => {
|
|
358
624
|
await result.current.pushWorkspaceChangesToCloud('sig-push-retry');
|
|
359
625
|
});
|
|
360
626
|
await waitFor(() => {
|
|
361
|
-
expect(runWorkspacePushSyncServiceMock).
|
|
627
|
+
expect(runWorkspacePushSyncServiceMock.mock.calls.length).toBeGreaterThanOrEqual(2);
|
|
362
628
|
});
|
|
363
629
|
expect(result.current.workspaceSyncPhase).toBe('active');
|
|
364
|
-
expect(result.current.workspaceLastPushAt).
|
|
630
|
+
expect(result.current.workspaceLastPushAt).toBeTruthy();
|
|
365
631
|
await act(async () => {
|
|
366
632
|
await Promise.resolve();
|
|
367
633
|
await Promise.resolve();
|
|
@@ -391,7 +657,20 @@ describe('useSyncOrchestrator', () => {
|
|
|
391
657
|
})
|
|
392
658
|
.mockImplementationOnce(() => new Promise((resolve) => {
|
|
393
659
|
resolveRetryPull = resolve;
|
|
394
|
-
}))
|
|
660
|
+
}))
|
|
661
|
+
.mockResolvedValue({
|
|
662
|
+
success: true,
|
|
663
|
+
syncedAt: '2026-03-15T19:30:00.000Z',
|
|
664
|
+
cursor: null,
|
|
665
|
+
pages: 1,
|
|
666
|
+
appliedChanges: 0,
|
|
667
|
+
pullRequestMs: 1,
|
|
668
|
+
applyMs: 0,
|
|
669
|
+
pulledDeleteTaskIds: new Set(),
|
|
670
|
+
pulledActiveUpserts: false,
|
|
671
|
+
pulledArchivedUpserts: false,
|
|
672
|
+
documentDecryptFailures: []
|
|
673
|
+
});
|
|
395
674
|
const { result, unmount } = renderHook((props) => useSyncOrchestrator(props), {
|
|
396
675
|
initialProps: buildInput()
|
|
397
676
|
});
|
|
@@ -435,6 +714,223 @@ describe('useSyncOrchestrator', () => {
|
|
|
435
714
|
});
|
|
436
715
|
unmount();
|
|
437
716
|
});
|
|
717
|
+
it('schedules a push when local task state changes without waiting for snapshot fingerprint changes', async () => {
|
|
718
|
+
vi.useFakeTimers();
|
|
719
|
+
runWorkspacePullSyncServiceMock.mockResolvedValue({
|
|
720
|
+
success: true,
|
|
721
|
+
syncedAt: '2026-03-15T19:30:00.000Z',
|
|
722
|
+
cursor: null,
|
|
723
|
+
pages: 1,
|
|
724
|
+
appliedChanges: 0,
|
|
725
|
+
pullRequestMs: 1,
|
|
726
|
+
applyMs: 0,
|
|
727
|
+
pulledDeleteTaskIds: new Set(),
|
|
728
|
+
pulledActiveUpserts: false,
|
|
729
|
+
pulledArchivedUpserts: false,
|
|
730
|
+
documentDecryptFailures: []
|
|
731
|
+
});
|
|
732
|
+
runWorkspacePushSyncServiceMock.mockResolvedValue({
|
|
733
|
+
success: true,
|
|
734
|
+
syncedAt: '2026-03-15T15:00:00.000Z',
|
|
735
|
+
requestMs: 1,
|
|
736
|
+
changeCount: 1,
|
|
737
|
+
deleteCount: 0,
|
|
738
|
+
currentTaskIds: new Set(['task-local-1']),
|
|
739
|
+
deleteTaskIds: new Set(),
|
|
740
|
+
currentDocumentPaths: new Set(),
|
|
741
|
+
deleteDocumentPaths: new Set(),
|
|
742
|
+
currentDocumentWatermarks: new Map(),
|
|
743
|
+
currentAssetPaths: new Set(),
|
|
744
|
+
deleteAssetPaths: new Set(),
|
|
745
|
+
currentAssetWatermarks: new Map(),
|
|
746
|
+
currentDocumentReviewSessionIds: new Set(),
|
|
747
|
+
deleteDocumentReviewSessionIds: new Set(),
|
|
748
|
+
currentDocumentReviewSessionWatermarks: new Map(),
|
|
749
|
+
currentAnnotatedAttachmentSessionIds: new Set(),
|
|
750
|
+
deleteAnnotatedAttachmentSessionIds: new Set(),
|
|
751
|
+
currentAnnotatedAttachmentSessionWatermarks: new Map(),
|
|
752
|
+
pushedWatermarks: new Map([['task-local-1', '2026-03-14T12:00:00.000Z']]),
|
|
753
|
+
emittedEventIds: []
|
|
754
|
+
});
|
|
755
|
+
let input = buildInput();
|
|
756
|
+
const { result, rerender, unmount } = renderHook((props) => useSyncOrchestrator(props), {
|
|
757
|
+
initialProps: input
|
|
758
|
+
});
|
|
759
|
+
act(() => {
|
|
760
|
+
result.current.applyWorkspaceSyncStateSnapshot({
|
|
761
|
+
enabled: true,
|
|
762
|
+
phase: 'provision-local',
|
|
763
|
+
pullCursor: null
|
|
764
|
+
});
|
|
765
|
+
});
|
|
766
|
+
await act(async () => {
|
|
767
|
+
await vi.runOnlyPendingTimersAsync();
|
|
768
|
+
await Promise.resolve();
|
|
769
|
+
await Promise.resolve();
|
|
770
|
+
});
|
|
771
|
+
runWorkspacePushSyncServiceMock.mockClear();
|
|
772
|
+
input = buildInput({
|
|
773
|
+
tasks: [{
|
|
774
|
+
id: 'task-local-1',
|
|
775
|
+
title: 'Local pending task',
|
|
776
|
+
status: 'task',
|
|
777
|
+
createdAt: '2026-03-14T12:00:00.000Z',
|
|
778
|
+
updatedAt: '2026-03-14T12:00:00.000Z',
|
|
779
|
+
localReferenceNumber: 7,
|
|
780
|
+
referenceNumber: null
|
|
781
|
+
}]
|
|
782
|
+
});
|
|
783
|
+
rerender(input);
|
|
784
|
+
await act(async () => {
|
|
785
|
+
await vi.advanceTimersByTimeAsync(1600);
|
|
786
|
+
await Promise.resolve();
|
|
787
|
+
await Promise.resolve();
|
|
788
|
+
});
|
|
789
|
+
expect(runWorkspacePushSyncServiceMock.mock.calls.length).toBeGreaterThanOrEqual(1);
|
|
790
|
+
const pushedChanges = runWorkspacePushSyncServiceMock.mock.calls
|
|
791
|
+
.map((call) => call?.[0]?.payload?.changes)
|
|
792
|
+
.filter(Array.isArray);
|
|
793
|
+
expect(pushedChanges).toEqual(expect.arrayContaining([
|
|
794
|
+
expect.arrayContaining([
|
|
795
|
+
expect.objectContaining({
|
|
796
|
+
op: 'upsert',
|
|
797
|
+
archived: false,
|
|
798
|
+
task: expect.objectContaining({
|
|
799
|
+
id: 'task-local-1'
|
|
800
|
+
})
|
|
801
|
+
})
|
|
802
|
+
])
|
|
803
|
+
]));
|
|
804
|
+
unmount();
|
|
805
|
+
});
|
|
806
|
+
it('schedules a push when only task activity events change', async () => {
|
|
807
|
+
vi.useFakeTimers();
|
|
808
|
+
const baseTask = {
|
|
809
|
+
id: 'task-local-activity-1',
|
|
810
|
+
title: 'Local task activity',
|
|
811
|
+
status: 'task',
|
|
812
|
+
createdAt: '2026-03-14T12:00:00.000Z',
|
|
813
|
+
updatedAt: '2026-03-14T12:00:00.000Z',
|
|
814
|
+
taskEvents: []
|
|
815
|
+
};
|
|
816
|
+
runWorkspacePushSyncServiceMock.mockResolvedValue({
|
|
817
|
+
success: true,
|
|
818
|
+
syncedAt: '2026-03-15T15:05:00.000Z',
|
|
819
|
+
requestMs: 1,
|
|
820
|
+
changeCount: 1,
|
|
821
|
+
deleteCount: 0,
|
|
822
|
+
currentTaskIds: new Set(['task-local-activity-1']),
|
|
823
|
+
deleteTaskIds: new Set(),
|
|
824
|
+
currentDocumentPaths: new Set(),
|
|
825
|
+
deleteDocumentPaths: new Set(),
|
|
826
|
+
currentDocumentWatermarks: new Map(),
|
|
827
|
+
currentAssetPaths: new Set(),
|
|
828
|
+
deleteAssetPaths: new Set(),
|
|
829
|
+
currentAssetWatermarks: new Map(),
|
|
830
|
+
currentDocumentReviewSessionIds: new Set(),
|
|
831
|
+
deleteDocumentReviewSessionIds: new Set(),
|
|
832
|
+
currentDocumentReviewSessionWatermarks: new Map(),
|
|
833
|
+
currentAnnotatedAttachmentSessionIds: new Set(),
|
|
834
|
+
deleteAnnotatedAttachmentSessionIds: new Set(),
|
|
835
|
+
currentAnnotatedAttachmentSessionWatermarks: new Map(),
|
|
836
|
+
currentTaskEventWatermarks: new Map(),
|
|
837
|
+
pushedWatermarks: new Map([['task-local-activity-1', '2026-03-14T12:00:00.000Z']]),
|
|
838
|
+
emittedEventIds: []
|
|
839
|
+
});
|
|
840
|
+
let input = buildInput({
|
|
841
|
+
tasks: [baseTask]
|
|
842
|
+
});
|
|
843
|
+
const { result, rerender, unmount } = renderHook((props) => useSyncOrchestrator(props), {
|
|
844
|
+
initialProps: input
|
|
845
|
+
});
|
|
846
|
+
act(() => {
|
|
847
|
+
result.current.applyWorkspaceSyncStateSnapshot({
|
|
848
|
+
enabled: true,
|
|
849
|
+
phase: 'provision-local',
|
|
850
|
+
pullCursor: null
|
|
851
|
+
});
|
|
852
|
+
});
|
|
853
|
+
await act(async () => {
|
|
854
|
+
await vi.runOnlyPendingTimersAsync();
|
|
855
|
+
await Promise.resolve();
|
|
856
|
+
await Promise.resolve();
|
|
857
|
+
});
|
|
858
|
+
runWorkspacePushSyncServiceMock.mockClear();
|
|
859
|
+
input = buildInput({
|
|
860
|
+
tasks: [{
|
|
861
|
+
...baseTask,
|
|
862
|
+
taskEvents: [{
|
|
863
|
+
id: 'event-1',
|
|
864
|
+
taskId: 'task-local-activity-1',
|
|
865
|
+
workspaceId: 'workspace-local-active',
|
|
866
|
+
action: 'updated',
|
|
867
|
+
actor: 'user-1',
|
|
868
|
+
actorType: 'human',
|
|
869
|
+
createdAt: '2026-03-15T15:06:00.000Z',
|
|
870
|
+
details: {
|
|
871
|
+
changes: {
|
|
872
|
+
status: {
|
|
873
|
+
from: 'task',
|
|
874
|
+
to: 'task'
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}]
|
|
879
|
+
}]
|
|
880
|
+
});
|
|
881
|
+
rerender(input);
|
|
882
|
+
await act(async () => {
|
|
883
|
+
await vi.advanceTimersByTimeAsync(1600);
|
|
884
|
+
await Promise.resolve();
|
|
885
|
+
await Promise.resolve();
|
|
886
|
+
});
|
|
887
|
+
expect(runWorkspacePushSyncServiceMock.mock.calls.length).toBeGreaterThanOrEqual(1);
|
|
888
|
+
expect(runWorkspacePushSyncServiceMock.mock.calls[0]?.[0]?.payload?.changes).toEqual(expect.arrayContaining([
|
|
889
|
+
expect.objectContaining({
|
|
890
|
+
op: 'task-event-upsert',
|
|
891
|
+
event: expect.objectContaining({
|
|
892
|
+
id: 'event-1',
|
|
893
|
+
taskId: 'task-local-activity-1'
|
|
894
|
+
})
|
|
895
|
+
})
|
|
896
|
+
]));
|
|
897
|
+
unmount();
|
|
898
|
+
});
|
|
899
|
+
it('runs a startup full reconcile after the first successful pull when a saved cursor exists', async () => {
|
|
900
|
+
vi.useFakeTimers();
|
|
901
|
+
runWorkspacePullSyncServiceMock.mockResolvedValue({
|
|
902
|
+
success: true,
|
|
903
|
+
syncedAt: '2026-03-15T19:30:00.000Z',
|
|
904
|
+
cursor: 'server-cursor-1',
|
|
905
|
+
pages: 1,
|
|
906
|
+
appliedChanges: 0,
|
|
907
|
+
pullRequestMs: 1,
|
|
908
|
+
applyMs: 0,
|
|
909
|
+
pulledDeleteTaskIds: new Set(),
|
|
910
|
+
pulledActiveUpserts: false,
|
|
911
|
+
pulledArchivedUpserts: false,
|
|
912
|
+
documentDecryptFailures: []
|
|
913
|
+
});
|
|
914
|
+
const { result, unmount } = renderHook((props) => useSyncOrchestrator(props), {
|
|
915
|
+
initialProps: buildInput()
|
|
916
|
+
});
|
|
917
|
+
act(() => {
|
|
918
|
+
result.current.applyWorkspaceSyncStateSnapshot({
|
|
919
|
+
enabled: true,
|
|
920
|
+
phase: 'active',
|
|
921
|
+
pullCursor: 'stale-cursor'
|
|
922
|
+
});
|
|
923
|
+
});
|
|
924
|
+
await act(async () => {
|
|
925
|
+
await vi.advanceTimersByTimeAsync(300);
|
|
926
|
+
await Promise.resolve();
|
|
927
|
+
await Promise.resolve();
|
|
928
|
+
});
|
|
929
|
+
expect(runWorkspacePullSyncServiceMock.mock.calls.length).toBeGreaterThanOrEqual(2);
|
|
930
|
+
expect(runWorkspacePullSyncServiceMock.mock.calls.some((call) => call?.[0]?.cursor === 'stale-cursor')).toBe(true);
|
|
931
|
+
expect(runWorkspacePullSyncServiceMock.mock.calls.some((call) => call?.[0]?.cursor === null)).toBe(true);
|
|
932
|
+
unmount();
|
|
933
|
+
});
|
|
438
934
|
it('finishes provision-local bootstrap by moving to active after the first push', async () => {
|
|
439
935
|
runWorkspacePushSyncServiceMock.mockResolvedValue({
|
|
440
936
|
success: true,
|
|
@@ -506,6 +1002,80 @@ describe('useSyncOrchestrator', () => {
|
|
|
506
1002
|
});
|
|
507
1003
|
unmount();
|
|
508
1004
|
});
|
|
1005
|
+
it('finishes attach-cloud bootstrap locally even if persisting the active phase fails', async () => {
|
|
1006
|
+
vi.stubGlobal('fetch', vi.fn((url, init) => {
|
|
1007
|
+
if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
|
|
1008
|
+
return Promise.resolve({
|
|
1009
|
+
ok: true,
|
|
1010
|
+
json: () => Promise.resolve({
|
|
1011
|
+
success: true,
|
|
1012
|
+
state: {
|
|
1013
|
+
version: 2,
|
|
1014
|
+
enabled: true,
|
|
1015
|
+
phase: 'attach-cloud',
|
|
1016
|
+
pullCursor: null,
|
|
1017
|
+
lastPullAt: null,
|
|
1018
|
+
lastPushAt: null,
|
|
1019
|
+
lastSyncedAt: null
|
|
1020
|
+
}
|
|
1021
|
+
})
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
if (url.includes('/api/taskforce/ui-state') && String(init?.method || '').toUpperCase() === 'POST') {
|
|
1025
|
+
return Promise.resolve({
|
|
1026
|
+
ok: false,
|
|
1027
|
+
status: 502,
|
|
1028
|
+
json: () => Promise.resolve({ success: false, error: 'Bad gateway' })
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
if (url.includes('/api/taskforce/sync/workspace/documents')) {
|
|
1032
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ documents: [] }) });
|
|
1033
|
+
}
|
|
1034
|
+
if (url.includes('/api/taskforce/sync/workspace/annotated-attachments')) {
|
|
1035
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ sessions: [] }) });
|
|
1036
|
+
}
|
|
1037
|
+
if (url.includes('/api/taskforce/sync/events')) {
|
|
1038
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ success: true }) });
|
|
1039
|
+
}
|
|
1040
|
+
if (url.includes('/api/taskforce/tasks')) {
|
|
1041
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ tasks: [] }) });
|
|
1042
|
+
}
|
|
1043
|
+
if (url.includes('/api/taskforce/archive')) {
|
|
1044
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ archived: [] }) });
|
|
1045
|
+
}
|
|
1046
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({ success: true }) });
|
|
1047
|
+
}));
|
|
1048
|
+
runWorkspacePullSyncServiceMock.mockResolvedValue({
|
|
1049
|
+
success: true,
|
|
1050
|
+
syncedAt: '2026-03-15T19:05:00.000Z',
|
|
1051
|
+
cursor: null,
|
|
1052
|
+
pages: 1,
|
|
1053
|
+
appliedChanges: 0,
|
|
1054
|
+
pullRequestMs: 1,
|
|
1055
|
+
applyMs: 0,
|
|
1056
|
+
pulledDeleteTaskIds: new Set(),
|
|
1057
|
+
pulledActiveUpserts: false,
|
|
1058
|
+
pulledArchivedUpserts: false,
|
|
1059
|
+
documentDecryptFailures: []
|
|
1060
|
+
});
|
|
1061
|
+
const { result, unmount } = renderHook((props) => useSyncOrchestrator(props), {
|
|
1062
|
+
initialProps: buildInput()
|
|
1063
|
+
});
|
|
1064
|
+
act(() => {
|
|
1065
|
+
result.current.applyWorkspaceSyncStateSnapshot({
|
|
1066
|
+
enabled: true,
|
|
1067
|
+
phase: 'attach-cloud',
|
|
1068
|
+
pullCursor: null
|
|
1069
|
+
});
|
|
1070
|
+
});
|
|
1071
|
+
await waitFor(() => {
|
|
1072
|
+
expect(result.current.workspaceSyncPhase).toBe('active');
|
|
1073
|
+
expect(result.current.workspaceLastPullAt).toBe('2026-03-15T19:05:00.000Z');
|
|
1074
|
+
});
|
|
1075
|
+
expect(result.current.workspaceLastErrorMessage).toBeNull();
|
|
1076
|
+
expect(result.current.workspaceSyncStatus).toBe('healthy');
|
|
1077
|
+
unmount();
|
|
1078
|
+
});
|
|
509
1079
|
it('does not auto-push local state immediately after attach-cloud bootstrap completes', async () => {
|
|
510
1080
|
vi.useFakeTimers();
|
|
511
1081
|
const task = {
|
|
@@ -822,7 +1392,8 @@ describe('useSyncOrchestrator', () => {
|
|
|
822
1392
|
await Promise.resolve();
|
|
823
1393
|
await Promise.resolve();
|
|
824
1394
|
});
|
|
825
|
-
|
|
1395
|
+
const pullCallsDuringRepair = runWorkspacePullSyncServiceMock.mock.calls.length;
|
|
1396
|
+
expect(pullCallsDuringRepair).toBeGreaterThanOrEqual(1);
|
|
826
1397
|
await act(async () => {
|
|
827
1398
|
const pushed = await result.current.pushWorkspaceChangesToCloud('sig-during-repair');
|
|
828
1399
|
const pulled = await result.current.pullWorkspaceChangesFromCloud();
|
|
@@ -830,7 +1401,7 @@ describe('useSyncOrchestrator', () => {
|
|
|
830
1401
|
expect(pulled).toBe(false);
|
|
831
1402
|
});
|
|
832
1403
|
expect(runWorkspacePushSyncServiceMock).not.toHaveBeenCalled();
|
|
833
|
-
expect(runWorkspacePullSyncServiceMock).toHaveBeenCalledTimes(
|
|
1404
|
+
expect(runWorkspacePullSyncServiceMock).toHaveBeenCalledTimes(pullCallsDuringRepair);
|
|
834
1405
|
await act(async () => {
|
|
835
1406
|
resolveRepairPull?.({
|
|
836
1407
|
success: true,
|
|
@@ -853,6 +1424,70 @@ describe('useSyncOrchestrator', () => {
|
|
|
853
1424
|
expect(result.current.workspaceLastPullAt).toBe('2026-03-15T21:05:00.000Z');
|
|
854
1425
|
unmount();
|
|
855
1426
|
});
|
|
1427
|
+
it('periodically retries a stale local push signature even without a new state change', async () => {
|
|
1428
|
+
vi.useFakeTimers();
|
|
1429
|
+
const localTask = {
|
|
1430
|
+
id: 'task-local-watchdog',
|
|
1431
|
+
title: 'Watchdog push recovery',
|
|
1432
|
+
status: 'task',
|
|
1433
|
+
priority: 2,
|
|
1434
|
+
complexity: 3,
|
|
1435
|
+
type: 'feature',
|
|
1436
|
+
category: 'general',
|
|
1437
|
+
createdAt: '2026-03-15T18:00:00.000Z',
|
|
1438
|
+
updatedAt: '2026-03-15T18:00:00.000Z',
|
|
1439
|
+
comments: [],
|
|
1440
|
+
attachments: [],
|
|
1441
|
+
checklistItems: [],
|
|
1442
|
+
taxonomies: {},
|
|
1443
|
+
assignee: 'unassigned',
|
|
1444
|
+
referenceNumber: null,
|
|
1445
|
+
localReferenceNumber: 18
|
|
1446
|
+
};
|
|
1447
|
+
const { result, unmount } = renderHook((props) => useSyncOrchestrator(props), {
|
|
1448
|
+
initialProps: buildInput({ tasks: [localTask] })
|
|
1449
|
+
});
|
|
1450
|
+
act(() => {
|
|
1451
|
+
result.current.applyWorkspaceSyncStateSnapshot({
|
|
1452
|
+
enabled: true,
|
|
1453
|
+
phase: 'active',
|
|
1454
|
+
pullCursor: null
|
|
1455
|
+
});
|
|
1456
|
+
});
|
|
1457
|
+
await act(async () => {
|
|
1458
|
+
await result.current.pushWorkspaceChangesToCloud('sig-initial-watchdog');
|
|
1459
|
+
});
|
|
1460
|
+
expect(runWorkspacePushSyncServiceMock).toHaveBeenCalledTimes(1);
|
|
1461
|
+
runWorkspacePushSyncServiceMock.mockClear();
|
|
1462
|
+
act(() => {
|
|
1463
|
+
result.current.workspaceLastPushedSignatureRef.current = 'stale-signature';
|
|
1464
|
+
result.current.workspacePullInFlightRef.current = true;
|
|
1465
|
+
});
|
|
1466
|
+
await act(async () => {
|
|
1467
|
+
await vi.advanceTimersByTimeAsync(20_000);
|
|
1468
|
+
});
|
|
1469
|
+
expect(runWorkspacePushSyncServiceMock).not.toHaveBeenCalled();
|
|
1470
|
+
act(() => {
|
|
1471
|
+
result.current.workspacePullInFlightRef.current = false;
|
|
1472
|
+
});
|
|
1473
|
+
await act(async () => {
|
|
1474
|
+
await vi.advanceTimersByTimeAsync(12_000);
|
|
1475
|
+
});
|
|
1476
|
+
expect(runWorkspacePushSyncServiceMock).toHaveBeenCalledTimes(1);
|
|
1477
|
+
expect(runWorkspacePushSyncServiceMock).toHaveBeenCalledWith(expect.objectContaining({
|
|
1478
|
+
payload: expect.objectContaining({
|
|
1479
|
+
changes: expect.arrayContaining([
|
|
1480
|
+
expect.objectContaining({
|
|
1481
|
+
op: 'upsert',
|
|
1482
|
+
task: expect.objectContaining({
|
|
1483
|
+
id: 'task-local-watchdog'
|
|
1484
|
+
})
|
|
1485
|
+
})
|
|
1486
|
+
])
|
|
1487
|
+
})
|
|
1488
|
+
}));
|
|
1489
|
+
unmount();
|
|
1490
|
+
});
|
|
856
1491
|
it('forces a full ai-profile push during manual retry even when the workspace signature is unchanged', async () => {
|
|
857
1492
|
vi.stubGlobal('fetch', vi.fn((url, init) => {
|
|
858
1493
|
if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
|