gz-laya-pilot 0.1.2 → 0.1.3

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.
@@ -1,139 +1,139 @@
1
- import type { AgentStatus, CaseEvidence } from './schema.js';
2
-
3
- export interface UpstreamStep {
4
- kind: string;
5
- value?: unknown;
6
- target?: { name?: string; label?: string };
7
- spec?: { title?: string };
8
- }
9
- export interface UpstreamCase {
10
- id: string;
11
- title: string;
12
- operation?: string;
13
- status: string;
14
- reason: string;
15
- steps: UpstreamStep[];
16
- evidence?: string;
17
- failedStep?: { number: number; action: string; target?: string } | null;
18
- browserEvents?: { type?: string; message?: string; url?: string }[];
19
- }
20
- export interface UpstreamReport {
21
- runStatus?: string;
22
- status?: string;
23
- error?: string;
24
- exitCode?: number;
25
- results: UpstreamCase[];
26
- activeCase?: { title?: string };
27
- activity?: string;
28
- caseFile?: string;
29
- retainedRecord?: string;
30
- pendingWrite?: unknown;
31
- metrics?: { modelCalls?: number };
32
- runtime?: { currentName?: string };
33
- coverage?: AgentStatus['coverage'];
34
- }
35
- function assertionTitle(step: UpstreamStep): string {
36
- if (step.spec?.title) return step.spec.title;
37
- const target = step.target?.label ?? step.target?.name ?? '';
38
- const value = Array.isArray(step.value)
39
- ? step.value.join('、')
40
- : typeof step.value === 'string'
41
- ? step.value
42
- .replaceAll('${recordName}', '本轮测试记录')
43
- .replaceAll('${updatedName}', '修改后的本轮记录')
44
- : '';
45
- const titles: Record<string, string> = {
46
- 'assert-control': `控件可见且唯一:${target}`,
47
- 'assert-selected': `页签已选中:${target}`,
48
- 'assert-disabled': `控件不可用:${target}`,
49
- 'assert-headers': `列表包含列头:${value}`,
50
- 'assert-form-errors': `表单提示必填错误:${value}`,
51
- 'assert-input-invalid': `输入校验阻止无效数据:${target}`,
52
- 'assert-row': `列表存在唯一记录:${value}`,
53
- 'assert-absent': `列表中记录已消失:${value}`,
54
- 'assert-persisted-row': `独立会话重新打开后存在唯一记录:${value}`,
55
- 'assert-persisted-absent': `独立会话重新打开后记录不存在:${value}`,
56
- 'assert-text': `页面显示文本:${value}`,
57
- 'assert-record-detail': `列表之外的详情显示本轮记录:${value}`,
58
- 'assert-tab-panel': `页签已选中且关联内容面板可见:${target}`,
59
- 'assert-query-result': `唯一关键词查询仅返回本轮记录:${value}`,
60
- 'assert-disclosure': `展开 ${target} 后出现新控件,并已恢复原状态`,
61
- 'assert-related-records':
62
- '关联添加后显示唯一记录,独立会话确认持久化;移除后列表恢复为空,并再次独立核对',
63
- };
64
- return titles[step.kind] ?? `${step.kind} ${target}`;
65
- }
66
- /** Preserve upstream truth: recorded assertion steps are appended after successful execution. */
67
- export function projectReport(
68
- report: UpstreamReport,
69
- mode: AgentStatus['mode'],
70
- final: boolean,
71
- ): AgentStatus {
72
- const cases: CaseEvidence[] = (report.results ?? []).map((c) => ({
73
- id: c.id,
74
- title: c.title,
75
- ...(c.operation ? { operation: c.operation } : {}),
76
- state: ['通过', '已验证'].includes(c.status)
77
- ? 'passed'
78
- : ['不适用', '未选择'].includes(c.status)
79
- ? 'skipped'
80
- : 'failed',
81
- reason: `${c.status}:${c.reason}`,
82
- screenshot: c.evidence || undefined,
83
- assertions: [
84
- ...c.steps.flatMap((step, i) =>
85
- step.kind.startsWith('assert-')
86
- ? [
87
- {
88
- step: i + 1,
89
- expected: assertionTitle(step),
90
- actual: '页面断言已通过,原始执行记录和浏览器证据见报告。',
91
- passed: true,
92
- },
93
- ]
94
- : [],
95
- ),
96
- ...(c.failedStep?.action.startsWith('assert-')
97
- ? [
98
- {
99
- step: c.failedStep.number,
100
- expected: assertionTitle({
101
- kind: c.failedStep.action,
102
- target: { name: c.failedStep.target },
103
- }),
104
- actual: c.reason,
105
- passed: false,
106
- },
107
- ]
108
- : []),
109
- ],
110
- errors: (c.browserEvents ?? []).map((e) => e.message ?? e.type ?? '页面事件'),
111
- ...(report.retainedRecord
112
- ? { cleanup: `保留测试记录:${report.retainedRecord}` }
113
- : report.pendingWrite
114
- ? { cleanup: '存在未确认写入,请核对 checkpoint.json 后清理。' }
115
- : {}),
116
- }));
117
- const passed = cases.filter((c) => c.state === 'passed').length;
118
- const state: AgentStatus['state'] = !final
119
- ? 'running'
120
- : report.runStatus === 'interrupted'
121
- ? 'stopped'
122
- : report.exitCode === 0
123
- ? 'passed'
124
- : passed
125
- ? 'partial'
126
- : 'failed';
127
- return {
128
- mode,
129
- state,
130
- cases,
131
- decisions: report.metrics?.modelCalls ?? 0,
132
- ...(report.coverage ? { coverage: report.coverage } : {}),
133
- message: !final
134
- ? report.activity || report.activeCase?.title || '正在识别页面控件并生成可验证用例'
135
- : (report.error ??
136
- `${mode === 'explore' ? '探索' : '回放'}结束:${passed} 条通过,${cases.filter((c) => c.state === 'failed').length} 条失败,${cases.filter((c) => c.state === 'skipped').length} 条不适用/未选择${report.coverage?.gaps.length ? `;另有 ${report.coverage.gaps.length} 项入口尚未验证` : ''}`),
137
- ...(final && mode === 'explore' && report.caseFile ? { workbook: 'cases.xlsx' } : {}),
138
- };
139
- }
1
+ import type { AgentStatus, CaseEvidence } from './schema.js';
2
+
3
+ export interface UpstreamStep {
4
+ kind: string;
5
+ value?: unknown;
6
+ target?: { name?: string; label?: string };
7
+ spec?: { title?: string };
8
+ }
9
+ export interface UpstreamCase {
10
+ id: string;
11
+ title: string;
12
+ operation?: string;
13
+ status: string;
14
+ reason: string;
15
+ steps: UpstreamStep[];
16
+ evidence?: string;
17
+ failedStep?: { number: number; action: string; target?: string } | null;
18
+ browserEvents?: { type?: string; message?: string; url?: string }[];
19
+ }
20
+ export interface UpstreamReport {
21
+ runStatus?: string;
22
+ status?: string;
23
+ error?: string;
24
+ exitCode?: number;
25
+ results: UpstreamCase[];
26
+ activeCase?: { title?: string };
27
+ activity?: string;
28
+ caseFile?: string;
29
+ retainedRecord?: string;
30
+ pendingWrite?: unknown;
31
+ metrics?: { modelCalls?: number };
32
+ runtime?: { currentName?: string };
33
+ coverage?: AgentStatus['coverage'];
34
+ }
35
+ function assertionTitle(step: UpstreamStep): string {
36
+ if (step.spec?.title) return step.spec.title;
37
+ const target = step.target?.label ?? step.target?.name ?? '';
38
+ const value = Array.isArray(step.value)
39
+ ? step.value.join('、')
40
+ : typeof step.value === 'string'
41
+ ? step.value
42
+ .replaceAll('${recordName}', '本轮测试记录')
43
+ .replaceAll('${updatedName}', '修改后的本轮记录')
44
+ : '';
45
+ const titles: Record<string, string> = {
46
+ 'assert-control': `控件可见且唯一:${target}`,
47
+ 'assert-selected': `页签已选中:${target}`,
48
+ 'assert-disabled': `控件不可用:${target}`,
49
+ 'assert-headers': `列表包含列头:${value}`,
50
+ 'assert-form-errors': `表单提示必填错误:${value}`,
51
+ 'assert-input-invalid': `输入校验阻止无效数据:${target}`,
52
+ 'assert-row': `列表存在唯一记录:${value}`,
53
+ 'assert-absent': `列表中记录已消失:${value}`,
54
+ 'assert-persisted-row': `独立会话重新打开后存在唯一记录:${value}`,
55
+ 'assert-persisted-absent': `独立会话重新打开后记录不存在:${value}`,
56
+ 'assert-text': `页面显示文本:${value}`,
57
+ 'assert-record-detail': `列表之外的详情显示本轮记录:${value}`,
58
+ 'assert-tab-panel': `页签已选中且关联内容面板可见:${target}`,
59
+ 'assert-query-result': `唯一关键词查询仅返回本轮记录:${value}`,
60
+ 'assert-disclosure': `展开 ${target} 后出现新控件,并已恢复原状态`,
61
+ 'assert-related-records':
62
+ '关联添加后显示唯一记录,独立会话确认持久化;移除后列表恢复为空,并再次独立核对',
63
+ };
64
+ return titles[step.kind] ?? `${step.kind} ${target}`;
65
+ }
66
+ /** Preserve upstream truth: recorded assertion steps are appended after successful execution. */
67
+ export function projectReport(
68
+ report: UpstreamReport,
69
+ mode: AgentStatus['mode'],
70
+ final: boolean,
71
+ ): AgentStatus {
72
+ const cases: CaseEvidence[] = (report.results ?? []).map((c) => ({
73
+ id: c.id,
74
+ title: c.title,
75
+ ...(c.operation ? { operation: c.operation } : {}),
76
+ state: ['通过', '已验证'].includes(c.status)
77
+ ? 'passed'
78
+ : ['不适用', '未选择'].includes(c.status)
79
+ ? 'skipped'
80
+ : 'failed',
81
+ reason: `${c.status}:${c.reason}`,
82
+ screenshot: c.evidence || undefined,
83
+ assertions: [
84
+ ...c.steps.flatMap((step, i) =>
85
+ step.kind.startsWith('assert-')
86
+ ? [
87
+ {
88
+ step: i + 1,
89
+ expected: assertionTitle(step),
90
+ actual: '页面断言已通过,原始执行记录和浏览器证据见报告。',
91
+ passed: true,
92
+ },
93
+ ]
94
+ : [],
95
+ ),
96
+ ...(c.failedStep?.action.startsWith('assert-')
97
+ ? [
98
+ {
99
+ step: c.failedStep.number,
100
+ expected: assertionTitle({
101
+ kind: c.failedStep.action,
102
+ target: { name: c.failedStep.target },
103
+ }),
104
+ actual: c.reason,
105
+ passed: false,
106
+ },
107
+ ]
108
+ : []),
109
+ ],
110
+ errors: (c.browserEvents ?? []).map((e) => e.message ?? e.type ?? '页面事件'),
111
+ ...(report.retainedRecord
112
+ ? { cleanup: `保留测试记录:${report.retainedRecord}` }
113
+ : report.pendingWrite
114
+ ? { cleanup: '存在未确认写入,请核对 checkpoint.json 后清理。' }
115
+ : {}),
116
+ }));
117
+ const passed = cases.filter((c) => c.state === 'passed').length;
118
+ const state: AgentStatus['state'] = !final
119
+ ? 'running'
120
+ : report.runStatus === 'interrupted'
121
+ ? 'stopped'
122
+ : report.exitCode === 0
123
+ ? 'passed'
124
+ : passed
125
+ ? 'partial'
126
+ : 'failed';
127
+ return {
128
+ mode,
129
+ state,
130
+ cases,
131
+ decisions: report.metrics?.modelCalls ?? 0,
132
+ ...(report.coverage ? { coverage: report.coverage } : {}),
133
+ message: !final
134
+ ? report.activity || report.activeCase?.title || '正在识别页面控件并生成可验证用例'
135
+ : (report.error ??
136
+ `${mode === 'explore' ? '探索' : '回放'}结束:${passed} 条通过,${cases.filter((c) => c.state === 'failed').length} 条失败,${cases.filter((c) => c.state === 'skipped').length} 条不适用/未选择${report.coverage?.gaps.length ? `;另有 ${report.coverage.gaps.length} 项入口尚未验证` : ''}`),
137
+ ...(final && mode === 'explore' && report.caseFile ? { workbook: 'cases.xlsx' } : {}),
138
+ };
139
+ }
package/src/agent/run.ts CHANGED
@@ -1,136 +1,136 @@
1
- import { fork, execFile } from 'node:child_process';
2
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
3
- import { existsSync } from 'node:fs';
4
- import { fileURLToPath } from 'node:url';
5
- import path from 'node:path';
6
- import { testUrl, type AgentStatus } from './schema.js';
7
- import { projectReport, type UpstreamReport } from './report.js';
8
-
9
- export interface AgentOptions {
10
- url: string;
11
- outputDir: string;
12
- python: string;
13
- model: string;
14
- workbook?: string;
15
- allowWrite?: boolean;
16
- headed?: boolean;
17
- channel?: string;
18
- authState?: string;
19
- authCheck?: string;
20
- manualLogin?: boolean;
21
- signal?: AbortSignal;
22
- timeout?: number;
23
- onProgress?: (status: AgentStatus) => void;
24
- }
25
- /** Functional npm facade over the pinned upstream generate/execute workflow. No second planner. */
26
- export async function runAgent(options: AgentOptions): Promise<AgentStatus> {
27
- options.signal?.throwIfAborted();
28
- const url = testUrl(options.url),
29
- outputDir = path.resolve(options.outputDir);
30
- if (!existsSync(options.python) || !existsSync(options.model))
31
- throw Error('请配置可用的本地 Laya Python 和模型路径');
32
- if (options.authState && !options.authCheck)
33
- throw Error('复用登录态需要 authCheck 校验登录成功页面');
34
- await mkdir(outputDir, { recursive: true });
35
- if (existsSync(path.join(outputDir, 'checkpoint.json')))
36
- throw Error('输出目录已有运行记录,请使用新的目录');
37
- const mode = options.workbook ? 'replay' : 'explore';
38
- let last: AgentStatus = {
39
- state: 'running',
40
- mode,
41
- message: '正在启动上游 LayaPilot',
42
- cases: [],
43
- decisions: 0,
44
- };
45
- options.onProgress?.(last);
46
- const child = fork(fileURLToPath(new URL('./worker.js', import.meta.url)), [], {
47
- execArgv: [],
48
- stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
49
- ...{ windowsHide: true },
50
- env: {
51
- ...process.env,
52
- PYTHONIOENCODING: 'utf-8',
53
- PYTHONUTF8: '1',
54
- PYTHONDONTWRITEBYTECODE: '1',
55
- HF_HUB_OFFLINE: '1',
56
- },
57
- });
58
- let stopped = false,
59
- finished = false,
60
- diagnostic = '',
61
- stopping: ReturnType<typeof setTimeout> | undefined;
62
- const stop = () => {
63
- if (stopped) return;
64
- stopped = true;
65
- if (child.connected) child.send({ type: 'stop' }, () => {});
66
- stopping = setTimeout(() => {
67
- if (child.exitCode !== null || !child.pid) return;
68
- if (process.platform === 'win32')
69
- execFile(
70
- 'taskkill',
71
- ['/PID', String(child.pid), '/T', '/F'],
72
- { windowsHide: true },
73
- () => {},
74
- );
75
- else child.kill('SIGKILL');
76
- }, 20000);
77
- };
78
- options.signal?.addEventListener('abort', stop, { once: true });
79
- const timeout = setTimeout(stop, options.timeout ?? 12 * 60 * 1000);
80
- const readProgress = async () => {
81
- try {
82
- const report = JSON.parse(
83
- await readFile(path.join(outputDir, 'checkpoint.json'), 'utf8'),
84
- ) as UpstreamReport;
85
- if (finished) return;
86
- last = projectReport(report, mode, false);
87
- options.onProgress?.(last);
88
- } catch {
89
- /* Atomic checkpoint may not exist until startup completes. */
90
- }
91
- };
92
- const polling = setInterval(() => void readProgress(), 1000);
93
- child.stdout?.on('data', (chunk) => {
94
- const message = chunk.toString().trim();
95
- if (message && !message.startsWith('RESULT '))
96
- options.onProgress?.({ ...last, message: message.slice(-1000) });
97
- });
98
- child.stderr?.on('data', (chunk) => {
99
- diagnostic = (diagnostic + chunk.toString()).slice(-1000);
100
- });
101
- child.on('message', (message: { error?: string }) => {
102
- if (message.error) diagnostic = message.error;
103
- });
104
- try {
105
- const exited = new Promise<number | null>((resolve, reject) => {
106
- child.once('error', reject);
107
- child.once('exit', resolve);
108
- });
109
- child.send({
110
- type: 'run',
111
- options: { ...options, url, outputDir, signal: undefined, onProgress: undefined },
112
- });
113
- if (options.signal?.aborted) stop();
114
- const code = await exited;
115
- finished = true;
116
- clearInterval(polling);
117
- let report: UpstreamReport;
118
- try {
119
- report = JSON.parse(await readFile(path.join(outputDir, 'results.json'), 'utf8'));
120
- } catch {
121
- report = { results: [], exitCode: code ?? 1, error: diagnostic || '上游执行未生成报告' };
122
- }
123
- last = projectReport(report, mode, true);
124
- if (stopped) last.state = 'stopped';
125
- if (existsSync(path.join(outputDir, 'trace.zip'))) last.trace = 'trace.zip';
126
- await writeFile(path.join(outputDir, 'assistant-status.json'), JSON.stringify(last, null, 2));
127
- options.onProgress?.(last);
128
- return last;
129
- } finally {
130
- finished = true;
131
- clearInterval(polling);
132
- clearTimeout(timeout);
133
- clearTimeout(stopping);
134
- options.signal?.removeEventListener('abort', stop);
135
- }
136
- }
1
+ import { fork, execFile } from 'node:child_process';
2
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
3
+ import { existsSync } from 'node:fs';
4
+ import { fileURLToPath } from 'node:url';
5
+ import path from 'node:path';
6
+ import { testUrl, type AgentStatus } from './schema.js';
7
+ import { projectReport, type UpstreamReport } from './report.js';
8
+
9
+ export interface AgentOptions {
10
+ url: string;
11
+ outputDir: string;
12
+ python: string;
13
+ model: string;
14
+ workbook?: string;
15
+ allowWrite?: boolean;
16
+ headed?: boolean;
17
+ channel?: string;
18
+ authState?: string;
19
+ authCheck?: string;
20
+ manualLogin?: boolean;
21
+ signal?: AbortSignal;
22
+ timeout?: number;
23
+ onProgress?: (status: AgentStatus) => void;
24
+ }
25
+ /** Functional npm facade over the pinned upstream generate/execute workflow. No second planner. */
26
+ export async function runAgent(options: AgentOptions): Promise<AgentStatus> {
27
+ options.signal?.throwIfAborted();
28
+ const url = testUrl(options.url),
29
+ outputDir = path.resolve(options.outputDir);
30
+ if (!existsSync(options.python) || !existsSync(options.model))
31
+ throw Error('请配置可用的本地 Laya Python 和模型路径');
32
+ if (options.authState && !options.authCheck)
33
+ throw Error('复用登录态需要 authCheck 校验登录成功页面');
34
+ await mkdir(outputDir, { recursive: true });
35
+ if (existsSync(path.join(outputDir, 'checkpoint.json')))
36
+ throw Error('输出目录已有运行记录,请使用新的目录');
37
+ const mode = options.workbook ? 'replay' : 'explore';
38
+ let last: AgentStatus = {
39
+ state: 'running',
40
+ mode,
41
+ message: '正在启动上游 LayaPilot',
42
+ cases: [],
43
+ decisions: 0,
44
+ };
45
+ options.onProgress?.(last);
46
+ const child = fork(fileURLToPath(new URL('./worker.js', import.meta.url)), [], {
47
+ execArgv: [],
48
+ stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
49
+ ...{ windowsHide: true },
50
+ env: {
51
+ ...process.env,
52
+ PYTHONIOENCODING: 'utf-8',
53
+ PYTHONUTF8: '1',
54
+ PYTHONDONTWRITEBYTECODE: '1',
55
+ HF_HUB_OFFLINE: '1',
56
+ },
57
+ });
58
+ let stopped = false,
59
+ finished = false,
60
+ diagnostic = '',
61
+ stopping: ReturnType<typeof setTimeout> | undefined;
62
+ const stop = () => {
63
+ if (stopped) return;
64
+ stopped = true;
65
+ if (child.connected) child.send({ type: 'stop' }, () => {});
66
+ stopping = setTimeout(() => {
67
+ if (child.exitCode !== null || !child.pid) return;
68
+ if (process.platform === 'win32')
69
+ execFile(
70
+ 'taskkill',
71
+ ['/PID', String(child.pid), '/T', '/F'],
72
+ { windowsHide: true },
73
+ () => {},
74
+ );
75
+ else child.kill('SIGKILL');
76
+ }, 20000);
77
+ };
78
+ options.signal?.addEventListener('abort', stop, { once: true });
79
+ const timeout = setTimeout(stop, options.timeout ?? 12 * 60 * 1000);
80
+ const readProgress = async () => {
81
+ try {
82
+ const report = JSON.parse(
83
+ await readFile(path.join(outputDir, 'checkpoint.json'), 'utf8'),
84
+ ) as UpstreamReport;
85
+ if (finished) return;
86
+ last = projectReport(report, mode, false);
87
+ options.onProgress?.(last);
88
+ } catch {
89
+ /* Atomic checkpoint may not exist until startup completes. */
90
+ }
91
+ };
92
+ const polling = setInterval(() => void readProgress(), 1000);
93
+ child.stdout?.on('data', (chunk) => {
94
+ const message = chunk.toString().trim();
95
+ if (message && !message.startsWith('RESULT '))
96
+ options.onProgress?.({ ...last, message: message.slice(-1000) });
97
+ });
98
+ child.stderr?.on('data', (chunk) => {
99
+ diagnostic = (diagnostic + chunk.toString()).slice(-1000);
100
+ });
101
+ child.on('message', (message: { error?: string }) => {
102
+ if (message.error) diagnostic = message.error;
103
+ });
104
+ try {
105
+ const exited = new Promise<number | null>((resolve, reject) => {
106
+ child.once('error', reject);
107
+ child.once('exit', resolve);
108
+ });
109
+ child.send({
110
+ type: 'run',
111
+ options: { ...options, url, outputDir, signal: undefined, onProgress: undefined },
112
+ });
113
+ if (options.signal?.aborted) stop();
114
+ const code = await exited;
115
+ finished = true;
116
+ clearInterval(polling);
117
+ let report: UpstreamReport;
118
+ try {
119
+ report = JSON.parse(await readFile(path.join(outputDir, 'results.json'), 'utf8'));
120
+ } catch {
121
+ report = { results: [], exitCode: code ?? 1, error: diagnostic || '上游执行未生成报告' };
122
+ }
123
+ last = projectReport(report, mode, true);
124
+ if (stopped) last.state = 'stopped';
125
+ if (existsSync(path.join(outputDir, 'trace.zip'))) last.trace = 'trace.zip';
126
+ await writeFile(path.join(outputDir, 'assistant-status.json'), JSON.stringify(last, null, 2));
127
+ options.onProgress?.(last);
128
+ return last;
129
+ } finally {
130
+ finished = true;
131
+ clearInterval(polling);
132
+ clearTimeout(timeout);
133
+ clearTimeout(stopping);
134
+ options.signal?.removeEventListener('abort', stop);
135
+ }
136
+ }
@@ -1,38 +1,38 @@
1
- /** UI projection of upstream reports. Execution and workbook grammar remain upstream-owned. */
2
- export interface CaseEvidence {
3
- id: string;
4
- title: string;
5
- operation?: string;
6
- state: 'passed' | 'failed' | 'skipped';
7
- reason: string;
8
- assertions: { step: number; expected: string; actual: string; passed: boolean }[];
9
- screenshot?: string;
10
- errors: string[];
11
- cleanup?: string;
12
- }
13
- export interface AgentStatus {
14
- id?: string;
15
- state: 'idle' | 'running' | 'passed' | 'partial' | 'failed' | 'stopped';
16
- mode: 'explore' | 'replay';
17
- message: string;
18
- cases: CaseEvidence[];
19
- decisions: number;
20
- workbook?: string;
21
- trace?: string;
22
- coverage?: {
23
- states: string[];
24
- gaps: { state: string; role: string; name: string; reason: string }[];
25
- };
26
- }
27
- export interface AgentCapabilities {
28
- configured: boolean;
29
- message: string;
30
- targets: string[];
31
- }
32
- export function testUrl(value: unknown): string {
33
- if (typeof value !== 'string' || value.length > 2000) throw Error('测试地址格式错误');
34
- const url = new URL(value);
35
- if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password)
36
- throw Error('测试地址必须为不含凭据的 HTTP(S) 地址');
37
- return url.href;
38
- }
1
+ /** UI projection of upstream reports. Execution and workbook grammar remain upstream-owned. */
2
+ export interface CaseEvidence {
3
+ id: string;
4
+ title: string;
5
+ operation?: string;
6
+ state: 'passed' | 'failed' | 'skipped';
7
+ reason: string;
8
+ assertions: { step: number; expected: string; actual: string; passed: boolean }[];
9
+ screenshot?: string;
10
+ errors: string[];
11
+ cleanup?: string;
12
+ }
13
+ export interface AgentStatus {
14
+ id?: string;
15
+ state: 'idle' | 'running' | 'passed' | 'partial' | 'failed' | 'stopped';
16
+ mode: 'explore' | 'replay';
17
+ message: string;
18
+ cases: CaseEvidence[];
19
+ decisions: number;
20
+ workbook?: string;
21
+ trace?: string;
22
+ coverage?: {
23
+ states: string[];
24
+ gaps: { state: string; role: string; name: string; reason: string }[];
25
+ };
26
+ }
27
+ export interface AgentCapabilities {
28
+ configured: boolean;
29
+ message: string;
30
+ targets: string[];
31
+ }
32
+ export function testUrl(value: unknown): string {
33
+ if (typeof value !== 'string' || value.length > 2000) throw Error('测试地址格式错误');
34
+ const url = new URL(value);
35
+ if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password)
36
+ throw Error('测试地址必须为不含凭据的 HTTP(S) 地址');
37
+ return url.href;
38
+ }