@jsb188/schedule 1.1.12 → 1.1.13

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +33 -14
  3. package/src/constants/schedule.ts +710 -306
  4. package/src/types/schedule.d.ts +1827 -456
  5. package/src/ui/ScheduleSettingsUI.tsx +21 -23
  6. package/src/utils/autofill.ts +469 -0
  7. package/src/utils/availability.ts +167 -0
  8. package/src/utils/candidates.ts +447 -0
  9. package/src/utils/coverage.helpers.ts +509 -554
  10. package/src/utils/coverage.ts +1121 -526
  11. package/src/utils/cpm.helpers.ts +27 -29
  12. package/src/utils/cpm.ts +53 -41
  13. package/src/utils/cpmLeveling.helpers.ts +89 -16
  14. package/src/utils/cpmLeveling.ts +28 -26
  15. package/src/utils/cycle.ts +325 -0
  16. package/src/utils/demand.ts +239 -0
  17. package/src/utils/eligibility.ts +553 -400
  18. package/src/utils/ids.ts +47 -0
  19. package/src/utils/laborRules.ts +740 -0
  20. package/src/utils/localTime.ts +312 -0
  21. package/src/utils/offer.ts +300 -0
  22. package/src/utils/planCsv.ts +73 -19
  23. package/src/utils/predicate.ts +111 -0
  24. package/src/utils/request.ts +212 -114
  25. package/src/utils/resource.ts +412 -112
  26. package/src/utils/rule.ts +697 -163
  27. package/src/utils/rulePresets.ts +116 -0
  28. package/src/utils/run.ts +0 -8
  29. package/src/utils/scheduleText.ts +4074 -0
  30. package/src/utils/shiftChange.ts +279 -0
  31. package/src/utils/standing.ts +730 -0
  32. package/src/utils/template.ts +619 -0
  33. package/src/utils/violation.ts +184 -0
  34. package/src/utils/workTime.ts +341 -120
  35. package/src/utils/defaults.ts +0 -8
  36. package/src/utils/recurrence.ts +0 -616
  37. package/src/utils/series.ts +0 -161
  38. package/src/utils/slot.ts +0 -208
  39. package/tests/coverage.fixtures.ts +0 -111
  40. package/tests/coverage.test.ts +0 -503
  41. package/tests/cpm.bench.test.ts +0 -154
  42. package/tests/cpm.test.ts +0 -354
  43. package/tests/cpmCorrectness.test.ts +0 -327
  44. package/tests/cpmLeveling.test.ts +0 -471
  45. package/tests/eligibility.test.ts +0 -320
  46. package/tests/gantt-geometry.test.ts +0 -367
  47. package/tests/gantt-histogram.test.ts +0 -78
  48. package/tests/gantt-keyboard.test.ts +0 -69
  49. package/tests/helpers/cpmFixtures.ts +0 -101
  50. package/tests/projectInputs.test.ts +0 -165
  51. package/tests/recurrence.test.ts +0 -68
  52. package/tests/request.test.ts +0 -99
  53. package/tests/resource.test.ts +0 -95
  54. package/tests/rule.test.ts +0 -98
  55. package/tests/series.test.ts +0 -120
  56. package/tests/workTime.test.ts +0 -1007
  57. package/tests/workTimeContracts.test.ts +0 -111
  58. package/tsconfig.json +0 -13
  59. package/vitest.config.ts +0 -8
