dsh-uitest 2.3.0 → 2.4.0
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 +76 -11
- package/bin/uitest.mjs +189 -11
- package/client.js +222 -25
- package/host/agent-bridge.mjs +9 -2
- package/host/agent-test.mjs +1 -1
- package/host/context-budget.mjs +1 -1
- package/index.js +14 -2
- package/lib/agent-session.mjs +81 -3
- package/lib/agent-tasks.mjs +212 -0
- package/lib/batch.mjs +204 -13
- package/lib/browser-ab.mjs +21 -6
- package/lib/browser.mjs +5 -5
- package/lib/config.mjs +1 -0
- package/lib/convert.mjs +178 -40
- package/lib/doc-structure.mjs +316 -0
- package/lib/flow.mjs +49 -14
- package/lib/knowledge-central-episodes.mjs +120 -0
- package/lib/knowledge-central-import.mjs +16 -1
- package/lib/knowledge-central.mjs +176 -25
- package/lib/knowledge-clean.mjs +749 -0
- package/lib/knowledge-consolidate.mjs +1271 -0
- package/lib/knowledge-coverage.mjs +150 -0
- package/lib/knowledge-docs.mjs +3 -3
- package/lib/knowledge-effect.mjs +148 -0
- package/lib/knowledge-facts.mjs +1008 -0
- package/lib/knowledge-maintain.mjs +185 -0
- package/lib/knowledge-permission.mjs +447 -0
- package/lib/knowledge-query.mjs +304 -26
- package/lib/knowledge-store.mjs +169 -14
- package/lib/knowledge-summarize.mjs +332 -0
- package/lib/knowledge.mjs +944 -47
- package/lib/learn-run.mjs +157 -51
- package/lib/run-learn.mjs +34 -0
- package/lib/run-observe.mjs +95 -27
- package/lib/run-stats.mjs +71 -0
- package/package.json +12 -2
- package/scripts/knowledge-central-purge.mjs +248 -0
- package/scripts/knowledge-central-sync.mjs +102 -20
- package/scripts/knowledge-consolidate.mjs +158 -0
- package/scripts/knowledge-coverage.mjs +94 -0
- package/scripts/knowledge-effect.mjs +82 -0
- package/scripts/knowledge-permission-probe.mjs +196 -0
- package/scripts/knowledge-permission-report.mjs +140 -0
- package/scripts/knowledge-report.mjs +492 -0
- package/scripts/knowledge-summarize.mjs +200 -0
- package/skills/uitest/SKILL.md +4 -2
- package/skills/uitest/references/convert-knowledge.md +66 -13
- package/studio/host.mjs +143 -6
- package/studio/knowledge.mjs +279 -42
- package/studio/snapshot.mjs +6 -1
package/lib/batch.mjs
CHANGED
|
@@ -17,6 +17,11 @@ import {
|
|
|
17
17
|
describeRecipeLibrary,
|
|
18
18
|
} from './seed.mjs';
|
|
19
19
|
import { addResult, collectRunEvidence } from './results.mjs';
|
|
20
|
+
import { planAgentTasks, saveAgentTasks } from './agent-tasks.mjs';
|
|
21
|
+
import { learnRun } from './run-learn.mjs';
|
|
22
|
+
import { loadFlowRunStats } from './run-stats.mjs';
|
|
23
|
+
import { convertCase } from './convert.mjs';
|
|
24
|
+
import { loadKnowledge, resolveRunDir } from './knowledge.mjs';
|
|
20
25
|
import * as abDriver from './browser-ab.mjs';
|
|
21
26
|
|
|
22
27
|
// 批量测试固定走 agent-browser;Playwright 只保留给登录/审批兼容层和手工对照。
|
|
@@ -92,18 +97,62 @@ export function indexFlowsByCase(flows = []) {
|
|
|
92
97
|
return map;
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
return 0;
|
|
100
|
+
function flowOutcomeRank(flow, runStats) {
|
|
101
|
+
const stat = runStats?.[flow.name];
|
|
102
|
+
if (!stat || stat.lastStatus === null) return 1;
|
|
103
|
+
return stat.lastStatus === 'passed' ? 0 : stat.lastStatus === 'failed' ? 2 : 1;
|
|
99
104
|
}
|
|
100
105
|
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
/**
|
|
107
|
+
* 来源排序:人工 flow 最先;真实跑通的 Agent 轨迹其次;规则生成的 needsReview 草稿最后。
|
|
108
|
+
* Agent 轨迹里含判断步骤时仍排在草稿前面,CLI 回放会把这些步骤标成未验证。
|
|
109
|
+
*/
|
|
110
|
+
function flowSourceRank(flow) {
|
|
111
|
+
const tags = asArray(flow.tags);
|
|
112
|
+
const generatedBy = flow.generated?.by;
|
|
113
|
+
if (!generatedBy) return 0;
|
|
114
|
+
const agentVerified = tags.includes('agent-verified') || generatedBy === 'uitest-agent-execute';
|
|
115
|
+
if (agentVerified) return (flow.steps || []).some((step) => step.action === 'agent') ? 3 : 1;
|
|
116
|
+
if (flow.generated?.needsReview === true) return 4;
|
|
117
|
+
return 2;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** 一个用例只选一条执行 flow:最近成功优先,其次人工 flow,再次 Agent 真实轨迹,最后是规则草稿。 */
|
|
121
|
+
function pickCaseFlow(matched, runStats = {}) {
|
|
122
|
+
const sorted = [...matched].sort((a, b) =>
|
|
123
|
+
flowOutcomeRank(a, runStats) - flowOutcomeRank(b, runStats)
|
|
124
|
+
|| flowSourceRank(a) - flowSourceRank(b)
|
|
125
|
+
|| String(a.name).localeCompare(String(b.name)));
|
|
104
126
|
return { chosen: sorted[0] || null, alternatives: sorted.slice(1) };
|
|
105
127
|
}
|
|
106
128
|
|
|
129
|
+
function flowHealth(flow, runStats) {
|
|
130
|
+
const stat = runStats?.[flow.name];
|
|
131
|
+
if (!stat) return null;
|
|
132
|
+
return {
|
|
133
|
+
lastStatus: stat.lastStatus,
|
|
134
|
+
lastStartedAt: stat.lastStartedAt,
|
|
135
|
+
lastDurationMs: stat.lastDurationMs,
|
|
136
|
+
successRate: stat.successRate,
|
|
137
|
+
runs: stat.runs,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 规则草稿至少要能到达页面并核对一个断言,才算可执行。
|
|
143
|
+
* 人工 flow 和 Agent 真实轨迹不受此限;Agent 判断步骤本身就是验证。
|
|
144
|
+
*/
|
|
145
|
+
export function flowExecutable(flow) {
|
|
146
|
+
if (!flow) return false;
|
|
147
|
+
const tags = Array.isArray(flow.tags) ? flow.tags : [];
|
|
148
|
+
const agentVerified = tags.includes('agent-verified') || flow.generated?.by === 'uitest-agent-execute';
|
|
149
|
+
if (!flow.generated?.by || agentVerified) return true;
|
|
150
|
+
const steps = Array.isArray(flow.steps) ? flow.steps : [];
|
|
151
|
+
const hasNavigation = steps.some((step) => step.action === 'goto' || step.action === 'subflow');
|
|
152
|
+
const hasAssertion = steps.some((step) => step.action === 'expect' || step.action === 'assert');
|
|
153
|
+
return hasNavigation && hasAssertion;
|
|
154
|
+
}
|
|
155
|
+
|
|
107
156
|
/* ------------------------------------------------------------------ */
|
|
108
157
|
/* 计划 */
|
|
109
158
|
/* ------------------------------------------------------------------ */
|
|
@@ -148,6 +197,7 @@ export function buildBatchPlan({
|
|
|
148
197
|
classFilter,
|
|
149
198
|
limit,
|
|
150
199
|
scope = 'flows',
|
|
200
|
+
runStats = {},
|
|
151
201
|
} = {}) {
|
|
152
202
|
const selected = selectCases({ cases, flows, tag, caseRefs, classFilter, limit, scope });
|
|
153
203
|
const byCase = indexFlowsByCase(flows);
|
|
@@ -156,8 +206,12 @@ export function buildBatchPlan({
|
|
|
156
206
|
const caseId = String(caseItem.tcId);
|
|
157
207
|
let candidates = byCase.get(caseId) || [];
|
|
158
208
|
if (tagSet) candidates = candidates.filter((flow) => flow.tags.includes(tag));
|
|
159
|
-
const
|
|
209
|
+
const executable = candidates.filter((flow) => flowExecutable(flow));
|
|
210
|
+
const unusable = candidates.filter((flow) => !flowExecutable(flow));
|
|
211
|
+
const { chosen, alternatives } = pickCaseFlow(executable, runStats);
|
|
212
|
+
const draft = chosen ? null : pickCaseFlow(unusable, runStats).chosen;
|
|
160
213
|
const matched = chosen ? [chosen] : [];
|
|
214
|
+
const chosenHealth = chosen ? flowHealth(chosen, runStats) : null;
|
|
161
215
|
const requires = uniq(matched.flatMap((flow) => flow.requires));
|
|
162
216
|
const preferredRecipes = uniq(matched.flatMap((flow) => flow.seedRecipes || []));
|
|
163
217
|
const seed = planSeeds({ needs: requires, recipes, allowWrites, preferRecipeIds: preferredRecipes });
|
|
@@ -170,7 +224,11 @@ export function buildBatchPlan({
|
|
|
170
224
|
reasons.push('用例标注不可自动化/已知缺陷,需人工执行');
|
|
171
225
|
} else {
|
|
172
226
|
state = 'agent-ready';
|
|
173
|
-
reasons.push(
|
|
227
|
+
reasons.push(
|
|
228
|
+
draft
|
|
229
|
+
? `flow ${draft.name} 没有可执行入口或断言,交给 Agent 修正后再回放`
|
|
230
|
+
: '没有 flow;可由 DSH Agent 按自然语言直接执行,通过后沉淀 flow',
|
|
231
|
+
);
|
|
174
232
|
}
|
|
175
233
|
} else if (seed.state === 'missing') {
|
|
176
234
|
state = 'needs-data';
|
|
@@ -181,6 +239,9 @@ export function buildBatchPlan({
|
|
|
181
239
|
} else {
|
|
182
240
|
state = 'ready';
|
|
183
241
|
}
|
|
242
|
+
if (chosen && chosenHealth?.lastStatus === 'failed') {
|
|
243
|
+
reasons.push('该 flow 上次执行失败;批次前会按最近运行与人工反馈尝试刷新');
|
|
244
|
+
}
|
|
184
245
|
return {
|
|
185
246
|
caseId,
|
|
186
247
|
seq: caseItem.seq,
|
|
@@ -202,8 +263,12 @@ export function buildBatchPlan({
|
|
|
202
263
|
requires: flow.requires,
|
|
203
264
|
seedRecipes: flow.seedRecipes || [],
|
|
204
265
|
generated: flow.generated || null,
|
|
266
|
+
health: flowHealth(flow, runStats),
|
|
205
267
|
})),
|
|
206
|
-
alternativeFlows: alternatives.map((flow) => ({ name: flow.name, file: flow.file, tags: flow.tags })),
|
|
268
|
+
alternativeFlows: [...alternatives, ...unusable].map((flow) => ({ name: flow.name, file: flow.file, tags: flow.tags, health: flowHealth(flow, runStats) })),
|
|
269
|
+
draftFlow: draft
|
|
270
|
+
? { name: draft.name, title: draft.title, file: draft.file, generated: draft.generated || null, health: flowHealth(draft, runStats) }
|
|
271
|
+
: null,
|
|
207
272
|
seed,
|
|
208
273
|
state,
|
|
209
274
|
reasons,
|
|
@@ -230,6 +295,7 @@ export function buildBatchPlan({
|
|
|
230
295
|
manual: byState.manual || 0,
|
|
231
296
|
blocked: byState.blocked || 0,
|
|
232
297
|
withSeed: items.filter((item) => item.seed.needs.length).length,
|
|
298
|
+
withDraft: items.filter((item) => item.draftFlow).length,
|
|
233
299
|
},
|
|
234
300
|
};
|
|
235
301
|
}
|
|
@@ -240,6 +306,7 @@ export function planBatch(config, options = {}) {
|
|
|
240
306
|
const { flows, warnings: flowWarnings } = readFlows(config, { dir: options.dir });
|
|
241
307
|
const loadedRecipes = loadSeedRecipes(config);
|
|
242
308
|
const allowWrites = options.allowWrites === true || config.seed?.allowWrites === true;
|
|
309
|
+
const runStats = options.runStats || loadFlowRunStats(config);
|
|
243
310
|
const plan = buildBatchPlan({
|
|
244
311
|
cases: loadedCases.cases,
|
|
245
312
|
flows,
|
|
@@ -250,6 +317,7 @@ export function planBatch(config, options = {}) {
|
|
|
250
317
|
classFilter: options.classFilter,
|
|
251
318
|
limit: options.limit,
|
|
252
319
|
scope: options.scope,
|
|
320
|
+
runStats,
|
|
253
321
|
});
|
|
254
322
|
plan.recipeLibrary = describeRecipeLibrary(config);
|
|
255
323
|
plan.caseLibrary = {
|
|
@@ -269,6 +337,7 @@ export function planBatch(config, options = {}) {
|
|
|
269
337
|
requires: flow.requires,
|
|
270
338
|
seedRecipes: flow.seedRecipes || [],
|
|
271
339
|
generated: flow.generated || null,
|
|
340
|
+
health: flowHealth(flow, runStats),
|
|
272
341
|
}));
|
|
273
342
|
return plan;
|
|
274
343
|
}
|
|
@@ -293,11 +362,16 @@ export async function runPool(items, size, fn) {
|
|
|
293
362
|
return results;
|
|
294
363
|
}
|
|
295
364
|
|
|
296
|
-
function flowRunNote({ flow, result, seed, index }) {
|
|
365
|
+
export function flowRunNote({ flow, result, seed, index }) {
|
|
297
366
|
const parts = [];
|
|
298
367
|
parts.push(`flow ${flow.name} ${result.status === 'passed' ? '通过' : '失败'}`);
|
|
299
368
|
if (result.durationMs !== undefined) parts.push(`${(result.durationMs / 1000).toFixed(1)}s`);
|
|
300
|
-
|
|
369
|
+
const hard = (result.failedSteps || []).filter((step) => !step.soft);
|
|
370
|
+
const soft = (result.failedSteps || []).filter((step) => step.soft);
|
|
371
|
+
if (hard.length) parts.push(`失败步骤 ${hard.map((step) => step.id).join('、')}`);
|
|
372
|
+
if (soft.length) parts.push(`未验证断言 ${soft.map((step) => step.id).join('、')}`);
|
|
373
|
+
if (result.skipped > 0) parts.push(`未验证判断 ${result.skipped} 步`);
|
|
374
|
+
if (result.assertions === 0) parts.push('无可执行断言(预期结果仅剩 comment)');
|
|
301
375
|
if (seed?.state === 'passed' && seed.runs?.length) {
|
|
302
376
|
parts.push(`前置造数 ${seed.runs.map((run) => `${run.recipeId}(${Object.keys(run.vars || {}).join('/')})`).join(' → ')}`);
|
|
303
377
|
}
|
|
@@ -367,6 +441,7 @@ export function renderBatchSummary(summary) {
|
|
|
367
441
|
`| 并发 | ${summary.workers} |`,
|
|
368
442
|
`| 用例 | ${summary.total}(通过 ${summary.passed} / 失败 ${summary.failed} / 阻塞 ${summary.blocked} / 未执行 ${summary.notExecuted}) |`,
|
|
369
443
|
`| 造数 | ${JSON.stringify(summary.seed)} |`,
|
|
444
|
+
...(summary.agentTasks ? [`| Agent 交接 | ${summary.agentTasks.total} 条 pending,见 agent-tasks.json |`] : []),
|
|
370
445
|
'',
|
|
371
446
|
'| 用例 | 结果 | 用时 | flow | 关键/错误截图 | 备注 |',
|
|
372
447
|
'| --- | --- | --- | --- | --- | --- |',
|
|
@@ -376,6 +451,73 @@ export function renderBatchSummary(summary) {
|
|
|
376
451
|
return lines.join('\n');
|
|
377
452
|
}
|
|
378
453
|
|
|
454
|
+
function markRunLearned(config, runDir, result) {
|
|
455
|
+
try {
|
|
456
|
+
const dir = resolveRunDir(config, runDir);
|
|
457
|
+
const file = path.join(dir, 'run.json');
|
|
458
|
+
const run = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
459
|
+
run.learn = {
|
|
460
|
+
at: nowIso(),
|
|
461
|
+
pagesAdded: result.observations?.pagesAdded || 0,
|
|
462
|
+
actionsAdded: result.observations?.actionsAdded || 0,
|
|
463
|
+
waitsUpdated: result.timing?.updatedPages?.length || 0,
|
|
464
|
+
suggestions: result.timing?.suggestions?.length || 0,
|
|
465
|
+
learnings: result.timing?.learnings?.length || 0,
|
|
466
|
+
errors: result.errors,
|
|
467
|
+
};
|
|
468
|
+
run.updatedAt = run.learn.at;
|
|
469
|
+
writeFileAtomic(file, `${JSON.stringify(run, null, 2)}\n`);
|
|
470
|
+
} catch {
|
|
471
|
+
/* 标记失败不影响沉淀本身 */
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* 批次前刷新上次失败的 generated flow:只处理非 agent flow,知识库为空时跳过。
|
|
477
|
+
* convert 可注入,便于单测;默认使用 convertCase。
|
|
478
|
+
*/
|
|
479
|
+
export function refreshFailedFlows({
|
|
480
|
+
config,
|
|
481
|
+
plan,
|
|
482
|
+
allCases = [],
|
|
483
|
+
convert = convertCase,
|
|
484
|
+
knowledge = null,
|
|
485
|
+
log = null,
|
|
486
|
+
} = {}) {
|
|
487
|
+
const result = { enabled: true, refreshed: [], errors: [] };
|
|
488
|
+
let loaded = knowledge;
|
|
489
|
+
for (const item of plan?.items || []) {
|
|
490
|
+
if (item.state !== 'ready') continue;
|
|
491
|
+
const flow = item.flows?.[0];
|
|
492
|
+
if (!flow || flow.health?.lastStatus !== 'failed' || !flow.generated) continue;
|
|
493
|
+
if (asArray(flow.tags).includes('agent')) continue;
|
|
494
|
+
const caseItem = findCase(allCases, item.caseId)?.case;
|
|
495
|
+
if (!caseItem) continue;
|
|
496
|
+
try {
|
|
497
|
+
loaded = loaded || loadKnowledge(config);
|
|
498
|
+
if (loaded?.missing || !(loaded?.pages?.pages || []).length) {
|
|
499
|
+
result.errors.push({ caseId: item.caseId, flow: flow.name, error: '知识库没有页面,跳过刷新' });
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
const converted = convert({
|
|
503
|
+
knowledge: loaded,
|
|
504
|
+
caseItem,
|
|
505
|
+
config,
|
|
506
|
+
options: { save: true, force: true, regen: true },
|
|
507
|
+
});
|
|
508
|
+
if (converted.savedPath) {
|
|
509
|
+
result.refreshed.push({ caseId: item.caseId, flow: flow.name, file: converted.savedPath, diagnostics: converted.diagnostics?.length || 0 });
|
|
510
|
+
} else {
|
|
511
|
+
result.errors.push({ caseId: item.caseId, flow: flow.name, error: converted.diagnostics?.map((entry) => entry.message).join(';') || '未保存' });
|
|
512
|
+
}
|
|
513
|
+
} catch (error) {
|
|
514
|
+
result.errors.push({ caseId: item.caseId, flow: flow.name, error: String(error?.message || error) });
|
|
515
|
+
if (log) log.warn(`刷新失败 flow 跳过 ${item.caseId}/${flow.name}:${error.message}`);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
return result;
|
|
519
|
+
}
|
|
520
|
+
|
|
379
521
|
/**
|
|
380
522
|
* 执行批次。
|
|
381
523
|
* @param {object} options
|
|
@@ -402,18 +544,31 @@ export async function runBatch({
|
|
|
402
544
|
logger = null,
|
|
403
545
|
runFlowImpl = runFlow,
|
|
404
546
|
recordImpl = addResult,
|
|
547
|
+
learn = config?.learn?.autoAfterRun !== false,
|
|
548
|
+
refresh = config?.learn?.refreshFailedFlows !== false,
|
|
405
549
|
sessionFactory,
|
|
406
550
|
} = {}) {
|
|
407
551
|
if (!config) throw new ConfigError('runBatch 缺少 config');
|
|
408
552
|
if (!plan) throw new ConfigError('runBatch 缺少 plan');
|
|
553
|
+
const learnEnabled = learn === false ? false : learn === true ? true : config.learn?.autoAfterRun !== false;
|
|
409
554
|
const log = logger || createLogger({ quiet: true });
|
|
410
555
|
const workerCount = Math.max(1, Number(workers) || Number(config.batch?.workers) || 3);
|
|
411
556
|
const loadedRecipes = loadSeedRecipes(config);
|
|
412
557
|
const allCases = loadProjectCases(config).cases;
|
|
413
558
|
const batchDir = ensureDir(path.join(config.paths.outputDir, 'batches', runId));
|
|
414
559
|
const startedAt = nowIso();
|
|
560
|
+
let agentTasks = null;
|
|
561
|
+
try {
|
|
562
|
+
agentTasks = saveAgentTasks(config, runId, planAgentTasks({ config, plan, cases: allCases, batchId: runId, createdAt: startedAt }), startedAt);
|
|
563
|
+
} catch (error) {
|
|
564
|
+
log.warn(`Agent 交接清单写入失败:${error.message}`);
|
|
565
|
+
}
|
|
415
566
|
const sharedSeeds = new SharedSeedStore();
|
|
416
567
|
const headless = config.browser?.headless !== false;
|
|
568
|
+
const refreshEnabled = refresh !== false;
|
|
569
|
+
const refreshResult = refreshEnabled
|
|
570
|
+
? refreshFailedFlows({ config, plan, allCases, log })
|
|
571
|
+
: { enabled: false, refreshed: [], errors: [] };
|
|
417
572
|
|
|
418
573
|
const runnable = plan.items.filter((item) => item.state === 'ready');
|
|
419
574
|
const notRunnable = plan.items.filter((item) => item.state !== 'ready');
|
|
@@ -502,7 +657,7 @@ export async function runBatch({
|
|
|
502
657
|
vars: seed.vars || {},
|
|
503
658
|
session,
|
|
504
659
|
shotEveryStep,
|
|
505
|
-
observePages:
|
|
660
|
+
observePages: learnEnabled,
|
|
506
661
|
learnAfterRun: false,
|
|
507
662
|
logger: log,
|
|
508
663
|
liveEnabled: false,
|
|
@@ -516,6 +671,8 @@ export async function runBatch({
|
|
|
516
671
|
failed: result.failed,
|
|
517
672
|
total: result.total,
|
|
518
673
|
durationMs: new Date(result.endedAt).getTime() - new Date(result.startedAt).getTime(),
|
|
674
|
+
assertions: result.assertions,
|
|
675
|
+
skipped: result.skipped,
|
|
519
676
|
runDir: result.runDir,
|
|
520
677
|
runLabel: result.label,
|
|
521
678
|
failedSteps: result.failedSteps,
|
|
@@ -612,6 +769,37 @@ export async function runBatch({
|
|
|
612
769
|
});
|
|
613
770
|
});
|
|
614
771
|
|
|
772
|
+
// 批次结束后串行沉淀,避免并发 worker 同时改写 pages.json / learnings.jsonl。
|
|
773
|
+
const learning = { enabled: learnEnabled, learned: [], errors: [] };
|
|
774
|
+
if (learnEnabled) {
|
|
775
|
+
const learnedDirs = new Set();
|
|
776
|
+
for (const run of caseRuns) {
|
|
777
|
+
for (const dir of asArray(run.runDirs)) {
|
|
778
|
+
if (dir) learnedDirs.add(String(dir));
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
for (const dir of learnedDirs) {
|
|
782
|
+
try {
|
|
783
|
+
const result = learnRun(config, { runDir: dir, logger: log });
|
|
784
|
+
markRunLearned(config, dir, result);
|
|
785
|
+
learning.learned.push({
|
|
786
|
+
runDir: dir,
|
|
787
|
+
pagesAdded: result.observations?.pagesAdded || 0,
|
|
788
|
+
actionsAdded: result.observations?.actionsAdded || 0,
|
|
789
|
+
waitsUpdated: result.timing?.updatedPages?.length || 0,
|
|
790
|
+
suggestions: result.timing?.suggestions?.length || 0,
|
|
791
|
+
errors: result.errors,
|
|
792
|
+
});
|
|
793
|
+
if (result.errors.length) {
|
|
794
|
+
learning.errors.push({ runDir: dir, errors: result.errors });
|
|
795
|
+
}
|
|
796
|
+
} catch (error) {
|
|
797
|
+
learning.errors.push({ runDir: dir, errors: [{ stage: 'learn', message: String(error?.message || error) }] });
|
|
798
|
+
log.warn(`批次沉淀跳过 ${dir}:${error.message}`);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
615
803
|
const allRuns = [...caseRuns, ...skippedRuns];
|
|
616
804
|
const recorded = [];
|
|
617
805
|
const skippedRecords = [];
|
|
@@ -663,6 +851,9 @@ export async function runBatch({
|
|
|
663
851
|
seed: summarizeSeedRuns(allRuns.map((run) => ({ seed: run.seed }))),
|
|
664
852
|
recorded: recorded.length,
|
|
665
853
|
recordedSkipped: skippedRecords,
|
|
854
|
+
learning,
|
|
855
|
+
refresh: refreshResult,
|
|
856
|
+
agentTasks,
|
|
666
857
|
cases: allRuns.map((run) => ({
|
|
667
858
|
caseId: run.caseId,
|
|
668
859
|
title: caseById.get(run.caseId)?.title || '',
|
package/lib/browser-ab.mjs
CHANGED
|
@@ -317,14 +317,29 @@ export async function login(session, { logger = null, screenshotPath = null, for
|
|
|
317
317
|
if (!user || !password) {
|
|
318
318
|
throw new StepError('会话已过期,且未设置登录密码(' + pwEnv + ' / OMS_PASSWORD / 账号配置)');
|
|
319
319
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
320
|
+
// 登录页是 SPA,表单在脚本执行后才挂载;按钮晚到不能直接判缺失。
|
|
321
|
+
const formReady = await pollExpr(
|
|
322
|
+
ab,
|
|
323
|
+
null,
|
|
324
|
+
"(() => { const vis=e=>e&&e.getBoundingClientRect().width>0; return Boolean([...document.querySelectorAll('input[type=password]')].find(vis) && [...document.querySelectorAll('button')].find(b=>/^\\s*登录\\s*$/.test((b.innerText||'').trim())&&vis(b))); })()",
|
|
325
|
+
{ timeout: 20000, interval: 500 },
|
|
326
|
+
);
|
|
327
|
+
if (!formReady) throw new StepError('登录页找不到「登录」按钮');
|
|
328
|
+
const mark = (sel, tag) => ab.eval(
|
|
329
|
+
"(() => { const e=[...document.querySelectorAll(" + json(sel) + ")].find(x => { const r=x.getBoundingClientRect(); return r.width>0 && r.height>0; }); if(!e) return null; document.querySelectorAll('[data-ab-target]').forEach(x=>x.removeAttribute('data-ab-target')); e.setAttribute('data-ab-target','" + tag + "'); return '[data-ab-target=\"" + tag + "\"]'; })()",
|
|
330
|
+
);
|
|
331
|
+
// React 受控输入只认真实按键;直接改 value 再点登录会被当成空表单。
|
|
332
|
+
const typeInto = async (sel, value) => {
|
|
333
|
+
try {
|
|
334
|
+
await ab.type(sel, value, { clear: true, delay: 40 });
|
|
335
|
+
} catch {
|
|
336
|
+
await ab.fill(sel, value);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
324
339
|
const userSel = await mark('input[type=text]', 'login-user');
|
|
325
|
-
if (userSel) await
|
|
340
|
+
if (userSel) await typeInto(userSel, user);
|
|
326
341
|
const pwSel = await mark('input[type=password]', 'login-pwd');
|
|
327
|
-
if (pwSel) await
|
|
342
|
+
if (pwSel) await typeInto(pwSel, password);
|
|
328
343
|
const btnSel = await mark('button', 'login-btn-all').catch(() => null);
|
|
329
344
|
const loginBtn = await ab.eval(() => {
|
|
330
345
|
const b = [...document.querySelectorAll('button')].find(x => /^\s*登录\s*$/.test((x.innerText || '').trim()) && x.getBoundingClientRect().width > 0);
|
package/lib/browser.mjs
CHANGED
|
@@ -518,14 +518,14 @@ export async function locateClickableByText(page, text, { exact = false, index =
|
|
|
518
518
|
for (const factory of strategies) {
|
|
519
519
|
const locator = factory();
|
|
520
520
|
const count = await locator.count().catch(() => 0);
|
|
521
|
-
|
|
521
|
+
const visible = [];
|
|
522
522
|
for (let i = 0; i < Math.min(count, 60); i += 1) {
|
|
523
523
|
const item = locator.nth(i);
|
|
524
|
-
if (await item.isVisible().catch(() => false))
|
|
525
|
-
if (visible === index) return item;
|
|
526
|
-
visible += 1;
|
|
527
|
-
}
|
|
524
|
+
if (await item.isVisible().catch(() => false)) visible.push(item);
|
|
528
525
|
}
|
|
526
|
+
// 负索引从可见匹配的末尾取(-1 即最后一个),用于同文案多个入口时点最后一行。
|
|
527
|
+
if (index < 0 && visible.length >= Math.abs(index)) return visible[visible.length + index];
|
|
528
|
+
if (index >= 0 && visible.length > index) return visible[index];
|
|
529
529
|
}
|
|
530
530
|
if (Date.now() >= deadline) break;
|
|
531
531
|
await sleep(250);
|
package/lib/config.mjs
CHANGED
|
@@ -164,6 +164,7 @@ export function loadConfig(projectDir = process.cwd()) {
|
|
|
164
164
|
library: config.knowledge.library ?? null,
|
|
165
165
|
dir: config.knowledge.dir ?? null,
|
|
166
166
|
central: isPlainObject(config.knowledge.central) ? config.knowledge.central : null,
|
|
167
|
+
maintenance: isPlainObject(config.knowledge.maintenance) ? config.knowledge.maintenance : null,
|
|
167
168
|
};
|
|
168
169
|
return resolveConfig(config, dir, configPath);
|
|
169
170
|
}
|