@elaraai/e3-api-tests 1.0.98 → 1.0.99
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/README.md +1 -2
- package/dist/src/fixtures.d.ts +145 -14
- package/dist/src/fixtures.d.ts.map +1 -1
- package/dist/src/fixtures.js +305 -160
- package/dist/src/fixtures.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/suites/bundles.d.ts +13 -0
- package/dist/src/suites/bundles.d.ts.map +1 -0
- package/dist/src/suites/bundles.js +96 -0
- package/dist/src/suites/bundles.js.map +1 -0
- package/dist/src/suites/datasets.d.ts.map +1 -1
- package/dist/src/suites/datasets.js +1 -2
- package/dist/src/suites/datasets.js.map +1 -1
- package/dist/src/suites/package-transfer.d.ts.map +1 -1
- package/dist/src/suites/package-transfer.js +3 -2
- package/dist/src/suites/package-transfer.js.map +1 -1
- package/dist/src/suites/platform.js +4 -4
- package/dist/src/suites/platform.js.map +1 -1
- package/dist/src/suites/records-area.d.ts.map +1 -1
- package/dist/src/suites/records-area.js +53 -46
- package/dist/src/suites/records-area.js.map +1 -1
- package/dist/src/suites/records-keyed.d.ts.map +1 -1
- package/dist/src/suites/records-keyed.js +34 -36
- package/dist/src/suites/records-keyed.js.map +1 -1
- package/dist/src/suites/records-place.d.ts.map +1 -1
- package/dist/src/suites/records-place.js +50 -46
- package/dist/src/suites/records-place.js.map +1 -1
- package/dist/src/suites/records-series.d.ts.map +1 -1
- package/dist/src/suites/records-series.js +533 -104
- package/dist/src/suites/records-series.js.map +1 -1
- package/dist/src/suites/repository.js +9 -9
- package/dist/src/suites/repository.js.map +1 -1
- package/dist/src/template.d.ts +35 -0
- package/dist/src/template.d.ts.map +1 -0
- package/dist/src/template.js +51 -0
- package/dist/src/template.js.map +1 -0
- package/package.json +10 -10
|
@@ -4,31 +4,44 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* A record read in two dimensions (#1039): a block of presses over a span of
|
|
7
|
-
* weeks, read through a series index (`
|
|
8
|
-
*
|
|
9
|
-
* alone — each entry carries its job's row whole — and, zoomed out, the
|
|
10
|
-
* a summary index (`
|
|
11
|
-
* how many jobs touch it, and the milliseconds of it they cover.
|
|
7
|
+
* weeks, read through a series index (`index.series`) as a range a
|
|
8
|
+
* press a level in one request (`findKeys`) and the runs they select, from the
|
|
9
|
+
* index alone — each entry carries its job's row whole — and, zoomed out, the
|
|
10
|
+
* totals a summary index (`index.summary`) keeps under each press and
|
|
11
|
+
* week: how many jobs touch it, and the milliseconds of it they cover.
|
|
12
12
|
*
|
|
13
|
-
* The
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
13
|
+
* The series files each job once (#1433): at the level its length fits, from
|
|
14
|
+
* the week up, under that level's tile holding its start — or, past a year,
|
|
15
|
+
* under each year it touches. The suite works out each job's filings and
|
|
16
|
+
* weeks itself, a week from its Monday, in UTC, half-open, so what a server
|
|
17
|
+
* answers is held to a brute force: under each level's run of tiles, the
|
|
18
|
+
* block's jobs filed there and no other, each once with its row, at one
|
|
19
|
+
* content hash, every job overlapping the weeks among them; and each total,
|
|
20
|
+
* the jobs that touch its week on its press and the time of it they cover.
|
|
21
|
+
* Then a job moved to another week, read and totalled where it went; jobs a
|
|
22
|
+
* hundred days and three years long, each read once; and a joined read, a
|
|
19
23
|
* placement and a membership read of the summary refused.
|
|
24
|
+
*
|
|
25
|
+
* And records whose rows nest what a series files (#1434), read through their
|
|
26
|
+
* one nested series index: a block of machines' jobs over three weeks as a
|
|
27
|
+
* range a machine a level, each job filed once and carried whole; each
|
|
28
|
+
* machine's month totals of its jobs and its load; a hall's mean of its
|
|
29
|
+
* members' loads a week at a time, as one range; a part's subtree's jobs,
|
|
30
|
+
* filed under it too, as one range a level; and a job moved, read back where
|
|
31
|
+
* it went — each held to a brute force over the rows written. The machines'
|
|
32
|
+
* other index carries each machine without its collections.
|
|
20
33
|
*/
|
|
21
34
|
import { describe, it } from 'node:test';
|
|
22
35
|
import assert from 'node:assert/strict';
|
|
23
36
|
import { readFileSync } from 'node:fs';
|
|
24
|
-
import { ArrayType, DateTimeType, IntegerType, NullType, OptionType, PatchType, SortedMap, StringType, StructType, compareFor, decodeBeast2For, diffFor, encodeBeast2For, equalFor, isTypeEqual, isTypeValueEqual, none, printFor, toEastTypeValue, variant, } from '@elaraai/east';
|
|
25
|
-
import { RecordSummaryTotalsType, indexWindowType } from '@elaraai/e3-types';
|
|
37
|
+
import { ArrayType, DateTimeType, FloatType, IntegerType, NullType, OptionType, PatchType, SortedMap, StringType, StructType, VariantType, compareFor, decodeBeast2For, diffFor, encodeBeast2For, equalFor, isTypeEqual, isTypeValueEqual, none, parseFor, printFor, printType, some, toEastTypeValue, variant, } from '@elaraai/east';
|
|
38
|
+
import { NestedEntryKeyType, NestedEntryType, RecordLevelType, RecordNestedItemType, RecordNestedPathType, RecordNestedRunType, RecordSummaryTotalsType, indexWindowType, } from '@elaraai/e3-types';
|
|
26
39
|
import { ApiError, packageImport, workspaceCreate, workspaceDeploy, workspaceRecordDescribe, workspaceRecordMutate, datasetFindKeys, datasetGet, datasetGetPage, datasetGetRuns, datasetGetStatus, datasetPlace, datasetWithin, } from '@elaraai/e3-api-client';
|
|
27
40
|
import { assertMutationCommitted } from '../assertions.js';
|
|
28
|
-
import {
|
|
41
|
+
import { templateWorkspace } from '../template.js';
|
|
42
|
+
import { AssembliesType, AssemblyType, HallType, HallsType, MachineType, MachinesType, NestedJobType, createNestedSeriesPackageZip, createSeriesRecordPackageZip, JOBS_FROM, JobPressLevelTileKeyType, JobPressWeekKeyType, JobRowType, JobsType, } from '../fixtures.js';
|
|
29
43
|
const PKG = 'series-record-pkg';
|
|
30
44
|
const VERSION = '1.0.0';
|
|
31
|
-
const WS = 'series-record-ws';
|
|
32
45
|
const jobsPath = [variant('field', 'records'), variant('field', 'jobs')];
|
|
33
46
|
/** How many jobs the record holds: more than a segment's 4,096 entries at
|
|
34
47
|
* most, so the series spans segments, and its searches and runs cross them. */
|
|
@@ -36,10 +49,10 @@ const JOBS = 6000n;
|
|
|
36
49
|
/** The series index, and the summary beside it. */
|
|
37
50
|
const SERIES = 'jobs_by_press_week';
|
|
38
51
|
const TOTALS = 'jobs_by_press_week_totals';
|
|
39
|
-
/** A series window's entries: the job's key under a
|
|
40
|
-
const SeriesWindowType = ArrayType(StructType({ ik:
|
|
41
|
-
/** A summary window's entries: each
|
|
42
|
-
const TotalsWindowType = ArrayType(StructType({ ik:
|
|
52
|
+
/** A series window's entries: the job's key under a press, a level and a tile, its row carried whole. The first test holds it to `indexWindowType`. */
|
|
53
|
+
const SeriesWindowType = ArrayType(StructType({ ik: JobPressLevelTileKeyType, key: StringType, value: JobRowType, row: OptionType(JobRowType) }));
|
|
54
|
+
/** A summary window's entries: each press and week, standing for every job of it — its `key` Null — with its totals. */
|
|
55
|
+
const TotalsWindowType = ArrayType(StructType({ ik: JobPressWeekKeyType, key: NullType, value: RecordSummaryTotalsType, row: OptionType(JobRowType) }));
|
|
43
56
|
const encodeInt = encodeBeast2For(IntegerType);
|
|
44
57
|
const encodePatch = encodeBeast2For(PatchType(JobsType));
|
|
45
58
|
const decodeJobs = decodeBeast2For(JobsType);
|
|
@@ -48,20 +61,64 @@ const decodeTotalsWindow = decodeBeast2For(TotalsWindowType);
|
|
|
48
61
|
const printDateTime = printFor(DateTimeType);
|
|
49
62
|
const printString = printFor(StringType);
|
|
50
63
|
/** A summary entry's key, `(ik=…, k=null)`, as a membership read names one. */
|
|
51
|
-
const printTotalsEntryKey = printFor(StructType({ ik:
|
|
64
|
+
const printTotalsEntryKey = printFor(StructType({ ik: JobPressWeekKeyType, k: NullType }));
|
|
65
|
+
const printLevel = printFor(RecordLevelType);
|
|
66
|
+
/** A key's `on`, printed whole, as an exact search names it (#1432). */
|
|
67
|
+
const printOn = printFor(JobPressLevelTileKeyType.fields.on);
|
|
52
68
|
const jobEqual = equalFor(JobRowType);
|
|
53
69
|
const unjoined = equalFor(OptionType(JobRowType));
|
|
54
70
|
const integerEqual = equalFor(IntegerType);
|
|
55
|
-
const dateTimeEqual = equalFor(DateTimeType);
|
|
56
71
|
const stringEqual = equalFor(StringType);
|
|
57
72
|
const stringOrder = compareFor(StringType);
|
|
58
|
-
const
|
|
59
|
-
/** A week, in milliseconds. */
|
|
60
|
-
const
|
|
73
|
+
const pressWeekOrder = compareFor(JobPressWeekKeyType);
|
|
74
|
+
/** A day, and a week, in milliseconds. */
|
|
75
|
+
const DAY_MS = 86_400_000;
|
|
76
|
+
const WEEK_MS = 7 * DAY_MS;
|
|
61
77
|
/** The week holding an instant, by its start: whole weeks from {@link JOBS_FROM}, a Monday. */
|
|
62
78
|
function weekHolding(ms) {
|
|
63
79
|
return JOBS_FROM.getTime() + Math.floor((ms - JOBS_FROM.getTime()) / WEEK_MS) * WEEK_MS;
|
|
64
80
|
}
|
|
81
|
+
/** The levels the series files at, from its week tile up, and each one's shortest tile (#1433). */
|
|
82
|
+
const LEVELS = ['week', 'month', 'quarter', 'year'];
|
|
83
|
+
const SHORTEST_MS = { week: 7 * DAY_MS, month: 28 * DAY_MS, quarter: 90 * DAY_MS, year: 365 * DAY_MS };
|
|
84
|
+
const MONTHS = { month: 1, quarter: 3, year: 12 };
|
|
85
|
+
/** The start of the level's tile holding an instant: a week from its Monday, a month, a quarter or a year by the UTC calendar. */
|
|
86
|
+
function tileStart(level, ms) {
|
|
87
|
+
if (level === 'week')
|
|
88
|
+
return weekHolding(ms);
|
|
89
|
+
const held = new Date(ms);
|
|
90
|
+
const month = held.getUTCMonth();
|
|
91
|
+
return Date.UTC(held.getUTCFullYear(), month - (month % MONTHS[level]), 1);
|
|
92
|
+
}
|
|
93
|
+
/** The start of the level's tile `by` tiles on from the one starting at `start` — back, for a negative `by`. */
|
|
94
|
+
function tileStep(level, start, by) {
|
|
95
|
+
if (level === 'week')
|
|
96
|
+
return start + by * WEEK_MS;
|
|
97
|
+
const held = new Date(start);
|
|
98
|
+
return Date.UTC(held.getUTCFullYear(), held.getUTCMonth() + by * MONTHS[level], 1);
|
|
99
|
+
}
|
|
100
|
+
/** Where the series files a job: once, at the first level whose shortest tile holds its length; past a year, under each year it touches. */
|
|
101
|
+
function filingsOf(job) {
|
|
102
|
+
const start = job.start.getTime();
|
|
103
|
+
const end = job.end.getTime();
|
|
104
|
+
for (const level of LEVELS) {
|
|
105
|
+
if (end - start <= SHORTEST_MS[level])
|
|
106
|
+
return [{ level, tile: tileStart(level, start) }];
|
|
107
|
+
}
|
|
108
|
+
const years = [];
|
|
109
|
+
for (let year = tileStart('year', start); year < end; year = tileStep('year', year, 1))
|
|
110
|
+
years.push({ level: 'year', tile: year });
|
|
111
|
+
return years;
|
|
112
|
+
}
|
|
113
|
+
/** What a reader reads of the series over `[from, to)`: a run a level, from two tiles before the one holding `from` to the one after the tile holding its last instant. */
|
|
114
|
+
function levelRuns(from, to) {
|
|
115
|
+
return LEVELS.map((level) => ({ level, from: tileStep(level, tileStart(level, from), -2), to: tileStep(level, tileStart(level, to - 1), 2) }));
|
|
116
|
+
}
|
|
117
|
+
/** A run's search over one press: from its first tile to the start of the one after its last, under the press and the level. */
|
|
118
|
+
function runSearch(press, run) {
|
|
119
|
+
const level = printLevel(variant(run.level, null));
|
|
120
|
+
return { from: [printString(press), level, printDateTime(new Date(run.from))], to: [printString(press), level, printDateTime(new Date(run.to))] };
|
|
121
|
+
}
|
|
65
122
|
/** The weeks a job touches, half-open, by each one's start, with the milliseconds of each it covers. */
|
|
66
123
|
function weeksOf(job) {
|
|
67
124
|
const start = job.start.getTime();
|
|
@@ -74,69 +131,193 @@ function weeksOf(job) {
|
|
|
74
131
|
}
|
|
75
132
|
return weeks;
|
|
76
133
|
}
|
|
77
|
-
/** The totals a summary of `jobs` holds, worked out from them: under each
|
|
134
|
+
/** The totals a summary of `jobs` holds, worked out from them: under each press and week, the jobs touching it and the time of it they cover. */
|
|
78
135
|
function totalsOf(jobs) {
|
|
79
|
-
const totals = new SortedMap(undefined,
|
|
136
|
+
const totals = new SortedMap(undefined, pressWeekOrder);
|
|
80
137
|
for (const job of jobs.values()) {
|
|
81
138
|
for (const { week, ms } of weeksOf(job)) {
|
|
82
|
-
const key = {
|
|
139
|
+
const key = { on: {}, key: job.press, tile: week };
|
|
83
140
|
const held = totals.get(key) ?? { count: 0n, ms: 0n };
|
|
84
141
|
totals.set(key, { count: held.count + 1n, ms: held.ms + ms });
|
|
85
142
|
}
|
|
86
143
|
}
|
|
87
144
|
return totals;
|
|
88
145
|
}
|
|
89
|
-
/** A week's search over a block of presses: from the block's first press to the one after its last, under the week. */
|
|
90
|
-
function blockSearch(week, from, to) {
|
|
91
|
-
return { from: [printDateTime(week), printString(from)], to: [printDateTime(week), printString(to)] };
|
|
92
|
-
}
|
|
93
146
|
/** Whether a press is in the block `[from, to)`. */
|
|
94
147
|
function inBlock(press, from, to) {
|
|
95
148
|
return stringOrder(press, from) >= 0 && stringOrder(press, to) < 0;
|
|
96
149
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
150
|
+
// ── Records nesting what they file (#1434) ───────────────────────────────────
|
|
151
|
+
const NESTED_PKG = 'nested-record-pkg';
|
|
152
|
+
/** A record's dataset path. */
|
|
153
|
+
function recordAt(name) {
|
|
154
|
+
return [variant('field', 'records'), variant('field', name)];
|
|
155
|
+
}
|
|
156
|
+
/** An hour, in milliseconds. */
|
|
157
|
+
const HOUR_MS = 3_600_000;
|
|
158
|
+
/** The machines' job lengths, in hours, a job each in turn: filed at the week, the week, the week, the month and the quarter. */
|
|
159
|
+
const JOB_HOURS = [4, 30, 80, 200, 1_000];
|
|
160
|
+
/** A nested index's entry key, at the records' String keys. */
|
|
161
|
+
const NestedKeyType = NestedEntryKeyType(StringType);
|
|
162
|
+
/** What each nested index files, by place, nesting as its declaration nests. */
|
|
163
|
+
const MachinePlacesType = VariantType({ jobs: NestedJobType, load: FloatType });
|
|
164
|
+
const HallPlacesType = VariantType({ members: VariantType({ load: FloatType }) });
|
|
165
|
+
const AssemblyPlacesType = VariantType({ parts: VariantType({ jobs: NestedJobType }) });
|
|
166
|
+
/** Each nested index's window: an entry's key, its row's key, what it carries, and no row — a nested index is read alone. */
|
|
167
|
+
const MachinesWindowType = ArrayType(StructType({ ik: NestedKeyType, key: StringType, value: NestedEntryType(MachinePlacesType), row: OptionType(MachineType) }));
|
|
168
|
+
const HallsWindowType = ArrayType(StructType({ ik: NestedKeyType, key: StringType, value: NestedEntryType(HallPlacesType), row: OptionType(HallType) }));
|
|
169
|
+
const AssembliesWindowType = ArrayType(StructType({
|
|
170
|
+
ik: NestedKeyType, key: StringType, value: NestedEntryType(AssemblyPlacesType), row: OptionType(AssemblyType),
|
|
171
|
+
}));
|
|
172
|
+
const decodeMachinesWindow = decodeBeast2For(MachinesWindowType);
|
|
173
|
+
const decodeHallsWindow = decodeBeast2For(HallsWindowType);
|
|
174
|
+
const decodeAssembliesWindow = decodeBeast2For(AssembliesWindowType);
|
|
175
|
+
const encodeMachinesPatch = encodeBeast2For(PatchType(MachinesType));
|
|
176
|
+
const encodeHallsPatch = encodeBeast2For(PatchType(HallsType));
|
|
177
|
+
const encodeAssembliesPatch = encodeBeast2For(PatchType(AssembliesType));
|
|
178
|
+
const printPath = printFor(RecordNestedPathType);
|
|
179
|
+
const printRun = printFor(RecordNestedRunType);
|
|
180
|
+
const printItem = printFor(RecordNestedItemType);
|
|
181
|
+
const machineEntryEqual = equalFor(NestedEntryType(MachinePlacesType));
|
|
182
|
+
const assemblyEntryEqual = equalFor(NestedEntryType(AssemblyPlacesType));
|
|
183
|
+
const hallEntryEqual = equalFor(NestedEntryType(HallPlacesType));
|
|
184
|
+
const machineEqual = equalFor(MachineType);
|
|
185
|
+
const dateOrder = compareFor(DateTimeType);
|
|
186
|
+
/** The run an entry is in: a node's own items, its totals, its subtree's items, or a parent's mean of its members'. */
|
|
187
|
+
const ITEMS = variant('items', null);
|
|
188
|
+
const TOTALS_RUN = variant('totals', null);
|
|
189
|
+
const SUBTREE = variant('subtree', null);
|
|
190
|
+
const MEAN = variant('subtotals', { fold: variant('mean', null), aggregate: variant('mean', null) });
|
|
191
|
+
/** A place, or a node's path, as a nested key holds it: its keys, folded from the last. */
|
|
192
|
+
function pathOf(keys) {
|
|
193
|
+
return keys.reduceRight((rest, key) => variant('step', { key, rest }), variant('end', null));
|
|
194
|
+
}
|
|
195
|
+
/** A nested key's leading fields, as a search names them: the collection's place, the row, the node's path, the run and the level. */
|
|
196
|
+
function nestedLead(collection, row, path, run, level) {
|
|
197
|
+
return [printPath(pathOf(collection)), printString(row), printPath(pathOf(path)), printRun(run), printLevel(variant(level, null))];
|
|
198
|
+
}
|
|
199
|
+
/** A search over one run of a nested index at one level: its tiles from `from` to before `to`. */
|
|
200
|
+
function nestedRange(collection, row, path, run, level, from, to) {
|
|
201
|
+
const lead = nestedLead(collection, row, path, run, level);
|
|
202
|
+
return { from: [...lead, printDateTime(new Date(from))], to: [...lead, printDateTime(new Date(to))] };
|
|
203
|
+
}
|
|
204
|
+
/** An exact search of one tile of a nested index's run. */
|
|
205
|
+
function nestedTile(collection, row, path, run, filed) {
|
|
206
|
+
return { fields: [...nestedLead(collection, row, path, run, filed.level), printDateTime(new Date(filed.tile))] };
|
|
207
|
+
}
|
|
208
|
+
/** The months a span touches, half-open, by each one's start, with the milliseconds of each it covers; an instant covers none of its month. */
|
|
209
|
+
function monthsOf(start, end) {
|
|
210
|
+
if (end <= start)
|
|
211
|
+
return [{ month: tileStart('month', start), ms: 0n }];
|
|
212
|
+
const months = [];
|
|
213
|
+
for (let month = tileStart('month', start); month < end; month = tileStep('month', month, 1)) {
|
|
214
|
+
months.push({ month, ms: BigInt(Math.min(tileStep('month', month, 1), end) - Math.max(month, start)) });
|
|
215
|
+
}
|
|
216
|
+
return months;
|
|
217
|
+
}
|
|
218
|
+
/** Jobs' totals a month at a time, worked out from them: under each month's start, the jobs touching it and the time of it they cover. */
|
|
219
|
+
function monthTotals(jobs) {
|
|
220
|
+
const totals = new Map();
|
|
221
|
+
for (const job of jobs) {
|
|
222
|
+
for (const { month, ms } of monthsOf(job.start.getTime(), job.end.getTime())) {
|
|
223
|
+
const held = totals.get(month) ?? { count: 0n, ms: 0n };
|
|
224
|
+
totals.set(month, { count: held.count + 1n, ms: held.ms + ms });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return totals;
|
|
228
|
+
}
|
|
229
|
+
/** The machines: sixty, each with ten jobs over six weeks from {@link JOBS_FROM}, four hours long to forty-one days, and a load each of those days. */
|
|
230
|
+
function nestedMachines() {
|
|
231
|
+
const machines = new SortedMap(undefined, stringOrder);
|
|
232
|
+
for (let m = 0; m < 60; m++) {
|
|
233
|
+
const name = `M-${String(m).padStart(3, '0')}`;
|
|
234
|
+
const jobs = new SortedMap(undefined, stringOrder);
|
|
235
|
+
for (let j = 0; j < 10; j++) {
|
|
236
|
+
const start = JOBS_FROM.getTime() + ((m * 7 + j * 5) % 42) * DAY_MS + (j % 3) * 6 * HOUR_MS;
|
|
237
|
+
jobs.set(`j-${m}-${j}`, { product: `P-${j % 4}`, start: new Date(start), end: new Date(start + JOB_HOURS[j % JOB_HOURS.length] * HOUR_MS) });
|
|
238
|
+
}
|
|
239
|
+
const load = new SortedMap(undefined, dateOrder);
|
|
240
|
+
for (let d = 0; d < 42; d++)
|
|
241
|
+
load.set(new Date(JOBS_FROM.getTime() + d * DAY_MS), ((m * 13 + d * 7) % 100) / 100);
|
|
242
|
+
machines.set(name, { name, site: `Site ${m % 3}`, status: 'up', jobs, load });
|
|
243
|
+
}
|
|
244
|
+
return machines;
|
|
245
|
+
}
|
|
246
|
+
/** The halls: four, each with five members, each member's load each of six weeks' days but one in four. */
|
|
247
|
+
function nestedHalls() {
|
|
248
|
+
const halls = new SortedMap(undefined, stringOrder);
|
|
249
|
+
for (let h = 0; h < 4; h++) {
|
|
250
|
+
const members = new SortedMap(undefined, stringOrder);
|
|
251
|
+
for (let m = 0; m < 5; m++) {
|
|
252
|
+
const load = new SortedMap(undefined, dateOrder);
|
|
253
|
+
for (let d = 0; d < 42; d++) {
|
|
254
|
+
if ((d + m) % 4 !== 0)
|
|
255
|
+
load.set(new Date(JOBS_FROM.getTime() + d * DAY_MS), ((h * 17 + m * 11 + d * 3) % 100) / 100);
|
|
256
|
+
}
|
|
257
|
+
members.set(`m-${m}`, { name: `Member ${m}`, load });
|
|
258
|
+
}
|
|
259
|
+
halls.set(`H-${h}`, { name: `Hall ${h}`, site: `Site ${h % 2}`, members });
|
|
260
|
+
}
|
|
261
|
+
return halls;
|
|
262
|
+
}
|
|
263
|
+
/** Each assembly's jobs by letter: the day it starts on, after the assembly's own, and how many hours it runs. */
|
|
264
|
+
const PART_JOBS = { a: [0, 4], b: [7, 30], c: [9, 200], d: [14, 1_000], e: [3, 8] };
|
|
265
|
+
/** Assembly `a`'s job of a letter: from six in the morning of its day, for its hours. */
|
|
266
|
+
function partJob(a, letter) {
|
|
267
|
+
const [days, hours] = PART_JOBS[letter];
|
|
268
|
+
const start = JOBS_FROM.getTime() + (a + days) * DAY_MS + 6 * HOUR_MS;
|
|
269
|
+
return { product: 'P-0', start: new Date(start), end: new Date(start + hours * HOUR_MS) };
|
|
270
|
+
}
|
|
271
|
+
const printJob = printFor(NestedJobType);
|
|
272
|
+
/**
|
|
273
|
+
* The assemblies: three, each a part p1 holding p1.1 holding p1.1.1, and p2
|
|
274
|
+
* beside it, a job or two each, written as East prints them and read by its
|
|
275
|
+
* parser — a part is a recursive type.
|
|
276
|
+
*/
|
|
277
|
+
function nestedAssemblies() {
|
|
278
|
+
const job = (a, letter) => `"j-${a}-${letter}":${printJob(partJob(a, letter))}`;
|
|
279
|
+
const part = (name, jobs, parts = '{:}') => `(name="${name}", jobs={${jobs}}, parts=${parts})`;
|
|
280
|
+
const assembly = (a) => {
|
|
281
|
+
const deepest = part('p1.1.1', job(a, 'd'));
|
|
282
|
+
const middle = part('p1.1', `${job(a, 'b')}, ${job(a, 'c')}`, `{"p1.1.1":${deepest}}`);
|
|
283
|
+
return `(name="Assembly ${a}", parts={"p1":${part('p1', job(a, 'a'), `{"p1.1":${middle}}`)}, "p2":${part('p2', job(a, 'e'))}})`;
|
|
109
284
|
};
|
|
285
|
+
const read = parseFor(AssembliesType)(`{${[0, 1, 2].map((a) => `"A-${a}":${assembly(a)}`).join(', ')}}`);
|
|
286
|
+
if (!read.success)
|
|
287
|
+
throw new Error(`the assemblies are not a ${printType(AssembliesType)}: ${read.error}`);
|
|
288
|
+
return read.value;
|
|
289
|
+
}
|
|
290
|
+
export function seriesRecordTests(setup) {
|
|
110
291
|
/** The content hash the record holds now. */
|
|
111
|
-
const hashOf = async (ctx) => {
|
|
112
|
-
const status = await datasetGetStatus(ctx.config.baseUrl, ctx.repoName,
|
|
292
|
+
const hashOf = async (ctx, ws) => {
|
|
293
|
+
const status = await datasetGetStatus(ctx.config.baseUrl, ctx.repoName, ws, jobsPath, await ctx.opts());
|
|
113
294
|
assert.ok(status.hash.type === 'some', 'the record holds a state');
|
|
114
295
|
return status.hash.value;
|
|
115
296
|
};
|
|
116
297
|
/** The record's jobs, read whole through the ordinary dataset door. */
|
|
117
|
-
const jobsOf = async (ctx) => {
|
|
118
|
-
const { data } = await datasetGet(ctx.config.baseUrl, ctx.repoName,
|
|
298
|
+
const jobsOf = async (ctx, ws) => {
|
|
299
|
+
const { data } = await datasetGet(ctx.config.baseUrl, ctx.repoName, ws, jobsPath, await ctx.opts());
|
|
119
300
|
return decodeJobs(data);
|
|
120
301
|
};
|
|
121
302
|
/**
|
|
122
|
-
* The
|
|
123
|
-
*
|
|
124
|
-
*
|
|
303
|
+
* The entries an index's searches select: the searches in one request, then
|
|
304
|
+
* the runs they select, read on until every entry is in hand — each at the
|
|
305
|
+
* hash given, and none joined.
|
|
125
306
|
*/
|
|
126
|
-
const
|
|
307
|
+
const readRuns = async (ctx, ws, path, index, searches, hash, decode) => {
|
|
127
308
|
const opts = await ctx.opts();
|
|
128
|
-
const base = [ctx.config.baseUrl, ctx.repoName,
|
|
129
|
-
const found = await datasetFindKeys(...base, { queries: searches, index
|
|
309
|
+
const base = [ctx.config.baseUrl, ctx.repoName, ws, path];
|
|
310
|
+
const found = await datasetFindKeys(...base, { queries: searches, index, hash }, opts);
|
|
130
311
|
assert.equal(found.hash, hash, 'every search is answered at the content pinned');
|
|
131
312
|
assert.equal(found.results.length, searches.length, 'an answer a search');
|
|
132
313
|
let rest = found.results.filter((result) => result.count > 0)
|
|
133
314
|
.map((result) => [result.row, result.count]).sort((a, b) => a[0] - b[0]);
|
|
134
315
|
const entries = [];
|
|
135
316
|
while (rest.length > 0) {
|
|
136
|
-
const read = await datasetGetRuns(...base, { runs: rest, hash, index
|
|
317
|
+
const read = await datasetGetRuns(...base, { runs: rest, hash, index }, opts);
|
|
137
318
|
assert.equal(read.hash, hash, 'the runs are read at the content pinned');
|
|
138
319
|
assert.ok(read.count > 0, 'a read of runs answers some of their entries');
|
|
139
|
-
entries.push(...
|
|
320
|
+
entries.push(...decode(read.data));
|
|
140
321
|
// The runs named, less the entries in hand.
|
|
141
322
|
let taken = read.count;
|
|
142
323
|
const next = [];
|
|
@@ -152,10 +333,12 @@ export function seriesRecordTests(setup) {
|
|
|
152
333
|
}
|
|
153
334
|
return entries;
|
|
154
335
|
};
|
|
336
|
+
/** The series entries a block's searches select ({@link readRuns}). */
|
|
337
|
+
const readSeries = (ctx, ws, searches, hash) => readRuns(ctx, ws, jobsPath, SERIES, searches, hash, decodeSeriesWindow);
|
|
155
338
|
/** Every total the summary holds, paged through at the hash given. */
|
|
156
|
-
const readTotals = async (ctx, hash) => {
|
|
339
|
+
const readTotals = async (ctx, ws, hash) => {
|
|
157
340
|
const opts = await ctx.opts();
|
|
158
|
-
const base = [ctx.config.baseUrl, ctx.repoName,
|
|
341
|
+
const base = [ctx.config.baseUrl, ctx.repoName, ws, jobsPath];
|
|
159
342
|
const entries = [];
|
|
160
343
|
for (let offset = 0;;) {
|
|
161
344
|
const page = await datasetGetPage(...base, { offset, limit: 1_000, index: TOTALS, hash }, opts);
|
|
@@ -171,7 +354,7 @@ export function seriesRecordTests(setup) {
|
|
|
171
354
|
const expected = totalsOf(jobs);
|
|
172
355
|
assert.equal(read.length, expected.size, 'a total for each week and press a job touches, and no other');
|
|
173
356
|
for (const entry of read) {
|
|
174
|
-
const at = `${printDateTime(entry.ik.
|
|
357
|
+
const at = `${printDateTime(entry.ik.tile)} on ${entry.ik.key}`;
|
|
175
358
|
const want = expected.get(entry.ik);
|
|
176
359
|
assert.ok(want !== undefined, `the summary holds a total for ${at}, which a job touches`);
|
|
177
360
|
assert.ok(integerEqual(entry.value.count, want.count), `the jobs touching ${at}: ${entry.value.count} read, ${want.count} there`);
|
|
@@ -180,50 +363,71 @@ export function seriesRecordTests(setup) {
|
|
|
180
363
|
}
|
|
181
364
|
};
|
|
182
365
|
describe('records read in two dimensions', { concurrency: false }, () => {
|
|
183
|
-
|
|
184
|
-
|
|
366
|
+
/** The record of {@link JOBS} jobs, deployed and seeded once for the suite. */
|
|
367
|
+
const record = templateWorkspace(setup, async (ctx, ws) => {
|
|
185
368
|
const opts = await ctx.opts();
|
|
186
|
-
const
|
|
369
|
+
const zipPath = await createSeriesRecordPackageZip(ctx.tempDir, PKG, VERSION);
|
|
370
|
+
await packageImport(ctx.config.baseUrl, ctx.repoName, readFileSync(zipPath), opts);
|
|
371
|
+
await workspaceCreate(ctx.config.baseUrl, ctx.repoName, ws, opts);
|
|
372
|
+
await workspaceDeploy(ctx.config.baseUrl, ctx.repoName, ws, `${PKG}@${VERSION}`, opts);
|
|
373
|
+
const seeded = await workspaceRecordMutate(ctx.config.baseUrl, ctx.repoName, ws, 'jobs', 'seed', { args: [encodeInt(JOBS)], actor: none, limits: none }, opts);
|
|
374
|
+
assertMutationCommitted(seeded, 'seeding');
|
|
375
|
+
});
|
|
376
|
+
/** A copy of the record, the test's own, the content hash it holds, and its jobs as it holds them. */
|
|
377
|
+
const withJobs = async (t) => {
|
|
378
|
+
const { ctx, workspace: ws } = await record(t);
|
|
379
|
+
return { ctx, ws, hash: await hashOf(ctx, ws), jobs: await jobsOf(ctx, ws) };
|
|
380
|
+
};
|
|
381
|
+
it('describes its series index carrying its rows and its summary holding its totals, both built, each keyed by a press first', async (t) => {
|
|
382
|
+
const { ctx, ws, hash } = await withJobs(t);
|
|
383
|
+
const opts = await ctx.opts();
|
|
384
|
+
const sig = await workspaceRecordDescribe(ctx.config.baseUrl, ctx.repoName, ws, 'jobs', opts);
|
|
187
385
|
assert.deepEqual(sig.indexes.map(({ name, multi, summary, built }) => [name, multi, summary, built]), [[SERIES, true, false, true], [TOTALS, true, true, true]]);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
386
|
+
assert.ok(isTypeValueEqual(sig.indexes[0].keyType, toEastTypeValue(JobPressLevelTileKeyType)), 'the series is keyed by a press, a level, then a tile');
|
|
387
|
+
assert.ok(isTypeValueEqual(sig.indexes[1].keyType, toEastTypeValue(JobPressWeekKeyType)), 'the summary by a press, then a week');
|
|
191
388
|
assert.ok(isTypeValueEqual(sig.indexes[0].valueType, toEastTypeValue(JobRowType)), 'the series carries the row whole');
|
|
192
389
|
assert.ok(isTypeValueEqual(sig.indexes[1].valueType, toEastTypeValue(RecordSummaryTotalsType)), 'the summary holds its totals');
|
|
193
|
-
assert.ok(isTypeEqual(SeriesWindowType, indexWindowType(StringType,
|
|
194
|
-
assert.ok(isTypeEqual(TotalsWindowType, indexWindowType(NullType,
|
|
195
|
-
const page = await datasetGetPage(ctx.config.baseUrl, ctx.repoName,
|
|
390
|
+
assert.ok(isTypeEqual(SeriesWindowType, indexWindowType(StringType, JobPressLevelTileKeyType, JobRowType, JobRowType)), 'the series window is e3-types\' index window');
|
|
391
|
+
assert.ok(isTypeEqual(TotalsWindowType, indexWindowType(NullType, JobPressWeekKeyType, RecordSummaryTotalsType, JobRowType)), 'the summary\'s is too, its key Null');
|
|
392
|
+
const page = await datasetGetPage(ctx.config.baseUrl, ctx.repoName, ws, jobsPath, { offset: 0, limit: 1, index: SERIES, hash }, opts);
|
|
196
393
|
assert.ok(page.segmentCount >= 2, `the series spans segments, got ${page.segmentCount}`);
|
|
197
394
|
});
|
|
198
|
-
it('reads a block of presses over three weeks from the series alone: a
|
|
199
|
-
const { ctx, hash, jobs } = await withJobs(t);
|
|
200
|
-
const
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
const expected = [...jobs]
|
|
214
|
-
.filter(([, job]) => inBlock(job.press, 'P-1005', 'P-1013') && weeksOf(job).some(({ week: touched }) => dateTimeEqual(touched, week)))
|
|
215
|
-
.map(([key]) => key).sort(stringOrder);
|
|
216
|
-
assert.ok(expected.length > 0, 'the block has jobs that week');
|
|
217
|
-
assert.deepEqual(keys, expected, `the block's jobs touching the week of ${printDateTime(week)}, and no other`);
|
|
395
|
+
it('reads a block of presses over three weeks from the series alone: a range a press a level, every job filed there once with its row, every job of the block overlapping the weeks among them', async (t) => {
|
|
396
|
+
const { ctx, ws, hash, jobs } = await withJobs(t);
|
|
397
|
+
const from = JOBS_FROM.getTime();
|
|
398
|
+
const to = from + 3 * WEEK_MS;
|
|
399
|
+
const presses = Array.from({ length: 8 }, (_, i) => `P-${1005 + i}`);
|
|
400
|
+
const runs = levelRuns(from, to);
|
|
401
|
+
const searches = presses.flatMap((press) => runs.map((run) => runSearch(press, run)));
|
|
402
|
+
assert.equal(searches.length, 8 * 4, 'a range a press a level, whatever the span');
|
|
403
|
+
const entries = await readSeries(ctx, ws, searches, hash);
|
|
404
|
+
for (const entry of entries) {
|
|
405
|
+
const job = jobs.get(entry.key);
|
|
406
|
+
assert.ok(job !== undefined && jobEqual(entry.value, job), `${entry.key}'s entry carries its row whole`);
|
|
407
|
+
assert.ok(unjoined(entry.row, none), `${entry.key} is read from the series alone, never joined`);
|
|
408
|
+
assert.ok(stringEqual(entry.ik.key, job.press), `${entry.key} is filed under its press`);
|
|
218
409
|
}
|
|
410
|
+
// Held to the brute force: under each run, the block's jobs filed there, each once, and no other.
|
|
411
|
+
const read = entries.map((entry) => `${entry.key} ${printLevel(entry.ik.level)} ${printDateTime(entry.ik.tile)}`).sort(stringOrder);
|
|
412
|
+
const expected = [...jobs].filter(([, job]) => inBlock(job.press, 'P-1005', 'P-1013')).flatMap(([key, job]) => filingsOf(job)
|
|
413
|
+
.filter((filed) => runs.some((run) => run.level === filed.level && filed.tile >= run.from && filed.tile < run.to))
|
|
414
|
+
.map((filed) => `${key} ${printLevel(variant(filed.level, null))} ${printDateTime(new Date(filed.tile))}`)).sort(stringOrder);
|
|
415
|
+
assert.deepEqual(read, expected, 'every job the runs hold, each once, and no other');
|
|
416
|
+
// Every job of the block overlapping the weeks is among them: what a reader keeps by its key.
|
|
417
|
+
const keys = new Set(entries.map((entry) => entry.key));
|
|
418
|
+
const overlapping = [...jobs].filter(([, job]) => inBlock(job.press, 'P-1005', 'P-1013')
|
|
419
|
+
&& job.start.getTime() < to && Math.max(job.end.getTime(), job.start.getTime() + 1) > from).map(([key]) => key);
|
|
420
|
+
assert.ok(overlapping.length > 0, 'the block has jobs those weeks');
|
|
421
|
+
for (const key of overlapping)
|
|
422
|
+
assert.ok(keys.has(key), `${key}, overlapping the weeks, is read`);
|
|
219
423
|
});
|
|
220
424
|
it('totals each week and press as the jobs touching it and the time of it they cover, and refuses a joined read, a placement and a membership read', async (t) => {
|
|
221
|
-
const { ctx, hash, jobs } = await withJobs(t);
|
|
425
|
+
const { ctx, ws, hash, jobs } = await withJobs(t);
|
|
222
426
|
const opts = await ctx.opts();
|
|
223
|
-
const totals = await readTotals(ctx, hash);
|
|
427
|
+
const totals = await readTotals(ctx, ws, hash);
|
|
224
428
|
assertTotals(totals, jobs);
|
|
225
429
|
// A summary's entry names no row: a joined read of it is refused.
|
|
226
|
-
const base = [ctx.config.baseUrl, ctx.repoName,
|
|
430
|
+
const base = [ctx.config.baseUrl, ctx.repoName, ws, jobsPath];
|
|
227
431
|
for (const read of [
|
|
228
432
|
() => datasetGetPage(...base, { offset: 0, limit: 10, index: TOTALS, hash, join: true }, opts),
|
|
229
433
|
() => datasetGetRuns(...base, { runs: [[0, 10]], hash, index: TOTALS, join: true }, opts),
|
|
@@ -248,32 +452,257 @@ export function seriesRecordTests(setup) {
|
|
|
248
452
|
}
|
|
249
453
|
});
|
|
250
454
|
it('a job moved three weeks on leaves the week it left, in the series and the totals, and is read and totalled where it went', async (t) => {
|
|
251
|
-
const { ctx, hash, jobs } = await withJobs(t);
|
|
455
|
+
const { ctx, ws, hash, jobs } = await withJobs(t);
|
|
252
456
|
const opts = await ctx.opts();
|
|
253
457
|
const moved = 'job-7';
|
|
254
458
|
const job = jobs.get(moved);
|
|
255
459
|
const next = new SortedMap(jobs, stringOrder);
|
|
256
460
|
next.set(moved, { ...job, start: new Date(job.start.getTime() + 3 * WEEK_MS), end: new Date(job.end.getTime() + 3 * WEEK_MS) });
|
|
257
461
|
// Another session moves it, through the record's patch door.
|
|
258
|
-
const patched = await workspaceRecordMutate(ctx.config.baseUrl, ctx.repoName,
|
|
462
|
+
const patched = await workspaceRecordMutate(ctx.config.baseUrl, ctx.repoName, ws, 'jobs', 'patch', { args: [encodePatch(diffFor(JobsType)(jobs, next))], actor: none, limits: none }, opts);
|
|
259
463
|
assertMutationCommitted(patched, 'the move');
|
|
260
|
-
const movedHash = await hashOf(ctx);
|
|
464
|
+
const movedHash = await hashOf(ctx, ws);
|
|
261
465
|
assert.notEqual(movedHash, hash, 'the move gives the record another state');
|
|
262
|
-
const now = await jobsOf(ctx);
|
|
466
|
+
const now = await jobsOf(ctx, ws);
|
|
263
467
|
assert.ok(jobEqual(now.get(moved), next.get(moved)), 'the record holds the job where it was moved to');
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
468
|
+
// An exact search names the key's own fields: its `on`, empty here, printed whole, then the press, the level and the tile (#1432, #1433).
|
|
469
|
+
const exact = (filed) => ({
|
|
470
|
+
fields: [printOn({}), printString(job.press), printLevel(variant(filed.level, null)), printDateTime(new Date(filed.tile))],
|
|
471
|
+
});
|
|
472
|
+
for (const filed of filingsOf(job)) {
|
|
473
|
+
const read = await readSeries(ctx, ws, [exact(filed)], movedHash);
|
|
474
|
+
assert.ok(!read.some((entry) => stringEqual(entry.key, moved)), `the moved job has left the ${filed.level} of ${printDateTime(new Date(filed.tile))}`);
|
|
270
475
|
}
|
|
271
|
-
for (const
|
|
272
|
-
const read = await readSeries(ctx, [exact(
|
|
476
|
+
for (const filed of filingsOf(next.get(moved))) {
|
|
477
|
+
const read = await readSeries(ctx, ws, [exact(filed)], movedHash);
|
|
273
478
|
const entry = read.find((e) => stringEqual(e.key, moved));
|
|
274
|
-
assert.ok(entry !== undefined && jobEqual(entry.value, next.get(moved)), `it is read in the
|
|
479
|
+
assert.ok(entry !== undefined && jobEqual(entry.value, next.get(moved)), `it is read in the ${filed.level} of ${printDateTime(new Date(filed.tile))}, its row as moved`);
|
|
480
|
+
}
|
|
481
|
+
assertTotals(await readTotals(ctx, ws, movedHash), now);
|
|
482
|
+
});
|
|
483
|
+
it('reads a job a hundred days long, and one three years long, once each among a block\'s runs, each filed where its length fits', async (t) => {
|
|
484
|
+
const { ctx, ws, jobs } = await withJobs(t);
|
|
485
|
+
const opts = await ctx.opts();
|
|
486
|
+
const from = JOBS_FROM.getTime() + WEEK_MS;
|
|
487
|
+
const long = new SortedMap(jobs, stringOrder);
|
|
488
|
+
long.set('job-season', { press: 'P-1005', start: new Date(from), end: new Date(from + 100 * DAY_MS), title: 'A season' });
|
|
489
|
+
long.set('job-years', { press: 'P-1005', start: new Date(from - DAY_MS), end: new Date(from + 3 * 365 * DAY_MS), title: 'Three years' });
|
|
490
|
+
const patched = await workspaceRecordMutate(ctx.config.baseUrl, ctx.repoName, ws, 'jobs', 'patch', { args: [encodePatch(diffFor(JobsType)(jobs, long))], actor: none, limits: none }, opts);
|
|
491
|
+
assertMutationCommitted(patched, 'the long jobs');
|
|
492
|
+
const hash = await hashOf(ctx, ws);
|
|
493
|
+
// A hundred days is past a quarter's ninety: filed once, under its year; three years under each of the four it touches.
|
|
494
|
+
assert.deepEqual(filingsOf(long.get('job-season')).map((filed) => filed.level), ['year']);
|
|
495
|
+
assert.equal(filingsOf(long.get('job-years')).length, 4);
|
|
496
|
+
const runs = levelRuns(from, from + WEEK_MS);
|
|
497
|
+
const entries = await readSeries(ctx, ws, runs.map((run) => runSearch('P-1005', run)), hash);
|
|
498
|
+
const ofKey = (key) => entries.filter((entry) => stringEqual(entry.key, key));
|
|
499
|
+
assert.equal(ofKey('job-season').length, 1, 'the season is read once');
|
|
500
|
+
assert.ok(ofKey('job-years').length >= 1, 'the three years are read under each year the runs hold');
|
|
501
|
+
assert.deepEqual([...new Set(entries.map((entry) => entry.key))].filter((key) => key === 'job-season' || key === 'job-years').sort(stringOrder), ['job-season', 'job-years'], 'a reader keeps each once, by its key');
|
|
502
|
+
for (const entry of [...ofKey('job-season'), ...ofKey('job-years')]) {
|
|
503
|
+
assert.ok(jobEqual(entry.value, long.get(entry.key)), `${entry.key} carries its row whole`);
|
|
504
|
+
}
|
|
505
|
+
assertTotals(await readTotals(ctx, ws, hash), await jobsOf(ctx, ws));
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
/** Writes a nested record through its patch door. */
|
|
509
|
+
const writeNested = async (ctx, ws, record, patch) => {
|
|
510
|
+
const written = await workspaceRecordMutate(ctx.config.baseUrl, ctx.repoName, ws, record, 'patch', { args: [patch], actor: none, limits: none }, await ctx.opts());
|
|
511
|
+
assertMutationCommitted(written, `the ${record}`);
|
|
512
|
+
};
|
|
513
|
+
/** The content hash a nested record holds now. */
|
|
514
|
+
const nestedHash = async (ctx, ws, record) => {
|
|
515
|
+
const status = await datasetGetStatus(ctx.config.baseUrl, ctx.repoName, ws, recordAt(record), await ctx.opts());
|
|
516
|
+
assert.ok(status.hash.type === 'some', `${record} holds a state`);
|
|
517
|
+
return status.hash.value;
|
|
518
|
+
};
|
|
519
|
+
describe('records nesting what they file, read through their nested series index', { concurrency: false }, () => {
|
|
520
|
+
/** The rows the records hold, as written. */
|
|
521
|
+
const machines = nestedMachines();
|
|
522
|
+
const halls = nestedHalls();
|
|
523
|
+
const assemblies = nestedAssemblies();
|
|
524
|
+
/** The records nesting what they file, deployed and written through their patch doors once for the suite. */
|
|
525
|
+
const records = templateWorkspace(setup, async (ctx, ws) => {
|
|
526
|
+
const opts = await ctx.opts();
|
|
527
|
+
const zipPath = await createNestedSeriesPackageZip(ctx.tempDir, NESTED_PKG, VERSION);
|
|
528
|
+
await packageImport(ctx.config.baseUrl, ctx.repoName, readFileSync(zipPath), opts);
|
|
529
|
+
await workspaceCreate(ctx.config.baseUrl, ctx.repoName, ws, opts);
|
|
530
|
+
await workspaceDeploy(ctx.config.baseUrl, ctx.repoName, ws, `${NESTED_PKG}@${VERSION}`, opts);
|
|
531
|
+
await writeNested(ctx, ws, 'machines', encodeMachinesPatch(diffFor(MachinesType)(new SortedMap(undefined, stringOrder), machines)));
|
|
532
|
+
await writeNested(ctx, ws, 'halls', encodeHallsPatch(diffFor(HallsType)(new SortedMap(undefined, stringOrder), halls)));
|
|
533
|
+
await writeNested(ctx, ws, 'assemblies', encodeAssembliesPatch(diffFor(AssembliesType)(new SortedMap(undefined, stringOrder), assemblies)));
|
|
534
|
+
});
|
|
535
|
+
/** A copy of the records, the test's own, and the rows written. */
|
|
536
|
+
const withNested = async (t) => {
|
|
537
|
+
const { ctx, workspace: ws } = await records(t);
|
|
538
|
+
return { ctx, ws, machines, halls, assemblies };
|
|
539
|
+
};
|
|
540
|
+
it('describes the machines\' nested index, keyed by place, row, path, run, level, tile and item, and their other index carrying each machine without its collections', async (t) => {
|
|
541
|
+
const { ctx, ws, machines } = await withNested(t);
|
|
542
|
+
const opts = await ctx.opts();
|
|
543
|
+
const sig = await workspaceRecordDescribe(ctx.config.baseUrl, ctx.repoName, ws, 'machines', opts);
|
|
544
|
+
const nested = sig.indexes.find((index) => stringEqual(index.name, 'machines_in_time'));
|
|
545
|
+
const bySite = sig.indexes.find((index) => stringEqual(index.name, 'machines_by_site'));
|
|
546
|
+
assert.ok(nested !== undefined && nested.built && nested.multi, 'the nested index is built, a row filing many entries');
|
|
547
|
+
assert.ok(isTypeValueEqual(nested.keyType, toEastTypeValue(NestedKeyType)), 'keyed by place, row, path, run, level, tile and item');
|
|
548
|
+
assert.ok(isTypeValueEqual(nested.valueType, toEastTypeValue(NestedEntryType(MachinePlacesType))), 'carrying an item, its totals or a subtotal');
|
|
549
|
+
assert.ok(isTypeEqual(MachinesWindowType, indexWindowType(StringType, NestedKeyType, NestedEntryType(MachinePlacesType), MachineType)), 'its window is e3-types\' index window');
|
|
550
|
+
assert.ok(bySite !== undefined && isTypeValueEqual(bySite.keyType, toEastTypeValue(StringType)), 'machines_by_site is keyed by the site');
|
|
551
|
+
assert.ok(isTypeValueEqual(bySite.valueType, toEastTypeValue(MachineType)), 'machines_by_site carries a machine');
|
|
552
|
+
// A page of it, read without a join: each machine without its jobs and its load.
|
|
553
|
+
const SiteWindowType = ArrayType(StructType({ ik: StringType, key: StringType, value: MachineType, row: OptionType(MachineType) }));
|
|
554
|
+
assert.ok(isTypeEqual(SiteWindowType, indexWindowType(StringType, StringType, MachineType, MachineType)), 'its window too');
|
|
555
|
+
const hash = await nestedHash(ctx, ws, 'machines');
|
|
556
|
+
const page = await datasetGetPage(ctx.config.baseUrl, ctx.repoName, ws, recordAt('machines'), { offset: 0, limit: 100, index: 'machines_by_site', hash }, opts);
|
|
557
|
+
const entries = decodeBeast2For(SiteWindowType)(page.data);
|
|
558
|
+
assert.equal(entries.length, machines.size, 'every machine, once');
|
|
559
|
+
const jobs = new SortedMap(undefined, stringOrder);
|
|
560
|
+
const load = new SortedMap(undefined, dateOrder);
|
|
561
|
+
for (const entry of entries) {
|
|
562
|
+
const machine = machines.get(entry.key);
|
|
563
|
+
assert.ok(machine !== undefined && machineEqual(entry.value, { ...machine, jobs, load }), `${entry.key} is carried without its collections`);
|
|
564
|
+
assert.ok(entry.row.type === 'none', `${entry.key} is read from the index alone`);
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
it('reads a block of fifty machines\' jobs over three weeks as a range a machine a level, in one request: every job filed there once, carried whole', async (t) => {
|
|
568
|
+
const { ctx, ws, machines } = await withNested(t);
|
|
569
|
+
const hash = await nestedHash(ctx, ws, 'machines');
|
|
570
|
+
const from = JOBS_FROM.getTime() + WEEK_MS;
|
|
571
|
+
const to = from + 3 * WEEK_MS;
|
|
572
|
+
const runs = levelRuns(from, to);
|
|
573
|
+
const block = [...machines.keys()].slice(5, 55);
|
|
574
|
+
const searches = block.flatMap((row) => runs.map((run) => nestedRange(['jobs'], row, [], ITEMS, run.level, run.from, run.to)));
|
|
575
|
+
assert.equal(searches.length, 50 * 4, 'a range a machine a level, whatever the span');
|
|
576
|
+
const entries = await readRuns(ctx, ws, recordAt('machines'), 'machines_in_time', searches, hash, decodeMachinesWindow);
|
|
577
|
+
const read = [];
|
|
578
|
+
for (const entry of entries) {
|
|
579
|
+
assert.ok(entry.ik.item.type === 'id', `${entry.key}: a job, by its id`);
|
|
580
|
+
const id = entry.ik.item.value;
|
|
581
|
+
const job = machines.get(entry.key)?.jobs.get(id);
|
|
582
|
+
assert.ok(job !== undefined && machineEntryEqual(entry.value, variant('item', variant('jobs', job))), `${entry.key} ${id} is carried whole`);
|
|
583
|
+
assert.ok(entry.row.type === 'none', `${entry.key} ${id} is read from the index alone`);
|
|
584
|
+
read.push(`${entry.key} ${printItem(entry.ik.item)} ${printLevel(entry.ik.level)} ${printDateTime(entry.ik.tile)}`);
|
|
585
|
+
}
|
|
586
|
+
// Held to the brute force: under each run, the block's jobs filed there, each once, and no other.
|
|
587
|
+
const expected = block.flatMap((row) => [...machines.get(row).jobs].flatMap(([id, job]) => filingsOf(job)
|
|
588
|
+
.filter((filed) => runs.some((run) => run.level === filed.level && filed.tile >= run.from && filed.tile < run.to))
|
|
589
|
+
.map((filed) => `${row} ${printItem(variant('id', id))} ${printLevel(variant(filed.level, null))} ${printDateTime(new Date(filed.tile))}`)));
|
|
590
|
+
assert.ok(expected.length > 0, 'the block has jobs those weeks');
|
|
591
|
+
assert.deepEqual(read.sort(stringOrder), expected.sort(stringOrder), 'every job the runs hold, each once, and no other');
|
|
592
|
+
});
|
|
593
|
+
it('keeps each machine\'s totals of its jobs and its load a month at a time: how many, the time they cover, and the load\'s sum, least, greatest and last', async (t) => {
|
|
594
|
+
const { ctx, ws, machines } = await withNested(t);
|
|
595
|
+
const hash = await nestedHash(ctx, ws, 'machines');
|
|
596
|
+
const from = tileStep('month', tileStart('month', JOBS_FROM.getTime()), -2);
|
|
597
|
+
const to = tileStep('month', from, 8);
|
|
598
|
+
const searches = [...machines.keys()].flatMap((row) => [
|
|
599
|
+
nestedRange(['jobs'], row, [], TOTALS_RUN, 'month', from, to), nestedRange(['load'], row, [], TOTALS_RUN, 'month', from, to),
|
|
600
|
+
]);
|
|
601
|
+
const entries = await readRuns(ctx, ws, recordAt('machines'), 'machines_in_time', searches, hash, decodeMachinesWindow);
|
|
602
|
+
// Worked out from the rows: each machine's jobs a month, and its load's values in key order.
|
|
603
|
+
const where = (row, collection, month) => `${row} ${collection} ${printDateTime(new Date(month))}`;
|
|
604
|
+
const expected = new Map();
|
|
605
|
+
for (const [row, machine] of machines) {
|
|
606
|
+
for (const [month, totals] of monthTotals(machine.jobs.values())) {
|
|
607
|
+
expected.set(where(row, 'jobs', month), variant('totals', { count: totals.count, ms: totals.ms, values: none }));
|
|
608
|
+
}
|
|
609
|
+
const loads = new Map();
|
|
610
|
+
for (const [at, value] of machine.load) {
|
|
611
|
+
const month = tileStart('month', at.getTime());
|
|
612
|
+
const held = loads.get(month);
|
|
613
|
+
loads.set(month, held === undefined ? { count: 1n, sum: value, min: value, max: value, last: value }
|
|
614
|
+
: { count: held.count + 1n, sum: held.sum + value, min: Math.min(held.min, value), max: Math.max(held.max, value), last: value });
|
|
615
|
+
}
|
|
616
|
+
for (const [month, { count, sum, min, max, last }] of loads) {
|
|
617
|
+
expected.set(where(row, 'load', month), variant('totals', { count, ms: 0n, values: some({ sum, min, max, last }) }));
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
assert.equal(entries.length, expected.size, 'a total for each month a machine\'s jobs or load touch, and no other');
|
|
621
|
+
for (const entry of entries) {
|
|
622
|
+
const collection = stringEqual(printPath(entry.ik.collection), printPath(pathOf(['jobs']))) ? 'jobs' : 'load';
|
|
623
|
+
const at = where(entry.key, collection, entry.ik.tile.getTime());
|
|
624
|
+
const want = expected.get(at);
|
|
625
|
+
assert.ok(want !== undefined && machineEntryEqual(entry.value, want), `${at}: ${printFor(NestedEntryType(MachinePlacesType))(entry.value)}`);
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
it('keeps a hall\'s mean of its members\' loads a week at a time, read as one range: each member\'s mean of its days, and their mean', async (t) => {
|
|
629
|
+
const { ctx, ws, halls } = await withNested(t);
|
|
630
|
+
const hash = await nestedHash(ctx, ws, 'halls');
|
|
631
|
+
const from = tileStep('week', weekHolding(JOBS_FROM.getTime()), -2);
|
|
632
|
+
const to = tileStep('week', from, 12);
|
|
633
|
+
const entries = await readRuns(ctx, ws, recordAt('halls'), 'halls_in_time', [nestedRange(['members', 'load'], 'H-1', [], MEAN, 'week', from, to)], hash, decodeHallsWindow);
|
|
634
|
+
// Worked out from the rows: each member's values a week, in key order, their mean; the hall's, its members' means' mean, in theirs.
|
|
635
|
+
const means = new Map();
|
|
636
|
+
for (const member of halls.get('H-1').members.values()) {
|
|
637
|
+
const weeks = new Map();
|
|
638
|
+
for (const [at, value] of member.load) {
|
|
639
|
+
const week = weekHolding(at.getTime());
|
|
640
|
+
const held = weeks.get(week) ?? { sum: 0, n: 0 };
|
|
641
|
+
weeks.set(week, { sum: held.sum + value, n: held.n + 1 });
|
|
642
|
+
}
|
|
643
|
+
for (const [week, { sum, n }] of weeks)
|
|
644
|
+
means.set(week, [...(means.get(week) ?? []), sum / n]);
|
|
645
|
+
}
|
|
646
|
+
assert.equal(entries.length, means.size, 'a subtotal for each week a member\'s value touches, and no other');
|
|
647
|
+
for (const entry of entries) {
|
|
648
|
+
const week = printDateTime(entry.ik.tile);
|
|
649
|
+
const own = means.get(entry.ik.tile.getTime());
|
|
650
|
+
assert.ok(own !== undefined && stringEqual(entry.key, 'H-1'), `the week of ${week} is H-1's, which a member's value touches`);
|
|
651
|
+
const mean = own.reduce((sum, value) => sum + value, 0) / own.length;
|
|
652
|
+
assert.ok(hallEntryEqual(entry.value, variant('subtotal', mean)), `the week of ${week}: ${printFor(NestedEntryType(HallPlacesType))(entry.value)}, the members' ${mean}`);
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
it('files each part\'s jobs under every part above it too, read under a part as one range a level: its subtree\'s jobs, each once, by their path beneath it', async (t) => {
|
|
656
|
+
const { ctx, ws } = await withNested(t);
|
|
657
|
+
const hash = await nestedHash(ctx, ws, 'assemblies');
|
|
658
|
+
const runs = levelRuns(JOBS_FROM.getTime(), JOBS_FROM.getTime() + 8 * WEEK_MS);
|
|
659
|
+
const searches = runs.map((run) => nestedRange(['parts', 'jobs'], 'A-0', ['p1'], SUBTREE, run.level, run.from, run.to));
|
|
660
|
+
assert.equal(searches.length, 4, 'a range a level');
|
|
661
|
+
const entries = await readRuns(ctx, ws, recordAt('assemblies'), 'assemblies_in_time', searches, hash, decodeAssembliesWindow);
|
|
662
|
+
// Beneath p1: p1.1's two jobs and p1.1.1's one — p1's own is in its items, not its subtree.
|
|
663
|
+
const beneath = [{ path: ['p1.1'], letter: 'b' }, { path: ['p1.1'], letter: 'c' }, { path: ['p1.1', 'p1.1.1'], letter: 'd' }];
|
|
664
|
+
const expected = beneath.flatMap(({ path, letter }) => filingsOf(partJob(0, letter)).map((filed) => `${printItem(variant('under', { path: pathOf(path), id: `j-0-${letter}` }))} ${printLevel(variant(filed.level, null))} ${printDateTime(new Date(filed.tile))}`));
|
|
665
|
+
const read = entries.map((entry) => `${printItem(entry.ik.item)} ${printLevel(entry.ik.level)} ${printDateTime(entry.ik.tile)}`);
|
|
666
|
+
assert.deepEqual(read.sort(stringOrder), expected.sort(stringOrder), 'every job beneath p1, each once, and no other');
|
|
667
|
+
for (const entry of entries) {
|
|
668
|
+
assert.ok(stringEqual(printPath(entry.ik.path), printPath(pathOf(['p1']))), 'filed under p1');
|
|
669
|
+
assert.ok(entry.ik.item.type === 'under', 'a job beneath it, by its path and id');
|
|
670
|
+
const letter = entry.ik.item.value.id.slice(-1);
|
|
671
|
+
assert.ok(assemblyEntryEqual(entry.value, variant('item', variant('parts', variant('jobs', partJob(0, letter))))), `${entry.ik.item.value.id} is carried whole`);
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
it('reads a job moved three weeks on where it went, and not where it was, and totals the months as the jobs then give them', async (t) => {
|
|
675
|
+
const { ctx, ws, machines } = await withNested(t);
|
|
676
|
+
const row = 'M-007';
|
|
677
|
+
const id = 'j-7-0';
|
|
678
|
+
const machine = machines.get(row);
|
|
679
|
+
const job = machine.jobs.get(id);
|
|
680
|
+
const moved = { ...job, start: new Date(job.start.getTime() + 3 * WEEK_MS), end: new Date(job.end.getTime() + 3 * WEEK_MS) };
|
|
681
|
+
const jobs = new SortedMap(machine.jobs, stringOrder);
|
|
682
|
+
jobs.set(id, moved);
|
|
683
|
+
const next = new SortedMap(machines, stringOrder);
|
|
684
|
+
next.set(row, { ...machine, jobs });
|
|
685
|
+
// Another session moves it, through the record's patch door.
|
|
686
|
+
await writeNested(ctx, ws, 'machines', encodeMachinesPatch(diffFor(MachinesType)(machines, next)));
|
|
687
|
+
const hash = await nestedHash(ctx, ws, 'machines');
|
|
688
|
+
const itemEqual = equalFor(RecordNestedItemType);
|
|
689
|
+
const tile = (filed) => readRuns(ctx, ws, recordAt('machines'), 'machines_in_time', [nestedTile(['jobs'], row, [], ITEMS, filed)], hash, decodeMachinesWindow);
|
|
690
|
+
for (const filed of filingsOf(job)) {
|
|
691
|
+
const read = await tile(filed);
|
|
692
|
+
assert.ok(!read.some((entry) => itemEqual(entry.ik.item, variant('id', id))), `${id} has left the ${filed.level} of ${printDateTime(new Date(filed.tile))}`);
|
|
693
|
+
}
|
|
694
|
+
for (const filed of filingsOf(moved)) {
|
|
695
|
+
const entry = (await tile(filed)).find((e) => itemEqual(e.ik.item, variant('id', id)));
|
|
696
|
+
assert.ok(entry !== undefined && machineEntryEqual(entry.value, variant('item', variant('jobs', moved))), `${id} is read in the ${filed.level} of ${printDateTime(new Date(filed.tile))}, as moved`);
|
|
697
|
+
}
|
|
698
|
+
const from = tileStep('month', tileStart('month', JOBS_FROM.getTime()), -2);
|
|
699
|
+
const totals = await readRuns(ctx, ws, recordAt('machines'), 'machines_in_time', [nestedRange(['jobs'], row, [], TOTALS_RUN, 'month', from, tileStep('month', from, 8))], hash, decodeMachinesWindow);
|
|
700
|
+
const expected = monthTotals(jobs.values());
|
|
701
|
+
assert.equal(totals.length, expected.size, 'a total for each month its jobs touch');
|
|
702
|
+
for (const entry of totals) {
|
|
703
|
+
const want = expected.get(entry.ik.tile.getTime());
|
|
704
|
+
assert.ok(want !== undefined && machineEntryEqual(entry.value, variant('totals', { count: want.count, ms: want.ms, values: none })), `${printDateTime(entry.ik.tile)}: ${printFor(NestedEntryType(MachinePlacesType))(entry.value)}`);
|
|
275
705
|
}
|
|
276
|
-
assertTotals(await readTotals(ctx, movedHash), now);
|
|
277
706
|
});
|
|
278
707
|
});
|
|
279
708
|
}
|