@taskforcehq/taskforce 0.3.309 → 0.3.313

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.
Files changed (470) hide show
  1. package/README.md +89 -127
  2. package/dist/TaskforceCore.js +1 -1
  3. package/dist/components/context/ContextAttachmentManager.js +4 -3
  4. package/dist/components/features/InitiativesModule.js +1 -1
  5. package/dist/components/features/TaskSettings.js +1 -1
  6. package/dist/components/ui/DisclosureSectionHeader.d.ts +12 -0
  7. package/dist/components/ui/DisclosureSectionHeader.js +8 -0
  8. package/dist/components/views/PlanComparisonPage.js +1 -1
  9. package/dist/components/views/StandaloneLayout.js +18 -4
  10. package/dist/components/views/panels/PlanningDrawer.js +2 -1
  11. package/dist/components/views/standalone/modals/AccountHubModal.js +1 -1
  12. package/dist/components/views/standalone/modals/HelpModal.d.ts +3 -1
  13. package/dist/components/views/standalone/modals/HelpModal.js +17 -2
  14. package/dist/core/PlanEntitlementService.d.ts +2 -0
  15. package/dist/core/PlanEntitlementService.js +57 -4
  16. package/dist/hooks/useFilterSort.js +1 -1
  17. package/dist/hooks/useTaskforce.js +2 -2
  18. package/dist/hooks/workspace/useTaskforceWorkspaceBootstrap.js +5 -2
  19. package/dist/localization/locales/en-US.js +1 -1
  20. package/dist/localization/locales/es-419.js +1 -1
  21. package/dist/localization/locales/pt-BR.js +1 -1
  22. package/dist/mcp/runtime.js +49 -14
  23. package/dist/server/routes/billing.js +0 -1
  24. package/dist/ui/assets/AgentsModule-BULqIo8e.js +1 -0
  25. package/dist/ui/assets/{AnnotatedAttachmentWorkspace-CCckzWYZ.js → AnnotatedAttachmentWorkspace-DHr4rHK9.js} +1 -1
  26. package/dist/ui/assets/ContextAttachmentManager-DoMe2OpY.js +3 -0
  27. package/dist/ui/assets/{DocumentWorkspace-BVaWPA25.js → DocumentWorkspace-DumBWhvb.js} +1 -1
  28. package/dist/ui/assets/{EntityActivityTimeline-DSj0ThaK.js → EntityActivityTimeline-sHk8Nzbq.js} +1 -1
  29. package/dist/ui/assets/{InitiativesModule-AxMkWtxH.js → InitiativesModule-3X9UNzHh.js} +1 -1
  30. package/dist/ui/assets/PlansPage-C3A3EYaV.js +1 -0
  31. package/dist/ui/assets/PlansPage-DeAzWYTb.css +1 -0
  32. package/dist/ui/assets/{TaskContextUpload-Dw4rTF4i.js → TaskContextUpload-C8G7pWkX.js} +1 -1
  33. package/dist/ui/assets/{TaskSettings-f2ga42_V.js → TaskSettings-DM1o9Wla.js} +2 -2
  34. package/dist/ui/assets/{WorkflowsModule-E4UL3mov.js → WorkflowsModule-CW0crzvD.js} +1 -1
  35. package/dist/ui/assets/documentReferences-BZB3nMRb.js +1 -0
  36. package/dist/ui/assets/index-BWFQ9mGn.js +5 -0
  37. package/dist/ui/assets/{index-BvAbqx5Q.css → index-DcK_8tuE.css} +1 -1
  38. package/dist/ui/assets/{vendor-icons-B32hGuF2.js → vendor-icons-CLnehDTw.js} +1 -1
  39. package/dist/ui/index.html +3 -3
  40. package/dist/utils/supportContact.d.ts +9 -0
  41. package/dist/utils/supportContact.js +32 -0
  42. package/package.json +12 -4
  43. package/scripts/postinstall.js +4 -3
  44. package/dist/TaskforceCore.CategoryFallback.test.d.ts +0 -1
  45. package/dist/TaskforceCore.CategoryFallback.test.js +0 -101
  46. package/dist/TaskforceCore.filter-persistence.test.d.ts +0 -1
  47. package/dist/TaskforceCore.filter-persistence.test.js +0 -402
  48. package/dist/TaskforceCore.routing.test.d.ts +0 -1
  49. package/dist/TaskforceCore.routing.test.js +0 -311
  50. package/dist/TaskforceCore.test.d.ts +0 -1
  51. package/dist/TaskforceCore.test.js +0 -7910
  52. package/dist/TaskforceWidget.test.d.ts +0 -1
  53. package/dist/TaskforceWidget.test.js +0 -92
  54. package/dist/UnsavedChangesRelaxed.test.d.ts +0 -1
  55. package/dist/UnsavedChangesRelaxed.test.js +0 -16
  56. package/dist/__tests__/localizationCatalogs.test.d.ts +0 -1
  57. package/dist/__tests__/localizationCatalogs.test.js +0 -54
  58. package/dist/__tests__/workflowSimulation.test.d.ts +0 -1
  59. package/dist/__tests__/workflowSimulation.test.js +0 -113
  60. package/dist/annotatedAttachments/AnnotatedAttachmentSessionStore.test.d.ts +0 -1
  61. package/dist/annotatedAttachments/AnnotatedAttachmentSessionStore.test.js +0 -278
  62. package/dist/annotatedAttachments/payload.test.d.ts +0 -1
  63. package/dist/annotatedAttachments/payload.test.js +0 -67
  64. package/dist/compat/workspaceSyncCompat.test.d.ts +0 -1
  65. package/dist/compat/workspaceSyncCompat.test.js +0 -124
  66. package/dist/components/features/AgentsModule.test.d.ts +0 -1
  67. package/dist/components/features/AgentsModule.test.js +0 -601
  68. package/dist/components/features/AnnotatedAttachmentWorkspace.test.d.ts +0 -1
  69. package/dist/components/features/AnnotatedAttachmentWorkspace.test.js +0 -2883
  70. package/dist/components/features/DocumentWorkspace.test.d.ts +0 -1
  71. package/dist/components/features/DocumentWorkspace.test.js +0 -1439
  72. package/dist/components/features/TaskSettings.test.d.ts +0 -1
  73. package/dist/components/features/TaskSettings.test.js +0 -1674
  74. package/dist/components/features/settings/TaxonomyLibraryManager.test.d.ts +0 -1
  75. package/dist/components/features/settings/TaxonomyLibraryManager.test.js +0 -141
  76. package/dist/components/task/TaskActionHeader.test.d.ts +0 -1
  77. package/dist/components/task/TaskActionHeader.test.js +0 -91
  78. package/dist/components/task/TaskCard.test.d.ts +0 -1
  79. package/dist/components/task/TaskCard.test.js +0 -513
  80. package/dist/components/task/TaskContextUpload.test.d.ts +0 -1
  81. package/dist/components/task/TaskContextUpload.test.js +0 -506
  82. package/dist/components/task/TaskForm.test.d.ts +0 -1
  83. package/dist/components/task/TaskForm.test.js +0 -946
  84. package/dist/components/task/TaskKanban.empty-column-drop.test.d.ts +0 -1
  85. package/dist/components/task/TaskKanban.empty-column-drop.test.js +0 -66
  86. package/dist/components/task/TaskKanban.planning-drop.test.d.ts +0 -1
  87. package/dist/components/task/TaskKanban.planning-drop.test.js +0 -93
  88. package/dist/components/task/TaskKanban.test.d.ts +0 -1
  89. package/dist/components/task/TaskKanban.test.js +0 -99
  90. package/dist/components/task/TaskList.test.d.ts +0 -1
  91. package/dist/components/task/TaskList.test.js +0 -473
  92. package/dist/components/task/TaskStatusActions.test.d.ts +0 -1
  93. package/dist/components/task/TaskStatusActions.test.js +0 -54
  94. package/dist/components/task/taskKanbanDropRules.test.d.ts +0 -1
  95. package/dist/components/task/taskKanbanDropRules.test.js +0 -114
  96. package/dist/components/ui/LevelSelector.test.d.ts +0 -1
  97. package/dist/components/ui/LevelSelector.test.js +0 -55
  98. package/dist/components/ui/Markdown.test.d.ts +0 -1
  99. package/dist/components/ui/Markdown.test.js +0 -38
  100. package/dist/components/ui/MultiSelectFilter.test.d.ts +0 -1
  101. package/dist/components/ui/MultiSelectFilter.test.js +0 -74
  102. package/dist/components/ui/TaxonomyDropdown.test.d.ts +0 -1
  103. package/dist/components/ui/TaxonomyDropdown.test.js +0 -130
  104. package/dist/components/ui/TopNoticeLayer.test.d.ts +0 -1
  105. package/dist/components/ui/TopNoticeLayer.test.js +0 -25
  106. package/dist/components/views/AppShellHeader.test.d.ts +0 -1
  107. package/dist/components/views/AppShellHeader.test.js +0 -42
  108. package/dist/components/views/PlanComparisonPage.test.d.ts +0 -1
  109. package/dist/components/views/PlanComparisonPage.test.js +0 -757
  110. package/dist/components/views/PlansPage.test.d.ts +0 -1
  111. package/dist/components/views/PlansPage.test.js +0 -710
  112. package/dist/components/views/chrome/WorkspaceChromeSections.test.d.ts +0 -1
  113. package/dist/components/views/chrome/WorkspaceChromeSections.test.js +0 -54
  114. package/dist/components/views/chrome/workspaceChrome.test.d.ts +0 -1
  115. package/dist/components/views/chrome/workspaceChrome.test.js +0 -52
  116. package/dist/components/views/panels/DocumentFilterToolbar.test.d.ts +0 -1
  117. package/dist/components/views/panels/DocumentFilterToolbar.test.js +0 -19
  118. package/dist/components/views/panels/FilterToolbar.test.d.ts +0 -1
  119. package/dist/components/views/panels/FilterToolbar.test.js +0 -47
  120. package/dist/components/views/panels/PlanningDrawer.test.d.ts +0 -1
  121. package/dist/components/views/panels/PlanningDrawer.test.js +0 -529
  122. package/dist/components/views/planningScope.test.d.ts +0 -1
  123. package/dist/components/views/planningScope.test.js +0 -60
  124. package/dist/components/views/standalone/modals/AccountHubModal.test.d.ts +0 -1
  125. package/dist/components/views/standalone/modals/AccountHubModal.test.js +0 -66
  126. package/dist/components/views/standalone/modals/SyncEnableWarningModal.test.d.ts +0 -1
  127. package/dist/components/views/standalone/modals/SyncEnableWarningModal.test.js +0 -24
  128. package/dist/components/views/teamManagementAccess.test.d.ts +0 -1
  129. package/dist/components/views/teamManagementAccess.test.js +0 -44
  130. package/dist/config/deployment.test.d.ts +0 -1
  131. package/dist/config/deployment.test.js +0 -90
  132. package/dist/config/envSchema.test.d.ts +0 -1
  133. package/dist/config/envSchema.test.js +0 -125
  134. package/dist/core/AiProfileService.test.d.ts +0 -1
  135. package/dist/core/AiProfileService.test.js +0 -184
  136. package/dist/core/AiProfiles.test.d.ts +0 -1
  137. package/dist/core/AiProfiles.test.js +0 -1873
  138. package/dist/core/AuthTokenService.test.d.ts +0 -1
  139. package/dist/core/AuthTokenService.test.js +0 -78
  140. package/dist/core/BulkUpdateFieldsPreview.test.d.ts +0 -1
  141. package/dist/core/BulkUpdateFieldsPreview.test.js +0 -62
  142. package/dist/core/CompletedAt.test.d.ts +0 -1
  143. package/dist/core/CompletedAt.test.js +0 -44
  144. package/dist/core/CreatedBy.test.d.ts +0 -1
  145. package/dist/core/CreatedBy.test.js +0 -188
  146. package/dist/core/DeletedTaskTrash.test.d.ts +0 -1
  147. package/dist/core/DeletedTaskTrash.test.js +0 -104
  148. package/dist/core/EntitlementsPolicy.test.d.ts +0 -1
  149. package/dist/core/EntitlementsPolicy.test.js +0 -280
  150. package/dist/core/GlobalSettingsService.test.d.ts +0 -1
  151. package/dist/core/GlobalSettingsService.test.js +0 -45
  152. package/dist/core/JsonBackupRuntime.test.d.ts +0 -1
  153. package/dist/core/JsonBackupRuntime.test.js +0 -155
  154. package/dist/core/PlanFeatureCatalog.test.d.ts +0 -1
  155. package/dist/core/PlanFeatureCatalog.test.js +0 -139
  156. package/dist/core/PlanVersionPolicy.test.d.ts +0 -1
  157. package/dist/core/PlanVersionPolicy.test.js +0 -204
  158. package/dist/core/PlanningEntities.test.d.ts +0 -1
  159. package/dist/core/PlanningEntities.test.js +0 -509
  160. package/dist/core/ScheduleFields.test.d.ts +0 -1
  161. package/dist/core/ScheduleFields.test.js +0 -193
  162. package/dist/core/SetupState.test.d.ts +0 -1
  163. package/dist/core/SetupState.test.js +0 -113
  164. package/dist/core/SignupMonetizationSettings.test.d.ts +0 -1
  165. package/dist/core/SignupMonetizationSettings.test.js +0 -515
  166. package/dist/core/Stats.test.d.ts +0 -1
  167. package/dist/core/Stats.test.js +0 -36
  168. package/dist/core/SystemAdmin.test.d.ts +0 -1
  169. package/dist/core/SystemAdmin.test.js +0 -1106
  170. package/dist/core/TaskActivitySync.test.d.ts +0 -1
  171. package/dist/core/TaskActivitySync.test.js +0 -90
  172. package/dist/core/TaskAttachmentsCanonical.test.d.ts +0 -1
  173. package/dist/core/TaskAttachmentsCanonical.test.js +0 -356
  174. package/dist/core/TaskAuditTimeline.test.d.ts +0 -1
  175. package/dist/core/TaskAuditTimeline.test.js +0 -319
  176. package/dist/core/TaskTaxonomyValidation.test.d.ts +0 -1
  177. package/dist/core/TaskTaxonomyValidation.test.js +0 -440
  178. package/dist/core/Taskforce.ids.test.d.ts +0 -1
  179. package/dist/core/Taskforce.ids.test.js +0 -611
  180. package/dist/core/Taskforce.listTasksSlim.test.d.ts +0 -1
  181. package/dist/core/Taskforce.listTasksSlim.test.js +0 -91
  182. package/dist/core/Taskforce.mcpAuth.test.d.ts +0 -1
  183. package/dist/core/Taskforce.mcpAuth.test.js +0 -450
  184. package/dist/core/Taskforce.realtimeMutation.test.d.ts +0 -1
  185. package/dist/core/Taskforce.realtimeMutation.test.js +0 -131
  186. package/dist/core/UserProfileAvatarDrafts.test.d.ts +0 -1
  187. package/dist/core/UserProfileAvatarDrafts.test.js +0 -138
  188. package/dist/core/WorkspaceDelete.test.d.ts +0 -1
  189. package/dist/core/WorkspaceDelete.test.js +0 -159
  190. package/dist/core/WorkspacePermissions.test.d.ts +0 -1
  191. package/dist/core/WorkspacePermissions.test.js +0 -270
  192. package/dist/core/WorkspacePlanMode.test.d.ts +0 -1
  193. package/dist/core/WorkspacePlanMode.test.js +0 -383
  194. package/dist/core/WorkspaceSyncSettings.test.d.ts +0 -1
  195. package/dist/core/WorkspaceSyncSettings.test.js +0 -65
  196. package/dist/core/__tests__/TaskAttachmentsCanonical.test.d.ts +0 -1
  197. package/dist/core/__tests__/TaskAttachmentsCanonical.test.js +0 -212
  198. package/dist/documentReviews/DocumentReviewSessionStore.test.d.ts +0 -1
  199. package/dist/documentReviews/DocumentReviewSessionStore.test.js +0 -127
  200. package/dist/hooks/authGuardPolicy.test.d.ts +0 -1
  201. package/dist/hooks/authGuardPolicy.test.js +0 -76
  202. package/dist/hooks/bootstrapTimeouts.test.d.ts +0 -1
  203. package/dist/hooks/bootstrapTimeouts.test.js +0 -12
  204. package/dist/hooks/sync/controlPlane.test.d.ts +0 -1
  205. package/dist/hooks/sync/controlPlane.test.js +0 -121
  206. package/dist/hooks/sync/lifecyclePolicy.test.d.ts +0 -1
  207. package/dist/hooks/sync/lifecyclePolicy.test.js +0 -124
  208. package/dist/hooks/sync/orchestratorShared.test.d.ts +0 -1
  209. package/dist/hooks/sync/orchestratorShared.test.js +0 -98
  210. package/dist/hooks/sync/pullLifecycle.test.d.ts +0 -1
  211. package/dist/hooks/sync/pullLifecycle.test.js +0 -80
  212. package/dist/hooks/sync/recovery.test.d.ts +0 -1
  213. package/dist/hooks/sync/recovery.test.js +0 -292
  214. package/dist/hooks/sync/transfers.test.d.ts +0 -1
  215. package/dist/hooks/sync/transfers.test.js +0 -928
  216. package/dist/hooks/sync/useRecentSyncEvents.test.d.ts +0 -1
  217. package/dist/hooks/sync/useRecentSyncEvents.test.js +0 -124
  218. package/dist/hooks/sync/useSyncStatusActions.test.d.ts +0 -1
  219. package/dist/hooks/sync/useSyncStatusActions.test.js +0 -133
  220. package/dist/hooks/sync/useSyncStatusControls.test.d.ts +0 -1
  221. package/dist/hooks/sync/useSyncStatusControls.test.js +0 -88
  222. package/dist/hooks/useFilterSort.test.d.ts +0 -1
  223. package/dist/hooks/useFilterSort.test.js +0 -419
  224. package/dist/hooks/useRealtimeSync.test.d.ts +0 -1
  225. package/dist/hooks/useRealtimeSync.test.js +0 -311
  226. package/dist/hooks/useSyncOrchestrator.aiProfiles.test.d.ts +0 -1
  227. package/dist/hooks/useSyncOrchestrator.aiProfiles.test.js +0 -54
  228. package/dist/hooks/useSyncOrchestrator.context-assets.test.d.ts +0 -1
  229. package/dist/hooks/useSyncOrchestrator.context-assets.test.js +0 -228
  230. package/dist/hooks/useSyncOrchestrator.retry-closure.test.d.ts +0 -1
  231. package/dist/hooks/useSyncOrchestrator.retry-closure.test.js +0 -2027
  232. package/dist/hooks/useTaskData.test.d.ts +0 -1
  233. package/dist/hooks/useTaskData.test.js +0 -291
  234. package/dist/hooks/useTaskMutations.test.d.ts +0 -1
  235. package/dist/hooks/useTaskMutations.test.js +0 -256
  236. package/dist/hooks/useTaskforce.contract.test.d.ts +0 -1
  237. package/dist/hooks/useTaskforce.contract.test.js +0 -7
  238. package/dist/hooks/useTaskforce.priority-filters.test.d.ts +0 -1
  239. package/dist/hooks/useTaskforce.priority-filters.test.js +0 -28
  240. package/dist/hooks/useTaskforce.runtime-routing.test.d.ts +0 -1
  241. package/dist/hooks/useTaskforce.runtime-routing.test.js +0 -246
  242. package/dist/hooks/useTaskforce.sync-behavior.test.d.ts +0 -1
  243. package/dist/hooks/useTaskforce.sync-behavior.test.js +0 -3644
  244. package/dist/hooks/useWorkspaceSyncController.test.d.ts +0 -1
  245. package/dist/hooks/useWorkspaceSyncController.test.js +0 -192
  246. package/dist/hooks/workspace/useTaskforceApiRouting.test.d.ts +0 -1
  247. package/dist/hooks/workspace/useTaskforceApiRouting.test.js +0 -77
  248. package/dist/hooks/workspace/workspaceLocalState.test.d.ts +0 -1
  249. package/dist/hooks/workspace/workspaceLocalState.test.js +0 -59
  250. package/dist/localization/localizationCatalogs.test.d.ts +0 -1
  251. package/dist/localization/localizationCatalogs.test.js +0 -37
  252. package/dist/mcp/aiProfileBootstrap.test.d.ts +0 -1
  253. package/dist/mcp/aiProfileBootstrap.test.js +0 -68
  254. package/dist/mcp/canonicalAssetHelpers.test.d.ts +0 -1
  255. package/dist/mcp/canonicalAssetHelpers.test.js +0 -67
  256. package/dist/mcp/clientIntegrations.test.d.ts +0 -1
  257. package/dist/mcp/clientIntegrations.test.js +0 -219
  258. package/dist/mcp/optionResolution.test.d.ts +0 -1
  259. package/dist/mcp/optionResolution.test.js +0 -43
  260. package/dist/mcp/runtime.test.d.ts +0 -1
  261. package/dist/mcp/runtime.test.js +0 -5120
  262. package/dist/mcp/structuredCommentValidation.test.d.ts +0 -1
  263. package/dist/mcp/structuredCommentValidation.test.js +0 -31
  264. package/dist/mcp/structuredDocValidation.test.d.ts +0 -1
  265. package/dist/mcp/structuredDocValidation.test.js +0 -35
  266. package/dist/mcp/toolRegistry.test.d.ts +0 -1
  267. package/dist/mcp/toolRegistry.test.js +0 -34
  268. package/dist/migrations/billingSchemaParity.test.d.ts +0 -1
  269. package/dist/migrations/billingSchemaParity.test.js +0 -160
  270. package/dist/migrations/taskSchemaMigrations.test.d.ts +0 -1
  271. package/dist/migrations/taskSchemaMigrations.test.js +0 -225
  272. package/dist/qaOpen.test.d.ts +0 -1
  273. package/dist/qaOpen.test.js +0 -56
  274. package/dist/releaseVersion.test.d.ts +0 -1
  275. package/dist/releaseVersion.test.js +0 -32
  276. package/dist/runtime/appGates.test.d.ts +0 -1
  277. package/dist/runtime/appGates.test.js +0 -42
  278. package/dist/server/aiProfileAvatarAssets.test.d.ts +0 -1
  279. package/dist/server/aiProfileAvatarAssets.test.js +0 -213
  280. package/dist/server/annotatedAttachmentsRoutes.test.d.ts +0 -1
  281. package/dist/server/annotatedAttachmentsRoutes.test.js +0 -532
  282. package/dist/server/auth.test.d.ts +0 -1
  283. package/dist/server/auth.test.js +0 -131
  284. package/dist/server/buildInfo.test.d.ts +0 -1
  285. package/dist/server/buildInfo.test.js +0 -29
  286. package/dist/server/cors.test.d.ts +0 -1
  287. package/dist/server/cors.test.js +0 -77
  288. package/dist/server/documentReviewRoutes.test.d.ts +0 -1
  289. package/dist/server/documentReviewRoutes.test.js +0 -190
  290. package/dist/server/email.test.d.ts +0 -1
  291. package/dist/server/email.test.js +0 -113
  292. package/dist/server/index.cookieProxy.test.d.ts +0 -1
  293. package/dist/server/index.cookieProxy.test.js +0 -67
  294. package/dist/server/index.rateLimit.test.d.ts +0 -1
  295. package/dist/server/index.rateLimit.test.js +0 -22
  296. package/dist/server/index.test.d.ts +0 -1
  297. package/dist/server/index.test.js +0 -283
  298. package/dist/server/rateLimit.test.d.ts +0 -1
  299. package/dist/server/rateLimit.test.js +0 -107
  300. package/dist/server/realtimeSync.auth.test.d.ts +0 -1
  301. package/dist/server/realtimeSync.auth.test.js +0 -62
  302. package/dist/server/realtimeSync.replay.test.d.ts +0 -1
  303. package/dist/server/realtimeSync.replay.test.js +0 -192
  304. package/dist/server/realtimeSync.workspaceIsolation.test.d.ts +0 -1
  305. package/dist/server/realtimeSync.workspaceIsolation.test.js +0 -101
  306. package/dist/server/routes/billing.test.d.ts +0 -1
  307. package/dist/server/routes/billing.test.js +0 -3455
  308. package/dist/server/routes/shared.test.d.ts +0 -1
  309. package/dist/server/routes/shared.test.js +0 -32
  310. package/dist/server/routes/sync.integration.test.d.ts +0 -1
  311. package/dist/server/routes/sync.integration.test.js +0 -2932
  312. package/dist/server/routes/syncAuxRoutes.test.d.ts +0 -1
  313. package/dist/server/routes/syncAuxRoutes.test.js +0 -158
  314. package/dist/server/routes/syncRouteGuards.test.d.ts +0 -1
  315. package/dist/server/routes/syncRouteGuards.test.js +0 -94
  316. package/dist/server/routes.test.d.ts +0 -1
  317. package/dist/server/routes.test.js +0 -15612
  318. package/dist/server/runtimeMode.test.d.ts +0 -1
  319. package/dist/server/runtimeMode.test.js +0 -26
  320. package/dist/server/securityHeaders.test.d.ts +0 -1
  321. package/dist/server/securityHeaders.test.js +0 -70
  322. package/dist/services/templateEngine.test.d.ts +0 -1
  323. package/dist/services/templateEngine.test.js +0 -150
  324. package/dist/services/templates.test.d.ts +0 -1
  325. package/dist/services/templates.test.js +0 -45
  326. package/dist/services/workflowDocumentFixtures.test.d.ts +0 -1
  327. package/dist/services/workflowDocumentFixtures.test.js +0 -78
  328. package/dist/services/workflowExportMatrix.test.d.ts +0 -1
  329. package/dist/services/workflowExportMatrix.test.js +0 -113
  330. package/dist/services/workflowExportSnapshots.test.d.ts +0 -1
  331. package/dist/services/workflowExportSnapshots.test.js +0 -30
  332. package/dist/services/workflowGeneration.test.d.ts +0 -1
  333. package/dist/services/workflowGeneration.test.js +0 -12
  334. package/dist/services/workflowSimulation.test.d.ts +0 -1
  335. package/dist/services/workflowSimulation.test.js +0 -113
  336. package/dist/services/workflowV2Policy.test.d.ts +0 -1
  337. package/dist/services/workflowV2Policy.test.js +0 -80
  338. package/dist/shared/customTaxonomyLibrary.test.d.ts +0 -1
  339. package/dist/shared/customTaxonomyLibrary.test.js +0 -20
  340. package/dist/shared/passwordPolicy.test.d.ts +0 -1
  341. package/dist/shared/passwordPolicy.test.js +0 -34
  342. package/dist/shared/runtimeContract.test.d.ts +0 -1
  343. package/dist/shared/runtimeContract.test.js +0 -23
  344. package/dist/shared/taxonomyLibrary.test.d.ts +0 -1
  345. package/dist/shared/taxonomyLibrary.test.js +0 -26
  346. package/dist/shared/taxonomyState.test.d.ts +0 -1
  347. package/dist/shared/taxonomyState.test.js +0 -71
  348. package/dist/soak/preflight.cli.d.ts +0 -1
  349. package/dist/soak/preflight.cli.js +0 -28
  350. package/dist/soak/preflight.d.ts +0 -26
  351. package/dist/soak/preflight.js +0 -113
  352. package/dist/soak/preflight.test.d.ts +0 -1
  353. package/dist/soak/preflight.test.js +0 -39
  354. package/dist/storage/objectStorageClient.test.d.ts +0 -1
  355. package/dist/storage/objectStorageClient.test.js +0 -82
  356. package/dist/storage/objectStorageConfig.test.d.ts +0 -1
  357. package/dist/storage/objectStorageConfig.test.js +0 -50
  358. package/dist/storage/postgresAdapter.test.d.ts +0 -1
  359. package/dist/storage/postgresAdapter.test.js +0 -29
  360. package/dist/storage/workspaceAssetStore.test.d.ts +0 -1
  361. package/dist/storage/workspaceAssetStore.test.js +0 -588
  362. package/dist/sync/cloudSyncApi.test.d.ts +0 -1
  363. package/dist/sync/cloudSyncApi.test.js +0 -111
  364. package/dist/sync/collaborationSyncPayload.test.d.ts +0 -1
  365. package/dist/sync/collaborationSyncPayload.test.js +0 -125
  366. package/dist/sync/contentSyncPayload.test.d.ts +0 -1
  367. package/dist/sync/contentSyncPayload.test.js +0 -143
  368. package/dist/sync/encryptionService.test.d.ts +0 -1
  369. package/dist/sync/encryptionService.test.js +0 -52
  370. package/dist/sync/planningSyncPayload.test.d.ts +0 -1
  371. package/dist/sync/planningSyncPayload.test.js +0 -92
  372. package/dist/sync/realtimeFeature.test.d.ts +0 -1
  373. package/dist/sync/realtimeFeature.test.js +0 -30
  374. package/dist/sync/realtimeReconcile.test.d.ts +0 -1
  375. package/dist/sync/realtimeReconcile.test.js +0 -43
  376. package/dist/sync/syncApplyHandlers.test.d.ts +0 -1
  377. package/dist/sync/syncApplyHandlers.test.js +0 -626
  378. package/dist/sync/syncService.test.d.ts +0 -1
  379. package/dist/sync/syncService.test.js +0 -903
  380. package/dist/sync/taskSyncPayload.test.d.ts +0 -1
  381. package/dist/sync/taskSyncPayload.test.js +0 -54
  382. package/dist/sync/workspacePullFeed.test.d.ts +0 -1
  383. package/dist/sync/workspacePullFeed.test.js +0 -438
  384. package/dist/sync/workspaceSyncModel.test.d.ts +0 -1
  385. package/dist/sync/workspaceSyncModel.test.js +0 -1442
  386. package/dist/test/setup.d.ts +0 -1
  387. package/dist/test/setup.js +0 -15
  388. package/dist/ui/assets/AgentsModule-BS4Pi_nC.js +0 -1
  389. package/dist/ui/assets/ContextAttachmentManager-CfG_ER7C.js +0 -3
  390. package/dist/ui/assets/PlansPage-B_z-D6Nh.css +0 -1
  391. package/dist/ui/assets/PlansPage-Ndt7mYfo.js +0 -1
  392. package/dist/ui/assets/documentReferences-BOUcJm6-.js +0 -1
  393. package/dist/ui/assets/index-MAHKvFqp.js +0 -4
  394. package/dist/utils/accountProfileSummaryCache.test.d.ts +0 -1
  395. package/dist/utils/accountProfileSummaryCache.test.js +0 -63
  396. package/dist/utils/annotatedAttachments.test.d.ts +0 -1
  397. package/dist/utils/annotatedAttachments.test.js +0 -108
  398. package/dist/utils/assignees.test.d.ts +0 -1
  399. package/dist/utils/assignees.test.js +0 -25
  400. package/dist/utils/avatarUpload.test.d.ts +0 -1
  401. package/dist/utils/avatarUpload.test.js +0 -40
  402. package/dist/utils/canonicalAssetKind.test.d.ts +0 -1
  403. package/dist/utils/canonicalAssetKind.test.js +0 -24
  404. package/dist/utils/coalescedRefresh.test.d.ts +0 -1
  405. package/dist/utils/coalescedRefresh.test.js +0 -30
  406. package/dist/utils/constants.icons.test.d.ts +0 -1
  407. package/dist/utils/constants.icons.test.js +0 -41
  408. package/dist/utils/planParser.test.d.ts +0 -1
  409. package/dist/utils/planParser.test.js +0 -183
  410. package/dist/utils/planningReferences.test.d.ts +0 -1
  411. package/dist/utils/planningReferences.test.js +0 -17
  412. package/dist/utils/syncEventDetails.test.d.ts +0 -1
  413. package/dist/utils/syncEventDetails.test.js +0 -23
  414. package/dist/utils/syncEventPresentation.test.d.ts +0 -1
  415. package/dist/utils/syncEventPresentation.test.js +0 -64
  416. package/dist/utils/syncStatusPresentation.test.d.ts +0 -1
  417. package/dist/utils/syncStatusPresentation.test.js +0 -164
  418. package/dist/utils/taskActivity.test.d.ts +0 -1
  419. package/dist/utils/taskActivity.test.js +0 -218
  420. package/dist/utils/taskDraftDefaults.test.d.ts +0 -1
  421. package/dist/utils/taskDraftDefaults.test.js +0 -34
  422. package/dist/utils/taskDragZones.test.d.ts +0 -1
  423. package/dist/utils/taskDragZones.test.js +0 -14
  424. package/dist/utils/taskNormalization.test.d.ts +0 -1
  425. package/dist/utils/taskNormalization.test.js +0 -158
  426. package/dist/utils/taskSearch.test.d.ts +0 -1
  427. package/dist/utils/taskSearch.test.js +0 -69
  428. package/dist/utils/taskUtils.test.d.ts +0 -1
  429. package/dist/utils/taskUtils.test.js +0 -19
  430. package/dist/utils/taskforceApiClient.test.d.ts +0 -1
  431. package/dist/utils/taskforceApiClient.test.js +0 -44
  432. package/dist/utils/taxonomyFormDefaults.test.d.ts +0 -1
  433. package/dist/utils/taxonomyFormDefaults.test.js +0 -63
  434. package/dist/utils/uiNotice.test.d.ts +0 -1
  435. package/dist/utils/uiNotice.test.js +0 -18
  436. package/dist/utils/workspaceIdentity.test.d.ts +0 -1
  437. package/dist/utils/workspaceIdentity.test.js +0 -61
  438. package/dist/utils/workspaceLifecycle.test.d.ts +0 -1
  439. package/dist/utils/workspaceLifecycle.test.js +0 -64
  440. package/dist/utils/workspaceSyncPresentation.test.d.ts +0 -1
  441. package/dist/utils/workspaceSyncPresentation.test.js +0 -71
  442. package/scripts/bootstrap-playwright-auth.mjs +0 -155
  443. package/scripts/check-cloud-mcp.mjs +0 -83
  444. package/scripts/check-compat-boundaries.mjs +0 -41
  445. package/scripts/check-env.ts +0 -31
  446. package/scripts/check-localization-strings.mjs +0 -49
  447. package/scripts/check-runtime-boundaries.mjs +0 -44
  448. package/scripts/debug-global.mjs +0 -34
  449. package/scripts/debug-login.mjs +0 -32
  450. package/scripts/debug-server.mjs +0 -36
  451. package/scripts/deploy-prod.sh +0 -41
  452. package/scripts/deploy-staging.sh +0 -23
  453. package/scripts/export-sqlite-to-postgres.mjs +0 -123
  454. package/scripts/generate-env-example.ts +0 -8
  455. package/scripts/mcp-stdio-adapter.mjs +0 -160
  456. package/scripts/migrate-task-data-assets.mjs +0 -408
  457. package/scripts/playwright-auth.sh +0 -19
  458. package/scripts/qa-open-lib.mjs +0 -175
  459. package/scripts/qa-open-lib.mjs.d.ts +0 -49
  460. package/scripts/qa-open.mjs +0 -352
  461. package/scripts/release-version-lib.mjs +0 -88
  462. package/scripts/release-version.mjs +0 -72
  463. package/scripts/run-billing-performance-smoke.sh +0 -24
  464. package/scripts/run-dev-proxy.sh +0 -51
  465. package/scripts/run-e2e-realtime.sh +0 -30
  466. package/scripts/run-smoke.sh +0 -35
  467. package/scripts/run-soak.sh +0 -41
  468. package/scripts/test-global.js +0 -143
  469. package/scripts/update-homebrew-formula.sh +0 -108
  470. package/scripts/with-esbuild.sh +0 -11
