@critical-path/core 0.35.0 → 0.36.1

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 (187) hide show
  1. package/README.md +11 -0
  2. package/dist/engine/index.d.ts +2 -0
  3. package/dist/engine/index.d.ts.map +1 -1
  4. package/dist/engine/index.js +25 -2
  5. package/dist/engine/index.js.map +1 -1
  6. package/dist/types/index.d.ts +11 -0
  7. package/dist/types/index.d.ts.map +1 -1
  8. package/package.json +5 -1
  9. package/CHANGELOG.md +0 -584
  10. package/dist/deliverables.test.d.ts +0 -2
  11. package/dist/deliverables.test.d.ts.map +0 -1
  12. package/dist/deliverables.test.js +0 -232
  13. package/dist/deliverables.test.js.map +0 -1
  14. package/dist/domain/calendar.test.d.ts +0 -2
  15. package/dist/domain/calendar.test.d.ts.map +0 -1
  16. package/dist/domain/calendar.test.js +0 -181
  17. package/dist/domain/calendar.test.js.map +0 -1
  18. package/dist/domain/cpm.test.d.ts +0 -2
  19. package/dist/domain/cpm.test.d.ts.map +0 -1
  20. package/dist/domain/cpm.test.js +0 -166
  21. package/dist/domain/cpm.test.js.map +0 -1
  22. package/dist/domain/ddd.test.d.ts +0 -2
  23. package/dist/domain/ddd.test.d.ts.map +0 -1
  24. package/dist/domain/ddd.test.js +0 -349
  25. package/dist/domain/ddd.test.js.map +0 -1
  26. package/dist/domain/ladder.test.d.ts +0 -2
  27. package/dist/domain/ladder.test.d.ts.map +0 -1
  28. package/dist/domain/ladder.test.js +0 -213
  29. package/dist/domain/ladder.test.js.map +0 -1
  30. package/dist/domain/metrics.test.d.ts +0 -2
  31. package/dist/domain/metrics.test.d.ts.map +0 -1
  32. package/dist/domain/metrics.test.js +0 -252
  33. package/dist/domain/metrics.test.js.map +0 -1
  34. package/dist/domain/task-duration.test.d.ts +0 -2
  35. package/dist/domain/task-duration.test.d.ts.map +0 -1
  36. package/dist/domain/task-duration.test.js +0 -307
  37. package/dist/domain/task-duration.test.js.map +0 -1
  38. package/dist/domain/workload.test.d.ts +0 -2
  39. package/dist/domain/workload.test.d.ts.map +0 -1
  40. package/dist/domain/workload.test.js +0 -261
  41. package/dist/domain/workload.test.js.map +0 -1
  42. package/dist/engine/actor.test.d.ts +0 -2
  43. package/dist/engine/actor.test.d.ts.map +0 -1
  44. package/dist/engine/actor.test.js +0 -54
  45. package/dist/engine/actor.test.js.map +0 -1
  46. package/dist/engine/authorization.test.d.ts +0 -2
  47. package/dist/engine/authorization.test.d.ts.map +0 -1
  48. package/dist/engine/authorization.test.js +0 -154
  49. package/dist/engine/authorization.test.js.map +0 -1
  50. package/dist/engine/cascade.test.d.ts +0 -2
  51. package/dist/engine/cascade.test.d.ts.map +0 -1
  52. package/dist/engine/cascade.test.js +0 -99
  53. package/dist/engine/cascade.test.js.map +0 -1
  54. package/dist/engine/config.test.d.ts +0 -2
  55. package/dist/engine/config.test.d.ts.map +0 -1
  56. package/dist/engine/config.test.js +0 -46
  57. package/dist/engine/config.test.js.map +0 -1
  58. package/dist/engine/entity-events.test.d.ts +0 -2
  59. package/dist/engine/entity-events.test.d.ts.map +0 -1
  60. package/dist/engine/entity-events.test.js +0 -61
  61. package/dist/engine/entity-events.test.js.map +0 -1
  62. package/dist/index.test.d.ts +0 -2
  63. package/dist/index.test.d.ts.map +0 -1
  64. package/dist/index.test.js +0 -429
  65. package/dist/index.test.js.map +0 -1
  66. package/dist/plugins/plugins.test.d.ts +0 -2
  67. package/dist/plugins/plugins.test.d.ts.map +0 -1
  68. package/dist/plugins/plugins.test.js +0 -137
  69. package/dist/plugins/plugins.test.js.map +0 -1
  70. package/dist/schemas/schemas.test.d.ts +0 -2
  71. package/dist/schemas/schemas.test.d.ts.map +0 -1
  72. package/dist/schemas/schemas.test.js +0 -58
  73. package/dist/schemas/schemas.test.js.map +0 -1
  74. package/dist/status.test.d.ts +0 -2
  75. package/dist/status.test.d.ts.map +0 -1
  76. package/dist/status.test.js +0 -295
  77. package/dist/status.test.js.map +0 -1
  78. package/dist/storage/storage.test.d.ts +0 -2
  79. package/dist/storage/storage.test.d.ts.map +0 -1
  80. package/dist/storage/storage.test.js +0 -236
  81. package/dist/storage/storage.test.js.map +0 -1
  82. package/dist/store/conformance.test.d.ts +0 -2
  83. package/dist/store/conformance.test.d.ts.map +0 -1
  84. package/dist/store/conformance.test.js +0 -15
  85. package/dist/store/conformance.test.js.map +0 -1
  86. package/dist/store/firebase.test.d.ts +0 -2
  87. package/dist/store/firebase.test.d.ts.map +0 -1
  88. package/dist/store/firebase.test.js +0 -103
  89. package/dist/store/firebase.test.js.map +0 -1
  90. package/dist/store/query.test.d.ts +0 -2
  91. package/dist/store/query.test.d.ts.map +0 -1
  92. package/dist/store/query.test.js +0 -89
  93. package/dist/store/query.test.js.map +0 -1
  94. package/dist/store/sqlite.test.d.ts +0 -2
  95. package/dist/store/sqlite.test.d.ts.map +0 -1
  96. package/dist/store/sqlite.test.js +0 -177
  97. package/dist/store/sqlite.test.js.map +0 -1
  98. package/dist/task-state.test.d.ts +0 -2
  99. package/dist/task-state.test.d.ts.map +0 -1
  100. package/dist/task-state.test.js +0 -423
  101. package/dist/task-state.test.js.map +0 -1
  102. package/dist/use-case-validation.test.d.ts +0 -2
  103. package/dist/use-case-validation.test.d.ts.map +0 -1
  104. package/dist/use-case-validation.test.js +0 -281
  105. package/dist/use-case-validation.test.js.map +0 -1
  106. package/dist/utils/fractional-index.test.d.ts +0 -2
  107. package/dist/utils/fractional-index.test.d.ts.map +0 -1
  108. package/dist/utils/fractional-index.test.js +0 -182
  109. package/dist/utils/fractional-index.test.js.map +0 -1
  110. package/dist/utils/key.test.d.ts +0 -2
  111. package/dist/utils/key.test.d.ts.map +0 -1
  112. package/dist/utils/key.test.js +0 -65
  113. package/dist/utils/key.test.js.map +0 -1
  114. package/dist/utils/mentions.test.d.ts +0 -2
  115. package/dist/utils/mentions.test.d.ts.map +0 -1
  116. package/dist/utils/mentions.test.js +0 -114
  117. package/dist/utils/mentions.test.js.map +0 -1
  118. package/dist/webhooks/webhooks.test.d.ts +0 -2
  119. package/dist/webhooks/webhooks.test.d.ts.map +0 -1
  120. package/dist/webhooks/webhooks.test.js +0 -154
  121. package/dist/webhooks/webhooks.test.js.map +0 -1
  122. package/src/deliverables.test.ts +0 -284
  123. package/src/domain/authorization.ts +0 -82
  124. package/src/domain/calendar.test.ts +0 -216
  125. package/src/domain/calendar.ts +0 -502
  126. package/src/domain/cpm.test.ts +0 -189
  127. package/src/domain/cpm.ts +0 -258
  128. package/src/domain/custom-fields.ts +0 -172
  129. package/src/domain/ddd.test.ts +0 -442
  130. package/src/domain/entities.ts +0 -798
  131. package/src/domain/errors.ts +0 -38
  132. package/src/domain/events.ts +0 -369
  133. package/src/domain/graph.ts +0 -70
  134. package/src/domain/index.ts +0 -12
  135. package/src/domain/ladder.test.ts +0 -251
  136. package/src/domain/ladder.ts +0 -474
  137. package/src/domain/metrics.test.ts +0 -288
  138. package/src/domain/metrics.ts +0 -497
  139. package/src/domain/task-duration.test.ts +0 -354
  140. package/src/domain/workload.test.ts +0 -311
  141. package/src/domain/workload.ts +0 -457
  142. package/src/engine/actor.test.ts +0 -63
  143. package/src/engine/authorization.test.ts +0 -199
  144. package/src/engine/cascade.test.ts +0 -121
  145. package/src/engine/config.test.ts +0 -51
  146. package/src/engine/entity-events.test.ts +0 -67
  147. package/src/engine/index.ts +0 -2472
  148. package/src/index.test.ts +0 -514
  149. package/src/index.ts +0 -9
  150. package/src/plugins/index.ts +0 -103
  151. package/src/plugins/plugins.test.ts +0 -161
  152. package/src/schemas/index.ts +0 -402
  153. package/src/schemas/schemas.test.ts +0 -116
  154. package/src/status.test.ts +0 -354
  155. package/src/storage/file-storage.ts +0 -200
  156. package/src/storage/firebase-storage.ts +0 -209
  157. package/src/storage/index.ts +0 -3
  158. package/src/storage/s3.ts +0 -151
  159. package/src/storage/storage.test.ts +0 -274
  160. package/src/store/conformance.test.ts +0 -15
  161. package/src/store/firebase.test.ts +0 -131
  162. package/src/store/firebase.ts +0 -658
  163. package/src/store/index.ts +0 -623
  164. package/src/store/query.test.ts +0 -110
  165. package/src/store/query.ts +0 -113
  166. package/src/store/sqlite.test.ts +0 -218
  167. package/src/store/sqlite.ts +0 -1480
  168. package/src/task-state.test.ts +0 -506
  169. package/src/testing/conformance.ts +0 -319
  170. package/src/testing/index.ts +0 -1
  171. package/src/types/index.ts +0 -859
  172. package/src/use-case-validation.test.ts +0 -324
  173. package/src/utils/fractional-index.test.ts +0 -228
  174. package/src/utils/fractional-index.ts +0 -254
  175. package/src/utils/index.ts +0 -7
  176. package/src/utils/key.test.ts +0 -76
  177. package/src/utils/key.ts +0 -62
  178. package/src/utils/mentions.test.ts +0 -132
  179. package/src/utils/mentions.ts +0 -131
  180. package/src/utils/status.ts +0 -419
  181. package/src/utils/workflow.ts +0 -306
  182. package/src/webhooks/dispatcher.ts +0 -190
  183. package/src/webhooks/index.ts +0 -2
  184. package/src/webhooks/signature.ts +0 -57
  185. package/src/webhooks/webhooks.test.ts +0 -201
  186. package/tsconfig.json +0 -8
  187. package/tsconfig.tsbuildinfo +0 -1
