gz-laya-pilot 0.1.1 → 0.1.2
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/NOTICE.md +14 -0
- package/README.md +25 -3
- package/dist/agent/bridge.js +1 -1
- package/dist/agent/bridge.js.map +1 -1
- package/dist/agent/report.d.ts +3 -0
- package/dist/agent/report.js +11 -2
- package/dist/agent/report.js.map +1 -1
- package/dist/agent/schema.d.ts +10 -0
- package/dist/agent/schema.js.map +1 -1
- package/package.json +1 -1
- package/src/agent/bridge.ts +1 -1
- package/src/agent/report.ts +15 -2
- package/src/agent/schema.ts +5 -0
- package/vendor/.gitattributes +1 -0
- package/vendor/UPSTREAM.json +94 -5
- package/vendor/laya-pilot/lib/browser-provider.mjs +18 -6
- package/vendor/laya-pilot/lib/discovery.mjs +182 -31
- package/vendor/laya-pilot/lib/dom.mjs +65 -2
- package/vendor/laya-pilot/lib/form.mjs +3 -3
- package/vendor/laya-pilot/lib/page-capabilities.mjs +356 -0
- package/vendor/laya-pilot/lib/page-exploration.mjs +372 -0
- package/vendor/laya-pilot/lib/page-session.mjs +69 -0
- package/vendor/laya-pilot/lib/related-records.mjs +328 -0
- package/vendor/laya-pilot/lib/run-state.mjs +15 -1
- package/vendor/laya-pilot/lib/test-data.mjs +15 -2
- package/vendor/laya-pilot/lib/workflow-policy.mjs +8 -1
- package/vendor/laya-pilot/lib/workflow.mjs +536 -121
- package/vendor/laya-pilot/lib/workflow_excel.py +33 -2
- package/vendor/laya-pilot/tests/retries.test.mjs +14 -1
- package/vendor/laya-pilot/tests/selected-pr1.test.mjs +21 -3
- package/vendor/patches/0001-native-field-recipes.patch +2966 -14
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
// Bounded extensions to the upstream workflow. Standard page semantics plus
|
|
2
|
+
// upstream component compatibility; no business routes, labels or second planner.
|
|
3
|
+
import { randomBytes } from 'node:crypto';
|
|
4
|
+
import { waitForVisibleStep } from './page-session.mjs';
|
|
5
|
+
|
|
6
|
+
export const MODAL =
|
|
7
|
+
'dialog[open],[role="dialog"],[role="alertdialog"],[data-slot="dialog-content"],[data-slot="alert-dialog-content"],.ant-drawer-open .ant-drawer-content,.el-dialog';
|
|
8
|
+
export const EDITOR = '[data-laya-editor-root]';
|
|
9
|
+
export const FORM_ROOT = `${EDITOR},${MODAL}`;
|
|
10
|
+
const TREE_REF = 'data-laya-tree-ref';
|
|
11
|
+
const SAVE = /保存|提交|\bsave\b|\bsubmit\b/i;
|
|
12
|
+
const CREATE = /新增|新建|创建|添加|\badd\b|\bnew\b|\bcreate\b/i;
|
|
13
|
+
const RECORD_TREE = '[role="tree"]:not(nav *,[role="navigation"] *,header *,[role="banner"] *)';
|
|
14
|
+
export const COLLECTION = `table:visible,[role="grid"]:visible,${RECORD_TREE}:visible`;
|
|
15
|
+
|
|
16
|
+
export const recordTrees = (page) => page.locator(RECORD_TREE).filter({ visible: true });
|
|
17
|
+
|
|
18
|
+
export function formRoot(page) {
|
|
19
|
+
const modal = page.locator(MODAL).filter({ visible: true });
|
|
20
|
+
return page
|
|
21
|
+
.locator(EDITOR)
|
|
22
|
+
.filter({ visible: true })
|
|
23
|
+
.filter({ hasNot: modal })
|
|
24
|
+
.or(modal)
|
|
25
|
+
.last();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Called only after a create/edit action. A filter form alone never activates an editor.
|
|
29
|
+
export async function activateEditor(page, timeout = 4000) {
|
|
30
|
+
const deadline = Date.now() + timeout;
|
|
31
|
+
do {
|
|
32
|
+
if (await formRoot(page).count()) return;
|
|
33
|
+
const roots = await page.evaluate(
|
|
34
|
+
({ attr, source }) => {
|
|
35
|
+
const visible = (e) =>
|
|
36
|
+
!!(e.getBoundingClientRect().width && e.getBoundingClientRect().height) &&
|
|
37
|
+
getComputedStyle(e).visibility !== 'hidden' &&
|
|
38
|
+
!e.closest('[hidden],[inert]');
|
|
39
|
+
const save = new RegExp(source, 'i');
|
|
40
|
+
const forms = [...document.querySelectorAll('form,[role="form"]')].filter(
|
|
41
|
+
(e) =>
|
|
42
|
+
visible(e) &&
|
|
43
|
+
e.querySelector(
|
|
44
|
+
'input[required],input[aria-required="true"],textarea[required],textarea[aria-required="true"]',
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
const roots = new Set();
|
|
48
|
+
for (const form of forms) {
|
|
49
|
+
const region = form.closest(
|
|
50
|
+
'[role="region"][aria-label],section[aria-label],main,[role="main"]',
|
|
51
|
+
);
|
|
52
|
+
const root = region || form;
|
|
53
|
+
const saves = [
|
|
54
|
+
...root.querySelectorAll('button,[role="button"],input[type="submit"]'),
|
|
55
|
+
].filter(
|
|
56
|
+
(e) =>
|
|
57
|
+
visible(e) &&
|
|
58
|
+
save.test(e.getAttribute('aria-label') || e.innerText || e.value || ''),
|
|
59
|
+
);
|
|
60
|
+
if (saves.length === 1 && forms.filter((f) => root.contains(f)).length === 1)
|
|
61
|
+
roots.add(root);
|
|
62
|
+
}
|
|
63
|
+
if (roots.size === 1) [...roots][0].setAttribute(attr, '');
|
|
64
|
+
return roots.size;
|
|
65
|
+
},
|
|
66
|
+
{ attr: 'data-laya-editor-root', source: SAVE.source },
|
|
67
|
+
);
|
|
68
|
+
if (roots > 1) throw Error('存在多个独立编辑表单,无法确定当前编辑区');
|
|
69
|
+
if (roots === 1) return;
|
|
70
|
+
await page.waitForTimeout(100);
|
|
71
|
+
} while (Date.now() < deadline);
|
|
72
|
+
throw Error('创建或修改入口未打开唯一可识别的表单(弹窗或独立编辑区)');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function sameRegion(a, b) {
|
|
76
|
+
if (a?.regionAmbiguous || b?.regionAmbiguous) return false;
|
|
77
|
+
if (a?.frame != null && b?.frame != null && a.frame !== b.frame) return false;
|
|
78
|
+
return (
|
|
79
|
+
(a?.region?.role || '') === (b?.region?.role || '') &&
|
|
80
|
+
(a?.region?.name || '') === (b?.region?.name || '')
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function verifyInput(w, control, value) {
|
|
85
|
+
// Input/change handlers may replace a DOM node. Re-observe the same semantic
|
|
86
|
+
// field for the postcondition; never re-submit a write or accept a stale ref.
|
|
87
|
+
const snap = await w.snapshot();
|
|
88
|
+
const matches = snap.controls.filter(
|
|
89
|
+
(c) =>
|
|
90
|
+
c.name === control.name &&
|
|
91
|
+
c.role === control.role &&
|
|
92
|
+
c.frame === control.frame &&
|
|
93
|
+
sameRegion(c, control) &&
|
|
94
|
+
!c.disabled &&
|
|
95
|
+
!c.readonly,
|
|
96
|
+
);
|
|
97
|
+
if (matches.length !== 1) throw Error('输入后无法唯一确认字段:' + control.name);
|
|
98
|
+
const current = matches[0];
|
|
99
|
+
const input = snap.frames[current.frame].locator(`[data-laya-live-ref="${current.ref}"]`);
|
|
100
|
+
if ((await input.inputValue()) !== value) throw Error('输入值没有进入' + control.name);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function recordRows(page, name) {
|
|
104
|
+
const table = page
|
|
105
|
+
.locator('table tbody tr:visible,[role="rowgroup"] [role="row"]:visible')
|
|
106
|
+
.filter({ has: page.getByText(name, { exact: true }) });
|
|
107
|
+
// Exact accessible record name prevents prefix collisions and parent-node matches.
|
|
108
|
+
return table.or(
|
|
109
|
+
recordTrees(page).getByRole('treeitem', { name, exact: true }).filter({ visible: true }),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function observeTree(page) {
|
|
114
|
+
return page.evaluate(
|
|
115
|
+
({ attr, nonce, selector }) => {
|
|
116
|
+
const visible = (e) =>
|
|
117
|
+
!!(e.getBoundingClientRect().width && e.getBoundingClientRect().height) &&
|
|
118
|
+
getComputedStyle(e).visibility !== 'hidden' &&
|
|
119
|
+
!e.closest('[hidden],[inert]');
|
|
120
|
+
const name = (e) =>
|
|
121
|
+
(
|
|
122
|
+
(e.getAttribute('aria-labelledby') || '')
|
|
123
|
+
.split(/\s+/)
|
|
124
|
+
.map((id) => e.getRootNode().getElementById(id)?.textContent || '')
|
|
125
|
+
.join(' ')
|
|
126
|
+
.trim() ||
|
|
127
|
+
e.getAttribute('aria-label') ||
|
|
128
|
+
''
|
|
129
|
+
)
|
|
130
|
+
.replace(/\s+/g, ' ')
|
|
131
|
+
.trim();
|
|
132
|
+
const trees = [...document.querySelectorAll(selector)].filter(visible);
|
|
133
|
+
if (trees.length > 1) throw Error('存在多个记录树,无法确定唯一探索范围');
|
|
134
|
+
if (trees.some((tree) => !name(tree) || name(tree).length > 150))
|
|
135
|
+
throw Error('记录树缺少明确的可访问名称或名称超过 150 字符');
|
|
136
|
+
return [...document.querySelectorAll('[role="treeitem"]')]
|
|
137
|
+
.filter((item) => visible(item) && trees.includes(item.closest('[role="tree"]')))
|
|
138
|
+
.map((item, i) => {
|
|
139
|
+
const tree = item.closest('[role="tree"]');
|
|
140
|
+
const path = [];
|
|
141
|
+
for (
|
|
142
|
+
let current = item;
|
|
143
|
+
current && current !== tree;
|
|
144
|
+
current = current.parentElement
|
|
145
|
+
)
|
|
146
|
+
if (current.getAttribute('role') === 'treeitem')
|
|
147
|
+
path.unshift(name(current));
|
|
148
|
+
if (path.some((n) => !n || n.length > 150) || path.length > 8)
|
|
149
|
+
throw Error(
|
|
150
|
+
'树节点路径缺少名称、名称超过 150 字符或超过 8 层,无法稳定回放',
|
|
151
|
+
);
|
|
152
|
+
const ref = nonce + '-' + i;
|
|
153
|
+
item.setAttribute(attr, ref);
|
|
154
|
+
return {
|
|
155
|
+
tree: name(tree),
|
|
156
|
+
path,
|
|
157
|
+
ref,
|
|
158
|
+
expanded: item.getAttribute('aria-expanded'),
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
{ attr: TREE_REF, nonce: randomBytes(4).toString('hex'), selector: RECORD_TREE },
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function validateTreeTarget(target, { allowRoot = false } = {}) {
|
|
167
|
+
if (
|
|
168
|
+
!target ||
|
|
169
|
+
typeof target.tree !== 'string' ||
|
|
170
|
+
!target.tree ||
|
|
171
|
+
target.tree.length > 150 ||
|
|
172
|
+
!Array.isArray(target.path) ||
|
|
173
|
+
(!allowRoot && !target.path.length) ||
|
|
174
|
+
target.path.length > 8 ||
|
|
175
|
+
target.path.some((n) => typeof n !== 'string' || !n || n.length > 150)
|
|
176
|
+
)
|
|
177
|
+
throw Error('树展开步骤缺少明确的树名称和节点路径');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export const sameTreePath = (a, b) =>
|
|
181
|
+
a?.tree === b?.tree &&
|
|
182
|
+
Array.isArray(a?.path) &&
|
|
183
|
+
Array.isArray(b?.path) &&
|
|
184
|
+
a.path.length === b.path.length &&
|
|
185
|
+
a.path.every((name, i) => name === b.path[i]);
|
|
186
|
+
|
|
187
|
+
// Store semantic ownership before navigation replaces the source DOM. Never
|
|
188
|
+
// persist child indexes, transient refs, CSS classes or the first matching name.
|
|
189
|
+
export async function captureTreePath(page, locator) {
|
|
190
|
+
if (!(await locator.evaluate((e) => !!e.closest('[role="tree"]')))) return undefined;
|
|
191
|
+
if (
|
|
192
|
+
!(await locator.evaluate(
|
|
193
|
+
(e, selector) => e.closest('[role="tree"]').matches(selector),
|
|
194
|
+
RECORD_TREE,
|
|
195
|
+
))
|
|
196
|
+
)
|
|
197
|
+
throw Error('全局导航树不能作为记录创建入口');
|
|
198
|
+
const nodes = await observeTree(page);
|
|
199
|
+
const owner = await locator.evaluate((e) => {
|
|
200
|
+
const item = e.closest('[role="treeitem"]');
|
|
201
|
+
return item ? { ref: item.getAttribute('data-laya-tree-ref') } : null;
|
|
202
|
+
});
|
|
203
|
+
if (owner) {
|
|
204
|
+
const node = nodes.find((n) => n.ref === owner.ref);
|
|
205
|
+
if (!node || nodes.filter((n) => sameTreePath(n, node)).length !== 1)
|
|
206
|
+
throw Error('创建入口所属树路径不唯一');
|
|
207
|
+
return { tree: node.tree, path: node.path };
|
|
208
|
+
}
|
|
209
|
+
const name = await recordTrees(page).evaluate(
|
|
210
|
+
(e) =>
|
|
211
|
+
(e.getAttribute('aria-labelledby') || '')
|
|
212
|
+
.split(/\s+/)
|
|
213
|
+
.map((id) => e.getRootNode().getElementById(id)?.textContent || '')
|
|
214
|
+
.join(' ')
|
|
215
|
+
.trim() ||
|
|
216
|
+
e.getAttribute('aria-label') ||
|
|
217
|
+
'',
|
|
218
|
+
);
|
|
219
|
+
return { tree: name.replace(/\s+/g, ' ').trim(), path: [] };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export async function expandTree(w, target, { record = true } = {}) {
|
|
223
|
+
validateTreeTarget(target);
|
|
224
|
+
const nodes = (await observeTree(w.page)).filter((n) => sameTreePath(n, target));
|
|
225
|
+
if (nodes.length !== 1) throw Error('树节点路径不唯一或已变化:' + target.path.join(' / '));
|
|
226
|
+
const node = nodes[0];
|
|
227
|
+
if (!['true', 'false'].includes(node.expanded)) throw Error('目标节点没有可展开状态');
|
|
228
|
+
const item = w.page.locator(`[${TREE_REF}="${node.ref}"]`);
|
|
229
|
+
if (node.expanded === 'false') {
|
|
230
|
+
// Only an expander owned by this node may be clicked, never an arbitrary child action.
|
|
231
|
+
const expanders = item.locator(
|
|
232
|
+
'button[aria-expanded="false"],[role="button"][aria-expanded="false"]',
|
|
233
|
+
);
|
|
234
|
+
const ownedCount = await expanders.evaluateAll(
|
|
235
|
+
(elements, ref) =>
|
|
236
|
+
elements.filter(
|
|
237
|
+
(e) =>
|
|
238
|
+
e.closest('[role="treeitem"]')?.getAttribute('data-laya-tree-ref') === ref,
|
|
239
|
+
).length,
|
|
240
|
+
node.ref,
|
|
241
|
+
);
|
|
242
|
+
if (ownedCount === 1) {
|
|
243
|
+
// Observe first so the existing model/locator binding can be reused.
|
|
244
|
+
const snap = await w.snapshot();
|
|
245
|
+
const candidates = [];
|
|
246
|
+
for (const c of snap.controls) {
|
|
247
|
+
const live = snap.frames[c.frame].locator(`[data-laya-live-ref="${c.ref}"]`);
|
|
248
|
+
if (
|
|
249
|
+
c.expanded === false &&
|
|
250
|
+
(await item.locator(`[data-laya-live-ref="${c.ref}"]`).count()) &&
|
|
251
|
+
(await live.evaluate((e) =>
|
|
252
|
+
e.closest('[role="treeitem"]')?.getAttribute('data-laya-tree-ref'),
|
|
253
|
+
)) === node.ref
|
|
254
|
+
)
|
|
255
|
+
candidates.push(c);
|
|
256
|
+
}
|
|
257
|
+
const found = await w.chooseFromSnapshot(
|
|
258
|
+
snap,
|
|
259
|
+
candidates,
|
|
260
|
+
'展开「' + target.path.at(-1) + '」',
|
|
261
|
+
);
|
|
262
|
+
await found.locator.click({ timeout: 4000 });
|
|
263
|
+
} else if (!ownedCount && (await item.getAttribute('tabindex')) !== null) {
|
|
264
|
+
await item.focus();
|
|
265
|
+
await item.press('ArrowRight');
|
|
266
|
+
} else throw Error('树节点没有唯一的语义展开控件');
|
|
267
|
+
const deadline = Date.now() + 3000;
|
|
268
|
+
let expanded = false;
|
|
269
|
+
do {
|
|
270
|
+
const live = (await observeTree(w.page)).filter((n) => sameTreePath(n, target));
|
|
271
|
+
expanded = live.length === 1 && live[0].expanded === 'true';
|
|
272
|
+
if (expanded) break;
|
|
273
|
+
await w.page.waitForTimeout(80);
|
|
274
|
+
} while (Date.now() < deadline);
|
|
275
|
+
if (!expanded) throw Error('点击后未证实树节点已展开:' + target.path.join(' / '));
|
|
276
|
+
await waitForVisibleStep(w);
|
|
277
|
+
}
|
|
278
|
+
if (record) w.record({ kind: 'expand-tree', target });
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export async function expandCollection(w, options) {
|
|
282
|
+
// Bounded structural navigation within the supplied module, not whole-site crawling.
|
|
283
|
+
for (let count = 0; count < 24; count++) {
|
|
284
|
+
w.checkInterrupted();
|
|
285
|
+
const node = (await observeTree(w.page)).find((n) => n.expanded === 'false');
|
|
286
|
+
if (!node) return;
|
|
287
|
+
await expandTree(w, { tree: node.tree, path: node.path }, options);
|
|
288
|
+
}
|
|
289
|
+
if ((await observeTree(w.page)).some((n) => n.expanded === 'false'))
|
|
290
|
+
throw Error('树探索达到 24 个展开节点上限,未将不完整列表视为成功');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export async function revealTreeActions(page, target) {
|
|
294
|
+
if (
|
|
295
|
+
target &&
|
|
296
|
+
!target.treePath &&
|
|
297
|
+
(await page
|
|
298
|
+
.getByRole(target.role, {
|
|
299
|
+
name: target.name,
|
|
300
|
+
exact: true,
|
|
301
|
+
})
|
|
302
|
+
.filter({ visible: true })
|
|
303
|
+
.count())
|
|
304
|
+
)
|
|
305
|
+
return;
|
|
306
|
+
const trees = recordTrees(page);
|
|
307
|
+
if (!(await trees.count())) {
|
|
308
|
+
if (target?.treePath) throw Error('记录的创建入口所属树已不存在');
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
// Validate the whole scope before hovering or clicking. Multiple independent
|
|
312
|
+
// collections and duplicate paths must not silently turn into "pick first".
|
|
313
|
+
await observeTree(page);
|
|
314
|
+
if (target?.treePath) validateTreeTarget(target.treePath, { allowRoot: true });
|
|
315
|
+
const roles = target ? [target.role] : ['button', 'link', 'menuitem'];
|
|
316
|
+
const create = roles
|
|
317
|
+
.map((role) =>
|
|
318
|
+
trees.getByRole(role, {
|
|
319
|
+
name: target?.name || CREATE,
|
|
320
|
+
exact: !!target?.name,
|
|
321
|
+
includeHidden: true,
|
|
322
|
+
}),
|
|
323
|
+
)
|
|
324
|
+
.reduce((all, locator) => all.or(locator));
|
|
325
|
+
const count = await create.count();
|
|
326
|
+
if (count > 24) throw Error('树创建入口超过 24 个观察上限');
|
|
327
|
+
const candidates = [];
|
|
328
|
+
for (let i = 0; i < count; i++) {
|
|
329
|
+
const button = create.nth(i);
|
|
330
|
+
if (await button.isDisabled()) continue;
|
|
331
|
+
const path = await captureTreePath(page, button);
|
|
332
|
+
if (!target?.treePath || sameTreePath(path, target.treePath)) candidates.push(button);
|
|
333
|
+
}
|
|
334
|
+
if (!candidates.length && !target?.treePath) return;
|
|
335
|
+
if (candidates.length !== 1) throw Error('树创建入口不唯一或所属路径已变化');
|
|
336
|
+
const button = candidates[0];
|
|
337
|
+
if (await button.isVisible()) return button;
|
|
338
|
+
// The trigger may sit above an invisible wrapper. Walk only within its
|
|
339
|
+
// owning tree node; never hover a sibling branch or assume one DOM level.
|
|
340
|
+
const ancestors = await button.evaluate((e) => {
|
|
341
|
+
const owner = e.closest('[role="treeitem"]') || e.closest('[role="tree"]');
|
|
342
|
+
let depth = 0;
|
|
343
|
+
for (let p = e.parentElement; p && depth < 12; p = p.parentElement) {
|
|
344
|
+
depth++;
|
|
345
|
+
if (p === owner) return depth;
|
|
346
|
+
}
|
|
347
|
+
throw Error('树操作入口嵌套超过 12 层,无法确定悬浮触发区');
|
|
348
|
+
});
|
|
349
|
+
let parent = button;
|
|
350
|
+
for (let i = 0; i < ancestors; i++) {
|
|
351
|
+
parent = parent.locator('..');
|
|
352
|
+
if (await parent.isVisible()) await parent.hover({ timeout: 1500 });
|
|
353
|
+
if (await button.isVisible()) return button;
|
|
354
|
+
}
|
|
355
|
+
throw Error('无法在所属树节点内显示创建入口');
|
|
356
|
+
}
|