@jsb188/schedule 1.1.11 → 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 (62) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +34 -14
  3. package/src/constants/schedule.ts +710 -306
  4. package/src/modules/Gantt.helpers.ts +11 -30
  5. package/src/modules/Gantt.tsx +46 -181
  6. package/src/types/schedule.d.ts +1827 -456
  7. package/src/ui/ProjectFormUI.tsx +8 -31
  8. package/src/ui/ScheduleSettingsUI.tsx +21 -23
  9. package/src/utils/autofill.ts +469 -0
  10. package/src/utils/availability.ts +167 -0
  11. package/src/utils/candidates.ts +447 -0
  12. package/src/utils/coverage.helpers.ts +509 -554
  13. package/src/utils/coverage.ts +1121 -526
  14. package/src/utils/cpm.helpers.ts +27 -29
  15. package/src/utils/cpm.ts +53 -41
  16. package/src/utils/cpmLeveling.helpers.ts +89 -16
  17. package/src/utils/cpmLeveling.ts +28 -26
  18. package/src/utils/cycle.ts +325 -0
  19. package/src/utils/demand.ts +239 -0
  20. package/src/utils/eligibility.ts +553 -400
  21. package/src/utils/ids.ts +47 -0
  22. package/src/utils/laborRules.ts +740 -0
  23. package/src/utils/localTime.ts +312 -0
  24. package/src/utils/offer.ts +300 -0
  25. package/src/utils/planCsv.ts +73 -19
  26. package/src/utils/predicate.ts +111 -0
  27. package/src/utils/request.ts +212 -114
  28. package/src/utils/resource.ts +412 -112
  29. package/src/utils/rule.ts +697 -163
  30. package/src/utils/rulePresets.ts +116 -0
  31. package/src/utils/run.ts +0 -8
  32. package/src/utils/scheduleText.ts +4074 -0
  33. package/src/utils/shiftChange.ts +279 -0
  34. package/src/utils/standing.ts +730 -0
  35. package/src/utils/template.ts +619 -0
  36. package/src/utils/violation.ts +184 -0
  37. package/src/utils/workTime.ts +341 -120
  38. package/src/utils/defaults.ts +0 -8
  39. package/src/utils/recurrence.ts +0 -616
  40. package/src/utils/series.ts +0 -161
  41. package/src/utils/slot.ts +0 -208
  42. package/tests/coverage.fixtures.ts +0 -111
  43. package/tests/coverage.test.ts +0 -503
  44. package/tests/cpm.bench.test.ts +0 -154
  45. package/tests/cpm.test.ts +0 -354
  46. package/tests/cpmCorrectness.test.ts +0 -327
  47. package/tests/cpmLeveling.test.ts +0 -471
  48. package/tests/eligibility.test.ts +0 -320
  49. package/tests/gantt-geometry.test.ts +0 -367
  50. package/tests/gantt-histogram.test.ts +0 -78
  51. package/tests/gantt-keyboard.test.ts +0 -69
  52. package/tests/helpers/cpmFixtures.ts +0 -101
  53. package/tests/projectInputs.test.ts +0 -165
  54. package/tests/recurrence.test.ts +0 -68
  55. package/tests/request.test.ts +0 -99
  56. package/tests/resource.test.ts +0 -95
  57. package/tests/rule.test.ts +0 -98
  58. package/tests/series.test.ts +0 -120
  59. package/tests/workTime.test.ts +0 -1007
  60. package/tests/workTimeContracts.test.ts +0 -111
  61. package/tsconfig.json +0 -13
  62. package/vitest.config.ts +0 -8