package/tests/cpm.test.ts DELETED
@@ -1,354 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type {
3
- CpmActivityInput,
4
- CpmRelationshipInput,
5
- CpmScheduleInput,
6
- } from '../src/types/schedule.d.ts';
7
- import { runCriticalPathSchedule } from '../src/utils/cpm.ts';
8
- import { getStandardWorkCalendarDef } from '../src/utils/workTime.ts';
9
-
10
- const ZONE = 'America/Los_Angeles';
11
- const calendars = { STANDARD: getStandardWorkCalendarDef(ZONE) };
12
-
13
- /*
14
- * Local LA time (PST) to UTC instant.
15
- */
16
- function la(date: string, time: string): Date {
17
- return new Date(`${date}T${time}:00-08:00`);
18
- }
19
-
20
- /*
21
- * One working day is 480 minutes on the standard calendar.
22
- */
23
- const DAY = 480;
24
-
25
- function task(
26
- id: string,
27
- days: number,
28
- extra: Partial<CpmActivityInput> = {},
29
- ): CpmActivityInput {
30
- return { id, type: 'TASK', plannedDurationMinutes: days * DAY, ...extra };
31
- }
32
-
33
- function fs(
34
- predecessorId: string,
35
- successorId: string,
36
- lagMinutes = 0,
37
- type: CpmRelationshipInput['type'] = 'FS',
38
- ): CpmRelationshipInput {
39
- return { predecessorId, successorId, type, lagMinutes };
40
- }
41
-
42
- function schedule(
43
- activities: CpmActivityInput[],
44
- relationships: CpmRelationshipInput[],
45
- extra: Partial<CpmScheduleInput> = {},
46
- ) {
47
- return runCriticalPathSchedule({
48
- activities,
49
- relationships,
50
- calendars,
51
- defaultCalendarId: 'STANDARD',
52
- projectStartAt: la('2026-01-05', '08:00'),
53
- dataDateAt: la('2026-01-05', '08:00'),
54
- ...extra,
55
- });
56
- }
57
-
58
- function byId(result: ReturnType<typeof runCriticalPathSchedule>, id: string) {
59
- return result.activities.find((activity) => activity.id === id)!;
60
- }
61
-
62
- describe('cpm', () => {
63
- it('schedules a finish-to-start chain on working time', () => {
64
- const result = schedule(
65
- [task('A', 3), task('B', 2), task('C', 1)],
66
- [fs('A', 'B'), fs('B', 'C')],
67
- );
68
-
69
- expect(result.ok).toBe(true);
70
- expect(byId(result, 'A').earlyStartAt.toISOString()).toBe(
71
- la('2026-01-05', '08:00').toISOString(),
72
- );
73
- expect(byId(result, 'A').earlyFinishAt.toISOString()).toBe(
74
- la('2026-01-07', '17:00').toISOString(),
75
- );
76
- expect(byId(result, 'B').earlyStartAt.toISOString()).toBe(
77
- la('2026-01-08', '08:00').toISOString(),
78
- );
79
- expect(byId(result, 'B').earlyFinishAt.toISOString()).toBe(
80
- la('2026-01-09', '17:00').toISOString(),
81
- );
82
- expect(byId(result, 'C').earlyStartAt.toISOString()).toBe(
83
- la('2026-01-12', '08:00').toISOString(),
84
- );
85
- expect(byId(result, 'C').earlyFinishAt.toISOString()).toBe(
86
- la('2026-01-12', '17:00').toISOString(),
87
- );
88
- expect(result.scheduledFinishAt?.toISOString()).toBe(
89
- la('2026-01-12', '17:00').toISOString(),
90
- );
91
-
92
- for (const id of ['A', 'B', 'C']) {
93
- expect(byId(result, id).totalFloatMinutes).toBe(0);
94
- expect(byId(result, id).isCritical).toBe(true);
95
- }
96
- expect(result.stats.criticalCount).toBe(3);
97
- });
98
-
99
- it('gives a parallel branch float and leaves it off the critical path', () => {
100
- const result = schedule(
101
- [task('A', 3), task('B', 2), task('C', 1), task('D', 1)],
102
- [fs('A', 'B'), fs('B', 'C'), fs('D', 'C')],
103
- );
104
-
105
- const d = byId(result, 'D');
106
- expect(d.earlyFinishAt.toISOString()).toBe(
107
- la('2026-01-05', '17:00').toISOString(),
108
- );
109
- expect(d.lateFinishAt.toISOString()).toBe(
110
- la('2026-01-09', '17:00').toISOString(),
111
- );
112
- expect(d.lateStartAt.toISOString()).toBe(
113
- la('2026-01-09', '08:00').toISOString(),
114
- );
115
- expect(d.totalFloatMinutes).toBe(4 * DAY);
116
- expect(d.freeFloatMinutes).toBe(4 * DAY);
117
- expect(d.isCritical).toBe(false);
118
- expect(
119
- result.diagnostics.some(
120
- (diagnostic) =>
121
- diagnostic.code === 'OPEN_START' && diagnostic.activityId === 'D',
122
- ),
123
- ).toBe(true);
124
- });
125
-
126
- it('applies start-to-start lag and finish-to-finish logic', () => {
127
- const result = schedule(
128
- [task('A', 3), task('B', 2), task('C', 1)],
129
- [fs('A', 'B', DAY, 'SS'), fs('A', 'C', 0, 'FF')],
130
- );
131
-
132
- expect(byId(result, 'B').earlyStartAt.toISOString()).toBe(
133
- la('2026-01-06', '08:00').toISOString(),
134
- );
135
- // C must finish when A finishes (Wednesday 17:00) and keeps its one-day duration
136
- expect(byId(result, 'C').earlyFinishAt.toISOString()).toBe(
137
- la('2026-01-07', '17:00').toISOString(),
138
- );
139
- expect(byId(result, 'C').earlyStartAt.toISOString()).toBe(
140
- la('2026-01-07', '08:00').toISOString(),
141
- );
142
- });
143
-
144
- it('honours a start-on-or-after constraint and pushes float upstream', () => {
145
- const result = schedule(
146
- [
147
- task('A', 3),
148
- task('B', 2),
149
- task('C', 1, {
150
- primaryConstraint: {
151
- type: 'START_ON_OR_AFTER',
152
- at: la('2026-01-14', '00:00'),
153
- },
154
- }),
155
- ],
156
- [fs('A', 'B'), fs('B', 'C')],
157
- );
158
-
159
- expect(byId(result, 'C').earlyStartAt.toISOString()).toBe(
160
- la('2026-01-14', '08:00').toISOString(),
161
- );
162
- expect(byId(result, 'A').totalFloatMinutes).toBe(2 * DAY);
163
- expect(byId(result, 'B').totalFloatMinutes).toBe(2 * DAY);
164
- expect(byId(result, 'C').totalFloatMinutes).toBe(0);
165
- });
166
-
167
- it('reports negative float against a must-finish date', () => {
168
- const result = schedule([task('A', 3), task('B', 2)], [fs('A', 'B')], {
169
- mustFinishByAt: la('2026-01-08', '17:00'),
170
- });
171
-
172
- expect(byId(result, 'B').totalFloatMinutes).toBe(-DAY);
173
- expect(byId(result, 'A').totalFloatMinutes).toBe(-DAY);
174
- expect(result.stats.negativeFloatCount).toBe(2);
175
- expect(
176
- result.diagnostics.some(
177
- (diagnostic) => diagnostic.code === 'NEGATIVE_FLOAT',
178
- ),
179
- ).toBe(true);
180
- });
181
-
182
- it('refuses a relationship loop', () => {
183
- const result = schedule(
184
- [task('A', 1), task('B', 1)],
185
- [fs('A', 'B'), fs('B', 'A')],
186
- );
187
-
188
- expect(result.ok).toBe(false);
189
- expect(
190
- result.diagnostics.filter((diagnostic) => diagnostic.code === 'CYCLE'),
191
- ).toHaveLength(1);
192
- });
193
-
194
- it('schedules remaining work from the data date with retained logic', () => {
195
- const result = schedule(
196
- [
197
- task('A', 3, {
198
- actualStartAt: la('2026-01-05', '08:00'),
199
- remainingDurationMinutes: DAY,
200
- }),
201
- task('B', 2),
202
- ],
203
- [fs('A', 'B')],
204
- { dataDateAt: la('2026-01-08', '08:00') },
205
- );
206
-
207
- const a = byId(result, 'A');
208
- expect(a.status).toBe('IN_PROGRESS');
209
- expect(a.earlyStartAt.toISOString()).toBe(
210
- la('2026-01-05', '08:00').toISOString(),
211
- );
212
- expect(a.earlyFinishAt.toISOString()).toBe(
213
- la('2026-01-08', '17:00').toISOString(),
214
- );
215
- expect(byId(result, 'B').earlyStartAt.toISOString()).toBe(
216
- la('2026-01-09', '08:00').toISOString(),
217
- );
218
- });
219
-
220
- it('keeps actual dates on completed work and flags out-of-sequence progress', () => {
221
- const result = schedule(
222
- [
223
- task('A', 2, {
224
- actualStartAt: la('2026-01-05', '08:00'),
225
- actualFinishAt: la('2026-01-06', '17:00'),
226
- }),
227
- task('B', 2, { actualStartAt: la('2026-01-06', '08:00') }),
228
- task('C', 1),
229
- ],
230
- [fs('A', 'B'), fs('C', 'B')],
231
- { dataDateAt: la('2026-01-07', '08:00') },
232
- );
233
-
234
- expect(byId(result, 'A').status).toBe('COMPLETE');
235
- expect(byId(result, 'A').totalFloatMinutes).toBeNull();
236
- expect(byId(result, 'B').status).toBe('IN_PROGRESS');
237
- expect(
238
- result.diagnostics.some(
239
- (diagnostic) =>
240
- diagnostic.code === 'OUT_OF_SEQUENCE' &&
241
- diagnostic.activityId === 'B',
242
- ),
243
- ).toBe(true);
244
- // C has not started, so retained logic holds B's remaining work behind it
245
- expect(byId(result, 'B').earlyFinishAt.getTime()).toBeGreaterThan(
246
- byId(result, 'C').earlyFinishAt.getTime(),
247
- );
248
- });
249
-
250
- it('places milestones and spans level-of-effort and WBS summary activities', () => {
251
- const result = schedule(
252
- [
253
- {
254
- id: 'START',
255
- type: 'START_MILESTONE',
256
- plannedDurationMinutes: 0,
257
- wbsId: 'w1',
258
- },
259
- task('A', 2, { wbsId: 'w1' }),
260
- task('B', 3, { wbsId: 'w2' }),
261
- {
262
- id: 'END',
263
- type: 'FINISH_MILESTONE',
264
- plannedDurationMinutes: 0,
265
- wbsId: 'w2',
266
- },
267
- { id: 'LOE', type: 'LEVEL_OF_EFFORT', plannedDurationMinutes: 0 },
268
- {
269
- id: 'SUM',
270
- type: 'WBS_SUMMARY',
271
- plannedDurationMinutes: 0,
272
- wbsId: 'root',
273
- },
274
- ],
275
- [
276
- fs('START', 'A'),
277
- fs('A', 'B'),
278
- fs('B', 'END'),
279
- fs('A', 'LOE', 0, 'SS'),
280
- fs('LOE', 'B', 0, 'FF'),
281
- ],
282
- { wbsPaths: { root: '/root/', w1: '/root/w1/', w2: '/root/w2/' } },
283
- );
284
-
285
- expect(result.ok).toBe(true);
286
- expect(byId(result, 'START').earlyStartAt.toISOString()).toBe(
287
- la('2026-01-05', '08:00').toISOString(),
288
- );
289
- expect(byId(result, 'END').earlyFinishAt.toISOString()).toBe(
290
- la('2026-01-09', '17:00').toISOString(),
291
- );
292
-
293
- const loe = byId(result, 'LOE');
294
- expect(loe.earlyStartAt.toISOString()).toBe(
295
- la('2026-01-05', '08:00').toISOString(),
296
- );
297
- expect(loe.earlyFinishAt.toISOString()).toBe(
298
- la('2026-01-09', '17:00').toISOString(),
299
- );
300
- expect(loe.remainingDurationMinutes).toBe(5 * DAY);
301
- expect(loe.isCritical).toBe(false);
302
-
303
- const summary = byId(result, 'SUM');
304
- expect(summary.earlyStartAt.toISOString()).toBe(
305
- la('2026-01-05', '08:00').toISOString(),
306
- );
307
- expect(summary.earlyFinishAt.toISOString()).toBe(
308
- la('2026-01-09', '17:00').toISOString(),
309
- );
310
- });
311
-
312
- it('delays an as-late-as-possible activity into its free float', () => {
313
- const result = schedule(
314
- [
315
- task('A', 3),
316
- task('B', 2),
317
- task('C', 1),
318
- task('D', 1, {
319
- primaryConstraint: { type: 'AS_LATE_AS_POSSIBLE', at: null },
320
- }),
321
- ],
322
- [fs('A', 'B'), fs('B', 'C'), fs('D', 'C')],
323
- );
324
-
325
- const d = byId(result, 'D');
326
- expect(d.earlyStartAt.toISOString()).toBe(
327
- la('2026-01-09', '08:00').toISOString(),
328
- );
329
- expect(d.earlyFinishAt.toISOString()).toBe(
330
- la('2026-01-09', '17:00').toISOString(),
331
- );
332
- expect(d.totalFloatMinutes).toBe(0);
333
- });
334
-
335
- it('warns when a mandatory constraint overrides the logic', () => {
336
- const result = schedule(
337
- [
338
- task('A', 3),
339
- task('B', 2, {
340
- primaryConstraint: {
341
- type: 'MANDATORY_START',
342
- at: la('2026-01-06', '08:00'),
343
- },
344
- }),
345
- ],
346
- [fs('A', 'B')],
347
- );
348
-
349
- expect(byId(result, 'B').earlyStartAt.toISOString()).toBe(
350
- la('2026-01-06', '08:00').toISOString(),
351
- );
352
- expect(result.stats.constraintOverrideCount).toBe(1);
353
- });
354
- });
@@ -1,327 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { CpmScheduleInput } from '../src/types/schedule.d.ts';
3
- import {
4
- getStandardWorkCalendarDef,
5
- workingMinutesBetween,
6
- } from '../src/utils/workTime.ts';
7
- import {
8
- byId,
9
- DAY,
10
- fs,
11
- la,
12
- milestone,
13
- schedule,
14
- task,
15
- } from './helpers/cpmFixtures.ts';
16
-
17
- describe('CPM correctness regressions', () => {
18
- it.each([
19
- task('A', 1),
20
- task('A', 0),
21
- milestone('A', 'START_MILESTONE'),
22
- milestone('A'),
23
- ])('normalizes equivalent zero-float late instants for $type', (activity) => {
24
- const result = schedule([activity]);
25
- const a = byId(result, 'A');
26
- expect(a.lateStartAt).toEqual(a.earlyStartAt);
27
- expect(a.lateFinishAt).toEqual(a.earlyFinishAt);
28
- });
29
- it('uses start snapping for SS/SF backward bounds', () => {
30
- for (const type of ['SS', 'SF'] as const) {
31
- const result = schedule(
32
- [task('A', 1), task('B', 1)],
33
- [fs('A', 'B', 0, type)],
34
- );
35
- expect(byId(result, 'A').lateStartAt.getTime()).toBeGreaterThanOrEqual(
36
- byId(result, 'A').earlyStartAt.getTime(),
37
- );
38
- }
39
- });
40
- it('ignores an unused empty calendar but refuses a referenced one', () => {
41
- const calendars = {
42
- STANDARD: getStandardWorkCalendarDef('UTC'),
43
- empty: { id: 'empty', timeZone: 'UTC', weekHours: {} },
44
- };
45
- expect(schedule([task('A')], [], { calendars }).ok).toBe(true);
46
- const result = schedule([task('A', 1, { calendarId: 'empty' })], [], {
47
- calendars,
48
- });
49
- expect(result.ok).toBe(false);
50
- expect(result.diagnostics[0].code).toBe('EMPTY_CALENDAR');
51
- });
52
- it('floors mandatory starts and exposes impossible mandatory finishes as negative float', () => {
53
- const result = schedule([
54
- task('A', 3, {
55
- primaryConstraint: {
56
- type: 'MANDATORY_FINISH',
57
- at: la('2026-01-06', '17:00'),
58
- },
59
- }),
60
- task('B', 1, {
61
- primaryConstraint: { type: 'MANDATORY_START', at: la('2026-01-01') },
62
- }),
63
- ]);
64
- expect(byId(result, 'A').earlyStartAt).toEqual(la('2026-01-05'));
65
- expect(byId(result, 'A').totalFloatMinutes).toBe(-DAY);
66
- expect(byId(result, 'B').earlyStartAt).toEqual(la('2026-01-05'));
67
- expect(result.stats.diagnosticCounts.CONSTRAINT_BEFORE_DATA_DATE).toBe(2);
68
- });
69
- it('resumes in-progress work no earlier than a future actual start', () => {
70
- const result = schedule([
71
- task('A', 5, {
72
- actualStartAt: la('2026-01-07'),
73
- remainingDurationMinutes: DAY,
74
- }),
75
- ]);
76
- expect(byId(result, 'A').earlyFinishAt).toEqual(la('2026-01-07', '17:00'));
77
- expect(result.stats.diagnosticCounts.ACTUALS_AFTER_DATA_DATE).toBe(1);
78
- });
79
- it('keeps an actual start fixed and ignores its future mandatory start', () => {
80
- const result = schedule([
81
- task('A', 5, {
82
- actualStartAt: la('2026-01-02'),
83
- remainingDurationMinutes: DAY,
84
- primaryConstraint: { type: 'MANDATORY_START', at: la('2026-02-01') },
85
- }),
86
- ]);
87
- const a = byId(result, 'A');
88
- expect(a.lateStartAt).toEqual(a.earlyStartAt);
89
- expect(a.totalFloatMinutes).toBe(0);
90
- });
91
- it('honors in-progress finish bounds and keeps an earlier mandatory finish as negative float', () => {
92
- const a = task('A', 5, {
93
- actualStartAt: la('2026-01-02'),
94
- remainingDurationMinutes: 3 * DAY,
95
- primaryConstraint: {
96
- type: 'MANDATORY_FINISH',
97
- at: la('2026-01-06', '17:00'),
98
- },
99
- });
100
- const result = schedule([a]);
101
- expect(byId(result, 'A').earlyFinishAt).toEqual(la('2026-01-07', '17:00'));
102
- expect(byId(result, 'A').totalFloatMinutes).toBe(-DAY);
103
- expect(result.stats.diagnosticCounts.CONSTRAINT_OVERRIDES_LOGIC).toBe(1);
104
- });
105
- it('keeps completed future actuals and drives successors from them', () => {
106
- const result = schedule(
107
- [
108
- task('A', 2, {
109
- actualStartAt: la('2026-01-05'),
110
- actualFinishAt: la('2026-01-07', '17:00'),
111
- }),
112
- task('B'),
113
- ],
114
- [fs('A', 'B')],
115
- );
116
- expect(byId(result, 'A').totalFloatMinutes).toBeNull();
117
- expect(byId(result, 'B').earlyStartAt).toEqual(la('2026-01-08'));
118
- });
119
- it('reports actual SCC members, excluding descendants of a loop', () => {
120
- const result = schedule(
121
- ['A', 'B', 'C', 'D', 'E', 'F'].map((id) => task(id)),
122
- [
123
- fs('A', 'B'),
124
- fs('B', 'A'),
125
- fs('B', 'C'),
126
- fs('D', 'E'),
127
- fs('E', 'D'),
128
- fs('E', 'F'),
129
- ],
130
- );
131
- expect(result.stats.cycleCount).toBe(2);
132
- expect(
133
- result.diagnostics
134
- .filter((d) => d.code === 'CYCLE')
135
- .map((d) => d.activityIds),
136
- ).toEqual([
137
- ['A', 'B'],
138
- ['D', 'E'],
139
- ]);
140
- });
141
- it('marks longest path even when a later finish target gives every activity float', () => {
142
- const base = { mustFinishByAt: la('2026-01-30', '17:00') };
143
- const activities = [task('A', 2), task('B', 2), task('C')];
144
- const relationships = [fs('A', 'B')];
145
- const normal = schedule(activities, relationships, base);
146
- const longest = schedule(activities, relationships, {
147
- ...base,
148
- options: { criticalityMode: 'LONGEST_PATH' },
149
- });
150
- expect(normal.stats.criticalCount).toBe(0);
151
- expect(normal.stats.longestPathCount).toBe(2);
152
- expect(
153
- longest.activities.filter((a) => a.isCritical).map((a) => a.id),
154
- ).toEqual(['A', 'B']);
155
- expect(byId(longest, 'B').drivingPredecessorIds).toEqual(['A']);
156
- });
157
- it('records working-instant ties from FS and SS predecessors across a weekend', () => {
158
- const result = schedule(
159
- [
160
- task('A', 5),
161
- task('B', 1, {
162
- primaryConstraint: {
163
- type: 'START_ON_OR_AFTER',
164
- at: la('2026-01-12'),
165
- },
166
- }),
167
- task('C'),
168
- ],
169
- [fs('A', 'C'), fs('B', 'C', 0, 'SS')],
170
- );
171
- expect(byId(result, 'C').drivingPredecessorIds).toEqual(['A', 'B']);
172
- });
173
- it('terminates the driving trace when a constraint moves an activity later', () => {
174
- const result = schedule(
175
- [
176
- task('A'),
177
- task('B', 1, {
178
- primaryConstraint: {
179
- type: 'START_ON_OR_AFTER',
180
- at: la('2026-01-15'),
181
- },
182
- }),
183
- ],
184
- [fs('A', 'B')],
185
- { options: { criticalityMode: 'LONGEST_PATH' } },
186
- );
187
- expect(byId(result, 'B').drivingPredecessorIds).toEqual([]);
188
- expect(byId(result, 'A').isCritical).toBe(false);
189
- });
190
- it('derives summary status from completed or started members and leaves an empty WBS at zero', () => {
191
- const result = schedule(
192
- [
193
- task('A', 1, {
194
- wbsId: 'child',
195
- actualStartAt: la('2026-01-01'),
196
- actualFinishAt: la('2026-01-02', '17:00'),
197
- }),
198
- task('S', 0, { type: 'WBS_SUMMARY', wbsId: 'root' }),
199
- task('E', 0, { type: 'WBS_SUMMARY', wbsId: 'empty' }),
200
- ],
201
- [],
202
- { wbsPaths: { root: '/root/', child: '/root/child/', empty: '/empty/' } },
203
- );
204
- expect(byId(result, 'S').status).toBe('COMPLETE');
205
- expect(byId(result, 'S').remainingDurationMinutes).toBe(0);
206
- expect(byId(result, 'E').startAt).toEqual(byId(result, 'E').finishAt);
207
- });
208
- it('computes nested LOE dates independently of activity input order', () => {
209
- const activities = [
210
- task('L1', 0, { type: 'LEVEL_OF_EFFORT' }),
211
- task('L2', 0, { type: 'LEVEL_OF_EFFORT' }),
212
- task('A', 3),
213
- ];
214
- const links = [fs('A', 'L2'), fs('L2', 'L1')];
215
- const first = schedule(activities, links);
216
- const second = schedule([...activities].reverse(), links);
217
- for (const id of ['L1', 'L2'])
218
- expect(byId(first, id)).toEqual(byId(second, id));
219
- });
220
- it('leaves a non-driving cycle as a warning and completes the project', () => {
221
- const result = schedule(
222
- [
223
- task('A'),
224
- task('L1', 0, { type: 'LEVEL_OF_EFFORT' }),
225
- task('L2', 0, { type: 'LEVEL_OF_EFFORT' }),
226
- ],
227
- [fs('L1', 'L2'), fs('L2', 'L1')],
228
- );
229
- expect(result.ok).toBe(true);
230
- expect(result.stats.cycleCount).toBe(0);
231
- expect(
232
- result.diagnostics
233
- .filter((d) => d.code === 'CYCLE')
234
- .every((d) => d.severity === 'WARN'),
235
- ).toBe(true);
236
- });
237
- it.each([
238
- { activities: [task('A'), task('A')] },
239
- { dataDateAt: 'not-a-date' },
240
- {
241
- calendars: {
242
- STANDARD: {
243
- id: 'bad',
244
- timeZone: 'Not/AZone',
245
- weekHours: { '1': [['08:00', '17:00']] },
246
- },
247
- },
248
- },
249
- {
250
- activities: [
251
- task('A', 1, {
252
- actualStartAt: la('2026-01-06'),
253
- actualFinishAt: la('2026-01-05'),
254
- }),
255
- ],
256
- },
257
- ])('refuses invalid structural input %#', (extra) => {
258
- const result = schedule(
259
- [task('A')],
260
- [],
261
- extra as Partial<CpmScheduleInput>,
262
- );
263
- expect(result.ok).toBe(false);
264
- expect(
265
- result.diagnostics.some(
266
- (d) => d.code === 'INVALID_INPUT' && d.severity === 'ERROR',
267
- ),
268
- ).toBe(true);
269
- });
270
- it('normalizes invalid durations and lags, ignores illegal secondary constraints, and deduplicates links', () => {
271
- const result = schedule(
272
- [
273
- task('A', NaN),
274
- task('B', 1, {
275
- calendarId: 'missing',
276
- secondaryConstraint: {
277
- type: 'MANDATORY_START',
278
- at: la('2026-02-01'),
279
- },
280
- }),
281
- ],
282
- [fs('A', 'B', NaN), fs('A', 'B', DAY)],
283
- );
284
- expect(result.ok).toBe(true);
285
- expect(byId(result, 'A').remainingDurationMinutes).toBe(0);
286
- expect(byId(result, 'B').earlyStartAt).toEqual(la('2026-01-05'));
287
- expect(result.stats.diagnosticCounts.INVALID_INPUT).toBe(4);
288
- expect(result.stats.diagnosticCounts.UNKNOWN_CALENDAR).toBe(1);
289
- });
290
- it('reports exact counts while bounding open-end diagnostics', () => {
291
- const result = schedule(
292
- Array.from({ length: 1000 }, (_, i) => task(String(i))),
293
- );
294
- expect(result.stats.openStartCount).toBe(999);
295
- expect(result.stats.openFinishCount).toBe(999);
296
- expect(result.diagnostics).toHaveLength(400);
297
- expect(result.stats.diagnosticsTruncated).toBe(true);
298
- });
299
- it('calculates float across eleven years and refuses a duration beyond forty years', () => {
300
- const result = schedule([task('A')], [], {
301
- mustFinishByAt: la('2037-01-05', '17:00'),
302
- });
303
- expect(byId(result, 'A').totalFloatMinutes).toBeGreaterThan(2500 * DAY);
304
- const tooLong = schedule([task('A', 15000)]);
305
- expect(tooLong.ok).toBe(false);
306
- expect(tooLong.diagnostics.at(-1)?.code).toBe('CALENDAR_RANGE_EXCEEDED');
307
- }, 10000);
308
- it('retains whole working durations and effective early dates with leveling disabled', () => {
309
- const result = schedule(
310
- [task('A', 2), task('B', 3)],
311
- [fs('A', 'B', -DAY, 'FF')],
312
- );
313
- for (const a of result.activities) {
314
- expect(a.startAt).toEqual(a.earlyStartAt);
315
- expect(a.finishAt).toEqual(a.earlyFinishAt);
316
- expect(
317
- workingMinutesBetween(
318
- getStandardWorkCalendarDef('America/Los_Angeles'),
319
- a.startAt,
320
- a.finishAt,
321
- ),
322
- ).toBe(a.remainingDurationMinutes);
323
- }
324
- expect(result.stats.leveled).toBe(false);
325
- expect(result.resourceUsage).toEqual([]);
326
- });
327
- });