lantern-harness 0.2.2 → 0.2.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.
- package/CHANGELOG.md +27 -0
- package/README.md +7 -7
- package/builtin/case-backup-contract.mjs +27 -0
- package/builtin/case-workflow-contract.mjs +158 -0
- package/builtin/session/lh-nav-groups.mjs +33 -1
- package/builtin/session/space-layout.mjs +8 -1
- package/builtin/session/space-skills.mjs +8 -1
- package/cli/mcp-server.mjs +986 -32
- package/cli/server.mjs +2 -0
- package/dist/500.html +9 -4
- package/dist/_astro/Base.BQf1tZMl.css +1 -0
- package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.XUV2H6ea.js → Base.astro_astro_type_script_index_0_lang.Dm3O_y-S.js} +1 -1
- package/dist/_astro/{BusinessMapBoard.mRxl2G3D.js → BusinessMapBoard.CYxHcku_.js} +1 -1
- package/dist/_astro/{CaseExecBoard.Cqkxuf5c.js → CaseExecBoard.CK9aGPmH.js} +1 -1
- package/dist/_astro/CaseExecutionBoard.C94pmIMQ.js +5 -0
- package/dist/_astro/CaseGenerateApp.D5xlk9At.js +10 -0
- package/dist/_astro/CasesLibrary.BHQC955x.js +21 -0
- package/dist/_astro/ChatApp.CIt15w_1.js +1 -0
- package/dist/_astro/ChatApp.d4a9R3YS.js +262 -0
- package/dist/_astro/{DashboardBoard.CAJVE2G4.js → DashboardBoard.qgc1s7pG.js} +1 -1
- package/dist/_astro/{DefectSubmitEntry.BzKXJ-zq.js → DefectSubmitEntry.JI85N1-i.js} +1 -1
- package/dist/_astro/{DocsFileBrowser.apKMbGVf.js → DocsFileBrowser.z5JZ74cy.js} +1 -1
- package/dist/_astro/{DocsPager.DMN9-Tjg.js → DocsPager.Dg765uHW.js} +1 -1
- package/dist/_astro/{KnowledgeLibrary.BcoMQeUd.js → KnowledgeLibrary.mkShtVun.js} +1 -1
- package/dist/_astro/{LifeKrTasksBoard.DJU0-QI-.js → LifeKrTasksBoard.DpAwQffE.js} +1 -1
- package/dist/_astro/{LifeKrTodosBoard.GK7KRAO3.js → LifeKrTodosBoard.BIjPiZ8H.js} +1 -1
- package/dist/_astro/{LifeObjectivesBoard.DuKa6Q3k.js → LifeObjectivesBoard.DYwLHPEG.js} +1 -1
- package/dist/_astro/{LifePlanTypeSelect.Cm2lUmnH.js → LifePlanTypeSelect.CYaziESp.js} +1 -1
- package/dist/_astro/{LifeReviewsBoard.BWOOVMtz.js → LifeReviewsBoard.DIxoWBDA.js} +1 -1
- package/dist/_astro/{LifeShared.bY2l01Ha.js → LifeShared.DuFQsMEx.js} +1 -1
- package/dist/_astro/{LifeStagesBoard.CIzxPOJB.js → LifeStagesBoard.DtOri9EW.js} +1 -1
- package/dist/_astro/{LifeYearCycleSelect.BlsyPmmI.js → LifeYearCycleSelect.ByJ9-PGg.js} +1 -1
- package/dist/_astro/{LifeYearPlansBoard.DaA9O08j.js → LifeYearPlansBoard.BQN07wcv.js} +1 -1
- package/dist/_astro/NavLibraries.BO4ezcUc.js +1 -0
- package/dist/_astro/{PluginsPage.B063QIlQ.js → PluginsPage.B1VeDtLx.js} +2 -2
- package/dist/_astro/{PmBugsBoard.Cu-v0Gfd.js → PmBugsBoard.Ddl3kqqt.js} +1 -1
- package/dist/_astro/{PmIterationsBoard.CgRzkP-j.js → PmIterationsBoard.BJN7disI.js} +1 -1
- package/dist/_astro/{PmProjectDetail.DVCEh0Lm.js → PmProjectDetail.D78gWhqk.js} +1 -1
- package/dist/_astro/{PmProjectsBoard.z-bQa98r.js → PmProjectsBoard.Bf8VB3t6.js} +1 -1
- package/dist/_astro/PmRequirementsBoard.CDyNHN2a.js +1 -0
- package/dist/_astro/{PmRequirementsBoard.CyfBI0u_.js → PmRequirementsBoard.DarfGIrL.js} +1 -1
- package/dist/_astro/{PmShared.BQVzwsiz.js → PmShared.TOjBbtV8.js} +1 -1
- package/dist/_astro/{ReportsPage.najSzJeT.js → ReportsPage.BXGduuY3.js} +1 -1
- package/dist/_astro/{ReqAnalysisBoard.BQb8dHFD.js → ReqAnalysisBoard.WLtIfBg8.js} +1 -1
- package/dist/_astro/{RequirementBreakdownLibrary.Cn6OV6xt.js → RequirementBreakdownLibrary.DMoeTeqX.js} +1 -1
- package/dist/_astro/{RequirementsLibrary.CqKNFVsP.js → RequirementsLibrary.Iv7zOqWe.js} +1 -1
- package/dist/_astro/{SettingsDialog.db3BpFw0.js → SettingsDialog.BvDU9EU6.js} +1 -1
- package/dist/_astro/SlideOverDrawer.CvyB-quk.js +1 -0
- package/dist/_astro/{SpaceSwitcher.DSUVAPOi.js → SpaceSwitcher.D9bBNQBZ.js} +1 -1
- package/dist/_astro/{TableFieldConfig.72AL-8p-.js → TableFieldConfig.DHj25OKN.js} +1 -1
- package/dist/_astro/{TasksBoard.CCDhCSR7.js → TasksBoard.CXmGdylV.js} +1 -1
- package/dist/_astro/TemplatesLibrary.DsL2q-wp.js +1 -0
- package/dist/_astro/{TestReportsLibrary.fWiEyCRx.js → TestReportsLibrary.BBC1TYgP.js} +1 -1
- package/dist/_astro/{TestStatsBoard.BSUBsWSu.js → TestStatsBoard.VXjP4hu6.js} +1 -1
- package/dist/_astro/{TodosBoard.By5YdlUe.js → TodosBoard.-yKgp06M.js} +1 -1
- package/dist/_astro/UiAutoBoard.BD5ZyLHj.js +3 -0
- package/dist/_astro/UiAutoEnvPanel.DrHUOlmH.js +10 -0
- package/dist/_astro/UiAutoGenerationDialog.gypq1zP9.js +12 -0
- package/dist/_astro/UiAutoProjectsPage.Dhzr09E9.js +3 -0
- package/dist/_astro/app-config.BSO5r82v.js +1 -0
- package/dist/_astro/app-version.CkDFkv4s.js +1 -0
- package/dist/_astro/{bash-tools.CS2w8LOb.js → bash-tools.C4DJiRJs.js} +1 -1
- package/dist/_astro/case-fields.C03NY3zC.js +148 -0
- package/dist/_astro/case-gen-run.C4p8uyU3.js +26 -0
- package/dist/_astro/case-prompt.ByLTgz4r.js +2 -0
- package/dist/_astro/{case-review.DFWZkoR9.js → case-review.BodP2jKm.js} +1 -1
- package/dist/_astro/{case-template.Clb7HrDB.js → case-template.CC2eXegU.js} +2 -2
- package/dist/_astro/case-types.BjF1BivA.js +1 -0
- package/dist/_astro/case-workflow-contract.BBQ9bbKL.js +1 -0
- package/dist/_astro/{defect-workbench.CjTb4FDv.js → defect-workbench.DBmohR-y.js} +1 -1
- package/dist/_astro/{hydrate-cache.O4CIma9y.js → hydrate-cache.CMMErx63.js} +1 -1
- package/dist/_astro/{i18n.Cp4so7KR.js → i18n.CEWjL5GX.js} +2 -2
- package/dist/_astro/{open-docs-in-session.BpcAcBSI.js → open-docs-in-session.BoyV6R2A.js} +1 -1
- package/dist/_astro/plugins.ChGmBEkF.js +1 -0
- package/dist/_astro/{project-docs.bB9lQ1Ki.js → project-docs.BRgNjXhG.js} +1 -1
- package/dist/_astro/{req-analysis.C_gARMrB.js → req-analysis.BLvcktvQ.js} +1 -1
- package/dist/_astro/{settings.D02wZj3w.js → settings.BojKNwUC.js} +2 -2
- package/dist/_astro/{spaces-client.BAtG6PkW.js → spaces-client.B28rzu8J.js} +1 -1
- package/dist/_astro/{story-review.DTN91Vl9.js → story-review.dEBWTeOW.js} +1 -1
- package/dist/_astro/{test-points.C7ZgggQT.js → test-points.BuNgdNcU.js} +1 -1
- package/dist/_astro/ui-auto.LUcREUMe.js +1 -0
- package/dist/_astro/{view-prefs.COAKEQtZ.js → view-prefs.CWc5cQ2q.js} +1 -1
- package/dist/business-map/index.html +10 -5
- package/dist/case-exec/index.html +10 -5
- package/dist/case-execution/index.html +10 -5
- package/dist/cases/api/index.html +988 -0
- package/dist/cases/automation/index.html +988 -0
- package/dist/cases/functional/index.html +988 -0
- package/dist/cases/generate/index.html +10 -5
- package/dist/cases/index.html +1 -1
- package/dist/cases/library/index.html +1 -983
- package/dist/cases/other/index.html +988 -0
- package/dist/cases/performance/index.html +988 -0
- package/dist/dashboard/index.html +10 -5
- package/dist/defect-rules/index.html +10 -5
- package/dist/defect-submit/index.html +10 -5
- package/dist/defect-submit/templates/index.html +10 -5
- package/dist/docs/changelog/index.html +88 -58
- package/dist/docs/install/index.html +12 -6
- package/dist/docs/manual/index.html +42 -31
- package/dist/knowledge/index.html +10 -5
- package/dist/life/kr-tasks/index.html +10 -5
- package/dist/life/kr-todos/index.html +10 -5
- package/dist/life/objectives/index.html +10 -5
- package/dist/life/reviews/index.html +10 -5
- package/dist/life/stages/index.html +10 -5
- package/dist/life/year-plans/index.html +10 -5
- package/dist/plugins/index.html +10 -5
- package/dist/pm/bugs/index.html +10 -5
- package/dist/pm/iterations/index.html +10 -5
- package/dist/pm/projects/detail/index.html +10 -5
- package/dist/pm/projects/index.html +10 -5
- package/dist/pm/requirements/index.html +10 -5
- package/dist/reports/index.html +10 -5
- package/dist/requirement-analysis/index.html +10 -5
- package/dist/requirement-breakdowns/index.html +10 -5
- package/dist/requirements/index.html +10 -5
- package/dist/tasks/index.html +10 -5
- package/dist/templates/index.html +10 -5
- package/dist/test-automation/index.html +10 -5
- package/dist/test-automation/projects/index.html +10 -5
- package/dist/test-reports/index.html +10 -5
- package/dist/test-stats/index.html +10 -5
- package/dist/todos/index.html +10 -5
- package/dist/workbench/index.html +10 -5
- package/docs/Codex-MCP/351/233/206/346/210/220.md +97 -53
- package/docs//344/274/232/350/257/235/346/217/222/344/273/266.md +7 -1
- package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +1 -1
- package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +4 -2
- package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +43 -36
- package/lh-plugins/case-automation/service.mjs +921 -0
- package/lh-plugins/case-automation/store.mjs +231 -0
- package/lh-plugins/case-automation/tables.mjs +115 -0
- package/lh-plugins/case-automation-prompt.mjs +57 -0
- package/lh-plugins/case-execution/assets.mjs +180 -0
- package/lh-plugins/case-execution/files.mjs +67 -15
- package/lh-plugins/case-execution/plans.mjs +318 -0
- package/lh-plugins/case-execution/service.mjs +80 -13
- package/lh-plugins/case-execution-prompt.mjs +4 -1
- package/lh-plugins/lh-case-automation.mjs +169 -0
- package/lh-plugins/lh-case-design.mjs +456 -0
- package/lh-plugins/lh-case-execution.mjs +53 -1
- package/lh-plugins/lh-case-review.mjs +29 -11
- package/lh-plugins/lh-project-docs.mjs +24 -0
- package/lh-plugins/lh-uiauto.mjs +111 -2
- package/lh-plugins/plugin-prompts.mjs +1 -0
- package/lh-plugins/uiauto-adapters/playwright.mjs +44 -4
- package/lh-plugins/uiauto-adapters/shared.mjs +4 -0
- package/lh-plugins/uiauto-explorer/emit-files.mjs +16 -2
- package/lh-plugins/uiauto-explorer/ir.mjs +3 -0
- package/lh-plugins/uiauto-explorer/merge.mjs +37 -1
- package/lh-plugins/uiauto-explorer/navigation-guard.mjs +255 -0
- package/lh-plugins/uiauto-explorer/runner.mjs +65 -3
- package/lh-plugins/uiauto-explorer/sessions.mjs +29 -1
- package/package.json +1 -1
- package/skills/case-automation-bridge/SKILL.md +27 -0
- package/skills/case-execution/SKILL.md +11 -0
- package/skills/lantern-workflow/SKILL.md +39 -1
- package/dist/_astro/Base.Du_-4L-4.css +0 -1
- package/dist/_astro/CaseExecutionBoard.CjX4CoKd.js +0 -5
- package/dist/_astro/CaseGenerateApp.acgnxl79.js +0 -10
- package/dist/_astro/CasesLibrary.zmzOQwdn.js +0 -21
- package/dist/_astro/ChatApp.Ben9LFra.js +0 -1
- package/dist/_astro/ChatApp.DBi6q7Qv.js +0 -262
- package/dist/_astro/NavLibraries.DVR5Ua-S.js +0 -1
- package/dist/_astro/PmRequirementsBoard.B0W6bsW2.js +0 -1
- package/dist/_astro/SlideOverDrawer.BMg2tce6.js +0 -1
- package/dist/_astro/TemplatesLibrary.peYzrHZ2.js +0 -1
- package/dist/_astro/UiAutoBoard.BGdlp5Sr.js +0 -3
- package/dist/_astro/UiAutoEnvPanel.BUASgPLB.js +0 -10
- package/dist/_astro/UiAutoGenerationDialog.D1PyCgrD.js +0 -12
- package/dist/_astro/UiAutoProjectsPage.B6A9NlVK.js +0 -3
- package/dist/_astro/app-config.Dvfzl5_N.js +0 -1
- package/dist/_astro/app-version.CNpnKIb9.js +0 -1
- package/dist/_astro/case-fields.CmePqYfh.js +0 -148
- package/dist/_astro/case-gen-run.Cvvdv_kv.js +0 -26
- package/dist/_astro/case-prompt.CZ3vWUju.js +0 -2
- package/dist/_astro/plugins.Db9xoFZb.js +0 -1
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createExecutionPlan,
|
|
3
|
+
listExecutionPlans,
|
|
4
|
+
getExecutionPlan,
|
|
5
|
+
startExecutionPlan,
|
|
6
|
+
stopExecutionPlan,
|
|
7
|
+
verifyExecutionPlanItem,
|
|
8
|
+
} from './case-execution/plans.mjs';
|
|
1
9
|
import fs from 'node:fs';
|
|
2
10
|
import path from 'node:path';
|
|
3
11
|
|
|
@@ -22,10 +30,13 @@ import {
|
|
|
22
30
|
} from './case-execution/service.mjs';
|
|
23
31
|
import {
|
|
24
32
|
applyCaseFieldUpdates,
|
|
33
|
+
prepareExecutionColumns,
|
|
25
34
|
listCaseDocuments,
|
|
26
35
|
loadCaseDocument,
|
|
27
36
|
} from './case-execution/files.mjs';
|
|
28
37
|
import { ensurePluginPrompt, isPluginOnInSpace } from './plugin-prompts.mjs';
|
|
38
|
+
import { automationSummaryForCase } from './case-automation/store.mjs';
|
|
39
|
+
import { refreshAutomationLinks } from './case-automation/service.mjs';
|
|
29
40
|
|
|
30
41
|
const PREFIX = '/__tb_case_run';
|
|
31
42
|
|
|
@@ -187,6 +198,31 @@ export function lhCaseExecutionPlugin() {
|
|
|
187
198
|
});
|
|
188
199
|
}
|
|
189
200
|
|
|
201
|
+
if (method === 'GET' && tail === '/plans')
|
|
202
|
+
return sendJson(res, 200, {
|
|
203
|
+
ok: true,
|
|
204
|
+
plans: listExecutionPlans(root, parsed.searchParams.get('path') || ''),
|
|
205
|
+
});
|
|
206
|
+
if (method === 'POST' && tail === '/plans')
|
|
207
|
+
return sendJson(res, 200, {
|
|
208
|
+
ok: true,
|
|
209
|
+
plan: await createExecutionPlan(root, JSON.parse((await readBody(req)) || '{}')),
|
|
210
|
+
});
|
|
211
|
+
if (tail.startsWith('/plans/')) {
|
|
212
|
+
const id = tail.split('/')[2];
|
|
213
|
+
if (method === 'POST' && tail.endsWith('/result'))
|
|
214
|
+
return sendJson(
|
|
215
|
+
res,
|
|
216
|
+
200,
|
|
217
|
+
await verifyExecutionPlanItem(root, id, JSON.parse((await readBody(req)) || '{}')),
|
|
218
|
+
);
|
|
219
|
+
if (method === 'GET')
|
|
220
|
+
return sendJson(res, 200, { ok: true, plan: getExecutionPlan(root, id) });
|
|
221
|
+
if (method === 'POST' && tail.endsWith('/start'))
|
|
222
|
+
return sendJson(res, 200, { ok: true, plan: startExecutionPlan(root, id) });
|
|
223
|
+
if (method === 'POST' && tail.endsWith('/stop'))
|
|
224
|
+
return sendJson(res, 200, { ok: true, plan: stopExecutionPlan(root, id) });
|
|
225
|
+
}
|
|
190
226
|
if (method === 'GET' && tail === '/files') {
|
|
191
227
|
return sendJson(res, 200, {
|
|
192
228
|
ok: true,
|
|
@@ -198,8 +234,18 @@ export function lhCaseExecutionPlugin() {
|
|
|
198
234
|
root,
|
|
199
235
|
String(parsed.searchParams.get('path') || ''),
|
|
200
236
|
);
|
|
237
|
+
refreshAutomationLinks(root, document);
|
|
201
238
|
const { _parsed, _map, abs, ...publicDocument } = document;
|
|
202
|
-
return sendJson(res, 200, {
|
|
239
|
+
return sendJson(res, 200, {
|
|
240
|
+
ok: true,
|
|
241
|
+
document: {
|
|
242
|
+
...publicDocument,
|
|
243
|
+
cases: publicDocument.cases.map((item) => ({
|
|
244
|
+
...item,
|
|
245
|
+
automation: automationSummaryForCase(root, publicDocument.path, item.id),
|
|
246
|
+
})),
|
|
247
|
+
},
|
|
248
|
+
});
|
|
203
249
|
}
|
|
204
250
|
if (method === 'GET' && tail === '/runs') {
|
|
205
251
|
return sendJson(res, 200, {
|
|
@@ -270,6 +316,12 @@ export function lhCaseExecutionPlugin() {
|
|
|
270
316
|
applied: await applyManualResult(root, body),
|
|
271
317
|
});
|
|
272
318
|
}
|
|
319
|
+
if (method === 'POST' && tail === '/prepare-columns')
|
|
320
|
+
return sendJson(
|
|
321
|
+
res,
|
|
322
|
+
200,
|
|
323
|
+
await prepareExecutionColumns(root, JSON.parse((await readBody(req)) || '{}')),
|
|
324
|
+
);
|
|
273
325
|
if (method === 'POST' && tail === '/fields') {
|
|
274
326
|
const body = JSON.parse((await readBody(req)) || '{}');
|
|
275
327
|
return sendJson(res, 200, {
|
|
@@ -17,6 +17,11 @@ import path from 'node:path';
|
|
|
17
17
|
|
|
18
18
|
import { getDataRoot } from '../builtin/session/space-context.mjs';
|
|
19
19
|
import { resolveContentRoot, spaceLocalFile } from '../builtin/session/space-layout.mjs';
|
|
20
|
+
import {
|
|
21
|
+
CASE_BACKUP_DIR_NAME,
|
|
22
|
+
backupDirectoryForCasePath,
|
|
23
|
+
isCaseBackupPath,
|
|
24
|
+
} from '../builtin/case-backup-contract.mjs';
|
|
20
25
|
import { ensurePluginPrompt, isPluginOnInSpace, readPluginPrompt } from './plugin-prompts.mjs';
|
|
21
26
|
import {
|
|
22
27
|
BLINDSPOT_PROMPT_FILE,
|
|
@@ -37,9 +42,6 @@ export const CASE_REVIEW_STORE_FILE = '用例评审.json';
|
|
|
37
42
|
|
|
38
43
|
/** 用例文件根目录(与 lh-project-docs 的 DOC_ROOT_DIRS.cases.dirName 一致) */
|
|
39
44
|
const CASES_DIR_NAME = '用例管理';
|
|
40
|
-
/** 用例管理下的备份文件夹(与前端 CASE_BACKUP_DIR_NAME 一致;首次备份才创建) */
|
|
41
|
-
const CASE_BACKUP_DIR_NAME = '备份列表';
|
|
42
|
-
|
|
43
45
|
const VERDICTS = ['usable', 'revise', 'invalid'];
|
|
44
46
|
const DIMENSION_KEYS = ['coverage', 'steps', 'expected', 'data', 'convention'];
|
|
45
47
|
const BLINDSPOT_CATEGORIES = ['nonfunctional', 'security', 'compatibility', 'business'];
|
|
@@ -284,9 +286,9 @@ function legacyReviewBackupDir(root) {
|
|
|
284
286
|
return spaceLocalFile(root, 'case-review/backup');
|
|
285
287
|
}
|
|
286
288
|
|
|
287
|
-
/**
|
|
288
|
-
function casesBackupDirAbs(root) {
|
|
289
|
-
return path.join(resolveContentRoot(root, CASES_DIR_NAME).abs,
|
|
289
|
+
/** 按用例所属类型返回备份目录;根目录历史文件仍写根备份列表。 */
|
|
290
|
+
function casesBackupDirAbs(root, backupRelDir = CASE_BACKUP_DIR_NAME) {
|
|
291
|
+
return path.join(resolveContentRoot(root, CASES_DIR_NAME).abs, ...backupRelDir.split('/'));
|
|
290
292
|
}
|
|
291
293
|
|
|
292
294
|
/** 备份文件名:默认用原名(用例名里通常已有时间戳),重名则 stem(2).ext */
|
|
@@ -305,7 +307,9 @@ function resolveBackupDest(dir, preferredName) {
|
|
|
305
307
|
}
|
|
306
308
|
|
|
307
309
|
function backupCaseFile(root, abs, preferredName) {
|
|
308
|
-
const
|
|
310
|
+
const casesRoot = resolveContentRoot(root, CASES_DIR_NAME).abs;
|
|
311
|
+
const sourceRel = path.relative(casesRoot, abs).split(path.sep).join('/');
|
|
312
|
+
const dir = casesBackupDirAbs(root, backupDirectoryForCasePath(sourceRel));
|
|
309
313
|
fs.mkdirSync(dir, { recursive: true });
|
|
310
314
|
const dest = resolveBackupDest(dir, preferredName || path.basename(abs));
|
|
311
315
|
fs.copyFileSync(abs, dest);
|
|
@@ -315,8 +319,16 @@ function backupCaseFile(root, abs, preferredName) {
|
|
|
315
319
|
/** 列出备份:用例管理/备份列表 + 历史 .lantern/case-review/backup */
|
|
316
320
|
function listReviewBackups(root) {
|
|
317
321
|
const items = [];
|
|
318
|
-
const
|
|
319
|
-
|
|
322
|
+
const casesRoot = resolveContentRoot(root, CASES_DIR_NAME).abs;
|
|
323
|
+
const typeDirs = fs.existsSync(casesRoot)
|
|
324
|
+
? fs
|
|
325
|
+
.readdirSync(casesRoot, { withFileTypes: true })
|
|
326
|
+
.filter((entry) => entry.isDirectory() && entry.name !== CASE_BACKUP_DIR_NAME)
|
|
327
|
+
.map((entry) => path.join(casesRoot, entry.name, CASE_BACKUP_DIR_NAME))
|
|
328
|
+
.filter((dir) => fs.existsSync(dir))
|
|
329
|
+
: [];
|
|
330
|
+
const folderDirs = [casesBackupDirAbs(root), ...typeDirs].filter((dir) => fs.existsSync(dir));
|
|
331
|
+
for (const folderDir of folderDirs) {
|
|
320
332
|
for (const name of fs.readdirSync(folderDir)) {
|
|
321
333
|
if (!name || name.startsWith('.') || name.includes('/') || name.includes('..')) continue;
|
|
322
334
|
const abs = path.join(folderDir, name);
|
|
@@ -327,7 +339,7 @@ function listReviewBackups(root) {
|
|
|
327
339
|
continue;
|
|
328
340
|
}
|
|
329
341
|
if (!st.isFile()) continue;
|
|
330
|
-
const casesPath =
|
|
342
|
+
const casesPath = path.relative(casesRoot, abs).split(path.sep).join('/');
|
|
331
343
|
items.push({
|
|
332
344
|
name,
|
|
333
345
|
path: casesPath,
|
|
@@ -685,6 +697,12 @@ async function reviewRoutes(req, res, root, tail, query) {
|
|
|
685
697
|
const rel = text(body.path, 400);
|
|
686
698
|
if (!rel) return sendJson(res, 400, { ok: false, error: '缺少用例文件路径' });
|
|
687
699
|
const abs = caseFileAbs(root, rel);
|
|
700
|
+
if (
|
|
701
|
+
body.expectedHash &&
|
|
702
|
+
body.expectedHash !== hashOfFile(abs) &&
|
|
703
|
+
body.expectedHash !== crypto.createHash('sha256').update(fs.readFileSync(abs)).digest('hex')
|
|
704
|
+
)
|
|
705
|
+
return sendJson(res, 409, { ok: false, error: '用例文件已变化,请重新审查' });
|
|
688
706
|
const store = readStore(root);
|
|
689
707
|
const idx = store.files.findIndex((x) => x.path === rel);
|
|
690
708
|
const base =
|
|
@@ -727,7 +745,7 @@ async function reviewRoutes(req, res, root, tail, query) {
|
|
|
727
745
|
}
|
|
728
746
|
// 禁止把「备份列表」里的文件再备份进自己
|
|
729
747
|
const norm = rel.replace(/\\/g, '/');
|
|
730
|
-
if (norm
|
|
748
|
+
if (isCaseBackupPath(norm)) {
|
|
731
749
|
return sendJson(res, 400, { ok: false, error: '不能备份「备份列表」内的文件' });
|
|
732
750
|
}
|
|
733
751
|
const preferred = text(body.name, 200) || path.basename(abs);
|
|
@@ -647,6 +647,30 @@ function createDocsPlugin(opts) {
|
|
|
647
647
|
return sendJson(res, 200, { ok: true, path: newDisplay, from: display });
|
|
648
648
|
}
|
|
649
649
|
|
|
650
|
+
if (url === `${prefix}/move` && req.method === 'POST') {
|
|
651
|
+
const body = JSON.parse((await readBody(req)).toString('utf8') || '{}');
|
|
652
|
+
const opRoot = overlayRoot(body.path) || absRoot;
|
|
653
|
+
const source = resolveUnderRoot(opRoot, body.path);
|
|
654
|
+
if (source.display === '.') return sendJson(res, 400, { error: '不能移动根目录' });
|
|
655
|
+
if (!fs.existsSync(source.abs))
|
|
656
|
+
return sendJson(res, 404, { error: 'not found', path: source.display });
|
|
657
|
+
const parent = String(body.parent || '.').trim() || '.';
|
|
658
|
+
const targetParent = resolveUnderRoot(opRoot, parent);
|
|
659
|
+
if (!fs.existsSync(targetParent.abs) || !fs.statSync(targetParent.abs).isDirectory())
|
|
660
|
+
return sendJson(res, 400, { error: '目标目录不存在', path: parent });
|
|
661
|
+
const targetAbs = path.join(targetParent.abs, path.basename(source.abs));
|
|
662
|
+
if (targetAbs !== source.abs && fs.existsSync(targetAbs))
|
|
663
|
+
return sendJson(res, 409, { error: '目标目录已有同名文件', path: parent });
|
|
664
|
+
fs.renameSync(source.abs, targetAbs);
|
|
665
|
+
const targetDisplay =
|
|
666
|
+
parent === '.' ? path.basename(targetAbs) : `${parent}/${path.basename(targetAbs)}`;
|
|
667
|
+
return sendJson(res, 200, {
|
|
668
|
+
ok: true,
|
|
669
|
+
path: targetDisplay,
|
|
670
|
+
from: source.display,
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
|
|
650
674
|
if (url === `${prefix}/open` && req.method === 'POST') {
|
|
651
675
|
const body = JSON.parse((await readBody(req)).toString('utf8') || '{}');
|
|
652
676
|
const opRoot = overlayRoot(body.path) || absRoot;
|
package/lh-plugins/lh-uiauto.mjs
CHANGED
|
@@ -67,6 +67,7 @@ import {
|
|
|
67
67
|
taskView,
|
|
68
68
|
} from './uiauto-adapters/tasks.mjs';
|
|
69
69
|
import { hasFilesInside, hasReportEntry, snapshotReport } from './uiauto-report.mjs';
|
|
70
|
+
import { readAutomationLinks, upsertAutomationLinks } from './case-automation/store.mjs';
|
|
70
71
|
import { nodeInstallPlan, nodeStatus, withProjectNode, writeNvmrc } from './uiauto-node.mjs';
|
|
71
72
|
import { resolvePackageManager } from './uiauto-pm.mjs';
|
|
72
73
|
import {
|
|
@@ -1395,6 +1396,40 @@ function normalizeRun(raw) {
|
|
|
1395
1396
|
.filter(Boolean)
|
|
1396
1397
|
.slice(0, 50)
|
|
1397
1398
|
: [],
|
|
1399
|
+
tests: Array.isArray(raw.tests)
|
|
1400
|
+
? raw.tests
|
|
1401
|
+
.filter((item) => item && typeof item === 'object')
|
|
1402
|
+
.slice(0, 5000)
|
|
1403
|
+
.map((item) => ({
|
|
1404
|
+
title: text(item.title, 1000),
|
|
1405
|
+
file: text(item.file, 1024),
|
|
1406
|
+
line: intOr(item.line, 0, 0, Number.MAX_SAFE_INTEGER),
|
|
1407
|
+
tags: Array.isArray(item.tags)
|
|
1408
|
+
? item.tags
|
|
1409
|
+
.map((tag) => text(tag, 100))
|
|
1410
|
+
.filter(Boolean)
|
|
1411
|
+
.slice(0, 20)
|
|
1412
|
+
: [],
|
|
1413
|
+
annotations: Array.isArray(item.annotations)
|
|
1414
|
+
? item.annotations
|
|
1415
|
+
.map((annotation) => ({
|
|
1416
|
+
type: text(annotation?.type, 200),
|
|
1417
|
+
description: text(annotation?.description, 2000),
|
|
1418
|
+
}))
|
|
1419
|
+
.filter((annotation) => annotation.type)
|
|
1420
|
+
.slice(0, 20)
|
|
1421
|
+
: [],
|
|
1422
|
+
automationCaseId: text(item.automationCaseId, 200),
|
|
1423
|
+
status: text(item.status, 40),
|
|
1424
|
+
durationMs: intOr(item.durationMs, 0, 0, Number.MAX_SAFE_INTEGER),
|
|
1425
|
+
errors: Array.isArray(item.errors)
|
|
1426
|
+
? item.errors
|
|
1427
|
+
.map((error) => text(error, 2000))
|
|
1428
|
+
.filter(Boolean)
|
|
1429
|
+
.slice(0, 20)
|
|
1430
|
+
: [],
|
|
1431
|
+
}))
|
|
1432
|
+
: [],
|
|
1398
1433
|
reportRel: text(raw.reportRel, 1024),
|
|
1399
1434
|
// Allure 静态报告快照目录 + 「有原始结果、可以 generate」标记
|
|
1400
1435
|
allureRel: text(raw.allureRel, 1024),
|
|
@@ -1993,6 +2028,7 @@ function finishRun(root, entry, runId, exitCode, spawnError) {
|
|
|
1993
2028
|
run.failed = summary.failed;
|
|
1994
2029
|
run.skipped = summary.skipped;
|
|
1995
2030
|
run.flaky = summary.flaky;
|
|
2031
|
+
run.tests = summary.tests;
|
|
1996
2032
|
if (summary.projectNames.length) run.projectNames = summary.projectNames;
|
|
1997
2033
|
run.reportRel = reportRel;
|
|
1998
2034
|
run.allureRel = allureRel;
|
|
@@ -2189,6 +2225,7 @@ function startRun(root, body) {
|
|
|
2189
2225
|
taskId,
|
|
2190
2226
|
taskLabel: task ? taskCommandLine(task) : '',
|
|
2191
2227
|
projectNames: [],
|
|
2228
|
+
tests: [],
|
|
2192
2229
|
reportRel: '',
|
|
2193
2230
|
resultRel,
|
|
2194
2231
|
logRel,
|
|
@@ -4462,6 +4499,35 @@ export function lhUiautoPlugin() {
|
|
|
4462
4499
|
return findProject(store, projectId);
|
|
4463
4500
|
};
|
|
4464
4501
|
|
|
4502
|
+
const applyPinnedIterationTarget = (project, record, files) => {
|
|
4503
|
+
const iterationFile = text(record?.iterationFile, 500).replace(/\\/g, '/');
|
|
4504
|
+
if (!iterationFile) return files;
|
|
4505
|
+
const layout = detectEmitLayout(project.dir);
|
|
4506
|
+
const fixture = `${layout.fixturesDir}/test.ts`.replace(/\\/g, '/');
|
|
4507
|
+
const fixtureAbs = path.join(project.dir, fixture);
|
|
4508
|
+
const testImport = fs.existsSync(fixtureAbs)
|
|
4509
|
+
? path.posix
|
|
4510
|
+
.relative(path.posix.dirname(iterationFile), fixture.replace(/\.ts$/, ''))
|
|
4511
|
+
.replace(/^([^.])/, './$1')
|
|
4512
|
+
: '@playwright/test';
|
|
4513
|
+
return files.map((file) =>
|
|
4514
|
+
file.role === 'spec'
|
|
4515
|
+
? {
|
|
4516
|
+
...file,
|
|
4517
|
+
path: iterationFile,
|
|
4518
|
+
testImport,
|
|
4519
|
+
content:
|
|
4520
|
+
testImport === '@playwright/test'
|
|
4521
|
+
? file.content
|
|
4522
|
+
: file.content.replace(
|
|
4523
|
+
"import { test, expect } from '@playwright/test';",
|
|
4524
|
+
`import { test, expect } from '${testImport}';`,
|
|
4525
|
+
),
|
|
4526
|
+
}
|
|
4527
|
+
: file,
|
|
4528
|
+
);
|
|
4529
|
+
};
|
|
4530
|
+
|
|
4465
4531
|
const requireExplorer = async (sessionId) => {
|
|
4466
4532
|
const record = readGeneratedSession(agentBaseDir, sessionId);
|
|
4467
4533
|
if (!record) throw new Error('生成会话不存在');
|
|
@@ -4877,13 +4943,22 @@ export function lhUiautoPlugin() {
|
|
|
4877
4943
|
pagesDir: '',
|
|
4878
4944
|
fixturesDir: '',
|
|
4879
4945
|
};
|
|
4880
|
-
const
|
|
4946
|
+
const record = text(body.sessionId, 64)
|
|
4947
|
+
? readGeneratedSession(agentBaseDir, text(body.sessionId, 64))
|
|
4948
|
+
: null;
|
|
4949
|
+
let multi = emitFiles(body.ir || {}, body.target, {
|
|
4881
4950
|
testDir: layout.testDir,
|
|
4882
4951
|
pagesDir: layout.pagesDir || undefined,
|
|
4883
4952
|
fixturesDir: layout.fixturesDir || undefined,
|
|
4884
4953
|
tag: text(body.tag, 40),
|
|
4885
4954
|
hasBaseURL: Boolean(body.hasBaseURL),
|
|
4886
4955
|
});
|
|
4956
|
+
if (project && record) {
|
|
4957
|
+
multi = {
|
|
4958
|
+
...multi,
|
|
4959
|
+
files: applyPinnedIterationTarget(project, record, multi.files),
|
|
4960
|
+
};
|
|
4961
|
+
}
|
|
4887
4962
|
return sendJson(res, 200, {
|
|
4888
4963
|
ok: true,
|
|
4889
4964
|
code: emitted.code,
|
|
@@ -4891,6 +4966,16 @@ export function lhUiautoPlugin() {
|
|
|
4891
4966
|
language: emitted.language,
|
|
4892
4967
|
files: multi.files,
|
|
4893
4968
|
configPatch: multi.configPatch,
|
|
4969
|
+
suggestedPath: project
|
|
4970
|
+
? suggestedPath({
|
|
4971
|
+
project,
|
|
4972
|
+
session: record || {
|
|
4973
|
+
target: body.target,
|
|
4974
|
+
title: body.title,
|
|
4975
|
+
ir: body.ir || {},
|
|
4976
|
+
},
|
|
4977
|
+
})
|
|
4978
|
+
: '',
|
|
4894
4979
|
});
|
|
4895
4980
|
}
|
|
4896
4981
|
|
|
@@ -4961,7 +5046,9 @@ export function lhUiautoPlugin() {
|
|
|
4961
5046
|
...detectEmitLayout(project.dir),
|
|
4962
5047
|
hasBaseURL: projectHasBaseURL(project.dir),
|
|
4963
5048
|
});
|
|
4964
|
-
files = emitted.files;
|
|
5049
|
+
files = applyPinnedIterationTarget(project, record, emitted.files);
|
|
5050
|
+
} else if (record.iterationFile) {
|
|
5051
|
+
files = applyPinnedIterationTarget(project, record, files);
|
|
4965
5052
|
}
|
|
4966
5053
|
|
|
4967
5054
|
const result = writeGeneratedFiles({
|
|
@@ -4989,6 +5076,20 @@ export function lhUiautoPlugin() {
|
|
|
4989
5076
|
savedPaths: mergedSaved,
|
|
4990
5077
|
changes: result.changes,
|
|
4991
5078
|
});
|
|
5079
|
+
if (record.automationCaseId) {
|
|
5080
|
+
const link = readAutomationLinks(root).items.find(
|
|
5081
|
+
(item) => item.automationCaseId === record.automationCaseId,
|
|
5082
|
+
);
|
|
5083
|
+
if (link) {
|
|
5084
|
+
upsertAutomationLinks(root, [
|
|
5085
|
+
{
|
|
5086
|
+
...link,
|
|
5087
|
+
scriptPath: spec || link.iterationFile || '',
|
|
5088
|
+
status: link.status === 'stale' ? 'stale' : 'connected',
|
|
5089
|
+
},
|
|
5090
|
+
]);
|
|
5091
|
+
}
|
|
5092
|
+
}
|
|
4992
5093
|
}
|
|
4993
5094
|
return sendJson(res, result.ok ? 200 : 409, {
|
|
4994
5095
|
...result,
|
|
@@ -5237,3 +5338,11 @@ export function lhUiautoPlugin() {
|
|
|
5237
5338
|
},
|
|
5238
5339
|
};
|
|
5239
5340
|
}
|
|
5341
|
+
|
|
5342
|
+
// In-process bridge: preserve the originating space while an execution plan runs.
|
|
5343
|
+
export { startRun as startAutomationProjectRun, stopRun as stopAutomationProjectRun };
|
|
5344
|
+
export function readAutomationProjectRun(root, id) {
|
|
5345
|
+
const run = findRun(readStore(root).store, id);
|
|
5346
|
+
if (!run) throw new Error('自动化执行记录不存在');
|
|
5347
|
+
return runView(run);
|
|
5348
|
+
}
|
|
@@ -70,6 +70,7 @@ export const PLUGIN_PROMPT_FILES = Object.freeze({
|
|
|
70
70
|
'用例质量评审提示词.md': 'caseReview',
|
|
71
71
|
'场景遗漏补全提示词.md': 'caseBlindspot',
|
|
72
72
|
'用例执行提示词.md': 'caseExecution',
|
|
73
|
+
'功能用例转UI自动化提示词.md': 'uiAuto',
|
|
73
74
|
'功能测试报告提示词.md': 'testReports',
|
|
74
75
|
'接口测试报告提示词.md': 'testReports',
|
|
75
76
|
'性能测试报告提示词.md': 'testReports',
|
|
@@ -118,23 +118,62 @@ export function parsePlaywrightReport(raw) {
|
|
|
118
118
|
.slice(0, 20)
|
|
119
119
|
: [];
|
|
120
120
|
const failedTests = [];
|
|
121
|
+
const tests = [];
|
|
121
122
|
const walk = (suite, trail) => {
|
|
122
123
|
if (!suite || typeof suite !== 'object') return;
|
|
123
124
|
const file = text(suite.file, 1024);
|
|
124
125
|
const own = text(suite.title, 500);
|
|
125
126
|
const nextTrail = own ? [...trail, own] : trail;
|
|
126
127
|
for (const spec of Array.isArray(suite.specs) ? suite.specs : []) {
|
|
127
|
-
const
|
|
128
|
-
const
|
|
128
|
+
const specTests = Array.isArray(spec?.tests) ? spec.tests : [];
|
|
129
|
+
const title = [...nextTrail, text(spec?.title, 500)].filter(Boolean).join(' › ');
|
|
130
|
+
const specAnnotations = Array.isArray(spec?.annotations) ? spec.annotations : [];
|
|
131
|
+
const tags = Array.isArray(spec?.tags) ? spec.tags.map((tag) => text(tag, 100)) : [];
|
|
132
|
+
for (const test of specTests.length ? specTests : [{}]) {
|
|
133
|
+
const annotations = [
|
|
134
|
+
...specAnnotations,
|
|
135
|
+
...(Array.isArray(test?.annotations) ? test.annotations : []),
|
|
136
|
+
]
|
|
137
|
+
.map((item) => ({
|
|
138
|
+
type: text(item?.type, 200),
|
|
139
|
+
description: text(item?.description, 2000),
|
|
140
|
+
}))
|
|
141
|
+
.filter((item) => item.type);
|
|
142
|
+
const results = Array.isArray(test?.results) ? test.results : [];
|
|
143
|
+
const status = text(test?.status, 40) || (results[0] ? text(results[0].status, 40) : '');
|
|
144
|
+
const errors = results
|
|
145
|
+
.flatMap((result) => (Array.isArray(result?.errors) ? result.errors : []))
|
|
146
|
+
.map((item) => text(item?.message || item?.stack, 2000))
|
|
147
|
+
.filter(Boolean)
|
|
148
|
+
.slice(0, 20);
|
|
149
|
+
const durationMs = results.reduce(
|
|
150
|
+
(sum, result) => sum + intOr(result?.duration, 0, 0, Number.MAX_SAFE_INTEGER),
|
|
151
|
+
0,
|
|
152
|
+
);
|
|
153
|
+
const automation = annotations.find((item) => item.type === 'com.lantern.automationCaseId');
|
|
154
|
+
tests.push({
|
|
155
|
+
title,
|
|
156
|
+
file,
|
|
157
|
+
line: intOr(spec?.line, 0, 0, Number.MAX_SAFE_INTEGER),
|
|
158
|
+
tags,
|
|
159
|
+
annotations,
|
|
160
|
+
automationCaseId: automation?.description || '',
|
|
161
|
+
status,
|
|
162
|
+
durationMs,
|
|
163
|
+
errors,
|
|
164
|
+
});
|
|
165
|
+
if (tests.length >= 5000) break;
|
|
166
|
+
}
|
|
167
|
+
const unmatched = specTests.some(
|
|
129
168
|
(t) =>
|
|
130
169
|
t?.status === 'unexpected' ||
|
|
131
170
|
t?.status === 'timedOut' ||
|
|
132
171
|
(Array.isArray(t?.results) &&
|
|
133
172
|
t.results.some((r) => r?.status === 'unexpected' || r?.status === 'timedOut')),
|
|
134
173
|
);
|
|
135
|
-
if (!
|
|
174
|
+
if (!unmatched) continue;
|
|
136
175
|
failedTests.push({
|
|
137
|
-
title
|
|
176
|
+
title,
|
|
138
177
|
file,
|
|
139
178
|
});
|
|
140
179
|
if (failedTests.length >= 50) return;
|
|
@@ -151,6 +190,7 @@ export function parsePlaywrightReport(raw) {
|
|
|
151
190
|
durationMs: intOr(stats.duration, 0, 0, Number.MAX_SAFE_INTEGER),
|
|
152
191
|
errors,
|
|
153
192
|
failedTests,
|
|
193
|
+
tests,
|
|
154
194
|
projectNames,
|
|
155
195
|
};
|
|
156
196
|
}
|
|
@@ -261,6 +261,7 @@ export function emptySummary() {
|
|
|
261
261
|
durationMs: 0,
|
|
262
262
|
errors: [],
|
|
263
263
|
failedTests: [],
|
|
264
|
+
tests: [],
|
|
264
265
|
projectNames: [],
|
|
265
266
|
};
|
|
266
267
|
}
|
|
@@ -329,6 +330,9 @@ export function mergeSummaries(list) {
|
|
|
329
330
|
for (const failed of item.failedTests ?? []) {
|
|
330
331
|
if (out.failedTests.length < 50) out.failedTests.push(failed);
|
|
331
332
|
}
|
|
333
|
+
for (const test of item.tests ?? []) {
|
|
334
|
+
if (out.tests.length < 5000) out.tests.push(test);
|
|
335
|
+
}
|
|
332
336
|
for (const name of item.projectNames ?? []) {
|
|
333
337
|
if (!out.projectNames.includes(name)) out.projectNames.push(name);
|
|
334
338
|
}
|
|
@@ -202,6 +202,8 @@ export function renderTsPage(page) {
|
|
|
202
202
|
/** TS spec:导航留在用例里,元素操作调 page object */
|
|
203
203
|
export function renderTsSpec(ir, pages, options = {}) {
|
|
204
204
|
const title = ir.title || 'AI 生成用例';
|
|
205
|
+
const automationCaseId = String(ir.automationCaseId || '').replace(/[^A-Za-z0-9_-]/g, '');
|
|
206
|
+
const automationTag = automationCaseId ? `@lantern-${automationCaseId.toLowerCase()}` : '';
|
|
205
207
|
const lines = [];
|
|
206
208
|
lines.push('/**');
|
|
207
209
|
lines.push(` * ${title}`);
|
|
@@ -211,7 +213,7 @@ export function renderTsSpec(ir, pages, options = {}) {
|
|
|
211
213
|
}
|
|
212
214
|
}
|
|
213
215
|
lines.push(' */');
|
|
214
|
-
lines.push(
|
|
216
|
+
lines.push(`import { test, expect } from '${options.testImport || '@playwright/test'}';`);
|
|
215
217
|
// 页面对象可能在根级 pages/(企业级骨架)或 tests/pages/(老布局),import 按实际相对位置算
|
|
216
218
|
const pagesImport = options.pagesImport || './pages';
|
|
217
219
|
for (const page of pages) {
|
|
@@ -232,10 +234,20 @@ export function renderTsSpec(ir, pages, options = {}) {
|
|
|
232
234
|
lines.push('');
|
|
233
235
|
}
|
|
234
236
|
|
|
237
|
+
if (automationCaseId) lines.push(`/* lantern-automation:start ${automationCaseId} */`);
|
|
235
238
|
lines.push(`test.describe(${q(title)}, () => {`);
|
|
239
|
+
const tags = [
|
|
240
|
+
normalizeTag(ir.tag) || normalizeTag(options.tag) || DEFAULT_TEST_TAG,
|
|
241
|
+
...(automationTag ? [automationTag] : []),
|
|
242
|
+
];
|
|
236
243
|
lines.push(
|
|
237
|
-
` test(${q(title)}, { tag: [${
|
|
244
|
+
` test(${q(title)}, { tag: [${tags.map((tag) => q(tag)).join(', ')}] }, async ({ page }, testInfo) => {`,
|
|
238
245
|
);
|
|
246
|
+
if (automationCaseId) {
|
|
247
|
+
lines.push(
|
|
248
|
+
` testInfo.annotations.push({ type: 'com.lantern.automationCaseId', description: ${q(automationCaseId)} });`,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
239
251
|
if (ir.baseURL) lines.push(` // baseURL: ${ir.baseURL}`);
|
|
240
252
|
for (const page of pages) {
|
|
241
253
|
lines.push(` const ${varName(page.name)} = new ${page.name}(page);`);
|
|
@@ -281,6 +293,7 @@ export function renderTsSpec(ir, pages, options = {}) {
|
|
|
281
293
|
}
|
|
282
294
|
lines.push(' });');
|
|
283
295
|
lines.push('});');
|
|
296
|
+
if (automationCaseId) lines.push(`/* lantern-automation:end ${automationCaseId} */`);
|
|
284
297
|
lines.push('');
|
|
285
298
|
return lines.join('\n');
|
|
286
299
|
}
|
|
@@ -488,6 +501,7 @@ export function emitFiles(rawIr, target, options = {}) {
|
|
|
488
501
|
fixtureImport,
|
|
489
502
|
pagesImport: relativeImport(testDir, pagesDir),
|
|
490
503
|
tag: options.tag,
|
|
504
|
+
testImport: options.testImport,
|
|
491
505
|
}),
|
|
492
506
|
language: 'ts',
|
|
493
507
|
role: 'spec',
|
|
@@ -71,6 +71,9 @@ export function normalizeIr(raw, fallback = {}) {
|
|
|
71
71
|
target: (source.target ?? fallback.target) === 'python' ? 'python' : 'ts',
|
|
72
72
|
baseURL: String(source.baseURL ?? fallback.baseURL ?? ''),
|
|
73
73
|
storageState: String(source.storageState ?? fallback.storageState ?? ''),
|
|
74
|
+
automationCaseId: String(source.automationCaseId ?? fallback.automationCaseId ?? '')
|
|
75
|
+
.replace(/[^A-Za-z0-9_-]/g, '')
|
|
76
|
+
.slice(0, 80),
|
|
74
77
|
// 分级标签:为空表示用缺省级别(出码时补 @regression)
|
|
75
78
|
tag: normalizeTag(source.tag ?? fallback.tag),
|
|
76
79
|
source: String(source.source ?? fallback.source ?? '').slice(0, 2000),
|
|
@@ -114,6 +114,42 @@ export function mergeSpec(existing, incoming, lang) {
|
|
|
114
114
|
return { content, unchanged: false };
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* 合并带 automationCaseId 边界的 TS 测试块。
|
|
119
|
+
* 同一自动化用例重新生成时只替换自己的块,保留 iteration 文件里的其它测试。
|
|
120
|
+
*/
|
|
121
|
+
export function mergeAutomationSpecBlock(existing, incoming, lang = 'ts') {
|
|
122
|
+
if (lang !== 'ts') return mergeSpec(existing, incoming, lang);
|
|
123
|
+
const id = /\/\* lantern-automation:start ([A-Za-z0-9_-]+) \*\//.exec(incoming)?.[1] || '';
|
|
124
|
+
if (!id) return mergeSpec(existing, incoming, lang);
|
|
125
|
+
const start = `/* lantern-automation:start ${id} */`;
|
|
126
|
+
const end = `/* lantern-automation:end ${id} */`;
|
|
127
|
+
const incStart = incoming.indexOf(start);
|
|
128
|
+
const incEnd = incoming.indexOf(end, incStart);
|
|
129
|
+
if (incStart < 0 || incEnd < 0) return null;
|
|
130
|
+
const incomingBlock = incoming.slice(incStart, incEnd + end.length);
|
|
131
|
+
const oldStart = existing.indexOf(start);
|
|
132
|
+
if (oldStart < 0) return mergeSpec(existing, incoming, lang);
|
|
133
|
+
if (existing.indexOf(start, oldStart + 1) >= 0 || existing.indexOf(end, oldStart) < 0)
|
|
134
|
+
return null;
|
|
135
|
+
const oldEnd = existing.indexOf(end, oldStart);
|
|
136
|
+
const next = existing.slice(0, oldStart) + incomingBlock + existing.slice(oldEnd + end.length);
|
|
137
|
+
const incLines = incoming.split('\n');
|
|
138
|
+
const [, incLastImport] = importRange(incLines, lang);
|
|
139
|
+
const existingSet = new Set(next.split('\n').map((line) => line.trim()));
|
|
140
|
+
const missing = [];
|
|
141
|
+
for (let index = 0; index <= incLastImport; index += 1) {
|
|
142
|
+
const line = incLines[index];
|
|
143
|
+
if (!isImportLine(line, lang)) continue;
|
|
144
|
+
const trimmed = line.trim();
|
|
145
|
+
if (!existingSet.has(trimmed)) missing.push(trimmed);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
content: insertImports(next, missing, lang),
|
|
149
|
+
unchanged: next === existing && !missing.length,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
117
153
|
/** TS page object 里的方法块(2 空格缩进,按大括号配平取方法体) */
|
|
118
154
|
function tsMethods(text) {
|
|
119
155
|
const lines = text.split('\n');
|
|
@@ -227,7 +263,7 @@ export function mergeGeneratedFile(existing, incoming, options = {}) {
|
|
|
227
263
|
if (before.trim() === after.trim()) return { content: before, unchanged: true };
|
|
228
264
|
|
|
229
265
|
const lang = guessLang(after, filePath);
|
|
230
|
-
if (role === 'spec') return
|
|
266
|
+
if (role === 'spec') return mergeAutomationSpecBlock(before, after, lang);
|
|
231
267
|
if (role === 'page')
|
|
232
268
|
return lang === 'python' ? mergePyPage(before, after) : mergeTsPage(before, after);
|
|
233
269
|
if (role === 'fixture') return mergeFixture(before, after);
|