@@ -1,354 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { TaskEntity } from './entities.js';
3
- import { CriticalPathEngine } from '../engine/index.js';
4
- import { InMemoryStore } from '../store/index.js';
5
- import { SQLiteStore } from '../store/sqlite.js';
6
- import { DEFAULT_SOFTWARE_WORKFLOW } from '../utils/workflow.js';
7
-
8
- describe('Task Execution Timestamps & Cumulative In-Progress Duration', () => {
9
- it('stamps actualStartDate and inProgressSince when moving to in_progress', () => {
10
- const task = TaskEntity.create({
11
- projectId: 'proj_1',
12
- title: 'Implement Task Timestamps',
13
- status: 'todo'
14
- });
15
-
16
- expect(task.actualStartDate).toBeUndefined();
17
- expect(task.actualEndDate).toBeUndefined();
18
- expect(task.inProgressSince).toBeUndefined();
19
- expect(task.actualDurationSeconds).toBeUndefined();
20
-
21
- task.transitionTo('in_progress', DEFAULT_SOFTWARE_WORKFLOW);
22
-
23
- expect(task.actualStartDate).toBeDefined();
24
- expect(task.inProgressSince).toBeDefined();
25
- expect(task.actualEndDate).toBeUndefined();
26
- });
27
-
28
- it('accumulates in-progress duration across pause/resume cycles and retains earliest actualStartDate', async () => {
29
- vi.useFakeTimers();
30
- try {
31
- const now = new Date('2026-09-23T10:00:00Z');
32
- vi.setSystemTime(now);
33
-
34
- const task = TaskEntity.create({
35
- projectId: 'proj_1',
36
- title: 'Work Tracking',
37
- status: 'todo'
38
- });
39
-
40
- // 1. Start working at 10:00
41
- task.transitionTo('in_progress', DEFAULT_SOFTWARE_WORKFLOW);
42
- const initialStartDate = task.actualStartDate;
43
- expect(initialStartDate).toBe(now.toISOString());
44
- expect(task.inProgressSince).toBe(now.toISOString());
45
-
46
- // Fast-forward 30 minutes (1800s)
47
- vi.setSystemTime(new Date('2026-09-23T10:30:00Z'));
48
-
49
- // 2. Pause: move to todo
50
- task.transitionTo('todo', DEFAULT_SOFTWARE_WORKFLOW);
51
- expect(task.inProgressSince).toBeNull();
52
- expect(task.actualDurationSeconds).toBe(1800);
53
- expect(task.actualHours).toBe(0.5);
54
- expect(task.actualDurationMinutes).toBe(30);
55
- expect(task.actualStartDate).toBe(initialStartDate); // Retains earliest
56
-
57
- // Paused for 1 hour
58
- vi.setSystemTime(new Date('2026-09-23T11:30:00Z'));
59
-
60
- // 3. Resume: move back to in_progress
61
- task.transitionTo('in_progress', DEFAULT_SOFTWARE_WORKFLOW);
62
- expect(task.actualStartDate).toBe(initialStartDate); // Still retains earliest
63
- expect(task.inProgressSince).toBe(new Date('2026-09-23T11:30:00Z').toISOString());
64
- expect(task.actualDurationSeconds).toBe(1800); // Unchanged until leaving
65
-
66
- // Fast-forward another 45 minutes (2700s)
67
- vi.setSystemTime(new Date('2026-09-23T12:15:00Z'));
68
-
69
- // 4. Complete: move to done
70
- task.transitionTo('done', DEFAULT_SOFTWARE_WORKFLOW);
71
- expect(task.inProgressSince).toBeNull();
72
- // Total duration = 1800s + 2700s = 4500s = 1.25h
73
- expect(task.actualDurationSeconds).toBe(4500);
74
- expect(task.actualHours).toBe(1.25);
75
- expect(task.actualDurationMinutes).toBe(75);
76
- expect(task.actualStartDate).toBe(initialStartDate);
77
- expect(task.actualEndDate).toBe(new Date('2026-09-23T12:15:00Z').toISOString());
78
- expect(task.progress).toBe(100);
79
-
80
- // 5. Reopen: move from done to todo, then to in_progress
81
- vi.setSystemTime(new Date('2026-09-23T14:00:00Z'));
82
- task.transitionTo('todo', DEFAULT_SOFTWARE_WORKFLOW);
83
- expect(task.actualEndDate).toBeUndefined(); // Reset upon reopen
84
- expect(task.actualStartDate).toBe(initialStartDate); // Retains earliest
85
-
86
- vi.setSystemTime(new Date('2026-09-23T14:15:00Z'));
87
- task.transitionTo('in_progress', DEFAULT_SOFTWARE_WORKFLOW);
88
- expect(task.actualEndDate).toBeUndefined();
89
- expect(task.actualStartDate).toBe(initialStartDate); // Retains earliest
90
- expect(task.inProgressSince).toBe(new Date('2026-09-23T14:15:00Z').toISOString());
91
- } finally {
92
- vi.useRealTimers();
93
- }
94
- });
95
-
96
- it('keeps actualDurationSeconds and actualHours synchronized on manual updates', () => {
97
- const task = TaskEntity.create({
98
- projectId: 'proj_1',
99
- title: 'Manual Adjustments',
100
- status: 'todo'
101
- });
102
-
103
- // Update actualDurationSeconds directly
104
- task.update({ actualDurationSeconds: 7200 });
105
- expect(task.actualHours).toBe(2);
106
- expect(task.actualDurationMinutes).toBe(120);
107
-
108
- // Update actualHours directly
109
- task.update({ actualHours: 1.5 });
110
- expect(task.actualDurationSeconds).toBe(5400);
111
- expect(task.actualDurationMinutes).toBe(90);
112
- });
113
-
114
- it('integrates with CriticalPathEngine updateTask and metrics calculation', async () => {
115
- vi.useFakeTimers();
116
- try {
117
- const store = new InMemoryStore();
118
- const engine = new CriticalPathEngine({ store });
119
-
120
- const project = await engine.createProject({ name: 'Engine Duration Test' });
121
-
122
- vi.setSystemTime(new Date('2026-09-23T09:00:00Z'));
123
- const task = await engine.createTask({
124
- projectId: project.id,
125
- title: 'Build Feature',
126
- estimatedHours: 8
127
- });
128
-
129
- // 1. Move to in_progress
130
- const started = await engine.updateTask(task.id, { status: 'in_progress' });
131
- expect(started?.actualStartDate).toBe('2026-09-23T09:00:00.000Z');
132
- expect(started?.inProgressSince).toBe('2026-09-23T09:00:00.000Z');
133
- expect(started?.actualEndDate).toBeUndefined();
134
-
135
- // 2. Work for 2 hours (7200s), then move to todo (pause)
136
- vi.setSystemTime(new Date('2026-09-23T11:00:00Z'));
137
- const paused = await engine.updateTask(task.id, { status: 'todo' });
138
- expect(paused?.inProgressSince).toBeNull();
139
- expect(paused?.actualDurationSeconds).toBe(7200);
140
- expect(paused?.actualHours).toBe(2);
141
-
142
- // 3. Complete task at 14:00 (move from todo to done)
143
- vi.setSystemTime(new Date('2026-09-23T14:00:00Z'));
144
- const completed = await engine.updateTask(task.id, { status: 'done' });
145
- expect(completed?.actualEndDate).toBe('2026-09-23T14:00:00.000Z');
146
- // in-progress duration should still be 7200s (since time in todo was paused)
147
- expect(completed?.actualDurationSeconds).toBe(7200);
148
-
149
- // 4. Verify metrics calculation
150
- const metrics = await engine.getTaskMetrics(task.id);
151
- expect(metrics?.inferredActuals.actualDurationSeconds).toBe(7200);
152
- expect(metrics?.inferredActuals.activeWorkingHours).toBe(2);
153
- // Calendar duration: 09:00 to 14:00 = 5.0 hours
154
- expect(metrics?.inferredActuals.calendarDurationHours).toBe(5);
155
-
156
- // 5. Reopen task (done -> todo -> in_progress): actualEndDate must be cleared (undefined)
157
- vi.setSystemTime(new Date('2026-09-23T15:00:00Z'));
158
- const reopenedTodo = await engine.updateTask(task.id, { status: 'todo' });
159
- expect(reopenedTodo?.actualEndDate).toBeUndefined();
160
-
161
- vi.setSystemTime(new Date('2026-09-23T15:30:00Z'));
162
- const reopenedProgress = await engine.updateTask(task.id, { status: 'in_progress' });
163
- expect(reopenedProgress?.actualEndDate).toBeUndefined();
164
- expect(reopenedProgress?.actualStartDate).toBe('2026-09-23T09:00:00.000Z'); // Earliest preserved
165
- expect(reopenedProgress?.inProgressSince).toBe('2026-09-23T15:30:00.000Z');
166
- expect(reopenedProgress?.actualDurationSeconds).toBe(7200);
167
- } finally {
168
- vi.useRealTimers();
169
- }
170
- });
171
-
172
- it('tracks blocked duration while task is in_progress', async () => {
173
- vi.useFakeTimers();
174
- try {
175
- const store = new InMemoryStore();
176
- const engine = new CriticalPathEngine({ store });
177
-
178
- const project = await engine.createProject({
179
- name: 'Blocked Project'
180
- });
181
-
182
- vi.setSystemTime(new Date('2026-09-24T10:00:00Z'));
183
- const task = await engine.createTask({
184
- projectId: project.id,
185
- title: 'Blocked Tracking Feature'
186
- });
187
-
188
- // 1. Being blocked in 'todo' does NOT accumulate blocked duration or stamp blockedSince
189
- await engine.updateTask(task.id, { isBlocked: true, blockedReason: 'Waiting for spec' });
190
- const todoBlocked = await engine.getTask(task.id);
191
- expect(todoBlocked?.isBlocked).toBe(true);
192
- expect(todoBlocked?.blockedSince).toBeUndefined();
193
- expect(todoBlocked?.blockedDurationSeconds).toBeUndefined();
194
-
195
- // 2. Unblock while still in todo
196
- await engine.updateTask(task.id, { isBlocked: false, blockedReason: null });
197
-
198
- // 3. Start task at 10:00:00 (in_progress)
199
- const started = await engine.updateTask(task.id, { status: 'in_progress' });
200
- expect(started?.inProgressSince).toBe('2026-09-24T10:00:00.000Z');
201
- expect(started?.blockedSince).toBeUndefined();
202
-
203
- // 4. Block task at 10:00:30 (30 seconds in)
204
- vi.setSystemTime(new Date('2026-09-24T10:00:30Z'));
205
- const blocked = await engine.updateTask(task.id, { isBlocked: true, blockedReason: 'API down' });
206
- expect(blocked?.isBlocked).toBe(true);
207
- expect(blocked?.blockedSince).toBe('2026-09-24T10:00:30.000Z');
208
-
209
- // 5. Unblock task at 10:01:00 (30 seconds blocked)
210
- vi.setSystemTime(new Date('2026-09-24T10:01:00Z'));
211
- const unblocked = await engine.updateTask(task.id, { isBlocked: false, blockedReason: null });
212
- expect(unblocked?.isBlocked).toBe(false);
213
- expect(unblocked?.blockedSince).toBeNull();
214
- expect(unblocked?.blockedDurationSeconds).toBe(30);
215
-
216
- // 6. Block again at 10:01:10
217
- vi.setSystemTime(new Date('2026-09-24T10:01:10Z'));
218
- const blockedAgain = await engine.updateTask(task.id, { isBlocked: true, blockedReason: 'Review pending' });
219
- expect(blockedAgain?.blockedSince).toBe('2026-09-24T10:01:10.000Z');
220
-
221
- // 7. Complete task at 10:01:24 while still blocked (14 seconds blocked)
222
- // Total gross in-progress: 84s (1m 24s)
223
- // Total blocked duration: 30s + 14s = 44s
224
- vi.setSystemTime(new Date('2026-09-24T10:01:24Z'));
225
- const completed = await engine.updateTask(task.id, { status: 'done' });
226
- expect(completed?.status).toBe('done');
227
- expect(completed?.actualDurationSeconds).toBe(84);
228
- expect(completed?.blockedDurationSeconds).toBe(44);
229
- expect(completed?.blockedSince).toBeNull();
230
-
231
- // 8. Verify metrics
232
- const metrics = await engine.getTaskMetrics(task.id);
233
- expect(metrics?.inferredActuals.actualDurationSeconds).toBe(84);
234
- expect(metrics?.inferredActuals.blockedDurationSeconds).toBe(44);
235
- } finally {
236
- vi.useRealTimers();
237
- }
238
- });
239
-
240
- it('persists and retrieves blocked duration fields in SQLiteStore', async () => {
241
- const store = new SQLiteStore({ filename: ':memory:' });
242
- const project = await store.createProject({ key: 'SQL', name: 'SQLite Project' });
243
-
244
- const task = await store.createTask({
245
- projectId: project.id,
246
- title: 'SQLite Blocked Task',
247
- status: 'in_progress',
248
- priority: 'medium',
249
- isBlocked: true,
250
- blockedReason: 'Third party dependency',
251
- blockedSince: '2026-09-24T12:00:00.000Z',
252
- blockedDurationSeconds: 120
253
- });
254
-
255
- const retrieved = await store.getTask(task.id);
256
- expect(retrieved?.isBlocked).toBe(true);
257
- expect(retrieved?.blockedReason).toBe('Third party dependency');
258
- expect(retrieved?.blockedSince).toBe('2026-09-24T12:00:00.000Z');
259
- expect(retrieved?.blockedDurationSeconds).toBe(120);
260
-
261
- const updated = await store.updateTask(task.id, {
262
- isBlocked: false,
263
- blockedReason: null,
264
- blockedSince: null,
265
- blockedDurationSeconds: 180
266
- });
267
- expect(updated?.isBlocked).toBe(false);
268
- expect(updated?.blockedReason).toBeFalsy();
269
- expect(updated?.blockedSince).toBeFalsy();
270
- expect(updated?.blockedDurationSeconds).toBe(180);
271
-
272
- const reloaded = await store.getTask(task.id);
273
- expect(reloaded?.isBlocked).toBe(false);
274
- expect(reloaded?.blockedReason).toBeUndefined();
275
- expect(reloaded?.blockedSince).toBeUndefined();
276
- expect(reloaded?.blockedDurationSeconds).toBe(180);
277
- });
278
-
279
- it('manages blocked state directly on TaskEntity transitions and updates', () => {
280
- vi.useFakeTimers();
281
- try {
282
- vi.setSystemTime(new Date('2026-09-24T12:00:00Z'));
283
- const task = TaskEntity.create({
284
- projectId: 'proj_blk',
285
- title: 'Entity Blocked Test',
286
- status: 'in_progress'
287
- });
288
-
289
- // Block while in progress
290
- vi.setSystemTime(new Date('2026-09-24T12:00:30Z'));
291
- task.update({ isBlocked: true, blockedReason: 'Database migration' });
292
- expect(task.isBlocked).toBe(true);
293
- expect(task.blockedSince).toBe('2026-09-24T12:00:30.000Z');
294
-
295
- // Unblock while in progress
296
- vi.setSystemTime(new Date('2026-09-24T12:01:00Z'));
297
- task.update({ isBlocked: false, blockedReason: null });
298
- expect(task.isBlocked).toBe(false);
299
- expect(task.blockedSince).toBeNull();
300
- expect(task.blockedDurationSeconds).toBe(30);
301
-
302
- // Block again
303
- vi.setSystemTime(new Date('2026-09-24T12:01:10Z'));
304
- task.update({ isBlocked: true, blockedReason: 'Code review' });
305
- expect(task.blockedSince).toBe('2026-09-24T12:01:10.000Z');
306
-
307
- // Transition to completed (done) while blocked
308
- vi.setSystemTime(new Date('2026-09-24T12:01:30Z'));
309
- task.transitionTo('done', DEFAULT_SOFTWARE_WORKFLOW);
310
- expect(task.status).toBe('done');
311
- expect(task.actualDurationSeconds).toBe(90);
312
- expect(task.blockedDurationSeconds).toBe(50); // 30s + 20s
313
- expect(task.blockedSince).toBeNull();
314
- } finally {
315
- vi.useRealTimers();
316
- }
317
- });
318
-
319
- it('sets completedAt and actualEndDate on completion and resets progress when reopening', async () => {
320
- vi.useFakeTimers();
321
- try {
322
- const store = new InMemoryStore();
323
- const engine = new CriticalPathEngine({ store });
324
-
325
- const project = await engine.createProject({ name: 'Progress Transition Proj' });
326
- vi.setSystemTime(new Date('2026-10-01T10:00:00Z'));
327
- const task = await engine.createTask({
328
- projectId: project.id,
329
- title: 'Task for completion test',
330
- status: 'in_progress',
331
- progress: 50
332
- });
333
-
334
- // Complete the task
335
- vi.setSystemTime(new Date('2026-10-01T12:00:00Z'));
336
- const completed = await engine.updateTask(task.id, { status: 'done' });
337
- expect(completed?.status).toBe('done');
338
- expect(completed?.actualEndDate).toBe('2026-10-01T12:00:00.000Z');
339
- expect(completed?.completedAt).toBe('2026-10-01T12:00:00.000Z');
340
- expect(completed?.progress).toBe(100);
341
-
342
- // Reopen to todo -> actualEndDate & completedAt cleared, progress reset from 100 to 0
343
- vi.setSystemTime(new Date('2026-10-01T13:00:00Z'));
344
- const reopened = await engine.updateTask(task.id, { status: 'todo' });
345
- expect(reopened?.status).toBe('todo');
346
- expect(reopened?.actualEndDate).toBeUndefined();
347
- expect(reopened?.completedAt).toBeUndefined();
348
- expect(reopened?.progress).toBe(0);
349
- } finally {
350
- vi.useRealTimers();
351
- }
352
- });
353
- });
354
-
@@ -1,311 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { calculateWorkloadDistribution } from './workload.js';
3
- import { CriticalPathEngine } from '../engine/index.js';
4
- import { InMemoryStore } from '../store/index.js';
5
- import type { Task, TimeEntry, User, Team } from '../types/index.js';
6
-
7
- describe('calculateWorkloadDistribution', () => {
8
- const users: User[] = [
9
- { id: 'u1', name: 'Alice', email: 'alice@example.com', role: 'contributor', weeklyCapacityHours: 35, createdAt: '2026-09-01' },
10
- { id: 'u2', name: 'Bob', email: 'bob@example.com', role: 'contributor', weeklyCapacityHours: 40, createdAt: '2026-09-01' }
11
- ];
12
-
13
- const teams: Team[] = [
14
- { id: 'team_frontend', name: 'Frontend', memberIds: ['u1'], createdAt: '2026-09-01', updatedAt: '2026-09-01' },
15
- { id: 'team_backend', name: 'Backend', memberIds: ['u2'], weeklyCapacityHours: 50, createdAt: '2026-09-01', updatedAt: '2026-09-01' }
16
- ];
17
-
18
- it('aggregates logged time entries accurately by assignee across weekly buckets', () => {
19
- const tasks: Task[] = [
20
- {
21
- id: 't1',
22
- projectId: 'p1',
23
- title: 'Task 1',
24
- status: 'in_progress',
25
- priority: 'high',
26
- assigneeId: 'u1',
27
- createdAt: '2026-09-01',
28
- updatedAt: '2026-09-01'
29
- }
30
- ];
31
-
32
- const timeEntries: TimeEntry[] = [
33
- { id: 'te1', taskId: 't1', userId: 'u1', hours: 4.5, loggedAt: '2026-09-08' },
34
- { id: 'te2', taskId: 't1', userId: 'u1', hours: 3.5, loggedAt: '2026-09-09' },
35
- { id: 'te3', taskId: 't1', userId: 'u2', hours: 6.0, loggedAt: '2026-09-15' }
36
- ];
37
-
38
- const result = calculateWorkloadDistribution(
39
- { tasks, timeEntries, users, teams },
40
- {
41
- startDate: '2026-09-07',
42
- endDate: '2026-09-21',
43
- interval: 'week',
44
- groupBy: 'assignee',
45
- metric: 'logged'
46
- }
47
- );
48
-
49
- expect(result.interval).toBe('week');
50
- expect(result.groupBy).toBe('assignee');
51
- expect(result.metric).toBe('logged');
52
- expect(result.seriesKeys).toContain('u1');
53
- expect(result.seriesKeys).toContain('u2');
54
- expect(result.seriesLabels.u1).toBe('Alice');
55
- expect(result.seriesLabels.u2).toBe('Bob');
56
-
57
- // Week 1: 2026-09-07 (contains 09-08 and 09-09)
58
- const week1 = result.buckets.find((b) => b.date === '2026-09-07');
59
- expect(week1).toBeDefined();
60
- expect(week1?.values.u1).toBe(8.0);
61
- expect(week1?.values.u2).toBe(0);
62
- expect(week1?.totalHours).toBe(8.0);
63
- expect(week1?.capacity?.u1).toBe(35);
64
- expect(week1?.capacity?.u2).toBe(40);
65
-
66
- // Week 2: 2026-09-14 (contains 09-15)
67
- const week2 = result.buckets.find((b) => b.date === '2026-09-14');
68
- expect(week2).toBeDefined();
69
- expect(week2?.values.u2).toBe(6.0);
70
- expect(week2?.values.u1).toBe(0);
71
- expect(week2?.totalHours).toBe(6.0);
72
-
73
- // Total
74
- expect(result.totalHours).toBe(14.0);
75
- });
76
-
77
- it('distributes scheduled estimated hours evenly across task duration', () => {
78
- const tasks: Task[] = [
79
- {
80
- id: 't1',
81
- projectId: 'p1',
82
- title: 'Multi-day Task',
83
- status: 'todo',
84
- priority: 'high',
85
- assigneeId: 'u1',
86
- estimatedHours: 40,
87
- plannedStartDate: '2026-09-07', // Monday
88
- dueDate: '2026-09-11', // Friday (5 days total = 8h/day)
89
- createdAt: '2026-09-01',
90
- updatedAt: '2026-09-01'
91
- }
92
- ];
93
-
94
- const result = calculateWorkloadDistribution(
95
- { tasks, users },
96
- {
97
- startDate: '2026-09-07',
98
- endDate: '2026-09-11',
99
- interval: 'day',
100
- groupBy: 'assignee',
101
- metric: 'scheduled'
102
- }
103
- );
104
-
105
- expect(result.buckets.length).toBe(5);
106
- for (const b of result.buckets) {
107
- expect(b.values.u1).toBe(8);
108
- expect(b.totalHours).toBe(8);
109
- expect(b.capacity?.u1).toBe(7); // 35 / 5 = 7h/day
110
- }
111
- expect(result.totalHours).toBe(40);
112
- });
113
-
114
- it('handles grouping by team with custom team capacity and unassigned tasks', () => {
115
- const tasks: Task[] = [
116
- {
117
- id: 't1',
118
- projectId: 'p1',
119
- title: 'Frontend Task',
120
- status: 'in_progress',
121
- priority: 'medium',
122
- teamId: 'team_frontend',
123
- estimatedHours: 20,
124
- plannedStartDate: '2026-09-07',
125
- dueDate: '2026-09-07',
126
- createdAt: '2026-09-01',
127
- updatedAt: '2026-09-01'
128
- },
129
- {
130
- id: 't2',
131
- projectId: 'p1',
132
- title: 'Unassigned Task',
133
- status: 'todo',
134
- priority: 'low',
135
- estimatedHours: 10,
136
- plannedStartDate: '2026-09-07',
137
- dueDate: '2026-09-07',
138
- createdAt: '2026-09-01',
139
- updatedAt: '2026-09-01'
140
- }
141
- ];
142
-
143
- const result = calculateWorkloadDistribution(
144
- { tasks, teams },
145
- {
146
- startDate: '2026-09-07',
147
- endDate: '2026-09-13',
148
- interval: 'week',
149
- groupBy: 'team',
150
- metric: 'scheduled'
151
- }
152
- );
153
-
154
- expect(result.seriesKeys).toContain('team_frontend');
155
- expect(result.seriesKeys).toContain('unassigned');
156
- expect(result.seriesLabels.team_frontend).toBe('Frontend');
157
- expect(result.seriesLabels.unassigned).toBe('Unassigned');
158
-
159
- const bucket = result.buckets[0];
160
- expect(bucket.values.team_frontend).toBe(20);
161
- expect(bucket.values.unassigned).toBe(10);
162
- expect(bucket.totalHours).toBe(30);
163
- });
164
-
165
- it('calculates streamgraph-ready tabular structure without gaps for D3 stack', () => {
166
- const tasks: Task[] = [
167
- {
168
- id: 't1',
169
- projectId: 'p1',
170
- title: 'Task A',
171
- status: 'done',
172
- priority: 'high',
173
- assigneeId: 'u1',
174
- createdAt: '2026-09-01',
175
- updatedAt: '2026-09-01'
176
- }
177
- ];
178
-
179
- const timeEntries: TimeEntry[] = [
180
- { id: 'te1', taskId: 't1', userId: 'u1', hours: 5, loggedAt: '2026-09-01' },
181
- { id: 'te2', taskId: 't1', userId: 'u2', hours: 8, loggedAt: '2026-09-08' }
182
- ];
183
-
184
- const result = calculateWorkloadDistribution(
185
- { tasks, timeEntries, users },
186
- {
187
- startDate: '2026-09-01',
188
- endDate: '2026-09-14',
189
- interval: 'week',
190
- groupBy: 'assignee',
191
- metric: 'logged'
192
- }
193
- );
194
-
195
- // Verify all buckets contain numerical values (0, not undefined) for every series key
196
- for (const bucket of result.buckets) {
197
- for (const key of result.seriesKeys) {
198
- expect(typeof bucket.values[key]).toBe('number');
199
- expect(bucket.values[key]).toBeGreaterThanOrEqual(0);
200
- }
201
- }
202
- });
203
-
204
- it('integrates with CriticalPathEngine.getWorkloadDistribution', async () => {
205
- const store = new InMemoryStore();
206
- const engine = new CriticalPathEngine({ store });
207
-
208
- const project = await engine.createProject({ name: 'Workload Project' });
209
- const task = await engine.createTask({
210
- projectId: project.id,
211
- title: 'Dev Task',
212
- status: 'in_progress',
213
- assigneeId: 'u1',
214
- estimatedHours: 15,
215
- plannedStartDate: '2026-09-07',
216
- dueDate: '2026-09-07'
217
- });
218
-
219
- await engine.logTime({
220
- taskId: task.id,
221
- userId: 'u1',
222
- hours: 5,
223
- loggedAt: '2026-09-07T10:00:00.000Z'
224
- });
225
-
226
- const distribution = await engine.getWorkloadDistribution(project.id, {
227
- startDate: '2026-09-07',
228
- endDate: '2026-09-13',
229
- interval: 'week',
230
- metric: 'blended'
231
- });
232
-
233
- expect(distribution.projectId).toBe(project.id);
234
- expect(distribution.totalHours).toBeGreaterThan(0);
235
- expect(distribution.buckets.length).toBeGreaterThan(0);
236
- expect(distribution.seriesKeys).toContain('u1');
237
- });
238
-
239
- it('distributes task effort only on working days and reduces capacity on holidays', () => {
240
- // Friday 2026-09-18 to Tuesday 2026-09-22 (5 calendar days: Fri, Sat, Sun, Mon, Tue)
241
- // Monday 2026-09-21 is a Holiday!
242
- // Active working days: Friday 2026-09-18 and Tuesday 2026-09-22 (2 days total)
243
- // 16 estimated hours should be divided into 8h on Fri, 0h on Sat, 0h on Sun, 0h on Mon, 8h on Tue!
244
- const customSchedule = {
245
- name: 'Holiday Calendar',
246
- defaultHoursPerDay: 8,
247
- days: [
248
- { dayOfWeek: 0, isWorkingDay: false },
249
- { dayOfWeek: 1, isWorkingDay: true, hours: [{ start: '09:00', end: '17:00' }] },
250
- { dayOfWeek: 2, isWorkingDay: true, hours: [{ start: '09:00', end: '17:00' }] },
251
- { dayOfWeek: 3, isWorkingDay: true, hours: [{ start: '09:00', end: '17:00' }] },
252
- { dayOfWeek: 4, isWorkingDay: true, hours: [{ start: '09:00', end: '17:00' }] },
253
- { dayOfWeek: 5, isWorkingDay: true, hours: [{ start: '09:00', end: '17:00' }] },
254
- { dayOfWeek: 6, isWorkingDay: false }
255
- ],
256
- holidays: [{ date: '2026-09-21', name: 'Monday Holiday' }]
257
- };
258
-
259
- const tasks: Task[] = [
260
- {
261
- id: 't_holiday',
262
- projectId: 'p1',
263
- title: 'Holiday Spanning Task',
264
- status: 'todo',
265
- priority: 'high',
266
- assigneeId: 'u2',
267
- estimatedHours: 16,
268
- plannedStartDate: '2026-09-18', // Friday
269
- dueDate: '2026-09-22', // Tuesday
270
- createdAt: '2026-09-01',
271
- updatedAt: '2026-09-01'
272
- }
273
- ];
274
-
275
- const result = calculateWorkloadDistribution(
276
- { tasks, users },
277
- {
278
- startDate: '2026-09-18',
279
- endDate: '2026-09-22',
280
- interval: 'day',
281
- groupBy: 'assignee',
282
- metric: 'scheduled',
283
- schedule: customSchedule
284
- }
285
- );
286
-
287
- const fri = result.buckets.find((b) => b.date === '2026-09-18');
288
- const sat = result.buckets.find((b) => b.date === '2026-09-19');
289
- const sun = result.buckets.find((b) => b.date === '2026-09-20');
290
- const mon = result.buckets.find((b) => b.date === '2026-09-21');
291
- const tue = result.buckets.find((b) => b.date === '2026-09-22');
292
-
293
- expect(fri?.values.u2).toBe(8);
294
- expect(fri?.capacity?.u2).toBe(8);
295
-
296
- expect(sat?.values.u2).toBe(0);
297
- expect(sat?.capacity?.u2).toBe(0);
298
-
299
- expect(sun?.values.u2).toBe(0);
300
- expect(sun?.capacity?.u2).toBe(0);
301
-
302
- // Monday is holiday: 0 scheduled effort, 0 capacity
303
- expect(mon?.values.u2).toBe(0);
304
- expect(mon?.capacity?.u2).toBe(0);
305
-
306
- expect(tue?.values.u2).toBe(8);
307
- expect(tue?.capacity?.u2).toBe(8);
308
-
309
- expect(result.totalHours).toBe(16);
310
- });
311
- });