@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/core/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INTRINSICS, arrayOf, holds, isError, isFiniteNumber, isFunction, isObject, isRecord, isString } from "@orkestrel/contract";
|
|
1
|
+
import { INTRINSICS, arrayOf, holds, isError, isFiniteNumber, isFunction, isObject, isRecord, isString, preview } from "@orkestrel/contract";
|
|
2
2
|
// src/core/constants.ts
|
|
3
3
|
/**
|
|
4
4
|
* Lists the condition axes a capture failure carries, in the order the executable reports them.
|
|
@@ -119,6 +119,31 @@ var CAPTURE_MANIFEST_FILE = "manifest.json";
|
|
|
119
119
|
* ```
|
|
120
120
|
*/
|
|
121
121
|
var CAPTURE_LOOKUPS_FILE = "lookups.json";
|
|
122
|
+
/**
|
|
123
|
+
* Names the tag prefix that marks a case's owner path and each ancestor of it.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* `${CAPTURE_OWNER_PREFIX}pages:mail` // 'owner:pages:mail'
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
var CAPTURE_OWNER_PREFIX = "owner:";
|
|
131
|
+
/**
|
|
132
|
+
* Names the journey artifact line prefixes that bind a run record and each case that ran.
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* The preflight reader requires the line `record=<record path>` and one `case-ran=<full name>`
|
|
136
|
+
* line for each stamping case.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* `${CAPTURE_ARTIFACT_PREFIXES.case}mail opens the inbox` // 'case-ran=mail opens the inbox'
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
var CAPTURE_ARTIFACT_PREFIXES = Object.freeze({
|
|
144
|
+
record: "record=",
|
|
145
|
+
case: "case-ran="
|
|
146
|
+
});
|
|
122
147
|
// src/core/errors.ts
|
|
123
148
|
/**
|
|
124
149
|
* Reports one capture failure under a stable condition axis.
|
|
@@ -870,8 +895,8 @@ function readCaptureReport(value) {
|
|
|
870
895
|
}));
|
|
871
896
|
requireCaptureUnique(assertions.map(resolveLookupKey), "reporter case identities");
|
|
872
897
|
return {
|
|
873
|
-
start:
|
|
874
|
-
end:
|
|
898
|
+
start: files.reduce((start, file) => Math.min(start, file.start), value.startTime),
|
|
899
|
+
end: files.reduce((end, file) => Math.max(end, file.end), -Infinity),
|
|
875
900
|
assertions
|
|
876
901
|
};
|
|
877
902
|
}
|
|
@@ -985,6 +1010,353 @@ function validateCaptureReceipt(receipt, report) {
|
|
|
985
1010
|
}
|
|
986
1011
|
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" });
|
|
987
1012
|
}
|
|
988
|
-
|
|
1013
|
+
/**
|
|
1014
|
+
* Expands an owner path into its prefixes, from its scope through the owner itself.
|
|
1015
|
+
*
|
|
1016
|
+
* @param owner - A canonical owner path
|
|
1017
|
+
* @returns Each colon-bounded prefix, shortest first
|
|
1018
|
+
*
|
|
1019
|
+
* @example
|
|
1020
|
+
* ```ts
|
|
1021
|
+
* collectCaptureAncestors('pages:mail:inbox') // ['pages', 'pages:mail', 'pages:mail:inbox']
|
|
1022
|
+
* ```
|
|
1023
|
+
*/
|
|
1024
|
+
function collectCaptureAncestors(owner) {
|
|
1025
|
+
return owner.split(":").map((_part, index, parts) => parts.slice(0, index + 1).join(":"));
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Builds the owner and capture tags a wrapper declares for its owner population.
|
|
1029
|
+
*
|
|
1030
|
+
* @param owners - Every canonical owner path the host declares
|
|
1031
|
+
* @returns The unique `owner:` tag of each owner and ancestor, and each owner's scope and part tags
|
|
1032
|
+
* @throws Thrown as a `HOST` capture error naming each owner that is not a canonical selector.
|
|
1033
|
+
*
|
|
1034
|
+
* @example
|
|
1035
|
+
* ```ts
|
|
1036
|
+
* buildCaptureTags(['pages:mail'])
|
|
1037
|
+
* // ['owner:pages', 'owner:pages:mail', 'pages', 'pages:mail']
|
|
1038
|
+
* ```
|
|
1039
|
+
*/
|
|
1040
|
+
function buildCaptureTags(owners) {
|
|
1041
|
+
const invalid = owners.filter((owner) => !isCaptureSelector(owner));
|
|
1042
|
+
if (invalid.length > 0) throw new CaptureError(`Invalid capture owners: ${invalid.map((owner) => preview(owner)).join(", ")}; expected colon-separated portable segments such as "pages:mail"`, {
|
|
1043
|
+
code: "HOST",
|
|
1044
|
+
context: { owners: invalid }
|
|
1045
|
+
});
|
|
1046
|
+
return [...new Set(owners.flatMap((owner) => [...collectCaptureAncestors(owner).map((path) => `${CAPTURE_OWNER_PREFIX}${path}`), ...collectCaptureAncestors(owner).slice(0, 2)]))];
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Builds the Vitest test options of one capture case from its declaration.
|
|
1050
|
+
*
|
|
1051
|
+
* @param input - The case's owner, states, producing variant, and harness values
|
|
1052
|
+
* @param rules - The host's owners and part resolver
|
|
1053
|
+
* @returns The derived tags, the capture metadata, and the optional timeout
|
|
1054
|
+
* @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.
|
|
1055
|
+
*
|
|
1056
|
+
* @example
|
|
1057
|
+
* ```ts
|
|
1058
|
+
* buildCaptureTest({ owner: 'pages:mail', states: ['inbox'], variant: 'light-390' }, rules).tags
|
|
1059
|
+
* // ['owner:pages', 'owner:pages:mail', 'pages', 'pages:mail']
|
|
1060
|
+
* ```
|
|
1061
|
+
*/
|
|
1062
|
+
function buildCaptureTest(input, rules) {
|
|
1063
|
+
const declared = buildCaptureTags(rules.owners);
|
|
1064
|
+
const owner = input.owner;
|
|
1065
|
+
if (owner !== void 0 && !declared.includes(`owner:${owner}`)) throw new CaptureError(`Unknown capture owner: ${preview(owner)}; expected a declared owner path or one of its ancestors`, {
|
|
1066
|
+
code: "HOST",
|
|
1067
|
+
context: { owner }
|
|
1068
|
+
});
|
|
1069
|
+
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`, {
|
|
1070
|
+
code: "HOST",
|
|
1071
|
+
context: { owner }
|
|
1072
|
+
});
|
|
1073
|
+
const unknown = (input.tags ?? []).filter((tag) => !declared.includes(tag));
|
|
1074
|
+
if (unknown.length > 0) throw new CaptureError(`Unknown capture tags: ${unknown.map((tag) => preview(tag)).join(", ")}; expected tags the owners declare`, {
|
|
1075
|
+
code: "HOST",
|
|
1076
|
+
context: { tags: unknown }
|
|
1077
|
+
});
|
|
1078
|
+
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" });
|
|
1079
|
+
const parts = (input.states ?? []).map((state) => {
|
|
1080
|
+
const part = rules.part(state);
|
|
1081
|
+
if (!declared.includes(`owner:${part}`)) throw new CaptureError(`Capture state ${state} resolves to an undeclared owner: ${preview(part)}`, {
|
|
1082
|
+
code: "HOST",
|
|
1083
|
+
context: {
|
|
1084
|
+
state,
|
|
1085
|
+
part
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
if (owner !== void 0 && !matchesCaptureSelector(part, owner)) throw new CaptureError(`Capture state ${state} belongs to ${part}, outside owner ${owner}; split the case by owner`, {
|
|
1089
|
+
code: "HOST",
|
|
1090
|
+
context: {
|
|
1091
|
+
state,
|
|
1092
|
+
part,
|
|
1093
|
+
owner
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
return part;
|
|
1097
|
+
});
|
|
1098
|
+
return {
|
|
1099
|
+
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))])],
|
|
1100
|
+
meta: {
|
|
1101
|
+
...input.owner === void 0 ? {} : { owner: input.owner },
|
|
1102
|
+
...input.states === void 0 ? {} : { states: [...input.states] },
|
|
1103
|
+
variant: input.variant,
|
|
1104
|
+
...input.eligible === void 0 ? {} : { eligible: input.eligible }
|
|
1105
|
+
},
|
|
1106
|
+
...input.timeout === void 0 ? {} : { timeout: input.timeout }
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Collects every leaf case under a task, keeping cases a runner filter excluded and their results.
|
|
1111
|
+
*
|
|
1112
|
+
* @param task - A Vitest file, suite, or test task
|
|
1113
|
+
* @param ancestors - The titles of the suites that enclose the task, excluding the file name. Default: none
|
|
1114
|
+
* @returns Each case with its suite titles and own title joined by spaces, as the Vitest JSON reporter names it
|
|
1115
|
+
*
|
|
1116
|
+
* @example
|
|
1117
|
+
* ```ts
|
|
1118
|
+
* collectCaptureCases({ name: 'mail', mode: 'run', meta: {}, tasks: [inbox] })[0]?.name
|
|
1119
|
+
* // 'mail opens the inbox'
|
|
1120
|
+
* ```
|
|
1121
|
+
*/
|
|
1122
|
+
function collectCaptureCases(task, ancestors = []) {
|
|
1123
|
+
const names = task.filepath === void 0 ? [...ancestors, task.name] : ancestors;
|
|
1124
|
+
if (task.tasks !== void 0) return task.tasks.flatMap((child) => collectCaptureCases(child, names));
|
|
1125
|
+
return [{
|
|
1126
|
+
name: names.join(" "),
|
|
1127
|
+
mode: task.mode,
|
|
1128
|
+
tags: [...task.tags ?? []],
|
|
1129
|
+
meta: {
|
|
1130
|
+
...task.meta.owner === void 0 ? {} : { owner: task.meta.owner },
|
|
1131
|
+
...task.meta.states === void 0 ? {} : { states: [...task.meta.states] },
|
|
1132
|
+
...task.meta.variant === void 0 ? {} : { variant: task.meta.variant },
|
|
1133
|
+
...task.meta.eligible === void 0 ? {} : { eligible: task.meta.eligible }
|
|
1134
|
+
},
|
|
1135
|
+
...task.result === void 0 ? {} : { result: {
|
|
1136
|
+
state: task.result.state,
|
|
1137
|
+
...task.result.duration === void 0 ? {} : { duration: task.result.duration }
|
|
1138
|
+
} }
|
|
1139
|
+
}];
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Refuses a selection whose cases place states owned outside the selected owner.
|
|
1143
|
+
*
|
|
1144
|
+
* @param cases - Every collected case, including cases a runner filter excluded
|
|
1145
|
+
* @param rules - The host's owners and part resolver
|
|
1146
|
+
* @param selection - The runner's selection, absent when no runner is the parent
|
|
1147
|
+
* @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.
|
|
1148
|
+
*
|
|
1149
|
+
* @example
|
|
1150
|
+
* ```ts
|
|
1151
|
+
* requireCaptureCases(cases, rules, { selector: 'pages:mail' }) // returns when no case is parked
|
|
1152
|
+
* ```
|
|
1153
|
+
*/
|
|
1154
|
+
function requireCaptureCases(cases, rules, selection) {
|
|
1155
|
+
if (selection === void 0 || selection.selector === "all") return;
|
|
1156
|
+
const { selector } = selection;
|
|
1157
|
+
if (!buildCaptureTags(rules.owners).includes(`owner:${selector}`)) throw new CaptureError(`Unknown capture selector: ${preview(selector)}; expected all or a declared owner path`, {
|
|
1158
|
+
code: "SELECTION",
|
|
1159
|
+
context: { selector }
|
|
1160
|
+
});
|
|
1161
|
+
const parked = cases.filter((entry) => selection.case === void 0 || entry.name === selection.case).flatMap((entry) => {
|
|
1162
|
+
const owner = entry.meta.owner;
|
|
1163
|
+
if (owner === void 0 || matchesCaptureSelector(owner, selector)) return [];
|
|
1164
|
+
const states = (entry.meta.states ?? []).filter((state) => matchesCaptureSelector(rules.part(state), selector));
|
|
1165
|
+
return states.length > 0 ? [`${entry.name}: owner ${owner}; foreign states ${states.join(", ")}`] : [];
|
|
1166
|
+
});
|
|
1167
|
+
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")}`, {
|
|
1168
|
+
code: "HOST",
|
|
1169
|
+
context: {
|
|
1170
|
+
selector,
|
|
1171
|
+
parked
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Builds the required output pair of each state an eligible owner-bearing case declares.
|
|
1177
|
+
*
|
|
1178
|
+
* @param cases - Every collected case, including cases a runner filter excluded
|
|
1179
|
+
* @param rules - The host's part and source resolvers
|
|
1180
|
+
* @param options - The producing project and the portfolio mapping of each state
|
|
1181
|
+
* @returns One destination per declared state, in case and state order
|
|
1182
|
+
* @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.
|
|
1183
|
+
*
|
|
1184
|
+
* @example
|
|
1185
|
+
* ```ts
|
|
1186
|
+
* buildCaptureDestinations(cases, rules, { project: 'journey:light-390', portfolios })[0]?.file
|
|
1187
|
+
* // 'tmp/captures/states/pages/inbox--light-390.png'
|
|
1188
|
+
* ```
|
|
1189
|
+
*/
|
|
1190
|
+
function buildCaptureDestinations(cases, rules, options) {
|
|
1191
|
+
return cases.flatMap((entry) => {
|
|
1192
|
+
const declared = entry.meta.owner;
|
|
1193
|
+
if (declared === void 0 || entry.meta.eligible === false) return [];
|
|
1194
|
+
return (entry.meta.states ?? []).map((state) => {
|
|
1195
|
+
const mappings = options.portfolios.filter((portfolio) => portfolio.states.includes(state));
|
|
1196
|
+
const [mapping] = mappings;
|
|
1197
|
+
if (mapping === void 0 || mappings.length > 1) throw new CaptureError(`Capture state ${state} needs exactly one portfolio mapping; mapped by: ${mappings.map((candidate) => preview(candidate.portfolio)).join(", ") || "none"}`, {
|
|
1198
|
+
code: "HOST",
|
|
1199
|
+
context: { state }
|
|
1200
|
+
});
|
|
1201
|
+
const owner = rules.part(state);
|
|
1202
|
+
if (!matchesCaptureSelector(owner, declared)) throw new CaptureError(`Capture state ${state} belongs to ${owner}, outside owner ${declared} of ${entry.name}`, {
|
|
1203
|
+
code: "HOST",
|
|
1204
|
+
context: {
|
|
1205
|
+
state,
|
|
1206
|
+
owner,
|
|
1207
|
+
declared
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
const [scope, part, section, ...rest] = owner.split(":");
|
|
1211
|
+
if (scope === void 0 || part === void 0 || rest.length > 0) throw new CaptureError(`Capture state ${state} resolves to ${preview(owner)}; expected scope:part or scope:part:section`, {
|
|
1212
|
+
code: "HOST",
|
|
1213
|
+
context: {
|
|
1214
|
+
state,
|
|
1215
|
+
owner
|
|
1216
|
+
}
|
|
1217
|
+
});
|
|
1218
|
+
return {
|
|
1219
|
+
portfolio: mapping.portfolio,
|
|
1220
|
+
state,
|
|
1221
|
+
scope,
|
|
1222
|
+
part,
|
|
1223
|
+
...section === void 0 ? {} : { section },
|
|
1224
|
+
variant: mapping.variant,
|
|
1225
|
+
project: options.project,
|
|
1226
|
+
file: `${mapping.directory}/${mapping.scoped ? `${scope}/` : ""}${state}--${mapping.variant}.png`,
|
|
1227
|
+
case: entry.name,
|
|
1228
|
+
sources: rules.sources(owner)
|
|
1229
|
+
};
|
|
1230
|
+
});
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Builds a run record from collected cases, the run's destinations, and its observed and emitted states.
|
|
1235
|
+
*
|
|
1236
|
+
* @param options - The cases, registry, observed states, emitted state-to-path pairs, and execution context
|
|
1237
|
+
* @returns The final record, without the journey artifact the caller binds after rendering it
|
|
1238
|
+
* @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.
|
|
1239
|
+
*
|
|
1240
|
+
* @example
|
|
1241
|
+
* ```ts
|
|
1242
|
+
* const run = buildCaptureRun({ cases, registry, observed, emitted, variant: 'light-390', time })
|
|
1243
|
+
* validateCaptureRun(run, readCaptureReport(parseJSON(text)), 'journey:light-390')
|
|
1244
|
+
* ```
|
|
1245
|
+
*/
|
|
1246
|
+
function buildCaptureRun(options) {
|
|
1247
|
+
const declarations = options.cases.flatMap((entry) => {
|
|
1248
|
+
const { owner, variant } = entry.meta;
|
|
1249
|
+
if (owner === void 0) return [];
|
|
1250
|
+
if (variant === void 0) throw new CaptureError(`Owner-bearing case declares no variant: ${entry.name}`, { code: "HOST" });
|
|
1251
|
+
return [{
|
|
1252
|
+
case: entry.name,
|
|
1253
|
+
owner,
|
|
1254
|
+
variant,
|
|
1255
|
+
eligible: entry.meta.eligible !== false,
|
|
1256
|
+
states: [...entry.meta.states ?? []]
|
|
1257
|
+
}];
|
|
1258
|
+
});
|
|
1259
|
+
const passed = declarations.filter((declaration) => declaration.eligible && options.cases.some((entry) => entry.name === declaration.case && entry.result?.state === "pass")).map((declaration) => declaration.case);
|
|
1260
|
+
const entries = options.emitted.map(([state, path]) => {
|
|
1261
|
+
const destination = options.registry.find((entry) => entry.state === state);
|
|
1262
|
+
if (destination === void 0) throw new CaptureError(`Emitted state has no registry destination: ${preview(state)}`, {
|
|
1263
|
+
code: "EVIDENCE",
|
|
1264
|
+
context: { state }
|
|
1265
|
+
});
|
|
1266
|
+
const written = path.replaceAll("\\", "/");
|
|
1267
|
+
if (written !== destination.file && !written.endsWith(`/${destination.file}`)) throw new CaptureError(`Emitted state ${state} was written at ${preview(path)}, not at its destination ${destination.file}`, {
|
|
1268
|
+
code: "EVIDENCE",
|
|
1269
|
+
context: {
|
|
1270
|
+
state,
|
|
1271
|
+
path,
|
|
1272
|
+
file: destination.file
|
|
1273
|
+
}
|
|
1274
|
+
});
|
|
1275
|
+
const duration = options.cases.find((entry) => entry.name === destination.case)?.result?.duration;
|
|
1276
|
+
if (duration === void 0) throw new CaptureError(`Emitting case has no measured duration: ${destination.case}`, {
|
|
1277
|
+
code: "EVIDENCE",
|
|
1278
|
+
context: {
|
|
1279
|
+
state,
|
|
1280
|
+
case: destination.case
|
|
1281
|
+
}
|
|
1282
|
+
});
|
|
1283
|
+
return {
|
|
1284
|
+
...destination,
|
|
1285
|
+
duration
|
|
1286
|
+
};
|
|
1287
|
+
});
|
|
1288
|
+
const eligible = declarations.filter((declaration) => declaration.eligible);
|
|
1289
|
+
const reference = options.registry.filter((entry) => entry.section === entry.state);
|
|
1290
|
+
const request = options.request;
|
|
1291
|
+
return {
|
|
1292
|
+
version: 1,
|
|
1293
|
+
...request === void 0 ? {} : {
|
|
1294
|
+
identity: {
|
|
1295
|
+
id: request.id,
|
|
1296
|
+
stage: request.stage,
|
|
1297
|
+
pid: request.pid,
|
|
1298
|
+
config: request.config
|
|
1299
|
+
},
|
|
1300
|
+
request
|
|
1301
|
+
},
|
|
1302
|
+
variant: options.variant,
|
|
1303
|
+
time: options.time,
|
|
1304
|
+
complete: eligible.length > 0 && eligible.every((entry) => passed.includes(entry.case)),
|
|
1305
|
+
reference: reference.length > 0 && reference.every((entry) => passed.includes(entry.case)),
|
|
1306
|
+
declarations,
|
|
1307
|
+
registry: [...options.registry],
|
|
1308
|
+
passed,
|
|
1309
|
+
observed: [...options.observed],
|
|
1310
|
+
entries
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1314
|
+
* Renders the journey artifact lines that bind a run record and each case that passed in it.
|
|
1315
|
+
*
|
|
1316
|
+
* @param record - The run record's portable path
|
|
1317
|
+
* @param run - The run whose passed cases the artifact names
|
|
1318
|
+
* @returns The `record=` line, then one `case-ran=` line per passed case, without line endings
|
|
1319
|
+
* @throws Thrown as an `EVIDENCE` capture error for a record path that is not portable or a case name that holds a line break.
|
|
1320
|
+
*
|
|
1321
|
+
* @example
|
|
1322
|
+
* ```ts
|
|
1323
|
+
* renderCaptureArtifact('tmp/captures/states/runs/run-1/selected/light-390.json', {
|
|
1324
|
+
* passed: ['mail opens the inbox'],
|
|
1325
|
+
* })
|
|
1326
|
+
* // ['record=tmp/captures/states/runs/run-1/selected/light-390.json', 'case-ran=mail opens the inbox']
|
|
1327
|
+
* ```
|
|
1328
|
+
*/
|
|
1329
|
+
function renderCaptureArtifact(record, run) {
|
|
1330
|
+
if (!isCapturePath(record)) throw new CaptureError(`Artifact record path is not a portable relative path: ${preview(record)}`, {
|
|
1331
|
+
code: "EVIDENCE",
|
|
1332
|
+
context: { record }
|
|
1333
|
+
});
|
|
1334
|
+
const broken = run.passed.filter((name) => /[\r\n]/u.test(name));
|
|
1335
|
+
if (broken.length > 0) throw new CaptureError(`Artifact cannot carry case names with line breaks: ${broken.map((name) => preview(name)).join(", ")}`, {
|
|
1336
|
+
code: "EVIDENCE",
|
|
1337
|
+
context: { cases: broken }
|
|
1338
|
+
});
|
|
1339
|
+
return [`${CAPTURE_ARTIFACT_PREFIXES.record}${record}`, ...run.passed.map((name) => `${CAPTURE_ARTIFACT_PREFIXES.case}${name}`)];
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* Reads the record bindings and the ran cases from a journey artifact's text.
|
|
1343
|
+
*
|
|
1344
|
+
* @param text - The artifact text, with LF or CRLF line endings
|
|
1345
|
+
* @returns The path of each `record=` line and the full name of each `case-ran=` line, in text order
|
|
1346
|
+
*
|
|
1347
|
+
* @example
|
|
1348
|
+
* ```ts
|
|
1349
|
+
* readCaptureArtifact('# light-390\r\nrecord=tmp/run.json\r\ncase-ran=mail opens the inbox\r\n')
|
|
1350
|
+
* // { records: ['tmp/run.json'], cases: ['mail opens the inbox'] }
|
|
1351
|
+
* ```
|
|
1352
|
+
*/
|
|
1353
|
+
function readCaptureArtifact(text) {
|
|
1354
|
+
const lines = text.split(/\r\n|\n/u);
|
|
1355
|
+
return {
|
|
1356
|
+
records: lines.filter((line) => line.startsWith(CAPTURE_ARTIFACT_PREFIXES.record)).map((line) => line.slice(CAPTURE_ARTIFACT_PREFIXES.record.length)),
|
|
1357
|
+
cases: lines.filter((line) => line.startsWith(CAPTURE_ARTIFACT_PREFIXES.case)).map((line) => line.slice(CAPTURE_ARTIFACT_PREFIXES.case.length))
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
export { CAPTURE_ARTIFACT_PREFIXES, CAPTURE_ERROR_BRAND, CAPTURE_ERROR_CODES, CAPTURE_LOOKUPS_FILE, CAPTURE_MANIFEST_FILE, CAPTURE_OWNER_PREFIX, CAPTURE_PNG_SIGNATURE, CAPTURE_REGISTRY_FILE, CAPTURE_REQUEST_PREFIX, CAPTURE_STATUS_PRECEDENCE, CAPTURE_VERSION, CaptureError, buildCaptureDestinations, buildCaptureRun, buildCaptureTags, buildCaptureTest, collectCaptureAncestors, collectCaptureCases, collectCaptureChanges, collectCaptureDuplicates, describeCaptureDeclaration, describeCaptureDestination, describeCaptureError, describeCaptureIdentity, describeCaptureRequest, isCaptureArtifact, isCaptureBox, isCaptureCollection, isCaptureDeclaration, isCaptureDestination, isCaptureDigest, isCaptureEntry, isCaptureError, isCaptureGeometry, isCaptureHash, isCaptureHashes, isCaptureIdentity, isCaptureLookup, isCaptureLookupJournal, isCaptureManifest, isCapturePath, isCapturePattern, isCaptureReceipt, isCaptureRegistry, isCaptureRequest, isCaptureRun, isCaptureSegment, isCaptureSelector, isCaptureSources, isCaptureStamp, isCaptureStoredManifest, matchesCaptureMembers, matchesCaptureSelector, readCaptureArtifact, readCaptureDirty, readCaptureReport, renderCaptureArtifact, requireCaptureCases, requireCaptureUnique, resolveCaptureKey, resolveCaptureOwner, resolveCaptureStatus, resolveLookupKey, validateCaptureReceipt, validateCaptureRun };
|
|
989
1361
|
|
|
990
1362
|
//# sourceMappingURL=index.js.map
|