@orkestrel/capture 0.0.8 → 0.0.9
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 +25 -19
- package/dist/src/core/index.cjs +385 -2
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +456 -0
- package/dist/src/core/index.d.ts +456 -0
- package/dist/src/core/index.js +376 -4
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +597 -129
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +459 -69
- package/dist/src/server/index.d.ts +459 -69
- package/dist/src/server/index.js +583 -125
- package/dist/src/server/index.js.map +1 -1
- package/package.json +12 -11
package/dist/src/server/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { appendFileSync, closeSync, existsSync, fstatSync, globSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, isAbsolute, matchesGlob, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
5
|
import { parseArgs } from "node:util";
|
|
5
6
|
import { crc32, deflateSync, inflateSync } from "node:zlib";
|
|
6
7
|
import { arrayOf, attempt, isArray, isError, isFunction, isRecord, isString, parseJSON, preview } from "@orkestrel/contract";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { createDuplex, executeSync, inspectProcess } from "@orkestrel/process/server";
|
|
9
|
+
import { computeProgress, computeProgressRun, createProgressPlugin, extractProgressEvents, readFileSnapshot, renderProgress } from "@orkestrel/test/server";
|
|
10
|
+
import { CAPTURE_LOOKUPS_FILE, CAPTURE_MANIFEST_FILE, CAPTURE_OWNER_PREFIX, CAPTURE_PNG_SIGNATURE, CAPTURE_REGISTRY_FILE, CAPTURE_REQUEST_PREFIX, CAPTURE_VERSION, CaptureError, buildCaptureTags, collectCaptureAncestors, collectCaptureChanges, collectCaptureDuplicates, describeCaptureDeclaration, describeCaptureDestination, describeCaptureError, describeCaptureIdentity, describeCaptureRequest, isCaptureError, isCaptureGeometry, isCaptureLookupJournal, isCapturePath, isCapturePattern, isCaptureReceipt, isCaptureRegistry, isCaptureRequest, isCaptureRun, isCaptureSegment, isCaptureSelector, isCaptureStoredManifest, matchesCaptureMembers, matchesCaptureSelector, readCaptureArtifact, readCaptureDirty, readCaptureReport, requireCaptureUnique, resolveCaptureKey, resolveCaptureOwner, resolveCaptureStatus, resolveLookupKey, validateCaptureReceipt, validateCaptureRun } from "../core/index.js";
|
|
10
11
|
import { StringDecoder } from "node:string_decoder";
|
|
11
12
|
import { createTimeout } from "@orkestrel/timeout";
|
|
12
13
|
// src/server/constants.ts
|
|
@@ -52,6 +53,14 @@ var CAPTURE_EXIT = Object.freeze({
|
|
|
52
53
|
*/
|
|
53
54
|
var CAPTURE_OWNER_FILE = ".capture-owner";
|
|
54
55
|
/**
|
|
56
|
+
* Holds the largest process id a POSIX or Windows host can assign, the signed 32-bit maximum.
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* CAPTURE_PID_LIMIT // 2147483647
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
var CAPTURE_PID_LIMIT = 2147483647;
|
|
63
|
+
/**
|
|
55
64
|
* Caps each refusal population so hostile records cannot flood a terminal or agent context.
|
|
56
65
|
* @example
|
|
57
66
|
* ```ts
|
|
@@ -83,6 +92,9 @@ var CAPTURE_STAGES = Object.freeze({
|
|
|
83
92
|
/**
|
|
84
93
|
* Defines each command's frozen options for Node's standard argument parser.
|
|
85
94
|
*
|
|
95
|
+
* @remarks A boolean option whose default is `true` reads only its `--no-` form, which sets it to
|
|
96
|
+
* `false`; `bail` is the one such option.
|
|
97
|
+
*
|
|
86
98
|
* @example
|
|
87
99
|
* ```ts
|
|
88
100
|
* CAPTURE_COMMAND_OPTIONS.journey.variant.multiple // true
|
|
@@ -98,6 +110,10 @@ var CAPTURE_COMMAND_OPTIONS = Object.freeze({
|
|
|
98
110
|
case: Object.freeze({ type: "string" }),
|
|
99
111
|
changed: Object.freeze({ type: "string" }),
|
|
100
112
|
plan: Object.freeze({ type: "boolean" }),
|
|
113
|
+
bail: Object.freeze({
|
|
114
|
+
type: "boolean",
|
|
115
|
+
default: true
|
|
116
|
+
}),
|
|
101
117
|
mode: Object.freeze({ type: "string" })
|
|
102
118
|
}),
|
|
103
119
|
capture: Object.freeze({
|
|
@@ -110,6 +126,10 @@ var CAPTURE_COMMAND_OPTIONS = Object.freeze({
|
|
|
110
126
|
state: Object.freeze({ type: "string" }),
|
|
111
127
|
changed: Object.freeze({ type: "string" }),
|
|
112
128
|
plan: Object.freeze({ type: "boolean" }),
|
|
129
|
+
bail: Object.freeze({
|
|
130
|
+
type: "boolean",
|
|
131
|
+
default: true
|
|
132
|
+
}),
|
|
113
133
|
mode: Object.freeze({ type: "string" })
|
|
114
134
|
}),
|
|
115
135
|
stale: Object.freeze({
|
|
@@ -156,8 +176,13 @@ var CAPTURE_COMMAND_OPTIONS = Object.freeze({
|
|
|
156
176
|
multiple: true
|
|
157
177
|
}),
|
|
158
178
|
config: Object.freeze({ type: "string" }),
|
|
179
|
+
bail: Object.freeze({
|
|
180
|
+
type: "boolean",
|
|
181
|
+
default: true
|
|
182
|
+
}),
|
|
159
183
|
mode: Object.freeze({ type: "string" })
|
|
160
|
-
})
|
|
184
|
+
}),
|
|
185
|
+
progress: Object.freeze({})
|
|
161
186
|
});
|
|
162
187
|
/**
|
|
163
188
|
* Lists the words a tag name can never be, because a tag filter reads them as operators.
|
|
@@ -173,15 +198,6 @@ var CAPTURE_TAG_OPERATORS = Object.freeze([
|
|
|
173
198
|
"not"
|
|
174
199
|
]);
|
|
175
200
|
/**
|
|
176
|
-
* Names the tag prefix that marks a case's owner path and each ancestor of it.
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* ```ts
|
|
180
|
-
* `${CAPTURE_OWNER_PREFIX}pages:mail` // 'owner:pages:mail'
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
var CAPTURE_OWNER_PREFIX = "owner:";
|
|
184
|
-
/**
|
|
185
201
|
* Names the environment variable that turns frame capture on for a Vitest child.
|
|
186
202
|
*
|
|
187
203
|
* @example
|
|
@@ -217,6 +233,32 @@ var CAPTURE_VITEST_ENTRY = "node_modules/vitest/vitest.mjs";
|
|
|
217
233
|
* ```
|
|
218
234
|
*/
|
|
219
235
|
var CAPTURE_RUNS_DIRECTORY = "runs";
|
|
236
|
+
/**
|
|
237
|
+
* Names the ending of the progress file each stage writes beneath its invocation's run directory.
|
|
238
|
+
*
|
|
239
|
+
* @remarks The stage's name precedes it, so `selected` writes `selected.progress.jsonl`.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* `tmp/capture/${CAPTURE_RUNS_DIRECTORY}/a/selected${CAPTURE_PROGRESS_SUFFIX}`
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
var CAPTURE_PROGRESS_SUFFIX = ".progress.jsonl";
|
|
247
|
+
/**
|
|
248
|
+
* Names the prefixes a journey wrapper derives its own paths from.
|
|
249
|
+
*
|
|
250
|
+
* @remarks `scratch` precedes the variant in the sibling of the evidence root a run without frame
|
|
251
|
+
* capture writes to, and `direct` precedes the random identity of a run no runner started.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* `tmp/captures/${CAPTURE_WRAPPER_PREFIXES.scratch}light-390` // 'tmp/captures/no-capture-light-390'
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
var CAPTURE_WRAPPER_PREFIXES = Object.freeze({
|
|
259
|
+
scratch: "no-capture-",
|
|
260
|
+
direct: "direct-"
|
|
261
|
+
});
|
|
220
262
|
/** Names the create-only child record beneath an invocation's run directory.
|
|
221
263
|
* @example
|
|
222
264
|
* ```ts
|
|
@@ -351,7 +393,8 @@ var CAPTURE_SUBCOMMANDS = Object.freeze([
|
|
|
351
393
|
"stale",
|
|
352
394
|
"preflight",
|
|
353
395
|
"sheets",
|
|
354
|
-
"registry"
|
|
396
|
+
"registry",
|
|
397
|
+
"progress"
|
|
355
398
|
]);
|
|
356
399
|
/**
|
|
357
400
|
* Holds the repository-relative paths the executable falls back to when the command line names none.
|
|
@@ -418,17 +461,20 @@ var CAPTURE_DISCOVERY = Object.freeze({
|
|
|
418
461
|
var CAPTURE_USAGE = [
|
|
419
462
|
"Usage: capture <command> [arguments]",
|
|
420
463
|
"Commands:",
|
|
421
|
-
" journey <selector> [--variant <name>]... [--case <full name>] [--mode <name>] [--config <file>]",
|
|
422
|
-
" journey --changed <ref> [--plan] [--variant <name>]... [--case <full name>] [--mode <name>] [--config <file>]",
|
|
423
|
-
" frames <selector> [--variant <name>]... [--case <full name>] [--state <name>] [--mode <name>] [--config <file>]",
|
|
424
|
-
" frames --changed <ref> [--plan] [--variant <name>]... [--case <full name>] [--state <name>] [--mode <name>] [--config <file>]",
|
|
464
|
+
" journey <selector> [--variant <name>]... [--case <full name>] [--no-bail] [--mode <name>] [--config <file>]",
|
|
465
|
+
" journey --changed <ref> [--plan] [--variant <name>]... [--case <full name>] [--no-bail] [--mode <name>] [--config <file>]",
|
|
466
|
+
" frames <selector> [--variant <name>]... [--case <full name>] [--state <name>] [--no-bail] [--mode <name>] [--config <file>]",
|
|
467
|
+
" frames --changed <ref> [--plan] [--variant <name>]... [--case <full name>] [--state <name>] [--no-bail] [--mode <name>] [--config <file>]",
|
|
425
468
|
" stale <selector> [--variant <name>]... [--case <full name>] [--state <name>] [--portfolio <name>] [--mode <name>] [--config <file>]",
|
|
426
469
|
" preflight <selector> [--variant <name>]... [--state <name>] [--case <full name>] [--portfolio <name>] [--mode <name>] [--config <file>] [--journeys <directory>] [--checks <module>]",
|
|
427
470
|
" sheets <selector> --output <new directory> [--variant <name>]... [--state <name>] [--case <full name>] [--portfolio <name>] [--mode <name>] [--config <file>] [--journeys <directory>] [--checks <module>]",
|
|
428
|
-
" registry [--variant <name>]... [--mode <name>] [--config <file>]",
|
|
471
|
+
" registry [--variant <name>]... [--no-bail] [--mode <name>] [--config <file>]",
|
|
472
|
+
" progress",
|
|
429
473
|
"--changed takes one Git ref; HEAD selects uncommitted work. It cannot accompany a selector.",
|
|
430
474
|
"--plan requires --changed and prints paths and commands after read-only discovery; no execution child starts.",
|
|
431
|
-
"
|
|
475
|
+
"--no-bail runs every selected case after a failure; by default a stage stops at its first failed case.",
|
|
476
|
+
"progress prints where the stage that is running, or that ran last, stands, from its progress file.",
|
|
477
|
+
"Only --variant repeats. Every flag except --plan and --no-bail takes one nonempty value, as --flag value or --flag=value; use --flag=-x for a value beginning with a dash. The -- terminator is refused.",
|
|
432
478
|
"Exit: 0 passed, 1 failed or refused by the evidence, 64 refused usage."
|
|
433
479
|
].join("\n");
|
|
434
480
|
// src/server/helpers.ts
|
|
@@ -483,7 +529,7 @@ function buildCaptureChangePlan(paths, entries) {
|
|
|
483
529
|
* Renders an exact owner command with the selected variants and filters in host shell syntax.
|
|
484
530
|
*
|
|
485
531
|
* @param command - The request command, translated to its executable name, or the registry command
|
|
486
|
-
* @param parsed - The parsed flags
|
|
532
|
+
* @param parsed - The parsed flags, a `false` bail rendered as `--no-bail` on every command but `stale`; changed and plan flags are deliberately replaced by the owner
|
|
487
533
|
* @param selector - The explicit owner or all selector; omitted for a registry refresh
|
|
488
534
|
* @param root - The workspace that makes the wrapper path relative
|
|
489
535
|
* @returns The command ready to copy into the host shell
|
|
@@ -503,6 +549,7 @@ function renderCaptureCommand(command, parsed, selector, root) {
|
|
|
503
549
|
...parsed.mode === void 0 ? [] : ["--mode", parsed.mode],
|
|
504
550
|
...parsed.case === void 0 ? [] : parsed.case.startsWith("-") ? [`--case=${parsed.case}`] : ["--case", parsed.case],
|
|
505
551
|
...parsed.state === void 0 ? [] : ["--state", parsed.state],
|
|
552
|
+
...parsed.bail === false && command !== "stale" ? ["--no-bail"] : [],
|
|
506
553
|
...config.startsWith("-") ? [`--config=${config}`] : ["--config", config]
|
|
507
554
|
].map((argument) => /^[\w./:-]+$/u.test(argument) ? argument : process.platform === "win32" ? `'${argument.replaceAll("'", "''")}'` : `'${argument.replaceAll("'", "'\\''")}'`).join(" ");
|
|
508
555
|
}
|
|
@@ -734,6 +781,45 @@ function buildCaptureDigest(patterns, files) {
|
|
|
734
781
|
};
|
|
735
782
|
}
|
|
736
783
|
/**
|
|
784
|
+
* Computes the key under which a pattern list's matched subset of one input population is memoized.
|
|
785
|
+
*
|
|
786
|
+
* @remarks
|
|
787
|
+
* The key joins the population's digest with the sorted patterns, so a list in any order over one
|
|
788
|
+
* population shares a key, and one population never answers for another.
|
|
789
|
+
*
|
|
790
|
+
* @param inputs - The digested input population the patterns match against
|
|
791
|
+
* @param patterns - The native glob patterns, in any order
|
|
792
|
+
* @returns The memo key of the population and the pattern list
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```ts
|
|
796
|
+
* const inputs = buildCaptureDigest(['src/**'], { 'src/a.ts': 'f'.repeat(64) })
|
|
797
|
+
* computeCaptureMatchKey(inputs, ['src/*.ts', 'src/*.md']) === computeCaptureMatchKey(inputs, ['src/*.md', 'src/*.ts']) // true
|
|
798
|
+
* ```
|
|
799
|
+
*/
|
|
800
|
+
function computeCaptureMatchKey(inputs, patterns) {
|
|
801
|
+
return JSON.stringify([inputs.digest, patterns.toSorted()]);
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Filters an input population's paths that match any listed pattern.
|
|
805
|
+
*
|
|
806
|
+
* @remarks
|
|
807
|
+
* Each path is matched with the `matchesGlob` function from `node:path`.
|
|
808
|
+
*
|
|
809
|
+
* @param inputs - The digested input population whose paths are matched
|
|
810
|
+
* @param patterns - The native glob patterns
|
|
811
|
+
* @returns The population's paths that match at least one pattern, in population order
|
|
812
|
+
*
|
|
813
|
+
* @example
|
|
814
|
+
* ```ts
|
|
815
|
+
* const inputs = buildCaptureDigest(['src/**'], { 'src/a.ts': 'f'.repeat(64), 'src/b.md': 'e'.repeat(64) })
|
|
816
|
+
* filterCaptureInputs(inputs, ['src/*.ts']) // Set { 'src/a.ts' }
|
|
817
|
+
* ```
|
|
818
|
+
*/
|
|
819
|
+
function filterCaptureInputs(inputs, patterns) {
|
|
820
|
+
return new Set(Object.keys(inputs.files).filter((path) => patterns.some((pattern) => matchesGlob(path, pattern))));
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
737
823
|
* Stores each distinct lookup input population once in a manifest-bound journal.
|
|
738
824
|
*
|
|
739
825
|
* @param lookups - The expanded passing case evidence to publish
|
|
@@ -968,15 +1054,14 @@ function requireCaptureImageSize(size) {
|
|
|
968
1054
|
* ```
|
|
969
1055
|
*/
|
|
970
1056
|
function unfilterCaptureRow(filter, line, above, channels) {
|
|
971
|
-
const bytes =
|
|
1057
|
+
const bytes = new Uint8Array(line.length);
|
|
972
1058
|
for (const [index, value] of line.entries()) {
|
|
973
1059
|
const left = index >= channels ? bytes[index - channels] ?? 0 : 0;
|
|
974
1060
|
const up = above?.[index] ?? 0;
|
|
975
1061
|
const corner = index >= channels ? above?.[index - channels] ?? 0 : 0;
|
|
976
|
-
|
|
977
|
-
bytes.push(value + predicted & 255);
|
|
1062
|
+
bytes[index] = value + (filter === 1 ? left : filter === 2 ? up : filter === 3 ? left + up >> 1 : filter === 4 ? predictCaptureByte(left, up, corner) : 0) & 255;
|
|
978
1063
|
}
|
|
979
|
-
return
|
|
1064
|
+
return bytes;
|
|
980
1065
|
}
|
|
981
1066
|
/**
|
|
982
1067
|
* Inflates a PNG's compressed stream, refusing one that is corrupt or longer than declared.
|
|
@@ -1034,16 +1119,31 @@ function decodeCapturePicture(bytes) {
|
|
|
1034
1119
|
const chunks = readCaptureChunks(bytes);
|
|
1035
1120
|
const raw = inflateCaptureStream(chunks.length === 1 && chunks[0] !== void 0 ? chunks[0] : Buffer.concat(chunks), length);
|
|
1036
1121
|
if (raw.length !== length) throw new CaptureError("Capture PNG scanline length differs", { code: "EVIDENCE" });
|
|
1037
|
-
const rows =
|
|
1122
|
+
const rows = new Uint8Array(stride * height);
|
|
1038
1123
|
for (const row of new Array(height).keys()) {
|
|
1039
1124
|
const filter = raw[row * (stride + 1)];
|
|
1040
1125
|
if (filter === void 0 || filter > 4) throw new CaptureError("Unsupported capture PNG filter", { code: "EVIDENCE" });
|
|
1041
|
-
|
|
1126
|
+
const line = raw.subarray(row * (stride + 1) + 1, (row + 1) * (stride + 1));
|
|
1127
|
+
rows.set(filter === 0 ? line : unfilterCaptureRow(filter, line, row === 0 ? void 0 : rows.subarray((row - 1) * stride, row * stride), channels), row * stride);
|
|
1128
|
+
}
|
|
1129
|
+
if (channels === 3) return {
|
|
1130
|
+
width,
|
|
1131
|
+
height,
|
|
1132
|
+
pixels: rows
|
|
1133
|
+
};
|
|
1134
|
+
const pixels = new Uint8Array(width * height * 3);
|
|
1135
|
+
const columns = Array.from({ length: width }, (_, column) => column);
|
|
1136
|
+
for (const row of new Array(height).keys()) for (const column of columns) {
|
|
1137
|
+
const source = (row * width + column) * channels;
|
|
1138
|
+
const target = (row * width + column) * 3;
|
|
1139
|
+
pixels[target] = rows[source] ?? 0;
|
|
1140
|
+
pixels[target + 1] = rows[source + (gray ? 0 : 1)] ?? 0;
|
|
1141
|
+
pixels[target + 2] = rows[source + (gray ? 0 : 2)] ?? 0;
|
|
1042
1142
|
}
|
|
1043
1143
|
return {
|
|
1044
1144
|
width,
|
|
1045
1145
|
height,
|
|
1046
|
-
pixels
|
|
1146
|
+
pixels
|
|
1047
1147
|
};
|
|
1048
1148
|
}
|
|
1049
1149
|
/**
|
|
@@ -1137,22 +1237,29 @@ function shrinkCapturePicture(picture, factor, limit) {
|
|
|
1137
1237
|
const width = Math.max(1, Math.ceil(picture.width / factor));
|
|
1138
1238
|
const height = Math.min(Math.max(1, Math.ceil(picture.height / factor)), limit);
|
|
1139
1239
|
const span = Array.from({ length: Math.ceil(Math.min(factor, Math.max(picture.width, picture.height))) }, (_, index) => index);
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
const
|
|
1147
|
-
|
|
1240
|
+
const pixels = new Uint8Array(Math.min(Math.max(Math.trunc(width * height * 3) || 0, 0), Number.MAX_SAFE_INTEGER));
|
|
1241
|
+
const offsets = Array.from({ length: Math.min(width * 3, pixels.length) }, (_, offset) => offset);
|
|
1242
|
+
const lines = pixels.length === 0 ? 0 : Math.ceil(pixels.length / (width * 3));
|
|
1243
|
+
for (const y of new Array(lines).keys()) {
|
|
1244
|
+
const rows = Math.min(factor, picture.height - y * factor);
|
|
1245
|
+
for (const offset of offsets) {
|
|
1246
|
+
const index = y * width * 3 + offset;
|
|
1247
|
+
if (index >= pixels.length) break;
|
|
1248
|
+
const channel = offset % 3;
|
|
1249
|
+
const x = Math.floor(offset / 3);
|
|
1148
1250
|
const columns = Math.min(factor, picture.width - x * factor);
|
|
1149
1251
|
const sum = span.reduce((total, row) => {
|
|
1150
1252
|
if (row >= rows) return total;
|
|
1151
1253
|
const start = (y * factor + row) * picture.width * 3 + x * Math.ceil(factor) * 3 + channel;
|
|
1152
1254
|
return span.reduce((block, column) => column >= columns ? block : block + (picture.pixels[start + column * 3] ?? 0), total);
|
|
1153
1255
|
}, 0);
|
|
1154
|
-
|
|
1155
|
-
}
|
|
1256
|
+
pixels[index] = Math.round(sum / (rows * columns));
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
return {
|
|
1260
|
+
width,
|
|
1261
|
+
height,
|
|
1262
|
+
pixels
|
|
1156
1263
|
};
|
|
1157
1264
|
}
|
|
1158
1265
|
/**
|
|
@@ -1162,7 +1269,10 @@ function shrinkCapturePicture(picture, factor, limit) {
|
|
|
1162
1269
|
* @param vertical - If `true`, stacks rows; if `false`, places cells side by side
|
|
1163
1270
|
* @param gap - The space between source pictures. Default: 6.
|
|
1164
1271
|
* @returns A separately owned composite
|
|
1165
|
-
* @throws Thrown for an empty picture selection.
|
|
1272
|
+
* @throws Thrown for an empty picture selection, with the `USAGE` condition.
|
|
1273
|
+
* @throws Thrown with the `EVIDENCE` condition when a width, a height, or the gap is not a whole
|
|
1274
|
+
* number from 0 to `CAPTURE_PNG_LIMITS.side`, or when the composite exceeds that side or the
|
|
1275
|
+
* `CAPTURE_PNG_LIMITS.pixels` budget.
|
|
1166
1276
|
*
|
|
1167
1277
|
* @example
|
|
1168
1278
|
* ```ts
|
|
@@ -1171,42 +1281,80 @@ function shrinkCapturePicture(picture, factor, limit) {
|
|
|
1171
1281
|
*/
|
|
1172
1282
|
function composeCapturePictures(pictures, vertical, gap = 6) {
|
|
1173
1283
|
if (pictures.length === 0) throw new CaptureError("Empty contact-sheet picture selection", { code: "USAGE" });
|
|
1174
|
-
const
|
|
1175
|
-
const
|
|
1284
|
+
const { side, pixels: budget } = CAPTURE_PNG_LIMITS;
|
|
1285
|
+
const faults = [...pictures.flatMap((picture, position) => ["width", "height"].flatMap((axis) => Number.isSafeInteger(picture[axis]) && picture[axis] >= 0 && picture[axis] <= side ? [] : [`pictures[${String(position)}].${axis} is ${preview(picture[axis])}`])), ...Number.isSafeInteger(gap) && gap >= 0 && gap <= side ? [] : [`gap is ${preview(gap)}`]];
|
|
1286
|
+
const width = vertical ? pictures.reduce((widest, entry) => Math.max(widest, entry.width), -Infinity) : pictures.reduce((sum, entry) => sum + entry.width, 0) + gap * (pictures.length - 1);
|
|
1287
|
+
const height = vertical ? pictures.reduce((sum, entry) => sum + entry.height, 0) + gap * (pictures.length - 1) : pictures.reduce((tallest, entry) => Math.max(tallest, entry.height), -Infinity);
|
|
1288
|
+
if (faults.length > 0 || width > side || height > side || width * height > budget) throw new CaptureError(`Contact-sheet geometry is out of range: ${faults.length === 0 ? `composite is ${String(width)} × ${String(height)}` : [...faults.slice(0, 16), ...faults.length > 16 ? [`… ${String(faults.length - 16)} more`] : []].join("; ")}; expected whole numbers from 0 to ${String(side)} for every width, height, and gap, and a composite of at most ${String(side)} per side and ${String(budget)} pixels`, { code: "EVIDENCE" });
|
|
1176
1289
|
const offsets = pictures.map((_picture, position) => pictures.slice(0, position).reduce((sum, entry) => sum + (vertical ? entry.height : entry.width) + gap, 0));
|
|
1290
|
+
const pixels = new Uint8Array(width * height * 3);
|
|
1291
|
+
const spans = pictures.map((picture, position) => ({
|
|
1292
|
+
picture,
|
|
1293
|
+
start: offsets[position] ?? 0,
|
|
1294
|
+
end: Math.min(offsets[position + 1] ?? Infinity, vertical ? height : width)
|
|
1295
|
+
}));
|
|
1296
|
+
if (vertical) {
|
|
1297
|
+
for (const { picture, start, end } of spans) for (const row of new Array(Math.max(0, end - start)).keys()) {
|
|
1298
|
+
const copied = row < picture.height ? picture.width : 0;
|
|
1299
|
+
const target = (start + row) * width * 3;
|
|
1300
|
+
pixels.set(picture.pixels.subarray(row * picture.width * 3, (row * picture.width + copied) * 3), target);
|
|
1301
|
+
pixels.fill(128, target + copied * 3, target + width * 3);
|
|
1302
|
+
}
|
|
1303
|
+
return {
|
|
1304
|
+
width,
|
|
1305
|
+
height,
|
|
1306
|
+
pixels
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
for (const row of new Array(height).keys()) for (const { picture, start, end } of spans) {
|
|
1310
|
+
const copied = row < picture.height ? Math.min(picture.width, end - start) : 0;
|
|
1311
|
+
const target = (row * width + start) * 3;
|
|
1312
|
+
pixels.set(picture.pixels.subarray(row * picture.width * 3, (row * picture.width + copied) * 3), target);
|
|
1313
|
+
pixels.fill(128, target + copied * 3, (row * width + end) * 3);
|
|
1314
|
+
}
|
|
1177
1315
|
return {
|
|
1178
1316
|
width,
|
|
1179
1317
|
height,
|
|
1180
|
-
pixels
|
|
1181
|
-
const x = Math.floor(index % (width * 3) / 3);
|
|
1182
|
-
const y = Math.floor(index / (width * 3));
|
|
1183
|
-
const position = offsets.findLastIndex((offset) => offset <= (vertical ? y : x));
|
|
1184
|
-
const picture = pictures[position];
|
|
1185
|
-
const offset = offsets[position];
|
|
1186
|
-
if (picture === void 0 || offset === void 0) return 128;
|
|
1187
|
-
const column = vertical ? x : x - offset;
|
|
1188
|
-
const row = vertical ? y - offset : y;
|
|
1189
|
-
return column < picture.width && row < picture.height ? picture.pixels[(row * picture.width + column) * 3 + index % 3] ?? 0 : 128;
|
|
1190
|
-
})
|
|
1318
|
+
pixels
|
|
1191
1319
|
};
|
|
1192
1320
|
}
|
|
1193
1321
|
/**
|
|
1194
1322
|
* Reads the process id that a request file, or its temporary sibling, names.
|
|
1195
1323
|
*
|
|
1196
1324
|
* @param name - A file name from the request directory
|
|
1197
|
-
* @returns The
|
|
1325
|
+
* @returns The process id the name carries, from 1 to `CAPTURE_PID_LIMIT`, or `undefined` for any
|
|
1326
|
+
* other name
|
|
1198
1327
|
*
|
|
1199
1328
|
* @example
|
|
1200
1329
|
* ```ts
|
|
1201
1330
|
* readCaptureRequestOwner('journey-selection-4242.json') // 4242
|
|
1202
1331
|
* readCaptureRequestOwner('journey-selection-4242.json.tmp') // 4242
|
|
1203
1332
|
* readCaptureRequestOwner('journey-selection.json') // undefined
|
|
1333
|
+
* readCaptureRequestOwner('journey-selection-4294967296.json') // undefined
|
|
1204
1334
|
* ```
|
|
1205
1335
|
*/
|
|
1206
1336
|
function readCaptureRequestOwner(name) {
|
|
1207
1337
|
const match = new RegExp(`^${CAPTURE_REQUEST_PREFIX}-(\\d+)\\.json(?:\\.tmp)?$`, "u").exec(name);
|
|
1208
1338
|
const pid = Number(match?.[1]);
|
|
1209
|
-
return Number.isSafeInteger(pid) && pid > 0 ? pid : void 0;
|
|
1339
|
+
return Number.isSafeInteger(pid) && pid > 0 && pid <= 2147483647 ? pid : void 0;
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* Describes the request holders that keep a workspace busy, naming apart those the host could not inspect.
|
|
1343
|
+
*
|
|
1344
|
+
* @param holders - The holders `CaptureInvocationInterface.holders` lists
|
|
1345
|
+
* @param directory - The workspace-relative request directory that holds their request files
|
|
1346
|
+
* @returns The running holders' sentence, then the uninspected holders' sentence with its correction
|
|
1347
|
+
*
|
|
1348
|
+
* @example
|
|
1349
|
+
* ```ts
|
|
1350
|
+
* describeCaptureHolders([{ pid: 4242, inspected: true }], 'tmp/capture')
|
|
1351
|
+
* // 'Another runner holds this workspace (process 4242)'
|
|
1352
|
+
* ```
|
|
1353
|
+
*/
|
|
1354
|
+
function describeCaptureHolders(holders, directory) {
|
|
1355
|
+
const running = holders.filter((holder) => holder.inspected).map((holder) => holder.pid);
|
|
1356
|
+
const unknown = holders.filter((holder) => !holder.inspected).map((holder) => holder.pid);
|
|
1357
|
+
return [...running.length === 0 ? [] : [`Another runner holds this workspace (process ${running.join(", ")})`], ...unknown.length === 0 ? [] : [`Request holder process ${unknown.join(", ")} could not be inspected; confirm no capture process or surviving child is running before deleting its request file in ${directory}`]].join(". ");
|
|
1210
1358
|
}
|
|
1211
1359
|
/**
|
|
1212
1360
|
* Resolves a path to the slash-separated form the evidence documents store, relative to a root.
|
|
@@ -1355,7 +1503,7 @@ function readCaptureVariants(root, file) {
|
|
|
1355
1503
|
* spaces and quotes. An exact case adds `-t` with the anchored pattern for that case and the
|
|
1356
1504
|
* final case, so the final case still writes the run record.
|
|
1357
1505
|
*
|
|
1358
|
-
* @param options - The entry, wrapper, report, projects, tag filter, and optional exact case and mode
|
|
1506
|
+
* @param options - The entry, wrapper, report and progress files, projects, tag filter, bail switch, and optional exact case and mode
|
|
1359
1507
|
* @returns The arguments after the Node executable
|
|
1360
1508
|
*
|
|
1361
1509
|
* @example
|
|
@@ -1364,6 +1512,7 @@ function readCaptureVariants(root, file) {
|
|
|
1364
1512
|
* entry: '/repo/node_modules/vitest/vitest.mjs',
|
|
1365
1513
|
* config: '/repo/vite.journey.config.ts',
|
|
1366
1514
|
* report: '/repo/tmp/units/runs/a/journey-selected.json',
|
|
1515
|
+
* progress: '/repo/tmp/units/runs/a/selected.progress.jsonl',
|
|
1367
1516
|
* projects: ['journey:light-390'],
|
|
1368
1517
|
* filter: 'owner:pages:mail',
|
|
1369
1518
|
* final: 'closes the run',
|
|
@@ -1382,13 +1531,13 @@ function buildCaptureArguments(options) {
|
|
|
1382
1531
|
"--configLoader",
|
|
1383
1532
|
"runner",
|
|
1384
1533
|
"--no-cache",
|
|
1385
|
-
"--bail=1",
|
|
1534
|
+
...options.bail === false ? [] : ["--bail=1"],
|
|
1386
1535
|
"--reporter=dot",
|
|
1387
1536
|
"--reporter=json",
|
|
1388
1537
|
`--outputFile.json=${options.report}`,
|
|
1538
|
+
`--outputFile.progress=${options.progress}`,
|
|
1389
1539
|
...options.projects.flatMap((project) => ["--project", project]),
|
|
1390
|
-
"--tags-filter",
|
|
1391
|
-
options.filter,
|
|
1540
|
+
...options.filter === void 0 ? [] : ["--tags-filter", options.filter],
|
|
1392
1541
|
...options.case === void 0 ? [] : ["-t", `^(?:${[options.case, options.final].map((name) => escapeCapturePattern((options.titles?.[name] ?? [name]).join(separator))).join("|")})$`]
|
|
1393
1542
|
];
|
|
1394
1543
|
}
|
|
@@ -1396,7 +1545,7 @@ function buildCaptureArguments(options) {
|
|
|
1396
1545
|
* Reads the installed workspace Vitest's exact title separator, refusing unsupported majors.
|
|
1397
1546
|
* @example
|
|
1398
1547
|
* ```ts
|
|
1399
|
-
* readCaptureSeparator('/workspace/node_modules/vitest/vitest.mjs') // ' ' on Vitest
|
|
1548
|
+
* readCaptureSeparator('/workspace/node_modules/vitest/vitest.mjs') // ' > ' on Vitest 5
|
|
1400
1549
|
* ```
|
|
1401
1550
|
*/
|
|
1402
1551
|
function readCaptureSeparator(entry) {
|
|
@@ -1408,9 +1557,8 @@ function readCaptureSeparator(entry) {
|
|
|
1408
1557
|
});
|
|
1409
1558
|
const manifest = loaded.value;
|
|
1410
1559
|
const version = isRecord(manifest) ? manifest.version : void 0;
|
|
1411
|
-
if (typeof version === "string" && version.split(".")[0] === "4") return " ";
|
|
1412
1560
|
if (typeof version === "string" && version.split(".")[0] === "5") return " > ";
|
|
1413
|
-
throw new CaptureError(describeCaptureFault("vitest.version", version, "a supported installed Vitest major", ["
|
|
1561
|
+
throw new CaptureError(describeCaptureFault("vitest.version", version, "a supported installed Vitest major", ["5"]), { code: "HOST" });
|
|
1414
1562
|
}
|
|
1415
1563
|
/**
|
|
1416
1564
|
* Reads original title segments from the accepted registry's authenticated JSON reporter files.
|
|
@@ -1449,6 +1597,10 @@ function readCaptureTitles(root, file, selector) {
|
|
|
1449
1597
|
/**
|
|
1450
1598
|
* Parses standard option tokens and refuses empty values, terminators, and repeated single options.
|
|
1451
1599
|
*
|
|
1600
|
+
* @remarks A boolean option whose default is `true` reads its `--no-` form as `false` and refuses
|
|
1601
|
+
* its positive form, so `--no-bail` is the one spelling of `bail`; the `--no-` form of any other
|
|
1602
|
+
* option is refused as unknown. An option and its `--no-` form repeat each other.
|
|
1603
|
+
*
|
|
1452
1604
|
* @param argv - The arguments after the subcommand
|
|
1453
1605
|
* @param options - The command's frozen Node option definitions
|
|
1454
1606
|
* @param usage - The command syntax appended to every parser refusal
|
|
@@ -1456,6 +1608,7 @@ function readCaptureTitles(root, file, selector) {
|
|
|
1456
1608
|
* @example
|
|
1457
1609
|
* ```ts
|
|
1458
1610
|
* readCaptureOptions(['--case=-draft'], CAPTURE_COMMAND_OPTIONS.journey, 'Usage: capture journey <selector>').values.case // '-draft'
|
|
1611
|
+
* readCaptureOptions(['--no-bail'], CAPTURE_COMMAND_OPTIONS.journey, 'Usage: capture journey <selector>').values.bail // false
|
|
1459
1612
|
* ```
|
|
1460
1613
|
*/
|
|
1461
1614
|
function readCaptureOptions(argv, options, usage) {
|
|
@@ -1465,11 +1618,14 @@ function readCaptureOptions(argv, options, usage) {
|
|
|
1465
1618
|
options,
|
|
1466
1619
|
tokens: true,
|
|
1467
1620
|
strict: true,
|
|
1468
|
-
allowPositionals: true
|
|
1621
|
+
allowPositionals: true,
|
|
1622
|
+
allowNegative: true
|
|
1469
1623
|
});
|
|
1470
1624
|
for (const token of parsed.tokens) {
|
|
1471
1625
|
if (token.kind === "option-terminator") throw new CaptureError("The -- option terminator is refused", { code: "USAGE" });
|
|
1472
1626
|
if (token.kind !== "option") continue;
|
|
1627
|
+
if (token.rawName === `--no-${token.name}` && options[token.name]?.default !== true) throw new CaptureError(`Unknown option '${token.rawName}'`, { code: "USAGE" });
|
|
1628
|
+
if (token.rawName === `--${token.name}` && options[token.name]?.default === true) throw new CaptureError(`Unknown option '${token.rawName}'; ${token.name} is on by default, and --no-${token.name} turns it off`, { code: "USAGE" });
|
|
1473
1629
|
if (token.value === "") throw new CaptureError(`Missing value: --${token.name}`, { code: "USAGE" });
|
|
1474
1630
|
if (options[token.name]?.multiple !== true && parsed.tokens.some((earlier) => earlier.kind === "option" && earlier.name === token.name && earlier.index < token.index)) throw new CaptureError(`Repeated option: --${token.name}`, { code: "USAGE" });
|
|
1475
1631
|
}
|
|
@@ -1486,7 +1642,8 @@ function readCaptureOptions(argv, options, usage) {
|
|
|
1486
1642
|
*
|
|
1487
1643
|
* @remarks
|
|
1488
1644
|
* `--state` belongs to `capture` and `stale`, and `--portfolio` to `stale`. Journey and capture
|
|
1489
|
-
* accept `--changed <ref>` instead of a selector, with optional valueless `--plan
|
|
1645
|
+
* accept `--changed <ref>` instead of a selector, with optional valueless `--plan`, and valueless
|
|
1646
|
+
* `--no-bail`, which sets `bail` to `false`. Every other
|
|
1490
1647
|
* flag takes one nonempty value, either separated or in equals form, and only `--variant` repeats.
|
|
1491
1648
|
* A value beginning with a dash requires equals form. A bare invocation leaves its selector absent
|
|
1492
1649
|
* so the caller can print usage with the declared selectors.
|
|
@@ -1522,12 +1679,14 @@ function readCaptureArguments(argv, command, root, fallback) {
|
|
|
1522
1679
|
const selector = positional.at(0);
|
|
1523
1680
|
const changed = "changed" in values && typeof values.changed === "string" ? values.changed : void 0;
|
|
1524
1681
|
const plan = "plan" in values && values.plan === true;
|
|
1682
|
+
const bail = !("bail" in values) || values.bail !== false;
|
|
1525
1683
|
if (changed !== void 0 && selector !== void 0) throw new CaptureError("A selector cannot be combined with --changed; use --changed <ref> alone", { code: "USAGE" });
|
|
1526
1684
|
if (plan && changed === void 0) throw new CaptureError("--plan requires --changed <ref>", { code: "USAGE" });
|
|
1527
1685
|
return {
|
|
1528
1686
|
...selector === void 0 ? {} : { selector },
|
|
1529
1687
|
...changed === void 0 ? {} : { changed },
|
|
1530
1688
|
...plan ? { plan: true } : {},
|
|
1689
|
+
...bail ? {} : { bail: false },
|
|
1531
1690
|
config: resolve(root, values.config ?? fallback),
|
|
1532
1691
|
...mode === void 0 ? {} : { mode },
|
|
1533
1692
|
variants,
|
|
@@ -1988,29 +2147,6 @@ function collectCaptureErrors(file, text) {
|
|
|
1988
2147
|
return text.split(/\r\n|\n/u).filter((line) => /\b(uncaught|unhandled|error:)/iu.test(line)).map((line) => `${file}: ${line}`);
|
|
1989
2148
|
}
|
|
1990
2149
|
/**
|
|
1991
|
-
* Checks whether a process with this id is running, counting one the caller may not signal.
|
|
1992
|
-
*
|
|
1993
|
-
* @remarks
|
|
1994
|
-
* A zero signal tests existence without sending one. A refusal for permission still proves the
|
|
1995
|
-
* process exists, so only a missing process reads as not running.
|
|
1996
|
-
*
|
|
1997
|
-
* @param pid - The process id
|
|
1998
|
-
* @returns True if the process exists; false otherwise
|
|
1999
|
-
*
|
|
2000
|
-
* @example
|
|
2001
|
-
* ```ts
|
|
2002
|
-
* readCaptureRunning(process.pid) // true
|
|
2003
|
-
* ```
|
|
2004
|
-
*/
|
|
2005
|
-
function readCaptureRunning(pid) {
|
|
2006
|
-
try {
|
|
2007
|
-
process.kill(pid, 0);
|
|
2008
|
-
return true;
|
|
2009
|
-
} catch (error) {
|
|
2010
|
-
return isError(error) && "code" in error && error.code === "EPERM";
|
|
2011
|
-
}
|
|
2012
|
-
}
|
|
2013
|
-
/**
|
|
2014
2150
|
* Resolves one entry of a wrapper's project list to the project it declares.
|
|
2015
2151
|
*
|
|
2016
2152
|
* @remarks
|
|
@@ -2213,12 +2349,294 @@ async function answerCaptureDiscovery(options) {
|
|
|
2213
2349
|
return true;
|
|
2214
2350
|
}
|
|
2215
2351
|
/**
|
|
2352
|
+
* Lists a directory through a reader, answering an empty list for a missing directory.
|
|
2353
|
+
*
|
|
2354
|
+
* @param directory - The absolute directory to list
|
|
2355
|
+
* @param list - Reads the directory's entries, such as `readdirSync` with its options
|
|
2356
|
+
* @returns The entries the reader returned, or none when the directory is missing
|
|
2357
|
+
* @throws Thrown as an `EVIDENCE` capture error naming the directory for any other failure to read it.
|
|
2358
|
+
*
|
|
2359
|
+
* @example
|
|
2360
|
+
* ```ts
|
|
2361
|
+
* readCaptureListing('/repo/tmp/captures/states/pages', (path) => readdirSync(path)) // ['inbox--light-390.png']
|
|
2362
|
+
* ```
|
|
2363
|
+
*/
|
|
2364
|
+
function readCaptureListing(directory, list) {
|
|
2365
|
+
const listed = attempt(() => list(directory));
|
|
2366
|
+
if (listed.success) return listed.value;
|
|
2367
|
+
if (isError(listed.error) && "code" in listed.error && listed.error.code === "ENOENT") return [];
|
|
2368
|
+
throw new CaptureError(`Cannot list capture frames under ${directory}`, {
|
|
2369
|
+
code: "EVIDENCE",
|
|
2370
|
+
cause: listed.error,
|
|
2371
|
+
context: { directory }
|
|
2372
|
+
});
|
|
2373
|
+
}
|
|
2374
|
+
/**
|
|
2375
|
+
* Lists the frames a portfolio directory holds, as paths relative to it, in sorted order.
|
|
2376
|
+
*
|
|
2377
|
+
* @remarks
|
|
2378
|
+
* A frame is a `.png` file at the directory's top level or directly inside one of the scope
|
|
2379
|
+
* directories. The run records directory holds no frame, and every other directory is unknown. A
|
|
2380
|
+
* missing directory, or one removed between the listing and its read, holds no frame.
|
|
2381
|
+
*
|
|
2382
|
+
* @param directory - The absolute portfolio directory
|
|
2383
|
+
* @param scopes - The scope directories the owners declare, each an owner path's first segment
|
|
2384
|
+
* @returns Each frame's slash-separated path relative to the directory
|
|
2385
|
+
* @throws Thrown as an `EVIDENCE` capture error for a frame beneath the run records, an unknown
|
|
2386
|
+
* directory, a directory inside a scope, or a directory the host refuses to read.
|
|
2387
|
+
*
|
|
2388
|
+
* @example
|
|
2389
|
+
* ```ts
|
|
2390
|
+
* readCaptureFrames('/repo/tmp/captures/states', ['pages']) // ['pages/inbox--light-390.png']
|
|
2391
|
+
* ```
|
|
2392
|
+
*/
|
|
2393
|
+
function readCaptureFrames(directory, scopes) {
|
|
2394
|
+
return readCaptureListing(directory, (path) => readdirSync(path, { withFileTypes: true })).flatMap((entry) => {
|
|
2395
|
+
if (!entry.isDirectory()) return entry.name.endsWith(".png") ? [entry.name] : [];
|
|
2396
|
+
if (entry.name === "runs") {
|
|
2397
|
+
const frames = readCaptureListing(resolve(directory, entry.name), (path) => readdirSync(path, {
|
|
2398
|
+
recursive: true,
|
|
2399
|
+
encoding: "utf8"
|
|
2400
|
+
})).filter((name) => name.endsWith(".png"));
|
|
2401
|
+
if (frames.length > 0) throw new CaptureError(`Frames sit beneath the run records: ${describeCaptureMembers(frames.map(normalizeSlashes))}`, {
|
|
2402
|
+
code: "EVIDENCE",
|
|
2403
|
+
context: { directory }
|
|
2404
|
+
});
|
|
2405
|
+
return [];
|
|
2406
|
+
}
|
|
2407
|
+
if (!scopes.includes(entry.name)) throw new CaptureError(`Unknown capture directory: ${describeCaptureFault("directory", entry.name, "a scope the owners declare, or the run records", [...scopes, CAPTURE_RUNS_DIRECTORY])}`, {
|
|
2408
|
+
code: "EVIDENCE",
|
|
2409
|
+
context: { directory }
|
|
2410
|
+
});
|
|
2411
|
+
return readCaptureListing(resolve(directory, entry.name), (path) => readdirSync(path, { withFileTypes: true })).flatMap((file) => {
|
|
2412
|
+
if (file.isDirectory()) throw new CaptureError(`Unknown capture directory: ${preview(`${entry.name}/${file.name}`)}; a scope holds frames only`, {
|
|
2413
|
+
code: "EVIDENCE",
|
|
2414
|
+
context: { directory }
|
|
2415
|
+
});
|
|
2416
|
+
return file.name.endsWith(".png") ? [`${entry.name}/${file.name}`] : [];
|
|
2417
|
+
});
|
|
2418
|
+
}).toSorted();
|
|
2419
|
+
}
|
|
2420
|
+
/**
|
|
2421
|
+
* Reads the progress file of the stage that is running, or that ran last, in a workspace.
|
|
2422
|
+
*
|
|
2423
|
+
* @remarks
|
|
2424
|
+
* The file is the most recently modified `<stage>.progress.jsonl` beneath the request directory's
|
|
2425
|
+
* run directories. The progress file is an observation of the run and never evidence. A partial
|
|
2426
|
+
* last line, which the reporter can still be appending, is not read, so a file with no complete
|
|
2427
|
+
* line holds no run. For each run with no `end` line, `alive` reads the process id its `init` line
|
|
2428
|
+
* records: a writer that has ended turns the run `interrupted`, measured to the time of its last
|
|
2429
|
+
* line, and a writer the host cannot inspect, or an id that is not a positive safe integer, lists
|
|
2430
|
+
* the run's id in `uninspected`.
|
|
2431
|
+
*
|
|
2432
|
+
* @param root - The absolute workspace path
|
|
2433
|
+
* @param requests - The workspace-relative request directory
|
|
2434
|
+
* @param now - The wall-clock time of the reading, in milliseconds since the Unix epoch. Default: `Date.now()`
|
|
2435
|
+
* @param alive - Reads whether a writer process exists, or `undefined` when the host cannot tell. Default: `inspectProcess` from `@orkestrel/process/server`
|
|
2436
|
+
* @returns The workspace-relative file, one reading per process that wrote it, and the writers the host could not inspect
|
|
2437
|
+
* @throws Thrown as a `STAGE` capture error when no stage has written a progress file, or when the
|
|
2438
|
+
* file cannot be read or holds a complete line that is not a progress event.
|
|
2439
|
+
*
|
|
2440
|
+
* @example
|
|
2441
|
+
* ```ts
|
|
2442
|
+
* readCaptureProgress('/repo', 'tmp/capture').runs[0]?.state // 'live' while the stage runs
|
|
2443
|
+
* ```
|
|
2444
|
+
*/
|
|
2445
|
+
function readCaptureProgress(root, requests, now = Date.now(), alive = inspectProcess) {
|
|
2446
|
+
const runs = resolve(root, requests, CAPTURE_RUNS_DIRECTORY);
|
|
2447
|
+
const [newest] = globSync(`*/*${CAPTURE_PROGRESS_SUFFIX}`, { cwd: runs }).flatMap((name) => {
|
|
2448
|
+
const stat = attempt(() => statSync(resolve(runs, name)));
|
|
2449
|
+
return stat.success && stat.value.isFile() ? [{
|
|
2450
|
+
file: resolveCaptureRelative(root, resolve(runs, name)),
|
|
2451
|
+
time: stat.value.mtimeMs
|
|
2452
|
+
}] : [];
|
|
2453
|
+
}).toSorted((left, right) => right.time - left.time || right.file.localeCompare(left.file));
|
|
2454
|
+
if (newest === void 0) throw new CaptureError(`No stage has written a progress file under ${resolveCaptureRelative(root, runs)}; run a journey, frames, or registry command first`, {
|
|
2455
|
+
code: "STAGE",
|
|
2456
|
+
context: { directory: resolveCaptureRelative(root, runs) }
|
|
2457
|
+
});
|
|
2458
|
+
const read = attempt(() => extractProgressEvents(readFileSnapshot(resolve(root, newest.file)).toString("utf8")));
|
|
2459
|
+
if (!read.success) throw new CaptureError(`Cannot read the progress file ${newest.file}: ${describeCaptureOutput(describeCaptureError(read.error))}`, {
|
|
2460
|
+
code: "STAGE",
|
|
2461
|
+
cause: read.error,
|
|
2462
|
+
context: { file: newest.file }
|
|
2463
|
+
});
|
|
2464
|
+
const events = read.value;
|
|
2465
|
+
const computed = computeProgress(events, now);
|
|
2466
|
+
const writers = new Map(computed.filter((run) => run.state === "live").map((run) => [run.pid, Number.isSafeInteger(run.pid) && run.pid > 0 ? alive(run.pid) : void 0]));
|
|
2467
|
+
return {
|
|
2468
|
+
file: newest.file,
|
|
2469
|
+
runs: computed.map((run) => {
|
|
2470
|
+
if (writers.get(run.pid) !== false) return run;
|
|
2471
|
+
const own = events.filter((event) => event.pid === run.pid);
|
|
2472
|
+
const init = own.findLast((event) => event.event === "init");
|
|
2473
|
+
const last = own.at(-1);
|
|
2474
|
+
return {
|
|
2475
|
+
...init === void 0 || last === void 0 ? run : computeProgressRun(own, init.wall + last.time - init.time) ?? run,
|
|
2476
|
+
state: "interrupted",
|
|
2477
|
+
running: [],
|
|
2478
|
+
remaining: void 0
|
|
2479
|
+
};
|
|
2480
|
+
}),
|
|
2481
|
+
uninspected: [...writers].flatMap(([pid, answer]) => answer === void 0 ? [pid] : [])
|
|
2482
|
+
};
|
|
2483
|
+
}
|
|
2484
|
+
/**
|
|
2485
|
+
* Renders a progress reading as the text `capture progress` prints.
|
|
2486
|
+
*
|
|
2487
|
+
* @param progress - The reading `readCaptureProgress` returns
|
|
2488
|
+
* @returns The file line, then each run as `renderProgress` from `@orkestrel/test/server` renders it,
|
|
2489
|
+
* followed by an unknown-state line for each run whose writer the host could not inspect
|
|
2490
|
+
*
|
|
2491
|
+
* @example
|
|
2492
|
+
* ```ts
|
|
2493
|
+
* renderCaptureProgress({ file: 'tmp/capture/runs/a/selected.progress.jsonl', runs: [], uninspected: [] })
|
|
2494
|
+
* // 'progress tmp/capture/runs/a/selected.progress.jsonl\nNo run has written a complete progress line yet'
|
|
2495
|
+
* ```
|
|
2496
|
+
*/
|
|
2497
|
+
function renderCaptureProgress(progress) {
|
|
2498
|
+
return [`progress ${progress.file}`, ...progress.runs.length === 0 ? ["No run has written a complete progress line yet"] : progress.runs.flatMap((run) => [renderProgress([run]), ...progress.uninspected.includes(run.pid) ? [` state unknown: the host could not inspect writer ${String(run.pid)}, so the run might have ended without its end line`] : []])].join("\n");
|
|
2499
|
+
}
|
|
2500
|
+
/**
|
|
2501
|
+
* Builds the values capture merges into one variant's Vitest project.
|
|
2502
|
+
*
|
|
2503
|
+
* @param options - The wrapper's declarations
|
|
2504
|
+
* @param variant - The variant the project produces
|
|
2505
|
+
* @param provided - The variant's frame directory, run record path, capture switch, and runner request
|
|
2506
|
+
* @returns The owner tags, the provided values, and the `readCaptureFrames` browser command over the directory
|
|
2507
|
+
*
|
|
2508
|
+
* @example
|
|
2509
|
+
* ```ts
|
|
2510
|
+
* buildCaptureOverride(options, variant, { directory, record, capture: true }).test.provide.record
|
|
2511
|
+
* // 'tmp/captures/states/runs/run-1/selected/light-390.json'
|
|
2512
|
+
* ```
|
|
2513
|
+
*/
|
|
2514
|
+
function buildCaptureOverride(options, variant, provided) {
|
|
2515
|
+
const scopes = [...new Set(options.owners.flatMap((owner) => collectCaptureAncestors(owner).slice(0, 1)))];
|
|
2516
|
+
return { test: {
|
|
2517
|
+
tags: buildCaptureTags(options.owners).map((name) => ({ name })),
|
|
2518
|
+
provide: {
|
|
2519
|
+
variant: variant.name,
|
|
2520
|
+
variants: options.variants,
|
|
2521
|
+
directory: provided.directory,
|
|
2522
|
+
record: provided.record,
|
|
2523
|
+
inputs: options.inputs,
|
|
2524
|
+
sources: options.sources,
|
|
2525
|
+
final: options.final,
|
|
2526
|
+
first: options.first,
|
|
2527
|
+
...options.uniform === void 0 ? {} : { uniform: options.uniform },
|
|
2528
|
+
portfolios: options.portfolios,
|
|
2529
|
+
capture: provided.capture,
|
|
2530
|
+
...provided.request === void 0 ? {} : { request: provided.request }
|
|
2531
|
+
},
|
|
2532
|
+
browser: { commands: { readCaptureFrames: () => readCaptureFrames(provided.directory, scopes) } }
|
|
2533
|
+
} };
|
|
2534
|
+
}
|
|
2535
|
+
/**
|
|
2536
|
+
* Builds a journey wrapper's Vitest configuration as plain data, answering discovery first.
|
|
2537
|
+
*
|
|
2538
|
+
* @remarks
|
|
2539
|
+
* Call it inside the wrapper's own `defineConfig` callback, before any other work: capture imports
|
|
2540
|
+
* neither Vite nor Vitest, so the result is data the wrapper returns. The wrapper path is `url`
|
|
2541
|
+
* relative to the working directory, which is the workspace root for every child the runner
|
|
2542
|
+
* spawns. During a discovery request it describes each variant's project as `{ name, tags,
|
|
2543
|
+
* provide }`, with the name the host's `project` chose, and returns `buildCaptureDiscoveryConfig()`.
|
|
2544
|
+
* Otherwise it reads the runner's request, provides each project the values `CaptureProvided`
|
|
2545
|
+
* declares except `standalone`, and registers the browser command `readCaptureFrames`, which lists the frames under
|
|
2546
|
+
* the provided directory. With the capture variable unset, each variant writes to its own scratch
|
|
2547
|
+
* sibling of the evidence root, emptied first. The result's root `plugins` holds one
|
|
2548
|
+
* `createProgressPlugin()`, so a stage the runner passes `--outputFile.progress` writes its
|
|
2549
|
+
* progress file.
|
|
2550
|
+
*
|
|
2551
|
+
* @param options - The wrapper path, variants, owners, stage and final names, evidence root, inputs, sources, portfolios, and project builder
|
|
2552
|
+
* @returns The discovery configuration while discovery runs, and otherwise the progress plugin and one project per variant
|
|
2553
|
+
* @throws Thrown as a `HOST` capture error, before any directory work, for a `url` that is no
|
|
2554
|
+
* `file:` URL, an evidence root that is not a portable relative path, or a variant name that is no
|
|
2555
|
+
* capture segment, and later for an invalid owner or a runner request that fails its checks; and as
|
|
2556
|
+
* a `CONTAINMENT` capture error for a wrapper or scratch path outside the workspace.
|
|
2557
|
+
*
|
|
2558
|
+
* @example
|
|
2559
|
+
* ```ts
|
|
2560
|
+
* export default defineConfig(({ mode }) =>
|
|
2561
|
+
* buildCaptureWrapper({ ...declarations, url: import.meta.url, project: (variant, override) => appJourney(variant, mode, override) }),
|
|
2562
|
+
* )
|
|
2563
|
+
* ```
|
|
2564
|
+
*/
|
|
2565
|
+
async function buildCaptureWrapper(options) {
|
|
2566
|
+
const root = process.cwd();
|
|
2567
|
+
const path = attempt(() => fileURLToPath(options.url));
|
|
2568
|
+
if (!path.success) throw new CaptureError(`Invalid wrapper url; ${describeCaptureFault("url", options.url, "the wrapper module's import.meta.url, a file: URL")}`, {
|
|
2569
|
+
code: "HOST",
|
|
2570
|
+
cause: path.error
|
|
2571
|
+
});
|
|
2572
|
+
requireCaptureContained(root, path.value);
|
|
2573
|
+
if (!isCapturePath(options.directory)) throw new CaptureError(`Invalid evidence root; ${describeCaptureFault("directory", options.directory, "a portable workspace-relative path")}`, { code: "HOST" });
|
|
2574
|
+
const invalid = options.variants.findIndex((variant) => !isCaptureSegment(variant.name));
|
|
2575
|
+
if (invalid !== -1) throw new CaptureError(`Invalid variant name; ${describeCaptureFault(`variants[${String(invalid)}].name`, options.variants[invalid]?.name, "a portable nonempty identity segment")}`, { code: "HOST" });
|
|
2576
|
+
const roots = [options.directory, ...options.portfolios.map((entry) => entry.directory)];
|
|
2577
|
+
for (const variant of options.variants) {
|
|
2578
|
+
const scratch = resolve(root, dirname(options.directory), `${CAPTURE_WRAPPER_PREFIXES.scratch}${variant.name}`);
|
|
2579
|
+
const overlap = roots.find((entry) => [relative(resolve(root, entry), scratch), relative(scratch, resolve(root, entry))].some((step) => step === "" || !step.startsWith("..") && !isAbsolute(step)));
|
|
2580
|
+
if (overlap !== void 0) throw new CaptureError(`Invalid evidence root; the no-capture scratch directory ${resolveCaptureRelative(root, scratch)} of variant ${variant.name} overlaps ${overlap}, which it would empty`, { code: "HOST" });
|
|
2581
|
+
}
|
|
2582
|
+
const config = resolveCaptureRelative(root, path.value);
|
|
2583
|
+
const argv = process.argv.slice(1);
|
|
2584
|
+
const capture = process.env[CAPTURE_FLAG] === "1";
|
|
2585
|
+
const evidence = resolve(root, options.directory);
|
|
2586
|
+
if (await answerCaptureDiscovery({
|
|
2587
|
+
ppid: process.ppid,
|
|
2588
|
+
argv,
|
|
2589
|
+
config,
|
|
2590
|
+
projects: options.variants.map((variant) => () => {
|
|
2591
|
+
const override = buildCaptureOverride(options, variant, {
|
|
2592
|
+
directory: evidence,
|
|
2593
|
+
record: `${options.directory}/runs/${CAPTURE_DISCOVERY.phase}/${variant.name}.json`,
|
|
2594
|
+
capture
|
|
2595
|
+
});
|
|
2596
|
+
const project = options.project(variant, override);
|
|
2597
|
+
return { test: {
|
|
2598
|
+
name: isRecord(project) && isRecord(project.test) ? project.test.name : void 0,
|
|
2599
|
+
tags: override.test.tags,
|
|
2600
|
+
provide: override.test.provide
|
|
2601
|
+
} };
|
|
2602
|
+
})
|
|
2603
|
+
})) return buildCaptureDiscoveryConfig();
|
|
2604
|
+
const request = readCaptureRequest({
|
|
2605
|
+
ppid: process.ppid,
|
|
2606
|
+
argv,
|
|
2607
|
+
config,
|
|
2608
|
+
owners: options.owners,
|
|
2609
|
+
variants: options.variants.map((variant) => variant.name)
|
|
2610
|
+
});
|
|
2611
|
+
const invocation = request === void 0 ? `${CAPTURE_WRAPPER_PREFIXES.direct}${randomUUID()}` : `${request.id}/${request.stage}`;
|
|
2612
|
+
return {
|
|
2613
|
+
plugins: [createProgressPlugin()],
|
|
2614
|
+
test: { projects: options.variants.map((variant) => {
|
|
2615
|
+
const directory = capture ? evidence : requireCaptureContained(root, resolve(root, dirname(options.directory), `${CAPTURE_WRAPPER_PREFIXES.scratch}${variant.name}`));
|
|
2616
|
+
if (!capture) {
|
|
2617
|
+
rmSync(directory, {
|
|
2618
|
+
recursive: true,
|
|
2619
|
+
force: true
|
|
2620
|
+
});
|
|
2621
|
+
mkdirSync(directory, { recursive: true });
|
|
2622
|
+
}
|
|
2623
|
+
return options.project(variant, buildCaptureOverride(options, variant, {
|
|
2624
|
+
directory,
|
|
2625
|
+
record: `${options.directory}/${CAPTURE_RUNS_DIRECTORY}/${invocation}/${variant.name}.json`,
|
|
2626
|
+
capture,
|
|
2627
|
+
...request === void 0 ? {} : { request }
|
|
2628
|
+
}));
|
|
2629
|
+
}) }
|
|
2630
|
+
};
|
|
2631
|
+
}
|
|
2632
|
+
/**
|
|
2216
2633
|
* Reads the registry command line into the wrapper path, the variants to refresh, and the mode.
|
|
2217
2634
|
*
|
|
2218
2635
|
* @remarks
|
|
2219
2636
|
* The command takes no selector: it refreshes every producing variant the wrapper declares, or the
|
|
2220
|
-
* variants named by repeated `--variant` flags. Every flag
|
|
2221
|
-
* repeats. `--mode` is forwarded to the wrapper's Vitest process
|
|
2637
|
+
* variants named by repeated `--variant` flags. Every flag but valueless `--no-bail` takes one
|
|
2638
|
+
* value, and only `--variant` repeats. `--mode` is forwarded to the wrapper's Vitest process
|
|
2639
|
+
* unread, and `--no-bail` sets `bail` to `false`.
|
|
2222
2640
|
*
|
|
2223
2641
|
* @param argv - The arguments after the subcommand
|
|
2224
2642
|
* @param root - The absolute workspace path the wrapper path resolves against
|
|
@@ -2234,7 +2652,7 @@ async function answerCaptureDiscovery(options) {
|
|
|
2234
2652
|
* ```
|
|
2235
2653
|
*/
|
|
2236
2654
|
function readCaptureRegistryArguments(argv, root, fallback) {
|
|
2237
|
-
const usage = "Usage: capture registry [--variant <name>]... [--mode <name>] [--config <file>]";
|
|
2655
|
+
const usage = "Usage: capture registry [--variant <name>]... [--no-bail] [--mode <name>] [--config <file>]";
|
|
2238
2656
|
const { values, positionals } = readCaptureOptions(argv, CAPTURE_COMMAND_OPTIONS.registry, usage);
|
|
2239
2657
|
if (positionals.length > 0) throw new CaptureError(`Unexpected argument ${JSON.stringify(positionals[0]?.slice(0, 80))}: the registry command takes no selector and refreshes every producing variant, or those named by --variant. ${usage}`, { code: "USAGE" });
|
|
2240
2658
|
const variants = values.variant ?? [];
|
|
@@ -2245,7 +2663,8 @@ function readCaptureRegistryArguments(argv, root, fallback) {
|
|
|
2245
2663
|
return {
|
|
2246
2664
|
config: resolve(root, values.config ?? fallback),
|
|
2247
2665
|
variants,
|
|
2248
|
-
...mode === void 0 ? {} : { mode }
|
|
2666
|
+
...mode === void 0 ? {} : { mode },
|
|
2667
|
+
...values.bail === false ? { bail: false } : {}
|
|
2249
2668
|
};
|
|
2250
2669
|
}
|
|
2251
2670
|
/**
|
|
@@ -2446,6 +2865,7 @@ var CaptureIntegrity = class {
|
|
|
2446
2865
|
#root;
|
|
2447
2866
|
#roots;
|
|
2448
2867
|
#hash;
|
|
2868
|
+
#matches = /* @__PURE__ */ new Map();
|
|
2449
2869
|
/**
|
|
2450
2870
|
* Binds the engine to an explicit workspace and host portfolio mapping.
|
|
2451
2871
|
*
|
|
@@ -3089,12 +3509,24 @@ var CaptureIntegrity = class {
|
|
|
3089
3509
|
]) {
|
|
3090
3510
|
const current = this.#digest(patterns, snapshots, digests);
|
|
3091
3511
|
if (Object.keys(current.files).some((file) => before.files[file] === void 0)) throw new CaptureError(`Attribution outside the predeclared host population: ${entry.file}`, { code: "STAGE" });
|
|
3092
|
-
const
|
|
3512
|
+
const matched = this.#match(before, patterns);
|
|
3513
|
+
const previous = Object.fromEntries(Object.entries(before.files).filter(([file]) => matched.has(file)));
|
|
3093
3514
|
if (collectCaptureChanges(previous, current.files).length > 0) throw new CaptureError(`Attributed inputs or membership changed during execution: ${entry.file}`, { code: "STAGE" });
|
|
3094
|
-
if (patterns.some((pattern) =>
|
|
3515
|
+
if (patterns.some((pattern) => {
|
|
3516
|
+
const files = this.#match(before, [pattern]);
|
|
3517
|
+
return !Object.keys(current.files).some((file) => files.has(file));
|
|
3518
|
+
})) throw new CaptureError(`Declared source pattern has no files: ${entry.file}`, { code: "HOST" });
|
|
3095
3519
|
}
|
|
3096
3520
|
stable.set(key, true);
|
|
3097
3521
|
}
|
|
3522
|
+
#match(inputs, patterns) {
|
|
3523
|
+
const key = computeCaptureMatchKey(inputs, patterns);
|
|
3524
|
+
const known = this.#matches.get(key);
|
|
3525
|
+
if (known !== void 0) return known;
|
|
3526
|
+
const matched = filterCaptureInputs(inputs, patterns);
|
|
3527
|
+
this.#matches.set(key, matched);
|
|
3528
|
+
return matched;
|
|
3529
|
+
}
|
|
3098
3530
|
#destination(entry, paths) {
|
|
3099
3531
|
const portfolio = this.#options.portfolios.find((candidate) => candidate.portfolio === entry.portfolio);
|
|
3100
3532
|
if (portfolio === void 0) throw new CaptureError(`Unknown portfolio: ${entry.portfolio}`, { code: "SELECTION" });
|
|
@@ -3394,6 +3826,7 @@ var CaptureInvocation = class {
|
|
|
3394
3826
|
}
|
|
3395
3827
|
async release() {
|
|
3396
3828
|
const failures = [];
|
|
3829
|
+
const kept = [];
|
|
3397
3830
|
try {
|
|
3398
3831
|
if (this.#termination !== void 0) await this.#termination;
|
|
3399
3832
|
failures.push(...await settleCaptureShutdown(() => this.retract(), [...this.#children].map((child) => () => this.#stop(child))));
|
|
@@ -3412,7 +3845,10 @@ var CaptureInvocation = class {
|
|
|
3412
3845
|
}
|
|
3413
3846
|
if (this.#owner(marker.value).id !== this.id) return;
|
|
3414
3847
|
if (this.#unconfirmed.size > 0) {
|
|
3415
|
-
this.#
|
|
3848
|
+
kept.push(`ownership marker retained: ${this.#lock}`);
|
|
3849
|
+
const record = attempt(() => this.#record());
|
|
3850
|
+
if (record.success) kept.push(`child record: ${record.value}`);
|
|
3851
|
+
else failures.push(record.error);
|
|
3416
3852
|
return;
|
|
3417
3853
|
}
|
|
3418
3854
|
this.#remove(deadline);
|
|
@@ -3421,7 +3857,7 @@ var CaptureInvocation = class {
|
|
|
3421
3857
|
else if (!removal.success) failures.push(removal.error);
|
|
3422
3858
|
}
|
|
3423
3859
|
}
|
|
3424
|
-
if (failures.length > 0 || this.#unconfirmed.size > 0) throw new CaptureError(`Capture shutdown failed${this.#unconfirmed.size === 0 ? "" : `; child termination was not confirmed for process ${[...this.#unconfirmed].join(", ")}
|
|
3860
|
+
if (failures.length > 0 || this.#unconfirmed.size > 0) throw new CaptureError(`Capture shutdown failed${this.#unconfirmed.size === 0 ? "" : `; child termination was not confirmed for process ${[...this.#unconfirmed].join(", ")}`}${kept.map((entry) => `; ${entry}`).join("")}`, {
|
|
3425
3861
|
code: "STAGE",
|
|
3426
3862
|
cause: new AggregateError(failures)
|
|
3427
3863
|
});
|
|
@@ -3433,15 +3869,21 @@ var CaptureInvocation = class {
|
|
|
3433
3869
|
for (const name of readdirSync(requests)) {
|
|
3434
3870
|
const pid = readCaptureRequestOwner(name);
|
|
3435
3871
|
if (pid === void 0 || pid === process.pid) continue;
|
|
3436
|
-
if (
|
|
3872
|
+
if (this.#alive(pid) === false) attempt(() => rmSync(resolve(requests, name), { force: true }));
|
|
3437
3873
|
}
|
|
3438
3874
|
}
|
|
3439
3875
|
holders() {
|
|
3440
3876
|
const requests = resolve(this.#options.root, this.#options.requests);
|
|
3441
3877
|
return [...new Set(readdirSync(requests).flatMap((name) => {
|
|
3442
3878
|
const pid = readCaptureRequestOwner(name);
|
|
3443
|
-
return pid === void 0 || pid === process.pid && this.#lease !== void 0
|
|
3444
|
-
}))]
|
|
3879
|
+
return pid === void 0 || pid === process.pid && this.#lease !== void 0 ? [] : [pid];
|
|
3880
|
+
}))].flatMap((pid) => {
|
|
3881
|
+
const alive = this.#alive(pid);
|
|
3882
|
+
return alive === false ? [] : [{
|
|
3883
|
+
pid,
|
|
3884
|
+
inspected: alive === true
|
|
3885
|
+
}];
|
|
3886
|
+
});
|
|
3445
3887
|
}
|
|
3446
3888
|
publish(request) {
|
|
3447
3889
|
this.#claim();
|
|
@@ -3476,16 +3918,13 @@ var CaptureInvocation = class {
|
|
|
3476
3918
|
try {
|
|
3477
3919
|
mkdirSync(this.#directory, { recursive: true });
|
|
3478
3920
|
writeFileSync(log, "");
|
|
3479
|
-
const environment = Object.fromEntries(Object.entries(process.env).filter(([name]) => name.toLowerCase() !== "CAPTURE".toLowerCase() && name.toLowerCase() !== "CAPTURE_REQUESTS".toLowerCase()));
|
|
3480
3921
|
const session = createDuplex({
|
|
3481
3922
|
command: {
|
|
3482
3923
|
file: process.execPath,
|
|
3483
3924
|
arguments: args,
|
|
3484
|
-
isolated: true,
|
|
3485
3925
|
environment: {
|
|
3486
|
-
...environment,
|
|
3487
3926
|
[CAPTURE_REQUESTS_FLAG]: resolve(this.#options.root, this.#options.requests),
|
|
3488
|
-
|
|
3927
|
+
[CAPTURE_FLAG]: capture ? "1" : void 0
|
|
3489
3928
|
}
|
|
3490
3929
|
},
|
|
3491
3930
|
workspace: this.#options.root,
|
|
@@ -3597,9 +4036,10 @@ var CaptureInvocation = class {
|
|
|
3597
4036
|
try {
|
|
3598
4037
|
if (this.#options.ownership?.write === void 0) writeFileSync(file, text, { flag: "wx" });
|
|
3599
4038
|
else this.#options.ownership.write(file, text);
|
|
4039
|
+
return file;
|
|
3600
4040
|
} catch (error) {
|
|
3601
4041
|
const code = error instanceof Error && "code" in error ? String(error.code) : describeCaptureError(error);
|
|
3602
|
-
if (code === "EEXIST") return;
|
|
4042
|
+
if (code === "EEXIST") return file;
|
|
3603
4043
|
if (code === "ENOENT" && retry) {
|
|
3604
4044
|
mkdirSync(this.#directory, { recursive: true });
|
|
3605
4045
|
return this.#record(false);
|
|
@@ -3623,9 +4063,9 @@ var CaptureInvocation = class {
|
|
|
3623
4063
|
}
|
|
3624
4064
|
#backoff(deadline, error) {
|
|
3625
4065
|
const left = deadline - performance.now();
|
|
3626
|
-
if (left <= 0) throw new CaptureError(`Capture ownership marker is temporarily unavailable (${error instanceof Error && "code" in error ? String(error.code) :
|
|
4066
|
+
if (left <= 0) throw new CaptureError(error === void 0 ? `Capture ownership marker kept changing until the deadline: ${this.#lock}; rerun after serializing capture commands` : `Capture ownership marker is temporarily unavailable (${error instanceof Error && "code" in error ? String(error.code) : describeCaptureError(error)}): ${this.#lock}; rerun after serializing capture commands`, {
|
|
3627
4067
|
code: "STAGE",
|
|
3628
|
-
cause: error
|
|
4068
|
+
...error === void 0 ? {} : { cause: error }
|
|
3629
4069
|
});
|
|
3630
4070
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Math.min(10, left));
|
|
3631
4071
|
}
|
|
@@ -3640,7 +4080,7 @@ var CaptureInvocation = class {
|
|
|
3640
4080
|
for (const name of readdirSync(requests)) {
|
|
3641
4081
|
if (!name.startsWith(`.capture-owner.`) || !name.endsWith(".tmp")) continue;
|
|
3642
4082
|
const [pid] = name.slice(CAPTURE_OWNER_FILE.length + 1).split(".");
|
|
3643
|
-
if (pid !== void 0 && /^\d+$/u.test(pid) && Number.isSafeInteger(Number(pid)) && Number(pid) > 0 &&
|
|
4083
|
+
if (pid !== void 0 && /^\d+$/u.test(pid) && Number.isSafeInteger(Number(pid)) && Number(pid) > 0 && this.#alive(Number(pid)) === false) attempt(() => rmSync(resolve(requests, name), { force: true }));
|
|
3644
4084
|
}
|
|
3645
4085
|
const temporary = `${this.#lock}.${String(process.pid)}.${this.id}.tmp`;
|
|
3646
4086
|
try {
|
|
@@ -3665,7 +4105,7 @@ var CaptureInvocation = class {
|
|
|
3665
4105
|
cause: error
|
|
3666
4106
|
});
|
|
3667
4107
|
} finally {
|
|
3668
|
-
rmSync(temporary, { force: true });
|
|
4108
|
+
attempt(() => rmSync(temporary, { force: true }));
|
|
3669
4109
|
}
|
|
3670
4110
|
}
|
|
3671
4111
|
#acquire(temporary, deadline) {
|
|
@@ -3692,7 +4132,7 @@ var CaptureInvocation = class {
|
|
|
3692
4132
|
});
|
|
3693
4133
|
}
|
|
3694
4134
|
const owner = attempt(() => this.#owner(marker.value));
|
|
3695
|
-
const alive = owner.success ?
|
|
4135
|
+
const alive = owner.success ? this.#alive(owner.value.pid) : void 0;
|
|
3696
4136
|
if (!owner.success) this.#backoff(deadline);
|
|
3697
4137
|
const confirmed = attempt(() => this.#read(deadline));
|
|
3698
4138
|
if (!confirmed.success) {
|
|
@@ -3711,7 +4151,10 @@ var CaptureInvocation = class {
|
|
|
3711
4151
|
return this.#acquire(temporary, deadline);
|
|
3712
4152
|
}
|
|
3713
4153
|
if (!owner.success) throw owner.error;
|
|
3714
|
-
this.#refuse(owner.value, alive
|
|
4154
|
+
this.#refuse(owner.value, alive);
|
|
4155
|
+
}
|
|
4156
|
+
#alive(pid) {
|
|
4157
|
+
return (this.#options.ownership?.alive ?? inspectProcess)(pid);
|
|
3715
4158
|
}
|
|
3716
4159
|
#owner(marker) {
|
|
3717
4160
|
if (marker === "") throw new CaptureError(`Capture ownership marker is empty; confirm no capture process or surviving child is running and inspect this file: ${this.#lock}; its holder cannot be established`, { code: "STAGE" });
|
|
@@ -3723,15 +4166,18 @@ var CaptureInvocation = class {
|
|
|
3723
4166
|
};
|
|
3724
4167
|
}
|
|
3725
4168
|
#refuse(holder, alive) {
|
|
3726
|
-
if (
|
|
4169
|
+
if (alive === false) throw new CaptureError(`Capture ownership process ${String(holder.pid)} is not running; invocation ${preview(holder.id)}. ${this.#survivors(holder)} Confirm no capture process or surviving child is running and re-read ${this.#lock} to confirm it still names pid ${String(holder.pid)} before you delete this file and rerun`, { code: "STAGE" });
|
|
4170
|
+
if (alive === void 0) throw new CaptureError(`Capture ownership process ${String(holder.pid)} could not be inspected; invocation ${preview(holder.id)}; serialize capture commands. Confirm no capture process or surviving child is running and re-read ${this.#lock} to confirm it still names pid ${String(holder.pid)} before deleting`, { code: "STAGE" });
|
|
3727
4171
|
throw new CaptureError(`Another runner holds this workspace (process ${preview(holder.pid)}); invocation ${preview(holder.id)}; serialize capture commands. If this pid is not a capture run, confirm no capture process or surviving child is running and re-read ${this.#lock} to confirm it still names pid ${String(holder.pid)} before deleting`, { code: "STAGE" });
|
|
3728
4172
|
}
|
|
3729
4173
|
#survivors(holder) {
|
|
4174
|
+
if (!/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/u.test(holder.id)) return `Invocation ${preview(holder.id)} is not an invocation id; no child record is read.`;
|
|
3730
4175
|
const file = resolve(this.#options.root, this.#options.requests, CAPTURE_RUNS_DIRECTORY, holder.id, CAPTURE_SURVIVORS_FILE);
|
|
3731
4176
|
try {
|
|
3732
4177
|
const record = parseJSON(this.#options.ownership?.read === void 0 ? readFileSync(file, "utf8") : this.#options.ownership.read(file));
|
|
3733
4178
|
if (!isRecord(record) || record.pid !== holder.pid || record.id !== holder.id || typeof record.command !== "string" || record.command === "" || typeof record.at !== "string" || !Number.isFinite(Date.parse(record.at)) || !Array.isArray(record.children) || !record.children.every((pid) => typeof pid === "number" && Number.isSafeInteger(pid) && pid > 0)) return `Child record could not be read (EINVAL): ${file}.`;
|
|
3734
|
-
|
|
4179
|
+
const omitted = record.children.length - 16;
|
|
4180
|
+
return `Unconfirmed child processes: ${[...record.children.slice(0, 16), ...omitted > 0 ? [`… ${String(omitted)} more`] : []].join(", ")}; stop them before deleting. Child record: ${file}.`;
|
|
3735
4181
|
} catch (error) {
|
|
3736
4182
|
const code = error instanceof SyntaxError ? "EINVAL" : error instanceof Error && "code" in error ? String(error.code) : describeCaptureError(error);
|
|
3737
4183
|
return code === "ENOENT" ? `No child record exists at ${file}.` : `Child record could not be read (${code}): ${file}.`;
|
|
@@ -4004,14 +4450,14 @@ var CapturePreflight = class {
|
|
|
4004
4450
|
issues: [describeCaptureError(outcome.error)]
|
|
4005
4451
|
};
|
|
4006
4452
|
const artifact = outcome.value;
|
|
4007
|
-
const lines = artifact.text
|
|
4453
|
+
const lines = readCaptureArtifact(artifact.text);
|
|
4008
4454
|
return {
|
|
4009
4455
|
entry,
|
|
4010
4456
|
artifact,
|
|
4011
4457
|
issues: [
|
|
4012
4458
|
...artifact.run.passed.includes(location.value.case) && artifact.run.entries.some((emitted) => resolveCaptureKey(emitted) === resolveCaptureKey(entry)) ? [] : [`Judged record does not cover ${entry.file}: ${artifact.record}`],
|
|
4013
|
-
...lines.includes(
|
|
4014
|
-
...lines.includes(
|
|
4459
|
+
...lines.records.includes(artifact.record) ? [] : [`Judged journey artifact does not cover its record: ${artifact.file}`],
|
|
4460
|
+
...lines.cases.includes(location.value.case) ? [] : [`Judged journey artifact does not cover ${location.value.case}: ${artifact.file}`]
|
|
4015
4461
|
]
|
|
4016
4462
|
};
|
|
4017
4463
|
});
|
|
@@ -4078,7 +4524,8 @@ var CapturePreflight = class {
|
|
|
4078
4524
|
* requires, so it cannot stamp through the integrity engine. It reads the wrapper through the same
|
|
4079
4525
|
* discovery the runner uses, takes the same invocation entity, request file, and Vitest child, and runs
|
|
4080
4526
|
* every selected producing variant in one stage, one child that receives each variant's project, with
|
|
4081
|
-
* the `all` selector and no capture variable.
|
|
4527
|
+
* the `all` selector and no capture variable. The stage passes no tag filter, so it runs the whole
|
|
4528
|
+
* suite, which stands in for the consumer's complete test run. It reads the stage's reporter once and each variant's
|
|
4082
4529
|
* final record, takes each project's input population before and after, and builds one receipt per
|
|
4083
4530
|
* variant, all naming the one reporter, through `buildCaptureRegistry`. The registry is written to a
|
|
4084
4531
|
* candidate beside its target, read back through the integrity engine, and only then renamed into
|
|
@@ -4171,14 +4618,14 @@ var CaptureRegistrar = class {
|
|
|
4171
4618
|
});
|
|
4172
4619
|
this.#inherit(options);
|
|
4173
4620
|
const holders = invocation.holders();
|
|
4174
|
-
if (holders.length > 0) throw new CaptureError(
|
|
4621
|
+
if (holders.length > 0) throw new CaptureError(`${describeCaptureHolders(holders, this.#options.requests)}; the registry refresh starts only while no runner is mid-stage`, {
|
|
4175
4622
|
code: "STAGE",
|
|
4176
|
-
context: { holders }
|
|
4623
|
+
context: { holders: holders.map((holder) => holder.pid) }
|
|
4177
4624
|
});
|
|
4178
4625
|
const retained = parsed.variants.length === 0 ? [] : this.#retain(target, variants, declared);
|
|
4179
4626
|
if (retained.length > 0) buildCaptureRegistry(retained);
|
|
4180
4627
|
if (invocation.interrupted) return CAPTURE_EXIT.failed;
|
|
4181
|
-
const imports = await this.#stage(invocation, parsed,
|
|
4628
|
+
const imports = await this.#stage(invocation, parsed, primary, selected);
|
|
4182
4629
|
if (invocation.interrupted) return CAPTURE_EXIT.failed;
|
|
4183
4630
|
const registry = buildCaptureRegistry([...retained, ...imports]);
|
|
4184
4631
|
const path = resolve(root, candidate);
|
|
@@ -4218,9 +4665,8 @@ var CaptureRegistrar = class {
|
|
|
4218
4665
|
}
|
|
4219
4666
|
}
|
|
4220
4667
|
}
|
|
4221
|
-
async #stage(invocation, parsed,
|
|
4668
|
+
async #stage(invocation, parsed, primary, selected) {
|
|
4222
4669
|
const { root } = this.#options;
|
|
4223
|
-
const selectors = [...new Set(projects.flatMap((candidate) => candidate.tags))].filter((tag) => tag.startsWith(CAPTURE_OWNER_PREFIX)).map((tag) => tag.slice(CAPTURE_OWNER_PREFIX.length));
|
|
4224
4670
|
const stage = CAPTURE_REGISTRY_STAGE;
|
|
4225
4671
|
const variants = selected.map((project) => project.variant);
|
|
4226
4672
|
const reportFile = resolve(invocation.directory, `${stage}.json`);
|
|
@@ -4230,8 +4676,9 @@ var CaptureRegistrar = class {
|
|
|
4230
4676
|
entry: resolve(root, CAPTURE_VITEST_ENTRY),
|
|
4231
4677
|
config: parsed.config,
|
|
4232
4678
|
report: reportFile,
|
|
4679
|
+
progress: resolve(invocation.directory, `${stage}${CAPTURE_PROGRESS_SUFFIX}`),
|
|
4680
|
+
...parsed.bail === void 0 ? {} : { bail: parsed.bail },
|
|
4233
4681
|
projects: selected.map((project) => project.name),
|
|
4234
|
-
filter: buildCaptureFilter("journey", "all", selectors),
|
|
4235
4682
|
final: primary.final,
|
|
4236
4683
|
...parsed.mode === void 0 ? {} : { mode: parsed.mode }
|
|
4237
4684
|
});
|
|
@@ -4590,7 +5037,8 @@ var CaptureRunner = class {
|
|
|
4590
5037
|
final: primary.final,
|
|
4591
5038
|
directory: resolveCaptureRelative(root, primary.directory),
|
|
4592
5039
|
config: resolveCaptureRelative(root, parsed.config),
|
|
4593
|
-
...parsed.mode === void 0 ? {} : { mode: parsed.mode }
|
|
5040
|
+
...parsed.mode === void 0 ? {} : { mode: parsed.mode },
|
|
5041
|
+
...parsed.bail === void 0 ? {} : { bail: parsed.bail }
|
|
4594
5042
|
};
|
|
4595
5043
|
const outcomes = [];
|
|
4596
5044
|
const stages = resolveCaptureStages(variants, primary.first, command);
|
|
@@ -4632,6 +5080,8 @@ var CaptureRunner = class {
|
|
|
4632
5080
|
entry: resolve(root, CAPTURE_VITEST_ENTRY),
|
|
4633
5081
|
config: resolve(root, plan.config),
|
|
4634
5082
|
report,
|
|
5083
|
+
progress: resolve(invocation.directory, `${stage.name}${CAPTURE_PROGRESS_SUFFIX}`),
|
|
5084
|
+
...plan.bail === void 0 ? {} : { bail: plan.bail },
|
|
4635
5085
|
projects: selected.map((project) => project.name),
|
|
4636
5086
|
filter: plan.filter,
|
|
4637
5087
|
...plan.mode === void 0 ? {} : { mode: plan.mode },
|
|
@@ -4915,9 +5365,10 @@ var CaptureSheets = class {
|
|
|
4915
5365
|
*
|
|
4916
5366
|
* @remarks
|
|
4917
5367
|
* The executable's whole behaviour: it reads the subcommand, hands the rest of the command line to
|
|
4918
|
-
* the runner, the registry refresh, the preflight, or the contact sheets,
|
|
4919
|
-
*
|
|
4920
|
-
* writer. An error that is not a capture refusal
|
|
5368
|
+
* the runner, the registry refresh, the preflight, or the contact sheets, or prints the progress of
|
|
5369
|
+
* the stage that ran last, and turns a refused usage into exit 64 and any other capture refusal
|
|
5370
|
+
* into exit 1, writing the refusal to its error writer. An error that is not a capture refusal
|
|
5371
|
+
* propagates.
|
|
4921
5372
|
*
|
|
4922
5373
|
* @example
|
|
4923
5374
|
* ```ts
|
|
@@ -4969,6 +5420,13 @@ var CaptureCLI = class {
|
|
|
4969
5420
|
stdout: this.#stdout,
|
|
4970
5421
|
stderr: this.#stderr
|
|
4971
5422
|
}).execute();
|
|
5423
|
+
case "progress": {
|
|
5424
|
+
const usage = "Usage: capture progress";
|
|
5425
|
+
const { positionals } = readCaptureOptions(argv, CAPTURE_COMMAND_OPTIONS.progress, usage);
|
|
5426
|
+
if (positionals.length > 0) throw new CaptureError(`Unexpected argument ${JSON.stringify(positionals[0]?.slice(0, 80))}: the progress command takes no argument. ${usage}`, { code: "USAGE" });
|
|
5427
|
+
this.#stdout(`${renderCaptureProgress(readCaptureProgress(root, CAPTURE_DEFAULTS.requests))}\n`);
|
|
5428
|
+
return CAPTURE_EXIT.passed;
|
|
5429
|
+
}
|
|
4972
5430
|
case "preflight": {
|
|
4973
5431
|
const { reader } = readCaptureReaderArguments(argv, root, CAPTURE_DEFAULTS, "preflight");
|
|
4974
5432
|
return await new CapturePreflight({
|
|
@@ -5126,6 +5584,6 @@ function createCaptureRegistrar(options) {
|
|
|
5126
5584
|
function createCaptureCLI(options = {}) {
|
|
5127
5585
|
return new CaptureCLI(options);
|
|
5128
5586
|
}
|
|
5129
|
-
export { CAPTURE_COMMAND_NAMES, CAPTURE_COMMAND_OPTIONS, CAPTURE_DEFAULTS, CAPTURE_DISCOVERY, CAPTURE_EXIT, CAPTURE_FLAG, CAPTURE_FLAG_VALUE, CAPTURE_MESSAGE_LIMIT, CAPTURE_MINIMUM_IMAGE, CAPTURE_OWNER_BACKOFF, CAPTURE_OWNER_FILE,
|
|
5587
|
+
export { CAPTURE_COMMAND_NAMES, CAPTURE_COMMAND_OPTIONS, CAPTURE_DEFAULTS, CAPTURE_DISCOVERY, CAPTURE_EXIT, CAPTURE_FLAG, CAPTURE_FLAG_VALUE, CAPTURE_MESSAGE_LIMIT, CAPTURE_MINIMUM_IMAGE, CAPTURE_OWNER_BACKOFF, CAPTURE_OWNER_FILE, CAPTURE_OWNER_TIMEOUT, CAPTURE_PID_LIMIT, CAPTURE_PNG_LIMITS, CAPTURE_PROGRESS_SUFFIX, CAPTURE_REFUSAL_LIMIT, CAPTURE_REGISTRY_LINE, CAPTURE_REGISTRY_STAGE, CAPTURE_REPORT_LINES, CAPTURE_REQUESTS_FLAG, CAPTURE_RUNS_DIRECTORY, CAPTURE_SHEET, CAPTURE_SHEET_FILES, CAPTURE_STAGES, CAPTURE_SUBCOMMANDS, CAPTURE_SURVIVORS_FILE, CAPTURE_TAG_OPERATORS, CAPTURE_USAGE, CAPTURE_VITEST_ENTRY, CAPTURE_WRAPPER_PREFIXES, CaptureCLI, CaptureDiscovery, CaptureIntegrity, CaptureInvocation, CapturePreflight, CaptureRegistrar, CaptureRunner, CaptureSheets, answerCaptureDiscovery, buildCaptureArguments, buildCaptureChangePlan, buildCaptureDigest, buildCaptureDiscoveryConfig, buildCaptureFilter, buildCaptureIntegrityOptions, buildCaptureLookupJournal, buildCaptureOverride, buildCaptureRegistry, buildCaptureRequestRefusal, buildCaptureWrapper, collectCaptureErrors, collectCaptureIdentical, composeCapturePictures, computeCaptureHash, computeCaptureMatchKey, computeRegistryDigest, createCaptureCLI, createCaptureDiscovery, createCaptureIntegrity, createCapturePreflight, createCaptureRegistrar, createCaptureRunner, createCaptureSheets, decodeCapturePicture, describeCaptureFault, describeCaptureHolders, describeCaptureMembers, describeCaptureOutput, describeCapturePortfolios, describeCaptureSelectorFault, encodeCaptureChunk, encodeCapturePicture, encodeCaptureWord, escapeCapturePattern, filterCaptureInputs, inflateCaptureStream, matchesCaptureFile, matchesCaptureSignature, matchesCaptureTransient, mergeCaptureLookups, normalizeSlashes, predictCaptureByte, readCaptureAncestor, readCaptureArguments, readCaptureChunks, readCaptureDescription, readCaptureEntry, readCaptureFrames, readCaptureImage, readCaptureInputs, readCaptureListing, readCaptureLookups, readCaptureOptions, readCapturePortfolios, readCaptureProgress, readCaptureProject, readCaptureReaderArguments, readCaptureRegistryArguments, readCaptureRequest, readCaptureRequestOwner, readCaptureSeparator, readCaptureTitles, readCaptureVariants, readCaptureViewport, renderCaptureCommand, renderCaptureProgress, requireCaptureArgument, requireCaptureContained, requireCaptureImageSize, requireCaptureProjects, requireCaptureSelection, resolveCaptureExit, resolveCapturePhysical, resolveCaptureRelative, resolveCaptureRequests, resolveCaptureSheetIdentity, resolveCaptureStages, resolveCaptureVariants, resolveCaptureWrapperProject, scanCaptureFrames, settleCaptureShutdown, shrinkCapturePicture, splitCapturePages, unfilterCaptureRow, writeCaptureDocument };
|
|
5130
5588
|
|
|
5131
5589
|
//# sourceMappingURL=index.js.map
|