gz-laya-pilot 0.1.0 → 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.
Files changed (95) hide show
  1. package/NOTICE.md +20 -2
  2. package/README.md +54 -2
  3. package/dist/agent/bridge.d.ts +21 -0
  4. package/dist/agent/bridge.js +158 -0
  5. package/dist/agent/bridge.js.map +1 -0
  6. package/dist/agent/report.d.ts +54 -0
  7. package/dist/agent/report.js +100 -0
  8. package/dist/agent/report.js.map +1 -0
  9. package/dist/agent/run.d.ts +19 -0
  10. package/dist/agent/run.js +121 -0
  11. package/dist/agent/run.js.map +1 -0
  12. package/dist/agent/schema.d.ts +42 -0
  13. package/dist/agent/schema.js +9 -0
  14. package/dist/agent/schema.js.map +1 -0
  15. package/dist/agent/worker.d.ts +1 -0
  16. package/dist/agent/worker.js +102 -0
  17. package/dist/agent/worker.js.map +1 -0
  18. package/dist/cli.d.ts +2 -0
  19. package/dist/cli.js +7 -0
  20. package/dist/cli.js.map +1 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.js +2 -0
  23. package/dist/index.js.map +1 -1
  24. package/package.json +14 -6
  25. package/src/agent/bridge.ts +180 -0
  26. package/src/agent/report.ts +139 -0
  27. package/src/agent/run.ts +136 -0
  28. package/src/agent/schema.ts +38 -0
  29. package/src/agent/worker.ts +114 -0
  30. package/src/cli.ts +5 -0
  31. package/src/index.ts +3 -0
  32. package/vendor/.gitattributes +5 -0
  33. package/vendor/UPSTREAM.json +168 -0
  34. package/vendor/laya-pilot/LICENSE +21 -0
  35. package/vendor/laya-pilot/README.en.md +116 -0
  36. package/vendor/laya-pilot/README.md +116 -0
  37. package/vendor/laya-pilot/ROADMAP.md +21 -0
  38. package/vendor/laya-pilot/config.example.json +14 -0
  39. package/vendor/laya-pilot/docs/architecture.md +21 -0
  40. package/vendor/laya-pilot/docs/browser-use-evaluation.md +32 -0
  41. package/vendor/laya-pilot/docs/demo.png +0 -0
  42. package/vendor/laya-pilot/docs/local-runtime.md +88 -0
  43. package/vendor/laya-pilot/docs/pr1-selection.md +33 -0
  44. package/vendor/laya-pilot/docs/retry-policy.md +14 -0
  45. package/vendor/laya-pilot/examples/demo-cases.xlsx +0 -0
  46. package/vendor/laya-pilot/examples/demo-server.mjs +19 -0
  47. package/vendor/laya-pilot/examples/demo.html +733 -0
  48. package/vendor/laya-pilot/lib/auth-state.mjs +141 -0
  49. package/vendor/laya-pilot/lib/browser-provider.mjs +43 -0
  50. package/vendor/laya-pilot/lib/diagnostics.mjs +210 -0
  51. package/vendor/laya-pilot/lib/discovery.mjs +474 -0
  52. package/vendor/laya-pilot/lib/dom.mjs +539 -0
  53. package/vendor/laya-pilot/lib/engine.mjs +879 -0
  54. package/vendor/laya-pilot/lib/form.mjs +377 -0
  55. package/vendor/laya-pilot/lib/language.mjs +273 -0
  56. package/vendor/laya-pilot/lib/model.mjs +271 -0
  57. package/vendor/laya-pilot/lib/page-capabilities.mjs +356 -0
  58. package/vendor/laya-pilot/lib/page-exploration.mjs +372 -0
  59. package/vendor/laya-pilot/lib/page-session.mjs +69 -0
  60. package/vendor/laya-pilot/lib/pending-writes.mjs +50 -0
  61. package/vendor/laya-pilot/lib/planner.mjs +127 -0
  62. package/vendor/laya-pilot/lib/project-config.mjs +95 -0
  63. package/vendor/laya-pilot/lib/readiness.mjs +179 -0
  64. package/vendor/laya-pilot/lib/related-records.mjs +328 -0
  65. package/vendor/laya-pilot/lib/replay-model.mjs +44 -0
  66. package/vendor/laya-pilot/lib/run-state.mjs +133 -0
  67. package/vendor/laya-pilot/lib/test-data.mjs +128 -0
  68. package/vendor/laya-pilot/lib/workflow-policy.mjs +68 -0
  69. package/vendor/laya-pilot/lib/workflow.mjs +2321 -0
  70. package/vendor/laya-pilot/lib/workflow_excel.py +462 -0
  71. package/vendor/laya-pilot/requirements-local.txt +2 -0
  72. package/vendor/laya-pilot/requirements.txt +1 -0
  73. package/vendor/laya-pilot/runner.mjs +452 -0
  74. package/vendor/laya-pilot/tests/api.test.mjs +98 -0
  75. package/vendor/laya-pilot/tests/browser/runtime.test.mjs +847 -0
  76. package/vendor/laya-pilot/tests/config.test.mjs +109 -0
  77. package/vendor/laya-pilot/tests/diagnostics.test.mjs +91 -0
  78. package/vendor/laya-pilot/tests/discovery.test.mjs +76 -0
  79. package/vendor/laya-pilot/tests/fixtures/local-model/laya.py +28 -0
  80. package/vendor/laya-pilot/tests/fixtures/local-model/torch.py +5 -0
  81. package/vendor/laya-pilot/tests/guards.test.mjs +43 -0
  82. package/vendor/laya-pilot/tests/language.test.mjs +39 -0
  83. package/vendor/laya-pilot/tests/planner.test.mjs +129 -0
  84. package/vendor/laya-pilot/tests/readiness.test.mjs +118 -0
  85. package/vendor/laya-pilot/tests/real-model.smoke.mjs +74 -0
  86. package/vendor/laya-pilot/tests/replay-model.test.mjs +90 -0
  87. package/vendor/laya-pilot/tests/retries.test.mjs +270 -0
  88. package/vendor/laya-pilot/tests/run-state.test.mjs +162 -0
  89. package/vendor/laya-pilot/tests/selected-pr1.test.mjs +309 -0
  90. package/vendor/laya-pilot/tests/test-data.test.mjs +83 -0
  91. package/vendor/laya-pilot/tests/test_workflow_excel.py +162 -0
  92. package/vendor/laya-pilot/tests/worker_test.py +33 -0
  93. package/vendor/laya-pilot/tests/workflow.test.mjs +98 -0
  94. package/vendor/laya-pilot/worker.py +135 -0
  95. package/vendor/patches/0001-native-field-recipes.patch +3009 -0
