@jsb188/mday 1.1.10 → 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 +105 -54
- package/src/constants/agentDoc.ts +12 -0
- package/src/constants/agentMemory.ts +154 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/campaign.ts +127 -0
- package/src/constants/dataTable.ts +35 -9
- package/src/constants/dataTableFieldTypes.generated.ts +63 -0
- package/src/constants/docAccess.ts +32 -0
- package/src/constants/email.ts +20 -4
- package/src/constants/fieldDoc.ts +34 -0
- package/src/constants/graphqlReactivity.ts +113 -0
- package/src/constants/integration.ts +8 -9
- package/src/constants/log.ts +7 -410
- package/src/constants/logActivityGroupColors.generated.ts +19 -0
- package/src/constants/logTaxonomy.generated.ts +1103 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +13 -15
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/schedule.ts +220 -0
- package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
- package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
- package/src/constants/sheet.ts +154 -6
- package/src/constants/sheetRegionSources.generated.ts +578 -0
- package/src/constants/square.ts +6 -6
- package/src/constants/storage.ts +56 -7
- package/src/constants/usage.ts +79 -0
- package/src/schemas/editLogEntry.ts +1010 -777
- package/src/schemas/fieldDocsQuery.ts +12 -0
- package/src/schemas/inboundContact.ts +60 -55
- package/src/schemas/logsQuery.ts +55 -49
- package/src/schemas/organization.ts +49 -46
- package/src/types/account.d.ts +4 -1
- package/src/types/agentDoc.d.ts +64 -0
- package/src/types/agentMemory.d.ts +74 -0
- package/src/types/campaign.d.ts +683 -0
- package/src/types/dataTable.d.ts +175 -256
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/email.d.ts +83 -12
- package/src/types/fieldDoc.d.ts +273 -0
- package/src/types/inboundContact.d.ts +2 -1
- package/src/types/log.d.ts +209 -341
- package/src/types/noteDoc.d.ts +86 -0
- package/src/types/organization.d.ts +83 -40
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/schedule.d.ts +391 -0
- package/src/types/sheet.d.ts +862 -30
- package/src/types/storage.d.ts +206 -125
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +149 -18
- package/src/utils/agentDoc.ts +109 -0
- package/src/utils/aiChat.ts +26 -0
- package/src/utils/campaign.ts +741 -0
- package/src/utils/campaignFormEditor.ts +871 -0
- package/src/utils/dataTable.ts +425 -410
- package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
- package/src/utils/dataTableRealtimeAuthority.ts +209 -0
- package/src/utils/dataTableRealtimeSelection.ts +134 -0
- package/src/utils/dataTableRowDocument.ts +508 -0
- package/src/utils/dataTableSource.ts +230 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +112 -53
- package/src/utils/fieldDoc.ts +113 -0
- package/src/utils/log.ts +169 -176
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +266 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +439 -0
- package/src/utils/noteDoc.ts +827 -0
- package/src/utils/organization.ts +510 -91
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/schedule.ts +799 -0
- package/src/utils/scheduleEvaluation.ts +1994 -0
- package/src/utils/scheduleICS.ts +246 -0
- package/src/utils/scheduleRuleTemplates.ts +188 -0
- package/src/utils/sheet.ts +4842 -39
- package/src/utils/sheetAxisMove.ts +830 -0
- package/src/utils/sheetBootstrap.ts +1769 -0
- package/src/utils/sheetCommand.ts +423 -0
- package/src/utils/sheetExport.ts +238 -0
- package/src/utils/sheetFormulaEvaluation.ts +914 -0
- package/src/utils/sheetFormulaEvaluator.ts +852 -0
- package/src/utils/sheetJournal.ts +78 -0
- package/src/utils/sheetNumberFormat.ts +1211 -0
- package/src/utils/sheetRegion.ts +374 -0
- package/src/utils/sheetRegionFilter.ts +1259 -0
- package/src/utils/sheetRegionSourceRegistry.ts +594 -0
- package/src/utils/sheetSequence.ts +148 -0
- package/src/utils/sheetSnapshot.ts +992 -0
- package/src/utils/sheetStructureEdit.ts +1284 -0
- package/src/utils/square.ts +22 -12
- package/src/utils/storage.ts +152 -0
- package/src/utils/table-route.ts +127 -11
- package/src/utils/workflow.ts +191 -23
- package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/noteDoc.test.ts +669 -0
- package/tests/schedule.test.ts +693 -0
- package/tests/scheduleEvaluation.test.ts +1970 -0
- package/tests/scheduleICS.test.ts +208 -0
- package/tests/scheduleRuleTemplates.test.ts +176 -0
- package/tests/scheduleSweepInvariants.test.ts +428 -0
- package/tests/sheetAxisMove.test.ts +343 -0
- package/tests/sheetFormulaEvaluator.test.ts +575 -0
- package/tests/sheetRegionFilter.test.ts +1135 -0
- package/tests/sheetSequence.test.ts +41 -0
- package/tests/sheetStructureEdit.test.ts +82 -0
- package/tsconfig.json +10 -10
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -235
- package/src/constants/product.ts +0 -42
- package/src/constants/report.ts +0 -44
- package/src/schemas/productsQuery.ts +0 -53
- package/src/schemas/reportsQuery.ts +0 -20
- package/src/types/product.d.ts +0 -84
- package/src/types/report.d.ts +0 -290
- package/src/utils/product-calEvent.ts +0 -455
- package/src/utils/report.ts +0 -158
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ScheduleEvalOccurrence,
|
|
3
|
+
ScheduleEvalRule,
|
|
4
|
+
ScheduleEvaluationSnapshot,
|
|
5
|
+
} from '@jsb188/mday/utils/scheduleEvaluation.ts';
|
|
6
|
+
import { evaluateScheduleWindow } from '@jsb188/mday/utils/scheduleEvaluation.ts';
|
|
7
|
+
import { describe, expect, it } from 'vitest';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Invariants of the sweep, checked across a corpus rather than one case each.
|
|
11
|
+
*
|
|
12
|
+
* The example-based suite next door pins what each rule kind decides. This file
|
|
13
|
+
* pins the properties the SWEEP itself has to have for those decisions to mean
|
|
14
|
+
* anything — and it exists because the bug that motivated it passed every
|
|
15
|
+
* example test there was. A snapshot's answer must not depend on how finely the
|
|
16
|
+
* window happened to be cut, nor on the order the inputs arrived in; both are
|
|
17
|
+
* implementation details of the sweep, and both have silently changed the
|
|
18
|
+
* answer before.
|
|
19
|
+
*
|
|
20
|
+
* There is no property-testing library in this repo and this does not add one.
|
|
21
|
+
* The corpus is enumerated by hand and the perturbations are exhaustive over a
|
|
22
|
+
* small bounded domain, so a failure names one concrete case instead of a seed.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const LA = 'America/Los_Angeles';
|
|
26
|
+
|
|
27
|
+
const at = (iso: string) => new Date(iso);
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Build one shift with its slot and assignees.
|
|
31
|
+
*/
|
|
32
|
+
function shift(parts: {
|
|
33
|
+
id: string;
|
|
34
|
+
resourceId?: string | null;
|
|
35
|
+
startAt: string;
|
|
36
|
+
endAt: string;
|
|
37
|
+
kind?: ScheduleEvalOccurrence['kind'];
|
|
38
|
+
requiredCount?: number;
|
|
39
|
+
assignees?: Array<{
|
|
40
|
+
id: string;
|
|
41
|
+
qualifications?: string[];
|
|
42
|
+
expiresAt?: string;
|
|
43
|
+
}>;
|
|
44
|
+
}): ScheduleEvalOccurrence {
|
|
45
|
+
const slotId = `${parts.id}-slot`;
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
id: parts.id,
|
|
49
|
+
kind: parts.kind || 'SHIFT',
|
|
50
|
+
resourceId: parts.resourceId === undefined ? 'room-a' : parts.resourceId,
|
|
51
|
+
startAt: at(parts.startAt),
|
|
52
|
+
endAt: at(parts.endAt),
|
|
53
|
+
slots: [
|
|
54
|
+
{
|
|
55
|
+
id: slotId,
|
|
56
|
+
key: 'lead',
|
|
57
|
+
requiredCount: parts.requiredCount ?? 1,
|
|
58
|
+
predicate: null,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
assignments: (parts.assignees || []).map((assignee) => ({
|
|
62
|
+
id: `${parts.id}-${assignee.id}`,
|
|
63
|
+
slotId,
|
|
64
|
+
actorType: 'ACCOUNT' as const,
|
|
65
|
+
actorId: assignee.id,
|
|
66
|
+
actorAccountId: assignee.id,
|
|
67
|
+
startAt: null,
|
|
68
|
+
endAt: null,
|
|
69
|
+
role: null,
|
|
70
|
+
qualifications: assignee.qualifications ?? [],
|
|
71
|
+
qualificationExpiry: assignee.expiresAt
|
|
72
|
+
? { CPR: at(assignee.expiresAt) }
|
|
73
|
+
: null,
|
|
74
|
+
tags: [],
|
|
75
|
+
})),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
* Build one rule at a chosen scope level.
|
|
81
|
+
*/
|
|
82
|
+
function rule(
|
|
83
|
+
parts: Partial<ScheduleEvalRule> & Pick<ScheduleEvalRule, 'id' | 'kind'>,
|
|
84
|
+
): ScheduleEvalRule {
|
|
85
|
+
return {
|
|
86
|
+
severity: 'BLOCK',
|
|
87
|
+
config: {},
|
|
88
|
+
operationTypeId: null,
|
|
89
|
+
organizationId: 'org-1',
|
|
90
|
+
calendarId: null,
|
|
91
|
+
resourceId: null,
|
|
92
|
+
effectiveFrom: null,
|
|
93
|
+
effectiveTo: null,
|
|
94
|
+
ordinal: 0,
|
|
95
|
+
...parts,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/*
|
|
100
|
+
* Build one snapshot over a fixed August day.
|
|
101
|
+
*/
|
|
102
|
+
function snapshot(
|
|
103
|
+
parts: Partial<ScheduleEvaluationSnapshot> = {},
|
|
104
|
+
): ScheduleEvaluationSnapshot {
|
|
105
|
+
return {
|
|
106
|
+
windowStart: at('2026-08-03T07:00:00Z'),
|
|
107
|
+
windowEnd: at('2026-08-04T07:00:00Z'),
|
|
108
|
+
timeZone: LA,
|
|
109
|
+
occurrences: [],
|
|
110
|
+
demand: [],
|
|
111
|
+
resources: [{ id: 'room-a', key: 'room-a', capacity: null, config: null }],
|
|
112
|
+
rules: [],
|
|
113
|
+
...parts,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/*
|
|
118
|
+
* Render one evaluation as a comparable value. Dates become ISO strings so a
|
|
119
|
+
* mismatch reads as the times it actually disagrees about.
|
|
120
|
+
*/
|
|
121
|
+
function fingerprint(snapshotToRun: ScheduleEvaluationSnapshot) {
|
|
122
|
+
return evaluateScheduleWindow(snapshotToRun)
|
|
123
|
+
.violations.map((violation) =>
|
|
124
|
+
[
|
|
125
|
+
violation.ruleId,
|
|
126
|
+
violation.kind,
|
|
127
|
+
violation.resourceId ?? '',
|
|
128
|
+
violation.occurrenceId ?? '',
|
|
129
|
+
violation.actorAccountId ?? '',
|
|
130
|
+
violation.segmentStart.toISOString(),
|
|
131
|
+
violation.segmentEnd.toISOString(),
|
|
132
|
+
JSON.stringify(violation.detail),
|
|
133
|
+
].join('|'),
|
|
134
|
+
)
|
|
135
|
+
.sort();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/*
|
|
139
|
+
* Return a copy of one snapshot with an extra sweep boundary at an instant, and
|
|
140
|
+
* no change to what any rule decides.
|
|
141
|
+
*
|
|
142
|
+
* The injector is a rule that can never win: it carries the same rule identity
|
|
143
|
+
* as one already present but sits at operation-type scope, which every
|
|
144
|
+
* organization-scoped rule beats. getSegmentBoundaries collects effective dates
|
|
145
|
+
* from EVERY rule rather than only the winners, so the losing rule contributes
|
|
146
|
+
* its cut point and nothing else — which is exactly the perturbation this file
|
|
147
|
+
* needs to be able to make.
|
|
148
|
+
*/
|
|
149
|
+
function withExtraBoundary(
|
|
150
|
+
base: ScheduleEvaluationSnapshot,
|
|
151
|
+
at_: Date,
|
|
152
|
+
): ScheduleEvaluationSnapshot {
|
|
153
|
+
return {
|
|
154
|
+
...base,
|
|
155
|
+
rules: [
|
|
156
|
+
...base.rules,
|
|
157
|
+
rule({
|
|
158
|
+
id: `boundary-${at_.getTime()}`,
|
|
159
|
+
kind: 'REQUIRED_COUNT',
|
|
160
|
+
operationTypeId: 'op-1',
|
|
161
|
+
organizationId: null,
|
|
162
|
+
effectiveFrom: at_,
|
|
163
|
+
}),
|
|
164
|
+
],
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/*
|
|
169
|
+
* The corpus. Each case is one snapshot the sweep has to answer consistently;
|
|
170
|
+
* between them they reach all five segment-local rule kinds, both cross-segment
|
|
171
|
+
* kinds, a partial-day gap, an expiring credential, and an empty day.
|
|
172
|
+
*/
|
|
173
|
+
const CASES: Array<{ id: string; snapshot: ScheduleEvaluationSnapshot }> = [
|
|
174
|
+
{
|
|
175
|
+
id: 'staffing shortfall',
|
|
176
|
+
snapshot: snapshot({
|
|
177
|
+
occurrences: [
|
|
178
|
+
shift({
|
|
179
|
+
id: 's1',
|
|
180
|
+
startAt: '2026-08-03T15:00:00Z',
|
|
181
|
+
endAt: '2026-08-03T19:00:00Z',
|
|
182
|
+
requiredCount: 2,
|
|
183
|
+
assignees: [{ id: 'a1' }],
|
|
184
|
+
}),
|
|
185
|
+
],
|
|
186
|
+
rules: [rule({ id: 'staffing', kind: 'REQUIRED_COUNT' })],
|
|
187
|
+
}),
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
id: 'room over capacity',
|
|
191
|
+
snapshot: snapshot({
|
|
192
|
+
occurrences: [
|
|
193
|
+
shift({
|
|
194
|
+
id: 'c1',
|
|
195
|
+
startAt: '2026-08-03T15:00:00Z',
|
|
196
|
+
endAt: '2026-08-03T19:00:00Z',
|
|
197
|
+
requiredCount: 0,
|
|
198
|
+
}),
|
|
199
|
+
shift({
|
|
200
|
+
id: 'c2',
|
|
201
|
+
startAt: '2026-08-03T16:00:00Z',
|
|
202
|
+
endAt: '2026-08-03T20:00:00Z',
|
|
203
|
+
requiredCount: 0,
|
|
204
|
+
}),
|
|
205
|
+
],
|
|
206
|
+
rules: [
|
|
207
|
+
rule({
|
|
208
|
+
id: 'capacity',
|
|
209
|
+
kind: 'RESOURCE_CAPACITY',
|
|
210
|
+
config: { capacity: 1 },
|
|
211
|
+
}),
|
|
212
|
+
],
|
|
213
|
+
}),
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
id: 'credential lapses mid-shift',
|
|
217
|
+
snapshot: snapshot({
|
|
218
|
+
occurrences: [
|
|
219
|
+
shift({
|
|
220
|
+
id: 'e1',
|
|
221
|
+
startAt: '2026-08-03T15:00:00Z',
|
|
222
|
+
endAt: '2026-08-03T21:00:00Z',
|
|
223
|
+
requiredCount: 0,
|
|
224
|
+
assignees: [
|
|
225
|
+
{
|
|
226
|
+
id: 'a1',
|
|
227
|
+
qualifications: ['CPR'],
|
|
228
|
+
expiresAt: '2026-08-03T18:00:00Z',
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
}),
|
|
232
|
+
],
|
|
233
|
+
rules: [
|
|
234
|
+
rule({
|
|
235
|
+
id: 'cert',
|
|
236
|
+
kind: 'ELIGIBILITY_AT_TIME',
|
|
237
|
+
config: { qualification: 'CPR' },
|
|
238
|
+
}),
|
|
239
|
+
],
|
|
240
|
+
}),
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
id: 'uncovered operating hours',
|
|
244
|
+
snapshot: snapshot({
|
|
245
|
+
occurrences: [
|
|
246
|
+
shift({
|
|
247
|
+
id: 'o1',
|
|
248
|
+
startAt: '2026-08-03T14:00:00Z',
|
|
249
|
+
endAt: '2026-08-03T16:00:00Z',
|
|
250
|
+
requiredCount: 0,
|
|
251
|
+
assignees: [{ id: 'a1' }],
|
|
252
|
+
}),
|
|
253
|
+
],
|
|
254
|
+
rules: [
|
|
255
|
+
rule({
|
|
256
|
+
id: 'open',
|
|
257
|
+
kind: 'CONTINUOUS_COVERAGE',
|
|
258
|
+
config: { opensAt: '07:00', closesAt: '18:00' },
|
|
259
|
+
}),
|
|
260
|
+
],
|
|
261
|
+
}),
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
id: 'empty day inside operating hours',
|
|
265
|
+
snapshot: snapshot({
|
|
266
|
+
rules: [
|
|
267
|
+
rule({
|
|
268
|
+
id: 'open',
|
|
269
|
+
kind: 'CONTINUOUS_COVERAGE',
|
|
270
|
+
config: { opensAt: '07:00', closesAt: '11:00' },
|
|
271
|
+
}),
|
|
272
|
+
],
|
|
273
|
+
}),
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
id: 'ratio against demand',
|
|
277
|
+
snapshot: snapshot({
|
|
278
|
+
occurrences: [
|
|
279
|
+
shift({
|
|
280
|
+
id: 'd1',
|
|
281
|
+
startAt: '2026-08-03T15:00:00Z',
|
|
282
|
+
endAt: '2026-08-03T19:00:00Z',
|
|
283
|
+
requiredCount: 0,
|
|
284
|
+
assignees: [{ id: 'a1' }],
|
|
285
|
+
}),
|
|
286
|
+
],
|
|
287
|
+
demand: [
|
|
288
|
+
{
|
|
289
|
+
resourceId: 'room-a',
|
|
290
|
+
category: 'INFANT',
|
|
291
|
+
startAt: at('2026-08-03T15:00:00Z'),
|
|
292
|
+
endAt: at('2026-08-03T19:00:00Z'),
|
|
293
|
+
quantity: 9,
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
rules: [
|
|
297
|
+
rule({
|
|
298
|
+
id: 'ratio',
|
|
299
|
+
kind: 'DERIVED_COUNT',
|
|
300
|
+
config: { category: 'INFANT', divisor: 4 },
|
|
301
|
+
}),
|
|
302
|
+
],
|
|
303
|
+
}),
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
id: 'turnover between bookings',
|
|
307
|
+
snapshot: snapshot({
|
|
308
|
+
occurrences: [
|
|
309
|
+
shift({
|
|
310
|
+
id: 't1',
|
|
311
|
+
kind: 'BLOCK',
|
|
312
|
+
startAt: '2026-08-03T15:00:00Z',
|
|
313
|
+
endAt: '2026-08-03T16:00:00Z',
|
|
314
|
+
requiredCount: 0,
|
|
315
|
+
}),
|
|
316
|
+
shift({
|
|
317
|
+
id: 't2',
|
|
318
|
+
startAt: '2026-08-03T16:10:00Z',
|
|
319
|
+
endAt: '2026-08-03T18:00:00Z',
|
|
320
|
+
requiredCount: 0,
|
|
321
|
+
}),
|
|
322
|
+
],
|
|
323
|
+
rules: [
|
|
324
|
+
rule({
|
|
325
|
+
id: 'turnover',
|
|
326
|
+
kind: 'EXCLUSION_WINDOW',
|
|
327
|
+
config: { afterKind: 'BLOCK', blockMinutes: 30 },
|
|
328
|
+
}),
|
|
329
|
+
],
|
|
330
|
+
}),
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
id: 'rolling per-actor limit',
|
|
334
|
+
snapshot: snapshot({
|
|
335
|
+
occurrences: [
|
|
336
|
+
shift({
|
|
337
|
+
id: 'r1',
|
|
338
|
+
startAt: '2026-08-03T08:00:00Z',
|
|
339
|
+
endAt: '2026-08-03T12:00:00Z',
|
|
340
|
+
requiredCount: 0,
|
|
341
|
+
assignees: [{ id: 'a1' }],
|
|
342
|
+
}),
|
|
343
|
+
shift({
|
|
344
|
+
id: 'r2',
|
|
345
|
+
startAt: '2026-08-03T15:00:00Z',
|
|
346
|
+
endAt: '2026-08-03T19:00:00Z',
|
|
347
|
+
requiredCount: 0,
|
|
348
|
+
assignees: [{ id: 'a1' }],
|
|
349
|
+
}),
|
|
350
|
+
],
|
|
351
|
+
rules: [
|
|
352
|
+
rule({
|
|
353
|
+
id: 'max-shifts',
|
|
354
|
+
kind: 'ACTOR_WINDOW_AGGREGATE',
|
|
355
|
+
config: { metric: 'SHIFTS', windowHours: 24, max: 1 },
|
|
356
|
+
}),
|
|
357
|
+
],
|
|
358
|
+
}),
|
|
359
|
+
},
|
|
360
|
+
];
|
|
361
|
+
|
|
362
|
+
describe('sweep invariants — boundary refinement', () => {
|
|
363
|
+
/*
|
|
364
|
+
* Cut points swept across the day, including instants that land inside a
|
|
365
|
+
* shift, on its edges, and in empty stretches.
|
|
366
|
+
*/
|
|
367
|
+
const CUT_POINTS = [
|
|
368
|
+
'2026-08-03T09:00:00Z',
|
|
369
|
+
'2026-08-03T14:00:00Z',
|
|
370
|
+
'2026-08-03T15:00:00Z',
|
|
371
|
+
'2026-08-03T16:30:00Z',
|
|
372
|
+
'2026-08-03T18:00:00Z',
|
|
373
|
+
'2026-08-03T23:15:00Z',
|
|
374
|
+
'2026-08-04T05:00:00Z',
|
|
375
|
+
];
|
|
376
|
+
|
|
377
|
+
for (const testCase of CASES) {
|
|
378
|
+
for (const cutPoint of CUT_POINTS) {
|
|
379
|
+
it(`${testCase.id}: an extra cut at ${cutPoint} changes nothing`, () => {
|
|
380
|
+
// Splitting a segment must never change the answer. If it does,
|
|
381
|
+
// the merge step is not restoring what the cut broke apart, and
|
|
382
|
+
// every violation's reported extent becomes an artifact of which
|
|
383
|
+
// unrelated rows happened to share the window.
|
|
384
|
+
expect(
|
|
385
|
+
fingerprint(withExtraBoundary(testCase.snapshot, at(cutPoint))),
|
|
386
|
+
).toEqual(fingerprint(testCase.snapshot));
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
describe('sweep invariants — input order', () => {
|
|
393
|
+
/*
|
|
394
|
+
* Reverse each input list. The sweep admits intervals in sorted order and
|
|
395
|
+
* the merge step sorts before joining, so neither should be able to see the
|
|
396
|
+
* order they were handed in — but the sweep was rewritten from a per-segment
|
|
397
|
+
* filter to a cursor, which changed exactly that iteration order.
|
|
398
|
+
*/
|
|
399
|
+
|
|
400
|
+
for (const testCase of CASES) {
|
|
401
|
+
it(`${testCase.id}: reversing the inputs changes nothing`, () => {
|
|
402
|
+
const reversed: ScheduleEvaluationSnapshot = {
|
|
403
|
+
...testCase.snapshot,
|
|
404
|
+
occurrences: [...testCase.snapshot.occurrences].reverse(),
|
|
405
|
+
demand: [...testCase.snapshot.demand].reverse(),
|
|
406
|
+
rules: [...testCase.snapshot.rules].reverse(),
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
expect(fingerprint(reversed)).toEqual(fingerprint(testCase.snapshot));
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
describe('sweep invariants — merge is idempotent', () => {
|
|
415
|
+
/*
|
|
416
|
+
* Evaluating the same snapshot twice must produce the same answer. Trivial
|
|
417
|
+
* unless something in the engine mutates its input — and the sweep does hand
|
|
418
|
+
* assignment arrays and rule objects straight through by reference.
|
|
419
|
+
*/
|
|
420
|
+
|
|
421
|
+
for (const testCase of CASES) {
|
|
422
|
+
it(`${testCase.id}: evaluating twice gives the same answer`, () => {
|
|
423
|
+
expect(fingerprint(testCase.snapshot)).toEqual(
|
|
424
|
+
fingerprint(testCase.snapshot),
|
|
425
|
+
);
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
});
|