@@ -1,3644 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { MemoryRouter } from 'react-router-dom';
3
- import { act, renderHook, waitFor } from '@testing-library/react';
4
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
- import { useTaskforce } from './useTaskforce';
6
- class MockWebSocket {
7
- static instances = [];
8
- static OPEN = 1;
9
- static CLOSED = 3;
10
- url;
11
- readyState = 0;
12
- sent = [];
13
- listeners = {
14
- open: [],
15
- message: [],
16
- close: [],
17
- error: []
18
- };
19
- constructor(url) {
20
- this.url = url;
21
- MockWebSocket.instances.push(this);
22
- }
23
- addEventListener(type, listener) {
24
- this.listeners[type] = this.listeners[type] || [];
25
- this.listeners[type].push(listener);
26
- }
27
- close() {
28
- this.readyState = MockWebSocket.CLOSED;
29
- this.emit('close', {});
30
- }
31
- send(payload) {
32
- this.sent.push(payload);
33
- }
34
- emit(type, event) {
35
- const handlers = this.listeners[type] || [];
36
- handlers.forEach((handler) => handler(event));
37
- }
38
- open() {
39
- this.readyState = MockWebSocket.OPEN;
40
- this.emit('open', {});
41
- }
42
- message(payload) {
43
- this.emit('message', { data: JSON.stringify(payload) });
44
- }
45
- }
46
- function jsonResponse(body, status = 200) {
47
- return Promise.resolve({
48
- ok: status >= 200 && status < 300,
49
- status,
50
- json: () => Promise.resolve(body)
51
- });
52
- }
53
- const wrapper = ({ children }) => (_jsx(MemoryRouter, { children: children }));
54
- const activeTask = {
55
- id: 'task-parent',
56
- title: 'Parent task',
57
- description: 'Parent description',
58
- category: 'general',
59
- type: 'feature',
60
- priority: 2,
61
- complexity: 3,
62
- status: 'task',
63
- createdAt: '2026-03-15T10:00:00.000Z',
64
- updatedAt: '2026-03-15T10:00:00.000Z'
65
- };
66
- const doneTask = {
67
- ...activeTask,
68
- id: 'task-done',
69
- title: 'Done task',
70
- status: 'done',
71
- completedAt: '2026-03-15T10:15:00.000Z',
72
- updatedAt: '2026-03-15T10:15:00.000Z'
73
- };
74
- const archivedTaskRecord = (id, title) => ({
75
- id,
76
- title,
77
- description: `${title} description`,
78
- category: 'general',
79
- type: 'feature',
80
- priority: 2,
81
- complexity: 3,
82
- status: 'done',
83
- createdAt: '2026-03-15T10:10:00.000Z',
84
- updatedAt: '2026-03-15T10:10:00.000Z',
85
- isArchived: true
86
- });
87
- describe('useTaskforce sync behavior', () => {
88
- beforeEach(() => {
89
- localStorage.clear();
90
- sessionStorage.clear();
91
- });
92
- afterEach(() => {
93
- vi.useRealTimers();
94
- vi.unstubAllGlobals();
95
- vi.clearAllMocks();
96
- MockWebSocket.instances = [];
97
- });
98
- it('merges a server-returned task into the active collection immediately', async () => {
99
- vi.stubGlobal('fetch', vi.fn((url, init) => {
100
- if (url.includes('/api/taskforce/auth/runtime-config')) {
101
- return jsonResponse({ config: { runtimeMode: 'local', workspaceMode: 'single-local', authSource: 'cloud' } });
102
- }
103
- if (url.includes('/api/taskforce/auth/session')) {
104
- return jsonResponse({
105
- authenticated: false,
106
- authRequiredForApi: false,
107
- betaAccess: true,
108
- userId: 'anonymous',
109
- email: '',
110
- workspaceId: 'workspace-local-active'
111
- });
112
- }
113
- if (url.includes('/api/taskforce/ui-state?key=app')) {
114
- return jsonResponse({ success: true, state: {} });
115
- }
116
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
117
- return jsonResponse({
118
- success: true,
119
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
120
- });
121
- }
122
- if (url.includes('/api/taskforce/config')) {
123
- return jsonResponse({
124
- projectName: 'Test Project',
125
- workspaceId: 'workspace-local-active',
126
- runtimeMode: 'local',
127
- setupState: {
128
- globalSetupState: 'complete',
129
- workspaceSetupState: 'complete',
130
- workspaceId: 'workspace-local-active'
131
- }
132
- });
133
- }
134
- if (url.includes('/api/taskforce/global-settings')) {
135
- return jsonResponse({});
136
- }
137
- if (url.includes('/api/taskforce/categories')) {
138
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
139
- }
140
- if (url.includes('/api/taskforce/types')) {
141
- return jsonResponse({ types: [] });
142
- }
143
- if (url.includes('/api/taskforce/priorities')) {
144
- return jsonResponse({ priorities: [] });
145
- }
146
- if (url.includes('/api/taskforce/approaches')) {
147
- return jsonResponse({ approaches: [] });
148
- }
149
- if (url.includes('/api/taskforce/specialists')) {
150
- return jsonResponse({ specialists: [] });
151
- }
152
- if (url.includes('/api/taskforce/tasks')) {
153
- return jsonResponse({ tasks: [activeTask] });
154
- }
155
- if (url.includes('/api/taskforce/archive')) {
156
- return jsonResponse({ archived: [] });
157
- }
158
- if (url.includes('/api/taskforce/task/task-child') && String(init?.method || '').toUpperCase() === 'PATCH') {
159
- return jsonResponse({
160
- id: 'task-child',
161
- title: 'Updated task',
162
- description: 'Updated description',
163
- category: 'general',
164
- type: 'feature',
165
- priority: 2,
166
- complexity: 3,
167
- status: 'in-progress',
168
- createdAt: '2026-03-15T10:05:00.000Z',
169
- updatedAt: '2026-03-15T10:06:00.000Z'
170
- });
171
- }
172
- if (url.includes('/api/taskforce/data-version')) {
173
- return jsonResponse({ dataVersion: 1 });
174
- }
175
- return jsonResponse({});
176
- }));
177
- const { result } = renderHook(() => useTaskforce({ config: {} }), { wrapper });
178
- await waitFor(() => {
179
- expect(result.current.tasks.some((task) => task.id === 'task-parent')).toBe(true);
180
- });
181
- await act(async () => {
182
- await result.current.handleUpdateTask('task-child', { status: 'in-progress' });
183
- });
184
- await waitFor(() => {
185
- const childTask = result.current.tasks.find((task) => task.id === 'task-child');
186
- expect(childTask?.status).toBe('in-progress');
187
- });
188
- });
189
- it('keeps a created workstream visible even if the follow-up planning refresh is stale', async () => {
190
- const initialInitiative = {
191
- id: 'initiative-1',
192
- title: 'AI & MCP',
193
- description: 'Planning initiative',
194
- ownerId: null,
195
- createdAt: '2026-03-15T10:00:00.000Z',
196
- updatedAt: '2026-03-15T10:00:00.000Z',
197
- referenceNumber: 5,
198
- referenceLabel: 'IN-5',
199
- isArchived: false,
200
- comments: [],
201
- attachments: []
202
- };
203
- const initialWorkstream = {
204
- id: 'workstream-1',
205
- title: 'MCP Tools',
206
- description: 'Existing workstream',
207
- ownerId: null,
208
- initiativeId: 'initiative-1',
209
- createdAt: '2026-03-15T10:05:00.000Z',
210
- updatedAt: '2026-03-15T10:05:00.000Z',
211
- referenceNumber: 640,
212
- referenceLabel: 'WS-640',
213
- isArchived: false,
214
- comments: [],
215
- attachments: []
216
- };
217
- const createdWorkstream = {
218
- id: 'workstream-2',
219
- title: 'Agent Manager',
220
- description: 'New workstream',
221
- ownerId: null,
222
- initiativeId: 'initiative-1',
223
- createdAt: '2026-03-15T10:10:00.000Z',
224
- updatedAt: '2026-03-15T10:10:00.000Z',
225
- referenceNumber: 641,
226
- referenceLabel: 'WS-641',
227
- isArchived: false,
228
- comments: [],
229
- attachments: []
230
- };
231
- vi.stubGlobal('fetch', vi.fn((url, init) => {
232
- if (url.includes('/api/taskforce/auth/runtime-config')) {
233
- return jsonResponse({ config: { runtimeMode: 'local', workspaceMode: 'single-local', authSource: 'cloud' } });
234
- }
235
- if (url.includes('/api/taskforce/auth/session')) {
236
- return jsonResponse({
237
- authenticated: false,
238
- authRequiredForApi: false,
239
- betaAccess: true,
240
- userId: 'anonymous',
241
- email: '',
242
- workspaceId: 'workspace-local-active'
243
- });
244
- }
245
- if (url.includes('/api/taskforce/ui-state?key=app')) {
246
- return jsonResponse({ success: true, state: {} });
247
- }
248
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
249
- return jsonResponse({
250
- success: true,
251
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
252
- });
253
- }
254
- if (url.includes('/api/taskforce/config')) {
255
- return jsonResponse({
256
- projectName: 'Test Project',
257
- workspaceId: 'workspace-local-active',
258
- runtimeMode: 'local',
259
- setupState: {
260
- globalSetupState: 'complete',
261
- workspaceSetupState: 'complete',
262
- workspaceId: 'workspace-local-active'
263
- }
264
- });
265
- }
266
- if (url.includes('/api/taskforce/global-settings'))
267
- return jsonResponse({});
268
- if (url.includes('/api/taskforce/categories'))
269
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
270
- if (url.includes('/api/taskforce/types'))
271
- return jsonResponse({ types: [] });
272
- if (url.includes('/api/taskforce/priorities'))
273
- return jsonResponse({ priorities: [] });
274
- if (url.includes('/api/taskforce/approaches'))
275
- return jsonResponse({ approaches: [] });
276
- if (url.includes('/api/taskforce/specialists'))
277
- return jsonResponse({ specialists: [] });
278
- if (url.includes('/api/taskforce/tasks'))
279
- return jsonResponse({ tasks: [activeTask] });
280
- if (url.includes('/api/taskforce/archive'))
281
- return jsonResponse({ archived: [] });
282
- if (url.includes('/api/taskforce/planning/bootstrap')) {
283
- return jsonResponse({
284
- initiatives: [initialInitiative],
285
- workstreams: [initialWorkstream],
286
- workstreamTaskSummaries: [{
287
- workstreamId: initialWorkstream.id,
288
- taskCount: 1,
289
- completedTaskCount: 0,
290
- tasks: [{
291
- id: activeTask.id,
292
- title: activeTask.title,
293
- status: activeTask.status,
294
- }],
295
- }],
296
- });
297
- }
298
- if (url.includes('/api/taskforce/workstream') && String(init?.method || '').toUpperCase() === 'POST') {
299
- return jsonResponse(createdWorkstream, 201);
300
- }
301
- if (url.includes('/api/taskforce/data-version')) {
302
- return jsonResponse({ dataVersion: 1 });
303
- }
304
- return jsonResponse({});
305
- }));
306
- const { result } = renderHook(() => useTaskforce({ config: {} }), { wrapper });
307
- await waitFor(() => {
308
- expect(result.current.tasks.some((task) => task.id === activeTask.id)).toBe(true);
309
- });
310
- await act(async () => {
311
- await result.current.createWorkstream({
312
- title: createdWorkstream.title,
313
- description: createdWorkstream.description,
314
- initiativeId: createdWorkstream.initiativeId
315
- });
316
- });
317
- await waitFor(() => {
318
- expect(result.current.workstreams.some((workstream) => workstream.id === createdWorkstream.id)).toBe(true);
319
- });
320
- });
321
- it('falls back to legacy planning endpoints when bootstrap is unavailable during startup', async () => {
322
- const initiative = {
323
- id: 'initiative-fallback-1',
324
- title: 'Fallback initiative',
325
- description: null,
326
- createdAt: '2026-03-15T10:00:00.000Z',
327
- };
328
- const workstream = {
329
- id: 'workstream-fallback-1',
330
- title: 'Fallback workstream',
331
- description: null,
332
- initiativeId: initiative.id,
333
- createdAt: '2026-03-15T10:05:00.000Z',
334
- };
335
- vi.stubGlobal('fetch', vi.fn((url) => {
336
- if (url.includes('/api/taskforce/auth/runtime-config')) {
337
- return jsonResponse({ config: { runtimeMode: 'local', workspaceMode: 'single-local', authSource: 'cloud' } });
338
- }
339
- if (url.includes('/api/taskforce/auth/session')) {
340
- return jsonResponse({
341
- authenticated: false,
342
- authRequiredForApi: false,
343
- betaAccess: true,
344
- userId: 'anonymous',
345
- email: '',
346
- workspaceId: 'workspace-local-active'
347
- });
348
- }
349
- if (url.includes('/api/taskforce/ui-state?key=app'))
350
- return jsonResponse({ success: true, state: {} });
351
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
352
- return jsonResponse({ success: true, state: { version: 2, enabled: false, phase: 'idle', pullCursor: null } });
353
- }
354
- if (url.includes('/api/taskforce/config')) {
355
- return jsonResponse({
356
- projectName: 'Test Project',
357
- workspaceId: 'workspace-local-active',
358
- runtimeMode: 'local',
359
- setupState: {
360
- globalSetupState: 'complete',
361
- workspaceSetupState: 'complete',
362
- workspaceId: 'workspace-local-active'
363
- }
364
- });
365
- }
366
- if (url.includes('/api/taskforce/global-settings'))
367
- return jsonResponse({});
368
- if (url.includes('/api/taskforce/categories'))
369
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
370
- if (url.includes('/api/taskforce/types'))
371
- return jsonResponse({ types: [] });
372
- if (url.includes('/api/taskforce/priorities'))
373
- return jsonResponse({ priorities: [] });
374
- if (url.includes('/api/taskforce/approaches'))
375
- return jsonResponse({ approaches: [] });
376
- if (url.includes('/api/taskforce/specialists'))
377
- return jsonResponse({ specialists: [] });
378
- if (url.includes('/api/taskforce/tasks'))
379
- return jsonResponse({ tasks: [activeTask] });
380
- if (url.includes('/api/taskforce/archive'))
381
- return jsonResponse({ archived: [] });
382
- if (url.includes('/api/taskforce/planning/bootstrap'))
383
- return jsonResponse({ error: 'missing' }, 404);
384
- if (url.includes('/api/taskforce/initiatives'))
385
- return jsonResponse([initiative]);
386
- if (url.includes('/api/taskforce/workstreams'))
387
- return jsonResponse([workstream]);
388
- if (url.includes('/api/taskforce/data-version'))
389
- return jsonResponse({ dataVersion: 1 });
390
- return jsonResponse({});
391
- }));
392
- const { result } = renderHook(() => useTaskforce({ config: {} }), { wrapper });
393
- await waitFor(() => {
394
- expect(result.current.tasks.some((task) => task.id === activeTask.id)).toBe(true);
395
- });
396
- await waitFor(() => {
397
- expect(result.current.initiatives.some((item) => item.id === initiative.id)).toBe(true);
398
- expect(result.current.workstreams.some((item) => item.id === workstream.id)).toBe(true);
399
- }, { timeout: 3000 });
400
- });
401
- it('retries planning bootstrap after a transient startup failure', async () => {
402
- const initiative = {
403
- id: 'initiative-retry-1',
404
- title: 'Retry initiative',
405
- description: null,
406
- createdAt: '2026-03-15T10:00:00.000Z',
407
- };
408
- const workstream = {
409
- id: 'workstream-retry-1',
410
- title: 'Retry workstream',
411
- description: null,
412
- initiativeId: initiative.id,
413
- createdAt: '2026-03-15T10:05:00.000Z',
414
- };
415
- let planningBootstrapCalls = 0;
416
- vi.stubGlobal('fetch', vi.fn((url) => {
417
- if (url.includes('/api/taskforce/auth/runtime-config')) {
418
- return jsonResponse({ config: { runtimeMode: 'local', workspaceMode: 'single-local', authSource: 'cloud' } });
419
- }
420
- if (url.includes('/api/taskforce/auth/session')) {
421
- return jsonResponse({
422
- authenticated: false,
423
- authRequiredForApi: false,
424
- betaAccess: true,
425
- userId: 'anonymous',
426
- email: '',
427
- workspaceId: 'workspace-local-active'
428
- });
429
- }
430
- if (url.includes('/api/taskforce/ui-state?key=app'))
431
- return jsonResponse({ success: true, state: {} });
432
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
433
- return jsonResponse({ success: true, state: { version: 2, enabled: false, phase: 'idle', pullCursor: null } });
434
- }
435
- if (url.includes('/api/taskforce/config')) {
436
- return jsonResponse({
437
- projectName: 'Test Project',
438
- workspaceId: 'workspace-local-active',
439
- runtimeMode: 'local',
440
- setupState: {
441
- globalSetupState: 'complete',
442
- workspaceSetupState: 'complete',
443
- workspaceId: 'workspace-local-active'
444
- }
445
- });
446
- }
447
- if (url.includes('/api/taskforce/global-settings'))
448
- return jsonResponse({});
449
- if (url.includes('/api/taskforce/categories'))
450
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
451
- if (url.includes('/api/taskforce/types'))
452
- return jsonResponse({ types: [] });
453
- if (url.includes('/api/taskforce/priorities'))
454
- return jsonResponse({ priorities: [] });
455
- if (url.includes('/api/taskforce/approaches'))
456
- return jsonResponse({ approaches: [] });
457
- if (url.includes('/api/taskforce/specialists'))
458
- return jsonResponse({ specialists: [] });
459
- if (url.includes('/api/taskforce/tasks'))
460
- return jsonResponse({ tasks: [activeTask] });
461
- if (url.includes('/api/taskforce/archive'))
462
- return jsonResponse({ archived: [] });
463
- if (url.includes('/api/taskforce/planning/bootstrap')) {
464
- planningBootstrapCalls += 1;
465
- if (planningBootstrapCalls === 1) {
466
- return Promise.reject(new Error('temporary failure'));
467
- }
468
- return jsonResponse({
469
- initiatives: [initiative],
470
- workstreams: [workstream],
471
- workstreamTaskSummaries: [],
472
- });
473
- }
474
- if (url.includes('/api/taskforce/data-version'))
475
- return jsonResponse({ dataVersion: 1 });
476
- return jsonResponse({});
477
- }));
478
- const { result } = renderHook(() => useTaskforce({ config: {} }), { wrapper });
479
- await waitFor(() => {
480
- expect(planningBootstrapCalls).toBeGreaterThanOrEqual(1);
481
- });
482
- await waitFor(() => {
483
- expect(result.current.tasks.some((task) => task.id === activeTask.id)).toBe(true);
484
- });
485
- await waitFor(() => {
486
- expect(result.current.initiatives.some((item) => item.id === initiative.id)).toBe(true);
487
- expect(result.current.workstreams.some((item) => item.id === workstream.id)).toBe(true);
488
- }, { timeout: 7000 });
489
- }, 10000);
490
- it('retries a timed-out planning bootstrap without falling back to legacy endpoints during startup', async () => {
491
- const initiative = {
492
- id: 'initiative-timeout-1',
493
- title: 'Timeout initiative',
494
- description: null,
495
- createdAt: '2026-03-15T10:00:00.000Z',
496
- };
497
- const workstream = {
498
- id: 'workstream-timeout-1',
499
- title: 'Timeout workstream',
500
- description: null,
501
- initiativeId: initiative.id,
502
- createdAt: '2026-03-15T10:05:00.000Z',
503
- };
504
- let planningBootstrapCalls = 0;
505
- let initiativesCalls = 0;
506
- let workstreamsCalls = 0;
507
- vi.stubGlobal('fetch', vi.fn((url) => {
508
- if (url.includes('/api/taskforce/auth/runtime-config')) {
509
- return jsonResponse({ config: { runtimeMode: 'local', workspaceMode: 'single-local', authSource: 'cloud' } });
510
- }
511
- if (url.includes('/api/taskforce/auth/session')) {
512
- return jsonResponse({
513
- authenticated: false,
514
- authRequiredForApi: false,
515
- betaAccess: true,
516
- userId: 'anonymous',
517
- email: '',
518
- workspaceId: 'workspace-local-active'
519
- });
520
- }
521
- if (url.includes('/api/taskforce/ui-state?key=app'))
522
- return jsonResponse({ success: true, state: {} });
523
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
524
- return jsonResponse({ success: true, state: { version: 2, enabled: false, phase: 'idle', pullCursor: null } });
525
- }
526
- if (url.includes('/api/taskforce/config')) {
527
- return jsonResponse({
528
- projectName: 'Test Project',
529
- workspaceId: 'workspace-local-active',
530
- runtimeMode: 'local',
531
- setupState: {
532
- globalSetupState: 'complete',
533
- workspaceSetupState: 'complete',
534
- workspaceId: 'workspace-local-active'
535
- }
536
- });
537
- }
538
- if (url.includes('/api/taskforce/global-settings'))
539
- return jsonResponse({});
540
- if (url.includes('/api/taskforce/categories'))
541
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
542
- if (url.includes('/api/taskforce/types'))
543
- return jsonResponse({ types: [] });
544
- if (url.includes('/api/taskforce/priorities'))
545
- return jsonResponse({ priorities: [] });
546
- if (url.includes('/api/taskforce/approaches'))
547
- return jsonResponse({ approaches: [] });
548
- if (url.includes('/api/taskforce/specialists'))
549
- return jsonResponse({ specialists: [] });
550
- if (url.includes('/api/taskforce/tasks'))
551
- return jsonResponse({ tasks: [activeTask] });
552
- if (url.includes('/api/taskforce/archive'))
553
- return jsonResponse({ archived: [] });
554
- if (url.includes('/api/taskforce/planning/bootstrap')) {
555
- planningBootstrapCalls += 1;
556
- if (planningBootstrapCalls === 1) {
557
- return Promise.reject(new DOMException('timed out', 'AbortError'));
558
- }
559
- return jsonResponse({
560
- initiatives: [initiative],
561
- workstreams: [workstream],
562
- workstreamTaskSummaries: [],
563
- });
564
- }
565
- if (url.includes('/api/taskforce/initiatives')) {
566
- initiativesCalls += 1;
567
- return jsonResponse([initiative]);
568
- }
569
- if (url.includes('/api/taskforce/workstreams')) {
570
- workstreamsCalls += 1;
571
- return jsonResponse([workstream]);
572
- }
573
- if (url.includes('/api/taskforce/data-version'))
574
- return jsonResponse({ dataVersion: 1 });
575
- return jsonResponse({});
576
- }));
577
- const { result } = renderHook(() => useTaskforce({ config: {} }), { wrapper });
578
- await waitFor(() => {
579
- expect(result.current.tasks.some((task) => task.id === activeTask.id)).toBe(true);
580
- });
581
- await waitFor(() => {
582
- expect(result.current.initiatives.some((item) => item.id === initiative.id)).toBe(true);
583
- expect(result.current.workstreams.some((item) => item.id === workstream.id)).toBe(true);
584
- }, { timeout: 7000 });
585
- expect(planningBootstrapCalls).toBeGreaterThanOrEqual(2);
586
- expect(initiativesCalls).toBe(0);
587
- expect(workstreamsCalls).toBe(0);
588
- }, 10000);
589
- it('does not block cloud bootstrap readiness on a slow planning bootstrap response', async () => {
590
- const delayedPlanningResponseMs = 1500;
591
- vi.stubGlobal('fetch', vi.fn((url) => {
592
- if (url.includes('/api/taskforce/auth/runtime-config')) {
593
- return jsonResponse({
594
- config: {
595
- runtimeMode: 'cloud',
596
- workspaceMode: 'single-cloud',
597
- authSource: 'cloud',
598
- workspaceSwitchingEnabled: false
599
- }
600
- });
601
- }
602
- if (url.includes('/api/taskforce/auth/session')) {
603
- return jsonResponse({
604
- authenticated: true,
605
- authRequiredForApi: true,
606
- betaAccess: true,
607
- userId: 'user-1',
608
- email: 'user@example.com',
609
- workspaceId: 'workspace-cloud-1'
610
- });
611
- }
612
- if (url.includes('/api/taskforce/ui-state?key=app'))
613
- return jsonResponse({ success: true, state: {} });
614
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
615
- return jsonResponse({
616
- success: true,
617
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
618
- });
619
- }
620
- if (url.includes('/api/taskforce/config')) {
621
- return jsonResponse({
622
- projectName: 'Cloud Project',
623
- workspaceId: 'workspace-cloud-1',
624
- runtimeMode: 'cloud',
625
- authRequiredForApi: true,
626
- userId: 'user-1',
627
- setupState: {
628
- globalSetupState: 'complete',
629
- workspaceSetupState: 'complete',
630
- workspaceId: 'workspace-cloud-1'
631
- }
632
- });
633
- }
634
- if (url.includes('/api/taskforce/taxonomy-state')) {
635
- return jsonResponse({
636
- categories: [{ value: 'general', label: 'General' }],
637
- types: [{ value: 'feature', label: 'Feature' }],
638
- priorities: [{ value: 2, label: 'Medium' }],
639
- taxonomies: []
640
- });
641
- }
642
- if (url.includes('/api/taskforce/global-settings'))
643
- return jsonResponse({});
644
- if (url.includes('/api/taskforce/workspace/assignee-options'))
645
- return jsonResponse({ assignees: [] });
646
- if (url.includes('/api/taskforce/auth/workspace-members'))
647
- return jsonResponse({ users: [] });
648
- if (url.includes('/api/taskforce/planning/bootstrap')) {
649
- return new Promise((resolve) => {
650
- setTimeout(() => {
651
- resolve({
652
- ok: true,
653
- status: 200,
654
- json: () => Promise.resolve({
655
- initiatives: [{
656
- id: 'initiative-slow-1',
657
- title: 'Slow initiative',
658
- description: null,
659
- createdAt: '2026-03-15T10:00:00.000Z',
660
- }],
661
- workstreams: [],
662
- workstreamTaskSummaries: []
663
- })
664
- });
665
- }, delayedPlanningResponseMs);
666
- });
667
- }
668
- if (url.includes('/api/taskforce/tasks'))
669
- return jsonResponse({ tasks: [activeTask] });
670
- if (url.includes('/api/taskforce/archive'))
671
- return jsonResponse({ archived: [] });
672
- if (url.includes('/api/taskforce/data-version'))
673
- return jsonResponse({ dataVersion: 1 });
674
- if (url.includes('/api/taskforce/build-info'))
675
- return jsonResponse({});
676
- return jsonResponse({});
677
- }));
678
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
679
- await waitFor(() => {
680
- expect(result.current.tasks.some((task) => task.id === activeTask.id)).toBe(true);
681
- expect(result.current.bootstrapState.pending).toBe(false);
682
- expect(result.current.bootstrapState.ready).toBe(true);
683
- }, { timeout: 700 });
684
- expect(result.current.initiatives).toEqual([]);
685
- await waitFor(() => {
686
- expect(result.current.initiatives.some((initiative) => initiative.id === 'initiative-slow-1')).toBe(true);
687
- }, { timeout: 2500 });
688
- });
689
- it('loads cloud assignee options only once during initial bootstrap', async () => {
690
- let assigneeRequestCount = 0;
691
- vi.stubGlobal('fetch', vi.fn((url) => {
692
- if (url.includes('/api/taskforce/auth/runtime-config')) {
693
- return jsonResponse({
694
- config: {
695
- runtimeMode: 'cloud',
696
- workspaceMode: 'single-cloud',
697
- authSource: 'cloud',
698
- workspaceSwitchingEnabled: false
699
- }
700
- });
701
- }
702
- if (url.includes('/api/taskforce/auth/session')) {
703
- return jsonResponse({
704
- authenticated: true,
705
- authRequiredForApi: true,
706
- betaAccess: true,
707
- userId: 'user-1',
708
- email: 'user@example.com',
709
- workspaceId: 'workspace-cloud-1'
710
- });
711
- }
712
- if (url.includes('/api/taskforce/ui-state?key=app'))
713
- return jsonResponse({ success: true, state: {} });
714
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
715
- return jsonResponse({
716
- success: true,
717
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
718
- });
719
- }
720
- if (url.includes('/api/taskforce/config')) {
721
- return jsonResponse({
722
- projectName: 'Cloud Project',
723
- workspaceId: 'workspace-cloud-1',
724
- runtimeMode: 'cloud',
725
- authRequiredForApi: true,
726
- userId: 'user-1',
727
- setupState: {
728
- globalSetupState: 'complete',
729
- workspaceSetupState: 'complete',
730
- workspaceId: 'workspace-cloud-1'
731
- }
732
- });
733
- }
734
- if (url.includes('/api/taskforce/taxonomy-state')) {
735
- return jsonResponse({
736
- categories: [{ value: 'general', label: 'General' }],
737
- types: [{ value: 'feature', label: 'Feature' }],
738
- priorities: [{ value: 2, label: 'Medium' }],
739
- taxonomies: []
740
- });
741
- }
742
- if (url.includes('/api/taskforce/global-settings'))
743
- return jsonResponse({});
744
- if (url.includes('/api/taskforce/workspace/assignee-options')) {
745
- assigneeRequestCount += 1;
746
- return jsonResponse({ assignees: [] });
747
- }
748
- if (url.includes('/api/taskforce/auth/workspace-members'))
749
- return jsonResponse({ users: [] });
750
- if (url.includes('/api/taskforce/planning/bootstrap'))
751
- return jsonResponse({ initiatives: [], workstreams: [], workstreamTaskSummaries: [] });
752
- if (url.includes('/api/taskforce/tasks'))
753
- return jsonResponse({ tasks: [activeTask] });
754
- if (url.includes('/api/taskforce/archive'))
755
- return jsonResponse({ archived: [] });
756
- if (url.includes('/api/taskforce/data-version'))
757
- return jsonResponse({ dataVersion: 1 });
758
- if (url.includes('/api/taskforce/build-info'))
759
- return jsonResponse({});
760
- return jsonResponse({});
761
- }));
762
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
763
- await waitFor(() => {
764
- expect(result.current.tasks.some((task) => task.id === activeTask.id)).toBe(true);
765
- expect(result.current.bootstrapState.pending).toBe(false);
766
- expect(result.current.bootstrapState.ready).toBe(true);
767
- }, { timeout: 2500 });
768
- await waitFor(() => {
769
- expect(assigneeRequestCount).toBe(1);
770
- }, { timeout: 2500 });
771
- });
772
- it('keeps the dawn theme when settings re-fetch configuration', async () => {
773
- const fetchMock = vi.fn((url) => {
774
- if (url.includes('/api/taskforce/auth/runtime-config')) {
775
- return jsonResponse({ config: { runtimeMode: 'local', workspaceMode: 'single-local', authSource: 'cloud' } });
776
- }
777
- if (url.includes('/api/taskforce/auth/session')) {
778
- return jsonResponse({
779
- authenticated: false,
780
- authRequiredForApi: false,
781
- betaAccess: true,
782
- userId: 'anonymous',
783
- email: '',
784
- workspaceId: 'workspace-local-active'
785
- });
786
- }
787
- if (url.includes('/api/taskforce/ui-state?key=app')) {
788
- return jsonResponse({ success: true, state: {} });
789
- }
790
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
791
- return jsonResponse({
792
- success: true,
793
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
794
- });
795
- }
796
- if (url.includes('/api/taskforce/config')) {
797
- return jsonResponse({
798
- theme: 'dawn',
799
- globalTheme: 'dawn',
800
- themeUseGlobalDefault: true,
801
- projectName: 'Test Project',
802
- workspaceId: 'workspace-local-active',
803
- runtimeMode: 'local',
804
- setupState: {
805
- globalSetupState: 'complete',
806
- workspaceSetupState: 'complete',
807
- workspaceId: 'workspace-local-active'
808
- }
809
- });
810
- }
811
- if (url.includes('/api/taskforce/global-settings'))
812
- return jsonResponse({});
813
- if (url.includes('/api/taskforce/categories'))
814
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
815
- if (url.includes('/api/taskforce/types'))
816
- return jsonResponse({ types: [] });
817
- if (url.includes('/api/taskforce/priorities'))
818
- return jsonResponse({ priorities: [] });
819
- if (url.includes('/api/taskforce/approaches'))
820
- return jsonResponse({ approaches: [] });
821
- if (url.includes('/api/taskforce/specialists'))
822
- return jsonResponse({ specialists: [] });
823
- if (url.includes('/api/taskforce/tasks'))
824
- return jsonResponse({ tasks: [activeTask] });
825
- if (url.includes('/api/taskforce/archive'))
826
- return jsonResponse({ archived: [] });
827
- if (url.includes('/api/taskforce/data-version'))
828
- return jsonResponse({ dataVersion: 1 });
829
- return jsonResponse({});
830
- });
831
- vi.stubGlobal('fetch', fetchMock);
832
- const { result } = renderHook(() => useTaskforce({ config: {} }), { wrapper });
833
- await waitFor(() => {
834
- expect(result.current.currentTheme).toBe('dawn');
835
- });
836
- await act(async () => {
837
- result.current.setIsOpen(true);
838
- result.current.setActiveTab('settings');
839
- });
840
- await waitFor(() => {
841
- expect(fetchMock.mock.calls.filter(([url]) => String(url).includes('/api/taskforce/config'))).toHaveLength(2);
842
- expect(result.current.currentTheme).toBe('dawn');
843
- });
844
- });
845
- it('merges a server-returned archived task immediately instead of dropping it between collections', async () => {
846
- vi.stubGlobal('fetch', vi.fn((url, init) => {
847
- if (url.includes('/api/taskforce/auth/runtime-config')) {
848
- return jsonResponse({ config: { runtimeMode: 'local', workspaceMode: 'single-local', authSource: 'cloud' } });
849
- }
850
- if (url.includes('/api/taskforce/ui-state?key=app')) {
851
- return jsonResponse({ success: true, state: {} });
852
- }
853
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
854
- return jsonResponse({
855
- success: true,
856
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
857
- });
858
- }
859
- if (url.includes('/api/taskforce/config')) {
860
- return jsonResponse({
861
- projectName: 'Test Project',
862
- workspaceId: 'workspace-local-active',
863
- runtimeMode: 'local',
864
- setupState: {
865
- globalSetupState: 'complete',
866
- workspaceSetupState: 'complete',
867
- workspaceId: 'workspace-local-active'
868
- }
869
- });
870
- }
871
- if (url.includes('/api/taskforce/global-settings')) {
872
- return jsonResponse({});
873
- }
874
- if (url.includes('/api/taskforce/categories')) {
875
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
876
- }
877
- if (url.includes('/api/taskforce/types')) {
878
- return jsonResponse({ types: [] });
879
- }
880
- if (url.includes('/api/taskforce/priorities')) {
881
- return jsonResponse({ priorities: [] });
882
- }
883
- if (url.includes('/api/taskforce/approaches')) {
884
- return jsonResponse({ approaches: [] });
885
- }
886
- if (url.includes('/api/taskforce/specialists')) {
887
- return jsonResponse({ specialists: [] });
888
- }
889
- if (url.includes('/api/taskforce/tasks')) {
890
- return jsonResponse({ tasks: [activeTask] });
891
- }
892
- if (url.includes('/api/taskforce/archive')) {
893
- return jsonResponse({ archived: [] });
894
- }
895
- if (url.includes('/api/taskforce/task/task-parent/complete') && String(init?.method || '').toUpperCase() === 'POST') {
896
- return jsonResponse({
897
- ...activeTask,
898
- status: 'done',
899
- isArchived: true,
900
- completedAt: '2026-03-15T10:20:00.000Z',
901
- updatedAt: '2026-03-15T10:20:00.000Z'
902
- });
903
- }
904
- if (url.includes('/api/taskforce/data-version')) {
905
- return jsonResponse({ dataVersion: 1 });
906
- }
907
- return jsonResponse({});
908
- }));
909
- const { result } = renderHook(() => useTaskforce({ config: {} }), { wrapper });
910
- await waitFor(() => {
911
- expect(result.current.tasks.some((task) => task.id === 'task-parent')).toBe(true);
912
- });
913
- await act(async () => {
914
- await result.current.handleArchiveTask(activeTask);
915
- });
916
- await waitFor(() => {
917
- expect(result.current.tasks.some((task) => task.id === 'task-parent')).toBe(false);
918
- const archived = result.current.archivedTasks.find((task) => task.id === 'task-parent');
919
- expect(archived?.isArchived).toBe(true);
920
- expect(archived?.status).toBe('done');
921
- });
922
- });
923
- it('merges a server-returned completed task immediately when toggling done', async () => {
924
- vi.stubGlobal('fetch', vi.fn((url, init) => {
925
- if (url.includes('/api/taskforce/auth/runtime-config')) {
926
- return jsonResponse({ config: { runtimeMode: 'local', workspaceMode: 'single-local', authSource: 'cloud' } });
927
- }
928
- if (url.includes('/api/taskforce/ui-state?key=app')) {
929
- return jsonResponse({ success: true, state: {} });
930
- }
931
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
932
- return jsonResponse({
933
- success: true,
934
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
935
- });
936
- }
937
- if (url.includes('/api/taskforce/config')) {
938
- return jsonResponse({
939
- projectName: 'Test Project',
940
- workspaceId: 'workspace-local-active',
941
- runtimeMode: 'local',
942
- setupState: {
943
- globalSetupState: 'complete',
944
- workspaceSetupState: 'complete',
945
- workspaceId: 'workspace-local-active'
946
- }
947
- });
948
- }
949
- if (url.includes('/api/taskforce/global-settings')) {
950
- return jsonResponse({});
951
- }
952
- if (url.includes('/api/taskforce/categories')) {
953
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
954
- }
955
- if (url.includes('/api/taskforce/types')) {
956
- return jsonResponse({ types: [] });
957
- }
958
- if (url.includes('/api/taskforce/priorities')) {
959
- return jsonResponse({ priorities: [] });
960
- }
961
- if (url.includes('/api/taskforce/approaches')) {
962
- return jsonResponse({ approaches: [] });
963
- }
964
- if (url.includes('/api/taskforce/specialists')) {
965
- return jsonResponse({ specialists: [] });
966
- }
967
- if (url.includes('/api/taskforce/tasks')) {
968
- return jsonResponse({ tasks: [activeTask] });
969
- }
970
- if (url.includes('/api/taskforce/archive')) {
971
- return jsonResponse({ archived: [] });
972
- }
973
- if (url.includes('/api/taskforce/task/task-parent') && String(init?.method || '').toUpperCase() === 'PATCH') {
974
- return jsonResponse({
975
- ...activeTask,
976
- status: 'done',
977
- completedAt: '2026-03-15T10:25:00.000Z',
978
- updatedAt: '2026-03-15T10:25:00.000Z'
979
- });
980
- }
981
- if (url.includes('/api/taskforce/data-version')) {
982
- return jsonResponse({ dataVersion: 1 });
983
- }
984
- return jsonResponse({});
985
- }));
986
- const { result } = renderHook(() => useTaskforce({ config: {} }), { wrapper });
987
- await waitFor(() => {
988
- expect(result.current.tasks.some((task) => task.id === 'task-parent')).toBe(true);
989
- });
990
- await act(async () => {
991
- await result.current.handleToggleComplete(activeTask);
992
- });
993
- await waitFor(() => {
994
- const completed = result.current.tasks.find((task) => task.id === 'task-parent');
995
- expect(completed?.status).toBe('done');
996
- expect(completed?.completedAt).toBe('2026-03-15T10:25:00.000Z');
997
- });
998
- });
999
- it('merges bulk-archived tasks immediately instead of relying on archive refresh timing', async () => {
1000
- vi.stubGlobal('confirm', vi.fn(() => true));
1001
- vi.stubGlobal('fetch', vi.fn((url, init) => {
1002
- if (url.includes('/api/taskforce/auth/runtime-config')) {
1003
- return jsonResponse({ config: { runtimeMode: 'local', workspaceMode: 'single-local', authSource: 'cloud' } });
1004
- }
1005
- if (url.includes('/api/taskforce/ui-state?key=app')) {
1006
- return jsonResponse({ success: true, state: {} });
1007
- }
1008
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
1009
- return jsonResponse({
1010
- success: true,
1011
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
1012
- });
1013
- }
1014
- if (url.includes('/api/taskforce/config')) {
1015
- return jsonResponse({
1016
- projectName: 'Test Project',
1017
- workspaceId: 'workspace-local-active',
1018
- runtimeMode: 'local',
1019
- setupState: {
1020
- globalSetupState: 'complete',
1021
- workspaceSetupState: 'complete',
1022
- workspaceId: 'workspace-local-active'
1023
- }
1024
- });
1025
- }
1026
- if (url.includes('/api/taskforce/global-settings')) {
1027
- return jsonResponse({});
1028
- }
1029
- if (url.includes('/api/taskforce/categories')) {
1030
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
1031
- }
1032
- if (url.includes('/api/taskforce/types')) {
1033
- return jsonResponse({ types: [] });
1034
- }
1035
- if (url.includes('/api/taskforce/priorities')) {
1036
- return jsonResponse({ priorities: [] });
1037
- }
1038
- if (url.includes('/api/taskforce/approaches')) {
1039
- return jsonResponse({ approaches: [] });
1040
- }
1041
- if (url.includes('/api/taskforce/specialists')) {
1042
- return jsonResponse({ specialists: [] });
1043
- }
1044
- if (url.includes('/api/taskforce/tasks')) {
1045
- return jsonResponse({ tasks: [activeTask, doneTask] });
1046
- }
1047
- if (url.includes('/api/taskforce/archive')) {
1048
- return jsonResponse({ archived: [] });
1049
- }
1050
- if (url.includes('/api/taskforce/bulk-archive') && String(init?.method || '').toUpperCase() === 'POST') {
1051
- return jsonResponse({
1052
- success: true,
1053
- results: {
1054
- archived: [
1055
- {
1056
- ...doneTask,
1057
- isArchived: true
1058
- }
1059
- ]
1060
- },
1061
- errors: []
1062
- });
1063
- }
1064
- if (url.includes('/api/taskforce/data-version')) {
1065
- return jsonResponse({ dataVersion: 1 });
1066
- }
1067
- return jsonResponse({});
1068
- }));
1069
- const { result } = renderHook(() => useTaskforce({ config: {} }), { wrapper });
1070
- await waitFor(() => {
1071
- expect(result.current.tasks.some((task) => task.id === 'task-done')).toBe(true);
1072
- });
1073
- await act(async () => {
1074
- await result.current.handleBulkArchive();
1075
- });
1076
- await waitFor(() => {
1077
- expect(result.current.tasks.some((task) => task.id === 'task-done')).toBe(false);
1078
- const archived = result.current.archivedTasks.find((task) => task.id === 'task-done');
1079
- expect(archived?.isArchived).toBe(true);
1080
- expect(archived?.status).toBe('done');
1081
- });
1082
- });
1083
- it('preserves an explicit local api base url instead of letting runtime-config reset it to the app origin', async () => {
1084
- vi.stubGlobal('fetch', vi.fn((url) => {
1085
- if (url.includes('/api/taskforce/auth/runtime-config')) {
1086
- return jsonResponse({
1087
- config: {
1088
- runtimeMode: 'local',
1089
- workspaceMode: 'single-local',
1090
- authSource: 'cloud',
1091
- baseUrl: 'http://localhost:5174',
1092
- apiBaseUrl: 'http://localhost:5174',
1093
- cloudAuthBaseUrl: 'http://localhost:5174'
1094
- }
1095
- });
1096
- }
1097
- if (url.includes('/api/taskforce/ui-state?key=app')) {
1098
- return jsonResponse({ success: true, state: {} });
1099
- }
1100
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
1101
- return jsonResponse({
1102
- success: true,
1103
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
1104
- });
1105
- }
1106
- if (url.includes('/api/taskforce/config')) {
1107
- return jsonResponse({
1108
- projectName: 'Test Project',
1109
- workspaceId: 'workspace-local-active',
1110
- runtimeMode: 'local',
1111
- setupState: {
1112
- globalSetupState: 'complete',
1113
- workspaceSetupState: 'complete',
1114
- workspaceId: 'workspace-local-active'
1115
- }
1116
- });
1117
- }
1118
- if (url.includes('/api/taskforce/global-settings')) {
1119
- return jsonResponse({});
1120
- }
1121
- if (url.includes('/api/taskforce/categories')) {
1122
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
1123
- }
1124
- if (url.includes('/api/taskforce/types')) {
1125
- return jsonResponse({ types: [] });
1126
- }
1127
- if (url.includes('/api/taskforce/priorities')) {
1128
- return jsonResponse({ priorities: [] });
1129
- }
1130
- if (url.includes('/api/taskforce/approaches')) {
1131
- return jsonResponse({ approaches: [] });
1132
- }
1133
- if (url.includes('/api/taskforce/specialists')) {
1134
- return jsonResponse({ specialists: [] });
1135
- }
1136
- if (url.includes('/api/taskforce/tasks')) {
1137
- return jsonResponse({ tasks: [activeTask] });
1138
- }
1139
- if (url.includes('/api/taskforce/archive')) {
1140
- return jsonResponse({ archived: [] });
1141
- }
1142
- if (url.includes('/api/taskforce/data-version')) {
1143
- return jsonResponse({ dataVersion: 1 });
1144
- }
1145
- return jsonResponse({});
1146
- }));
1147
- const { result } = renderHook(() => useTaskforce({ config: { apiBaseUrl: 'http://127.0.0.1:4280' } }), { wrapper });
1148
- await waitFor(() => {
1149
- expect(result.current.config.apiBaseUrl).toBe('http://127.0.0.1:4280');
1150
- });
1151
- });
1152
- it('opens archived tasks by id and enables archive view', async () => {
1153
- vi.stubGlobal('WebSocket', MockWebSocket);
1154
- const archivedChildren = [
1155
- archivedTaskRecord('task-archived-child-1', 'Archived Task 1')
1156
- ];
1157
- vi.stubGlobal('fetch', vi.fn((url) => {
1158
- if (url.includes('/api/taskforce/auth/runtime-config')) {
1159
- return jsonResponse({
1160
- config: {
1161
- runtimeMode: 'cloud',
1162
- workspaceMode: 'multi-cloud',
1163
- authSource: 'cloud',
1164
- workspaceSwitchingEnabled: true
1165
- }
1166
- });
1167
- }
1168
- if (url.includes('/api/taskforce/auth/session')) {
1169
- return jsonResponse({
1170
- authenticated: true,
1171
- authRequiredForApi: true,
1172
- betaAccess: true,
1173
- userId: 'user-1',
1174
- email: 'user@example.com',
1175
- workspaceId: 'workspace-cloud-1'
1176
- });
1177
- }
1178
- if (url.includes('/api/taskforce/ui-state?key=app')) {
1179
- return jsonResponse({ success: true, state: {} });
1180
- }
1181
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
1182
- return jsonResponse({
1183
- success: true,
1184
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
1185
- });
1186
- }
1187
- if (url.includes('/api/taskforce/config')) {
1188
- return jsonResponse({
1189
- projectName: 'Cloud Project',
1190
- workspaceId: 'workspace-cloud-1',
1191
- runtimeMode: 'cloud',
1192
- authRequiredForApi: true,
1193
- realtimeSyncEnabled: true,
1194
- userId: 'user-1',
1195
- setupState: {
1196
- globalSetupState: 'complete',
1197
- workspaceSetupState: 'complete',
1198
- workspaceId: 'workspace-cloud-1'
1199
- }
1200
- });
1201
- }
1202
- if (url.includes('/api/taskforce/global-settings'))
1203
- return jsonResponse({});
1204
- if (url.includes('/api/taskforce/categories'))
1205
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
1206
- if (url.includes('/api/taskforce/types'))
1207
- return jsonResponse({ types: [] });
1208
- if (url.includes('/api/taskforce/priorities'))
1209
- return jsonResponse({ priorities: [] });
1210
- if (url.includes('/api/taskforce/approaches'))
1211
- return jsonResponse({ approaches: [] });
1212
- if (url.includes('/api/taskforce/specialists'))
1213
- return jsonResponse({ specialists: [] });
1214
- if (url.includes('/api/taskforce/tasks'))
1215
- return jsonResponse({ tasks: [activeTask] });
1216
- if (url.includes('/api/taskforce/archive'))
1217
- return jsonResponse({ archived: archivedChildren });
1218
- if (url.includes('/api/taskforce/data-version'))
1219
- return jsonResponse({ dataVersion: 1 });
1220
- return jsonResponse({});
1221
- }));
1222
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
1223
- await waitFor(() => {
1224
- expect(result.current.archivedTasks.some((task) => task.id === 'task-archived-child-1')).toBe(true);
1225
- }, { timeout: 2500 });
1226
- act(() => {
1227
- result.current.handleOpenTaskById('task-archived-child-1');
1228
- });
1229
- await waitFor(() => {
1230
- expect(result.current.showArchive).toBe(true);
1231
- expect(result.current.editingTaskId).toBe('task-archived-child-1');
1232
- expect(result.current.currentTask?.isArchived).toBe(true);
1233
- });
1234
- });
1235
- it('hydrates cloud taxonomy filters when commercial onboarding continues into the app', async () => {
1236
- let configResolved = false;
1237
- let allowResolvedTaxonomyState = false;
1238
- vi.stubGlobal('fetch', vi.fn((url, init) => {
1239
- if (url.includes('/api/taskforce/auth/runtime-config')) {
1240
- return jsonResponse({
1241
- config: {
1242
- runtimeMode: 'cloud',
1243
- workspaceMode: 'multi-cloud',
1244
- authSource: 'cloud',
1245
- workspaceSwitchingEnabled: true
1246
- }
1247
- });
1248
- }
1249
- if (url.includes('/api/taskforce/auth/session')) {
1250
- return jsonResponse({
1251
- authenticated: true,
1252
- authRequiredForApi: true,
1253
- betaAccess: true,
1254
- userId: 'user-1',
1255
- email: 'user@example.com',
1256
- workspaceId: 'workspace-cloud-1'
1257
- });
1258
- }
1259
- if (url.includes('/api/taskforce/ui-state?key=app')) {
1260
- return jsonResponse({ success: true, state: {} });
1261
- }
1262
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
1263
- return jsonResponse({
1264
- success: true,
1265
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
1266
- });
1267
- }
1268
- if (url.includes('/api/taskforce/workspaces')) {
1269
- if (String(init?.method || 'GET').toUpperCase() === 'POST') {
1270
- return jsonResponse({ success: true });
1271
- }
1272
- return jsonResponse({
1273
- success: true,
1274
- currentWorkspaceId: 'workspace-cloud-1',
1275
- workspaces: [
1276
- { id: 'workspace-cloud-1', name: 'Cloud Workspace', role: 'owner' }
1277
- ]
1278
- });
1279
- }
1280
- if (url.includes('/api/taskforce/session/workspace')) {
1281
- return jsonResponse({ success: true });
1282
- }
1283
- if (url.includes('/api/taskforce/config')) {
1284
- return new Promise((resolve) => {
1285
- setTimeout(() => {
1286
- configResolved = true;
1287
- resolve({
1288
- ok: true,
1289
- status: 200,
1290
- json: () => Promise.resolve({
1291
- projectName: 'Cloud Project',
1292
- workspaceId: 'workspace-cloud-1',
1293
- runtimeMode: 'cloud',
1294
- authRequiredForApi: true,
1295
- userId: 'user-1',
1296
- setupState: {
1297
- globalSetupState: 'complete',
1298
- workspaceSetupState: 'complete',
1299
- workspaceId: 'workspace-cloud-1'
1300
- }
1301
- })
1302
- });
1303
- }, 25);
1304
- });
1305
- }
1306
- if (url.includes('/api/taskforce/taxonomy-state')) {
1307
- return jsonResponse(configResolved && allowResolvedTaxonomyState ? {
1308
- categories: [{ value: 'cloud-ops', label: 'Cloud Ops' }],
1309
- types: [{ value: 'incident', label: 'Incident' }],
1310
- priorities: [{ value: 4, label: 'Critical' }],
1311
- taxonomies: []
1312
- } : {
1313
- categories: [],
1314
- types: [],
1315
- priorities: [],
1316
- taxonomies: []
1317
- });
1318
- }
1319
- if (url.includes('/api/taskforce/global-settings'))
1320
- return jsonResponse({});
1321
- if (url.includes('/api/taskforce/workspace/assignee-options'))
1322
- return jsonResponse({ assignees: [] });
1323
- if (url.includes('/api/taskforce/auth/workspace-members'))
1324
- return jsonResponse({ users: [] });
1325
- if (url.includes('/api/taskforce/planning/bootstrap'))
1326
- return jsonResponse({ initiatives: [], workstreams: [], workstreamTaskSummaries: [] });
1327
- if (url.includes('/api/taskforce/tasks'))
1328
- return jsonResponse({ tasks: [activeTask] });
1329
- if (url.includes('/api/taskforce/archive'))
1330
- return jsonResponse({ archived: [] });
1331
- if (url.includes('/api/taskforce/data-version'))
1332
- return jsonResponse({ dataVersion: 1 });
1333
- if (url.includes('/api/taskforce/build-info'))
1334
- return jsonResponse({});
1335
- return jsonResponse({});
1336
- }));
1337
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
1338
- await waitFor(() => {
1339
- expect(result.current.authSessionResolved).toBe(true);
1340
- expect(result.current.isAuthenticated).toBe(true);
1341
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
1342
- }, { timeout: 2500 });
1343
- expect(result.current.activeCategories.some((category) => category.value === 'cloud-ops')).toBe(false);
1344
- allowResolvedTaxonomyState = true;
1345
- await act(async () => {
1346
- const outcome = await result.current.continueAfterCommercialOnboarding();
1347
- expect(outcome).toEqual({ success: true, destination: 'app' });
1348
- });
1349
- await waitFor(() => {
1350
- expect(result.current.activeCategories.some((category) => category.value === 'cloud-ops')).toBe(true);
1351
- expect(result.current.activeTypes.some((type) => type.value === 'incident')).toBe(true);
1352
- expect(result.current.priorities.some((priority) => priority.value === 4)).toBe(true);
1353
- }, { timeout: 2500 });
1354
- });
1355
- it('uses unified taxonomy-state payloads without falling back to category endpoints during cloud bootstrap', async () => {
1356
- const fetchMock = vi.fn((url, init) => {
1357
- if (url.includes('/api/taskforce/auth/runtime-config')) {
1358
- return jsonResponse({
1359
- config: {
1360
- runtimeMode: 'cloud',
1361
- workspaceMode: 'multi-cloud',
1362
- authSource: 'cloud',
1363
- workspaceSwitchingEnabled: true
1364
- }
1365
- });
1366
- }
1367
- if (url.includes('/api/taskforce/auth/session')) {
1368
- return jsonResponse({
1369
- authenticated: true,
1370
- authRequiredForApi: true,
1371
- betaAccess: true,
1372
- userId: 'user-1',
1373
- email: 'user@example.com',
1374
- workspaceId: 'workspace-cloud-1'
1375
- });
1376
- }
1377
- if (url.includes('/api/taskforce/ui-state?key=app'))
1378
- return jsonResponse({ success: true, state: {} });
1379
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
1380
- return jsonResponse({
1381
- success: true,
1382
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
1383
- });
1384
- }
1385
- if (url.includes('/api/taskforce/workspaces')) {
1386
- if (String(init?.method || 'GET').toUpperCase() === 'POST') {
1387
- return jsonResponse({ success: true });
1388
- }
1389
- return jsonResponse({
1390
- success: true,
1391
- currentWorkspaceId: 'workspace-cloud-1',
1392
- workspaces: [{ id: 'workspace-cloud-1', name: 'Cloud Workspace', role: 'owner' }]
1393
- });
1394
- }
1395
- if (url.includes('/api/taskforce/session/workspace'))
1396
- return jsonResponse({ success: true });
1397
- if (url.includes('/api/taskforce/config')) {
1398
- return jsonResponse({
1399
- projectName: 'Cloud Project',
1400
- workspaceId: 'workspace-cloud-1',
1401
- runtimeMode: 'cloud',
1402
- authRequiredForApi: true,
1403
- userId: 'user-1',
1404
- setupState: {
1405
- globalSetupState: 'complete',
1406
- workspaceSetupState: 'complete',
1407
- workspaceId: 'workspace-cloud-1'
1408
- }
1409
- });
1410
- }
1411
- if (url.includes('/api/taskforce/taxonomy-state')) {
1412
- return jsonResponse({
1413
- categories: [{ value: 'cloud-ops', label: 'Cloud Ops' }],
1414
- types: [{ value: 'incident', label: 'Incident' }],
1415
- priorities: [{ value: 4, label: 'Critical' }],
1416
- taxonomies: []
1417
- });
1418
- }
1419
- if (url.includes('/api/taskforce/global-settings'))
1420
- return jsonResponse({});
1421
- if (url.includes('/api/taskforce/workspace/assignee-options'))
1422
- return jsonResponse({ assignees: [] });
1423
- if (url.includes('/api/taskforce/auth/workspace-members'))
1424
- return jsonResponse({ users: [] });
1425
- if (url.includes('/api/taskforce/planning/bootstrap'))
1426
- return jsonResponse({ initiatives: [], workstreams: [], workstreamTaskSummaries: [] });
1427
- if (url.includes('/api/taskforce/tasks'))
1428
- return jsonResponse({ tasks: [activeTask] });
1429
- if (url.includes('/api/taskforce/archive'))
1430
- return jsonResponse({ archived: [] });
1431
- if (url.includes('/api/taskforce/data-version'))
1432
- return jsonResponse({ dataVersion: 1 });
1433
- if (url.includes('/api/taskforce/build-info'))
1434
- return jsonResponse({});
1435
- return jsonResponse({});
1436
- });
1437
- vi.stubGlobal('fetch', fetchMock);
1438
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
1439
- await waitFor(() => {
1440
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
1441
- expect(result.current.activeCategories.some((category) => category.value === 'cloud-ops')).toBe(true);
1442
- }, { timeout: 2500 });
1443
- expect(fetchMock.mock.calls.some(([url]) => String(url).includes('/api/taskforce/categories'))).toBe(false);
1444
- expect(fetchMock.mock.calls.some(([url]) => String(url).includes('/api/taskforce/types'))).toBe(false);
1445
- expect(fetchMock.mock.calls.some(([url]) => String(url).includes('/api/taskforce/priorities'))).toBe(false);
1446
- expect(fetchMock.mock.calls.some(([url]) => String(url).includes('/api/taskforce/taxonomies'))).toBe(false);
1447
- });
1448
- it('defers the initial cloud bootstrap on a real cloud host until auth resolves so taxonomy and planning data still load', async () => {
1449
- const windowProxy = new Proxy(window, {
1450
- get(target, prop, receiver) {
1451
- if (prop === 'location') {
1452
- return {
1453
- ...target.location,
1454
- hostname: 'app.taskforce.test'
1455
- };
1456
- }
1457
- return Reflect.get(target, prop, receiver);
1458
- }
1459
- });
1460
- vi.stubGlobal('window', windowProxy);
1461
- let runtimeConfigResolved = false;
1462
- let authSessionResolved = false;
1463
- const prematureProtectedCalls = [];
1464
- const fetchMock = vi.fn((url, init) => {
1465
- if (url.includes('/api/taskforce/auth/runtime-config')) {
1466
- return new Promise((resolve) => {
1467
- window.setTimeout(() => {
1468
- runtimeConfigResolved = true;
1469
- resolve({
1470
- ok: true,
1471
- status: 200,
1472
- json: () => Promise.resolve({
1473
- config: {
1474
- runtimeMode: 'cloud',
1475
- workspaceMode: 'multi-cloud',
1476
- authSource: 'cloud',
1477
- workspaceSwitchingEnabled: true
1478
- }
1479
- })
1480
- });
1481
- }, 20);
1482
- });
1483
- }
1484
- if (url.includes('/api/taskforce/auth/session')) {
1485
- return new Promise((resolve) => {
1486
- window.setTimeout(() => {
1487
- authSessionResolved = true;
1488
- resolve({
1489
- ok: true,
1490
- status: 200,
1491
- json: () => Promise.resolve({
1492
- authenticated: true,
1493
- authRequiredForApi: true,
1494
- betaAccess: true,
1495
- userId: 'user-1',
1496
- email: 'user@example.com',
1497
- workspaceId: 'workspace-cloud-1'
1498
- })
1499
- });
1500
- }, runtimeConfigResolved ? 20 : 40);
1501
- });
1502
- }
1503
- if ((url.includes('/api/taskforce/config')
1504
- || url.includes('/api/taskforce/taxonomy-state')
1505
- || url.includes('/api/taskforce/planning/bootstrap')
1506
- || url.includes('/api/taskforce/tasks'))
1507
- && !authSessionResolved) {
1508
- prematureProtectedCalls.push(url);
1509
- }
1510
- if (url.includes('/api/taskforce/ui-state?key=app'))
1511
- return jsonResponse({ success: true, state: {} });
1512
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
1513
- return jsonResponse({
1514
- success: true,
1515
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
1516
- });
1517
- }
1518
- if (url.includes('/api/taskforce/workspaces')) {
1519
- if (String(init?.method || 'GET').toUpperCase() === 'POST') {
1520
- return jsonResponse({ success: true });
1521
- }
1522
- return jsonResponse({
1523
- success: true,
1524
- currentWorkspaceId: 'workspace-cloud-1',
1525
- workspaces: [{ id: 'workspace-cloud-1', name: 'Cloud Workspace', role: 'owner' }]
1526
- });
1527
- }
1528
- if (url.includes('/api/taskforce/session/workspace'))
1529
- return jsonResponse({ success: true });
1530
- if (url.includes('/api/taskforce/config')) {
1531
- return jsonResponse({
1532
- projectName: 'Cloud Project',
1533
- workspaceId: 'workspace-cloud-1',
1534
- runtimeMode: 'cloud',
1535
- authRequiredForApi: true,
1536
- userId: 'user-1',
1537
- setupState: {
1538
- globalSetupState: 'complete',
1539
- workspaceSetupState: 'complete',
1540
- workspaceId: 'workspace-cloud-1'
1541
- }
1542
- });
1543
- }
1544
- if (url.includes('/api/taskforce/taxonomy-state')) {
1545
- return jsonResponse({
1546
- categories: [{ value: 'cloud-ops', label: 'Cloud Ops' }],
1547
- types: [{ value: 'incident', label: 'Incident' }],
1548
- priorities: [{ value: 4, label: 'Critical' }],
1549
- taxonomies: []
1550
- });
1551
- }
1552
- if (url.includes('/api/taskforce/global-settings'))
1553
- return jsonResponse({});
1554
- if (url.includes('/api/taskforce/workspace/assignee-options')) {
1555
- return jsonResponse({
1556
- assignees: [
1557
- { userId: 'member-1', email: 'member1@example.com', displayName: 'Member One', status: 'active', disabled: false },
1558
- { value: 'ai-profile-codex', label: 'Codex', icon: 'Bot', color: '#0ea5e9', kind: 'agent' }
1559
- ]
1560
- });
1561
- }
1562
- if (url.includes('/api/taskforce/auth/workspace-members')) {
1563
- return jsonResponse({
1564
- users: [
1565
- {
1566
- userId: 'user-1',
1567
- email: 'user@example.com',
1568
- displayName: 'Signed In Owner',
1569
- role: 'owner',
1570
- status: 'active',
1571
- disabled: false
1572
- },
1573
- {
1574
- userId: 'member-1',
1575
- email: 'member1@example.com',
1576
- displayName: 'Member One',
1577
- status: 'active',
1578
- disabled: false
1579
- }
1580
- ]
1581
- });
1582
- }
1583
- if (url.includes('/api/taskforce/planning/bootstrap')) {
1584
- return jsonResponse({
1585
- initiatives: [{
1586
- id: 'initiative-1',
1587
- title: 'Cloud Initiative',
1588
- description: '',
1589
- ownerId: null,
1590
- createdAt: '2026-03-15T10:00:00.000Z',
1591
- updatedAt: '2026-03-15T10:00:00.000Z',
1592
- referenceNumber: 5,
1593
- referenceLabel: 'IN-5',
1594
- isArchived: false,
1595
- comments: [],
1596
- attachments: []
1597
- }],
1598
- workstreams: [{
1599
- id: 'workstream-1',
1600
- title: 'Cloud Workstream',
1601
- description: '',
1602
- ownerId: null,
1603
- initiativeId: 'initiative-1',
1604
- createdAt: '2026-03-15T10:05:00.000Z',
1605
- updatedAt: '2026-03-15T10:05:00.000Z',
1606
- referenceNumber: 10,
1607
- referenceLabel: 'WS-10',
1608
- isArchived: false,
1609
- comments: [],
1610
- attachments: []
1611
- }],
1612
- workstreamTaskSummaries: []
1613
- });
1614
- }
1615
- if (url.includes('/api/taskforce/tasks'))
1616
- return jsonResponse({ tasks: [activeTask] });
1617
- if (url.includes('/api/taskforce/archive'))
1618
- return jsonResponse({ archived: [] });
1619
- if (url.includes('/api/taskforce/data-version'))
1620
- return jsonResponse({ dataVersion: 1 });
1621
- if (url.includes('/api/taskforce/build-info'))
1622
- return jsonResponse({});
1623
- return jsonResponse({});
1624
- });
1625
- vi.stubGlobal('fetch', fetchMock);
1626
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
1627
- await waitFor(() => {
1628
- expect(result.current.authSessionResolved).toBe(true);
1629
- expect(result.current.isAuthenticated).toBe(true);
1630
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
1631
- expect(result.current.activeCategories.some((category) => category.value === 'cloud-ops')).toBe(true);
1632
- expect(result.current.initiatives.some((initiative) => initiative.id === 'initiative-1')).toBe(true);
1633
- expect(result.current.workstreams.some((workstream) => workstream.id === 'workstream-1')).toBe(true);
1634
- expect(result.current.assigneeOptions.some((option) => option.value === 'member-1' && option.label === 'Member One')).toBe(true);
1635
- expect(result.current.assigneeOptions.some((option) => option.value === 'ai-profile-codex' && option.label === 'Codex')).toBe(true);
1636
- }, { timeout: 2500 });
1637
- expect(prematureProtectedCalls).toEqual([]);
1638
- });
1639
- it('falls back to category endpoints when taxonomy-state payload is unavailable during cloud bootstrap', async () => {
1640
- const fetchMock = vi.fn((url, init) => {
1641
- if (url.includes('/api/taskforce/auth/runtime-config')) {
1642
- return jsonResponse({
1643
- config: {
1644
- runtimeMode: 'cloud',
1645
- workspaceMode: 'multi-cloud',
1646
- authSource: 'cloud',
1647
- workspaceSwitchingEnabled: true
1648
- }
1649
- });
1650
- }
1651
- if (url.includes('/api/taskforce/auth/session')) {
1652
- return jsonResponse({
1653
- authenticated: true,
1654
- authRequiredForApi: true,
1655
- betaAccess: true,
1656
- userId: 'user-1',
1657
- email: 'user@example.com',
1658
- workspaceId: 'workspace-cloud-1'
1659
- });
1660
- }
1661
- if (url.includes('/api/taskforce/ui-state?key=app'))
1662
- return jsonResponse({ success: true, state: {} });
1663
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
1664
- return jsonResponse({
1665
- success: true,
1666
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
1667
- });
1668
- }
1669
- if (url.includes('/api/taskforce/workspaces')) {
1670
- if (String(init?.method || 'GET').toUpperCase() === 'POST') {
1671
- return jsonResponse({ success: true });
1672
- }
1673
- return jsonResponse({
1674
- success: true,
1675
- currentWorkspaceId: 'workspace-cloud-1',
1676
- workspaces: [{ id: 'workspace-cloud-1', name: 'Cloud Workspace', role: 'owner' }]
1677
- });
1678
- }
1679
- if (url.includes('/api/taskforce/session/workspace'))
1680
- return jsonResponse({ success: true });
1681
- if (url.includes('/api/taskforce/config')) {
1682
- return jsonResponse({
1683
- projectName: 'Cloud Project',
1684
- workspaceId: 'workspace-cloud-1',
1685
- runtimeMode: 'cloud',
1686
- authRequiredForApi: true,
1687
- userId: 'user-1',
1688
- setupState: {
1689
- globalSetupState: 'complete',
1690
- workspaceSetupState: 'complete',
1691
- workspaceId: 'workspace-cloud-1'
1692
- }
1693
- });
1694
- }
1695
- if (url.includes('/api/taskforce/taxonomy-state'))
1696
- return jsonResponse({});
1697
- if (url.includes('/api/taskforce/categories'))
1698
- return jsonResponse({ categories: [{ value: 'cloud-ops', label: 'Cloud Ops' }] });
1699
- if (url.includes('/api/taskforce/types'))
1700
- return jsonResponse({ types: [{ value: 'incident', label: 'Incident' }] });
1701
- if (url.includes('/api/taskforce/priorities'))
1702
- return jsonResponse({ priorities: [{ value: 4, label: 'Critical' }] });
1703
- if (url.includes('/api/taskforce/taxonomies'))
1704
- return jsonResponse({ taxonomies: [] });
1705
- if (url.includes('/api/taskforce/global-settings'))
1706
- return jsonResponse({});
1707
- if (url.includes('/api/taskforce/workspace/assignee-options'))
1708
- return jsonResponse({ assignees: [] });
1709
- if (url.includes('/api/taskforce/auth/workspace-members'))
1710
- return jsonResponse({ users: [] });
1711
- if (url.includes('/api/taskforce/planning/bootstrap'))
1712
- return jsonResponse({ initiatives: [], workstreams: [], workstreamTaskSummaries: [] });
1713
- if (url.includes('/api/taskforce/tasks'))
1714
- return jsonResponse({ tasks: [activeTask] });
1715
- if (url.includes('/api/taskforce/archive'))
1716
- return jsonResponse({ archived: [] });
1717
- if (url.includes('/api/taskforce/data-version'))
1718
- return jsonResponse({ dataVersion: 1 });
1719
- if (url.includes('/api/taskforce/build-info'))
1720
- return jsonResponse({});
1721
- return jsonResponse({});
1722
- });
1723
- vi.stubGlobal('fetch', fetchMock);
1724
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
1725
- await waitFor(() => {
1726
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
1727
- expect(result.current.activeCategories.some((category) => category.value === 'cloud-ops')).toBe(true);
1728
- expect(result.current.activeTypes.some((type) => type.value === 'incident')).toBe(true);
1729
- expect(result.current.priorities.some((priority) => priority.value === 4)).toBe(true);
1730
- }, { timeout: 2500 });
1731
- expect(fetchMock.mock.calls.some(([url]) => String(url).includes('/api/taskforce/categories'))).toBe(true);
1732
- expect(fetchMock.mock.calls.some(([url]) => String(url).includes('/api/taskforce/types'))).toBe(true);
1733
- expect(fetchMock.mock.calls.some(([url]) => String(url).includes('/api/taskforce/priorities'))).toBe(true);
1734
- expect(fetchMock.mock.calls.some(([url]) => String(url).includes('/api/taskforce/taxonomies'))).toBe(true);
1735
- });
1736
- it('rehydrates taxonomy state for the newly selected workspace after a cloud workspace switch', async () => {
1737
- let sessionWorkspaceId = 'workspace-cloud-1';
1738
- const fetchMock = vi.fn((url, init) => {
1739
- if (url.includes('/api/taskforce/auth/runtime-config')) {
1740
- return jsonResponse({
1741
- config: {
1742
- runtimeMode: 'cloud',
1743
- workspaceMode: 'multi-cloud',
1744
- authSource: 'cloud',
1745
- workspaceSwitchingEnabled: true
1746
- }
1747
- });
1748
- }
1749
- if (url.includes('/api/taskforce/auth/session')) {
1750
- return jsonResponse({
1751
- authenticated: true,
1752
- authRequiredForApi: true,
1753
- betaAccess: true,
1754
- userId: 'user-1',
1755
- email: 'user@example.com',
1756
- workspaceId: sessionWorkspaceId
1757
- });
1758
- }
1759
- if (url.includes('/api/taskforce/ui-state?key=app'))
1760
- return jsonResponse({ success: true, state: {} });
1761
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
1762
- return jsonResponse({
1763
- success: true,
1764
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
1765
- });
1766
- }
1767
- if (url.includes('/api/taskforce/workspaces')) {
1768
- if (String(init?.method || 'GET').toUpperCase() === 'POST') {
1769
- return jsonResponse({ success: true });
1770
- }
1771
- return jsonResponse({
1772
- success: true,
1773
- currentWorkspaceId: sessionWorkspaceId,
1774
- workspaces: [
1775
- { id: 'workspace-cloud-1', name: 'Cloud Workspace 1', role: 'owner' },
1776
- { id: 'workspace-cloud-2', name: 'Cloud Workspace 2', role: 'owner' }
1777
- ]
1778
- });
1779
- }
1780
- if (url.includes('/api/taskforce/session/workspace')) {
1781
- const body = JSON.parse(String(init?.body || '{}'));
1782
- sessionWorkspaceId = String(body.workspaceId || '').trim() || sessionWorkspaceId;
1783
- return jsonResponse({ success: true });
1784
- }
1785
- if (url.includes('/api/taskforce/config')) {
1786
- return jsonResponse({
1787
- projectName: sessionWorkspaceId === 'workspace-cloud-2' ? 'Cloud Project 2' : 'Cloud Project 1',
1788
- workspaceId: sessionWorkspaceId,
1789
- runtimeMode: 'cloud',
1790
- authRequiredForApi: true,
1791
- userId: 'user-1',
1792
- setupState: {
1793
- globalSetupState: 'complete',
1794
- workspaceSetupState: 'complete',
1795
- workspaceId: sessionWorkspaceId
1796
- }
1797
- });
1798
- }
1799
- if (url.includes('/api/taskforce/taxonomy-state')) {
1800
- if (sessionWorkspaceId === 'workspace-cloud-2') {
1801
- return jsonResponse({
1802
- categories: [{ value: 'workspace-two', label: 'Workspace Two' }],
1803
- types: [{ value: 'incident', label: 'Incident' }],
1804
- priorities: [{ value: 4, label: 'Critical' }],
1805
- taxonomies: []
1806
- });
1807
- }
1808
- return jsonResponse({
1809
- categories: [{ value: 'workspace-one', label: 'Workspace One' }],
1810
- types: [{ value: 'feature', label: 'Feature' }],
1811
- priorities: [{ value: 2, label: 'Medium' }],
1812
- taxonomies: []
1813
- });
1814
- }
1815
- if (url.includes('/api/taskforce/global-settings'))
1816
- return jsonResponse({});
1817
- if (url.includes('/api/taskforce/workspace/assignee-options'))
1818
- return jsonResponse({ assignees: [] });
1819
- if (url.includes('/api/taskforce/auth/workspace-members'))
1820
- return jsonResponse({ users: [] });
1821
- if (url.includes('/api/taskforce/planning/bootstrap'))
1822
- return jsonResponse({ initiatives: [], workstreams: [], workstreamTaskSummaries: [] });
1823
- if (url.includes('/api/taskforce/tasks'))
1824
- return jsonResponse({ tasks: [activeTask] });
1825
- if (url.includes('/api/taskforce/archive'))
1826
- return jsonResponse({ archived: [] });
1827
- if (url.includes('/api/taskforce/data-version'))
1828
- return jsonResponse({ dataVersion: 1 });
1829
- if (url.includes('/api/taskforce/build-info'))
1830
- return jsonResponse({});
1831
- return jsonResponse({});
1832
- });
1833
- vi.stubGlobal('fetch', fetchMock);
1834
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
1835
- await waitFor(() => {
1836
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
1837
- expect(result.current.activeCategories.some((category) => category.value === 'workspace-one')).toBe(true);
1838
- }, { timeout: 2500 });
1839
- await act(async () => {
1840
- const switched = await result.current.switchWorkspace('workspace-cloud-2');
1841
- expect(switched).toEqual({ success: true });
1842
- });
1843
- await waitFor(() => {
1844
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-2');
1845
- expect(result.current.activeCategories.some((category) => category.value === 'workspace-two')).toBe(true);
1846
- expect(result.current.activeCategories.some((category) => category.value === 'workspace-one')).toBe(false);
1847
- expect(result.current.activeTypes.some((type) => type.value === 'incident')).toBe(true);
1848
- expect(result.current.activeTypes.some((type) => type.value === 'feature')).toBe(false);
1849
- expect(result.current.priorities.some((priority) => priority.value === 4)).toBe(true);
1850
- }, { timeout: 2500 });
1851
- });
1852
- it('rehydrates assignee options and workspace role for the newly selected cloud workspace after a workspace switch', async () => {
1853
- let sessionWorkspaceId = 'workspace-cloud-1';
1854
- vi.stubGlobal('fetch', vi.fn((url, init) => {
1855
- if (url.includes('/api/taskforce/auth/runtime-config')) {
1856
- return jsonResponse({
1857
- config: {
1858
- runtimeMode: 'cloud',
1859
- workspaceMode: 'multi-cloud',
1860
- authSource: 'cloud',
1861
- workspaceSwitchingEnabled: true
1862
- }
1863
- });
1864
- }
1865
- if (url.includes('/api/taskforce/auth/session')) {
1866
- return jsonResponse({
1867
- authenticated: true,
1868
- authRequiredForApi: true,
1869
- betaAccess: true,
1870
- userId: 'user-1',
1871
- email: 'user@example.com',
1872
- workspaceId: sessionWorkspaceId
1873
- });
1874
- }
1875
- if (url.includes('/api/taskforce/ui-state?key=app'))
1876
- return jsonResponse({ success: true, state: {} });
1877
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
1878
- return jsonResponse({
1879
- success: true,
1880
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
1881
- });
1882
- }
1883
- if (url.includes('/api/taskforce/workspaces')) {
1884
- if (String(init?.method || 'GET').toUpperCase() === 'POST') {
1885
- return jsonResponse({ success: true });
1886
- }
1887
- return jsonResponse({
1888
- success: true,
1889
- currentWorkspaceId: sessionWorkspaceId,
1890
- workspaces: [
1891
- { id: 'workspace-cloud-1', name: 'Cloud Workspace 1', role: 'owner' },
1892
- { id: 'workspace-cloud-2', name: 'Cloud Workspace 2', role: 'member' }
1893
- ]
1894
- });
1895
- }
1896
- if (url.includes('/api/taskforce/session/workspace')) {
1897
- const body = JSON.parse(String(init?.body || '{}'));
1898
- sessionWorkspaceId = String(body.workspaceId || '').trim() || sessionWorkspaceId;
1899
- return jsonResponse({ success: true });
1900
- }
1901
- if (url.includes('/api/taskforce/config')) {
1902
- return jsonResponse({
1903
- projectName: sessionWorkspaceId === 'workspace-cloud-2' ? 'Cloud Project 2' : 'Cloud Project 1',
1904
- workspaceId: sessionWorkspaceId,
1905
- runtimeMode: 'cloud',
1906
- authRequiredForApi: true,
1907
- userId: 'user-1',
1908
- setupState: {
1909
- globalSetupState: 'complete',
1910
- workspaceSetupState: 'complete',
1911
- workspaceId: sessionWorkspaceId
1912
- }
1913
- });
1914
- }
1915
- if (url.includes('/api/taskforce/taxonomy-state')) {
1916
- return jsonResponse({
1917
- categories: [{ value: sessionWorkspaceId === 'workspace-cloud-2' ? 'workspace-two' : 'workspace-one', label: 'Workspace' }],
1918
- types: [{ value: 'feature', label: 'Feature' }],
1919
- priorities: [{ value: 2, label: 'Medium' }],
1920
- taxonomies: []
1921
- });
1922
- }
1923
- if (url.includes('/api/taskforce/auth/workspace-members')) {
1924
- if (sessionWorkspaceId === 'workspace-cloud-2') {
1925
- return jsonResponse({
1926
- users: [
1927
- {
1928
- userId: 'user-1',
1929
- email: 'user@example.com',
1930
- displayName: 'Signed In User',
1931
- role: 'member',
1932
- status: 'active',
1933
- disabled: false
1934
- },
1935
- {
1936
- userId: 'member-2',
1937
- email: 'member2@example.com',
1938
- displayName: 'Workspace Two Member',
1939
- status: 'active',
1940
- disabled: false
1941
- }
1942
- ]
1943
- });
1944
- }
1945
- return jsonResponse({
1946
- users: [
1947
- {
1948
- userId: 'user-1',
1949
- email: 'user@example.com',
1950
- displayName: 'Signed In User',
1951
- role: 'owner',
1952
- status: 'active',
1953
- disabled: false
1954
- },
1955
- {
1956
- userId: 'member-1',
1957
- email: 'member1@example.com',
1958
- displayName: 'Workspace One Member',
1959
- status: 'active',
1960
- disabled: false
1961
- }
1962
- ]
1963
- });
1964
- }
1965
- if (url.includes('/api/taskforce/workspace/assignee-options')) {
1966
- if (sessionWorkspaceId === 'workspace-cloud-2') {
1967
- return jsonResponse({
1968
- assignees: [
1969
- { userId: 'member-2', email: 'member2@example.com', displayName: 'Workspace Two Member', status: 'active', disabled: false },
1970
- { value: 'ai-profile-reviewer', label: 'Reviewer', icon: 'Bot', color: '#0ea5e9', kind: 'agent' }
1971
- ]
1972
- });
1973
- }
1974
- return jsonResponse({
1975
- assignees: [
1976
- { userId: 'member-1', email: 'member1@example.com', displayName: 'Workspace One Member', status: 'active', disabled: false },
1977
- { value: 'ai-profile-codex', label: 'Codex', icon: 'Bot', color: '#0ea5e9', kind: 'agent' }
1978
- ]
1979
- });
1980
- }
1981
- if (url.includes('/api/taskforce/planning/bootstrap'))
1982
- return jsonResponse({ initiatives: [], workstreams: [], workstreamTaskSummaries: [] });
1983
- if (url.includes('/api/taskforce/tasks'))
1984
- return jsonResponse({ tasks: [activeTask] });
1985
- if (url.includes('/api/taskforce/archive'))
1986
- return jsonResponse({ archived: [] });
1987
- if (url.includes('/api/taskforce/data-version'))
1988
- return jsonResponse({ dataVersion: 1 });
1989
- if (url.includes('/api/taskforce/build-info'))
1990
- return jsonResponse({});
1991
- if (url.includes('/api/taskforce/global-settings'))
1992
- return jsonResponse({});
1993
- return jsonResponse({});
1994
- }));
1995
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
1996
- await waitFor(() => {
1997
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
1998
- expect(result.current.currentWorkspaceRole).toBe('owner');
1999
- expect(result.current.assigneeOptions.some((option) => option.value === 'member-1' && option.label === 'Workspace One Member')).toBe(true);
2000
- expect(result.current.assigneeOptions.some((option) => option.value === 'ai-profile-codex' && option.label === 'Codex')).toBe(true);
2001
- }, { timeout: 2500 });
2002
- await act(async () => {
2003
- const switched = await result.current.switchWorkspace('workspace-cloud-2');
2004
- expect(switched).toEqual({ success: true });
2005
- });
2006
- await waitFor(() => {
2007
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-2');
2008
- expect(result.current.currentWorkspaceRole).toBe('member');
2009
- expect(result.current.assigneeOptions.some((option) => option.value === 'member-2' && option.label === 'Workspace Two Member')).toBe(true);
2010
- expect(result.current.assigneeOptions.some((option) => option.value === 'member-1')).toBe(false);
2011
- expect(result.current.assigneeOptions.some((option) => option.value === 'ai-profile-reviewer' && option.label === 'Reviewer')).toBe(true);
2012
- expect(result.current.assigneeOptions.some((option) => option.value === 'ai-profile-codex')).toBe(false);
2013
- }, { timeout: 2500 });
2014
- });
2015
- it('starts planning bootstrap before deferred assignee hydration after a cloud workspace switch', async () => {
2016
- let sessionWorkspaceId = 'workspace-cloud-1';
2017
- const requestOrder = [];
2018
- let resolveWorkspaceTwoAssignees = null;
2019
- vi.stubGlobal('fetch', vi.fn((url, init) => {
2020
- if (url.includes('/api/taskforce/auth/runtime-config')) {
2021
- return jsonResponse({
2022
- config: {
2023
- runtimeMode: 'cloud',
2024
- workspaceMode: 'multi-cloud',
2025
- authSource: 'cloud',
2026
- workspaceSwitchingEnabled: true
2027
- }
2028
- });
2029
- }
2030
- if (url.includes('/api/taskforce/auth/session')) {
2031
- return jsonResponse({
2032
- authenticated: true,
2033
- authRequiredForApi: true,
2034
- betaAccess: true,
2035
- userId: 'user-1',
2036
- email: 'user@example.com',
2037
- workspaceId: sessionWorkspaceId
2038
- });
2039
- }
2040
- if (url.includes('/api/taskforce/ui-state?key=app'))
2041
- return jsonResponse({ success: true, state: {} });
2042
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
2043
- return jsonResponse({
2044
- success: true,
2045
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
2046
- });
2047
- }
2048
- if (url.includes('/api/taskforce/workspaces')) {
2049
- if (String(init?.method || 'GET').toUpperCase() === 'POST')
2050
- return jsonResponse({ success: true });
2051
- return jsonResponse({
2052
- success: true,
2053
- currentWorkspaceId: sessionWorkspaceId,
2054
- workspaces: [
2055
- { id: 'workspace-cloud-1', name: 'Cloud Workspace 1', role: 'owner' },
2056
- { id: 'workspace-cloud-2', name: 'Cloud Workspace 2', role: 'member' }
2057
- ]
2058
- });
2059
- }
2060
- if (url.includes('/api/taskforce/session/workspace')) {
2061
- const body = JSON.parse(String(init?.body || '{}'));
2062
- sessionWorkspaceId = String(body.workspaceId || '').trim() || sessionWorkspaceId;
2063
- return jsonResponse({ success: true });
2064
- }
2065
- if (url.includes('/api/taskforce/config')) {
2066
- return jsonResponse({
2067
- projectName: sessionWorkspaceId === 'workspace-cloud-2' ? 'Cloud Project 2' : 'Cloud Project 1',
2068
- workspaceId: sessionWorkspaceId,
2069
- runtimeMode: 'cloud',
2070
- authRequiredForApi: true,
2071
- userId: 'user-1',
2072
- setupState: {
2073
- globalSetupState: 'complete',
2074
- workspaceSetupState: 'complete',
2075
- workspaceId: sessionWorkspaceId
2076
- }
2077
- });
2078
- }
2079
- if (url.includes('/api/taskforce/taxonomy-state')) {
2080
- return jsonResponse({
2081
- categories: [{ value: sessionWorkspaceId === 'workspace-cloud-2' ? 'workspace-two' : 'workspace-one', label: 'Workspace' }],
2082
- types: [{ value: 'feature', label: 'Feature' }],
2083
- priorities: [{ value: 2, label: 'Medium' }],
2084
- taxonomies: []
2085
- });
2086
- }
2087
- if (url.includes('/api/taskforce/auth/workspace-members'))
2088
- return jsonResponse({ users: [] });
2089
- if (url.includes('/api/taskforce/workspace/assignee-options')) {
2090
- requestOrder.push(`assignee:${sessionWorkspaceId}`);
2091
- if (sessionWorkspaceId === 'workspace-cloud-2') {
2092
- return new Promise((resolve) => {
2093
- resolveWorkspaceTwoAssignees = () => resolve({
2094
- ok: true,
2095
- status: 200,
2096
- json: () => Promise.resolve({ assignees: [] })
2097
- });
2098
- });
2099
- }
2100
- return jsonResponse({ assignees: [] });
2101
- }
2102
- if (url.includes('/api/taskforce/planning/bootstrap')) {
2103
- requestOrder.push(`planning:${sessionWorkspaceId}`);
2104
- return jsonResponse({
2105
- initiatives: [{ id: `initiative-${sessionWorkspaceId}`, title: `Initiative ${sessionWorkspaceId}` }],
2106
- workstreams: [],
2107
- workstreamTaskSummaries: []
2108
- });
2109
- }
2110
- if (url.includes('/api/taskforce/tasks'))
2111
- return jsonResponse({ tasks: [activeTask] });
2112
- if (url.includes('/api/taskforce/archive'))
2113
- return jsonResponse({ archived: [] });
2114
- if (url.includes('/api/taskforce/data-version'))
2115
- return jsonResponse({ dataVersion: 1 });
2116
- if (url.includes('/api/taskforce/build-info'))
2117
- return jsonResponse({});
2118
- if (url.includes('/api/taskforce/global-settings'))
2119
- return jsonResponse({});
2120
- return jsonResponse({});
2121
- }));
2122
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
2123
- await waitFor(() => {
2124
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
2125
- expect(result.current.initiatives.some((initiative) => initiative.id === 'initiative-workspace-cloud-1')).toBe(true);
2126
- }, { timeout: 2500 });
2127
- requestOrder.length = 0;
2128
- await act(async () => {
2129
- const switched = await result.current.switchWorkspace('workspace-cloud-2');
2130
- expect(switched).toEqual({ success: true });
2131
- });
2132
- await waitFor(() => {
2133
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-2');
2134
- expect(result.current.initiatives.some((initiative) => initiative.id === 'initiative-workspace-cloud-2')).toBe(true);
2135
- }, { timeout: 2500 });
2136
- await waitFor(() => {
2137
- expect(requestOrder).toContain('planning:workspace-cloud-2');
2138
- expect(requestOrder).toContain('assignee:workspace-cloud-2');
2139
- }, { timeout: 2500 });
2140
- expect(requestOrder.indexOf('planning:workspace-cloud-2')).toBeLessThan(requestOrder.indexOf('assignee:workspace-cloud-2'));
2141
- await act(async () => {
2142
- resolveWorkspaceTwoAssignees?.();
2143
- });
2144
- });
2145
- it('rehydrates planning bootstrap outputs for the newly selected cloud workspace after a workspace switch', async () => {
2146
- let sessionWorkspaceId = 'workspace-cloud-1';
2147
- const planningBootstrapWorkspaces = [];
2148
- const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => { });
2149
- vi.stubGlobal('fetch', vi.fn((url, init) => {
2150
- if (url.includes('/api/taskforce/auth/runtime-config')) {
2151
- return jsonResponse({
2152
- config: {
2153
- runtimeMode: 'cloud',
2154
- workspaceMode: 'multi-cloud',
2155
- authSource: 'cloud',
2156
- workspaceSwitchingEnabled: true
2157
- }
2158
- });
2159
- }
2160
- if (url.includes('/api/taskforce/auth/session')) {
2161
- return jsonResponse({
2162
- authenticated: true,
2163
- authRequiredForApi: true,
2164
- betaAccess: true,
2165
- userId: 'user-1',
2166
- email: 'user@example.com',
2167
- workspaceId: sessionWorkspaceId
2168
- });
2169
- }
2170
- if (url.includes('/api/taskforce/ui-state?key=app'))
2171
- return jsonResponse({ success: true, state: {} });
2172
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
2173
- return jsonResponse({
2174
- success: true,
2175
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
2176
- });
2177
- }
2178
- if (url.includes('/api/taskforce/workspaces')) {
2179
- if (String(init?.method || 'GET').toUpperCase() === 'POST') {
2180
- return jsonResponse({ success: true });
2181
- }
2182
- return jsonResponse({
2183
- success: true,
2184
- currentWorkspaceId: sessionWorkspaceId,
2185
- workspaces: [
2186
- { id: 'workspace-cloud-1', name: 'Cloud Workspace 1', role: 'owner' },
2187
- { id: 'workspace-cloud-2', name: 'Cloud Workspace 2', role: 'member' }
2188
- ]
2189
- });
2190
- }
2191
- if (url.includes('/api/taskforce/session/workspace')) {
2192
- const body = JSON.parse(String(init?.body || '{}'));
2193
- sessionWorkspaceId = String(body.workspaceId || '').trim() || sessionWorkspaceId;
2194
- return jsonResponse({ success: true });
2195
- }
2196
- if (url.includes('/api/taskforce/config')) {
2197
- return jsonResponse({
2198
- projectName: sessionWorkspaceId === 'workspace-cloud-2' ? 'Cloud Project 2' : 'Cloud Project 1',
2199
- workspaceId: sessionWorkspaceId,
2200
- runtimeMode: 'cloud',
2201
- authRequiredForApi: true,
2202
- userId: 'user-1',
2203
- setupState: {
2204
- globalSetupState: 'complete',
2205
- workspaceSetupState: 'complete',
2206
- workspaceId: sessionWorkspaceId
2207
- }
2208
- });
2209
- }
2210
- if (url.includes('/api/taskforce/taxonomy-state')) {
2211
- return jsonResponse({
2212
- categories: [{ value: sessionWorkspaceId === 'workspace-cloud-2' ? 'workspace-two' : 'workspace-one', label: 'Workspace' }],
2213
- types: [{ value: 'feature', label: 'Feature' }],
2214
- priorities: [{ value: 2, label: 'Medium' }],
2215
- taxonomies: []
2216
- });
2217
- }
2218
- if (url.includes('/api/taskforce/auth/workspace-members'))
2219
- return jsonResponse({ users: [] });
2220
- if (url.includes('/api/taskforce/workspace/assignee-options'))
2221
- return jsonResponse({ assignees: [] });
2222
- if (url.includes('/api/taskforce/planning/bootstrap')) {
2223
- planningBootstrapWorkspaces.push(sessionWorkspaceId);
2224
- if (sessionWorkspaceId === 'workspace-cloud-2') {
2225
- return jsonResponse({
2226
- initiatives: [
2227
- {
2228
- id: 'initiative-2',
2229
- title: 'Workspace Two Initiative',
2230
- description: 'Workspace two planning initiative',
2231
- ownerId: null,
2232
- createdAt: '2026-03-15T10:20:00.000Z',
2233
- updatedAt: '2026-03-15T10:20:00.000Z',
2234
- referenceNumber: 12,
2235
- referenceLabel: 'IN-12',
2236
- isArchived: false,
2237
- comments: [],
2238
- attachments: []
2239
- }
2240
- ],
2241
- workstreams: [
2242
- {
2243
- id: 'workstream-2',
2244
- title: 'Workspace Two Workstream',
2245
- description: 'Workspace two workstream',
2246
- ownerId: null,
2247
- initiativeId: 'initiative-2',
2248
- createdAt: '2026-03-15T10:25:00.000Z',
2249
- updatedAt: '2026-03-15T10:25:00.000Z',
2250
- referenceNumber: 102,
2251
- referenceLabel: 'WS-102',
2252
- isArchived: false,
2253
- comments: [],
2254
- attachments: []
2255
- }
2256
- ],
2257
- workstreamTaskSummaries: [{
2258
- workstreamId: 'workstream-2',
2259
- taskCount: 1,
2260
- completedTaskCount: 0,
2261
- tasks: [{
2262
- id: 'task-workspace-2',
2263
- title: 'Workspace Two Task',
2264
- status: 'task'
2265
- }]
2266
- }]
2267
- });
2268
- }
2269
- return jsonResponse({
2270
- initiatives: [
2271
- {
2272
- id: 'initiative-1',
2273
- title: 'Workspace One Initiative',
2274
- description: 'Workspace one planning initiative',
2275
- ownerId: null,
2276
- createdAt: '2026-03-15T10:00:00.000Z',
2277
- updatedAt: '2026-03-15T10:00:00.000Z',
2278
- referenceNumber: 11,
2279
- referenceLabel: 'IN-11',
2280
- isArchived: false,
2281
- comments: [],
2282
- attachments: []
2283
- }
2284
- ],
2285
- workstreams: [
2286
- {
2287
- id: 'workstream-1',
2288
- title: 'Workspace One Workstream',
2289
- description: 'Workspace one workstream',
2290
- ownerId: null,
2291
- initiativeId: 'initiative-1',
2292
- createdAt: '2026-03-15T10:05:00.000Z',
2293
- updatedAt: '2026-03-15T10:05:00.000Z',
2294
- referenceNumber: 101,
2295
- referenceLabel: 'WS-101',
2296
- isArchived: false,
2297
- comments: [],
2298
- attachments: []
2299
- }
2300
- ],
2301
- workstreamTaskSummaries: [{
2302
- workstreamId: 'workstream-1',
2303
- taskCount: 1,
2304
- completedTaskCount: 0,
2305
- tasks: [{
2306
- id: 'task-workspace-1',
2307
- title: 'Workspace One Task',
2308
- status: 'task'
2309
- }]
2310
- }]
2311
- });
2312
- }
2313
- if (url.includes('/api/taskforce/tasks'))
2314
- return jsonResponse({ tasks: [activeTask] });
2315
- if (url.includes('/api/taskforce/archive'))
2316
- return jsonResponse({ archived: [] });
2317
- if (url.includes('/api/taskforce/data-version'))
2318
- return jsonResponse({ dataVersion: 1 });
2319
- if (url.includes('/api/taskforce/build-info'))
2320
- return jsonResponse({});
2321
- if (url.includes('/api/taskforce/global-settings'))
2322
- return jsonResponse({});
2323
- return jsonResponse({});
2324
- }));
2325
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
2326
- await waitFor(() => {
2327
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
2328
- expect(result.current.initiatives.some((initiative) => initiative.id === 'initiative-1')).toBe(true);
2329
- expect(result.current.workstreams.some((workstream) => workstream.id === 'workstream-1')).toBe(true);
2330
- }, { timeout: 2500 });
2331
- await act(async () => {
2332
- const switched = await result.current.switchWorkspace('workspace-cloud-2');
2333
- expect(switched).toEqual({ success: true });
2334
- });
2335
- await waitFor(() => {
2336
- expect(planningBootstrapWorkspaces).toContain('workspace-cloud-2');
2337
- }, { timeout: 2500 });
2338
- await waitFor(() => {
2339
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-2');
2340
- expect(result.current.initiatives.map((initiative) => initiative.id)).toEqual(['initiative-2']);
2341
- expect(result.current.workstreams.map((workstream) => workstream.id)).toEqual(['workstream-2']);
2342
- }, { timeout: 2500 });
2343
- expect(consoleErrorSpy).not.toHaveBeenCalledWith('[Taskforce] Failed to fetch planning entities:', 'superseded');
2344
- });
2345
- it('does not log expected workspace-transition aborts during cloud workspace switches', async () => {
2346
- let sessionWorkspaceId = 'workspace-cloud-1';
2347
- let deletedAbortSeen = false;
2348
- const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => { });
2349
- const rejectOnAbort = (init, errorFactory) => new Promise((_resolve, reject) => {
2350
- const signal = init?.signal;
2351
- if (!signal)
2352
- return;
2353
- const onAbort = () => reject(errorFactory(signal));
2354
- if (signal.aborted) {
2355
- onAbort();
2356
- return;
2357
- }
2358
- signal.addEventListener('abort', onAbort, { once: true });
2359
- });
2360
- vi.stubGlobal('fetch', vi.fn((url, init) => {
2361
- if (url.includes('/api/taskforce/auth/runtime-config')) {
2362
- return jsonResponse({
2363
- config: {
2364
- runtimeMode: 'cloud',
2365
- workspaceMode: 'multi-cloud',
2366
- authSource: 'cloud',
2367
- workspaceSwitchingEnabled: true
2368
- }
2369
- });
2370
- }
2371
- if (url.includes('/api/taskforce/auth/session')) {
2372
- return jsonResponse({
2373
- authenticated: true,
2374
- authRequiredForApi: true,
2375
- betaAccess: true,
2376
- userId: 'user-1',
2377
- email: 'user@example.com',
2378
- workspaceId: sessionWorkspaceId
2379
- });
2380
- }
2381
- if (url.includes('/api/taskforce/ui-state?key=app'))
2382
- return jsonResponse({ success: true, state: {} });
2383
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
2384
- return jsonResponse({
2385
- success: true,
2386
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
2387
- });
2388
- }
2389
- if (url.includes('/api/taskforce/workspaces')) {
2390
- if (String(init?.method || 'GET').toUpperCase() === 'POST') {
2391
- return jsonResponse({ success: true });
2392
- }
2393
- return jsonResponse({
2394
- success: true,
2395
- currentWorkspaceId: sessionWorkspaceId,
2396
- workspaces: [
2397
- { id: 'workspace-cloud-1', name: 'Cloud Workspace 1', role: 'owner' },
2398
- { id: 'workspace-cloud-2', name: 'Cloud Workspace 2', role: 'member' }
2399
- ]
2400
- });
2401
- }
2402
- if (url.includes('/api/taskforce/session/workspace')) {
2403
- const body = JSON.parse(String(init?.body || '{}'));
2404
- sessionWorkspaceId = String(body.workspaceId || '').trim() || sessionWorkspaceId;
2405
- return jsonResponse({ success: true });
2406
- }
2407
- if (url.includes('/api/taskforce/config')) {
2408
- return jsonResponse({
2409
- projectName: 'Cloud Project',
2410
- workspaceId: sessionWorkspaceId,
2411
- runtimeMode: 'cloud',
2412
- authRequiredForApi: true,
2413
- userId: 'user-1',
2414
- setupState: {
2415
- globalSetupState: 'complete',
2416
- workspaceSetupState: 'complete',
2417
- workspaceId: sessionWorkspaceId
2418
- }
2419
- });
2420
- }
2421
- if (url.includes('/api/taskforce/taxonomy-state')) {
2422
- return jsonResponse({
2423
- categories: [{ value: 'general', label: 'General' }],
2424
- types: [{ value: 'feature', label: 'Feature' }],
2425
- priorities: [{ value: 2, label: 'Medium' }],
2426
- taxonomies: []
2427
- });
2428
- }
2429
- if (url.includes('/api/taskforce/auth/workspace-members'))
2430
- return jsonResponse({ users: [] });
2431
- if (url.includes('/api/taskforce/workspace/assignee-options'))
2432
- return jsonResponse({ assignees: [] });
2433
- if (url.includes('/api/taskforce/planning/bootstrap')) {
2434
- if (sessionWorkspaceId === 'workspace-cloud-1') {
2435
- return rejectOnAbort(init, (signal) => signal.reason || new TypeError('Failed to fetch'));
2436
- }
2437
- return jsonResponse({ initiatives: [], workstreams: [], workstreamTaskSummaries: [] });
2438
- }
2439
- if (url.includes('/api/taskforce/deleted')) {
2440
- return rejectOnAbort(init, () => {
2441
- deletedAbortSeen = true;
2442
- return new TypeError('Failed to fetch');
2443
- });
2444
- }
2445
- if (url.includes('/api/taskforce/tasks'))
2446
- return jsonResponse({ tasks: [activeTask] });
2447
- if (url.includes('/api/taskforce/archive'))
2448
- return jsonResponse({ archived: [] });
2449
- if (url.includes('/api/taskforce/data-version'))
2450
- return jsonResponse({ dataVersion: 1 });
2451
- if (url.includes('/api/taskforce/build-info'))
2452
- return jsonResponse({});
2453
- if (url.includes('/api/taskforce/global-settings'))
2454
- return jsonResponse({});
2455
- return jsonResponse({});
2456
- }));
2457
- try {
2458
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
2459
- await waitFor(() => {
2460
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
2461
- expect(result.current.bootstrapState.ready).toBe(true);
2462
- }, { timeout: 2500 });
2463
- act(() => {
2464
- void result.current.fetchDeletedTasks(true);
2465
- });
2466
- await act(async () => {
2467
- const switched = await result.current.switchWorkspace('workspace-cloud-2', { hydrate: false });
2468
- expect(switched).toEqual({ success: true });
2469
- });
2470
- await waitFor(() => {
2471
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-2');
2472
- expect(deletedAbortSeen).toBe(true);
2473
- }, { timeout: 2500 });
2474
- expect(consoleErrorSpy).not.toHaveBeenCalledWith('[Taskforce] Failed to fetch planning entities:', 'workspace-transition');
2475
- expect(consoleErrorSpy).not.toHaveBeenCalledWith('[Taskforce] Failed to fetch deleted tasks:', expect.any(TypeError));
2476
- }
2477
- finally {
2478
- consoleErrorSpy.mockRestore();
2479
- }
2480
- });
2481
- it('uses the preferred workspace returned by invite join during cloud re-entry', async () => {
2482
- let sessionWorkspaceId = 'workspace-home';
2483
- const sessionWorkspacePosts = [];
2484
- vi.stubGlobal('fetch', vi.fn((url, init) => {
2485
- if (url.includes('/api/taskforce/auth/runtime-config')) {
2486
- return jsonResponse({
2487
- config: {
2488
- runtimeMode: 'cloud',
2489
- workspaceMode: 'multi-cloud',
2490
- authSource: 'cloud',
2491
- workspaceSwitchingEnabled: true,
2492
- cloudAuthBaseUrl: 'https://cloud.example.com'
2493
- }
2494
- });
2495
- }
2496
- if (url.includes('/api/taskforce/auth/session')) {
2497
- return jsonResponse({
2498
- authenticated: true,
2499
- authRequiredForApi: true,
2500
- betaAccess: true,
2501
- userId: 'user-1',
2502
- email: 'user@example.com',
2503
- workspaceId: sessionWorkspaceId
2504
- });
2505
- }
2506
- if (url.includes('/api/taskforce/ui-state?key=app'))
2507
- return jsonResponse({ success: true, state: {} });
2508
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
2509
- return jsonResponse({
2510
- success: true,
2511
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
2512
- });
2513
- }
2514
- if (url.includes('/api/taskforce/workspaces')) {
2515
- return jsonResponse({
2516
- success: true,
2517
- currentWorkspaceId: sessionWorkspaceId,
2518
- workspaces: [
2519
- { id: 'workspace-home', name: 'Home Workspace', role: 'owner' },
2520
- { id: 'workspace-invite', name: 'Invited Workspace', role: 'member' }
2521
- ]
2522
- });
2523
- }
2524
- if (url.includes('/api/taskforce/session/workspace')) {
2525
- const body = JSON.parse(String(init?.body || '{}'));
2526
- const nextWorkspaceId = String(body.workspaceId || '').trim();
2527
- sessionWorkspacePosts.push(nextWorkspaceId);
2528
- sessionWorkspaceId = nextWorkspaceId || sessionWorkspaceId;
2529
- return jsonResponse({ success: true, workspaceId: sessionWorkspaceId });
2530
- }
2531
- if (url.includes('/api/taskforce/config')) {
2532
- return jsonResponse({
2533
- projectName: sessionWorkspaceId === 'workspace-invite' ? 'Invited Workspace' : 'Home Workspace',
2534
- workspaceId: sessionWorkspaceId,
2535
- runtimeMode: 'cloud',
2536
- authRequiredForApi: true,
2537
- userId: 'user-1',
2538
- setupState: {
2539
- globalSetupState: 'complete',
2540
- workspaceSetupState: 'complete',
2541
- workspaceId: sessionWorkspaceId
2542
- }
2543
- });
2544
- }
2545
- if (url.includes('/api/taskforce/taxonomy-state')) {
2546
- return jsonResponse({
2547
- categories: [{ value: sessionWorkspaceId === 'workspace-invite' ? 'invite' : 'home', label: 'Workspace' }],
2548
- types: [{ value: 'feature', label: 'Feature' }],
2549
- priorities: [{ value: 2, label: 'Medium' }],
2550
- taxonomies: []
2551
- });
2552
- }
2553
- if (url.includes('/api/taskforce/auth/invite/join')) {
2554
- return jsonResponse({ success: true, workspaceId: 'workspace-invite' });
2555
- }
2556
- if (url.includes('/api/taskforce/global-settings'))
2557
- return jsonResponse({});
2558
- if (url.includes('/api/taskforce/workspace/assignee-options'))
2559
- return jsonResponse({ assignees: [] });
2560
- if (url.includes('/api/taskforce/auth/workspace-members'))
2561
- return jsonResponse({ users: [] });
2562
- if (url.includes('/api/taskforce/planning/bootstrap'))
2563
- return jsonResponse({ initiatives: [], workstreams: [], workstreamTaskSummaries: [] });
2564
- if (url.includes('/api/taskforce/tasks'))
2565
- return jsonResponse({ tasks: [activeTask] });
2566
- if (url.includes('/api/taskforce/archive'))
2567
- return jsonResponse({ archived: [] });
2568
- if (url.includes('/api/taskforce/data-version'))
2569
- return jsonResponse({ dataVersion: 1 });
2570
- if (url.includes('/api/taskforce/build-info'))
2571
- return jsonResponse({});
2572
- return jsonResponse({});
2573
- }));
2574
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
2575
- await waitFor(() => {
2576
- expect(result.current.currentWorkspaceId).toBe('workspace-home');
2577
- expect(result.current.runtimeMode).toBe('cloud');
2578
- expect(result.current.workspaceSwitchingEnabled).toBe(true);
2579
- }, { timeout: 2500 });
2580
- await act(async () => {
2581
- const joined = await result.current.joinInviteWithToken('invite-token');
2582
- expect(joined).toEqual({ success: true, workspaceSetupRequired: false });
2583
- });
2584
- await waitFor(() => {
2585
- expect(sessionWorkspacePosts).toContain('workspace-invite');
2586
- }, { timeout: 2500 });
2587
- await waitFor(() => {
2588
- expect(result.current.currentWorkspaceId).toBe('workspace-invite');
2589
- }, { timeout: 2500 });
2590
- });
2591
- it('uses the preferred workspace returned by invite acceptance during cloud re-entry', async () => {
2592
- let sessionWorkspaceId = 'workspace-home';
2593
- const sessionWorkspacePosts = [];
2594
- vi.stubGlobal('fetch', vi.fn((url, init) => {
2595
- if (url.includes('/api/taskforce/auth/runtime-config')) {
2596
- return jsonResponse({
2597
- config: {
2598
- runtimeMode: 'cloud',
2599
- workspaceMode: 'multi-cloud',
2600
- authSource: 'cloud',
2601
- workspaceSwitchingEnabled: true,
2602
- cloudAuthBaseUrl: 'https://cloud.example.com'
2603
- }
2604
- });
2605
- }
2606
- if (url.includes('/api/taskforce/auth/session')) {
2607
- return jsonResponse({
2608
- authenticated: true,
2609
- authRequiredForApi: true,
2610
- betaAccess: true,
2611
- userId: 'user-1',
2612
- email: 'new@example.com',
2613
- workspaceId: sessionWorkspaceId
2614
- });
2615
- }
2616
- if (url.includes('/api/taskforce/ui-state?key=app'))
2617
- return jsonResponse({ success: true, state: {} });
2618
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
2619
- return jsonResponse({
2620
- success: true,
2621
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
2622
- });
2623
- }
2624
- if (url.includes('/api/taskforce/workspaces')) {
2625
- return jsonResponse({
2626
- success: true,
2627
- currentWorkspaceId: sessionWorkspaceId,
2628
- workspaces: [
2629
- { id: 'workspace-home', name: 'Home Workspace', role: 'owner' },
2630
- { id: 'workspace-invite', name: 'Invited Workspace', role: 'member' }
2631
- ]
2632
- });
2633
- }
2634
- if (url.includes('/api/taskforce/session/workspace')) {
2635
- const body = JSON.parse(String(init?.body || '{}'));
2636
- const nextWorkspaceId = String(body.workspaceId || '').trim();
2637
- sessionWorkspacePosts.push(nextWorkspaceId);
2638
- sessionWorkspaceId = nextWorkspaceId || sessionWorkspaceId;
2639
- return jsonResponse({ success: true, workspaceId: sessionWorkspaceId });
2640
- }
2641
- if (url.includes('/api/taskforce/config')) {
2642
- return jsonResponse({
2643
- projectName: sessionWorkspaceId === 'workspace-invite' ? 'Invited Workspace' : 'Home Workspace',
2644
- workspaceId: sessionWorkspaceId,
2645
- runtimeMode: 'cloud',
2646
- authRequiredForApi: true,
2647
- userId: 'user-1',
2648
- setupState: {
2649
- globalSetupState: 'complete',
2650
- workspaceSetupState: 'complete',
2651
- workspaceId: sessionWorkspaceId
2652
- }
2653
- });
2654
- }
2655
- if (url.includes('/api/taskforce/taxonomy-state')) {
2656
- return jsonResponse({
2657
- categories: [{ value: sessionWorkspaceId === 'workspace-invite' ? 'invite' : 'home', label: 'Workspace' }],
2658
- types: [{ value: 'feature', label: 'Feature' }],
2659
- priorities: [{ value: 2, label: 'Medium' }],
2660
- taxonomies: []
2661
- });
2662
- }
2663
- if (url.includes('/api/taskforce/auth/invite/accept')) {
2664
- return jsonResponse({ success: true, workspaceId: 'workspace-invite' });
2665
- }
2666
- if (url.includes('/api/taskforce/global-settings'))
2667
- return jsonResponse({});
2668
- if (url.includes('/api/taskforce/workspace/assignee-options'))
2669
- return jsonResponse({ assignees: [] });
2670
- if (url.includes('/api/taskforce/auth/workspace-members'))
2671
- return jsonResponse({ users: [] });
2672
- if (url.includes('/api/taskforce/planning/bootstrap'))
2673
- return jsonResponse({ initiatives: [], workstreams: [], workstreamTaskSummaries: [] });
2674
- if (url.includes('/api/taskforce/tasks'))
2675
- return jsonResponse({ tasks: [activeTask] });
2676
- if (url.includes('/api/taskforce/archive'))
2677
- return jsonResponse({ archived: [] });
2678
- if (url.includes('/api/taskforce/data-version'))
2679
- return jsonResponse({ dataVersion: 1 });
2680
- if (url.includes('/api/taskforce/build-info'))
2681
- return jsonResponse({});
2682
- return jsonResponse({});
2683
- }));
2684
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
2685
- await waitFor(() => {
2686
- expect(result.current.currentWorkspaceId).toBe('workspace-home');
2687
- expect(result.current.runtimeMode).toBe('cloud');
2688
- expect(result.current.workspaceSwitchingEnabled).toBe(true);
2689
- }, { timeout: 2500 });
2690
- await act(async () => {
2691
- const accepted = await result.current.acceptInviteWithToken('invite-token', 'NewUserPass123!');
2692
- expect(accepted).toEqual({ success: true, workspaceSetupRequired: false });
2693
- });
2694
- await waitFor(() => {
2695
- expect(sessionWorkspacePosts).toContain('workspace-invite');
2696
- }, { timeout: 2500 });
2697
- await waitFor(() => {
2698
- expect(result.current.currentWorkspaceId).toBe('workspace-invite');
2699
- }, { timeout: 2500 });
2700
- });
2701
- it('rehydrates taxonomy state after retryBootstrapChecks resolves a transient empty cloud taxonomy response', async () => {
2702
- let taxonomyReady = false;
2703
- vi.stubGlobal('fetch', vi.fn((url, init) => {
2704
- if (url.includes('/api/taskforce/auth/runtime-config')) {
2705
- return jsonResponse({
2706
- config: {
2707
- runtimeMode: 'cloud',
2708
- workspaceMode: 'multi-cloud',
2709
- authSource: 'cloud',
2710
- workspaceSwitchingEnabled: true
2711
- }
2712
- });
2713
- }
2714
- if (url.includes('/api/taskforce/auth/session')) {
2715
- return jsonResponse({
2716
- authenticated: true,
2717
- authRequiredForApi: true,
2718
- betaAccess: true,
2719
- userId: 'user-1',
2720
- email: 'user@example.com',
2721
- workspaceId: 'workspace-cloud-1'
2722
- });
2723
- }
2724
- if (url.includes('/api/taskforce/ui-state?key=app'))
2725
- return jsonResponse({ success: true, state: {} });
2726
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
2727
- return jsonResponse({
2728
- success: true,
2729
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
2730
- });
2731
- }
2732
- if (url.includes('/api/taskforce/workspaces')) {
2733
- if (String(init?.method || 'GET').toUpperCase() === 'POST') {
2734
- return jsonResponse({ success: true });
2735
- }
2736
- return jsonResponse({
2737
- success: true,
2738
- currentWorkspaceId: 'workspace-cloud-1',
2739
- workspaces: [{ id: 'workspace-cloud-1', name: 'Cloud Workspace', role: 'owner' }]
2740
- });
2741
- }
2742
- if (url.includes('/api/taskforce/session/workspace'))
2743
- return jsonResponse({ success: true });
2744
- if (url.includes('/api/taskforce/config')) {
2745
- return jsonResponse({
2746
- projectName: 'Cloud Project',
2747
- workspaceId: 'workspace-cloud-1',
2748
- runtimeMode: 'cloud',
2749
- authRequiredForApi: true,
2750
- userId: 'user-1',
2751
- setupState: {
2752
- globalSetupState: 'complete',
2753
- workspaceSetupState: 'complete',
2754
- workspaceId: 'workspace-cloud-1'
2755
- }
2756
- });
2757
- }
2758
- if (url.includes('/api/taskforce/taxonomy-state')) {
2759
- return jsonResponse(taxonomyReady ? {
2760
- categories: [{ value: 'cloud-ops', label: 'Cloud Ops' }],
2761
- types: [{ value: 'incident', label: 'Incident' }],
2762
- priorities: [{ value: 4, label: 'Critical' }],
2763
- taxonomies: []
2764
- } : {
2765
- categories: [],
2766
- types: [],
2767
- priorities: [],
2768
- taxonomies: []
2769
- });
2770
- }
2771
- if (url.includes('/api/taskforce/global-settings'))
2772
- return jsonResponse({});
2773
- if (url.includes('/api/taskforce/workspace/assignee-options'))
2774
- return jsonResponse({ assignees: [] });
2775
- if (url.includes('/api/taskforce/auth/workspace-members'))
2776
- return jsonResponse({ users: [] });
2777
- if (url.includes('/api/taskforce/planning/bootstrap'))
2778
- return jsonResponse({ initiatives: [], workstreams: [], workstreamTaskSummaries: [] });
2779
- if (url.includes('/api/taskforce/tasks'))
2780
- return jsonResponse({ tasks: [activeTask] });
2781
- if (url.includes('/api/taskforce/archive'))
2782
- return jsonResponse({ archived: [] });
2783
- if (url.includes('/api/taskforce/data-version'))
2784
- return jsonResponse({ dataVersion: 1 });
2785
- if (url.includes('/api/taskforce/build-info'))
2786
- return jsonResponse({});
2787
- return jsonResponse({});
2788
- }));
2789
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
2790
- await waitFor(() => {
2791
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
2792
- }, { timeout: 2500 });
2793
- expect(result.current.activeCategories.some((category) => category.value === 'cloud-ops')).toBe(false);
2794
- taxonomyReady = true;
2795
- await act(async () => {
2796
- await result.current.retryBootstrapChecks();
2797
- });
2798
- await waitFor(() => {
2799
- expect(result.current.activeCategories.some((category) => category.value === 'cloud-ops')).toBe(true);
2800
- expect(result.current.activeTypes.some((type) => type.value === 'incident')).toBe(true);
2801
- expect(result.current.priorities.some((priority) => priority.value === 4)).toBe(true);
2802
- }, { timeout: 2500 });
2803
- });
2804
- it('does not refetch assignee options during retryBootstrapChecks when they are already loaded', async () => {
2805
- let taxonomyReady = false;
2806
- const requestOrder = [];
2807
- vi.stubGlobal('fetch', vi.fn((url, init) => {
2808
- if (url.includes('/api/taskforce/auth/runtime-config')) {
2809
- return jsonResponse({
2810
- config: {
2811
- runtimeMode: 'cloud',
2812
- workspaceMode: 'multi-cloud',
2813
- authSource: 'cloud',
2814
- workspaceSwitchingEnabled: true
2815
- }
2816
- });
2817
- }
2818
- if (url.includes('/api/taskforce/auth/session')) {
2819
- return jsonResponse({
2820
- authenticated: true,
2821
- authRequiredForApi: true,
2822
- betaAccess: true,
2823
- userId: 'user-1',
2824
- email: 'user@example.com',
2825
- workspaceId: 'workspace-cloud-1'
2826
- });
2827
- }
2828
- if (url.includes('/api/taskforce/ui-state?key=app'))
2829
- return jsonResponse({ success: true, state: {} });
2830
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
2831
- return jsonResponse({
2832
- success: true,
2833
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
2834
- });
2835
- }
2836
- if (url.includes('/api/taskforce/workspaces')) {
2837
- if (String(init?.method || 'GET').toUpperCase() === 'POST')
2838
- return jsonResponse({ success: true });
2839
- return jsonResponse({
2840
- success: true,
2841
- currentWorkspaceId: 'workspace-cloud-1',
2842
- workspaces: [{ id: 'workspace-cloud-1', name: 'Cloud Workspace', role: 'owner' }]
2843
- });
2844
- }
2845
- if (url.includes('/api/taskforce/session/workspace'))
2846
- return jsonResponse({ success: true });
2847
- if (url.includes('/api/taskforce/config')) {
2848
- return jsonResponse({
2849
- projectName: 'Cloud Project',
2850
- workspaceId: 'workspace-cloud-1',
2851
- runtimeMode: 'cloud',
2852
- authRequiredForApi: true,
2853
- userId: 'user-1',
2854
- setupState: {
2855
- globalSetupState: 'complete',
2856
- workspaceSetupState: 'complete',
2857
- workspaceId: 'workspace-cloud-1'
2858
- }
2859
- });
2860
- }
2861
- if (url.includes('/api/taskforce/taxonomy-state')) {
2862
- return jsonResponse(taxonomyReady ? {
2863
- categories: [{ value: 'cloud-ops', label: 'Cloud Ops' }],
2864
- types: [{ value: 'incident', label: 'Incident' }],
2865
- priorities: [{ value: 4, label: 'Critical' }],
2866
- taxonomies: []
2867
- } : {
2868
- categories: [],
2869
- types: [],
2870
- priorities: [],
2871
- taxonomies: []
2872
- });
2873
- }
2874
- if (url.includes('/api/taskforce/global-settings'))
2875
- return jsonResponse({});
2876
- if (url.includes('/api/taskforce/workspace/assignee-options')) {
2877
- requestOrder.push('assignee');
2878
- return jsonResponse({ assignees: [] });
2879
- }
2880
- if (url.includes('/api/taskforce/auth/workspace-members'))
2881
- return jsonResponse({ users: [] });
2882
- if (url.includes('/api/taskforce/planning/bootstrap')) {
2883
- requestOrder.push('planning');
2884
- return jsonResponse({ initiatives: [], workstreams: [], workstreamTaskSummaries: [] });
2885
- }
2886
- if (url.includes('/api/taskforce/tasks'))
2887
- return jsonResponse({ tasks: [activeTask] });
2888
- if (url.includes('/api/taskforce/archive'))
2889
- return jsonResponse({ archived: [] });
2890
- if (url.includes('/api/taskforce/data-version'))
2891
- return jsonResponse({ dataVersion: 1 });
2892
- if (url.includes('/api/taskforce/build-info'))
2893
- return jsonResponse({});
2894
- return jsonResponse({});
2895
- }));
2896
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
2897
- await waitFor(() => {
2898
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
2899
- }, { timeout: 2500 });
2900
- await waitFor(() => {
2901
- expect(requestOrder.filter((entry) => entry === 'assignee')).toHaveLength(1);
2902
- }, { timeout: 2500 });
2903
- taxonomyReady = true;
2904
- requestOrder.length = 0;
2905
- await act(async () => {
2906
- await result.current.retryBootstrapChecks();
2907
- });
2908
- await waitFor(() => {
2909
- expect(result.current.activeCategories.some((category) => category.value === 'cloud-ops')).toBe(true);
2910
- expect(requestOrder).toContain('planning');
2911
- }, { timeout: 2500 });
2912
- expect(requestOrder).not.toContain('assignee');
2913
- });
2914
- it('hydrates merged human members and workspace ai assignees for a signed-in local workspace', async () => {
2915
- vi.stubGlobal('fetch', vi.fn((url) => {
2916
- if (url.includes('/api/taskforce/auth/runtime-config')) {
2917
- return jsonResponse({
2918
- config: {
2919
- runtimeMode: 'local',
2920
- workspaceMode: 'single-local',
2921
- authSource: 'cloud',
2922
- workspaceSwitchingEnabled: false
2923
- }
2924
- });
2925
- }
2926
- if (url.includes('/api/taskforce/auth/session')) {
2927
- return jsonResponse({
2928
- authenticated: true,
2929
- authRequiredForApi: true,
2930
- betaAccess: true,
2931
- userId: 'user-1',
2932
- email: 'user@example.com',
2933
- avatarUrl: '/api/taskforce/context/users%2Fuser-1%2Fprofile%2Favatar%2Fheadshot.webp',
2934
- workspaceId: 'workspace-cloud-1'
2935
- });
2936
- }
2937
- if (url.includes('/api/taskforce/ui-state?key=app')) {
2938
- return jsonResponse({ success: true, state: {} });
2939
- }
2940
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
2941
- return jsonResponse({
2942
- success: true,
2943
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
2944
- });
2945
- }
2946
- if (url.includes('/api/taskforce/config')) {
2947
- return jsonResponse({
2948
- projectName: 'Cloud Project',
2949
- workspaceId: 'workspace-cloud-1',
2950
- runtimeMode: 'cloud',
2951
- authRequiredForApi: true,
2952
- userId: 'user-1',
2953
- setupState: {
2954
- globalSetupState: 'complete',
2955
- workspaceSetupState: 'complete',
2956
- workspaceId: 'workspace-cloud-1'
2957
- }
2958
- });
2959
- }
2960
- if (url.includes('/api/taskforce/global-settings'))
2961
- return jsonResponse({});
2962
- if (url.includes('/api/taskforce/auth/workspace-members')) {
2963
- return jsonResponse({
2964
- users: [
2965
- {
2966
- userId: 'user-1',
2967
- email: 'user@example.com',
2968
- displayName: 'Signed In Owner',
2969
- role: 'owner',
2970
- status: 'active',
2971
- disabled: false
2972
- },
2973
- {
2974
- userId: 'member-1',
2975
- email: 'member1@example.com',
2976
- displayName: 'Member One',
2977
- status: 'active',
2978
- disabled: false
2979
- }
2980
- ]
2981
- });
2982
- }
2983
- if (url.includes('/api/taskforce/categories'))
2984
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
2985
- if (url.includes('/api/taskforce/types'))
2986
- return jsonResponse({ types: [] });
2987
- if (url.includes('/api/taskforce/priorities'))
2988
- return jsonResponse({ priorities: [] });
2989
- if (url.includes('/api/taskforce/approaches'))
2990
- return jsonResponse({ approaches: [] });
2991
- if (url.includes('/api/taskforce/specialists'))
2992
- return jsonResponse({ specialists: [] });
2993
- if (url.includes('/api/taskforce/tasks'))
2994
- return jsonResponse({ tasks: [activeTask] });
2995
- if (url.includes('/api/taskforce/archive'))
2996
- return jsonResponse({ archived: [] });
2997
- if (url.includes('/api/taskforce/workspace/assignee-options')) {
2998
- return jsonResponse({
2999
- assignees: [
3000
- { value: 'ai-profile-codex', label: 'Codex', icon: 'Bot', color: '#0ea5e9', kind: 'agent' }
3001
- ]
3002
- });
3003
- }
3004
- if (url.includes('/api/taskforce/data-version'))
3005
- return jsonResponse({ dataVersion: 1 });
3006
- return jsonResponse({});
3007
- }));
3008
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
3009
- await waitFor(() => {
3010
- expect(result.current.assigneeOptions.some((option) => option.value === 'member-1' && option.label === 'Member One')).toBe(true);
3011
- expect(result.current.assigneeOptions.find((option) => option.value === 'user-1')).toEqual(expect.objectContaining({
3012
- label: 'Signed In Owner',
3013
- avatarUrl: '/api/taskforce/context/users%2Fuser-1%2Fprofile%2Favatar%2Fheadshot.webp'
3014
- }));
3015
- expect(result.current.assigneeOptions.some((option) => option.value === 'ai-profile-codex' && option.label === 'Codex')).toBe(true);
3016
- expect(result.current.currentWorkspaceRole).toBe('owner');
3017
- });
3018
- });
3019
- it('keeps human assignees unavailable while signed out locally but still loads ai assignees', async () => {
3020
- vi.stubGlobal('fetch', vi.fn((url) => {
3021
- if (url.includes('/api/taskforce/auth/runtime-config')) {
3022
- return jsonResponse({
3023
- config: {
3024
- runtimeMode: 'local',
3025
- workspaceMode: 'single-local',
3026
- authSource: 'cloud',
3027
- workspaceSwitchingEnabled: false
3028
- }
3029
- });
3030
- }
3031
- if (url.includes('/api/taskforce/auth/session')) {
3032
- return jsonResponse({
3033
- authenticated: false,
3034
- authRequiredForApi: true,
3035
- betaAccess: false,
3036
- userId: 'anonymous',
3037
- email: '',
3038
- workspaceId: 'workspace-cloud-1'
3039
- });
3040
- }
3041
- if (url.includes('/api/taskforce/ui-state?key=app'))
3042
- return jsonResponse({ success: true, state: {} });
3043
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
3044
- return jsonResponse({
3045
- success: true,
3046
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
3047
- });
3048
- }
3049
- if (url.includes('/api/taskforce/config')) {
3050
- return jsonResponse({
3051
- projectName: 'Local Project',
3052
- workspaceId: 'workspace-cloud-1',
3053
- runtimeMode: 'local',
3054
- authRequiredForApi: true,
3055
- setupState: {
3056
- globalSetupState: 'complete',
3057
- workspaceSetupState: 'complete',
3058
- workspaceId: 'workspace-cloud-1'
3059
- }
3060
- });
3061
- }
3062
- if (url.includes('/api/taskforce/global-settings'))
3063
- return jsonResponse({});
3064
- if (url.includes('/api/taskforce/categories'))
3065
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
3066
- if (url.includes('/api/taskforce/types'))
3067
- return jsonResponse({ types: [] });
3068
- if (url.includes('/api/taskforce/priorities'))
3069
- return jsonResponse({ priorities: [] });
3070
- if (url.includes('/api/taskforce/approaches'))
3071
- return jsonResponse({ approaches: [] });
3072
- if (url.includes('/api/taskforce/specialists'))
3073
- return jsonResponse({ specialists: [] });
3074
- if (url.includes('/api/taskforce/tasks'))
3075
- return jsonResponse({ tasks: [activeTask] });
3076
- if (url.includes('/api/taskforce/archive'))
3077
- return jsonResponse({ archived: [] });
3078
- if (url.includes('/api/taskforce/workspace/assignee-options')) {
3079
- return jsonResponse({
3080
- assignees: [
3081
- { value: 'ai-profile-codex', label: 'Codex', icon: 'Bot', color: '#0ea5e9', kind: 'agent' }
3082
- ]
3083
- });
3084
- }
3085
- if (url.includes('/api/taskforce/data-version'))
3086
- return jsonResponse({ dataVersion: 1 });
3087
- return jsonResponse({});
3088
- }));
3089
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
3090
- await waitFor(() => {
3091
- expect(result.current.assigneeOptions.some((option) => option.value === 'ai-profile-codex' && option.label === 'Codex')).toBe(true);
3092
- expect(result.current.assigneeOptions.some((option) => option.kind === 'member')).toBe(false);
3093
- expect(result.current.currentWorkspaceRole).toBeNull();
3094
- });
3095
- });
3096
- it('keeps fallback human assignees when workspace-members only returns the signed-in user', async () => {
3097
- vi.stubGlobal('fetch', vi.fn((url) => {
3098
- if (url.includes('/api/taskforce/auth/runtime-config')) {
3099
- return jsonResponse({
3100
- config: {
3101
- runtimeMode: 'cloud',
3102
- workspaceMode: 'multi-cloud',
3103
- authSource: 'cloud',
3104
- workspaceSwitchingEnabled: true
3105
- }
3106
- });
3107
- }
3108
- if (url.includes('/api/taskforce/auth/session')) {
3109
- return jsonResponse({
3110
- authenticated: true,
3111
- authRequiredForApi: true,
3112
- betaAccess: true,
3113
- userId: 'member-self',
3114
- email: 'self@example.com',
3115
- workspaceId: 'workspace-cloud-1'
3116
- });
3117
- }
3118
- if (url.includes('/api/taskforce/ui-state?key=app'))
3119
- return jsonResponse({ success: true, state: {} });
3120
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
3121
- return jsonResponse({
3122
- success: true,
3123
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
3124
- });
3125
- }
3126
- if (url.includes('/api/taskforce/config')) {
3127
- return jsonResponse({
3128
- projectName: 'Cloud Project',
3129
- workspaceId: 'workspace-cloud-1',
3130
- runtimeMode: 'cloud',
3131
- authRequiredForApi: true,
3132
- userId: 'member-self',
3133
- setupState: {
3134
- globalSetupState: 'complete',
3135
- workspaceSetupState: 'complete',
3136
- workspaceId: 'workspace-cloud-1'
3137
- }
3138
- });
3139
- }
3140
- if (url.includes('/api/taskforce/global-settings'))
3141
- return jsonResponse({});
3142
- if (url.includes('/api/taskforce/auth/workspace-members')) {
3143
- return jsonResponse({
3144
- users: [
3145
- {
3146
- userId: 'member-self',
3147
- email: 'self@example.com',
3148
- displayName: 'Self User',
3149
- status: 'active',
3150
- disabled: false
3151
- }
3152
- ]
3153
- });
3154
- }
3155
- if (url.includes('/api/taskforce/categories'))
3156
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
3157
- if (url.includes('/api/taskforce/types'))
3158
- return jsonResponse({ types: [] });
3159
- if (url.includes('/api/taskforce/priorities'))
3160
- return jsonResponse({ priorities: [] });
3161
- if (url.includes('/api/taskforce/approaches'))
3162
- return jsonResponse({ approaches: [] });
3163
- if (url.includes('/api/taskforce/specialists'))
3164
- return jsonResponse({ specialists: [] });
3165
- if (url.includes('/api/taskforce/tasks'))
3166
- return jsonResponse({ tasks: [activeTask] });
3167
- if (url.includes('/api/taskforce/archive'))
3168
- return jsonResponse({ archived: [] });
3169
- if (url.includes('/api/taskforce/workspace/assignee-options')) {
3170
- return jsonResponse({
3171
- assignees: [
3172
- { userId: 'member-self', email: 'self@example.com', displayName: 'Self User', status: 'active', disabled: false },
3173
- { userId: 'member-2', email: 'member2@example.com', displayName: 'Member Two', status: 'active', disabled: false },
3174
- { value: 'ai-profile-codex', label: 'Codex', icon: 'Bot', color: '#0ea5e9', kind: 'agent' }
3175
- ]
3176
- });
3177
- }
3178
- if (url.includes('/api/taskforce/data-version'))
3179
- return jsonResponse({ dataVersion: 1 });
3180
- return jsonResponse({});
3181
- }));
3182
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
3183
- await waitFor(() => {
3184
- expect(result.current.assigneeOptions.some((option) => option.value === 'member-self' && option.label === 'Self User')).toBe(true);
3185
- expect(result.current.assigneeOptions.some((option) => option.value === 'member-2' && option.label === 'Member Two')).toBe(true);
3186
- expect(result.current.assigneeOptions.some((option) => option.value === 'ai-profile-codex' && option.label === 'Codex')).toBe(true);
3187
- });
3188
- });
3189
- it('keeps the local hydrated workspace role when workspace-members temporarily fails', async () => {
3190
- let workspaceMembersCalls = 0;
3191
- vi.stubGlobal('fetch', vi.fn((url) => {
3192
- if (url.includes('/api/taskforce/auth/runtime-config')) {
3193
- return jsonResponse({
3194
- config: {
3195
- runtimeMode: 'local',
3196
- workspaceMode: 'single-local',
3197
- authSource: 'cloud',
3198
- workspaceSwitchingEnabled: false
3199
- }
3200
- });
3201
- }
3202
- if (url.includes('/api/taskforce/auth/session')) {
3203
- return jsonResponse({
3204
- authenticated: true,
3205
- authRequiredForApi: true,
3206
- betaAccess: true,
3207
- userId: 'user-1',
3208
- email: 'user@example.com',
3209
- workspaceId: 'workspace-cloud-1'
3210
- });
3211
- }
3212
- if (url.includes('/api/taskforce/ui-state?key=app'))
3213
- return jsonResponse({ success: true, state: {} });
3214
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
3215
- return jsonResponse({
3216
- success: true,
3217
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
3218
- });
3219
- }
3220
- if (url.includes('/api/taskforce/config')) {
3221
- return jsonResponse({
3222
- projectName: 'Local Project',
3223
- workspaceId: 'workspace-cloud-1',
3224
- runtimeMode: 'local',
3225
- authRequiredForApi: true,
3226
- userId: 'user-1',
3227
- setupState: {
3228
- globalSetupState: 'complete',
3229
- workspaceSetupState: 'complete',
3230
- workspaceId: 'workspace-cloud-1'
3231
- }
3232
- });
3233
- }
3234
- if (url.includes('/api/taskforce/global-settings'))
3235
- return jsonResponse({});
3236
- if (url.includes('/api/taskforce/categories'))
3237
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
3238
- if (url.includes('/api/taskforce/types'))
3239
- return jsonResponse({ types: [] });
3240
- if (url.includes('/api/taskforce/priorities'))
3241
- return jsonResponse({ priorities: [] });
3242
- if (url.includes('/api/taskforce/approaches'))
3243
- return jsonResponse({ approaches: [] });
3244
- if (url.includes('/api/taskforce/specialists'))
3245
- return jsonResponse({ specialists: [] });
3246
- if (url.includes('/api/taskforce/tasks'))
3247
- return jsonResponse({ tasks: [activeTask] });
3248
- if (url.includes('/api/taskforce/archive'))
3249
- return jsonResponse({ archived: [] });
3250
- if (url.includes('/api/taskforce/workspace/assignee-options')) {
3251
- return jsonResponse({
3252
- assignees: [
3253
- { value: 'member-1', label: 'Member One', icon: 'User', color: '#22c55e', kind: 'member', userId: 'member-1', email: 'member1@example.com' }
3254
- ]
3255
- });
3256
- }
3257
- if (url.includes('/api/taskforce/auth/workspace-members')) {
3258
- workspaceMembersCalls += 1;
3259
- if (workspaceMembersCalls === 1) {
3260
- return jsonResponse({
3261
- users: [
3262
- {
3263
- userId: 'user-1',
3264
- email: 'user@example.com',
3265
- displayName: 'Signed In Owner',
3266
- role: 'owner',
3267
- status: 'active',
3268
- disabled: false
3269
- }
3270
- ]
3271
- });
3272
- }
3273
- return Promise.reject(new Error('temporary workspace-members failure'));
3274
- }
3275
- if (url.includes('/api/taskforce/data-version'))
3276
- return jsonResponse({ dataVersion: 1 });
3277
- return jsonResponse({});
3278
- }));
3279
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
3280
- await waitFor(() => {
3281
- expect(result.current.currentWorkspaceRole).toBe('owner');
3282
- });
3283
- await act(async () => {
3284
- await result.current.fetchAssigneeOptions();
3285
- });
3286
- expect(result.current.currentWorkspaceRole).toBe('owner');
3287
- });
3288
- it('seeds local auth state from the persisted loopback actor while localhost session bootstrap is in flight', async () => {
3289
- sessionStorage.setItem('taskforce.localMutationActorUserId.v1', 'user-1');
3290
- const fetchMock = vi.fn((url) => {
3291
- if (url.includes('/api/taskforce/auth/runtime-config')) {
3292
- return jsonResponse({
3293
- config: {
3294
- runtimeMode: 'local',
3295
- workspaceMode: 'single-local',
3296
- authSource: 'cloud',
3297
- workspaceSwitchingEnabled: false,
3298
- cloudAuthBaseUrl: 'https://app.taskforcehq.ai',
3299
- cloudAuthViaLocalProxy: true
3300
- }
3301
- });
3302
- }
3303
- if (url.includes('/api/taskforce/auth/session')) {
3304
- return jsonResponse({
3305
- authenticated: true,
3306
- authRequiredForApi: true,
3307
- betaAccess: true,
3308
- userId: 'user-1',
3309
- email: 'user@example.com',
3310
- workspaceId: 'workspace-cloud-1'
3311
- });
3312
- }
3313
- if (url.includes('/api/taskforce/ui-state?key=app'))
3314
- return jsonResponse({ success: true, state: {} });
3315
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
3316
- return jsonResponse({
3317
- success: true,
3318
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
3319
- });
3320
- }
3321
- if (url.includes('/api/taskforce/config')) {
3322
- return jsonResponse({
3323
- projectName: 'Local Project',
3324
- workspaceId: 'workspace-cloud-1',
3325
- runtimeMode: 'local',
3326
- setupState: {
3327
- globalSetupState: 'complete',
3328
- workspaceSetupState: 'complete',
3329
- workspaceId: 'workspace-cloud-1'
3330
- }
3331
- });
3332
- }
3333
- if (url.includes('/api/taskforce/global-settings'))
3334
- return jsonResponse({});
3335
- if (url.includes('/api/taskforce/categories'))
3336
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
3337
- if (url.includes('/api/taskforce/types'))
3338
- return jsonResponse({ types: [] });
3339
- if (url.includes('/api/taskforce/priorities'))
3340
- return jsonResponse({ priorities: [] });
3341
- if (url.includes('/api/taskforce/approaches'))
3342
- return jsonResponse({ approaches: [] });
3343
- if (url.includes('/api/taskforce/specialists'))
3344
- return jsonResponse({ specialists: [] });
3345
- if (url.includes('/api/taskforce/tasks'))
3346
- return jsonResponse({ tasks: [activeTask] });
3347
- if (url.includes('/api/taskforce/archive'))
3348
- return jsonResponse({ archived: [] });
3349
- if (url.includes('/api/taskforce/workspace/assignee-options'))
3350
- return jsonResponse({ assignees: [] });
3351
- if (url.includes('/api/taskforce/data-version'))
3352
- return jsonResponse({ dataVersion: 1 });
3353
- return jsonResponse({});
3354
- });
3355
- vi.stubGlobal('fetch', fetchMock);
3356
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://app.taskforcehq.ai' } }), { wrapper });
3357
- expect(result.current.isAuthenticated).toBe(true);
3358
- expect(result.current.authSessionResolved).toBe(true);
3359
- await waitFor(() => {
3360
- expect(fetchMock.mock.calls.some(([url]) => String(url).includes('/api/taskforce/auth/session'))).toBe(true);
3361
- });
3362
- await waitFor(() => {
3363
- expect(result.current.isAuthenticated).toBe(true);
3364
- expect(result.current.authSessionResolved).toBe(true);
3365
- });
3366
- });
3367
- it('keeps loopback cloud runtime auth on same-origin after runtime config resolves', async () => {
3368
- const fetchMock = vi.fn((url) => {
3369
- if (url.includes('/api/taskforce/auth/runtime-config')) {
3370
- return jsonResponse({
3371
- config: {
3372
- runtimeMode: 'cloud',
3373
- workspaceMode: 'multi-cloud',
3374
- authSource: 'cloud',
3375
- workspaceSwitchingEnabled: true
3376
- }
3377
- });
3378
- }
3379
- if (url.startsWith('https://app.taskforcehq.ai/api/taskforce/auth/session')) {
3380
- return jsonResponse({ authenticated: false, authRequiredForApi: true }, 401);
3381
- }
3382
- if (url.includes('/api/taskforce/auth/session')) {
3383
- return jsonResponse({
3384
- authenticated: true,
3385
- authRequiredForApi: true,
3386
- betaAccess: true,
3387
- userId: 'user-1',
3388
- email: 'user@example.com',
3389
- workspaceId: 'workspace-cloud-1'
3390
- });
3391
- }
3392
- if (url.includes('/api/taskforce/ui-state?key=app'))
3393
- return jsonResponse({ success: true, state: {} });
3394
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
3395
- return jsonResponse({
3396
- success: true,
3397
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
3398
- });
3399
- }
3400
- if (url.includes('/api/taskforce/config')) {
3401
- return jsonResponse({
3402
- projectName: 'Loopback Cloud Project',
3403
- workspaceId: 'workspace-cloud-1',
3404
- runtimeMode: 'cloud',
3405
- authRequiredForApi: true,
3406
- userId: 'user-1',
3407
- setupState: {
3408
- globalSetupState: 'complete',
3409
- workspaceSetupState: 'complete',
3410
- workspaceId: 'workspace-cloud-1'
3411
- }
3412
- });
3413
- }
3414
- if (url.includes('/api/taskforce/global-settings'))
3415
- return jsonResponse({});
3416
- if (url.includes('/api/taskforce/categories'))
3417
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
3418
- if (url.includes('/api/taskforce/types'))
3419
- return jsonResponse({ types: [] });
3420
- if (url.includes('/api/taskforce/priorities'))
3421
- return jsonResponse({ priorities: [] });
3422
- if (url.includes('/api/taskforce/approaches'))
3423
- return jsonResponse({ approaches: [] });
3424
- if (url.includes('/api/taskforce/specialists'))
3425
- return jsonResponse({ specialists: [] });
3426
- if (url.includes('/api/taskforce/tasks'))
3427
- return jsonResponse({ tasks: [activeTask] });
3428
- if (url.includes('/api/taskforce/archive'))
3429
- return jsonResponse({ archived: [] });
3430
- if (url.includes('/api/taskforce/workspace/assignee-options'))
3431
- return jsonResponse({ assignees: [] });
3432
- if (url.includes('/api/taskforce/data-version'))
3433
- return jsonResponse({ dataVersion: 1 });
3434
- return jsonResponse({});
3435
- });
3436
- vi.stubGlobal('fetch', fetchMock);
3437
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://app.taskforcehq.ai' } }), { wrapper });
3438
- await waitFor(() => {
3439
- expect(result.current.authSessionResolved).toBe(true);
3440
- expect(result.current.isAuthenticated).toBe(true);
3441
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
3442
- });
3443
- expect(fetchMock.mock.calls.some(([url]) => String(url).startsWith('https://app.taskforcehq.ai/api/taskforce/auth/session'))).toBe(false);
3444
- });
3445
- it('enables cloud realtime refresh for authenticated sessions and refreshes open task comments from signals', async () => {
3446
- vi.stubGlobal('WebSocket', MockWebSocket);
3447
- let invalidationTaskFetchCount = 0;
3448
- const fetchMock = vi.fn((url) => {
3449
- if (url.includes('/api/taskforce/auth/runtime-config')) {
3450
- return jsonResponse({
3451
- config: {
3452
- runtimeMode: 'cloud',
3453
- workspaceMode: 'multi-cloud',
3454
- authSource: 'cloud',
3455
- workspaceSwitchingEnabled: true,
3456
- wsBaseUrl: 'https://cloud.example.com'
3457
- }
3458
- });
3459
- }
3460
- if (url.includes('/api/taskforce/auth/session')) {
3461
- return jsonResponse({
3462
- authenticated: true,
3463
- authRequiredForApi: true,
3464
- betaAccess: true,
3465
- userId: 'user-1',
3466
- email: 'user@example.com',
3467
- workspaceId: 'workspace-cloud-1'
3468
- });
3469
- }
3470
- if (url.includes('/api/taskforce/ui-state?key=app')) {
3471
- return jsonResponse({ success: true, state: {} });
3472
- }
3473
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
3474
- return jsonResponse({
3475
- success: true,
3476
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
3477
- });
3478
- }
3479
- if (url.includes('/api/taskforce/config')) {
3480
- return jsonResponse({
3481
- projectName: 'Cloud Project',
3482
- workspaceId: 'workspace-cloud-1',
3483
- runtimeMode: 'cloud',
3484
- authRequiredForApi: true,
3485
- userId: 'user-1',
3486
- setupState: {
3487
- globalSetupState: 'complete',
3488
- workspaceSetupState: 'complete',
3489
- workspaceId: 'workspace-cloud-1'
3490
- }
3491
- });
3492
- }
3493
- if (url.includes('/api/taskforce/global-settings'))
3494
- return jsonResponse({});
3495
- if (url.includes('/api/taskforce/categories'))
3496
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
3497
- if (url.includes('/api/taskforce/types'))
3498
- return jsonResponse({ types: [] });
3499
- if (url.includes('/api/taskforce/priorities'))
3500
- return jsonResponse({ priorities: [] });
3501
- if (url.includes('/api/taskforce/approaches'))
3502
- return jsonResponse({ approaches: [] });
3503
- if (url.includes('/api/taskforce/specialists'))
3504
- return jsonResponse({ specialists: [] });
3505
- if (url.includes('/api/taskforce/tasks')) {
3506
- const serveUpdatedTask = invalidationTaskFetchCount >= 2;
3507
- if (invalidationTaskFetchCount > 0) {
3508
- invalidationTaskFetchCount += 1;
3509
- }
3510
- const updatedAt = serveUpdatedTask ? '2026-03-16T10:05:00.000Z' : '2026-03-16T10:00:00.000Z';
3511
- const comments = serveUpdatedTask
3512
- ? [{ id: 'comment-2', author: 'user', text: 'Fresh synced comment', timestamp: '2026-03-16T10:05:00.000Z' }]
3513
- : [{ id: 'comment-1', author: 'user', text: 'Initial comment', timestamp: '2026-03-16T10:00:00.000Z' }];
3514
- return jsonResponse({
3515
- tasks: [{
3516
- ...activeTask,
3517
- updatedAt,
3518
- comments
3519
- }]
3520
- });
3521
- }
3522
- if (url.includes('/api/taskforce/archive'))
3523
- return jsonResponse({ archived: [] });
3524
- if (url.includes('/api/taskforce/data-version'))
3525
- return jsonResponse({ dataVersion: 1 });
3526
- return jsonResponse({});
3527
- });
3528
- vi.stubGlobal('fetch', fetchMock);
3529
- const { result } = renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
3530
- await waitFor(() => {
3531
- expect(result.current.tasks).toHaveLength(1);
3532
- });
3533
- await waitFor(() => {
3534
- expect(result.current.authSessionResolved).toBe(true);
3535
- expect(result.current.isAuthenticated).toBe(true);
3536
- expect(result.current.currentWorkspaceId).toBe('workspace-cloud-1');
3537
- expect(MockWebSocket.instances).toHaveLength(1);
3538
- });
3539
- const socket = MockWebSocket.instances[0];
3540
- act(() => {
3541
- socket.open();
3542
- result.current.handleEdit(result.current.tasks[0]);
3543
- });
3544
- await waitFor(() => {
3545
- expect(result.current.comments).toEqual([
3546
- { id: 'comment-1', author: 'user', text: 'Initial comment', timestamp: '2026-03-16T10:00:00.000Z' }
3547
- ]);
3548
- });
3549
- act(() => {
3550
- result.current.setNewCommentText('Unsaved draft');
3551
- invalidationTaskFetchCount = 1;
3552
- socket.message({ type: 'taskforce:update', workspaceId: 'workspace-cloud-1' });
3553
- });
3554
- await waitFor(() => {
3555
- expect(result.current.comments).toEqual([
3556
- { id: 'comment-1', author: 'user', text: 'Initial comment', timestamp: '2026-03-16T10:00:00.000Z' }
3557
- ]);
3558
- });
3559
- await act(async () => {
3560
- await new Promise((resolve) => setTimeout(resolve, 350));
3561
- });
3562
- await waitFor(() => {
3563
- expect(result.current.comments).toEqual([
3564
- { id: 'comment-2', author: 'user', text: 'Fresh synced comment', timestamp: '2026-03-16T10:05:00.000Z' }
3565
- ]);
3566
- expect(result.current.currentTask?.updatedAt).toBe('2026-03-16T10:05:00.000Z');
3567
- expect(result.current.newCommentText).toBe('Unsaved draft');
3568
- });
3569
- const taskFetches = fetchMock.mock.calls.filter(([url]) => String(url).includes('/api/taskforce/tasks'));
3570
- expect(taskFetches.length).toBeGreaterThanOrEqual(3);
3571
- });
3572
- it('does not start cloud realtime before auth session resolves with a real user id', async () => {
3573
- vi.stubGlobal('WebSocket', MockWebSocket);
3574
- vi.stubGlobal('fetch', vi.fn((url) => {
3575
- if (url.includes('/api/taskforce/auth/runtime-config')) {
3576
- return jsonResponse({
3577
- config: {
3578
- runtimeMode: 'cloud',
3579
- workspaceMode: 'multi-cloud',
3580
- authSource: 'cloud',
3581
- workspaceSwitchingEnabled: true,
3582
- wsBaseUrl: 'https://cloud.example.com'
3583
- }
3584
- });
3585
- }
3586
- if (url.includes('/api/taskforce/auth/session')) {
3587
- return jsonResponse({
3588
- authenticated: false,
3589
- authRequiredForApi: true,
3590
- betaAccess: true,
3591
- userId: 'anonymous',
3592
- email: '',
3593
- workspaceId: 'workspace-cloud-1'
3594
- });
3595
- }
3596
- if (url.includes('/api/taskforce/ui-state?key=app'))
3597
- return jsonResponse({ success: true, state: {} });
3598
- if (url.includes('/api/taskforce/ui-state?key=workspace-sync')) {
3599
- return jsonResponse({
3600
- success: true,
3601
- state: { version: 2, enabled: false, phase: 'idle', pullCursor: null }
3602
- });
3603
- }
3604
- if (url.includes('/api/taskforce/config')) {
3605
- return jsonResponse({
3606
- projectName: 'Cloud Project',
3607
- workspaceId: 'workspace-cloud-1',
3608
- runtimeMode: 'cloud',
3609
- authRequiredForApi: true,
3610
- realtimeSyncEnabled: true,
3611
- userId: 'anonymous',
3612
- setupState: {
3613
- globalSetupState: 'complete',
3614
- workspaceSetupState: 'complete',
3615
- workspaceId: 'workspace-cloud-1'
3616
- }
3617
- });
3618
- }
3619
- if (url.includes('/api/taskforce/global-settings'))
3620
- return jsonResponse({});
3621
- if (url.includes('/api/taskforce/categories'))
3622
- return jsonResponse({ categories: [{ value: 'general', label: 'General' }] });
3623
- if (url.includes('/api/taskforce/types'))
3624
- return jsonResponse({ types: [] });
3625
- if (url.includes('/api/taskforce/priorities'))
3626
- return jsonResponse({ priorities: [] });
3627
- if (url.includes('/api/taskforce/approaches'))
3628
- return jsonResponse({ approaches: [] });
3629
- if (url.includes('/api/taskforce/specialists'))
3630
- return jsonResponse({ specialists: [] });
3631
- if (url.includes('/api/taskforce/tasks'))
3632
- return jsonResponse({ tasks: [activeTask] });
3633
- if (url.includes('/api/taskforce/archive'))
3634
- return jsonResponse({ archived: [] });
3635
- if (url.includes('/api/taskforce/data-version'))
3636
- return jsonResponse({ dataVersion: 1 });
3637
- return jsonResponse({});
3638
- }));
3639
- renderHook(() => useTaskforce({ config: { cloudAuthBaseUrl: 'https://cloud.example.com' } }), { wrapper });
3640
- await waitFor(() => {
3641
- expect(MockWebSocket.instances).toHaveLength(0);
3642
- });
3643
- });
3644
- });