@jsb188/schedule 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +61 -0
- package/src/constants/schedule.ts +549 -0
- package/src/css.d.ts +7 -0
- package/src/libs/gantt-geometry.ts +771 -0
- package/src/libs/gantt-histogram.ts +124 -0
- package/src/libs/gantt-keyboard.ts +113 -0
- package/src/libs/gantt-state.ts +57 -0
- package/src/libs/gantt-url.ts +63 -0
- package/src/modules/Gantt.helpers.ts +138 -0
- package/src/modules/Gantt.tsx +719 -0
- package/src/types/schedule.d.ts +1149 -0
- package/src/ui/ActivityFormUI.tsx +133 -0
- package/src/ui/GanttEditorsUI.tsx +102 -0
- package/src/ui/GanttHistogramUI.tsx +236 -0
- package/src/ui/GanttUI.tsx +792 -0
- package/src/ui/ProjectFormUI.tsx +273 -0
- package/src/ui/ProjectMobileListUI.tsx +80 -0
- package/src/ui/ProjectToolbarUI.tsx +54 -0
- package/src/ui/RelationshipListUI.tsx +176 -0
- package/src/ui/ScheduleRunUI.tsx +173 -0
- package/src/ui/ScheduleSettingsUI.tsx +420 -0
- package/src/utils/coverage.helpers.ts +679 -0
- package/src/utils/coverage.ts +630 -0
- package/src/utils/cpm.helpers.ts +674 -0
- package/src/utils/cpm.ts +907 -0
- package/src/utils/cpmLeveling.helpers.ts +564 -0
- package/src/utils/cpmLeveling.ts +367 -0
- package/src/utils/defaults.ts +8 -0
- package/src/utils/eligibility.ts +457 -0
- package/src/utils/planCsv.ts +344 -0
- package/src/utils/predecessorText.ts +96 -0
- package/src/utils/recurrence.ts +616 -0
- package/src/utils/request.ts +153 -0
- package/src/utils/resource.ts +182 -0
- package/src/utils/rule.ts +216 -0
- package/src/utils/run.ts +43 -0
- package/src/utils/series.ts +161 -0
- package/src/utils/slot.ts +208 -0
- package/src/utils/workTime.ts +1382 -0
- package/tests/coverage.fixtures.ts +111 -0
- package/tests/coverage.test.ts +503 -0
- package/tests/cpm.bench.test.ts +154 -0
- package/tests/cpm.test.ts +354 -0
- package/tests/cpmCorrectness.test.ts +327 -0
- package/tests/cpmLeveling.test.ts +471 -0
- package/tests/eligibility.test.ts +320 -0
- package/tests/gantt-geometry.test.ts +367 -0
- package/tests/gantt-histogram.test.ts +78 -0
- package/tests/gantt-keyboard.test.ts +69 -0
- package/tests/helpers/cpmFixtures.ts +101 -0
- package/tests/projectInputs.test.ts +165 -0
- package/tests/recurrence.test.ts +68 -0
- package/tests/request.test.ts +99 -0
- package/tests/resource.test.ts +95 -0
- package/tests/rule.test.ts +98 -0
- package/tests/series.test.ts +120 -0
- package/tests/workTime.test.ts +1007 -0
- package/tests/workTimeContracts.test.ts +111 -0
- package/tsconfig.json +13 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,327 @@
|
|
|
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
|
+
});
|