@testmuai/playwright-bindings 0.1.40 → 0.1.41
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/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +9 -1
- package/dist/capability.js.map +1 -1
- package/dist/helpers/a11yFlatten.d.ts +37 -0
- package/dist/helpers/a11yFlatten.d.ts.map +1 -0
- package/dist/helpers/a11yFlatten.js +569 -0
- package/dist/helpers/a11yFlatten.js.map +1 -0
- package/dist/helpers/assertion.d.ts +1 -0
- package/dist/helpers/assertion.d.ts.map +1 -1
- package/dist/helpers/assertion.js +42 -6
- package/dist/helpers/assertion.js.map +1 -1
- package/dist/helpers/condition.d.ts +16 -0
- package/dist/helpers/condition.d.ts.map +1 -1
- package/dist/helpers/condition.js +67 -2
- package/dist/helpers/condition.js.map +1 -1
- package/dist/helpers/credits.d.ts +19 -0
- package/dist/helpers/credits.d.ts.map +1 -0
- package/dist/helpers/credits.js +52 -0
- package/dist/helpers/credits.js.map +1 -0
- package/dist/helpers/executeApi.d.ts +9 -1
- package/dist/helpers/executeApi.d.ts.map +1 -1
- package/dist/helpers/executeApi.js +86 -6
- package/dist/helpers/executeApi.js.map +1 -1
- package/dist/helpers/healCascade.d.ts +0 -18
- package/dist/helpers/healCascade.d.ts.map +1 -1
- package/dist/helpers/healCascade.js +90 -38
- package/dist/helpers/healCascade.js.map +1 -1
- package/dist/helpers/iframeA11y.d.ts +30 -0
- package/dist/helpers/iframeA11y.d.ts.map +1 -0
- package/dist/helpers/iframeA11y.js +128 -0
- package/dist/helpers/iframeA11y.js.map +1 -0
- package/dist/helpers/math.d.ts +14 -1
- package/dist/helpers/math.d.ts.map +1 -1
- package/dist/helpers/math.js +84 -4
- package/dist/helpers/math.js.map +1 -1
- package/dist/helpers/pageReady.d.ts +36 -0
- package/dist/helpers/pageReady.d.ts.map +1 -0
- package/dist/helpers/pageReady.js +85 -0
- package/dist/helpers/pageReady.js.map +1 -0
- package/dist/helpers/runtimeSnapshot.d.ts +59 -0
- package/dist/helpers/runtimeSnapshot.d.ts.map +1 -0
- package/dist/helpers/runtimeSnapshot.js +204 -0
- package/dist/helpers/runtimeSnapshot.js.map +1 -0
- package/dist/helpers/visionFence.d.ts +35 -0
- package/dist/helpers/visionFence.d.ts.map +1 -0
- package/dist/helpers/visionFence.js +58 -0
- package/dist/helpers/visionFence.js.map +1 -0
- package/dist/helpers/visionV3.d.ts +14 -0
- package/dist/helpers/visionV3.d.ts.map +1 -1
- package/dist/helpers/visionV3.js +92 -18
- package/dist/helpers/visionV3.js.map +1 -1
- package/dist/reporters/index.d.ts +3 -0
- package/dist/reporters/index.d.ts.map +1 -1
- package/dist/reporters/index.js.map +1 -1
- package/dist/reporters/lt.d.ts.map +1 -1
- package/dist/reporters/lt.js +23 -0
- package/dist/reporters/lt.js.map +1 -1
- package/dist/step.d.ts +8 -0
- package/dist/step.d.ts.map +1 -1
- package/dist/step.js +19 -0
- package/dist/step.js.map +1 -1
- package/dist/stepVariables.d.ts +15 -0
- package/dist/stepVariables.d.ts.map +1 -0
- package/dist/stepVariables.js +61 -0
- package/dist/stepVariables.js.map +1 -0
- package/dist/vars.d.ts +12 -0
- package/dist/vars.d.ts.map +1 -1
- package/dist/vars.js +117 -17
- package/dist/vars.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-owned retry for automind's `page_not_ready` (HTTP 409) answer.
|
|
3
|
+
*
|
|
4
|
+
* The VQE does NOT retry internally. When the vision model reports an active
|
|
5
|
+
* loader, auteur-automind returns `{"error": "page_not_ready", ...}`
|
|
6
|
+
* (`app/services/vqe_service.py`) and the heal route maps it to **409** with an
|
|
7
|
+
* explicit contract (`app/api/endpoints/healer.py`):
|
|
8
|
+
*
|
|
9
|
+
* # 409 is pragmatic (outside tenacity's 5xx retry set) — client
|
|
10
|
+
* # owns the retry loop; do NOT switch this to a 5xx.
|
|
11
|
+
*
|
|
12
|
+
* Retrying inside the HTTP layer would re-POST the *same stale screenshot* and
|
|
13
|
+
* could never observe a settled page, so the budget has to wrap the screenshot
|
|
14
|
+
* capture — which is what `retryOnPageNotReady` does.
|
|
15
|
+
*
|
|
16
|
+
* Port of the V2 source
|
|
17
|
+
* (`_is_page_not_ready_response` + the `Heal.vision_query` loop): 3 POSTs,
|
|
18
|
+
* 3s between them, a fresh screenshot and a fresh `request_id` every attempt.
|
|
19
|
+
*/
|
|
20
|
+
import { randomUUID } from 'node:crypto';
|
|
21
|
+
import { log } from '../log.js';
|
|
22
|
+
/** Body discriminator automind sets when the VQE saw an active loader. */
|
|
23
|
+
export const PAGE_NOT_READY_ERROR = 'page_not_ready';
|
|
24
|
+
/** Status automind pairs with it (picked to sit outside the transport retry set). */
|
|
25
|
+
export const PAGE_NOT_READY_STATUS = 409;
|
|
26
|
+
/** Total POSTs per vision call (V2 parity). */
|
|
27
|
+
export const MAX_ATTEMPTS = 3;
|
|
28
|
+
/** Delay between attempts. The final attempt is not followed by a sleep. */
|
|
29
|
+
export const SLEEP_MS = 3000;
|
|
30
|
+
/**
|
|
31
|
+
* Fresh per-attempt id so every retry lands in its own automind VQE debug
|
|
32
|
+
* folder (`{org_id}/vqe/{request_id}`) instead of overwriting the last one.
|
|
33
|
+
*/
|
|
34
|
+
export function newRequestId() {
|
|
35
|
+
return randomUUID().replace(/-/g, '').slice(0, 16);
|
|
36
|
+
}
|
|
37
|
+
/** True when a parsed heal response carries the loader signal. */
|
|
38
|
+
export function isPageNotReadyBody(body) {
|
|
39
|
+
return (typeof body === 'object' &&
|
|
40
|
+
body !== null &&
|
|
41
|
+
body['error'] === PAGE_NOT_READY_ERROR);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Terminal message for an exhausted budget, preserving loader diagnostics.
|
|
45
|
+
*
|
|
46
|
+
* Keeps the literal `page_not_ready` substring: auteur's
|
|
47
|
+
* `selenium_test_agent/llm/code_generation.py` routes on
|
|
48
|
+
* `"page_not_ready" in str(e)` to surface PAGE_NOT_READY_AFTER_RETRIES rather
|
|
49
|
+
* than a generic action failure.
|
|
50
|
+
*/
|
|
51
|
+
export function pageNotReadyMessage(prefix, body) {
|
|
52
|
+
const b = (typeof body === 'object' && body !== null ? body : {});
|
|
53
|
+
const loaderReason = b['loader_reason'] ?? '';
|
|
54
|
+
const attempts = b['attempts'] ?? '';
|
|
55
|
+
return (`${prefix}: ${PAGE_NOT_READY_ERROR} ` +
|
|
56
|
+
`(loader_reason=${JSON.stringify(String(loaderReason))}, attempts=${String(attempts)}, ` +
|
|
57
|
+
`client_attempts=${MAX_ATTEMPTS})`);
|
|
58
|
+
}
|
|
59
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
60
|
+
/**
|
|
61
|
+
* Run `attemptFn()` until it stops answering `page_not_ready`.
|
|
62
|
+
*
|
|
63
|
+
* `attemptFn` MUST re-capture the screenshot on every call — retrying above the
|
|
64
|
+
* transport layer is only useful because attempt N+1 observes a fresh page.
|
|
65
|
+
*
|
|
66
|
+
* Returns the last parsed body, which may still carry the loader error when the
|
|
67
|
+
* budget is exhausted; the caller raises from it so `loader_reason` survives
|
|
68
|
+
* into the step error.
|
|
69
|
+
*/
|
|
70
|
+
export async function retryOnPageNotReady(attemptFn, label = 'vision') {
|
|
71
|
+
let result = await attemptFn();
|
|
72
|
+
for (let attempt = 1; attempt < MAX_ATTEMPTS; attempt++) {
|
|
73
|
+
if (!isPageNotReadyBody(result))
|
|
74
|
+
return result;
|
|
75
|
+
log.helper(`${label} :: page_not_ready (attempt ${attempt}/${MAX_ATTEMPTS}), waiting ` +
|
|
76
|
+
`${SLEEP_MS / 1000}s and retrying with a fresh screenshot`);
|
|
77
|
+
await sleep(SLEEP_MS);
|
|
78
|
+
result = await attemptFn();
|
|
79
|
+
}
|
|
80
|
+
if (isPageNotReadyBody(result)) {
|
|
81
|
+
log.helper(`${label} :: page_not_ready after ${MAX_ATTEMPTS} attempts — giving up`);
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=pageReady.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageReady.js","sourceRoot":"","sources":["../../src/helpers/pageReady.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,0EAA0E;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AACrD,qFAAqF;AACrF,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AACzC,+CAA+C;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAC9B,4EAA4E;AAC5E,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC;AAE7B;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,UAAU,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACrD,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,kBAAkB,CAAC,IAAa;IAC9C,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,KAAK,IAAI;QACZ,IAAgC,CAAC,OAAO,CAAC,KAAK,oBAAoB,CACpE,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc,EAAE,IAAa;IAC/D,MAAM,CAAC,GAAG,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAA4B,CAAC;IAC7F,MAAM,YAAY,GAAG,CAAC,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IAC9C,MAAM,QAAQ,GAAG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NAPSHOT_ERROR = "Required runtime asset returned an invalid snapshot.";
|
|
3
|
+
/** Fixed Foreman asset path for the worker host OS. */
|
|
4
|
+
export declare function runtimeSnapshotAssetPath(platform?: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Read the host-provisioned snapshot implementation. Held in a mutable binding
|
|
7
|
+
* rather than called directly so unit tests can substitute it — the proprietary
|
|
8
|
+
* runtime asset only exists on a provisioned worker, so tests must never need
|
|
9
|
+
* the real file. (An ESM `import` binding cannot be spied on from outside.)
|
|
10
|
+
*/
|
|
11
|
+
export declare function readRuntimeSnapshotAsset(): string;
|
|
12
|
+
/** Test seam — substitute the asset reader. Pass nothing to restore the real one. */
|
|
13
|
+
export declare function _setRuntimeSnapshotReader(fn?: () => string): void;
|
|
14
|
+
/** Load the provisioned implementation once, on first use. */
|
|
15
|
+
export declare function loadRuntimeSnapshotAsset(): string;
|
|
16
|
+
/** Test seam — drop the memoized source. */
|
|
17
|
+
export declare function _resetRuntimeSnapshotCache(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Wrap the provisioned IIFE, both snapshot calls, and the global cleanup into
|
|
20
|
+
* ONE page evaluation. Splitting define and invoke would break Firefox, whose
|
|
21
|
+
* sandboxes do not persist page globals between evaluations, and would leave the
|
|
22
|
+
* runtime's globals attached if the second call threw.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildRuntimeSnapshotExpression(source: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Validate the runtime's minimal CDP-shaped payload before it goes on the wire.
|
|
27
|
+
* A malformed snapshot must fail HERE with a clear message rather than as an
|
|
28
|
+
* opaque server-side error on the heal endpoint.
|
|
29
|
+
*/
|
|
30
|
+
export declare function validateRuntimeSnapshotPair(result: unknown): [unknown, unknown];
|
|
31
|
+
/** Best-effort local engine identity; a relay may report Chromium for all engines. */
|
|
32
|
+
export declare function browserEngineName(page: {
|
|
33
|
+
context(): {
|
|
34
|
+
browser(): {
|
|
35
|
+
browserType(): {
|
|
36
|
+
name(): string;
|
|
37
|
+
};
|
|
38
|
+
} | null;
|
|
39
|
+
};
|
|
40
|
+
}): string;
|
|
41
|
+
export type SnapshotRoute = 'runtime' | 'native' | 'unknown';
|
|
42
|
+
/**
|
|
43
|
+
* Which capture route this session takes.
|
|
44
|
+
*
|
|
45
|
+
* The REQUESTED browser name wins over the local engine identity: cloud runs go
|
|
46
|
+
* through a relay that reports Chromium regardless of the real engine, so
|
|
47
|
+
* trusting the engine alone would route a WebKit session into CDP. `unknown`
|
|
48
|
+
* means "try CDP, fall back on an explicit non-Chromium rejection".
|
|
49
|
+
*/
|
|
50
|
+
export declare function v3SnapshotCaptureRoute(page: Parameters<typeof browserEngineName>[0]): SnapshotRoute;
|
|
51
|
+
/** Playwright's explicit non-Chromium CDP rejection, and only that. */
|
|
52
|
+
export declare function isExplicitUnsupportedCdpError(error: unknown): boolean;
|
|
53
|
+
/** Errors that must keep their original Playwright diagnostics. */
|
|
54
|
+
export declare function isPageLifecycleOrTransportError(error: unknown): boolean;
|
|
55
|
+
/** Capture both snapshots through the provisioned runtime. */
|
|
56
|
+
export declare function captureSnapshotsWithRuntimeAsset(page: {
|
|
57
|
+
evaluate(fn: string): Promise<unknown>;
|
|
58
|
+
}): Promise<[unknown, unknown]>;
|
|
59
|
+
//# sourceMappingURL=runtimeSnapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeSnapshot.d.ts","sourceRoot":"","sources":["../../src/helpers/runtimeSnapshot.ts"],"names":[],"mappings":"AAyCA,eAAO,MAAM,2BAA2B,gDAAgD,CAAC;AACzF,eAAO,MAAM,8BAA8B,yDAAyD,CAAC;AAErG,uDAAuD;AACvD,wBAAgB,wBAAwB,CAAC,QAAQ,GAAE,MAAyB,GAAG,MAAM,CAKpF;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAEjD;AAKD,qFAAqF;AACrF,wBAAgB,yBAAyB,CAAC,EAAE,CAAC,EAAE,MAAM,MAA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but the TS capability builder
|
|
5
|
+
* maps `safari → pw-webkit` and `firefox → pw-firefox`, so a WebKit or Firefox
|
|
6
|
+
* grid session reaches the V3 textual-query path and cannot take the CDP route.
|
|
7
|
+
* Those sessions read the snapshot implementation that the test worker
|
|
8
|
+
* provisions on disk and evaluate it in the page instead.
|
|
9
|
+
*
|
|
10
|
+
* This mirrors `playwright-python/testmu/_helpers/vision.py` (and the
|
|
11
|
+
* selenium-python / selenium-java / playwright-csharp equivalents), which read
|
|
12
|
+
* the same Foreman asset rather than embedding the bundle in the package — the
|
|
13
|
+
* bindings ship via npm/pip/Maven/NuGet with no asset-delivery path of their own,
|
|
14
|
+
* and the runtime is proprietary and versioned with the worker, not the binding.
|
|
15
|
+
*/
|
|
16
|
+
import { readFileSync } from 'node:fs';
|
|
17
|
+
import { log } from '../log.js';
|
|
18
|
+
const LINUX_ASSET_PATH = '/home/ltuser/foreman/ltuser/aria_snapshot.js';
|
|
19
|
+
const MACOS_ASSET_PATH = '/Users/ltuser/foreman/ltuser/aria_snapshot.js';
|
|
20
|
+
const WINDOWS_ASSET_PATH = 'D:/foreman/ltuser/aria_snapshot.js';
|
|
21
|
+
/**
|
|
22
|
+
* Globals the provisioned runtime attaches to `globalThis`. Deleted after every
|
|
23
|
+
* capture so a page under test never observes them — the snapshot must not be
|
|
24
|
+
* able to change what it is snapshotting.
|
|
25
|
+
*/
|
|
26
|
+
const RUNTIME_GLOBALS = [
|
|
27
|
+
'__ariaSnapshot',
|
|
28
|
+
'__ariaSnapshotDetails',
|
|
29
|
+
'__ariaSnapshotJSON',
|
|
30
|
+
'__ariaSnapshotCDP',
|
|
31
|
+
'__ariaSnapshotRaw',
|
|
32
|
+
'__domSnapshot',
|
|
33
|
+
'__domSnapshotCDP',
|
|
34
|
+
'__resolveDomSnapshotNode',
|
|
35
|
+
'__domSnapshotRaw',
|
|
36
|
+
'__domSnapshotRefs',
|
|
37
|
+
'__aria_snap_dom_streamer__',
|
|
38
|
+
];
|
|
39
|
+
export const MISSING_RUNTIME_ASSET_ERROR = 'Required runtime asset was not provisioned.';
|
|
40
|
+
export const INVALID_RUNTIME_SNAPSHOT_ERROR = 'Required runtime asset returned an invalid snapshot.';
|
|
41
|
+
/** Fixed Foreman asset path for the worker host OS. */
|
|
42
|
+
export function runtimeSnapshotAssetPath(platform = process.platform) {
|
|
43
|
+
const p = String(platform).toLowerCase();
|
|
44
|
+
if (p === 'darwin')
|
|
45
|
+
return MACOS_ASSET_PATH;
|
|
46
|
+
if (p.startsWith('win'))
|
|
47
|
+
return WINDOWS_ASSET_PATH;
|
|
48
|
+
return LINUX_ASSET_PATH;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Read the host-provisioned snapshot implementation. Held in a mutable binding
|
|
52
|
+
* rather than called directly so unit tests can substitute it — the proprietary
|
|
53
|
+
* runtime asset only exists on a provisioned worker, so tests must never need
|
|
54
|
+
* the real file. (An ESM `import` binding cannot be spied on from outside.)
|
|
55
|
+
*/
|
|
56
|
+
export function readRuntimeSnapshotAsset() {
|
|
57
|
+
return readFileSync(runtimeSnapshotAssetPath(), 'utf-8');
|
|
58
|
+
}
|
|
59
|
+
let reader = readRuntimeSnapshotAsset;
|
|
60
|
+
let cachedSource = null;
|
|
61
|
+
/** Test seam — substitute the asset reader. Pass nothing to restore the real one. */
|
|
62
|
+
export function _setRuntimeSnapshotReader(fn) {
|
|
63
|
+
reader = fn ?? readRuntimeSnapshotAsset;
|
|
64
|
+
cachedSource = null;
|
|
65
|
+
}
|
|
66
|
+
/** Load the provisioned implementation once, on first use. */
|
|
67
|
+
export function loadRuntimeSnapshotAsset() {
|
|
68
|
+
if (cachedSource !== null)
|
|
69
|
+
return cachedSource;
|
|
70
|
+
let source;
|
|
71
|
+
try {
|
|
72
|
+
source = reader();
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
throw new Error(MISSING_RUNTIME_ASSET_ERROR);
|
|
76
|
+
}
|
|
77
|
+
if (source.trim() === '')
|
|
78
|
+
throw new Error(MISSING_RUNTIME_ASSET_ERROR);
|
|
79
|
+
cachedSource = source;
|
|
80
|
+
return source;
|
|
81
|
+
}
|
|
82
|
+
/** Test seam — drop the memoized source. */
|
|
83
|
+
export function _resetRuntimeSnapshotCache() {
|
|
84
|
+
cachedSource = null;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Wrap the provisioned IIFE, both snapshot calls, and the global cleanup into
|
|
88
|
+
* ONE page evaluation. Splitting define and invoke would break Firefox, whose
|
|
89
|
+
* sandboxes do not persist page globals between evaluations, and would leave the
|
|
90
|
+
* runtime's globals attached if the second call threw.
|
|
91
|
+
*/
|
|
92
|
+
export function buildRuntimeSnapshotExpression(source) {
|
|
93
|
+
const cleanupKeys = RUNTIME_GLOBALS.map((key) => JSON.stringify(key)).join(', ');
|
|
94
|
+
return `() => {
|
|
95
|
+
const cleanupKeys = [${cleanupKeys}];
|
|
96
|
+
try {
|
|
97
|
+
${source}
|
|
98
|
+
return {
|
|
99
|
+
a11y_snapshot: globalThis.__ariaSnapshotCDP(),
|
|
100
|
+
dom_snapshot: globalThis.__domSnapshotCDP(),
|
|
101
|
+
};
|
|
102
|
+
} finally {
|
|
103
|
+
for (const key of cleanupKeys) {
|
|
104
|
+
try { delete globalThis[key]; } catch (_) {}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}`;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Validate the runtime's minimal CDP-shaped payload before it goes on the wire.
|
|
111
|
+
* A malformed snapshot must fail HERE with a clear message rather than as an
|
|
112
|
+
* opaque server-side error on the heal endpoint.
|
|
113
|
+
*/
|
|
114
|
+
export function validateRuntimeSnapshotPair(result) {
|
|
115
|
+
const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
116
|
+
if (!isRecord(result))
|
|
117
|
+
throw new Error(INVALID_RUNTIME_SNAPSHOT_ERROR);
|
|
118
|
+
const a11ySnapshot = result['a11y_snapshot'];
|
|
119
|
+
const domSnapshot = result['dom_snapshot'];
|
|
120
|
+
const documents = isRecord(domSnapshot) ? domSnapshot['documents'] : undefined;
|
|
121
|
+
const firstDocument = Array.isArray(documents) ? documents[0] : undefined;
|
|
122
|
+
if (!isRecord(a11ySnapshot) ||
|
|
123
|
+
!Array.isArray(a11ySnapshot['nodes']) ||
|
|
124
|
+
!isRecord(domSnapshot) ||
|
|
125
|
+
!Array.isArray(documents) ||
|
|
126
|
+
documents.length === 0 ||
|
|
127
|
+
!Array.isArray(domSnapshot['strings']) ||
|
|
128
|
+
!isRecord(firstDocument) ||
|
|
129
|
+
!isRecord(firstDocument['nodes']) ||
|
|
130
|
+
!isRecord(firstDocument['layout'])) {
|
|
131
|
+
throw new Error(INVALID_RUNTIME_SNAPSHOT_ERROR);
|
|
132
|
+
}
|
|
133
|
+
return [a11ySnapshot, domSnapshot];
|
|
134
|
+
}
|
|
135
|
+
/** Best-effort local engine identity; a relay may report Chromium for all engines. */
|
|
136
|
+
export function browserEngineName(page) {
|
|
137
|
+
try {
|
|
138
|
+
const name = page.context().browser()?.browserType().name();
|
|
139
|
+
return String(name ?? '').trim().toLowerCase();
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return '';
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Which capture route this session takes.
|
|
147
|
+
*
|
|
148
|
+
* The REQUESTED browser name wins over the local engine identity: cloud runs go
|
|
149
|
+
* through a relay that reports Chromium regardless of the real engine, so
|
|
150
|
+
* trusting the engine alone would route a WebKit session into CDP. `unknown`
|
|
151
|
+
* means "try CDP, fall back on an explicit non-Chromium rejection".
|
|
152
|
+
*/
|
|
153
|
+
export function v3SnapshotCaptureRoute(page) {
|
|
154
|
+
const requested = (process.env['smart_browser_name'] ?? '').trim().toLowerCase();
|
|
155
|
+
if (requested === 'pw-webkit' || requested === 'pw-firefox')
|
|
156
|
+
return 'runtime';
|
|
157
|
+
if (['chrome', 'chromium', 'googlechrome', 'microsoftedge', 'edge', 'pw-chromium', 'island']
|
|
158
|
+
.includes(requested)) {
|
|
159
|
+
return 'native';
|
|
160
|
+
}
|
|
161
|
+
if (requested !== '')
|
|
162
|
+
return 'unknown';
|
|
163
|
+
const engine = browserEngineName(page);
|
|
164
|
+
if (engine === 'webkit' || engine === 'firefox')
|
|
165
|
+
return 'runtime';
|
|
166
|
+
if (engine === 'chromium')
|
|
167
|
+
return 'native';
|
|
168
|
+
return 'unknown';
|
|
169
|
+
}
|
|
170
|
+
/** Playwright's explicit non-Chromium CDP rejection, and only that. */
|
|
171
|
+
export function isExplicitUnsupportedCdpError(error) {
|
|
172
|
+
const message = String(error instanceof Error ? error.message : error).toLowerCase();
|
|
173
|
+
const exclusivity = message.includes('only supported') || message.includes('only available');
|
|
174
|
+
return message.includes('cdp') && message.includes('chromium') && exclusivity;
|
|
175
|
+
}
|
|
176
|
+
/** Errors that must keep their original Playwright diagnostics. */
|
|
177
|
+
export function isPageLifecycleOrTransportError(error) {
|
|
178
|
+
const message = String(error instanceof Error ? error.message : error).toLowerCase();
|
|
179
|
+
return [
|
|
180
|
+
'page closed',
|
|
181
|
+
'context closed',
|
|
182
|
+
'browser closed',
|
|
183
|
+
'target closed',
|
|
184
|
+
'websocket',
|
|
185
|
+
'connection closed',
|
|
186
|
+
'navigation',
|
|
187
|
+
].some((marker) => message.includes(marker));
|
|
188
|
+
}
|
|
189
|
+
/** Capture both snapshots through the provisioned runtime. */
|
|
190
|
+
export async function captureSnapshotsWithRuntimeAsset(page) {
|
|
191
|
+
const source = loadRuntimeSnapshotAsset();
|
|
192
|
+
log.helper('[snapshot] capturing via provisioned runtime asset (non-CDP engine)');
|
|
193
|
+
let result;
|
|
194
|
+
try {
|
|
195
|
+
result = await page.evaluate(buildRuntimeSnapshotExpression(source));
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
if (isPageLifecycleOrTransportError(err))
|
|
199
|
+
throw err;
|
|
200
|
+
throw new Error(INVALID_RUNTIME_SNAPSHOT_ERROR);
|
|
201
|
+
}
|
|
202
|
+
return validateRuntimeSnapshotPair(result);
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=runtimeSnapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeSnapshot.js","sourceRoot":"","sources":["../../src/helpers/runtimeSnapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,MAAM,gBAAgB,GAAG,8CAA8C,CAAC;AACxE,MAAM,gBAAgB,GAAG,+CAA+C,CAAC;AACzE,MAAM,kBAAkB,GAAG,oCAAoC,CAAC;AAEhE;;;;GAIG;AACH,MAAM,eAAe,GAAG;IACtB,gBAAgB;IAChB,uBAAuB;IACvB,oBAAoB;IACpB,mBAAmB;IACnB,mBAAmB;IACnB,eAAe;IACf,kBAAkB;IAClB,0BAA0B;IAC1B,kBAAkB;IAClB,mBAAmB;IACnB,4BAA4B;CACpB,CAAC;AAEX,MAAM,CAAC,MAAM,2BAA2B,GAAG,6CAA6C,CAAC;AACzF,MAAM,CAAC,MAAM,8BAA8B,GAAG,sDAAsD,CAAC;AAErG,uDAAuD;AACvD,MAAM,UAAU,wBAAwB,CAAC,WAAmB,OAAO,CAAC,QAAQ;IAC1E,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IACzC,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAO,gBAAgB,CAAC;IAC5C,IAAI,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,kBAAkB,CAAC;IACnD,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB;IACtC,OAAO,YAAY,CAAC,wBAAwB,EAAE,EAAE,OAAO,CAAC,CAAC;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Q,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,WAAW,CAAC;AAChF,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,+BAA+B,CAAC,KAAc;IAC5D,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IACrF,OAAO;QACL,aAAa;QACb,gBAAgB;QAChB,gBAAgB;QAChB,eAAe;QACf,WAAW;QACX,mBAAmB;QACnB,YAAY;KACb,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,8DAA8D;AAC9D,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,IAAgD;IAEhD,MAAM,MAAM,GAAG,wBAAwB,EAAE,CAAC;IAC1C,GAAG,CAAC,MAAM,CAAC,qEAAqE,CAAC,CAAC;IAClF,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,8BAA8B,CAAC,MAAM,CAAC,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,+BAA+B,CAAC,GAAG,CAAC;YAAE,MAAM,GAAG,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,2BAA2B,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fence captured values spliced into a VQE vision query.
|
|
3
|
+
*
|
|
4
|
+
* automind's vision model reads the query as prose. A multi-line or list value substituted inline
|
|
5
|
+
* runs together with the surrounding words, and the model binds the predicate to the LAST line
|
|
6
|
+
* instead of the whole captured block — a confident, wrong verdict.
|
|
7
|
+
*
|
|
8
|
+
* Fencing wraps each substituted value in triple quotes so the whole block reads as one reference.
|
|
9
|
+
*
|
|
10
|
+
* Vision-query text ONLY. This deliberately lives beside the vision helper rather than inside the
|
|
11
|
+
* shared variable resolver: fencing an ordinary variable read would put quote characters into
|
|
12
|
+
* typed values, assertion operands and fill text.
|
|
13
|
+
*
|
|
14
|
+
* Port of V2 (_fence_vision_query_value).
|
|
15
|
+
*/
|
|
16
|
+
/** Wrap one substituted value in a triple-quoted block. */
|
|
17
|
+
export declare function fenceValue(rendered: unknown): string;
|
|
18
|
+
/**
|
|
19
|
+
* Resolve every template in `description`, fencing each substituted value.
|
|
20
|
+
*
|
|
21
|
+
* Each token is resolved in isolation through `resolver` (the package's own `resolveVar`), so
|
|
22
|
+
* namespace dispatch, defaults and traversal behave exactly as they do everywhere else — only the
|
|
23
|
+
* rendering differs.
|
|
24
|
+
*
|
|
25
|
+
* A token the resolver cannot resolve is left as the literal `{{name}}` and is NOT fenced: an
|
|
26
|
+
* unresolved name must stay visible so the failure is legible rather than buried in quotes.
|
|
27
|
+
*
|
|
28
|
+
* Resolvers disagree on how they signal "unresolved" — some hand back the literal token, others an
|
|
29
|
+
* empty/nullish result — so all are treated as unresolved. The cost is that a variable holding a
|
|
30
|
+
* genuinely empty value also renders as its literal token, which is the better failure anyway: an
|
|
31
|
+
* empty fenced block tells the vision model nothing, while a visible `{{name}}` shows what was
|
|
32
|
+
* missing.
|
|
33
|
+
*/
|
|
34
|
+
export declare function fenceTemplates(description: unknown, resolver: (token: string) => Promise<unknown>): Promise<unknown>;
|
|
35
|
+
//# sourceMappingURL=visionFence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visionFence.d.ts","sourceRoot":"","sources":["../../src/helpers/visionFence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,2DAA2D;AAC3D,wBAAgB,UAAU,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAEpD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,OAAO,EACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAC5C,OAAO,CAAC,OAAO,CAAC,CAkBlB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fence captured values spliced into a VQE vision query.
|
|
3
|
+
*
|
|
4
|
+
* automind's vision model reads the query as prose. A multi-line or list value substituted inline
|
|
5
|
+
* runs together with the surrounding words, and the model binds the predicate to the LAST line
|
|
6
|
+
* instead of the whole captured block — a confident, wrong verdict.
|
|
7
|
+
*
|
|
8
|
+
* Fencing wraps each substituted value in triple quotes so the whole block reads as one reference.
|
|
9
|
+
*
|
|
10
|
+
* Vision-query text ONLY. This deliberately lives beside the vision helper rather than inside the
|
|
11
|
+
* shared variable resolver: fencing an ordinary variable read would put quote characters into
|
|
12
|
+
* typed values, assertion operands and fill text.
|
|
13
|
+
*
|
|
14
|
+
* Port of V2 (_fence_vision_query_value).
|
|
15
|
+
*/
|
|
16
|
+
/** Matches the two template forms the resolver understands. */
|
|
17
|
+
const TEMPLATE_RE = /\{\{[^{}]+\}\}|\$\{[^{}]+\}/g;
|
|
18
|
+
/** Wrap one substituted value in a triple-quoted block. */
|
|
19
|
+
export function fenceValue(rendered) {
|
|
20
|
+
return `\n"""\n${String(rendered)}\n"""\n`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolve every template in `description`, fencing each substituted value.
|
|
24
|
+
*
|
|
25
|
+
* Each token is resolved in isolation through `resolver` (the package's own `resolveVar`), so
|
|
26
|
+
* namespace dispatch, defaults and traversal behave exactly as they do everywhere else — only the
|
|
27
|
+
* rendering differs.
|
|
28
|
+
*
|
|
29
|
+
* A token the resolver cannot resolve is left as the literal `{{name}}` and is NOT fenced: an
|
|
30
|
+
* unresolved name must stay visible so the failure is legible rather than buried in quotes.
|
|
31
|
+
*
|
|
32
|
+
* Resolvers disagree on how they signal "unresolved" — some hand back the literal token, others an
|
|
33
|
+
* empty/nullish result — so all are treated as unresolved. The cost is that a variable holding a
|
|
34
|
+
* genuinely empty value also renders as its literal token, which is the better failure anyway: an
|
|
35
|
+
* empty fenced block tells the vision model nothing, while a visible `{{name}}` shows what was
|
|
36
|
+
* missing.
|
|
37
|
+
*/
|
|
38
|
+
export async function fenceTemplates(description, resolver) {
|
|
39
|
+
if (typeof description !== 'string')
|
|
40
|
+
return description;
|
|
41
|
+
const tokens = description.match(TEMPLATE_RE);
|
|
42
|
+
if (!tokens)
|
|
43
|
+
return description;
|
|
44
|
+
let out = '';
|
|
45
|
+
let cursor = 0;
|
|
46
|
+
TEMPLATE_RE.lastIndex = 0;
|
|
47
|
+
for (let m = TEMPLATE_RE.exec(description); m !== null; m = TEMPLATE_RE.exec(description)) {
|
|
48
|
+
const token = m[0];
|
|
49
|
+
const resolved = await resolver(token);
|
|
50
|
+
// Unresolved: the literal token back, or an empty/nullish result (see above).
|
|
51
|
+
const unresolved = resolved === token || resolved === null || resolved === undefined || resolved === '';
|
|
52
|
+
const rendered = unresolved ? token : fenceValue(resolved);
|
|
53
|
+
out += description.slice(cursor, m.index) + rendered;
|
|
54
|
+
cursor = m.index + token.length;
|
|
55
|
+
}
|
|
56
|
+
return out + description.slice(cursor);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=visionFence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visionFence.js","sourceRoot":"","sources":["../../src/helpers/visionFence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,+DAA+D;AAC/D,MAAM,WAAW,GAAG,8BAA8B,CAAC;AAEnD,2DAA2D;AAC3D,MAAM,UAAU,UAAU,CAAC,QAAiB;IAC1C,OAAO,UAAU,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;AAC7C,CAAC;AAED;;;;;;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junk store is worse than a loud step fail).
|
|
25
25
|
*/
|
|
26
26
|
export declare function visionQueryV3(page: Page, description: string, returnType: string, codeJs?: string): Promise<unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Capture the V3 server snapshots by whichever route this session supports
|
|
29
|
+
*.
|
|
30
|
+
*
|
|
31
|
+
* `newCDPSession` is Chromium-only, but capability.ts maps `safari → pw-webkit`
|
|
32
|
+
* and `firefox → pw-firefox`, so those sessions reach this path and previously
|
|
33
|
+
* died on the CDP call. They take the worker-provisioned aria-snap runtime
|
|
34
|
+
* instead — same route the Python/Java/C# bindings already use.
|
|
35
|
+
*
|
|
36
|
+
* The `unknown` route tries CDP first and falls back ONLY on Playwright's
|
|
37
|
+
* explicit non-Chromium rejection: any other CDP failure is a real error and
|
|
38
|
+
* must keep its own diagnostics rather than being masked by a second attempt.
|
|
39
|
+
*/
|
|
40
|
+
export declare function captureV3ServerSnapshots(page: Page): Promise<[unknown, unknown]>;
|
|
27
41
|
/**
|
|
28
42
|
* V3 textual query — locate element locally then read the attribute, with the
|
|
29
43
|
* server POST as last-resort fallback (PY _textual_query_v3 route table):
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visionV3.d.ts","sourceRoot":"","sources":["../../src/helpers/visionV3.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"visionV3.d.ts","sourceRoot":"","sources":["../../src/helpers/visionV3.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAyBvC,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AACrD,eAAO,MAAM,0BAA0B,2BAA2B,CAAC;AAenE;qEACqE;AACrE,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAejF;AAED;6EAC6E;AAC7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