@@ -0,0 +1,474 @@
1
+ import { inspectForm, findFormItem, inspectLooseRequired, invalidExampleValue } from './form.mjs';
2
+ import { assertPageIdentity, activity, waitForVisibleStep } from './page-session.mjs';
3
+ import { settle } from './dom.mjs';
4
+ import {
5
+ sameRegion,
6
+ expandCollection,
7
+ revealTreeActions,
8
+ recordTrees,
9
+ validateTreeTarget,
10
+ } from './page-capabilities.mjs';
11
+
12
+ const SEARCH = /搜索|查询|search|query/i;
13
+ const RESET = /^(重置|清空|reset|clear)$/i;
14
+ const CREATE = /新增|新建|创建|添加|\badd\b|\bnew\b|\bcreate\b/i;
15
+ const CANCEL = /^(取消|关闭|cancel|close)$/i;
16
+ const searchField = /名称|姓名|用户名|账号|账户|name|account|搜索|查询|search/i;
17
+ const target = ({ name, role, region, treePath }) => ({
18
+ name,
19
+ role,
20
+ ...(region ? { region } : {}),
21
+ ...(treePath ? { treePath } : {}),
22
+ });
23
+ const keyOf = (c) => `${c.role}:${c.name}`;
24
+
25
+ export function discoveryCandidates(snapshot, form) {
26
+ const controls = snapshot.controls.filter((c) => !c.disabled);
27
+ const unique = (items) =>
28
+ items.filter((c) => items.filter((x) => keyOf(x) === keyOf(c)).length === 1);
29
+ const fields = unique(
30
+ controls.filter(
31
+ (c) =>
32
+ c.role === 'textbox' &&
33
+ !c.readonly &&
34
+ searchField.test(c.name) &&
35
+ !c.regionAmbiguous &&
36
+ !['banner', 'navigation'].includes(c.region?.role),
37
+ ),
38
+ );
39
+ let searches = unique(controls.filter((c) => c.role === 'button' && SEARCH.test(c.name)));
40
+ if (fields.length === 1) searches = searches.filter((c) => sameRegion(c, fields[0]));
41
+ const explicitSearch = searches.filter((c) => /^(搜索|查询|search|query)$/i.test(c.name));
42
+ if (explicitSearch.length === 1) searches = explicitSearch;
43
+ const resets = unique(
44
+ controls.filter(
45
+ (c) =>
46
+ c.role === 'button' &&
47
+ RESET.test(c.name) &&
48
+ (fields.length !== 1 || sameRegion(c, fields[0])),
49
+ ),
50
+ );
51
+ const candidates = [];
52
+ const query =
53
+ fields.length === 1 && searches.length <= 1
54
+ ? { field: target(fields[0]), ...(searches[0] ? { search: target(searches[0]) } : {}) }
55
+ : null;
56
+ if (query) {
57
+ const base = query;
58
+ candidates.push({
59
+ check: 'filter-empty',
60
+ ...base,
61
+ title: '不存在的关键词查询显示空结果',
62
+ evidence: `${fields[0].name};${searches[0]?.name || '输入后筛选'}`,
63
+ });
64
+ if (resets.length === 1)
65
+ candidates.push({
66
+ check: 'filter-reset',
67
+ ...base,
68
+ reset: target(resets[0]),
69
+ title: '筛选重置清空条件并恢复列表',
70
+ evidence: `${fields[0].name};${resets[0].name}`,
71
+ });
72
+ }
73
+ if (form?.create && form.cancel && form.fields.length) {
74
+ const base = { create: form.create, cancel: form.cancel };
75
+ const field = form.fields.find(
76
+ (f) =>
77
+ !f.combo && f.inputs.some((i) => !i.readonly && ['text', 'input'].includes(i.type)),
78
+ );
79
+ if (field && query)
80
+ candidates.push({
81
+ check: 'cancel-create',
82
+ ...base,
83
+ ...query,
84
+ label: field.label,
85
+ title: '填写新增表单后取消,不产生新记录',
86
+ evidence: `${form.create.name};${field.label};${form.cancel.name}`,
87
+ });
88
+ for (const f of form.fields.filter((f) => !f.combo)) {
89
+ const input = f.inputs[0];
90
+ if (f.inputs.length !== 1 || !input || input.readonly) continue;
91
+ if (input.type === 'email')
92
+ candidates.push({
93
+ check: 'field-invalid',
94
+ ...base,
95
+ label: f.label,
96
+ constraint: 'email',
97
+ title: `${f.label}拒绝非法邮箱格式`,
98
+ evidence: `${f.label}:type=email`,
99
+ });
100
+ if (input.type === 'number') {
101
+ for (const constraint of ['min', 'max']) {
102
+ const bound = input[constraint];
103
+ if (bound !== '' && bound != null && Number.isFinite(Number(bound)))
104
+ candidates.push({
105
+ check: 'field-invalid',
106
+ ...base,
107
+ label: f.label,
108
+ constraint,
109
+ bound: Number(bound),
110
+ title: `${f.label}校验${constraint === 'min' ? '下' : '上'}界`,
111
+ evidence: `${f.label}:${constraint}=${bound}`,
112
+ });
113
+ }
114
+ }
115
+ }
116
+ }
117
+ return candidates;
118
+ }
119
+
120
+ export function validateDiscovery(step, { readOnly = false } = {}) {
121
+ const c = step.spec;
122
+ if (c?.create?.treePath) validateTreeTarget(c.create.treePath, { allowRoot: true });
123
+ if (
124
+ step.kind !== 'assert-discovery' ||
125
+ !c ||
126
+ !['filter-empty', 'filter-reset', 'cancel-create', 'field-invalid'].includes(c.check)
127
+ )
128
+ throw Error('不支持的补充测试步骤');
129
+ if (readOnly && !['filter-empty', 'filter-reset'].includes(c.check))
130
+ throw Error('只读探索只允许筛选及恢复验证,不能打开新增表单');
131
+ const named = (t, role, pattern) =>
132
+ t?.role === role &&
133
+ typeof t.name === 'string' &&
134
+ t.name.length <= 150 &&
135
+ pattern.test(t.name);
136
+ if (c.check.startsWith('filter-')) {
137
+ if (
138
+ !named(c.field, 'textbox', searchField) ||
139
+ (c.search && !named(c.search, 'button', SEARCH)) ||
140
+ (c.check === 'filter-reset' && !named(c.reset, 'button', RESET))
141
+ )
142
+ throw Error('补充筛选测试缺少明确控件');
143
+ } else if (
144
+ !named(c.create, 'button', CREATE) ||
145
+ !named(c.cancel, 'button', CANCEL) ||
146
+ typeof c.label !== 'string' ||
147
+ !c.label
148
+ )
149
+ throw Error('补充表单测试缺少明确控件');
150
+ if (
151
+ c.check === 'cancel-create' &&
152
+ (!named(c.field, 'textbox', searchField) ||
153
+ (c.search && !named(c.search, 'button', SEARCH)))
154
+ )
155
+ throw Error('取消新增测试缺少查询验证控件');
156
+ if (
157
+ c.check === 'field-invalid' &&
158
+ (!['email', 'min', 'max'].includes(c.constraint) ||
159
+ (c.constraint !== 'email' && !Number.isFinite(c.bound)))
160
+ )
161
+ throw Error('补充字段测试缺少页面约束');
162
+ return c;
163
+ }
164
+
165
+ export async function selectDiscovery(laya, candidate) {
166
+ const decision = await laya.choose(
167
+ `测试「${candidate.title}」,页面已观察到:${candidate.evidence}`,
168
+ {
169
+ 执行: `验证${candidate.title};使用页面现有控件,能够断言结果`,
170
+ 跳过: '当前页面证据不足,无法执行或无法断言该测试',
171
+ },
172
+ { phase: 'test-discovery', candidate },
173
+ );
174
+ return {
175
+ selected:
176
+ decision.choice === '执行' &&
177
+ (decision.probabilities?.执行 || 0) >= 0.5 &&
178
+ decision.margin >= 0.1,
179
+ choice: decision.choice,
180
+ confidence: decision.probabilities?.[decision.choice] || 0,
181
+ };
182
+ }
183
+
184
+ async function control(w, t) {
185
+ return w.withAttempts('定位恢复控件', async () => {
186
+ const treeAction = t.treePath ? await revealTreeActions(w.page, t) : null;
187
+ const snap = await w.snapshot();
188
+ const treeRef = treeAction ? await treeAction.getAttribute('data-laya-live-ref') : null;
189
+ return (
190
+ await w.chooseFromSnapshot(
191
+ snap,
192
+ snap.controls.filter(
193
+ (c) =>
194
+ c.name === t.name &&
195
+ c.role === t.role &&
196
+ !c.disabled &&
197
+ (!treeAction || c.ref === treeRef) &&
198
+ (!t.region || sameRegion(c, t)),
199
+ ),
200
+ `${['textbox', 'spinbutton'].includes(t.role) ? '填写' : '点击'}「${t.name}」`,
201
+ )
202
+ ).locator;
203
+ });
204
+ }
205
+ async function setFilter(w, c, value) {
206
+ await assertPageIdentity(w.page, w.identity);
207
+ const input = await control(w, c.field);
208
+ if ((await input.inputValue()) !== value) {
209
+ await input.fill(value);
210
+ await settle(w.page, 180);
211
+ }
212
+ if ((await (await control(w, c.field)).inputValue()) !== value)
213
+ throw Error('筛选条件没有恢复到预期值');
214
+ if (c.search) await (await control(w, c.search)).click();
215
+ await w.pendingWrites.wait(w.config.pageTimeout || 8000);
216
+ await expandCollection(w, { record: false });
217
+ }
218
+
219
+ const sameRows = (a, b) => JSON.stringify([...a].sort()) === JSON.stringify([...b].sort());
220
+
221
+ async function restoreDiscovery(w, c, original, baseline) {
222
+ activity(w, '正在恢复当前子应用的表单和筛选条件,不刷新主应用');
223
+ try {
224
+ await assertPageIdentity(w.page, w.identity);
225
+ if (await w.editorPresent()) {
226
+ if (!c.cancel) throw Error('没有已确认的取消入口,无法恢复编辑区');
227
+ await (await control(w, c.cancel)).click();
228
+ await w.waitModalClosed();
229
+ }
230
+ if (c.field) await setFilter(w, c, original);
231
+ await waitTable(w, (rows) => sameRows(rows, baseline));
232
+ await waitForVisibleStep(w);
233
+ } catch (error) {
234
+ // Do not turn an assertion failure into success by refreshing. The next
235
+ // case must not run against an unknown child-app state either.
236
+ w.restorationFailure = `当前子应用状态恢复失败,已停止后续探索:${error.message}`;
237
+ throw Error(w.restorationFailure, { cause: error });
238
+ } finally {
239
+ activity(w, '');
240
+ }
241
+ }
242
+ async function tableState(w) {
243
+ const trees = recordTrees(w.page);
244
+ if (await trees.count()) {
245
+ if ((await trees.count()) !== 1) throw Error('补充测试无法确定唯一记录树');
246
+ return trees
247
+ .getByRole('treeitem')
248
+ .filter({ visible: true })
249
+ .evaluateAll((items) =>
250
+ items
251
+ .filter((item) => !item.hasAttribute('aria-expanded'))
252
+ .map((item) => item.getAttribute('aria-label') || item.innerText),
253
+ );
254
+ }
255
+ const table = w.page.locator('table:visible,[role="grid"]:visible');
256
+ // Fixed-column copies are not independent tables. Require a single main table.
257
+ const main = table
258
+ .filter({ hasNot: w.page.locator('table') })
259
+ .locator(
260
+ 'xpath=self::*[not(ancestor::*[contains(@class,"ant-table-fixed-left") or contains(@class,"ant-table-fixed-right")])]',
261
+ );
262
+ if ((await main.count()) !== 1) throw Error('补充测试无法确定唯一主表格');
263
+ return main
264
+ .locator('tbody tr,[role="rowgroup"] [role="row"]')
265
+ .filter({ visible: true })
266
+ .evaluateAll((rows) =>
267
+ rows
268
+ .filter(
269
+ (r) =>
270
+ !r.matches('.ant-table-placeholder') &&
271
+ !r.querySelector('.ant-empty,.el-table__empty-block') &&
272
+ r.querySelectorAll('td,[role="cell"]').length > 1,
273
+ )
274
+ .map((r) => r.innerText),
275
+ );
276
+ }
277
+ async function waitTable(w, check) {
278
+ const deadline = Date.now() + (w.config.assertTimeout || 4000);
279
+ do {
280
+ await w.pendingWrites.wait(w.config.pageTimeout || 8000);
281
+ const rows = await tableState(w);
282
+ if (check(rows)) return rows;
283
+ await w.page.waitForTimeout(100);
284
+ } while (Date.now() < deadline);
285
+ throw Error('补充测试的列表断言未通过');
286
+ }
287
+
288
+ // This bounded grammar never submits a form. Replay uses the recorded recipe;
289
+ // the model cannot introduce selectors, scripts, URLs or write operations.
290
+ export async function executeDiscovery(w, step) {
291
+ if (w.restorationFailure) throw Error(w.restorationFailure);
292
+ const c = validateDiscovery(step, { readOnly: w.config.readOnly });
293
+ await assertPageIdentity(w.page, w.identity);
294
+ // The recipe's precondition is an unfiltered list in both generation and
295
+ // replay. A preceding delete may leave its run-owned keyword in the field.
296
+ if (c.field && (await (await control(w, c.field)).inputValue()) !== '')
297
+ await setFilter(w, c, '');
298
+ await expandCollection(w, { record: false });
299
+ const baseline = await tableState(w);
300
+ const original = c.field ? await (await control(w, c.field)).inputValue() : null;
301
+ let failure;
302
+ try {
303
+ if (c.check.startsWith('filter-')) {
304
+ if (!baseline.length) throw Error('列表原本为空,无法验证筛选及恢复');
305
+ await (await control(w, c.field)).fill(`no_match_${w.variables.recordAccount}`);
306
+ if (c.search) await (await control(w, c.search)).click();
307
+ await waitTable(w, (rows) => rows.length === 0);
308
+ await waitForVisibleStep(w);
309
+ if (c.check === 'filter-reset') {
310
+ await (await control(w, c.reset)).click();
311
+ if ((await (await control(w, c.field)).inputValue()) !== '')
312
+ throw Error('重置后筛选值未清空');
313
+ await waitTable(
314
+ w,
315
+ (rows) => rows.length > 0 && rows.some((r) => baseline.includes(r)),
316
+ );
317
+ }
318
+ } else {
319
+ if (!c.create.treePath) await revealTreeActions(w.page, c.create);
320
+ await (await control(w, c.create)).click();
321
+ await w.waitForEditor();
322
+ await waitForVisibleStep(w);
323
+ if (w.mode === 'execute') await w.matchFormTarget(c.label);
324
+ const { info, item } = await findFormItem(w.page, c.label);
325
+ const input = item.locator('input:visible,textarea:visible');
326
+ if ((await input.count()) !== 1 || !(await input.isEditable()))
327
+ throw Error('补充测试字段已变化');
328
+ if (c.check === 'cancel-create') {
329
+ await input.fill(w.variables.recordAccount);
330
+ await waitForVisibleStep(w);
331
+ await (await control(w, c.cancel)).click();
332
+ await w.waitModalClosed();
333
+ await waitForVisibleStep(w);
334
+ await (await control(w, c.field)).fill(w.variables.recordAccount);
335
+ if (c.search) await (await control(w, c.search)).click();
336
+ await waitTable(w, (rows) => rows.length === 0);
337
+ await w.assertPersisted('${recordAccount}', false, {
338
+ record: false,
339
+ query: [
340
+ {
341
+ kind: 'fill',
342
+ target: { ...c.field, scope: 'page' },
343
+ value: '${recordAccount}',
344
+ },
345
+ ...(c.search
346
+ ? [
347
+ {
348
+ kind: 'click',
349
+ purpose: 'search',
350
+ target: { ...c.search, scope: 'page' },
351
+ },
352
+ ]
353
+ : []),
354
+ ],
355
+ });
356
+ } else {
357
+ const observed = info.inputs[0];
358
+ if (
359
+ (c.constraint === 'email' && observed.type !== 'email') ||
360
+ (c.constraint !== 'email' &&
361
+ (observed.type !== 'number' ||
362
+ observed[c.constraint] === '' ||
363
+ Number(observed[c.constraint]) !== c.bound))
364
+ )
365
+ throw Error('原先记录的字段约束已变化');
366
+ const value =
367
+ c.constraint === 'email'
368
+ ? 'not-an-email'
369
+ : String(c.bound + (c.constraint === 'min' ? -1 : 1));
370
+ await input.fill(value);
371
+ await input.press('Tab');
372
+ const invalid = await input.evaluate(
373
+ (e, constraint) =>
374
+ constraint === 'email'
375
+ ? e.validity.typeMismatch
376
+ : constraint === 'min'
377
+ ? e.validity.rangeUnderflow
378
+ : e.validity.rangeOverflow,
379
+ c.constraint,
380
+ );
381
+ if (!invalid) throw Error('字段未按声明的约束拒绝非法值');
382
+ await waitForVisibleStep(w);
383
+ await (await control(w, c.cancel)).click();
384
+ await w.waitModalClosed();
385
+ }
386
+ }
387
+ } catch (error) {
388
+ failure = error;
389
+ }
390
+ try {
391
+ await restoreDiscovery(w, c, original, baseline);
392
+ } catch (error) {
393
+ if (!failure) throw error;
394
+ throw Error(`${failure.message};${error.message}`, { cause: failure });
395
+ }
396
+ if (failure) throw failure;
397
+ w.record(step);
398
+ }
399
+
400
+ export async function discoverTests(w, { readOnly = w.config.readOnly } = {}) {
401
+ if (w.pendingWrite || w.created) {
402
+ w.discovery = {
403
+ status: 'blocked',
404
+ reason: '仍有未确认写入或未清理测试记录',
405
+ candidates: [],
406
+ };
407
+ return;
408
+ }
409
+ await assertPageIdentity(w.page, w.identity);
410
+ if (await w.editorPresent()) throw Error('编辑区未关闭,停止补充探索');
411
+ let snapshot = await w.snapshot();
412
+ const query = discoveryCandidates(snapshot, null).find((c) => c.check === 'filter-empty');
413
+ if (query && (await (await control(w, query.field)).inputValue()) !== '') {
414
+ activity(w, '正在清除本轮查询条件,保留主应用及其他子应用状态');
415
+ try {
416
+ await setFilter(w, query, '');
417
+ } finally {
418
+ activity(w, '');
419
+ }
420
+ }
421
+ await expandCollection(w, { record: false });
422
+ snapshot = await w.snapshot();
423
+ const candidates = discoveryCandidates(snapshot, readOnly ? null : w.formEvidence);
424
+ w.discovery = {
425
+ status: 'completed',
426
+ candidates: [],
427
+ unsupported: snapshot.controls
428
+ .filter((c) => /导入|导出|上传|审批|审核|重置密码|启用|停用|批量/.test(c.name))
429
+ .map((c) => c.name)
430
+ .slice(0, 20),
431
+ };
432
+ for (const [i, c] of candidates.slice(0, 12).entries()) {
433
+ w.checkInterrupted();
434
+ const decision = await selectDiscovery(w.laya, c);
435
+ const entry = { ...c, ...decision };
436
+ w.discovery.candidates.push(entry);
437
+ if (!decision.selected) continue;
438
+ const result = await w.runCase(
439
+ `discover-${i + 1}`,
440
+ c.title,
441
+ readOnly ? 'filters' : 'discover',
442
+ async () => {
443
+ await executeDiscovery(w, { kind: 'assert-discovery', spec: c });
444
+ },
445
+ );
446
+ entry.status = result.status;
447
+ entry.reason = result.reason;
448
+ w.completeCase(result);
449
+ console.log(`${result.status} ${result.id}: ${result.reason}`);
450
+ if (w.restorationFailure) {
451
+ w.discovery.status = 'blocked';
452
+ w.discovery.reason = w.restorationFailure;
453
+ break;
454
+ }
455
+ }
456
+ w.discovery.truncated = Math.max(0, candidates.length - 12);
457
+ }
458
+
459
+ export async function observeFormEvidence(w, create) {
460
+ const snap = await w.snapshot();
461
+ const closes = snap.controls.filter(
462
+ (c) => c.role === 'button' && CANCEL.test(c.name) && !c.disabled,
463
+ );
464
+ const explicitCancel = closes.filter((c) => /^(取消|cancel)$/i.test(c.name));
465
+ const cancel = explicitCancel.length === 1 ? explicitCancel : closes;
466
+ w.formEvidence = {
467
+ create: target(create),
468
+ cancel: cancel.length === 1 ? target(cancel[0]) : null,
469
+ fields: await inspectForm(w.page),
470
+ hasRangeFormatInput: (await inspectLooseRequired(w.page)).some((input) =>
471
+ invalidExampleValue(input.placeholder),
472
+ ),
473
+ };
474
+ }