@@ -1,503 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- evaluateScheduleCoverage,
4
- hasBlockingViolations,
5
- } from '../src/utils/coverage.ts';
6
- import {
7
- at,
8
- person,
9
- rule,
10
- shift,
11
- slot,
12
- snapshot,
13
- } from './coverage.fixtures.ts';
14
-
15
- /* Project violation intervals for readable half-open stretch assertions. */
16
- function intervals(
17
- result: ReturnType<typeof evaluateScheduleCoverage>,
18
- kind: string,
19
- code?: string,
20
- ) {
21
- return result.violations
22
- .filter((v) => v.kind === kind && (!code || v.code === code))
23
- .map((v) => [v.startAt.toISOString(), v.endAt.toISOString(), v.degree]);
24
- }
25
-
26
- describe('per-instant coverage', () => {
27
- it('combines adults from multiple shifts in a room', () => {
28
- const result = evaluateScheduleCoverage(
29
- snapshot({
30
- occurrences: [shift('10', ['1', '2']), shift('11', ['3'])],
31
- demand: [
32
- {
33
- id: 'd',
34
- resourceId: 'room',
35
- key: 'INFANT',
36
- quantity: 12,
37
- startAt: at(8),
38
- endAt: at(12),
39
- },
40
- ],
41
- rules: [
42
- rule('DERIVED_COUNT', { ratios: { INFANT: 4 }, predicate: null }),
43
- ],
44
- }),
45
- );
46
- expect(result.violations).toEqual([]);
47
- });
48
- it('sums overlapping demand instead of taking the peak', () => {
49
- const result = evaluateScheduleCoverage(
50
- snapshot({
51
- occurrences: [shift('10', ['1', '2'])],
52
- demand: [
53
- {
54
- id: 'd1',
55
- resourceId: 'room',
56
- key: 'INFANT',
57
- quantity: 6,
58
- startAt: at(8),
59
- endAt: at(11),
60
- },
61
- {
62
- id: 'd2',
63
- resourceId: 'room',
64
- key: 'INFANT',
65
- quantity: 6,
66
- startAt: at(9),
67
- endAt: at(12),
68
- },
69
- ],
70
- rules: [
71
- rule('DERIVED_COUNT', { ratios: { INFANT: 4 }, predicate: null }),
72
- ],
73
- }),
74
- );
75
- expect(intervals(result, 'DERIVED_COUNT')).toEqual([[at(9), at(11), 1]]);
76
- });
77
- it('licensed capacity judges children, never shifts or blocks', () => {
78
- const base = snapshot({
79
- resources: [person('room', { kind: 'SPACE', capacity: 1 })],
80
- occurrences: [
81
- shift('10'),
82
- shift('11'),
83
- shift('12', [], { kind: 'BLOCK' }),
84
- ],
85
- });
86
- expect(intervals(evaluateScheduleCoverage(base), 'ROOM_CAPACITY')).toEqual(
87
- [],
88
- );
89
- expect(
90
- intervals(
91
- evaluateScheduleCoverage({
92
- ...base,
93
- demand: [
94
- {
95
- id: 'd',
96
- resourceId: 'room',
97
- key: 'INFANT',
98
- quantity: 1.5,
99
- startAt: at(9),
100
- endAt: at(10),
101
- },
102
- ],
103
- }),
104
- 'ROOM_CAPACITY',
105
- ),
106
- ).toEqual([[at(9), at(10), 0.5]]);
107
- });
108
- it.each([1, 2])('places %i unslotted people once each', (count) => {
109
- const result = evaluateScheduleCoverage(
110
- snapshot({
111
- occurrences: [
112
- shift('10', [], {
113
- slots: [slot('a'), slot('b', { ordinal: 1 })],
114
- assignments: ['1', '2']
115
- .slice(0, count)
116
- .map((resourceId) => ({
117
- id: resourceId,
118
- resourceId,
119
- slotKey: null,
120
- })),
121
- }),
122
- ],
123
- }),
124
- );
125
- expect(result.violations.map((v) => v.slotKey)).toEqual(
126
- count === 1 ? ['b'] : [],
127
- );
128
- });
129
- it('does not overflow pinned people into another slot', () => {
130
- const result = evaluateScheduleCoverage(
131
- snapshot({
132
- occurrences: [
133
- shift('10', [], {
134
- slots: [slot('a'), slot('b', { ordinal: 1 })],
135
- assignments: ['1', '2'].map((resourceId) => ({
136
- id: resourceId,
137
- resourceId,
138
- slotKey: 'a',
139
- })),
140
- }),
141
- ],
142
- }),
143
- );
144
- expect(result.violations.map((v) => v.slotKey)).toEqual(['b']);
145
- });
146
- it.each([8, 10, 12])('cuts certificate expiry at hour %i', (expiry) => {
147
- const staff = person('1');
148
- staff.config.qualifications = [{ key: 'CPR', expiresAt: at(expiry) }];
149
- const result = evaluateScheduleCoverage(
150
- snapshot({
151
- resources: [staff],
152
- occurrences: [
153
- shift('10', ['1'], {
154
- resourceId: null,
155
- slots: [
156
- slot('teacher', { predicate: { qualifications: ['CPR'] } }),
157
- ],
158
- }),
159
- ],
160
- }),
161
- );
162
- expect(intervals(result, 'ELIGIBILITY', 'QUALIFICATION_EXPIRED')).toEqual(
163
- expiry === 12 ? [] : [[at(expiry), at(12), 1]],
164
- );
165
- expect(intervals(result, 'REQUIRED_COUNT')).toEqual(
166
- expiry === 12 ? [] : [[at(expiry), at(12), 1]],
167
- );
168
- });
169
- it('reports invalid expiry and treats it as expired', () => {
170
- const staff = person('1');
171
- staff.config.qualifications = [{ key: 'CPR', expiresAt: 'invalid' }];
172
- const result = evaluateScheduleCoverage(
173
- snapshot({
174
- resources: [staff],
175
- occurrences: [
176
- shift('10', ['1'], {
177
- resourceId: null,
178
- slots: [
179
- slot('teacher', { predicate: { qualifications: ['CPR'] } }),
180
- ],
181
- }),
182
- ],
183
- }),
184
- );
185
- expect(result.diagnostics.map((d) => d.code)).toEqual([
186
- 'QUALIFICATION_EXPIRY_INVALID',
187
- ]);
188
- expect(intervals(result, 'ELIGIBILITY', 'QUALIFICATION_EXPIRED')).toEqual([
189
- [at(8), at(12), 1],
190
- ]);
191
- });
192
- it('reports unslotted expired qualifications', () => {
193
- const staff = person('1');
194
- staff.config.qualifications = [{ key: 'CPR', expiresAt: at(10) }];
195
- const result = evaluateScheduleCoverage(
196
- snapshot({
197
- resources: [staff],
198
- occurrences: [
199
- shift('10', [], {
200
- resourceId: null,
201
- slots: [
202
- slot('teacher', { predicate: { qualifications: ['CPR'] } }),
203
- ],
204
- assignments: [{ id: 'a', resourceId: '1', slotKey: null }],
205
- }),
206
- ],
207
- }),
208
- );
209
- expect(intervals(result, 'ELIGIBILITY', 'QUALIFICATION_EXPIRED')).toEqual([
210
- [at(10), at(12), 1],
211
- ]);
212
- });
213
- it('flags an unknown slot while using its assignee as unslotted', () => {
214
- const result = evaluateScheduleCoverage(
215
- snapshot({
216
- occurrences: [
217
- shift('10', [], {
218
- assignments: [{ id: 'a', resourceId: '1', slotKey: 'typo' }],
219
- }),
220
- ],
221
- }),
222
- );
223
- expect(result.diagnostics.map((d) => d.code)).toEqual(['UNKNOWN_SLOT_KEY']);
224
- expect(result.violations.map((v) => v.code)).toEqual(['SLOT_UNKNOWN']);
225
- });
226
- it('allows room-less shifts and reports an unknown room without discarding staff', () => {
227
- expect(
228
- evaluateScheduleCoverage(
229
- snapshot({ occurrences: [shift('10', ['1'], { resourceId: null })] }),
230
- ).diagnostics,
231
- ).toEqual([]);
232
- const result = evaluateScheduleCoverage(
233
- snapshot({
234
- occurrences: [shift('10', ['1'], { resourceId: 'unknown' })],
235
- }),
236
- );
237
- expect(result.diagnostics.map((d) => d.code)).toEqual(['UNKNOWN_RESOURCE']);
238
- expect(result.violations).toEqual([]);
239
- });
240
- it('cuts time-off to the actual interval', () => {
241
- const result = evaluateScheduleCoverage(
242
- snapshot({
243
- occurrences: [shift('10', ['1'])],
244
- timeOff: [
245
- { id: 'off', resourceId: '1', startAt: at(9), endAt: at(10) },
246
- ],
247
- }),
248
- );
249
- expect(intervals(result, 'ELIGIBILITY', 'TIME_OFF')).toEqual([
250
- [at(9), at(10), 1],
251
- ]);
252
- });
253
- it('emits own overlap once on the larger numeric shift id', () => {
254
- const result = evaluateScheduleCoverage(
255
- snapshot({
256
- occurrences: [
257
- shift('9', ['1']),
258
- shift('10', ['1'], { startAt: at(10), endAt: at(14) }),
259
- ],
260
- }),
261
- );
262
- expect(intervals(result, 'ELIGIBILITY', 'OVERLAP')).toEqual([
263
- [at(10), at(12), 1],
264
- ]);
265
- expect(
266
- result.violations.find((v) => v.code === 'OVERLAP')?.occurrenceId,
267
- ).toBe('10');
268
- });
269
- it('cuts external overlap at external endpoints', () => {
270
- const result = evaluateScheduleCoverage(
271
- snapshot({
272
- occurrences: [shift('10', ['1'])],
273
- external: [
274
- {
275
- occurrenceId: '20',
276
- calendarId: 'other',
277
- resourceId: '1',
278
- kind: 'SHIFT',
279
- startAt: at(9),
280
- endAt: at(10),
281
- },
282
- ],
283
- }),
284
- );
285
- expect(intervals(result, 'ELIGIBILITY', 'OVERLAP')).toEqual([
286
- [at(9), at(10), 1],
287
- ]);
288
- });
289
- it('deduplicates own rows loaded again as external evidence', () => {
290
- const result = evaluateScheduleCoverage(
291
- snapshot({
292
- occurrences: [shift('10', ['1'])],
293
- external: [
294
- {
295
- occurrenceId: '10',
296
- calendarId: 'calendar',
297
- resourceId: '1',
298
- kind: 'SHIFT',
299
- startAt: at(8),
300
- endAt: at(12),
301
- },
302
- ],
303
- }),
304
- );
305
- expect(result.violations).toEqual([]);
306
- });
307
- it('does not apply eligibility to EVENT assignments', () => {
308
- const result = evaluateScheduleCoverage(
309
- snapshot({
310
- occurrences: [
311
- shift('10', ['1']),
312
- shift('11', ['1'], { kind: 'EVENT' }),
313
- shift('12', ['1'], { kind: 'EVENT' }),
314
- ],
315
- timeOff: [
316
- { id: 'off', resourceId: '1', startAt: at(8), endAt: at(12) },
317
- ],
318
- }),
319
- );
320
- expect(
321
- result.violations
322
- .filter((v) => v.kind === 'ELIGIBILITY')
323
- .every((v) => v.occurrenceId === '10'),
324
- ).toBe(true);
325
- });
326
- it('requires adults in an empty open center except during BLOCK closures', () => {
327
- const result = evaluateScheduleCoverage(
328
- snapshot({
329
- operatingHours: {
330
- id: 'work',
331
- timeZone: 'UTC',
332
- minutesPerDay: 480,
333
- weekHours: { '1': [['08:00', '12:00']] },
334
- exceptions: null,
335
- },
336
- rules: [rule('OPERATING_HOURS', { minAdults: 2, predicate: null })],
337
- occurrences: [
338
- shift('closed', [], {
339
- kind: 'BLOCK',
340
- resourceId: null,
341
- startAt: at(9),
342
- endAt: at(10),
343
- }),
344
- ],
345
- }),
346
- );
347
- expect(intervals(result, 'OPERATING_HOURS')).toEqual([
348
- [at(8), at(9), 2],
349
- [at(10), at(12), 2],
350
- ]);
351
- });
352
- it('counts floaters in the center without counting them in a room', () => {
353
- const result = evaluateScheduleCoverage(
354
- snapshot({
355
- operatingHours: {
356
- id: 'work',
357
- timeZone: 'UTC',
358
- minutesPerDay: 240,
359
- weekHours: { '1': [['08:00', '12:00']] },
360
- exceptions: null,
361
- },
362
- rules: [
363
- rule('OPERATING_HOURS', { minAdults: 1, predicate: null }),
364
- rule(
365
- 'OPERATING_HOURS',
366
- { minAdults: 1, predicate: null },
367
- { id: 'roomRule', resourceId: 'room' },
368
- ),
369
- ],
370
- occurrences: [shift('10', ['1'], { resourceId: null })],
371
- }),
372
- );
373
- expect(result.violations.map((v) => v.resourceId)).toEqual(['room']);
374
- });
375
- it('diagnoses missing operating hours only when a rule applies', () => {
376
- expect(evaluateScheduleCoverage(snapshot()).diagnostics).toEqual([]);
377
- expect(
378
- evaluateScheduleCoverage(
379
- snapshot({
380
- rules: [rule('OPERATING_HOURS', { minAdults: 1, predicate: null })],
381
- }),
382
- ).diagnostics.map((d) => d.code),
383
- ).toEqual(['OPERATING_HOURS_NOT_CONFIGURED']);
384
- });
385
- it('loads history into rolling totals without making external rows subjects', () => {
386
- const result = evaluateScheduleCoverage(
387
- snapshot({
388
- occurrences: [shift('10', ['1'])],
389
- external: [
390
- {
391
- occurrenceId: '9',
392
- calendarId: 'other',
393
- resourceId: '1',
394
- kind: 'SHIFT',
395
- startAt: at(8, 6),
396
- endAt: at(16, 6),
397
- },
398
- ],
399
- rules: [
400
- rule('ACTOR_WINDOW_AGGREGATE', {
401
- windowDays: 7,
402
- maxMinutes: 600,
403
- minRestMinutes: null,
404
- }),
405
- ],
406
- }),
407
- );
408
- expect(intervals(result, 'ACTOR_WINDOW_AGGREGATE', 'HOURS')).toEqual([
409
- [at(8), at(12), 120],
410
- ]);
411
- });
412
- it.each([11, 12])(
413
- 'judges rest for a subsequent shift beginning at %i',
414
- (start) => {
415
- const result = evaluateScheduleCoverage(
416
- snapshot({
417
- occurrences: [
418
- shift('10', ['1']),
419
- shift('11', ['1'], { startAt: at(start), endAt: at(14) }),
420
- ],
421
- rules: [
422
- rule('ACTOR_WINDOW_AGGREGATE', {
423
- windowDays: null,
424
- maxMinutes: null,
425
- minRestMinutes: 60,
426
- }),
427
- ],
428
- }),
429
- );
430
- expect(intervals(result, 'ACTOR_WINDOW_AGGREGATE', 'REST')).toEqual(
431
- start === 11 ? [] : [[at(12), at(14), 60]],
432
- );
433
- },
434
- );
435
- it('is deterministic across input order and preserves warning-only publication', () => {
436
- const base = snapshot({
437
- occurrences: [shift('10'), shift('11')],
438
- rules: [rule('REQUIRED_COUNT', {}, { severity: 'WARN' })],
439
- });
440
- const a = evaluateScheduleCoverage(base);
441
- expect(
442
- evaluateScheduleCoverage({
443
- ...base,
444
- occurrences: [...base.occurrences].reverse(),
445
- resources: [...base.resources].reverse(),
446
- }),
447
- ).toEqual(a);
448
- expect(hasBlockingViolations(a.violations)).toBe(false);
449
- });
450
- it('clips output and preserves a sixty-character slot key', () => {
451
- const key = 'x'.repeat(60);
452
- const result = evaluateScheduleCoverage(
453
- snapshot({
454
- window: { from: at(9), to: at(10) },
455
- occurrences: [shift('10', [], { slots: [slot(key)] })],
456
- }),
457
- );
458
- expect(intervals(result, 'REQUIRED_COUNT')).toEqual([[at(9), at(10), 1]]);
459
- expect(result.violations[0].identity).toContain(key);
460
- expect(result.violations[0].key.length).toBeLessThan(255);
461
- });
462
- });
463
-
464
- describe('coverage scale', () => {
465
- it('evaluates 150 staff across two weeks and a maximum-size window', () => {
466
- for (const days of [14, 62]) {
467
- const resources = [
468
- person('room', { kind: 'SPACE', capacity: 600 }),
469
- ...Array.from({ length: 150 }, (_, i) => person(String(i + 1))),
470
- ];
471
- const occurrences = Array.from({ length: days }, (_, day) =>
472
- Array.from({ length: 150 }, (_, index) =>
473
- shift(String(day * 150 + index + 1), [String(index + 1)], {
474
- startAt: at(8, 7 + day),
475
- endAt: at(16, 7 + day),
476
- }),
477
- ),
478
- ).flat();
479
- const base = snapshot({
480
- resources,
481
- occurrences,
482
- window: { from: at(0), to: at(0, 7 + days) },
483
- rules: [
484
- rule('ACTOR_WINDOW_AGGREGATE', {
485
- windowDays: 7,
486
- maxMinutes: 4000,
487
- minRestMinutes: 480,
488
- }),
489
- ],
490
- });
491
- const started = performance.now();
492
- const result = evaluateScheduleCoverage(base);
493
- const elapsed = performance.now() - started;
494
- expect(result.violations).toEqual([]);
495
- expect(result.diagnostics).toEqual([]);
496
- expect(elapsed).toBeLessThan(1500);
497
- if (process.env.BENCH)
498
- console.log(
499
- `coverage ${days} days / ${occurrences.length} shifts: ${elapsed.toFixed(1)} ms`,
500
- );
501
- }
502
- });
503
- });
@@ -1,154 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type {
3
- CpmActivityInput,
4
- CpmRelationshipInput,
5
- } from '../src/types/schedule.d.ts';
6
- import {
7
- buildWorkCalendarTable,
8
- getStandardWorkCalendarDef,
9
- } from '../src/utils/workTime.ts';
10
- import {
11
- assignment,
12
- fs,
13
- level,
14
- resource,
15
- schedule,
16
- task,
17
- } from './helpers/cpmFixtures.ts';
18
-
19
- /* Build seeded construction DAG components, keeping the generated project inside its forty-year horizon. */
20
- function network(count: number, edgeCount: number) {
21
- let seed = 42;
22
- /* Produce stable pseudo-random values independently of the host runtime. */
23
- const random = () => {
24
- seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
25
- return seed / 4294967296;
26
- };
27
- const activities: CpmActivityInput[] = Array.from({ length: count }, (_, i) =>
28
- task(String(i), 1 + Math.floor(random() * 30), {
29
- type:
30
- i % 50 === 0
31
- ? 'LEVEL_OF_EFFORT'
32
- : i % 20 === 0
33
- ? 'FINISH_MILESTONE'
34
- : 'TASK',
35
- wbsId: String(i % 100),
36
- }),
37
- );
38
- const relationships: CpmRelationshipInput[] = [];
39
- const seen = new Set<string>();
40
- while (relationships.length < edgeCount) {
41
- const from = Math.floor(random() * (count - 20));
42
- const to = from + 1 + Math.floor(random() * 19);
43
- if (Math.floor(from / 200) !== Math.floor(to / 200)) continue;
44
- const key = `${from}:${to}`;
45
- if (seen.has(key)) continue;
46
- seen.add(key);
47
- relationships.push(
48
- fs(
49
- String(from),
50
- String(to),
51
- (Math.floor(random() * 3) - 1) * 480,
52
- (['FS', 'SS', 'FF', 'SF'] as const)[Math.floor(random() * 4)],
53
- ),
54
- );
55
- }
56
- return { activities, relationships };
57
- }
58
-
59
- /* Run opt-in timing gates separately from correctness suites to avoid machine contention. */
60
- describe.skipIf(process.env.SCHEDULE_BENCH !== '1')(
61
- 'CPM performance gates',
62
- () => {
63
- it.each([
64
- [5000, 10000, 1000],
65
- [20000, 60000, 6000],
66
- ])(
67
- 'schedules %i activities and %i relationships under %i ms',
68
- (count, edges, limit) => {
69
- const input = network(count, edges);
70
- const start = performance.now();
71
- const result = schedule(input.activities, input.relationships);
72
- const elapsed = performance.now() - start;
73
- console.log(`CPM ${count}/${edges}: ${elapsed.toFixed(1)} ms`);
74
- expect(result.ok).toBe(true);
75
- expect(elapsed).toBeLessThan(limit);
76
- },
77
- 15000,
78
- );
79
- it('levels 5000 activities on 50 resources over two years under four seconds', () => {
80
- const input = network(5000, 10000);
81
- const resources = Array.from({ length: 50 }, (_, i) =>
82
- resource(String(i)),
83
- );
84
- const assignments = input.activities
85
- .filter((a) => a.type === 'TASK')
86
- .flatMap((a, i) =>
87
- i % 2
88
- ? [assignment(a.id, String(i % 50), 240)]
89
- : [
90
- assignment(a.id, String(i % 50), 240),
91
- assignment(a.id, String((i + 1) % 50), 240),
92
- ],
93
- );
94
- const externalUsage = resources
95
- .filter((_, i) => i % 5 === 0)
96
- .map((r) => ({
97
- resourceId: r.id,
98
- startAt: new Date('2026-01-05T16:00:00Z'),
99
- finishAt: new Date('2026-06-01T00:00:00Z'),
100
- unitsPerDay: 48,
101
- }));
102
- const start = performance.now();
103
- const result = level(input.activities, {
104
- relationships: input.relationships,
105
- assignments,
106
- resources,
107
- externalUsage,
108
- });
109
- const elapsed = performance.now() - start;
110
- console.log(`Leveling 5000×50×730: ${elapsed.toFixed(1)} ms`);
111
- expect(result.ok).toBe(true);
112
- expect(result.stats.leveled).toBe(true);
113
- expect(elapsed).toBeLessThan(4000);
114
- }, 15000);
115
- it('reports a 20000-node loop without recursion under one second', () => {
116
- const activities = Array.from({ length: 20000 }, (_, i) =>
117
- task(String(i)),
118
- );
119
- const relationships = activities.map((a, i) =>
120
- fs(a.id, String((i + 1) % activities.length)),
121
- );
122
- const start = performance.now();
123
- const result = schedule(activities, relationships);
124
- const elapsed = performance.now() - start;
125
- console.log(`Cycle 20000: ${elapsed.toFixed(1)} ms`);
126
- expect(result.stats.cycleCount).toBe(1);
127
- expect(elapsed).toBeLessThan(1000);
128
- });
129
- it('schedules 20000 unlinked activities with bounded diagnostics under 500 ms', () => {
130
- const activities = Array.from({ length: 20000 }, (_, i) =>
131
- task(String(i)),
132
- );
133
- const start = performance.now();
134
- const result = schedule(activities);
135
- const elapsed = performance.now() - start;
136
- console.log(`Unlinked 20000: ${elapsed.toFixed(1)} ms`);
137
- expect(result.diagnostics.length).toBe(400);
138
- expect(result.stats.openStartCount).toBe(19999);
139
- expect(elapsed).toBeLessThan(500);
140
- });
141
- it('builds ten-year tables for three calendars under 300 ms', () => {
142
- const start = performance.now();
143
- for (const zone of ['UTC', 'America/New_York', 'Europe/London'])
144
- buildWorkCalendarTable(
145
- getStandardWorkCalendarDef(zone),
146
- new Date('2026-01-01T00:00:00Z'),
147
- new Date('2036-01-01T00:00:00Z'),
148
- );
149
- const elapsed = performance.now() - start;
150
- console.log(`Calendar tables 3×10 years: ${elapsed.toFixed(1)} ms`);
151
- expect(elapsed).toBeLessThan(300);
152
- });
153
- },
154
- );