@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/README.md
CHANGED
|
@@ -16,18 +16,19 @@ npm install -D @orkestrel/capture
|
|
|
16
16
|
|
|
17
17
|
The manifest declares these peer ranges; install the browser peers when you run browser journeys:
|
|
18
18
|
|
|
19
|
-
| Peer | Range
|
|
20
|
-
| ---------------------------- |
|
|
21
|
-
| `vitest` | `^
|
|
22
|
-
| `vite` | `^8.3.
|
|
23
|
-
| `@vitest/browser-playwright` | `^
|
|
24
|
-
| `playwright` | `^1.
|
|
19
|
+
| Peer | Range | Required by the manifest |
|
|
20
|
+
| ---------------------------- | --------- | ------------------------ |
|
|
21
|
+
| `vitest` | `^5.1.0` | Yes |
|
|
22
|
+
| `vite` | `^8.3.8` | Yes |
|
|
23
|
+
| `@vitest/browser-playwright` | `^5.0.5` | Optional |
|
|
24
|
+
| `playwright` | `^1.65.0` | Optional |
|
|
25
|
+
| `@orkestrel/test` | `~0.0.41` | Yes |
|
|
25
26
|
|
|
26
27
|
## Requirements
|
|
27
28
|
|
|
28
29
|
The CLI workflow requires the following host setup:
|
|
29
30
|
|
|
30
|
-
- Node.js
|
|
31
|
+
- Node.js `^22.18.0 || >=24.4.0`.
|
|
31
32
|
- A Git workspace with a commit and locally installed Vitest.
|
|
32
33
|
- A Vitest browser provider and its browser runtime for execution stages. The integration proof uses
|
|
33
34
|
`@vitest/browser-playwright` and Chromium.
|
|
@@ -60,22 +61,23 @@ contact sheets. Preflight and sheets report `acceptance: false`; they provide it
|
|
|
60
61
|
|
|
61
62
|
## Commands
|
|
62
63
|
|
|
63
|
-
Every command accepts `--config <file>`. The principal selection and output flags are as follows:
|
|
64
|
+
Every command but `progress` accepts `--config <file>`. The principal selection and output flags are as follows:
|
|
64
65
|
|
|
65
|
-
| Command | Flags and behavior
|
|
66
|
-
| ------------------------------------------------ |
|
|
67
|
-
| `capture registry` | `--variant <name>` repeats to refresh selected producing variants; `--mode <name>` selects the wrapper's mode. Takes no selector.
|
|
68
|
-
| `capture journey <selector>` | `--variant <name>` repeats; `--case <full name>` selects an exact case; `--mode <name>` selects the wrapper mode. Use `--changed <ref>` instead of the selector, with optional `--plan`. |
|
|
69
|
-
| `capture frames <selector>` | Journey flags plus `--state <name>` to resolve a state through fresh passing lookup evidence; `--mode <name>` selects the wrapper mode.
|
|
70
|
-
| `capture stale <selector>` | `--variant <name>` repeats; `--case <full name>`, `--state <name>`, `--portfolio <name>`, and `--mode <name>` narrow the freshness reading.
|
|
71
|
-
| `capture preflight <selector>` | Stale flags plus `--mode <name>`, `--journeys <directory>` for artifacts, and `--checks <module>` for the host's `CAPTURE_CHECKS` export.
|
|
72
|
-
| `capture sheets <selector> --output <directory>` | Preflight flags, including `--mode <name>`, plus required `--output <directory>` for a new contained directory outside selected captures.
|
|
66
|
+
| Command | Flags and behavior |
|
|
67
|
+
| ------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
68
|
+
| `capture registry` | `--variant <name>` repeats to refresh selected producing variants; `--no-bail` runs every case after a failure; `--mode <name>` selects the wrapper's mode. Takes no selector. |
|
|
69
|
+
| `capture journey <selector>` | `--variant <name>` repeats; `--case <full name>` selects an exact case; `--no-bail` runs every selected case after a failure; `--mode <name>` selects the wrapper mode. Use `--changed <ref>` instead of the selector, with optional `--plan`. |
|
|
70
|
+
| `capture frames <selector>` | Journey flags plus `--state <name>` to resolve a state through fresh passing lookup evidence; `--mode <name>` selects the wrapper mode. |
|
|
71
|
+
| `capture stale <selector>` | `--variant <name>` repeats; `--case <full name>`, `--state <name>`, `--portfolio <name>`, and `--mode <name>` narrow the freshness reading. |
|
|
72
|
+
| `capture preflight <selector>` | Stale flags plus `--mode <name>`, `--journeys <directory>` for artifacts, and `--checks <module>` for the host's `CAPTURE_CHECKS` export. |
|
|
73
|
+
| `capture sheets <selector> --output <directory>` | Preflight flags, including `--mode <name>`, plus required `--output <directory>` for a new contained directory outside selected captures. |
|
|
74
|
+
| `capture progress` | Takes no argument. Prints the cases done against the cases known, the failures, the case running, and the time elapsed, from the progress file of the stage that is running or that ran last. |
|
|
73
75
|
|
|
74
76
|
`--mode <name>` is available on every command that reads the wrapper. It reaches discovery and execution children and wrapper project factories; omission keeps Vitest's default mode.
|
|
75
77
|
|
|
76
78
|
A selector is `all` or a declared colon-separated owner path. Only `--variant` repeats. Every
|
|
77
|
-
flag except `--plan` takes a nonempty value as `--flag value` or `--flag=value`; a
|
|
78
|
-
with a dash needs equals form. The CLI refuses the `--` terminator and repeated single-value flags.
|
|
79
|
+
flag except `--plan` and `--no-bail` takes a nonempty value as `--flag value` or `--flag=value`; a
|
|
80
|
+
value beginning with a dash needs equals form. The CLI refuses the `--` terminator and repeated single-value flags.
|
|
79
81
|
|
|
80
82
|
Registry refresh checks inherited manifest and lookup journal schemas before starting a stage.
|
|
81
83
|
An unreadable or unsupported document refuses the refresh and names the file to inspect and repair.
|
|
@@ -106,6 +108,9 @@ parent PID, process arguments, wrapper path, and project declarations. When the
|
|
|
106
108
|
return `buildCaptureDiscoveryConfig()` so discovery starts no browser or test. For an execution
|
|
107
109
|
child, read `readCaptureRequest` with the same parent, arguments, and wrapper identity plus the
|
|
108
110
|
declared owners and variants. The runner passes the request directory through `CAPTURE_REQUESTS`.
|
|
111
|
+
`buildCaptureWrapper` from `@orkestrel/capture/server` performs these steps from the host's
|
|
112
|
+
declarations, provides each project the following values except `standalone`, and mounts the progress plugin the
|
|
113
|
+
`capture progress` command reads.
|
|
109
114
|
|
|
110
115
|
Each project's `test.provide` object supplies the following host declarations:
|
|
111
116
|
|
|
@@ -116,9 +121,10 @@ Each project's `test.provide` object supplies the following host declarations:
|
|
|
116
121
|
| `final` | The exact final case name that persists the run record, including under exact-case selection. |
|
|
117
122
|
| `directory`, `record` | The primary evidence directory and the project's declared record path. Stage records bind the request's invocation, stage, and variant. |
|
|
118
123
|
| `inputs` | Bounded native glob patterns for the input snapshot. |
|
|
124
|
+
| `sources` | The `shared` and `tests` source patterns the suite attributes to every destination. |
|
|
119
125
|
| `portfolios` | Authorized portfolio roots with their `portfolio`, `directory`, and `scoped` declarations. |
|
|
120
126
|
| `uniform` | Optional owner selectors for mixed-framing checks. Omission checks every scope; an empty list checks none. |
|
|
121
|
-
| `standalone` | Optional portfolio roots with no stamping route through this wrapper.
|
|
127
|
+
| `standalone` | Optional portfolio roots with no stamping route through this wrapper. `buildCaptureWrapper` provides no standalone roots. |
|
|
122
128
|
|
|
123
129
|
Declare `owner:` tags for owners and their ancestors, and capture tags for the scopes and parts
|
|
124
130
|
that produce frames. Projects must agree on shared host declarations. The final case must retain
|
package/dist/src/core/index.cjs
CHANGED
|
@@ -120,6 +120,31 @@ var CAPTURE_MANIFEST_FILE = "manifest.json";
|
|
|
120
120
|
* ```
|
|
121
121
|
*/
|
|
122
122
|
var CAPTURE_LOOKUPS_FILE = "lookups.json";
|
|
123
|
+
/**
|
|
124
|
+
* Names the tag prefix that marks a case's owner path and each ancestor of it.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* `${CAPTURE_OWNER_PREFIX}pages:mail` // 'owner:pages:mail'
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
var CAPTURE_OWNER_PREFIX = "owner:";
|
|
132
|
+
/**
|
|
133
|
+
* Names the journey artifact line prefixes that bind a run record and each case that ran.
|
|
134
|
+
*
|
|
135
|
+
* @remarks
|
|
136
|
+
* The preflight reader requires the line `record=<record path>` and one `case-ran=<full name>`
|
|
137
|
+
* line for each stamping case.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* `${CAPTURE_ARTIFACT_PREFIXES.case}mail opens the inbox` // 'case-ran=mail opens the inbox'
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
var CAPTURE_ARTIFACT_PREFIXES = Object.freeze({
|
|
145
|
+
record: "record=",
|
|
146
|
+
case: "case-ran="
|
|
147
|
+
});
|
|
123
148
|
// src/core/errors.ts
|
|
124
149
|
/**
|
|
125
150
|
* Reports one capture failure under a stable condition axis.
|
|
@@ -871,8 +896,8 @@ function readCaptureReport(value) {
|
|
|
871
896
|
}));
|
|
872
897
|
requireCaptureUnique(assertions.map(resolveLookupKey), "reporter case identities");
|
|
873
898
|
return {
|
|
874
|
-
start:
|
|
875
|
-
end:
|
|
899
|
+
start: files.reduce((start, file) => Math.min(start, file.start), value.startTime),
|
|
900
|
+
end: files.reduce((end, file) => Math.max(end, file.end), -Infinity),
|
|
876
901
|
assertions
|
|
877
902
|
};
|
|
878
903
|
}
|
|
@@ -986,16 +1011,371 @@ function validateCaptureReceipt(receipt, report) {
|
|
|
986
1011
|
}
|
|
987
1012
|
if (receipt.registry.some((entry) => !eligible.some((declaration) => declaration.case === entry.case)) || new Set(receipt.registry.map((entry) => entry.project)).size > 1) throw new CaptureError("Registry receipt contains an undeclared output or mixes producing projects", { code: "EVIDENCE" });
|
|
988
1013
|
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Expands an owner path into its prefixes, from its scope through the owner itself.
|
|
1016
|
+
*
|
|
1017
|
+
* @param owner - A canonical owner path
|
|
1018
|
+
* @returns Each colon-bounded prefix, shortest first
|
|
1019
|
+
*
|
|
1020
|
+
* @example
|
|
1021
|
+
* ```ts
|
|
1022
|
+
* collectCaptureAncestors('pages:mail:inbox') // ['pages', 'pages:mail', 'pages:mail:inbox']
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
1025
|
+
function collectCaptureAncestors(owner) {
|
|
1026
|
+
return owner.split(":").map((_part, index, parts) => parts.slice(0, index + 1).join(":"));
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Builds the owner and capture tags a wrapper declares for its owner population.
|
|
1030
|
+
*
|
|
1031
|
+
* @param owners - Every canonical owner path the host declares
|
|
1032
|
+
* @returns The unique `owner:` tag of each owner and ancestor, and each owner's scope and part tags
|
|
1033
|
+
* @throws Thrown as a `HOST` capture error naming each owner that is not a canonical selector.
|
|
1034
|
+
*
|
|
1035
|
+
* @example
|
|
1036
|
+
* ```ts
|
|
1037
|
+
* buildCaptureTags(['pages:mail'])
|
|
1038
|
+
* // ['owner:pages', 'owner:pages:mail', 'pages', 'pages:mail']
|
|
1039
|
+
* ```
|
|
1040
|
+
*/
|
|
1041
|
+
function buildCaptureTags(owners) {
|
|
1042
|
+
const invalid = owners.filter((owner) => !isCaptureSelector(owner));
|
|
1043
|
+
if (invalid.length > 0) throw new CaptureError(`Invalid capture owners: ${invalid.map((owner) => (0, _orkestrel_contract.preview)(owner)).join(", ")}; expected colon-separated portable segments such as "pages:mail"`, {
|
|
1044
|
+
code: "HOST",
|
|
1045
|
+
context: { owners: invalid }
|
|
1046
|
+
});
|
|
1047
|
+
return [...new Set(owners.flatMap((owner) => [...collectCaptureAncestors(owner).map((path) => `${CAPTURE_OWNER_PREFIX}${path}`), ...collectCaptureAncestors(owner).slice(0, 2)]))];
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Builds the Vitest test options of one capture case from its declaration.
|
|
1051
|
+
*
|
|
1052
|
+
* @param input - The case's owner, states, producing variant, and harness values
|
|
1053
|
+
* @param rules - The host's owners and part resolver
|
|
1054
|
+
* @returns The derived tags, the capture metadata, and the optional timeout
|
|
1055
|
+
* @throws Thrown as a `HOST` capture error for an undeclared owner or tag, tags beside an owner, capture tags with no states, or a state whose part is undeclared or outside the owner.
|
|
1056
|
+
*
|
|
1057
|
+
* @example
|
|
1058
|
+
* ```ts
|
|
1059
|
+
* buildCaptureTest({ owner: 'pages:mail', states: ['inbox'], variant: 'light-390' }, rules).tags
|
|
1060
|
+
* // ['owner:pages', 'owner:pages:mail', 'pages', 'pages:mail']
|
|
1061
|
+
* ```
|
|
1062
|
+
*/
|
|
1063
|
+
function buildCaptureTest(input, rules) {
|
|
1064
|
+
const declared = buildCaptureTags(rules.owners);
|
|
1065
|
+
const owner = input.owner;
|
|
1066
|
+
if (owner !== void 0 && !declared.includes(`owner:${owner}`)) throw new CaptureError(`Unknown capture owner: ${(0, _orkestrel_contract.preview)(owner)}; expected a declared owner path or one of its ancestors`, {
|
|
1067
|
+
code: "HOST",
|
|
1068
|
+
context: { owner }
|
|
1069
|
+
});
|
|
1070
|
+
if (owner !== void 0 && input.tags !== void 0) throw new CaptureError(`Capture case owned by ${owner} derives its tags from its owner and states; remove its tags`, {
|
|
1071
|
+
code: "HOST",
|
|
1072
|
+
context: { owner }
|
|
1073
|
+
});
|
|
1074
|
+
const unknown = (input.tags ?? []).filter((tag) => !declared.includes(tag));
|
|
1075
|
+
if (unknown.length > 0) throw new CaptureError(`Unknown capture tags: ${unknown.map((tag) => (0, _orkestrel_contract.preview)(tag)).join(", ")}; expected tags the owners declare`, {
|
|
1076
|
+
code: "HOST",
|
|
1077
|
+
context: { tags: unknown }
|
|
1078
|
+
});
|
|
1079
|
+
if (input.states === void 0 && (input.tags ?? []).some((tag) => !tag.startsWith("owner:"))) throw new CaptureError("Capture case names capture tags but declares no states; declare its states, an empty list included", { code: "HOST" });
|
|
1080
|
+
const parts = (input.states ?? []).map((state) => {
|
|
1081
|
+
const part = rules.part(state);
|
|
1082
|
+
if (!declared.includes(`owner:${part}`)) throw new CaptureError(`Capture state ${state} resolves to an undeclared owner: ${(0, _orkestrel_contract.preview)(part)}`, {
|
|
1083
|
+
code: "HOST",
|
|
1084
|
+
context: {
|
|
1085
|
+
state,
|
|
1086
|
+
part
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1089
|
+
if (owner !== void 0 && !matchesCaptureSelector(part, owner)) throw new CaptureError(`Capture state ${state} belongs to ${part}, outside owner ${owner}; split the case by owner`, {
|
|
1090
|
+
code: "HOST",
|
|
1091
|
+
context: {
|
|
1092
|
+
state,
|
|
1093
|
+
part,
|
|
1094
|
+
owner
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
return part;
|
|
1098
|
+
});
|
|
1099
|
+
return {
|
|
1100
|
+
tags: [.../* @__PURE__ */ new Set([...input.owner === void 0 ? input.tags ?? [] : collectCaptureAncestors(input.owner).map((path) => `${CAPTURE_OWNER_PREFIX}${path}`), ...parts.flatMap((part) => collectCaptureAncestors(part).slice(0, 2))])],
|
|
1101
|
+
meta: {
|
|
1102
|
+
...input.owner === void 0 ? {} : { owner: input.owner },
|
|
1103
|
+
...input.states === void 0 ? {} : { states: [...input.states] },
|
|
1104
|
+
variant: input.variant,
|
|
1105
|
+
...input.eligible === void 0 ? {} : { eligible: input.eligible }
|
|
1106
|
+
},
|
|
1107
|
+
...input.timeout === void 0 ? {} : { timeout: input.timeout }
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Collects every leaf case under a task, keeping cases a runner filter excluded and their results.
|
|
1112
|
+
*
|
|
1113
|
+
* @param task - A Vitest file, suite, or test task
|
|
1114
|
+
* @param ancestors - The titles of the suites that enclose the task, excluding the file name. Default: none
|
|
1115
|
+
* @returns Each case with its suite titles and own title joined by spaces, as the Vitest JSON reporter names it
|
|
1116
|
+
*
|
|
1117
|
+
* @example
|
|
1118
|
+
* ```ts
|
|
1119
|
+
* collectCaptureCases({ name: 'mail', mode: 'run', meta: {}, tasks: [inbox] })[0]?.name
|
|
1120
|
+
* // 'mail opens the inbox'
|
|
1121
|
+
* ```
|
|
1122
|
+
*/
|
|
1123
|
+
function collectCaptureCases(task, ancestors = []) {
|
|
1124
|
+
const names = task.filepath === void 0 ? [...ancestors, task.name] : ancestors;
|
|
1125
|
+
if (task.tasks !== void 0) return task.tasks.flatMap((child) => collectCaptureCases(child, names));
|
|
1126
|
+
return [{
|
|
1127
|
+
name: names.join(" "),
|
|
1128
|
+
mode: task.mode,
|
|
1129
|
+
tags: [...task.tags ?? []],
|
|
1130
|
+
meta: {
|
|
1131
|
+
...task.meta.owner === void 0 ? {} : { owner: task.meta.owner },
|
|
1132
|
+
...task.meta.states === void 0 ? {} : { states: [...task.meta.states] },
|
|
1133
|
+
...task.meta.variant === void 0 ? {} : { variant: task.meta.variant },
|
|
1134
|
+
...task.meta.eligible === void 0 ? {} : { eligible: task.meta.eligible }
|
|
1135
|
+
},
|
|
1136
|
+
...task.result === void 0 ? {} : { result: {
|
|
1137
|
+
state: task.result.state,
|
|
1138
|
+
...task.result.duration === void 0 ? {} : { duration: task.result.duration }
|
|
1139
|
+
} }
|
|
1140
|
+
}];
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Refuses a selection whose cases place states owned outside the selected owner.
|
|
1144
|
+
*
|
|
1145
|
+
* @param cases - Every collected case, including cases a runner filter excluded
|
|
1146
|
+
* @param rules - The host's owners and part resolver
|
|
1147
|
+
* @param selection - The runner's selection, absent when no runner is the parent
|
|
1148
|
+
* @throws Thrown as a `SELECTION` capture error for an undeclared selector, and as a `HOST` capture error naming each case that places a selected state from outside the selected owner.
|
|
1149
|
+
*
|
|
1150
|
+
* @example
|
|
1151
|
+
* ```ts
|
|
1152
|
+
* requireCaptureCases(cases, rules, { selector: 'pages:mail' }) // returns when no case is parked
|
|
1153
|
+
* ```
|
|
1154
|
+
*/
|
|
1155
|
+
function requireCaptureCases(cases, rules, selection) {
|
|
1156
|
+
if (selection === void 0 || selection.selector === "all") return;
|
|
1157
|
+
const { selector } = selection;
|
|
1158
|
+
if (!buildCaptureTags(rules.owners).includes(`owner:${selector}`)) throw new CaptureError(`Unknown capture selector: ${(0, _orkestrel_contract.preview)(selector)}; expected all or a declared owner path`, {
|
|
1159
|
+
code: "SELECTION",
|
|
1160
|
+
context: { selector }
|
|
1161
|
+
});
|
|
1162
|
+
const parked = cases.filter((entry) => selection.case === void 0 || entry.name === selection.case).flatMap((entry) => {
|
|
1163
|
+
const owner = entry.meta.owner;
|
|
1164
|
+
if (owner === void 0 || matchesCaptureSelector(owner, selector)) return [];
|
|
1165
|
+
const states = (entry.meta.states ?? []).filter((state) => matchesCaptureSelector(rules.part(state), selector));
|
|
1166
|
+
return states.length > 0 ? [`${entry.name}: owner ${owner}; foreign states ${states.join(", ")}`] : [];
|
|
1167
|
+
});
|
|
1168
|
+
if (parked.length > 0) throw new CaptureError(`Capture selection ${selector} is parked; split each case so its states stay inside its owner:\n${parked.join("\n")}`, {
|
|
1169
|
+
code: "HOST",
|
|
1170
|
+
context: {
|
|
1171
|
+
selector,
|
|
1172
|
+
parked
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Builds the required output pair of each state an eligible owner-bearing case declares.
|
|
1178
|
+
*
|
|
1179
|
+
* @param cases - Every collected case, including cases a runner filter excluded
|
|
1180
|
+
* @param rules - The host's part and source resolvers
|
|
1181
|
+
* @param options - The producing project and the portfolio mapping of each state
|
|
1182
|
+
* @returns One destination per declared state, in case and state order
|
|
1183
|
+
* @throws Thrown as a `HOST` capture error when a state has no single mapping or resolves outside its case's owner or the scope, part, and optional section form.
|
|
1184
|
+
*
|
|
1185
|
+
* @example
|
|
1186
|
+
* ```ts
|
|
1187
|
+
* buildCaptureDestinations(cases, rules, { project: 'journey:light-390', portfolios })[0]?.file
|
|
1188
|
+
* // 'tmp/captures/states/pages/inbox--light-390.png'
|
|
1189
|
+
* ```
|
|
1190
|
+
*/
|
|
1191
|
+
function buildCaptureDestinations(cases, rules, options) {
|
|
1192
|
+
return cases.flatMap((entry) => {
|
|
1193
|
+
const declared = entry.meta.owner;
|
|
1194
|
+
if (declared === void 0 || entry.meta.eligible === false) return [];
|
|
1195
|
+
return (entry.meta.states ?? []).map((state) => {
|
|
1196
|
+
const mappings = options.portfolios.filter((portfolio) => portfolio.states.includes(state));
|
|
1197
|
+
const [mapping] = mappings;
|
|
1198
|
+
if (mapping === void 0 || mappings.length > 1) throw new CaptureError(`Capture state ${state} needs exactly one portfolio mapping; mapped by: ${mappings.map((candidate) => (0, _orkestrel_contract.preview)(candidate.portfolio)).join(", ") || "none"}`, {
|
|
1199
|
+
code: "HOST",
|
|
1200
|
+
context: { state }
|
|
1201
|
+
});
|
|
1202
|
+
const owner = rules.part(state);
|
|
1203
|
+
if (!matchesCaptureSelector(owner, declared)) throw new CaptureError(`Capture state ${state} belongs to ${owner}, outside owner ${declared} of ${entry.name}`, {
|
|
1204
|
+
code: "HOST",
|
|
1205
|
+
context: {
|
|
1206
|
+
state,
|
|
1207
|
+
owner,
|
|
1208
|
+
declared
|
|
1209
|
+
}
|
|
1210
|
+
});
|
|
1211
|
+
const [scope, part, section, ...rest] = owner.split(":");
|
|
1212
|
+
if (scope === void 0 || part === void 0 || rest.length > 0) throw new CaptureError(`Capture state ${state} resolves to ${(0, _orkestrel_contract.preview)(owner)}; expected scope:part or scope:part:section`, {
|
|
1213
|
+
code: "HOST",
|
|
1214
|
+
context: {
|
|
1215
|
+
state,
|
|
1216
|
+
owner
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1219
|
+
return {
|
|
1220
|
+
portfolio: mapping.portfolio,
|
|
1221
|
+
state,
|
|
1222
|
+
scope,
|
|
1223
|
+
part,
|
|
1224
|
+
...section === void 0 ? {} : { section },
|
|
1225
|
+
variant: mapping.variant,
|
|
1226
|
+
project: options.project,
|
|
1227
|
+
file: `${mapping.directory}/${mapping.scoped ? `${scope}/` : ""}${state}--${mapping.variant}.png`,
|
|
1228
|
+
case: entry.name,
|
|
1229
|
+
sources: rules.sources(owner)
|
|
1230
|
+
};
|
|
1231
|
+
});
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Builds a run record from collected cases, the run's destinations, and its observed and emitted states.
|
|
1236
|
+
*
|
|
1237
|
+
* @param options - The cases, registry, observed states, emitted state-to-path pairs, and execution context
|
|
1238
|
+
* @returns The final record, without the journey artifact the caller binds after rendering it
|
|
1239
|
+
* @throws Thrown as a `HOST` capture error for an owner-bearing case with no variant, and as an `EVIDENCE` capture error for an emitted state with no destination, a path other than its destination's file, or a producing case with no measured duration.
|
|
1240
|
+
*
|
|
1241
|
+
* @example
|
|
1242
|
+
* ```ts
|
|
1243
|
+
* const run = buildCaptureRun({ cases, registry, observed, emitted, variant: 'light-390', time })
|
|
1244
|
+
* validateCaptureRun(run, readCaptureReport(parseJSON(text)), 'journey:light-390')
|
|
1245
|
+
* ```
|
|
1246
|
+
*/
|
|
1247
|
+
function buildCaptureRun(options) {
|
|
1248
|
+
const declarations = options.cases.flatMap((entry) => {
|
|
1249
|
+
const { owner, variant } = entry.meta;
|
|
1250
|
+
if (owner === void 0) return [];
|
|
1251
|
+
if (variant === void 0) throw new CaptureError(`Owner-bearing case declares no variant: ${entry.name}`, { code: "HOST" });
|
|
1252
|
+
return [{
|
|
1253
|
+
case: entry.name,
|
|
1254
|
+
owner,
|
|
1255
|
+
variant,
|
|
1256
|
+
eligible: entry.meta.eligible !== false,
|
|
1257
|
+
states: [...entry.meta.states ?? []]
|
|
1258
|
+
}];
|
|
1259
|
+
});
|
|
1260
|
+
const passed = declarations.filter((declaration) => declaration.eligible && options.cases.some((entry) => entry.name === declaration.case && entry.result?.state === "pass")).map((declaration) => declaration.case);
|
|
1261
|
+
const entries = options.emitted.map(([state, path]) => {
|
|
1262
|
+
const destination = options.registry.find((entry) => entry.state === state);
|
|
1263
|
+
if (destination === void 0) throw new CaptureError(`Emitted state has no registry destination: ${(0, _orkestrel_contract.preview)(state)}`, {
|
|
1264
|
+
code: "EVIDENCE",
|
|
1265
|
+
context: { state }
|
|
1266
|
+
});
|
|
1267
|
+
const written = path.replaceAll("\\", "/");
|
|
1268
|
+
if (written !== destination.file && !written.endsWith(`/${destination.file}`)) throw new CaptureError(`Emitted state ${state} was written at ${(0, _orkestrel_contract.preview)(path)}, not at its destination ${destination.file}`, {
|
|
1269
|
+
code: "EVIDENCE",
|
|
1270
|
+
context: {
|
|
1271
|
+
state,
|
|
1272
|
+
path,
|
|
1273
|
+
file: destination.file
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
const duration = options.cases.find((entry) => entry.name === destination.case)?.result?.duration;
|
|
1277
|
+
if (duration === void 0) throw new CaptureError(`Emitting case has no measured duration: ${destination.case}`, {
|
|
1278
|
+
code: "EVIDENCE",
|
|
1279
|
+
context: {
|
|
1280
|
+
state,
|
|
1281
|
+
case: destination.case
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
return {
|
|
1285
|
+
...destination,
|
|
1286
|
+
duration
|
|
1287
|
+
};
|
|
1288
|
+
});
|
|
1289
|
+
const eligible = declarations.filter((declaration) => declaration.eligible);
|
|
1290
|
+
const reference = options.registry.filter((entry) => entry.section === entry.state);
|
|
1291
|
+
const request = options.request;
|
|
1292
|
+
return {
|
|
1293
|
+
version: 1,
|
|
1294
|
+
...request === void 0 ? {} : {
|
|
1295
|
+
identity: {
|
|
1296
|
+
id: request.id,
|
|
1297
|
+
stage: request.stage,
|
|
1298
|
+
pid: request.pid,
|
|
1299
|
+
config: request.config
|
|
1300
|
+
},
|
|
1301
|
+
request
|
|
1302
|
+
},
|
|
1303
|
+
variant: options.variant,
|
|
1304
|
+
time: options.time,
|
|
1305
|
+
complete: eligible.length > 0 && eligible.every((entry) => passed.includes(entry.case)),
|
|
1306
|
+
reference: reference.length > 0 && reference.every((entry) => passed.includes(entry.case)),
|
|
1307
|
+
declarations,
|
|
1308
|
+
registry: [...options.registry],
|
|
1309
|
+
passed,
|
|
1310
|
+
observed: [...options.observed],
|
|
1311
|
+
entries
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Renders the journey artifact lines that bind a run record and each case that passed in it.
|
|
1316
|
+
*
|
|
1317
|
+
* @param record - The run record's portable path
|
|
1318
|
+
* @param run - The run whose passed cases the artifact names
|
|
1319
|
+
* @returns The `record=` line, then one `case-ran=` line per passed case, without line endings
|
|
1320
|
+
* @throws Thrown as an `EVIDENCE` capture error for a record path that is not portable or a case name that holds a line break.
|
|
1321
|
+
*
|
|
1322
|
+
* @example
|
|
1323
|
+
* ```ts
|
|
1324
|
+
* renderCaptureArtifact('tmp/captures/states/runs/run-1/selected/light-390.json', {
|
|
1325
|
+
* passed: ['mail opens the inbox'],
|
|
1326
|
+
* })
|
|
1327
|
+
* // ['record=tmp/captures/states/runs/run-1/selected/light-390.json', 'case-ran=mail opens the inbox']
|
|
1328
|
+
* ```
|
|
1329
|
+
*/
|
|
1330
|
+
function renderCaptureArtifact(record, run) {
|
|
1331
|
+
if (!isCapturePath(record)) throw new CaptureError(`Artifact record path is not a portable relative path: ${(0, _orkestrel_contract.preview)(record)}`, {
|
|
1332
|
+
code: "EVIDENCE",
|
|
1333
|
+
context: { record }
|
|
1334
|
+
});
|
|
1335
|
+
const broken = run.passed.filter((name) => /[\r\n]/u.test(name));
|
|
1336
|
+
if (broken.length > 0) throw new CaptureError(`Artifact cannot carry case names with line breaks: ${broken.map((name) => (0, _orkestrel_contract.preview)(name)).join(", ")}`, {
|
|
1337
|
+
code: "EVIDENCE",
|
|
1338
|
+
context: { cases: broken }
|
|
1339
|
+
});
|
|
1340
|
+
return [`${CAPTURE_ARTIFACT_PREFIXES.record}${record}`, ...run.passed.map((name) => `${CAPTURE_ARTIFACT_PREFIXES.case}${name}`)];
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Reads the record bindings and the ran cases from a journey artifact's text.
|
|
1344
|
+
*
|
|
1345
|
+
* @param text - The artifact text, with LF or CRLF line endings
|
|
1346
|
+
* @returns The path of each `record=` line and the full name of each `case-ran=` line, in text order
|
|
1347
|
+
*
|
|
1348
|
+
* @example
|
|
1349
|
+
* ```ts
|
|
1350
|
+
* readCaptureArtifact('# light-390\r\nrecord=tmp/run.json\r\ncase-ran=mail opens the inbox\r\n')
|
|
1351
|
+
* // { records: ['tmp/run.json'], cases: ['mail opens the inbox'] }
|
|
1352
|
+
* ```
|
|
1353
|
+
*/
|
|
1354
|
+
function readCaptureArtifact(text) {
|
|
1355
|
+
const lines = text.split(/\r\n|\n/u);
|
|
1356
|
+
return {
|
|
1357
|
+
records: lines.filter((line) => line.startsWith(CAPTURE_ARTIFACT_PREFIXES.record)).map((line) => line.slice(CAPTURE_ARTIFACT_PREFIXES.record.length)),
|
|
1358
|
+
cases: lines.filter((line) => line.startsWith(CAPTURE_ARTIFACT_PREFIXES.case)).map((line) => line.slice(CAPTURE_ARTIFACT_PREFIXES.case.length))
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
exports.CAPTURE_ARTIFACT_PREFIXES = CAPTURE_ARTIFACT_PREFIXES;
|
|
989
1362
|
exports.CAPTURE_ERROR_BRAND = CAPTURE_ERROR_BRAND;
|
|
990
1363
|
exports.CAPTURE_ERROR_CODES = CAPTURE_ERROR_CODES;
|
|
991
1364
|
exports.CAPTURE_LOOKUPS_FILE = CAPTURE_LOOKUPS_FILE;
|
|
992
1365
|
exports.CAPTURE_MANIFEST_FILE = CAPTURE_MANIFEST_FILE;
|
|
1366
|
+
exports.CAPTURE_OWNER_PREFIX = CAPTURE_OWNER_PREFIX;
|
|
993
1367
|
exports.CAPTURE_PNG_SIGNATURE = CAPTURE_PNG_SIGNATURE;
|
|
994
1368
|
exports.CAPTURE_REGISTRY_FILE = CAPTURE_REGISTRY_FILE;
|
|
995
1369
|
exports.CAPTURE_REQUEST_PREFIX = CAPTURE_REQUEST_PREFIX;
|
|
996
1370
|
exports.CAPTURE_STATUS_PRECEDENCE = CAPTURE_STATUS_PRECEDENCE;
|
|
997
1371
|
exports.CAPTURE_VERSION = CAPTURE_VERSION;
|
|
998
1372
|
exports.CaptureError = CaptureError;
|
|
1373
|
+
exports.buildCaptureDestinations = buildCaptureDestinations;
|
|
1374
|
+
exports.buildCaptureRun = buildCaptureRun;
|
|
1375
|
+
exports.buildCaptureTags = buildCaptureTags;
|
|
1376
|
+
exports.buildCaptureTest = buildCaptureTest;
|
|
1377
|
+
exports.collectCaptureAncestors = collectCaptureAncestors;
|
|
1378
|
+
exports.collectCaptureCases = collectCaptureCases;
|
|
999
1379
|
exports.collectCaptureChanges = collectCaptureChanges;
|
|
1000
1380
|
exports.collectCaptureDuplicates = collectCaptureDuplicates;
|
|
1001
1381
|
exports.describeCaptureDeclaration = describeCaptureDeclaration;
|
|
@@ -1031,8 +1411,11 @@ exports.isCaptureStamp = isCaptureStamp;
|
|
|
1031
1411
|
exports.isCaptureStoredManifest = isCaptureStoredManifest;
|
|
1032
1412
|
exports.matchesCaptureMembers = matchesCaptureMembers;
|
|
1033
1413
|
exports.matchesCaptureSelector = matchesCaptureSelector;
|
|
1414
|
+
exports.readCaptureArtifact = readCaptureArtifact;
|
|
1034
1415
|
exports.readCaptureDirty = readCaptureDirty;
|
|
1035
1416
|
exports.readCaptureReport = readCaptureReport;
|
|
1417
|
+
exports.renderCaptureArtifact = renderCaptureArtifact;
|
|
1418
|
+
exports.requireCaptureCases = requireCaptureCases;
|
|
1036
1419
|
exports.requireCaptureUnique = requireCaptureUnique;
|
|
1037
1420
|
exports.resolveCaptureKey = resolveCaptureKey;
|
|
1038
1421
|
exports.resolveCaptureOwner = resolveCaptureOwner;
|