lantern-harness 0.1.9 → 0.1.11
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/CHANGELOG.md +90 -0
- package/README.md +6 -6
- package/builtin/session/lh-fs.mjs +32 -14
- package/dist/500.html +258 -22
- package/dist/_astro/Base.Bgxs1QQl.css +1 -0
- package/dist/_astro/Base.astro_astro_type_script_index_0_lang.CvbRi7Tl.js +1 -0
- package/dist/_astro/CaseExecBoard.Dttqp0wg.js +1 -0
- package/dist/_astro/CaseGenerateApp.DqW_nWMc.js +9 -0
- package/dist/_astro/CasesLibrary.8aMUUGp_.js +1 -0
- package/dist/_astro/ChatApp.BLxf0h1d.js +219 -0
- package/dist/_astro/ColumnResize.BEkEW7qw.js +1 -0
- package/dist/_astro/{ConfirmDialog.CBVsDJ8f.js → ConfirmDialog.BZzZWDci.js} +1 -1
- package/dist/_astro/{DashboardBoard.DCtfrrJz.js → DashboardBoard.CkSbhEDI.js} +3 -3
- package/dist/_astro/DatePicker.Bkl71M49.js +1 -0
- package/dist/_astro/DocsFileBrowser.MKVCfZrE.js +1 -0
- package/dist/_astro/DocsPager.DJY4foYL.js +1 -0
- package/dist/_astro/{DrawerField.CWMLhcPX.js → DrawerField.CHRg77LG.js} +1 -1
- package/dist/_astro/{ExcelFieldTags.B_XMwNNx.js → ExcelFieldTags.DXMeaDa5.js} +4 -4
- package/dist/_astro/KnowledgeLibrary.B-p1aoQN.js +1 -0
- package/dist/_astro/NamePromptDialog.Wa9O530a.js +1 -0
- package/dist/_astro/NavLibraries.C6LImMO_.js +1 -0
- package/dist/_astro/OverflowHint.D6v4Uj2N.js +1 -0
- package/dist/_astro/PluginsPage.-97n3x2U.js +39 -0
- package/dist/_astro/PluginsPage.DkmRPfbU.js +1 -0
- package/dist/_astro/PmBugsBoard.CMT4-eoB.js +1 -0
- package/dist/_astro/PmIterationsBoard.BQM_dzdZ.js +1 -0
- package/dist/_astro/PmProjectDetail.CzU80pat.js +1 -0
- package/dist/_astro/PmProjectsBoard.Cxsa7SYQ.js +1 -0
- package/dist/_astro/PmRequirementsBoard.4_JMDDN0.js +1 -0
- package/dist/_astro/PmRequirementsBoard.B8HL07cw.js +1 -0
- package/dist/_astro/PmShared.Ca2Ao7v_.js +1 -0
- package/dist/_astro/PromptsLibrary.C9BcIxKK.js +1 -0
- package/dist/_astro/ReportsPage.Fh5DRKLT.js +1 -0
- package/dist/_astro/RequirementsLibrary.CBkuWE8X.js +1 -0
- package/dist/_astro/SearchableSelect.DnjoSslK.js +1 -0
- package/dist/_astro/SelectDropdown.CuuDHa8s.js +1 -0
- package/dist/_astro/SettingsDialog.CVB5Gtk4.js +1 -0
- package/dist/_astro/SlideOverDrawer.B7B5Wu8I.js +1 -0
- package/dist/_astro/{SpaceSwitcher.CI3KDBOA.js → SpaceSwitcher.BVQLt_tL.js} +2 -2
- package/dist/_astro/TagSelect.CuN5RdF4.js +1 -0
- package/dist/_astro/TasksBoard.Bu-fpIZ7.js +1 -0
- package/dist/_astro/TemplatesLibrary.DSylQGlN.js +1 -0
- package/dist/_astro/TestStatsBoard.CPyKW4wc.js +1 -0
- package/dist/_astro/Toast.R8_2OWRX.js +1 -0
- package/dist/_astro/TodosBoard.8kvRTEW-.js +1 -0
- package/dist/_astro/UiAutoBoard.DFTiDqCp.js +9 -0
- package/dist/_astro/active-element-history.CED-m1Zp.js +1 -0
- package/dist/_astro/app-config.BUPzGl9f.js +1 -0
- package/dist/_astro/{client.Be_SakrB.js → client.BHNTqLjv.js} +3 -3
- package/dist/_astro/dialog.BAPTk9a_.js +1 -0
- package/dist/_astro/hydrate-cache.BXX604Bw.js +1 -0
- package/dist/_astro/{i18n.B52gLzii.js → i18n.BGPnP1Bg.js} +1 -1
- package/dist/_astro/index.astro_astro_type_script_index_0_lang.LPL9mPQY.js +1 -0
- package/dist/_astro/jsx-runtime.DUg_B_vD.js +1 -0
- package/dist/_astro/{lib.DJNDi_Ht.js → lib.CgXLzMMd.js} +15 -15
- package/dist/_astro/listbox.C96OCanh.js +1 -0
- package/dist/_astro/markdown-client.DRva7DS9.js +58 -0
- package/dist/_astro/menu.IPWdRoNM.js +1 -0
- package/dist/_astro/{open-docs-in-session.Xg3OSOfc.js → open-docs-in-session.CyFNgh1I.js} +1 -1
- package/dist/_astro/{plugins.BDZqJNOy.js → plugins.C2BMfzv1.js} +1 -1
- package/dist/_astro/{pm.Bl3hz9fF.js → pm.CagBA-ht.js} +2 -2
- package/dist/_astro/{portal.Cm9XlIPf.js → portal.C0hAhXDF.js} +2 -2
- package/dist/_astro/prompts-meta.Bua-j14I.js +2 -0
- package/dist/_astro/react-dom.DLW9pGCF.js +1 -0
- package/dist/_astro/{react-dom.CqAxpHMt.js → react.Blvh0GOs.js} +1 -1
- package/dist/_astro/report-prompt.CAfZ6RIo.js +1 -0
- package/dist/_astro/{settings.C6NWuiFO.js → settings.Ceefeil5.js} +2 -2
- package/dist/_astro/{spaces-client.k_ciWMai.js → spaces-client.BocUabwy.js} +1 -1
- package/dist/_astro/ui-auto-prompt.CX8fju7r.js +3 -0
- package/dist/_astro/ui-auto.BmC9JJ_X.js +1 -0
- package/dist/_astro/update.CtF8vsag.js +1 -0
- package/dist/_astro/use-text-value.DBQvHeNl.js +1 -0
- package/dist/_astro/use-tree-walker.DFU2AaAP.js +1 -0
- package/dist/_astro/useListAnim.BoerpmsB.js +1 -0
- package/dist/_astro/{view-prefs.Dyu_lmN2.js → view-prefs.BEAZRcxF.js} +1 -1
- package/dist/case-exec/index.html +458 -22
- package/dist/cases/generate/index.html +258 -22
- package/dist/cases/library/index.html +458 -22
- package/dist/dashboard/index.html +458 -22
- package/dist/docs/changelog/index.html +373 -23
- package/dist/docs/install/index.html +258 -22
- package/dist/docs/manual/index.html +314 -35
- package/dist/index.html +2 -281
- package/dist/knowledge/index.html +458 -22
- package/dist/knowledge//345/212/237/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/347/274/226/345/206/231/350/247/204/350/214/203/index.html +258 -22
- package/dist/plugins/index.html +258 -22
- package/dist/pm/bugs/index.html +458 -22
- package/dist/pm/iterations/index.html +458 -22
- package/dist/pm/projects/detail/index.html +458 -22
- package/dist/pm/projects/index.html +458 -22
- package/dist/pm/requirements/index.html +458 -22
- package/dist/prompts/index.html +458 -22
- package/dist/reports/index.html +458 -22
- package/dist/requirements/index.html +458 -22
- package/dist/tasks/index.html +458 -22
- package/dist/templates/index.html +458 -22
- package/dist/templates//345/212/237/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212//345/212/237/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +258 -22
- package/dist/templates//346/200/247/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212//346/200/247/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +258 -22
- package/dist/templates//346/200/247/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213//346/200/247/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/346/250/241/346/235/277/index.html +258 -22
- package/dist/templates//346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212//346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +258 -22
- package/dist/templates//350/207/252/345/212/250/345/214/226/346/265/213/350/257/225/347/224/250/344/276/213//350/207/252/345/212/250/345/214/226/346/265/213/350/257/225/347/224/250/344/276/213/346/250/241/346/235/277/index.html +258 -22
- package/dist/test-automation/index.html +717 -0
- package/dist/test-stats/index.html +458 -22
- package/dist/todos/index.html +458 -22
- package/dist/workbench/index.html +517 -0
- package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +80 -43
- package/lh-plugins/lh-project-docs.mjs +14 -0
- package/lh-plugins/lh-uiauto.mjs +1445 -386
- package/lh-plugins/plugin-prompts.mjs +200 -0
- package/lh-plugins/storage-domain.mjs +6 -0
- package/lh-plugins/uiauto-adapters/index.mjs +57 -0
- package/lh-plugins/uiauto-adapters/playwright.mjs +215 -0
- package/lh-plugins/uiauto-adapters/pytest.mjs +151 -0
- package/lh-plugins/uiauto-adapters/selenium.mjs +163 -0
- package/lh-plugins/uiauto-adapters/shared.mjs +371 -0
- package/lh-plugins/uiauto-adapters/tasks.mjs +369 -0
- package/lh-plugins/uiauto-explorer/apps.mjs +332 -0
- package/lh-plugins/uiauto-explorer/diff.mjs +159 -0
- package/lh-plugins/uiauto-explorer/emit-files.mjs +506 -0
- package/lh-plugins/uiauto-explorer/emit-python.mjs +160 -0
- package/lh-plugins/uiauto-explorer/emit-ts.mjs +118 -0
- package/lh-plugins/uiauto-explorer/emit.mjs +15 -0
- package/lh-plugins/uiauto-explorer/ir.mjs +114 -0
- package/lh-plugins/uiauto-explorer/locators.mjs +267 -0
- package/lh-plugins/uiauto-explorer/merge.mjs +235 -0
- package/lh-plugins/uiauto-explorer/plan.mjs +165 -0
- package/lh-plugins/uiauto-explorer/runner.mjs +370 -0
- package/lh-plugins/uiauto-explorer/sessions.mjs +1373 -0
- package/lh-plugins/uiauto-explorer/snapshot.mjs +492 -0
- package/lh-plugins/uiauto-prompt.mjs +122 -0
- package/lh-plugins/uiauto-report.mjs +111 -0
- package/package.json +1 -1
- package/dist/_astro/Base.4X_wsSoR.css +0 -1
- package/dist/_astro/Base.astro_astro_type_script_index_0_lang.Dy7fJoxu.js +0 -1
- package/dist/_astro/CaseExecBoard.DKdfW5fM.js +0 -1
- package/dist/_astro/CaseGenerateApp.Bm8AyH9s.js +0 -9
- package/dist/_astro/CasesLibrary.CvVJZ74h.js +0 -1
- package/dist/_astro/ChatApp.BS-wLBRa.js +0 -276
- package/dist/_astro/ColumnResize.Bs6GL3DJ.js +0 -1
- package/dist/_astro/DatePicker.CMfX7F6z.js +0 -1
- package/dist/_astro/DocsFileBrowser.BtRoZ787.js +0 -1
- package/dist/_astro/DocsPager.C20ue_JZ.js +0 -1
- package/dist/_astro/KnowledgeLibrary.CV4DyStj.js +0 -1
- package/dist/_astro/NamePromptDialog.Dl5kSnQI.js +0 -1
- package/dist/_astro/NavLibraries.DmD2lZBZ.js +0 -1
- package/dist/_astro/OverflowHint.lzmplP5j.js +0 -1
- package/dist/_astro/PluginsPage.B59AMDrB.js +0 -1
- package/dist/_astro/PluginsPage.BEAPymNL.js +0 -39
- package/dist/_astro/PmBugsBoard.CPEyBp0l.js +0 -1
- package/dist/_astro/PmIterationsBoard.zCeLpcBo.js +0 -1
- package/dist/_astro/PmProjectDetail.ejIam5sD.js +0 -1
- package/dist/_astro/PmProjectsBoard.DbXzir8o.js +0 -1
- package/dist/_astro/PmRequirementsBoard.CynewRfv.js +0 -1
- package/dist/_astro/PmRequirementsBoard.D9eUMJWI.js +0 -1
- package/dist/_astro/PmShared.BxTHKdjY.js +0 -1
- package/dist/_astro/PromptsLibrary.Bkruu80b.js +0 -1
- package/dist/_astro/ReportsPage.BoBQshMQ.js +0 -1
- package/dist/_astro/RequirementsLibrary.BC0A8qdk.js +0 -1
- package/dist/_astro/SearchableSelect.CXa1hiDd.js +0 -1
- package/dist/_astro/SelectDropdown.Buv7rQJ_.js +0 -1
- package/dist/_astro/SettingsDialog.Dc-9QNJI.js +0 -1
- package/dist/_astro/SlideOverDrawer.TPbGEoWn.js +0 -1
- package/dist/_astro/TagSelect.u8DTop7v.js +0 -1
- package/dist/_astro/TasksBoard.Bb--oVV8.js +0 -1
- package/dist/_astro/TemplatesLibrary.D1wZq94E.js +0 -1
- package/dist/_astro/TestStatsBoard.DlVezlXl.js +0 -1
- package/dist/_astro/TodosBoard.S84wqcWY.js +0 -1
- package/dist/_astro/UiAutoBoard.BKp9ifxg.js +0 -1
- package/dist/_astro/active-element-history.CeefGkFQ.js +0 -1
- package/dist/_astro/app-config.DUyozIL9.js +0 -1
- package/dist/_astro/dialog.DXHznyjD.js +0 -1
- package/dist/_astro/jsx-runtime.BUXbF_vF.js +0 -1
- package/dist/_astro/listbox.Di-t5U37.js +0 -1
- package/dist/_astro/menu.Bkluqxic.js +0 -1
- package/dist/_astro/prompts-meta.F4wwkjUA.js +0 -2
- package/dist/_astro/report-prompt.Cmw4XzfY.js +0 -1
- package/dist/_astro/update.Bl_HfSe6.js +0 -1
- package/dist/_astro/use-text-value.BuY0Cm1z.js +0 -1
- package/dist/_astro/use-tree-walker.CfTHFX43.js +0 -1
- package/dist/_astro/useListAnim.CpGB1cft.js +0 -1
- package/dist/ui-automation/index.html +0 -281
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 写入已存在的文件时,默认「合并」而不是整文件覆盖。
|
|
3
|
+
*
|
|
4
|
+
* 起因:项目里原有 admin_cart.spec.ts 有几百行、好几个用例,新增一个用例
|
|
5
|
+
* 直接把整文件覆盖等于把人家的用例全删了。所以按文件角色分别合并:
|
|
6
|
+
* - spec:保留原文件,只把这次生成的用例追加进去(缺的 import 补到 import 区)
|
|
7
|
+
* - page object:保类不动,只往类里补缺失的方法
|
|
8
|
+
* - fixture:已经有 STORAGE_STATE 就不动,没有才追加
|
|
9
|
+
*
|
|
10
|
+
* 合并真正做不了(比如类名/文件名对不上、语法结构认不出来)时返回 null,
|
|
11
|
+
* 上层按「冲突」处理,让用户显式勾选覆盖。
|
|
12
|
+
*
|
|
13
|
+
* 全部函数都是纯字符串处理,方便单测。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const TS_IMPORT = /^import\s/;
|
|
17
|
+
const PY_IMPORT = /^(?:import\s|from\s+\S+\s+import\s)/;
|
|
18
|
+
|
|
19
|
+
function isImportLine(line, lang) {
|
|
20
|
+
if (!line || /^\s/.test(line)) return false;
|
|
21
|
+
return lang === 'python' ? PY_IMPORT.test(line) : TS_IMPORT.test(line);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function escapeRe(value) {
|
|
25
|
+
return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** 找出 import 区的范围:返回 [第一行 import 下标, 最后一行 import 下标] */
|
|
29
|
+
function importRange(lines, lang) {
|
|
30
|
+
let first = -1;
|
|
31
|
+
let last = -1;
|
|
32
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
33
|
+
if (!isImportLine(lines[index], lang)) continue;
|
|
34
|
+
if (first === -1) first = index;
|
|
35
|
+
last = index;
|
|
36
|
+
}
|
|
37
|
+
return [first, last];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 把缺的 import 补到已有文件里:有 import 就接在最后一个后面,没有就放最前面 */
|
|
41
|
+
function insertImports(existing, imports, lang) {
|
|
42
|
+
if (!imports.length) return existing;
|
|
43
|
+
const lines = existing.split('\n');
|
|
44
|
+
const [, lastIndex] = importRange(lines, lang);
|
|
45
|
+
if (lastIndex === -1) return [...imports, '', ...lines].join('\n');
|
|
46
|
+
const head = lines.slice(0, lastIndex + 1);
|
|
47
|
+
const tail = lines.slice(lastIndex + 1);
|
|
48
|
+
// 后面紧跟着空行就保持一个空行,不额外再加
|
|
49
|
+
if (tail.length && tail[0].trim() === '') return [...head, ...imports, ...tail].join('\n');
|
|
50
|
+
return [...head, ...imports, '', ...tail].join('\n');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function guessLang(text, filePath) {
|
|
54
|
+
if (/\.py$/i.test(filePath || '')) return 'python';
|
|
55
|
+
if (/\.(ts|tsx|js|mjs|cjs|jsx)$/i.test(filePath || '')) return 'ts';
|
|
56
|
+
return /^\s*(?:from|import)\s+\S+\s*$/m.test(text) || /\bdef\s+\w+\(/.test(text)
|
|
57
|
+
? 'python'
|
|
58
|
+
: 'ts';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** spec 的「用例签名」:用来判断这个用例是不是已经写过了 */
|
|
62
|
+
function specSignature(text, lang) {
|
|
63
|
+
if (lang === 'python') {
|
|
64
|
+
const hit = /^def\s+(test_\w+)\(/m.exec(text);
|
|
65
|
+
return hit ? `def ${hit[1]}(` : '';
|
|
66
|
+
}
|
|
67
|
+
const hit = /^\s*test\("([^"]+)"/m.exec(text);
|
|
68
|
+
return hit ? `test("${hit[1]}"` : '';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* spec 合并:补 import + 追加用例块。
|
|
73
|
+
* 用例已经存在(同名 test / 同名 test_ 函数)就原样返回,避免重复跑。
|
|
74
|
+
*/
|
|
75
|
+
export function mergeSpec(existing, incoming, lang) {
|
|
76
|
+
const incLines = incoming.split('\n');
|
|
77
|
+
const [, incLastImport] = importRange(incLines, lang);
|
|
78
|
+
const existingLines = existing.split('\n');
|
|
79
|
+
const existingSet = new Set(existingLines.map((line) => line.trim()));
|
|
80
|
+
|
|
81
|
+
const missing = [];
|
|
82
|
+
for (let index = 0; index <= incLastImport; index += 1) {
|
|
83
|
+
const line = incLines[index];
|
|
84
|
+
if (!isImportLine(line, lang)) continue;
|
|
85
|
+
const trimmed = line.trim();
|
|
86
|
+
if (!existingSet.has(trimmed)) missing.push(trimmed);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const sig = specSignature(incoming, lang);
|
|
90
|
+
if (sig && existing.includes(sig)) {
|
|
91
|
+
return { content: existing, unchanged: true };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 用例正文 = 最后一个 import 之后的内容(顺带丢掉文件头的说明注释)
|
|
95
|
+
const bodyLines = [];
|
|
96
|
+
const topLevel = [];
|
|
97
|
+
for (const line of incLines.slice(incLastImport + 1)) {
|
|
98
|
+
const trimmed = line.trim();
|
|
99
|
+
// test.use / BASE_URL 这类文件级语句:已有就别重复,缺的提到 import 后面
|
|
100
|
+
if (/^test\.use\(/.test(trimmed) || /^BASE_URL\s*=/.test(trimmed)) {
|
|
101
|
+
if (!existingSet.has(trimmed)) topLevel.push(trimmed);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
bodyLines.push(line);
|
|
105
|
+
}
|
|
106
|
+
const body = bodyLines.join('\n').trim();
|
|
107
|
+
if (!body && !topLevel.length) return { content: existing, unchanged: true };
|
|
108
|
+
|
|
109
|
+
const block = topLevel.length ? [...missing, '', ...topLevel] : missing;
|
|
110
|
+
const withImports = insertImports(existing, block, lang);
|
|
111
|
+
const content = body
|
|
112
|
+
? `${withImports.replace(/\s+$/, '')}\n\n${body}\n`
|
|
113
|
+
: `${withImports.replace(/\s+$/, '')}\n`;
|
|
114
|
+
return { content, unchanged: false };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** TS page object 里的方法块(2 空格缩进,按大括号配平取方法体) */
|
|
118
|
+
function tsMethods(text) {
|
|
119
|
+
const lines = text.split('\n');
|
|
120
|
+
const out = [];
|
|
121
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
122
|
+
const start = /^ {2}(?:async\s+)?([A-Za-z_$][\w$]*)\s*\(/.exec(lines[index]);
|
|
123
|
+
if (!start) continue;
|
|
124
|
+
let depth = 0;
|
|
125
|
+
let opened = false;
|
|
126
|
+
let end = index;
|
|
127
|
+
for (let cursor = index; cursor < lines.length; cursor += 1) {
|
|
128
|
+
const line = lines[cursor];
|
|
129
|
+
for (const char of line) {
|
|
130
|
+
if (char === '{') {
|
|
131
|
+
depth += 1;
|
|
132
|
+
opened = true;
|
|
133
|
+
} else if (char === '}') {
|
|
134
|
+
depth -= 1;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
end = cursor;
|
|
138
|
+
if (opened && depth <= 0) break;
|
|
139
|
+
}
|
|
140
|
+
out.push({ name: start[1], code: lines.slice(index, end + 1).join('\n') });
|
|
141
|
+
index = end;
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Python page object 里的方法块(4 空格缩进,到下一个同级语句为止) */
|
|
147
|
+
function pyMethods(text) {
|
|
148
|
+
const lines = text.split('\n');
|
|
149
|
+
const out = [];
|
|
150
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
151
|
+
const start = /^ {4}def\s+(\w+)\s*\(/.exec(lines[index]);
|
|
152
|
+
if (!start) continue;
|
|
153
|
+
let end = lines.length - 1;
|
|
154
|
+
for (let cursor = index + 1; cursor < lines.length; cursor += 1) {
|
|
155
|
+
if (/^ {0,4}\S/.test(lines[cursor])) {
|
|
156
|
+
end = cursor - 1;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
while (end > index && lines[end].trim() === '') end -= 1;
|
|
161
|
+
out.push({ name: start[1], code: lines.slice(index, end + 1).join('\n') });
|
|
162
|
+
index = end;
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** TS page object 合并:类名一致时只补缺失的方法,插在类结尾 } 之前 */
|
|
168
|
+
export function mergeTsPage(existing, incoming) {
|
|
169
|
+
const cls = /export\s+class\s+(\w+)/.exec(incoming)?.[1];
|
|
170
|
+
if (!cls) return null;
|
|
171
|
+
if (!new RegExp(`export\\s+class\\s+${escapeRe(cls)}\\b`).test(existing)) return null;
|
|
172
|
+
|
|
173
|
+
const missing = tsMethods(incoming).filter(
|
|
174
|
+
(method) =>
|
|
175
|
+
method.name !== 'constructor' &&
|
|
176
|
+
!new RegExp(`(?:async\\s+)?${escapeRe(method.name)}\\s*\\(`).test(existing),
|
|
177
|
+
);
|
|
178
|
+
if (!missing.length) return { content: existing, unchanged: true };
|
|
179
|
+
|
|
180
|
+
const closeAt = existing.lastIndexOf('\n}');
|
|
181
|
+
if (closeAt === -1) return null;
|
|
182
|
+
// 每个方法前留一个空行,和生成器保持一致
|
|
183
|
+
const blocks = missing.map((method) => `\n\n${method.code}`);
|
|
184
|
+
const content = `${existing.slice(0, closeAt)}${blocks.join('')}\n${existing
|
|
185
|
+
.slice(closeAt)
|
|
186
|
+
.replace(/^\n/, '')}`;
|
|
187
|
+
return { content, unchanged: false };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Python page object 合并:类名一致时把缺失的方法追加到文件末尾(类在文件最后) */
|
|
191
|
+
export function mergePyPage(existing, incoming) {
|
|
192
|
+
const cls = /^class\s+(\w+)/m.exec(incoming)?.[1];
|
|
193
|
+
if (!cls) return null;
|
|
194
|
+
if (!new RegExp(`^class\\s+${escapeRe(cls)}\\b`, 'm').test(existing)) return null;
|
|
195
|
+
|
|
196
|
+
const missing = pyMethods(incoming).filter(
|
|
197
|
+
(method) =>
|
|
198
|
+
method.name !== '__init__' &&
|
|
199
|
+
!new RegExp(`def\\s+${escapeRe(method.name)}\\s*\\(`).test(existing),
|
|
200
|
+
);
|
|
201
|
+
if (!missing.length) return { content: existing, unchanged: true };
|
|
202
|
+
|
|
203
|
+
const content = `${existing.replace(/\s+$/, '')}\n\n${missing
|
|
204
|
+
.map((method) => method.code)
|
|
205
|
+
.join('\n\n')}\n`;
|
|
206
|
+
return { content, unchanged: false };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** 登录态常量:已经有 STORAGE_STATE 就完全不动 */
|
|
210
|
+
export function mergeFixture(existing, incoming) {
|
|
211
|
+
if (/STORAGE_STATE/.test(existing)) return { content: existing, unchanged: true };
|
|
212
|
+
const body = incoming.trim();
|
|
213
|
+
if (!body) return { content: existing, unchanged: true };
|
|
214
|
+
return { content: `${existing.replace(/\s+$/, '')}\n\n${body}\n`, unchanged: false };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 入口:按角色合并。返回 `{ content, unchanged }`;无法安全合并返回 null。
|
|
219
|
+
*/
|
|
220
|
+
export function mergeGeneratedFile(existing, incoming, options = {}) {
|
|
221
|
+
const role = String(options.role || '');
|
|
222
|
+
const filePath = String(options.path || '');
|
|
223
|
+
const before = String(existing ?? '');
|
|
224
|
+
const after = String(incoming ?? '');
|
|
225
|
+
if (!after.trim()) return { content: before, unchanged: true };
|
|
226
|
+
if (!before.trim()) return { content: after, unchanged: false };
|
|
227
|
+
if (before.trim() === after.trim()) return { content: before, unchanged: true };
|
|
228
|
+
|
|
229
|
+
const lang = guessLang(after, filePath);
|
|
230
|
+
if (role === 'spec') return mergeSpec(before, after, lang);
|
|
231
|
+
if (role === 'page')
|
|
232
|
+
return lang === 'python' ? mergePyPage(before, after) : mergeTsPage(before, after);
|
|
233
|
+
if (role === 'fixture') return mergeFixture(before, after);
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 步骤计划(Plan):人看得懂的「做什么」,不含定位器。
|
|
3
|
+
*
|
|
4
|
+
* 为什么不直接让模型产 IR:
|
|
5
|
+
* - 定位器必须由探索时的 `locator_probe` 现场校验,凭空写出来的值会把错误带进脚本;
|
|
6
|
+
* - 计划可以给人改(增删 / 排序 / 改描述),IR 是机器产物,改起来门槛高。
|
|
7
|
+
*
|
|
8
|
+
* 计划绑定的定位器由 `/agent/probe` 回填,状态从 pending → bound。
|
|
9
|
+
*/
|
|
10
|
+
import { STEP_ACTIONS } from './ir.mjs';
|
|
11
|
+
|
|
12
|
+
/** 计划步允许的动作:截图是探索时给人看的工具动作,不是测试步骤 */
|
|
13
|
+
export const PLAN_ACTIONS = STEP_ACTIONS.filter((action) => action !== 'screenshot');
|
|
14
|
+
|
|
15
|
+
export const PLAN_STATUSES = ['pending', 'bound', 'done', 'failed'];
|
|
16
|
+
|
|
17
|
+
const MAX_PLAN_STEPS = 40;
|
|
18
|
+
const MAX_TARGET = 120;
|
|
19
|
+
const MAX_VALUE = 400;
|
|
20
|
+
|
|
21
|
+
/** 不需要目标的动作:整页级操作 */
|
|
22
|
+
const NO_TARGET_ACTIONS = new Set(['goto', 'wait', 'screenshot', 'press']);
|
|
23
|
+
|
|
24
|
+
const clean = (value) =>
|
|
25
|
+
String(value ?? '')
|
|
26
|
+
.replace(/\s+/g, ' ')
|
|
27
|
+
.trim();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 把模型 / 前端给的计划归一化。
|
|
31
|
+
* - 未知动作、缺目标(整页动作除外)直接丢掉
|
|
32
|
+
* - id 缺失时按顺序补;重复 id 换新
|
|
33
|
+
* - value 里的 `${ENV}` 原样保留,出码时才转成环境变量
|
|
34
|
+
*/
|
|
35
|
+
export function normalizePlan(raw) {
|
|
36
|
+
const list = Array.isArray(raw) ? raw : Array.isArray(raw?.steps) ? raw.steps : [];
|
|
37
|
+
const used = new Set();
|
|
38
|
+
const steps = [];
|
|
39
|
+
for (const item of list) {
|
|
40
|
+
if (!item || typeof item !== 'object') continue;
|
|
41
|
+
if (steps.length >= MAX_PLAN_STEPS) break;
|
|
42
|
+
const action = String(item.action ?? '').trim();
|
|
43
|
+
if (!PLAN_ACTIONS.includes(action)) continue;
|
|
44
|
+
const target = clean(item.target ?? item.label ?? item.note).slice(0, MAX_TARGET);
|
|
45
|
+
if (!target && !NO_TARGET_ACTIONS.has(action)) continue;
|
|
46
|
+
|
|
47
|
+
let id = clean(item.id)
|
|
48
|
+
.replace(/[^\w-]/g, '')
|
|
49
|
+
.slice(0, 40);
|
|
50
|
+
if (!id || used.has(id)) {
|
|
51
|
+
let seq = steps.length + 1;
|
|
52
|
+
while (used.has(`p${seq}`)) seq += 1;
|
|
53
|
+
id = `p${seq}`;
|
|
54
|
+
}
|
|
55
|
+
used.add(id);
|
|
56
|
+
|
|
57
|
+
const step = { id, action, target, status: 'pending' };
|
|
58
|
+
if (item.value != null && String(item.value) !== '') {
|
|
59
|
+
step.value = String(item.value).slice(0, MAX_VALUE);
|
|
60
|
+
}
|
|
61
|
+
const url = clean(item.url);
|
|
62
|
+
if (url) step.url = url.slice(0, 500);
|
|
63
|
+
const note = clean(item.note);
|
|
64
|
+
if (note && note !== target) step.note = note.slice(0, 200);
|
|
65
|
+
if (PLAN_STATUSES.includes(item.status)) step.status = item.status;
|
|
66
|
+
if (item.locator && typeof item.locator === 'object') step.locator = item.locator;
|
|
67
|
+
if (item.warning) step.warning = clean(item.warning).slice(0, 200);
|
|
68
|
+
steps.push(step);
|
|
69
|
+
}
|
|
70
|
+
return steps;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 模型提交的计划合并进用户现有计划。
|
|
75
|
+
*
|
|
76
|
+
* 探索时模型会再调一次 `ui_plan_steps`(可能少写几步、改措辞、或干脆传空),
|
|
77
|
+
* 早先直接覆盖整份计划:用户手改的动作 / 目标就这么没了,页面刷新后看起来
|
|
78
|
+
* 「计划不见了」。这里的原则是**用户已经写下的内容优先**:
|
|
79
|
+
* - 同 id:只吸收 status / locator / warning,动作和目标保持用户版
|
|
80
|
+
* - 新 id:追加
|
|
81
|
+
* - 模型传空:原样返回,绝不清空
|
|
82
|
+
*/
|
|
83
|
+
export function mergePlanWithModel(current, incoming) {
|
|
84
|
+
const base = normalizePlan(current);
|
|
85
|
+
const next = normalizePlan(incoming);
|
|
86
|
+
if (!next.length) return base;
|
|
87
|
+
const byId = new Map(next.map((step) => [step.id, step]));
|
|
88
|
+
const merged = base.map((step) => {
|
|
89
|
+
const patch = byId.get(step.id);
|
|
90
|
+
if (!patch) return step;
|
|
91
|
+
byId.delete(step.id);
|
|
92
|
+
const out = { ...step };
|
|
93
|
+
if (patch.locator) out.locator = patch.locator;
|
|
94
|
+
if (patch.warning) out.warning = patch.warning;
|
|
95
|
+
// 用户已经绑定过的步骤不要被模型打回 pending
|
|
96
|
+
if (patch.status && !(step.status === 'bound' && patch.status === 'pending')) {
|
|
97
|
+
out.status = patch.status;
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
});
|
|
101
|
+
for (const step of next) {
|
|
102
|
+
if (!byId.has(step.id)) continue;
|
|
103
|
+
merged.push(step);
|
|
104
|
+
if (merged.length >= MAX_PLAN_STEPS) break;
|
|
105
|
+
}
|
|
106
|
+
return merged;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 计划里真正需要在页面上操作 / 断言的步骤(探索时要逐个 probe) */ export function planNeedsLocator(
|
|
110
|
+
step,
|
|
111
|
+
) {
|
|
112
|
+
return ['click', 'fill', 'select', 'hover', 'expect'].includes(step?.action);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 计划 → 给模型看的清单(探索和规划共用一份措辞) */
|
|
116
|
+
export function describePlan(plan) {
|
|
117
|
+
if (!Array.isArray(plan) || !plan.length) return '';
|
|
118
|
+
return plan
|
|
119
|
+
.map((step, index) => {
|
|
120
|
+
const parts = [`${index + 1}. [${step.id}] ${step.action}`];
|
|
121
|
+
if (step.target) parts.push(`目标:${step.target}`);
|
|
122
|
+
if (step.url) parts.push(`url=${step.url}`);
|
|
123
|
+
if (step.value) parts.push(`值=${step.value}`);
|
|
124
|
+
if (step.status === 'bound' && step.locator) {
|
|
125
|
+
parts.push(`已绑定:${describeLocator(step.locator)}`);
|
|
126
|
+
}
|
|
127
|
+
return parts.join(' · ');
|
|
128
|
+
})
|
|
129
|
+
.join('\n');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 定位器的简短说明,给计划和活动日志用 */
|
|
133
|
+
export function describeLocator(locator) {
|
|
134
|
+
if (!locator || typeof locator !== 'object') return '';
|
|
135
|
+
const nth = Number.isInteger(locator.nth) ? ` nth=${locator.nth}` : '';
|
|
136
|
+
if (locator.kind === 'role') {
|
|
137
|
+
return `role=${locator.role}${locator.name ? ` name="${locator.name}"` : ''}${nth}`;
|
|
138
|
+
}
|
|
139
|
+
if (locator.kind === 'attr') return `[${locator.attr}="${locator.value}"]${nth}`;
|
|
140
|
+
if (locator.kind === 'testid') return `testid=${locator.value}${nth}`;
|
|
141
|
+
return `${locator.kind}="${locator.value ?? ''}"${nth}`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** 用探测结果回填某一步 */
|
|
145
|
+
export function bindPlanStep(plan, stepId, probe) {
|
|
146
|
+
if (!Array.isArray(plan) || !stepId) return plan;
|
|
147
|
+
return plan.map((step) => {
|
|
148
|
+
if (step.id !== stepId) return step;
|
|
149
|
+
const locator = probe?.recommended ?? null;
|
|
150
|
+
if (!locator) {
|
|
151
|
+
return {
|
|
152
|
+
...step,
|
|
153
|
+
status: 'failed',
|
|
154
|
+
warning: probe?.warning || '没有唯一候选,换一个更具体的元素',
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
...step,
|
|
159
|
+
status: 'bound',
|
|
160
|
+
locator,
|
|
161
|
+
warning:
|
|
162
|
+
probe?.confidence === 'high' ? '' : probe?.warning || '定位器不够稳,建议补 data-testid',
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
}
|