@docsxai/engine 0.2.1-rc.1 → 0.3.0-rc.1
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 +18 -5
- package/dist/address-class.d.ts +14 -0
- package/dist/address-class.js +151 -0
- package/dist/auth/api-login.d.ts +3 -3
- package/dist/auth/email-otp.d.ts +60 -60
- package/dist/auth/jwt-injection.d.ts +45 -45
- package/dist/auth/pat-header.d.ts +2 -2
- package/dist/auth/types.d.ts +2 -2
- package/dist/auth/ui-form.d.ts +54 -54
- package/dist/auth/webauthn.d.ts +22 -22
- package/dist/backend-client-contracts.d.ts +4 -2
- package/dist/calibrate.d.ts +2 -2
- package/dist/calibrate.js +5 -0
- package/dist/cli-commands-authoring.js +23 -4
- package/dist/cli-commands-backend.js +2 -2
- package/dist/cli-commands-docpack.d.ts +5 -0
- package/dist/cli-commands-docpack.js +70 -24
- package/dist/cli-commands-pack.d.ts +2 -0
- package/dist/cli-commands-pack.js +69 -0
- package/dist/cli-commands-session.js +92 -89
- package/dist/cli-retired.d.ts +6 -0
- package/dist/cli-retired.js +12 -0
- package/dist/cli-usage.d.ts +1 -1
- package/dist/cli-usage.js +52 -4
- package/dist/cli-verify.d.ts +14 -0
- package/dist/cli-verify.js +54 -0
- package/dist/cli.js +14 -1
- package/dist/deprecation.d.ts +19 -0
- package/dist/deprecation.js +32 -0
- package/dist/diagnose.d.ts +25 -0
- package/dist/diagnose.js +69 -3
- package/dist/diff-compute.js +1 -0
- package/dist/doc-pack-io.d.ts +14 -0
- package/dist/doc-pack-io.js +121 -14
- package/dist/doc-pack.d.ts +2282 -387
- package/dist/doc-pack.js +135 -43
- package/dist/doctor-checks.d.ts +1 -1
- package/dist/doctor-checks.js +25 -1
- package/dist/driver-budget.d.ts +6 -0
- package/dist/driver-budget.js +15 -0
- package/dist/egress-guard.d.ts +58 -0
- package/dist/egress-guard.js +136 -0
- package/dist/environment-spec.d.ts +67 -0
- package/dist/environment-spec.js +38 -0
- package/dist/export/playwright-test.js +42 -10
- package/dist/flow-file.d.ts +9 -3
- package/dist/flow-file.js +21 -1
- package/dist/flow-halt.d.ts +16 -0
- package/dist/flow-halt.js +76 -0
- package/dist/flow-hidden.d.ts +9 -0
- package/dist/flow-hidden.js +20 -0
- package/dist/flow-lint.js +91 -1
- package/dist/flow-matrix-lint.d.ts +10 -0
- package/dist/flow-matrix-lint.js +40 -0
- package/dist/flow-matrix.d.ts +44 -0
- package/dist/flow-matrix.js +238 -0
- package/dist/flow-name-rules.d.ts +15 -0
- package/dist/flow-name-rules.js +39 -0
- package/dist/flow-runtime.d.ts +52 -22
- package/dist/flow-runtime.js +63 -117
- package/dist/flow-success.d.ts +3 -0
- package/dist/flow-success.js +37 -0
- package/dist/flow-tree.d.ts +2 -0
- package/dist/flow-tree.js +17 -5
- package/dist/flow-wait.d.ts +3 -0
- package/dist/flow-wait.js +22 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/matrix-spec.d.ts +145 -0
- package/dist/matrix-spec.js +120 -0
- package/dist/page-hide.d.ts +10 -0
- package/dist/page-hide.js +45 -0
- package/dist/page-settle.d.ts +39 -0
- package/dist/page-settle.js +142 -0
- package/dist/playwright-driver.d.ts +28 -8
- package/dist/playwright-driver.js +73 -28
- package/dist/plugins/manifest.d.ts +9 -9
- package/dist/run-flows.d.ts +40 -0
- package/dist/run-flows.js +129 -0
- package/dist/style.d.ts +2 -2
- package/dist/upload-path.d.ts +15 -0
- package/dist/upload-path.js +63 -0
- package/dist/verify-compare.d.ts +43 -0
- package/dist/verify-compare.js +237 -0
- package/dist/verify-determinism.d.ts +16 -0
- package/dist/verify-determinism.js +88 -0
- package/dist/verify-report.d.ts +53 -0
- package/dist/verify-report.js +141 -0
- package/dist/verify-tree.d.ts +27 -0
- package/dist/verify-tree.js +95 -0
- package/dist/viewer-bin.d.ts +6 -0
- package/dist/viewer-bin.js +24 -0
- package/dist/zip.d.ts +2 -2
- package/package.json +3 -2
package/dist/flow-runtime.js
CHANGED
|
@@ -8,60 +8,16 @@
|
|
|
8
8
|
// The runtime is written against a thin {@link BrowserDriver} abstraction so it's testable
|
|
9
9
|
// without a real browser; the Playwright-backed driver lives in a separate module.
|
|
10
10
|
import { locatorRefName } from "./flow-file.js";
|
|
11
|
+
import { FlowExecutionError, inferHaltCause } from "./flow-halt.js";
|
|
12
|
+
import { pickCopy, variantDocDir } from "./flow-matrix.js";
|
|
13
|
+
import { checkSuccess } from "./flow-success.js";
|
|
14
|
+
import { applyWait } from "./flow-wait.js";
|
|
11
15
|
import { OBSTACLE_RADIUS, selectObstacles } from "./obstacles.js";
|
|
12
16
|
// ---------------------------------------------------------------------------
|
|
13
17
|
// Errors
|
|
14
18
|
// ---------------------------------------------------------------------------
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
cause;
|
|
18
|
-
constructor(message, stepId, cause) {
|
|
19
|
-
super(message);
|
|
20
|
-
this.stepId = stepId;
|
|
21
|
-
this.cause = cause;
|
|
22
|
-
this.name = "FlowExecutionError";
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Best-effort 1-line cause extracted from a Playwright actionability log (or similar driver
|
|
27
|
-
* error). Returns undefined when nothing matches — keeps the halt message short rather than
|
|
28
|
-
* guessing. Surfaced as a `[cause]` prefix on the halt message so the agent doesn't have to
|
|
29
|
-
* scan the multi-line actionability log.
|
|
30
|
-
*/
|
|
31
|
-
export function inferHaltCause(rawError) {
|
|
32
|
-
const hints = [
|
|
33
|
-
[/element is disabled\b/i, "target is disabled"],
|
|
34
|
-
[/element is not enabled\b/i, "target is not enabled"],
|
|
35
|
-
[
|
|
36
|
-
/element is not visible\b/i,
|
|
37
|
-
"target is not visible (display:none / visibility:hidden / zero-sized)",
|
|
38
|
-
],
|
|
39
|
-
[
|
|
40
|
-
/element is not attached\b/i,
|
|
41
|
-
"target was detached from the DOM (likely unmounted by an earlier action)",
|
|
42
|
-
],
|
|
43
|
-
[/element is outside of the viewport\b/i, "target is outside the visible viewport"],
|
|
44
|
-
[/element is not stable\b/i, "target is animating / not yet stable"],
|
|
45
|
-
[/intercepts? pointer events\b/i, "target is covered by another element"],
|
|
46
|
-
[
|
|
47
|
-
/strict mode violation\b/i,
|
|
48
|
-
"selector matched multiple elements (strict-mode violation) — scope with :visible / :nth-match",
|
|
49
|
-
],
|
|
50
|
-
[
|
|
51
|
-
/timeout .* exceeded.*waiting for/is,
|
|
52
|
-
"timeout waiting for selector — element didn't appear in time (consider raising timeout_ms or revisiting the locator)",
|
|
53
|
-
],
|
|
54
|
-
];
|
|
55
|
-
for (const [re, msg] of hints) {
|
|
56
|
-
if (re.test(rawError))
|
|
57
|
-
return msg;
|
|
58
|
-
}
|
|
59
|
-
const resolved = rawError.match(/locator resolved to (<[^>\n]*>)/);
|
|
60
|
-
if (resolved)
|
|
61
|
-
return `target resolved to ${resolved[1]}`;
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
const defaultScreenshotPath = (flow, stepId) => `docs/${flow}/screenshots/${stepId}.png`;
|
|
19
|
+
export { FlowExecutionError, inferHaltCause } from "./flow-halt.js";
|
|
20
|
+
const defaultScreenshotPath = (flow, stepId, variant) => `${variantDocDir(flow, variant)}/screenshots/${stepId}.png`;
|
|
65
21
|
/** Resolve a `target` value (`$name` ref or inline selector) using the flow-file's locators (or a custom resolver). */
|
|
66
22
|
export function resolveTarget(value, flow, resolver) {
|
|
67
23
|
const name = locatorRefName(value);
|
|
@@ -74,64 +30,24 @@ export function resolveTarget(value, flow, resolver) {
|
|
|
74
30
|
return resolved;
|
|
75
31
|
}
|
|
76
32
|
/** Obstacles around `selector`, best-effort like the halo box: a failed scan leaves the field off. */
|
|
77
|
-
async function obstaclesAround(driver, selector, target, stepId) {
|
|
33
|
+
async function obstaclesAround(driver, selector, target, stepId, placement) {
|
|
34
|
+
if (!driver.nearbyBoxes)
|
|
35
|
+
return [];
|
|
36
|
+
const radius = placement?.obstacle_radius ?? OBSTACLE_RADIUS;
|
|
78
37
|
try {
|
|
79
|
-
const scan = await driver.nearbyBoxes(selector,
|
|
80
|
-
return scan
|
|
38
|
+
const scan = await driver.nearbyBoxes(selector, radius, 2000);
|
|
39
|
+
return scan
|
|
40
|
+
? selectObstacles(scan, target, {
|
|
41
|
+
radius,
|
|
42
|
+
...(placement?.obstacle_limit !== undefined ? { limit: placement.obstacle_limit } : {}),
|
|
43
|
+
})
|
|
44
|
+
: [];
|
|
81
45
|
}
|
|
82
46
|
catch (e) {
|
|
83
47
|
process.stderr.write(`runFlow: step "${stepId}" — obstacle scan skipped (${e.message})\n`);
|
|
84
48
|
return [];
|
|
85
49
|
}
|
|
86
50
|
}
|
|
87
|
-
async function applyWait(driver, wait, resolve) {
|
|
88
|
-
if (typeof wait === "string") {
|
|
89
|
-
if (wait === "network_idle")
|
|
90
|
-
return driver.waitForNetworkIdle();
|
|
91
|
-
if (wait === "load")
|
|
92
|
-
return driver.waitForLoad();
|
|
93
|
-
// element_stable without a selector is a no-op signal in this prototype; a real driver may track layout.
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if ("selector" in wait)
|
|
97
|
-
return driver.waitForSelector(resolve(wait.selector), wait.timeout_ms);
|
|
98
|
-
if ("timeout_ms" in wait)
|
|
99
|
-
return driver.waitForTimeout(wait.timeout_ms);
|
|
100
|
-
}
|
|
101
|
-
async function checkSuccess(driver, success, resolve, stepId) {
|
|
102
|
-
const at = async () => `at ${await driver.currentUrl().catch(() => "?")}`;
|
|
103
|
-
if ("visible" in success) {
|
|
104
|
-
const sel = resolve(success.visible);
|
|
105
|
-
if (!(await driver.isVisible(sel))) {
|
|
106
|
-
throw new FlowExecutionError(`expected ${success.visible} to be visible — ${await at()}; ${await driver.count(sel).catch(() => "?")} element(s) match the selector`, stepId);
|
|
107
|
-
}
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if ("hidden" in success) {
|
|
111
|
-
const sel = resolve(success.hidden);
|
|
112
|
-
if (await driver.isVisible(sel)) {
|
|
113
|
-
throw new FlowExecutionError(`expected ${success.hidden} to be hidden but a match is visible — ${await at()}; ${await driver.count(sel).catch(() => "?")} element(s) match`, stepId);
|
|
114
|
-
}
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if ("url_matches" in success) {
|
|
118
|
-
if (!(await driver.urlMatches(success.url_matches))) {
|
|
119
|
-
throw new FlowExecutionError(`expected URL to match /${success.url_matches}/ — actual: ${await driver.currentUrl().catch(() => "?")}`, stepId);
|
|
120
|
-
}
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if ("text_contains" in success) {
|
|
124
|
-
const { selector, text } = success.text_contains;
|
|
125
|
-
const sel = resolve(selector);
|
|
126
|
-
if (!(await driver.textContains(sel, text))) {
|
|
127
|
-
const actual = ((await driver.textOf(sel).catch(() => null)) ?? "")
|
|
128
|
-
.replace(/\s+/g, " ")
|
|
129
|
-
.trim()
|
|
130
|
-
.slice(0, 200);
|
|
131
|
-
throw new FlowExecutionError(`expected ${selector} to contain ${JSON.stringify(text)} — ${await at()}; actual text: ${JSON.stringify(actual)}`, stepId);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
51
|
async function executeAction(driver, step, selector) {
|
|
136
52
|
switch (step.action) {
|
|
137
53
|
case "navigate":
|
|
@@ -139,33 +55,45 @@ async function executeAction(driver, step, selector) {
|
|
|
139
55
|
throw new FlowExecutionError("navigate requires `value` (path/URL)", step.id);
|
|
140
56
|
return driver.goto(step.value);
|
|
141
57
|
case "click":
|
|
142
|
-
return driver.click(needSelector(selector, step));
|
|
58
|
+
return driver.click(needSelector(selector, step), step.timeout_ms);
|
|
143
59
|
case "fill":
|
|
144
60
|
if (step.value === undefined)
|
|
145
61
|
throw new FlowExecutionError("fill requires `value`", step.id);
|
|
146
|
-
return driver.fill(needSelector(selector, step), step.value);
|
|
62
|
+
return driver.fill(needSelector(selector, step), step.value, step.timeout_ms);
|
|
147
63
|
case "upload":
|
|
148
64
|
if (step.value === undefined)
|
|
149
65
|
throw new FlowExecutionError("upload requires `value` (file path)", step.id);
|
|
150
|
-
return driver.upload(needSelector(selector, step), step.value);
|
|
66
|
+
return driver.upload(needSelector(selector, step), step.value, step.timeout_ms);
|
|
151
67
|
case "press":
|
|
152
68
|
if (!step.value)
|
|
153
69
|
throw new FlowExecutionError("press requires `value` (key)", step.id);
|
|
154
|
-
return driver.press(selector, step.value);
|
|
70
|
+
return driver.press(selector, step.value, step.timeout_ms);
|
|
155
71
|
case "hover":
|
|
156
|
-
return driver.hover(needSelector(selector, step));
|
|
72
|
+
return driver.hover(needSelector(selector, step), step.timeout_ms);
|
|
157
73
|
case "select":
|
|
158
74
|
if (step.value === undefined)
|
|
159
75
|
throw new FlowExecutionError("select requires `value` (option)", step.id);
|
|
160
|
-
return driver.selectOption(needSelector(selector, step), step.value);
|
|
76
|
+
return driver.selectOption(needSelector(selector, step), step.value, step.timeout_ms);
|
|
161
77
|
case "check":
|
|
162
|
-
return driver.setChecked(needSelector(selector, step), true);
|
|
78
|
+
return driver.setChecked(needSelector(selector, step), true, step.timeout_ms);
|
|
163
79
|
case "uncheck":
|
|
164
|
-
return driver.setChecked(needSelector(selector, step), false);
|
|
80
|
+
return driver.setChecked(needSelector(selector, step), false, step.timeout_ms);
|
|
165
81
|
case "wait":
|
|
166
82
|
return; // a bare `wait` step just runs its `wait_for`
|
|
83
|
+
case "hide":
|
|
84
|
+
if (!driver.hideElements)
|
|
85
|
+
throw new Error(missingMethod("hide", "hideElements"));
|
|
86
|
+
return driver.hideElements(needSelector(selector, step), step.timeout_ms);
|
|
87
|
+
case "show":
|
|
88
|
+
if (!driver.showElements)
|
|
89
|
+
throw new Error(missingMethod("show", "showElements"));
|
|
90
|
+
return driver.showElements(selector); // no target = show everything hidden so far
|
|
167
91
|
}
|
|
168
92
|
}
|
|
93
|
+
/** The halt message for a step whose optional driver method is missing. `halt-cause` keys on its shape. */
|
|
94
|
+
function missingMethod(feature, method) {
|
|
95
|
+
return `${feature}: driver has no ${method} (this browser driver doesn't implement it)`;
|
|
96
|
+
}
|
|
169
97
|
function needSelector(selector, step) {
|
|
170
98
|
if (selector === null)
|
|
171
99
|
throw new FlowExecutionError(`action "${step.action}" requires a \`target\``, step.id);
|
|
@@ -177,8 +105,14 @@ function needSelector(selector, step) {
|
|
|
177
105
|
* locator / success-criterion failure.
|
|
178
106
|
*/
|
|
179
107
|
export async function runFlow(flow, driver, opts = {}) {
|
|
108
|
+
if (flow.matrix) {
|
|
109
|
+
throw new Error(`runFlow: flow "${flow.name}" has a \`matrix\`; expand it (expandFlow) and run each variant`);
|
|
110
|
+
}
|
|
180
111
|
const captureDocs = opts.captureDocs ?? true;
|
|
181
|
-
const
|
|
112
|
+
const variantId = opts.variant?.id;
|
|
113
|
+
const screenshotPathOf = opts.screenshotPath ??
|
|
114
|
+
((name, stepId) => defaultScreenshotPath(name, stepId, variantId));
|
|
115
|
+
const locale = flow.environment?.locale;
|
|
182
116
|
const resolve = (v) => resolveTarget(v, flow, opts.resolveLocator);
|
|
183
117
|
const executed = [];
|
|
184
118
|
const annotations = [];
|
|
@@ -208,7 +142,7 @@ export async function runFlow(flow, driver, opts = {}) {
|
|
|
208
142
|
if (step.wait_for === "element_stable" && selector)
|
|
209
143
|
await driver.waitForElementStable(selector);
|
|
210
144
|
else
|
|
211
|
-
await applyWait(driver, step.wait_for, resolve);
|
|
145
|
+
await applyWait(driver, step.wait_for, resolve, step.action === "wait" || step.wait_for === "settled" ? step.timeout_ms : undefined);
|
|
212
146
|
}
|
|
213
147
|
if (step.success)
|
|
214
148
|
await checkSuccess(driver, step.success, resolve, step.id);
|
|
@@ -223,18 +157,19 @@ export async function runFlow(flow, driver, opts = {}) {
|
|
|
223
157
|
// Halt: dump a screenshot for triage (best-effort), prepend a 1-line inferred cause
|
|
224
158
|
// (parsed from Playwright's actionability log so the agent doesn't have to scan ~20 lines
|
|
225
159
|
// to know why), then surface step id + url + halt-shot path uniformly.
|
|
226
|
-
const haltShot =
|
|
160
|
+
const haltShot = `${variantDocDir(flow.name, variantId)}/halts/${step.id}.png`;
|
|
227
161
|
// Halt shots can capture the same sensitive UI as step shots — same redactions apply.
|
|
228
162
|
if (captureDocs)
|
|
229
163
|
await driver.screenshot(haltShot, redactions).catch(() => undefined);
|
|
230
164
|
const suffix = captureDocs ? ` (halt screenshot: ${haltShot})` : "";
|
|
231
165
|
const cause = inferHaltCause(e.message ?? "");
|
|
232
166
|
const causePrefix = cause ? `[${cause}] ` : "";
|
|
167
|
+
const variantTag = variantId ? `[variant ${variantId}] ` : "";
|
|
233
168
|
if (e instanceof FlowExecutionError) {
|
|
234
|
-
throw new FlowExecutionError(`${causePrefix}${e.message}${suffix}`, e.stepId, e.cause);
|
|
169
|
+
throw new FlowExecutionError(`${causePrefix}${variantTag}${e.message}${suffix}`, e.stepId, e.cause, variantId);
|
|
235
170
|
}
|
|
236
171
|
const where = await driver.currentUrl().catch(() => "?");
|
|
237
|
-
throw new FlowExecutionError(`${causePrefix}step "${step.id}" (${step.action}) failed at ${where}: ${e.message}${suffix}`, step.id, e);
|
|
172
|
+
throw new FlowExecutionError(`${causePrefix}${variantTag}step "${step.id}" (${step.action}) failed at ${where}: ${e.message}${suffix}`, step.id, e, variantId);
|
|
238
173
|
}
|
|
239
174
|
const ex = {
|
|
240
175
|
id: step.id,
|
|
@@ -249,6 +184,11 @@ export async function runFlow(flow, driver, opts = {}) {
|
|
|
249
184
|
// each becomes one record with a 1-based `index`; an `annotation` (singular) emits one record without
|
|
250
185
|
// `index` (un-numbered, back-compat).
|
|
251
186
|
const anns = step.annotations ?? (step.annotation ? [step.annotation] : []);
|
|
187
|
+
if (captureDocs && anns.length > 0 && opts.obstacles && !driver.nearbyBoxes) {
|
|
188
|
+
// Obstacle scanning was asked for and cannot run: halt rather than write annotations without it.
|
|
189
|
+
throw new FlowExecutionError(missingMethod("obstacles", "nearbyBoxes") +
|
|
190
|
+
"; turn off `annotations.obstacles` in .docsxai.json or use a driver that has it", step.id, undefined, variantId);
|
|
191
|
+
}
|
|
252
192
|
if (captureDocs && anns.length > 0) {
|
|
253
193
|
try {
|
|
254
194
|
const shot = screenshotPathOf(flow.name, step.id);
|
|
@@ -259,16 +199,17 @@ export async function runFlow(flow, driver, opts = {}) {
|
|
|
259
199
|
const annSelector = ann.target ? resolve(ann.target) : selector;
|
|
260
200
|
const bbox = annSelector ? await driver.boundingBox(annSelector, 2000) : null;
|
|
261
201
|
const obstacles = opts.obstacles && annSelector && bbox
|
|
262
|
-
? await obstaclesAround(driver, annSelector, bbox, step.id)
|
|
202
|
+
? await obstaclesAround(driver, annSelector, bbox, step.id, ann.placement)
|
|
263
203
|
: [];
|
|
264
204
|
annotations.push({
|
|
265
205
|
step: step.id,
|
|
266
206
|
selector: annSelector ?? "",
|
|
267
207
|
...(bbox ? { bounding_box: bbox } : {}),
|
|
268
208
|
...(obstacles.length > 0 ? { obstacles } : {}),
|
|
269
|
-
copy: ann
|
|
209
|
+
copy: pickCopy(ann, locale),
|
|
270
210
|
...(ann.arrow ? { arrow_style: ann.arrow } : {}),
|
|
271
211
|
...(ann.nudge ? { nudge: ann.nudge } : {}),
|
|
212
|
+
...(ann.placement ? { placement: ann.placement } : {}),
|
|
272
213
|
...(anns.length > 1 ? { index: i + 1 } : {}),
|
|
273
214
|
});
|
|
274
215
|
}
|
|
@@ -284,6 +225,11 @@ export async function runFlow(flow, driver, opts = {}) {
|
|
|
284
225
|
return {
|
|
285
226
|
flow: flow.name,
|
|
286
227
|
steps: executed,
|
|
287
|
-
annotations: {
|
|
228
|
+
annotations: {
|
|
229
|
+
schema: "docsxai/annotations@1",
|
|
230
|
+
flow: flow.name,
|
|
231
|
+
...(opts.variant ? { variant: opts.variant } : {}),
|
|
232
|
+
annotations,
|
|
233
|
+
},
|
|
288
234
|
};
|
|
289
235
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Checking a step's `success` criterion after its action. Changes when a criterion form is added
|
|
2
|
+
// or its halt message changes.
|
|
3
|
+
import { FlowExecutionError } from "./flow-halt.js";
|
|
4
|
+
export async function checkSuccess(driver, success, resolve, stepId) {
|
|
5
|
+
const at = async () => `at ${await driver.currentUrl().catch(() => "?")}`;
|
|
6
|
+
if ("visible" in success) {
|
|
7
|
+
const sel = resolve(success.visible);
|
|
8
|
+
if (!(await driver.isVisible(sel))) {
|
|
9
|
+
throw new FlowExecutionError(`expected ${success.visible} to be visible — ${await at()}; ${await driver.count(sel).catch(() => "?")} element(s) match the selector`, stepId);
|
|
10
|
+
}
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if ("hidden" in success) {
|
|
14
|
+
const sel = resolve(success.hidden);
|
|
15
|
+
if (await driver.isVisible(sel)) {
|
|
16
|
+
throw new FlowExecutionError(`expected ${success.hidden} to be hidden but a match is visible — ${await at()}; ${await driver.count(sel).catch(() => "?")} element(s) match`, stepId);
|
|
17
|
+
}
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if ("url_matches" in success) {
|
|
21
|
+
if (!(await driver.urlMatches(success.url_matches))) {
|
|
22
|
+
throw new FlowExecutionError(`expected URL to match /${success.url_matches}/ — actual: ${await driver.currentUrl().catch(() => "?")}`, stepId);
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if ("text_contains" in success) {
|
|
27
|
+
const { selector, text } = success.text_contains;
|
|
28
|
+
const sel = resolve(selector);
|
|
29
|
+
if (!(await driver.textContains(sel, text))) {
|
|
30
|
+
const actual = ((await driver.textOf(sel).catch(() => null)) ?? "")
|
|
31
|
+
.replace(/\s+/g, " ")
|
|
32
|
+
.trim()
|
|
33
|
+
.slice(0, 200);
|
|
34
|
+
throw new FlowExecutionError(`expected ${selector} to contain ${JSON.stringify(text)} — ${await at()}; actual text: ${JSON.stringify(actual)}`, stepId);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
package/dist/flow-tree.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { FlowFile } from "./doc-pack.js";
|
|
|
2
2
|
export type FlowTreeNode = {
|
|
3
3
|
name: string;
|
|
4
4
|
steps: number;
|
|
5
|
+
/** Variant ids the flow's `matrix` expands to, in run order. Absent for a flow without a `matrix`. */
|
|
6
|
+
variants?: string[];
|
|
5
7
|
children: FlowTreeNode[];
|
|
6
8
|
};
|
|
7
9
|
export type FlowTreeIssue = {
|
package/dist/flow-tree.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Visualise the `extends` graph across a workspace's flow-files; report step-id collisions
|
|
2
2
|
// across the merged step list. Pure-static — no Playwright, no live page. Run via `docsxai flow-tree`.
|
|
3
|
-
import { resolveFlowExtends } from "./flow-file.js";
|
|
3
|
+
import { expandFlowVariants, resolveFlowExtends } from "./flow-file.js";
|
|
4
|
+
import { matrixVariantIds } from "./flow-matrix.js";
|
|
4
5
|
export async function buildFlowTree(flowsByName) {
|
|
5
6
|
const childrenOf = new Map();
|
|
6
7
|
const orphanNames = [];
|
|
@@ -21,7 +22,12 @@ export async function buildFlowTree(flowsByName) {
|
|
|
21
22
|
const build = (name) => {
|
|
22
23
|
const flow = flowsByName.get(name);
|
|
23
24
|
const kids = (childrenOf.get(name) ?? []).slice().sort().map(build);
|
|
24
|
-
return {
|
|
25
|
+
return {
|
|
26
|
+
name,
|
|
27
|
+
steps: flow.steps.length,
|
|
28
|
+
...(flow.matrix ? { variants: matrixVariantIds(flow.matrix) } : {}),
|
|
29
|
+
children: kids,
|
|
30
|
+
};
|
|
25
31
|
};
|
|
26
32
|
const issues = [];
|
|
27
33
|
const loadFlow = (n) => {
|
|
@@ -34,7 +40,8 @@ export async function buildFlowTree(flowsByName) {
|
|
|
34
40
|
if (!flow.extends || orphanNames.includes(name))
|
|
35
41
|
continue;
|
|
36
42
|
try {
|
|
37
|
-
|
|
43
|
+
// The merged flow is what runs, so its `only`/`skip` are checked against its own matrix here.
|
|
44
|
+
expandFlowVariants(await resolveFlowExtends(flow, loadFlow));
|
|
38
45
|
}
|
|
39
46
|
catch (e) {
|
|
40
47
|
issues.push({ flow: name, message: e.message });
|
|
@@ -68,8 +75,13 @@ export function formatTreeText(result) {
|
|
|
68
75
|
}
|
|
69
76
|
return out;
|
|
70
77
|
}
|
|
78
|
+
/** ` {4 variants: a, b, c, d}` for a flow with a matrix, else nothing. */
|
|
79
|
+
function variantNote(node) {
|
|
80
|
+
const v = node.variants;
|
|
81
|
+
return v ? ` {${v.length} variant${v.length !== 1 ? "s" : ""}: ${v.join(", ")}}` : "";
|
|
82
|
+
}
|
|
71
83
|
function renderRoot(node) {
|
|
72
|
-
let out = `${node.name} [${node.steps} step${node.steps !== 1 ? "s" : ""}]\n`;
|
|
84
|
+
let out = `${node.name} [${node.steps} step${node.steps !== 1 ? "s" : ""}]${variantNote(node)}\n`;
|
|
73
85
|
for (let i = 0; i < node.children.length; i++) {
|
|
74
86
|
out += renderChild(node.children[i], "", i === node.children.length - 1);
|
|
75
87
|
}
|
|
@@ -77,7 +89,7 @@ function renderRoot(node) {
|
|
|
77
89
|
}
|
|
78
90
|
function renderChild(node, parentPrefix, isLast) {
|
|
79
91
|
const connector = isLast ? "└── " : "├── ";
|
|
80
|
-
let out = `${parentPrefix}${connector}${node.name} [+${node.steps} step${node.steps !== 1 ? "s" : ""}]\n`;
|
|
92
|
+
let out = `${parentPrefix}${connector}${node.name} [+${node.steps} step${node.steps !== 1 ? "s" : ""}]${variantNote(node)}\n`;
|
|
81
93
|
const childPrefix = parentPrefix + (isLast ? " " : "│ ");
|
|
82
94
|
for (let i = 0; i < node.children.length; i++) {
|
|
83
95
|
out += renderChild(node.children[i], childPrefix, i === node.children.length - 1);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Applying a step's `wait_for` through the driver. Changes when a wait form is added or its
|
|
2
|
+
// driver call changes.
|
|
3
|
+
export async function applyWait(driver, wait, resolve, stepTimeoutMs) {
|
|
4
|
+
if (typeof wait === "string") {
|
|
5
|
+
if (wait === "network_idle")
|
|
6
|
+
return driver.waitForNetworkIdle();
|
|
7
|
+
if (wait === "load")
|
|
8
|
+
return driver.waitForLoad();
|
|
9
|
+
if (wait === "settled") {
|
|
10
|
+
if (!driver.waitForSettled) {
|
|
11
|
+
throw new Error("settled: driver has no waitForSettled (this browser driver doesn't implement it)");
|
|
12
|
+
}
|
|
13
|
+
return driver.waitForSettled(stepTimeoutMs);
|
|
14
|
+
}
|
|
15
|
+
// element_stable without a selector is a no-op signal in this prototype; a real driver may track layout.
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if ("selector" in wait)
|
|
19
|
+
return driver.waitForSelector(resolve(wait.selector), wait.timeout_ms ?? stepTimeoutMs);
|
|
20
|
+
if ("timeout_ms" in wait)
|
|
21
|
+
return driver.waitForTimeout(wait.timeout_ms);
|
|
22
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./doc-pack.js";
|
|
|
3
3
|
export * from "./doc-pack-io.js";
|
|
4
4
|
export * from "./flow-file.js";
|
|
5
5
|
export * from "./flow-runtime.js";
|
|
6
|
+
export * from "./flow-matrix.js";
|
|
6
7
|
export * from "./obstacles.js";
|
|
7
8
|
export * from "./flow-lint.js";
|
|
8
9
|
export * from "./flow-tree.js";
|
|
@@ -11,6 +12,7 @@ export * from "./backend-client.js";
|
|
|
11
12
|
export * from "./calibrate.js";
|
|
12
13
|
export * from "./diagnose.js";
|
|
13
14
|
export * from "./doctor.js";
|
|
15
|
+
export * from "./egress-guard.js";
|
|
14
16
|
export * from "./playwright-driver.js";
|
|
15
17
|
export * from "./playwright-instrumented-browser.js";
|
|
16
18
|
export * from "./style.js";
|
|
@@ -26,3 +28,6 @@ export * from "./viewer-bin.js";
|
|
|
26
28
|
export * from "./export/adf.js";
|
|
27
29
|
export * from "./export/playwright-test.js";
|
|
28
30
|
export * from "./diff.js";
|
|
31
|
+
export * from "./deprecation.js";
|
|
32
|
+
export * from "./verify-compare.js";
|
|
33
|
+
export * from "./verify-report.js";
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./doc-pack.js";
|
|
|
7
7
|
export * from "./doc-pack-io.js";
|
|
8
8
|
export * from "./flow-file.js";
|
|
9
9
|
export * from "./flow-runtime.js";
|
|
10
|
+
export * from "./flow-matrix.js";
|
|
10
11
|
export * from "./obstacles.js";
|
|
11
12
|
export * from "./flow-lint.js";
|
|
12
13
|
export * from "./flow-tree.js";
|
|
@@ -15,6 +16,7 @@ export * from "./backend-client.js";
|
|
|
15
16
|
export * from "./calibrate.js";
|
|
16
17
|
export * from "./diagnose.js";
|
|
17
18
|
export * from "./doctor.js";
|
|
19
|
+
export * from "./egress-guard.js";
|
|
18
20
|
export * from "./playwright-driver.js";
|
|
19
21
|
export * from "./playwright-instrumented-browser.js";
|
|
20
22
|
export * from "./style.js";
|
|
@@ -30,3 +32,6 @@ export * from "./viewer-bin.js";
|
|
|
30
32
|
export * from "./export/adf.js";
|
|
31
33
|
export * from "./export/playwright-test.js";
|
|
32
34
|
export * from "./diff.js";
|
|
35
|
+
export * from "./deprecation.js";
|
|
36
|
+
export * from "./verify-compare.js";
|
|
37
|
+
export * from "./verify-report.js";
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type ViewportSize } from "./environment-spec.js";
|
|
3
|
+
/** Most variants one flow may expand to. A flow over the cap is rejected at parse time. */
|
|
4
|
+
export declare const MAX_MATRIX_VARIANTS = 64;
|
|
5
|
+
/** A matrix viewport: a preset name, or a size with an optional name (default `<width>x<height>`). */
|
|
6
|
+
export declare const MatrixViewport: z.ZodUnion<[z.ZodEnum<["desktop", "tablet", "mobile"]>, z.ZodObject<{
|
|
7
|
+
name: z.ZodOptional<z.ZodString>;
|
|
8
|
+
width: z.ZodNumber;
|
|
9
|
+
height: z.ZodNumber;
|
|
10
|
+
}, "strict", z.ZodTypeAny, {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
name?: string | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
name?: string | undefined;
|
|
18
|
+
}>]>;
|
|
19
|
+
export type MatrixViewport = z.infer<typeof MatrixViewport>;
|
|
20
|
+
/** A matrix viewport with its name and size spelled out. */
|
|
21
|
+
export interface ResolvedMatrixViewport extends ViewportSize {
|
|
22
|
+
name: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function resolveMatrixViewport(entry: MatrixViewport): ResolvedMatrixViewport;
|
|
25
|
+
/**
|
|
26
|
+
* The `matrix:` block of a flow-file. Each axis is a bounded list; the flow expands to the product
|
|
27
|
+
* of the axes it names. Locale and viewport entries must be unique (locales ignoring case,
|
|
28
|
+
* viewports by name), and the product may not pass {@link MAX_MATRIX_VARIANTS}.
|
|
29
|
+
*/
|
|
30
|
+
export declare const MatrixSpec: z.ZodEffects<z.ZodObject<{
|
|
31
|
+
locales: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
32
|
+
color_schemes: z.ZodOptional<z.ZodArray<z.ZodEnum<["light", "dark"]>, "many">>;
|
|
33
|
+
viewports: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodEnum<["desktop", "tablet", "mobile"]>, z.ZodObject<{
|
|
34
|
+
name: z.ZodOptional<z.ZodString>;
|
|
35
|
+
width: z.ZodNumber;
|
|
36
|
+
height: z.ZodNumber;
|
|
37
|
+
}, "strict", z.ZodTypeAny, {
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
name?: string | undefined;
|
|
41
|
+
}, {
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
name?: string | undefined;
|
|
45
|
+
}>]>, "many">>;
|
|
46
|
+
}, "strict", z.ZodTypeAny, {
|
|
47
|
+
locales?: string[] | undefined;
|
|
48
|
+
color_schemes?: ("light" | "dark")[] | undefined;
|
|
49
|
+
viewports?: ("desktop" | "tablet" | "mobile" | {
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
name?: string | undefined;
|
|
53
|
+
})[] | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
locales?: string[] | undefined;
|
|
56
|
+
color_schemes?: ("light" | "dark")[] | undefined;
|
|
57
|
+
viewports?: ("desktop" | "tablet" | "mobile" | {
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
name?: string | undefined;
|
|
61
|
+
})[] | undefined;
|
|
62
|
+
}>, {
|
|
63
|
+
locales?: string[] | undefined;
|
|
64
|
+
color_schemes?: ("light" | "dark")[] | undefined;
|
|
65
|
+
viewports?: ("desktop" | "tablet" | "mobile" | {
|
|
66
|
+
width: number;
|
|
67
|
+
height: number;
|
|
68
|
+
name?: string | undefined;
|
|
69
|
+
})[] | undefined;
|
|
70
|
+
}, {
|
|
71
|
+
locales?: string[] | undefined;
|
|
72
|
+
color_schemes?: ("light" | "dark")[] | undefined;
|
|
73
|
+
viewports?: ("desktop" | "tablet" | "mobile" | {
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
name?: string | undefined;
|
|
77
|
+
})[] | undefined;
|
|
78
|
+
}>;
|
|
79
|
+
export type MatrixSpec = z.infer<typeof MatrixSpec>;
|
|
80
|
+
/**
|
|
81
|
+
* Which variants a step or annotation applies to (`only`) or is dropped from (`skip`). A clause
|
|
82
|
+
* names axes; it matches a variant when every axis it names matches (any value in the list).
|
|
83
|
+
* `viewport` values are matrix viewport names, `locale` values match exactly or by language
|
|
84
|
+
* (`es` matches `es-ES`).
|
|
85
|
+
*/
|
|
86
|
+
export declare const VariantSelector: z.ZodEffects<z.ZodObject<{
|
|
87
|
+
viewport: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
88
|
+
color_scheme: z.ZodOptional<z.ZodArray<z.ZodEnum<["light", "dark"]>, "many">>;
|
|
89
|
+
locale: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
90
|
+
}, "strict", z.ZodTypeAny, {
|
|
91
|
+
locale?: string[] | undefined;
|
|
92
|
+
viewport?: string[] | undefined;
|
|
93
|
+
color_scheme?: ("light" | "dark")[] | undefined;
|
|
94
|
+
}, {
|
|
95
|
+
locale?: string[] | undefined;
|
|
96
|
+
viewport?: string[] | undefined;
|
|
97
|
+
color_scheme?: ("light" | "dark")[] | undefined;
|
|
98
|
+
}>, {
|
|
99
|
+
locale?: string[] | undefined;
|
|
100
|
+
viewport?: string[] | undefined;
|
|
101
|
+
color_scheme?: ("light" | "dark")[] | undefined;
|
|
102
|
+
}, {
|
|
103
|
+
locale?: string[] | undefined;
|
|
104
|
+
viewport?: string[] | undefined;
|
|
105
|
+
color_scheme?: ("light" | "dark")[] | undefined;
|
|
106
|
+
}>;
|
|
107
|
+
export type VariantSelector = z.infer<typeof VariantSelector>;
|
|
108
|
+
/** The variant a run executed, recorded as `variant` in `annotations.json`. */
|
|
109
|
+
export declare const VariantInfo: z.ZodObject<{
|
|
110
|
+
id: z.ZodString;
|
|
111
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
112
|
+
color_scheme: z.ZodOptional<z.ZodEnum<["light", "dark"]>>;
|
|
113
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
114
|
+
name: z.ZodString;
|
|
115
|
+
width: z.ZodNumber;
|
|
116
|
+
height: z.ZodNumber;
|
|
117
|
+
}, "strict", z.ZodTypeAny, {
|
|
118
|
+
width: number;
|
|
119
|
+
height: number;
|
|
120
|
+
name: string;
|
|
121
|
+
}, {
|
|
122
|
+
width: number;
|
|
123
|
+
height: number;
|
|
124
|
+
name: string;
|
|
125
|
+
}>>;
|
|
126
|
+
}, "strict", z.ZodTypeAny, {
|
|
127
|
+
id: string;
|
|
128
|
+
locale?: string | undefined;
|
|
129
|
+
viewport?: {
|
|
130
|
+
width: number;
|
|
131
|
+
height: number;
|
|
132
|
+
name: string;
|
|
133
|
+
} | undefined;
|
|
134
|
+
color_scheme?: "light" | "dark" | undefined;
|
|
135
|
+
}, {
|
|
136
|
+
id: string;
|
|
137
|
+
locale?: string | undefined;
|
|
138
|
+
viewport?: {
|
|
139
|
+
width: number;
|
|
140
|
+
height: number;
|
|
141
|
+
name: string;
|
|
142
|
+
} | undefined;
|
|
143
|
+
color_scheme?: "light" | "dark" | undefined;
|
|
144
|
+
}>;
|
|
145
|
+
export type VariantInfo = z.infer<typeof VariantInfo>;
|