@docsxai/engine 0.2.0 → 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 +26 -6
- package/dist/address-class.d.ts +14 -0
- package/dist/address-class.js +151 -0
- package/dist/auth/api-login.js +6 -2
- package/dist/backend-client-contracts.d.ts +2 -0
- 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 -88
- 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 +53 -5
- 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 +2165 -181
- package/dist/doc-pack.js +152 -42
- package/dist/doctor-checks.d.ts +1 -1
- package/dist/doctor-checks.js +29 -5
- 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 +7 -1
- 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 +67 -21
- package/dist/flow-runtime.js +72 -110
- 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 +6 -0
- package/dist/index.js +6 -0
- package/dist/matrix-spec.d.ts +145 -0
- package/dist/matrix-spec.js +120 -0
- package/dist/obstacles.d.ts +33 -0
- package/dist/obstacles.js +72 -0
- package/dist/page-hide.d.ts +10 -0
- package/dist/page-hide.js +45 -0
- package/dist/page-nearby-boxes.d.ts +9 -0
- package/dist/page-nearby-boxes.js +92 -0
- package/dist/page-settle.d.ts +39 -0
- package/dist/page-settle.js +142 -0
- package/dist/playwright-driver.d.ts +30 -8
- package/dist/playwright-driver.js +88 -18
- package/dist/run-flows.d.ts +40 -0
- package/dist/run-flows.js +129 -0
- 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/workspace.d.ts +8 -0
- package/package.json +7 -6
package/dist/flow-runtime.js
CHANGED
|
@@ -8,59 +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";
|
|
15
|
+
import { OBSTACLE_RADIUS, selectObstacles } from "./obstacles.js";
|
|
11
16
|
// ---------------------------------------------------------------------------
|
|
12
17
|
// Errors
|
|
13
18
|
// ---------------------------------------------------------------------------
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
cause;
|
|
17
|
-
constructor(message, stepId, cause) {
|
|
18
|
-
super(message);
|
|
19
|
-
this.stepId = stepId;
|
|
20
|
-
this.cause = cause;
|
|
21
|
-
this.name = "FlowExecutionError";
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Best-effort 1-line cause extracted from a Playwright actionability log (or similar driver
|
|
26
|
-
* error). Returns undefined when nothing matches — keeps the halt message short rather than
|
|
27
|
-
* guessing. Surfaced as a `[cause]` prefix on the halt message so the agent doesn't have to
|
|
28
|
-
* scan the multi-line actionability log.
|
|
29
|
-
*/
|
|
30
|
-
export function inferHaltCause(rawError) {
|
|
31
|
-
const hints = [
|
|
32
|
-
[/element is disabled\b/i, "target is disabled"],
|
|
33
|
-
[/element is not enabled\b/i, "target is not enabled"],
|
|
34
|
-
[
|
|
35
|
-
/element is not visible\b/i,
|
|
36
|
-
"target is not visible (display:none / visibility:hidden / zero-sized)",
|
|
37
|
-
],
|
|
38
|
-
[
|
|
39
|
-
/element is not attached\b/i,
|
|
40
|
-
"target was detached from the DOM (likely unmounted by an earlier action)",
|
|
41
|
-
],
|
|
42
|
-
[/element is outside of the viewport\b/i, "target is outside the visible viewport"],
|
|
43
|
-
[/element is not stable\b/i, "target is animating / not yet stable"],
|
|
44
|
-
[/intercepts? pointer events\b/i, "target is covered by another element"],
|
|
45
|
-
[
|
|
46
|
-
/strict mode violation\b/i,
|
|
47
|
-
"selector matched multiple elements (strict-mode violation) — scope with :visible / :nth-match",
|
|
48
|
-
],
|
|
49
|
-
[
|
|
50
|
-
/timeout .* exceeded.*waiting for/is,
|
|
51
|
-
"timeout waiting for selector — element didn't appear in time (consider raising timeout_ms or revisiting the locator)",
|
|
52
|
-
],
|
|
53
|
-
];
|
|
54
|
-
for (const [re, msg] of hints) {
|
|
55
|
-
if (re.test(rawError))
|
|
56
|
-
return msg;
|
|
57
|
-
}
|
|
58
|
-
const resolved = rawError.match(/locator resolved to (<[^>\n]*>)/);
|
|
59
|
-
if (resolved)
|
|
60
|
-
return `target resolved to ${resolved[1]}`;
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
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`;
|
|
64
21
|
/** Resolve a `target` value (`$name` ref or inline selector) using the flow-file's locators (or a custom resolver). */
|
|
65
22
|
export function resolveTarget(value, flow, resolver) {
|
|
66
23
|
const name = locatorRefName(value);
|
|
@@ -72,52 +29,23 @@ export function resolveTarget(value, flow, resolver) {
|
|
|
72
29
|
}
|
|
73
30
|
return resolved;
|
|
74
31
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return
|
|
32
|
+
/** Obstacles around `selector`, best-effort like the halo box: a failed scan leaves the field off. */
|
|
33
|
+
async function obstaclesAround(driver, selector, target, stepId, placement) {
|
|
34
|
+
if (!driver.nearbyBoxes)
|
|
35
|
+
return [];
|
|
36
|
+
const radius = placement?.obstacle_radius ?? OBSTACLE_RADIUS;
|
|
37
|
+
try {
|
|
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
|
+
: [];
|
|
83
45
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return driver.waitForTimeout(wait.timeout_ms);
|
|
88
|
-
}
|
|
89
|
-
async function checkSuccess(driver, success, resolve, stepId) {
|
|
90
|
-
const at = async () => `at ${await driver.currentUrl().catch(() => "?")}`;
|
|
91
|
-
if ("visible" in success) {
|
|
92
|
-
const sel = resolve(success.visible);
|
|
93
|
-
if (!(await driver.isVisible(sel))) {
|
|
94
|
-
throw new FlowExecutionError(`expected ${success.visible} to be visible — ${await at()}; ${await driver.count(sel).catch(() => "?")} element(s) match the selector`, stepId);
|
|
95
|
-
}
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if ("hidden" in success) {
|
|
99
|
-
const sel = resolve(success.hidden);
|
|
100
|
-
if (await driver.isVisible(sel)) {
|
|
101
|
-
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);
|
|
102
|
-
}
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
if ("url_matches" in success) {
|
|
106
|
-
if (!(await driver.urlMatches(success.url_matches))) {
|
|
107
|
-
throw new FlowExecutionError(`expected URL to match /${success.url_matches}/ — actual: ${await driver.currentUrl().catch(() => "?")}`, stepId);
|
|
108
|
-
}
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if ("text_contains" in success) {
|
|
112
|
-
const { selector, text } = success.text_contains;
|
|
113
|
-
const sel = resolve(selector);
|
|
114
|
-
if (!(await driver.textContains(sel, text))) {
|
|
115
|
-
const actual = ((await driver.textOf(sel).catch(() => null)) ?? "")
|
|
116
|
-
.replace(/\s+/g, " ")
|
|
117
|
-
.trim()
|
|
118
|
-
.slice(0, 200);
|
|
119
|
-
throw new FlowExecutionError(`expected ${selector} to contain ${JSON.stringify(text)} — ${await at()}; actual text: ${JSON.stringify(actual)}`, stepId);
|
|
120
|
-
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
process.stderr.write(`runFlow: step "${stepId}" — obstacle scan skipped (${e.message})\n`);
|
|
48
|
+
return [];
|
|
121
49
|
}
|
|
122
50
|
}
|
|
123
51
|
async function executeAction(driver, step, selector) {
|
|
@@ -127,33 +55,45 @@ async function executeAction(driver, step, selector) {
|
|
|
127
55
|
throw new FlowExecutionError("navigate requires `value` (path/URL)", step.id);
|
|
128
56
|
return driver.goto(step.value);
|
|
129
57
|
case "click":
|
|
130
|
-
return driver.click(needSelector(selector, step));
|
|
58
|
+
return driver.click(needSelector(selector, step), step.timeout_ms);
|
|
131
59
|
case "fill":
|
|
132
60
|
if (step.value === undefined)
|
|
133
61
|
throw new FlowExecutionError("fill requires `value`", step.id);
|
|
134
|
-
return driver.fill(needSelector(selector, step), step.value);
|
|
62
|
+
return driver.fill(needSelector(selector, step), step.value, step.timeout_ms);
|
|
135
63
|
case "upload":
|
|
136
64
|
if (step.value === undefined)
|
|
137
65
|
throw new FlowExecutionError("upload requires `value` (file path)", step.id);
|
|
138
|
-
return driver.upload(needSelector(selector, step), step.value);
|
|
66
|
+
return driver.upload(needSelector(selector, step), step.value, step.timeout_ms);
|
|
139
67
|
case "press":
|
|
140
68
|
if (!step.value)
|
|
141
69
|
throw new FlowExecutionError("press requires `value` (key)", step.id);
|
|
142
|
-
return driver.press(selector, step.value);
|
|
70
|
+
return driver.press(selector, step.value, step.timeout_ms);
|
|
143
71
|
case "hover":
|
|
144
|
-
return driver.hover(needSelector(selector, step));
|
|
72
|
+
return driver.hover(needSelector(selector, step), step.timeout_ms);
|
|
145
73
|
case "select":
|
|
146
74
|
if (step.value === undefined)
|
|
147
75
|
throw new FlowExecutionError("select requires `value` (option)", step.id);
|
|
148
|
-
return driver.selectOption(needSelector(selector, step), step.value);
|
|
76
|
+
return driver.selectOption(needSelector(selector, step), step.value, step.timeout_ms);
|
|
149
77
|
case "check":
|
|
150
|
-
return driver.setChecked(needSelector(selector, step), true);
|
|
78
|
+
return driver.setChecked(needSelector(selector, step), true, step.timeout_ms);
|
|
151
79
|
case "uncheck":
|
|
152
|
-
return driver.setChecked(needSelector(selector, step), false);
|
|
80
|
+
return driver.setChecked(needSelector(selector, step), false, step.timeout_ms);
|
|
153
81
|
case "wait":
|
|
154
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
|
|
155
91
|
}
|
|
156
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
|
+
}
|
|
157
97
|
function needSelector(selector, step) {
|
|
158
98
|
if (selector === null)
|
|
159
99
|
throw new FlowExecutionError(`action "${step.action}" requires a \`target\``, step.id);
|
|
@@ -165,8 +105,14 @@ function needSelector(selector, step) {
|
|
|
165
105
|
* locator / success-criterion failure.
|
|
166
106
|
*/
|
|
167
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
|
+
}
|
|
168
111
|
const captureDocs = opts.captureDocs ?? true;
|
|
169
|
-
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;
|
|
170
116
|
const resolve = (v) => resolveTarget(v, flow, opts.resolveLocator);
|
|
171
117
|
const executed = [];
|
|
172
118
|
const annotations = [];
|
|
@@ -196,7 +142,7 @@ export async function runFlow(flow, driver, opts = {}) {
|
|
|
196
142
|
if (step.wait_for === "element_stable" && selector)
|
|
197
143
|
await driver.waitForElementStable(selector);
|
|
198
144
|
else
|
|
199
|
-
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);
|
|
200
146
|
}
|
|
201
147
|
if (step.success)
|
|
202
148
|
await checkSuccess(driver, step.success, resolve, step.id);
|
|
@@ -211,18 +157,19 @@ export async function runFlow(flow, driver, opts = {}) {
|
|
|
211
157
|
// Halt: dump a screenshot for triage (best-effort), prepend a 1-line inferred cause
|
|
212
158
|
// (parsed from Playwright's actionability log so the agent doesn't have to scan ~20 lines
|
|
213
159
|
// to know why), then surface step id + url + halt-shot path uniformly.
|
|
214
|
-
const haltShot =
|
|
160
|
+
const haltShot = `${variantDocDir(flow.name, variantId)}/halts/${step.id}.png`;
|
|
215
161
|
// Halt shots can capture the same sensitive UI as step shots — same redactions apply.
|
|
216
162
|
if (captureDocs)
|
|
217
163
|
await driver.screenshot(haltShot, redactions).catch(() => undefined);
|
|
218
164
|
const suffix = captureDocs ? ` (halt screenshot: ${haltShot})` : "";
|
|
219
165
|
const cause = inferHaltCause(e.message ?? "");
|
|
220
166
|
const causePrefix = cause ? `[${cause}] ` : "";
|
|
167
|
+
const variantTag = variantId ? `[variant ${variantId}] ` : "";
|
|
221
168
|
if (e instanceof FlowExecutionError) {
|
|
222
|
-
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);
|
|
223
170
|
}
|
|
224
171
|
const where = await driver.currentUrl().catch(() => "?");
|
|
225
|
-
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);
|
|
226
173
|
}
|
|
227
174
|
const ex = {
|
|
228
175
|
id: step.id,
|
|
@@ -237,6 +184,11 @@ export async function runFlow(flow, driver, opts = {}) {
|
|
|
237
184
|
// each becomes one record with a 1-based `index`; an `annotation` (singular) emits one record without
|
|
238
185
|
// `index` (un-numbered, back-compat).
|
|
239
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
|
+
}
|
|
240
192
|
if (captureDocs && anns.length > 0) {
|
|
241
193
|
try {
|
|
242
194
|
const shot = screenshotPathOf(flow.name, step.id);
|
|
@@ -246,13 +198,18 @@ export async function runFlow(flow, driver, opts = {}) {
|
|
|
246
198
|
const ann = anns[i];
|
|
247
199
|
const annSelector = ann.target ? resolve(ann.target) : selector;
|
|
248
200
|
const bbox = annSelector ? await driver.boundingBox(annSelector, 2000) : null;
|
|
201
|
+
const obstacles = opts.obstacles && annSelector && bbox
|
|
202
|
+
? await obstaclesAround(driver, annSelector, bbox, step.id, ann.placement)
|
|
203
|
+
: [];
|
|
249
204
|
annotations.push({
|
|
250
205
|
step: step.id,
|
|
251
206
|
selector: annSelector ?? "",
|
|
252
207
|
...(bbox ? { bounding_box: bbox } : {}),
|
|
253
|
-
|
|
208
|
+
...(obstacles.length > 0 ? { obstacles } : {}),
|
|
209
|
+
copy: pickCopy(ann, locale),
|
|
254
210
|
...(ann.arrow ? { arrow_style: ann.arrow } : {}),
|
|
255
211
|
...(ann.nudge ? { nudge: ann.nudge } : {}),
|
|
212
|
+
...(ann.placement ? { placement: ann.placement } : {}),
|
|
256
213
|
...(anns.length > 1 ? { index: i + 1 } : {}),
|
|
257
214
|
});
|
|
258
215
|
}
|
|
@@ -268,6 +225,11 @@ export async function runFlow(flow, driver, opts = {}) {
|
|
|
268
225
|
return {
|
|
269
226
|
flow: flow.name,
|
|
270
227
|
steps: executed,
|
|
271
|
-
annotations: {
|
|
228
|
+
annotations: {
|
|
229
|
+
schema: "docsxai/annotations@1",
|
|
230
|
+
flow: flow.name,
|
|
231
|
+
...(opts.variant ? { variant: opts.variant } : {}),
|
|
232
|
+
annotations,
|
|
233
|
+
},
|
|
272
234
|
};
|
|
273
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,8 @@ 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";
|
|
7
|
+
export * from "./obstacles.js";
|
|
6
8
|
export * from "./flow-lint.js";
|
|
7
9
|
export * from "./flow-tree.js";
|
|
8
10
|
export * from "./auth.js";
|
|
@@ -10,6 +12,7 @@ export * from "./backend-client.js";
|
|
|
10
12
|
export * from "./calibrate.js";
|
|
11
13
|
export * from "./diagnose.js";
|
|
12
14
|
export * from "./doctor.js";
|
|
15
|
+
export * from "./egress-guard.js";
|
|
13
16
|
export * from "./playwright-driver.js";
|
|
14
17
|
export * from "./playwright-instrumented-browser.js";
|
|
15
18
|
export * from "./style.js";
|
|
@@ -25,3 +28,6 @@ export * from "./viewer-bin.js";
|
|
|
25
28
|
export * from "./export/adf.js";
|
|
26
29
|
export * from "./export/playwright-test.js";
|
|
27
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,8 @@ 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";
|
|
11
|
+
export * from "./obstacles.js";
|
|
10
12
|
export * from "./flow-lint.js";
|
|
11
13
|
export * from "./flow-tree.js";
|
|
12
14
|
export * from "./auth.js";
|
|
@@ -14,6 +16,7 @@ export * from "./backend-client.js";
|
|
|
14
16
|
export * from "./calibrate.js";
|
|
15
17
|
export * from "./diagnose.js";
|
|
16
18
|
export * from "./doctor.js";
|
|
19
|
+
export * from "./egress-guard.js";
|
|
17
20
|
export * from "./playwright-driver.js";
|
|
18
21
|
export * from "./playwright-instrumented-browser.js";
|
|
19
22
|
export * from "./style.js";
|
|
@@ -29,3 +32,6 @@ export * from "./viewer-bin.js";
|
|
|
29
32
|
export * from "./export/adf.js";
|
|
30
33
|
export * from "./export/playwright-test.js";
|
|
31
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>;
|