@orkestrel/test 0.0.37 → 0.0.38
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 +13 -5
- package/dist/reporter/main.d.ts +5 -0
- package/dist/reporter/main.js +6 -0
- package/dist/reporter/main.js.map +1 -0
- package/dist/src/server/index.cjs +640 -1
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +568 -0
- package/dist/src/server/index.d.ts +568 -0
- package/dist/src/server/index.js +626 -4
- package/dist/src/server/index.js.map +1 -1
- package/package.json +16 -6
package/dist/src/server/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { arrayOf, isFunction, isNumber, isObject, isString, literalOf, recordOf, unionOf } from "@orkestrel/contract";
|
|
1
2
|
import { Buffer } from "node:buffer";
|
|
2
3
|
import { createHash } from "node:crypto";
|
|
3
|
-
import { lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { appendFileSync, closeSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, realpathSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
|
|
4
5
|
import { readFile } from "node:fs/promises";
|
|
5
6
|
import { request } from "node:http";
|
|
6
7
|
import { tmpdir } from "node:os";
|
|
7
8
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
8
9
|
import { fileURLToPath } from "node:url";
|
|
9
|
-
import {
|
|
10
|
-
import { checkBounds, waitForDelay, waitForEvent } from "../core/index.js";
|
|
10
|
+
import { stripVTControlCharacters } from "node:util";
|
|
11
|
+
import { checkBounds, decodeJSONLines, waitForDelay, waitForEvent } from "../core/index.js";
|
|
11
12
|
import { once } from "node:events";
|
|
13
|
+
import { performance as performance$1 } from "node:perf_hooks";
|
|
12
14
|
// src/server/constants.ts
|
|
13
15
|
/**
|
|
14
16
|
* Caps the attempts `removeTree` makes before rethrowing a retryable removal error.
|
|
@@ -26,6 +28,117 @@ var REMOVE_TREE_RETRYABLE_CODES = Object.freeze([
|
|
|
26
28
|
"ENOTEMPTY",
|
|
27
29
|
"EPERM"
|
|
28
30
|
]);
|
|
31
|
+
/**
|
|
32
|
+
* Names the format version a progress file's `init` line carries; a reader refuses any other.
|
|
33
|
+
*/
|
|
34
|
+
var PROGRESS_VERSION = 1;
|
|
35
|
+
/**
|
|
36
|
+
* Caps the characters a progress error message keeps.
|
|
37
|
+
*/
|
|
38
|
+
var PROGRESS_MESSAGE_LIMIT = 300;
|
|
39
|
+
/**
|
|
40
|
+
* Names the label a rendered progress reading prints for each failure relation.
|
|
41
|
+
*/
|
|
42
|
+
var PROGRESS_LABELS = Object.freeze({
|
|
43
|
+
first: "FIRST",
|
|
44
|
+
bail: "AFTER-BAIL",
|
|
45
|
+
later: "FAILED"
|
|
46
|
+
});
|
|
47
|
+
// src/server/validators.ts
|
|
48
|
+
/**
|
|
49
|
+
* Checks whether a value is one error a progress line carries.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { isProgressError } from '@orkestrel/test/server'
|
|
54
|
+
*
|
|
55
|
+
* isProgressError({ message: 'Error: refused', location: 'tests/a.test.ts:4:9' }) // true
|
|
56
|
+
* isProgressError({ location: 'tests/a.test.ts:4:9' }) // false
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
var isProgressError = recordOf({
|
|
60
|
+
message: isString,
|
|
61
|
+
location: isString
|
|
62
|
+
}, ["location"]);
|
|
63
|
+
/**
|
|
64
|
+
* Checks whether a value is one line of a progress file.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { isProgressEvent } from '@orkestrel/test/server'
|
|
69
|
+
*
|
|
70
|
+
* isProgressEvent({ event: 'cancel', reason: 'test-failure', wall: 1, time: 2, pid: 3 }) // true
|
|
71
|
+
* isProgressEvent({ event: 'cancel', reason: 'test-failure' }) // false
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
var isProgressEvent = unionOf(recordOf({
|
|
75
|
+
event: literalOf("init"),
|
|
76
|
+
version: isNumber,
|
|
77
|
+
wall: isNumber,
|
|
78
|
+
bail: isNumber,
|
|
79
|
+
time: isNumber,
|
|
80
|
+
pid: isNumber
|
|
81
|
+
}), recordOf({
|
|
82
|
+
event: literalOf("start"),
|
|
83
|
+
specifications: arrayOf(recordOf({
|
|
84
|
+
project: isString,
|
|
85
|
+
module: isString
|
|
86
|
+
})),
|
|
87
|
+
time: isNumber,
|
|
88
|
+
pid: isNumber
|
|
89
|
+
}), recordOf({
|
|
90
|
+
event: literalOf("collected"),
|
|
91
|
+
project: isString,
|
|
92
|
+
module: isString,
|
|
93
|
+
planned: isNumber,
|
|
94
|
+
errors: arrayOf(isProgressError),
|
|
95
|
+
time: isNumber,
|
|
96
|
+
pid: isNumber
|
|
97
|
+
}), recordOf({
|
|
98
|
+
event: literalOf("ready"),
|
|
99
|
+
project: isString,
|
|
100
|
+
id: isString,
|
|
101
|
+
name: isString,
|
|
102
|
+
time: isNumber,
|
|
103
|
+
pid: isNumber
|
|
104
|
+
}), recordOf({
|
|
105
|
+
event: literalOf("case"),
|
|
106
|
+
project: isString,
|
|
107
|
+
module: isString,
|
|
108
|
+
id: isString,
|
|
109
|
+
name: isString,
|
|
110
|
+
state: literalOf("passed", "failed", "skipped", "pending"),
|
|
111
|
+
duration: isNumber,
|
|
112
|
+
start: isNumber,
|
|
113
|
+
errors: arrayOf(isProgressError),
|
|
114
|
+
time: isNumber,
|
|
115
|
+
pid: isNumber
|
|
116
|
+
}, [
|
|
117
|
+
"duration",
|
|
118
|
+
"start",
|
|
119
|
+
"errors"
|
|
120
|
+
]), recordOf({
|
|
121
|
+
event: literalOf("cancel"),
|
|
122
|
+
reason: isString,
|
|
123
|
+
wall: isNumber,
|
|
124
|
+
time: isNumber,
|
|
125
|
+
pid: isNumber
|
|
126
|
+
}), recordOf({
|
|
127
|
+
event: literalOf("module"),
|
|
128
|
+
project: isString,
|
|
129
|
+
module: isString,
|
|
130
|
+
state: literalOf("passed", "failed", "skipped", "pending", "queued"),
|
|
131
|
+
duration: isNumber,
|
|
132
|
+
time: isNumber,
|
|
133
|
+
pid: isNumber
|
|
134
|
+
}), recordOf({
|
|
135
|
+
event: literalOf("end"),
|
|
136
|
+
reason: literalOf("passed", "interrupted", "failed"),
|
|
137
|
+
overhead: isNumber,
|
|
138
|
+
unhandled: arrayOf(isProgressError),
|
|
139
|
+
time: isNumber,
|
|
140
|
+
pid: isNumber
|
|
141
|
+
}));
|
|
29
142
|
// src/server/helpers.ts
|
|
30
143
|
/**
|
|
31
144
|
* Reads the lowercase hexadecimal SHA-256 digest of a captured file's bytes.
|
|
@@ -866,6 +979,351 @@ async function chooseFiles(context, request) {
|
|
|
866
979
|
await target.dispose();
|
|
867
980
|
}
|
|
868
981
|
}
|
|
982
|
+
/**
|
|
983
|
+
* Normalizes a module or stack-frame path to the form a progress line carries.
|
|
984
|
+
*
|
|
985
|
+
* @param file - The path Vitest reports, a Vite `/@fs/` path included.
|
|
986
|
+
* @param root - The run's root directory.
|
|
987
|
+
* @returns The path relative to the root with `/` separators, or the path unchanged when it resolves
|
|
988
|
+
* outside the root.
|
|
989
|
+
*
|
|
990
|
+
* @example
|
|
991
|
+
* ```ts
|
|
992
|
+
* import { normalizeProgressPath } from '@orkestrel/test/server'
|
|
993
|
+
*
|
|
994
|
+
* normalizeProgressPath('/work/tests/a.test.ts', '/work') // 'tests/a.test.ts'
|
|
995
|
+
* normalizeProgressPath('/elsewhere/b.ts', '/work') // '/elsewhere/b.ts'
|
|
996
|
+
* ```
|
|
997
|
+
*/
|
|
998
|
+
function normalizeProgressPath(file, root) {
|
|
999
|
+
const path = relative(root, file.replace(/^\/@fs\//u, "")).replaceAll("\\", "/");
|
|
1000
|
+
return path === ".." || path.startsWith("../") || isAbsolute(path) ? file : path;
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Extracts the message line and location a progress line keeps from one Vitest error.
|
|
1004
|
+
*
|
|
1005
|
+
* @param error - The serialized error Vitest reports.
|
|
1006
|
+
* @param root - The run's root directory, which the location is relative to.
|
|
1007
|
+
* @returns The error's name and first message line, capped at `PROGRESS_MESSAGE_LIMIT` characters,
|
|
1008
|
+
* and the first stack frame outside `node_modules`, or the first frame when every frame sits there.
|
|
1009
|
+
*
|
|
1010
|
+
* @example
|
|
1011
|
+
* ```ts
|
|
1012
|
+
* import { extractProgressError } from '@orkestrel/test/server'
|
|
1013
|
+
*
|
|
1014
|
+
* extractProgressError(
|
|
1015
|
+
* {
|
|
1016
|
+
* name: 'AssertionError',
|
|
1017
|
+
* message: 'expected 1 to be 2\nfull diff',
|
|
1018
|
+
* stacks: [{ method: '', file: '/work/tests/a.test.ts', line: 4, column: 9 }],
|
|
1019
|
+
* },
|
|
1020
|
+
* '/work',
|
|
1021
|
+
* )
|
|
1022
|
+
* // { message: 'AssertionError: expected 1 to be 2', location: 'tests/a.test.ts:4:9' }
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
1025
|
+
function extractProgressError(error, root) {
|
|
1026
|
+
const [line = ""] = stripVTControlCharacters(`${error.name ?? "Error"}: ${error.message}`).split(/\r?\n/u);
|
|
1027
|
+
const message = line.slice(0, 300);
|
|
1028
|
+
const frame = error.stacks?.find((stack) => !stack.file.includes("node_modules")) ?? error.stacks?.[0];
|
|
1029
|
+
return frame === void 0 ? { message } : {
|
|
1030
|
+
message,
|
|
1031
|
+
location: `${normalizeProgressPath(frame.file, root)}:${frame.line}:${frame.column}`
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* Reports whether a collected case is one the run plans to report.
|
|
1036
|
+
*
|
|
1037
|
+
* @param test - A Vitest case, or any value carrying its `options.mode`.
|
|
1038
|
+
* @returns True if the case's mode is `run` or `only`; false for a case that `skip`, `todo`, or a
|
|
1039
|
+
* name filter removed.
|
|
1040
|
+
*
|
|
1041
|
+
* @example
|
|
1042
|
+
* ```ts
|
|
1043
|
+
* import { matchesPlannedCase } from '@orkestrel/test/server'
|
|
1044
|
+
*
|
|
1045
|
+
* matchesPlannedCase({ options: { mode: 'run' } }) // true
|
|
1046
|
+
* matchesPlannedCase({ options: { mode: 'skip' } }) // false
|
|
1047
|
+
* ```
|
|
1048
|
+
*/
|
|
1049
|
+
function matchesPlannedCase(test) {
|
|
1050
|
+
return test.options.mode === "run" || test.options.mode === "only";
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Reads the bytes a file holds when it is opened, leaving out every byte appended during the read.
|
|
1054
|
+
*
|
|
1055
|
+
* @param path - The file to read.
|
|
1056
|
+
* @returns The bytes up to the length the file had at open.
|
|
1057
|
+
* @throws Thrown when the host refuses to open, inspect, or read the file.
|
|
1058
|
+
*
|
|
1059
|
+
* @example
|
|
1060
|
+
* ```ts
|
|
1061
|
+
* import { writeFileSync } from 'node:fs'
|
|
1062
|
+
* import { readFileSnapshot } from '@orkestrel/test/server'
|
|
1063
|
+
*
|
|
1064
|
+
* writeFileSync('progress.jsonl', '{"event":"init"}\n')
|
|
1065
|
+
* readFileSnapshot('progress.jsonl').length // 17
|
|
1066
|
+
* ```
|
|
1067
|
+
*/
|
|
1068
|
+
function readFileSnapshot(path) {
|
|
1069
|
+
const descriptor = openSync(path, "r");
|
|
1070
|
+
try {
|
|
1071
|
+
const bytes = Buffer.alloc(fstatSync(descriptor).size);
|
|
1072
|
+
return bytes.subarray(0, readSync(descriptor, bytes, 0, bytes.length, 0));
|
|
1073
|
+
} finally {
|
|
1074
|
+
closeSync(descriptor);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Filters the progress lines of one event.
|
|
1079
|
+
*
|
|
1080
|
+
* @typeParam TName - The event to keep.
|
|
1081
|
+
* @param events - The lines to filter.
|
|
1082
|
+
* @param name - The event to keep.
|
|
1083
|
+
* @returns The matching lines in order.
|
|
1084
|
+
*
|
|
1085
|
+
* @example
|
|
1086
|
+
* ```ts
|
|
1087
|
+
* import { filterProgressEvents } from '@orkestrel/test/server'
|
|
1088
|
+
*
|
|
1089
|
+
* filterProgressEvents(
|
|
1090
|
+
* [
|
|
1091
|
+
* { event: 'cancel', reason: 'test-failure', wall: 1, time: 2, pid: 3 },
|
|
1092
|
+
* { event: 'ready', project: 'unit', id: 'a', name: 'adds', time: 3, pid: 3 },
|
|
1093
|
+
* ],
|
|
1094
|
+
* 'cancel',
|
|
1095
|
+
* ).length // 1
|
|
1096
|
+
* ```
|
|
1097
|
+
*/
|
|
1098
|
+
function filterProgressEvents(events, name) {
|
|
1099
|
+
return events.filter((event) => event.event === name);
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Extracts the progress lines a text holds, skipping a partial last line.
|
|
1103
|
+
*
|
|
1104
|
+
* @param text - Progress file text, live or finished.
|
|
1105
|
+
* @returns Each complete line's event, in file order. The text after the last line feed is a line
|
|
1106
|
+
* the writer can still be appending, so it is never decoded.
|
|
1107
|
+
* @throws Thrown when a complete line is not valid JSON, is not a progress event, or is an `init`
|
|
1108
|
+
* line of another format version.
|
|
1109
|
+
*
|
|
1110
|
+
* @example
|
|
1111
|
+
* ```ts
|
|
1112
|
+
* import { extractProgressEvents } from '@orkestrel/test/server'
|
|
1113
|
+
*
|
|
1114
|
+
* extractProgressEvents(
|
|
1115
|
+
* '{"event":"cancel","reason":"test-failure","wall":1,"time":2,"pid":3}\n{"event":"ca',
|
|
1116
|
+
* ).length // 1
|
|
1117
|
+
* ```
|
|
1118
|
+
*/
|
|
1119
|
+
function extractProgressEvents(text) {
|
|
1120
|
+
return decodeJSONLines(text.slice(0, text.lastIndexOf("\n") + 1)).map((value, index) => {
|
|
1121
|
+
if (!isProgressEvent(value)) throw new Error(`Progress record ${index + 1} is not a progress event: ${JSON.stringify(value)?.slice(0, 200)}`);
|
|
1122
|
+
if (value.event === "init" && value.version !== 1) throw new Error(`Progress record ${index + 1} follows format version ${value.version}; this reader reads version 1`);
|
|
1123
|
+
return value;
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Computes where the run one process wrote stands, from its last `init` line on.
|
|
1128
|
+
*
|
|
1129
|
+
* @param events - The lines one process wrote, in file order. Every line must carry the same `pid`;
|
|
1130
|
+
* lines of several processes read as one run and miscompute it, so pass a whole file to
|
|
1131
|
+
* `computeProgress`, which groups them first.
|
|
1132
|
+
* @param now - The wall-clock time of the reading, in milliseconds since the Unix epoch, which a
|
|
1133
|
+
* live run's elapsed time is measured to.
|
|
1134
|
+
* @returns The run, or `undefined` when no `init` line opens it.
|
|
1135
|
+
*
|
|
1136
|
+
* @example
|
|
1137
|
+
* ```ts
|
|
1138
|
+
* import { computeProgressRun } from '@orkestrel/test/server'
|
|
1139
|
+
*
|
|
1140
|
+
* computeProgressRun(
|
|
1141
|
+
* [{ event: 'init', version: 1, wall: 1_000, bail: 1, time: 0, pid: 7 }],
|
|
1142
|
+
* 4_000,
|
|
1143
|
+
* )?.elapsed // 3000
|
|
1144
|
+
* ```
|
|
1145
|
+
*/
|
|
1146
|
+
function computeProgressRun(events, now) {
|
|
1147
|
+
const begin = events.findLastIndex((event) => event.event === "init");
|
|
1148
|
+
const init = events[begin];
|
|
1149
|
+
if (init?.event !== "init") return void 0;
|
|
1150
|
+
const own = events.slice(begin);
|
|
1151
|
+
const specifications = filterProgressEvents(own, "start").flatMap((start) => start.specifications);
|
|
1152
|
+
const collections = filterProgressEvents(own, "collected");
|
|
1153
|
+
const cases = filterProgressEvents(own, "case");
|
|
1154
|
+
const cancel = filterProgressEvents(own, "cancel").at(0);
|
|
1155
|
+
const end = filterProgressEvents(own, "end").at(0);
|
|
1156
|
+
const clock = end?.time ?? now - init.wall + init.time;
|
|
1157
|
+
const projects = [.../* @__PURE__ */ new Set([
|
|
1158
|
+
...specifications.map((entry) => entry.project),
|
|
1159
|
+
...collections.map((entry) => entry.project),
|
|
1160
|
+
...cases.map((entry) => entry.project)
|
|
1161
|
+
])].map((name) => {
|
|
1162
|
+
const results = cases.filter((entry) => entry.project === name);
|
|
1163
|
+
const collected = collections.filter((entry) => entry.project === name);
|
|
1164
|
+
return {
|
|
1165
|
+
name,
|
|
1166
|
+
planned: collected.reduce((total, entry) => total + entry.planned, 0),
|
|
1167
|
+
done: results.length,
|
|
1168
|
+
passed: results.filter((entry) => entry.state === "passed").length,
|
|
1169
|
+
failed: results.filter((entry) => entry.state === "failed").length + collected.filter((entry) => entry.errors.length > 0).length,
|
|
1170
|
+
skipped: results.filter((entry) => entry.state === "skipped").length,
|
|
1171
|
+
modules: specifications.filter((entry) => entry.project === name).length,
|
|
1172
|
+
collected: collected.length
|
|
1173
|
+
};
|
|
1174
|
+
});
|
|
1175
|
+
const planned = projects.reduce((total, project) => total + project.planned, 0);
|
|
1176
|
+
const exact = specifications.length > 0 && projects.every((project) => project.collected >= project.modules);
|
|
1177
|
+
const first = cases.at(0);
|
|
1178
|
+
const span = first === void 0 ? 0 : clock - (first.time - (first.duration ?? 0));
|
|
1179
|
+
const rate = cases.length > 0 && span > 0 ? cases.length / span * 6e4 : void 0;
|
|
1180
|
+
const finished = new Set(cases.map((entry) => entry.id));
|
|
1181
|
+
const position = cancel === void 0 ? -1 : own.indexOf(cancel);
|
|
1182
|
+
const trigger = own.find((event) => event.event === "case" && event.state === "failed");
|
|
1183
|
+
const failures = own.flatMap((event, index) => event.event === "case" && event.state === "failed" || event.event === "collected" && event.errors.length > 0 ? [{
|
|
1184
|
+
event,
|
|
1185
|
+
index
|
|
1186
|
+
}] : []).map(({ event, index }, order) => {
|
|
1187
|
+
const ended = event.event === "case" ? (event.start ?? 0) + (event.duration ?? 0) : Number.NEGATIVE_INFINITY;
|
|
1188
|
+
return {
|
|
1189
|
+
project: event.project,
|
|
1190
|
+
module: event.module,
|
|
1191
|
+
name: event.event === "case" ? event.name : void 0,
|
|
1192
|
+
time: event.time,
|
|
1193
|
+
relation: order === 0 ? "first" : order < init.bail || init.bail > 0 && event === trigger || cancel === void 0 || index < position && ended <= cancel.wall ? "later" : "bail",
|
|
1194
|
+
error: event.errors?.at(0)
|
|
1195
|
+
};
|
|
1196
|
+
});
|
|
1197
|
+
return {
|
|
1198
|
+
pid: init.pid,
|
|
1199
|
+
wall: init.wall,
|
|
1200
|
+
state: end?.reason ?? "live",
|
|
1201
|
+
bail: init.bail,
|
|
1202
|
+
elapsed: clock,
|
|
1203
|
+
done: cases.length,
|
|
1204
|
+
planned,
|
|
1205
|
+
exact,
|
|
1206
|
+
rate,
|
|
1207
|
+
remaining: end === void 0 && exact && rate !== void 0 ? Math.max(0, (planned - cases.length) / rate * 6e4) : void 0,
|
|
1208
|
+
projects,
|
|
1209
|
+
running: end === void 0 ? filterProgressEvents(own, "ready").filter((ready) => !finished.has(ready.id)).map((ready) => ({
|
|
1210
|
+
project: ready.project,
|
|
1211
|
+
name: ready.name,
|
|
1212
|
+
duration: Math.max(0, clock - ready.time)
|
|
1213
|
+
})) : [],
|
|
1214
|
+
cancel: cancel === void 0 ? void 0 : {
|
|
1215
|
+
reason: cancel.reason,
|
|
1216
|
+
time: cancel.time
|
|
1217
|
+
},
|
|
1218
|
+
failures,
|
|
1219
|
+
overhead: end?.overhead,
|
|
1220
|
+
unhandled: end?.unhandled ?? []
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* Computes where every run a progress file holds stands, one run per writing process.
|
|
1225
|
+
*
|
|
1226
|
+
* @param events - The file's lines, in file order, from any number of processes.
|
|
1227
|
+
* @param now - The wall-clock time of the reading, in milliseconds since the Unix epoch.
|
|
1228
|
+
* @returns One run per process id in first-seen order, each computed by `computeProgressRun` from
|
|
1229
|
+
* that process's lines alone. A process whose lines no `init` line opens contributes no run.
|
|
1230
|
+
*
|
|
1231
|
+
* @example
|
|
1232
|
+
* ```ts
|
|
1233
|
+
* import { computeProgress } from '@orkestrel/test/server'
|
|
1234
|
+
*
|
|
1235
|
+
* computeProgress(
|
|
1236
|
+
* [
|
|
1237
|
+
* { event: 'init', version: 1, wall: 1_000, bail: 0, time: 0, pid: 7 },
|
|
1238
|
+
* { event: 'init', version: 1, wall: 1_000, bail: 0, time: 0, pid: 8 },
|
|
1239
|
+
* ],
|
|
1240
|
+
* 4_000,
|
|
1241
|
+
* ).map((run) => [run.pid, run.elapsed]) // [[7, 3000], [8, 3000]]
|
|
1242
|
+
* ```
|
|
1243
|
+
*/
|
|
1244
|
+
function computeProgress(events, now) {
|
|
1245
|
+
return [...new Set(events.map((event) => event.pid))].flatMap((pid) => {
|
|
1246
|
+
const run = computeProgressRun(events.filter((event) => event.pid === pid), now);
|
|
1247
|
+
return run === void 0 ? [] : [run];
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
/**
|
|
1251
|
+
* Reads where every run a progress file holds stands, live or finished.
|
|
1252
|
+
*
|
|
1253
|
+
* @param path - The progress file.
|
|
1254
|
+
* @param now - The wall-clock time of the reading. Default: `Date.now()`.
|
|
1255
|
+
* @returns One run per writing process.
|
|
1256
|
+
* @throws Thrown when the host refuses to read the file, or when a complete line is not a progress
|
|
1257
|
+
* event of this format version.
|
|
1258
|
+
* @remarks Reads the file once, up to its length at open, decodes complete lines only, holds no
|
|
1259
|
+
* timer, and writes nothing.
|
|
1260
|
+
*
|
|
1261
|
+
* @example
|
|
1262
|
+
* ```ts
|
|
1263
|
+
* import { readProgress } from '@orkestrel/test/server'
|
|
1264
|
+
*
|
|
1265
|
+
* const [run] = readProgress('tmp/runs/journey.progress.jsonl')
|
|
1266
|
+
* run?.state // 'live' while the run writes, then its end reason
|
|
1267
|
+
* ```
|
|
1268
|
+
*/
|
|
1269
|
+
function readProgress(path, now = Date.now()) {
|
|
1270
|
+
return computeProgress(extractProgressEvents(readFileSnapshot(path).toString("utf8")), now);
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Renders a duration as whole minutes and seconds.
|
|
1274
|
+
*
|
|
1275
|
+
* @param milliseconds - The duration. A negative or non-finite duration renders as zero.
|
|
1276
|
+
* @returns The duration as `<minutes>m<seconds>s`, the seconds padded to two digits.
|
|
1277
|
+
*
|
|
1278
|
+
* @example
|
|
1279
|
+
* ```ts
|
|
1280
|
+
* import { renderDuration } from '@orkestrel/test/server'
|
|
1281
|
+
*
|
|
1282
|
+
* renderDuration(65_400) // '1m05s'
|
|
1283
|
+
* renderDuration(Number.NaN) // '0m00s'
|
|
1284
|
+
* ```
|
|
1285
|
+
*/
|
|
1286
|
+
function renderDuration(milliseconds) {
|
|
1287
|
+
const seconds = Number.isFinite(milliseconds) ? Math.max(0, Math.floor(milliseconds / 1e3)) : 0;
|
|
1288
|
+
return `${Math.floor(seconds / 60)}m${String(seconds % 60).padStart(2, "0")}s`;
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Renders progress runs as the text a person reads mid-run.
|
|
1292
|
+
*
|
|
1293
|
+
* @param runs - The runs to render.
|
|
1294
|
+
* @returns One block per run: a summary line with done against planned cases, elapsed time, rate, and
|
|
1295
|
+
* estimate; a line per project; the running cases; the cancel; each failure labelled `FIRST`,
|
|
1296
|
+
* `AFTER-BAIL`, or `FAILED` under its module and case, or its module alone when the module failed to
|
|
1297
|
+
* collect, with its first message line and location; each unhandled error; and, after the end, the
|
|
1298
|
+
* reporter's overhead.
|
|
1299
|
+
*
|
|
1300
|
+
* @example
|
|
1301
|
+
* ```ts
|
|
1302
|
+
* import { readProgress, renderProgress } from '@orkestrel/test/server'
|
|
1303
|
+
*
|
|
1304
|
+
* renderProgress(readProgress('tmp/runs/journey.progress.jsonl'))
|
|
1305
|
+
* // 'run 37252 interrupted bail=1: 52/52 cases, elapsed 0m51s, rate 61.2/min, ETA -\n…'
|
|
1306
|
+
* ```
|
|
1307
|
+
*/
|
|
1308
|
+
function renderProgress(runs) {
|
|
1309
|
+
return runs.map((run) => {
|
|
1310
|
+
const width = Math.max(0, ...run.projects.map((project) => project.name.length));
|
|
1311
|
+
return [
|
|
1312
|
+
`run ${run.pid} ${run.state} ${run.bail === 0 ? "full" : `bail=${run.bail}`}: ${run.done}/${run.planned}${run.exact ? "" : "+"} cases, elapsed ${renderDuration(run.elapsed)}, rate ${run.rate === void 0 ? "-" : `${run.rate.toFixed(1)}/min`}, ETA ${run.remaining === void 0 ? "-" : renderDuration(run.remaining)}`,
|
|
1313
|
+
...run.projects.map((project) => ` ${project.name.padEnd(width)} ${project.done}/${project.planned} passed ${project.passed} failed ${project.failed} skipped ${project.skipped}${project.collected < project.modules ? ` (${project.collected}/${project.modules} modules collected)` : ""}`),
|
|
1314
|
+
...run.running.map((entry) => ` running ${renderDuration(entry.duration)} [${entry.project}] ${entry.name}`),
|
|
1315
|
+
...run.cancel === void 0 ? [] : [` cancelled (${run.cancel.reason}) at ${renderDuration(run.cancel.time)}`],
|
|
1316
|
+
...[...run.failures.map((failure) => ({
|
|
1317
|
+
heading: ` ${PROGRESS_LABELS[failure.relation]} ${renderDuration(failure.time)} [${failure.project}] ${failure.name === void 0 ? failure.module : `${failure.module} > ${failure.name}`}`,
|
|
1318
|
+
error: failure.error
|
|
1319
|
+
})), ...run.unhandled.map((error) => ({
|
|
1320
|
+
heading: " UNHANDLED",
|
|
1321
|
+
error
|
|
1322
|
+
}))].flatMap(({ heading, error }) => [heading, ...error === void 0 ? [" (no error recorded)"] : [` ${error.message}`, ...error.location === void 0 ? [] : [` at ${error.location}`]]]),
|
|
1323
|
+
...run.overhead === void 0 ? [] : [` reporter overhead ${run.overhead} ms`]
|
|
1324
|
+
].join("\n");
|
|
1325
|
+
}).join("\n");
|
|
1326
|
+
}
|
|
869
1327
|
// src/server/Loopback.ts
|
|
870
1328
|
/** Owns the one shutdown promise behind a loopback projection. */
|
|
871
1329
|
var Loopback = class {
|
|
@@ -1094,6 +1552,170 @@ function createCookieJar() {
|
|
|
1094
1552
|
}
|
|
1095
1553
|
};
|
|
1096
1554
|
}
|
|
1097
|
-
|
|
1555
|
+
// src/server/reporters/ProgressReporter.ts
|
|
1556
|
+
/**
|
|
1557
|
+
* Appends one JSON line per Vitest run event to the file `--outputFile.progress` names, so a live
|
|
1558
|
+
* run's progress and each failure's first error can be read before the run ends.
|
|
1559
|
+
*
|
|
1560
|
+
* @example
|
|
1561
|
+
* ```ts
|
|
1562
|
+
* import { defineConfig } from 'vitest/config'
|
|
1563
|
+
* import { ProgressReporter } from '@orkestrel/test/server'
|
|
1564
|
+
*
|
|
1565
|
+
* export default defineConfig({
|
|
1566
|
+
* test: {
|
|
1567
|
+
* reporters: ['dot', new ProgressReporter()],
|
|
1568
|
+
* outputFile: { progress: 'tmp/runs/progress.jsonl' },
|
|
1569
|
+
* },
|
|
1570
|
+
* })
|
|
1571
|
+
* ```
|
|
1572
|
+
*/
|
|
1573
|
+
var ProgressReporter = class {
|
|
1574
|
+
#origin = performance$1.now();
|
|
1575
|
+
#listener;
|
|
1576
|
+
#planned = /* @__PURE__ */ new WeakSet();
|
|
1577
|
+
#vitest;
|
|
1578
|
+
#path;
|
|
1579
|
+
#overhead = 0;
|
|
1580
|
+
constructor() {
|
|
1581
|
+
this.#listener = this.#cancel.bind(this);
|
|
1582
|
+
}
|
|
1583
|
+
onInit(vitest) {
|
|
1584
|
+
this.#measure(() => {
|
|
1585
|
+
const output = vitest.config.outputFile;
|
|
1586
|
+
const named = typeof output === "object" ? output.progress : void 0;
|
|
1587
|
+
if (named === void 0) throw new Error("ProgressReporter writes no file: pass --outputFile.progress=<file>, or set outputFile: { progress: <file> } in the test config");
|
|
1588
|
+
this.#vitest = vitest;
|
|
1589
|
+
this.#path = resolve(vitest.config.root, named);
|
|
1590
|
+
mkdirSync(dirname(this.#path), { recursive: true });
|
|
1591
|
+
this.#write({
|
|
1592
|
+
event: "init",
|
|
1593
|
+
version: 1,
|
|
1594
|
+
wall: Date.now(),
|
|
1595
|
+
bail: vitest.config.bail ?? 0,
|
|
1596
|
+
...this.#stamp()
|
|
1597
|
+
});
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
onTestModuleQueued() {
|
|
1601
|
+
this.#vitest?.onCancel(this.#listener);
|
|
1602
|
+
}
|
|
1603
|
+
onTestRunStart(specifications) {
|
|
1604
|
+
this.#measure(() => {
|
|
1605
|
+
this.#write({
|
|
1606
|
+
event: "start",
|
|
1607
|
+
specifications: specifications.map((specification) => ({
|
|
1608
|
+
project: specification.project.name,
|
|
1609
|
+
module: this.#relative(specification.moduleId)
|
|
1610
|
+
})),
|
|
1611
|
+
...this.#stamp()
|
|
1612
|
+
});
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
onTestModuleCollected(module) {
|
|
1616
|
+
this.#measure(() => {
|
|
1617
|
+
const planned = [...module.children.allTests()].filter((test) => matchesPlannedCase(test));
|
|
1618
|
+
for (const test of planned) this.#planned.add(test);
|
|
1619
|
+
this.#write({
|
|
1620
|
+
event: "collected",
|
|
1621
|
+
project: module.project.name,
|
|
1622
|
+
module: this.#relative(module.moduleId),
|
|
1623
|
+
planned: planned.length,
|
|
1624
|
+
errors: module.errors().map((error) => this.#error(error)),
|
|
1625
|
+
...this.#stamp()
|
|
1626
|
+
});
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
onTestCaseReady(test) {
|
|
1630
|
+
this.#measure(() => {
|
|
1631
|
+
if (!this.#planned.has(test)) return;
|
|
1632
|
+
this.#write({
|
|
1633
|
+
event: "ready",
|
|
1634
|
+
project: test.project.name,
|
|
1635
|
+
id: test.id,
|
|
1636
|
+
name: test.fullName,
|
|
1637
|
+
...this.#stamp()
|
|
1638
|
+
});
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
onTestCaseResult(test) {
|
|
1642
|
+
this.#measure(() => {
|
|
1643
|
+
if (!this.#planned.delete(test)) return;
|
|
1644
|
+
const result = test.result();
|
|
1645
|
+
const diagnostic = test.diagnostic();
|
|
1646
|
+
this.#write({
|
|
1647
|
+
event: "case",
|
|
1648
|
+
project: test.project.name,
|
|
1649
|
+
module: this.#relative(test.module.moduleId),
|
|
1650
|
+
id: test.id,
|
|
1651
|
+
name: test.fullName,
|
|
1652
|
+
state: result.state,
|
|
1653
|
+
...diagnostic === void 0 ? {} : {
|
|
1654
|
+
duration: Math.round(diagnostic.duration),
|
|
1655
|
+
start: Math.round(diagnostic.startTime)
|
|
1656
|
+
},
|
|
1657
|
+
...result.state === "failed" ? { errors: result.errors.map((error) => this.#error(error)) } : {},
|
|
1658
|
+
...this.#stamp()
|
|
1659
|
+
});
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
onTestModuleEnd(module) {
|
|
1663
|
+
this.#measure(() => {
|
|
1664
|
+
this.#write({
|
|
1665
|
+
event: "module",
|
|
1666
|
+
project: module.project.name,
|
|
1667
|
+
module: this.#relative(module.moduleId),
|
|
1668
|
+
state: module.state(),
|
|
1669
|
+
duration: Math.round(module.diagnostic().duration),
|
|
1670
|
+
...this.#stamp()
|
|
1671
|
+
});
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
onTestRunEnd(_modules, unhandled, reason) {
|
|
1675
|
+
const errors = unhandled.map((error) => this.#error(error));
|
|
1676
|
+
this.#write({
|
|
1677
|
+
event: "end",
|
|
1678
|
+
reason,
|
|
1679
|
+
overhead: Math.round(this.#overhead * 100) / 100,
|
|
1680
|
+
unhandled: errors,
|
|
1681
|
+
...this.#stamp()
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
1684
|
+
#cancel(reason) {
|
|
1685
|
+
this.#measure(() => {
|
|
1686
|
+
this.#write({
|
|
1687
|
+
event: "cancel",
|
|
1688
|
+
reason,
|
|
1689
|
+
wall: Date.now(),
|
|
1690
|
+
...this.#stamp()
|
|
1691
|
+
});
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
#error(error) {
|
|
1695
|
+
return extractProgressError(error, this.#vitest?.config.root ?? process.cwd());
|
|
1696
|
+
}
|
|
1697
|
+
#relative(file) {
|
|
1698
|
+
return normalizeProgressPath(file, this.#vitest?.config.root ?? process.cwd());
|
|
1699
|
+
}
|
|
1700
|
+
#stamp() {
|
|
1701
|
+
return {
|
|
1702
|
+
time: Math.round(performance$1.now() - this.#origin),
|
|
1703
|
+
pid: process.pid
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
#measure(work) {
|
|
1707
|
+
const begin = performance$1.now();
|
|
1708
|
+
try {
|
|
1709
|
+
work();
|
|
1710
|
+
} finally {
|
|
1711
|
+
this.#overhead += performance$1.now() - begin;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
#write(event) {
|
|
1715
|
+
if (this.#path === void 0) return;
|
|
1716
|
+
appendFileSync(this.#path, `${JSON.stringify(event)}\n`);
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
export { PROGRESS_LABELS, PROGRESS_MESSAGE_LIMIT, PROGRESS_VERSION, ProgressReporter, REMOVE_TREE_MAX_ATTEMPTS, REMOVE_TREE_RETRYABLE_CODES, REMOVE_TREE_RETRY_DELAY_MS, alignLoopClock, chooseFiles, computeProgress, computeProgressRun, createCookieJar, createLink, createLoopback, createScratch, destroyScratch, extractProgressError, extractProgressEvents, filterProgressEvents, hasScratchPath, isExcluded, isProgressError, isProgressEvent, isRunning, matchesIdentity, matchesPlannedCase, normalizeProgressPath, readCapture, readErrorCode, readFileSnapshot, readIdentity, readInventory, readLoopClock, readProgress, removeTree, renderDuration, renderProgress, requestUpgrade, requireContained, resolveContained, supportsBytes, supportsCase, supportsDirectoryLinks, supportsFileLinks, supportsMode, waitForSocketClose };
|
|
1098
1720
|
|
|
1099
1721
|
//# sourceMappingURL=index.js.map
|