lantern-harness 0.2.2 → 0.2.4
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 +46 -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 +1211 -72
- package/cli/server.mjs +2 -0
- package/dist/500.html +9 -4
- package/dist/_astro/Base.ANghvs5L.css +1 -0
- package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.XUV2H6ea.js → Base.astro_astro_type_script_index_0_lang.f7BIL9Qf.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.p6Y23xyH.js +4 -0
- package/dist/_astro/CaseGenerateApp.D5uj5bSb.js +10 -0
- package/dist/_astro/CasesLibrary.CY1PRdzc.js +21 -0
- package/dist/_astro/ChatApp.BnV7drSC.js +1 -0
- package/dist/_astro/ChatApp.CqyrMX90.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.Cb6977dz.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.C7V_fEh9.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.CRbfEiyw.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.BZkPzwi8.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.B7nd7uBP.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.DQR6uvH5.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.efWkT7Gv.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.Dm9VcR6v.js} +1 -1
- package/dist/_astro/{test-points.C7ZgggQT.js → test-points.BSfPfq8z.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 +105 -58
- package/dist/docs/install/index.html +12 -6
- package/dist/docs/manual/index.html +62 -40
- 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 +117 -53
- package/docs//344/274/232/350/257/235/346/217/222/344/273/266.md +14 -1
- package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +5 -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 +45 -36
- package/lh-plugins/case-automation/service.mjs +927 -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 +123 -23
- 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-stats.mjs +65 -4
- 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 +19 -2
- 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,32 +1,60 @@
|
|
|
1
|
+
import { bindCaseIdentities, recordManualVerification } from './assets.mjs';
|
|
1
2
|
import crypto from 'node:crypto';
|
|
3
|
+
import { validateDefectLinks, CASE_FIELD_ALIASES } from '../../builtin/case-workflow-contract.mjs';
|
|
2
4
|
import fs from 'node:fs';
|
|
3
5
|
import path from 'node:path';
|
|
4
6
|
|
|
5
7
|
import { resolveContentRoot } from '../../builtin/session/space-layout.mjs';
|
|
8
|
+
import {
|
|
9
|
+
CASE_BACKUP_DIR_NAME,
|
|
10
|
+
backupDirectoryForCasePath,
|
|
11
|
+
} from '../../builtin/case-backup-contract.mjs';
|
|
6
12
|
|
|
7
13
|
const CASE_DIR_NAME = '用例管理';
|
|
8
|
-
const
|
|
9
|
-
const
|
|
14
|
+
const DEFECT_URL_HEADER = '缺陷信息';
|
|
15
|
+
const LEGACY_DEFECT_URL_HEADER = '缺陷地址';
|
|
16
|
+
const DEFECT_TITLE_HEADER = '缺陷标题';
|
|
10
17
|
const EXECUTION_STATUSES = ['待验证', '通过', '不通过', '阻塞', '跳过'];
|
|
11
18
|
|
|
12
19
|
const ALIASES = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
...CASE_FIELD_ALIASES,
|
|
21
|
+
no: CASE_FIELD_ALIASES.no,
|
|
22
|
+
title: CASE_FIELD_ALIASES.title,
|
|
23
|
+
precondition: CASE_FIELD_ALIASES.precondition,
|
|
24
|
+
steps: CASE_FIELD_ALIASES.steps,
|
|
25
|
+
expected: CASE_FIELD_ALIASES.expected,
|
|
26
|
+
priority: CASE_FIELD_ALIASES.priority,
|
|
27
|
+
module: CASE_FIELD_ALIASES.module,
|
|
28
|
+
submodule: CASE_FIELD_ALIASES.submodule,
|
|
21
29
|
status: ['用例状态', '执行状态', '执行结果', '测试结果'],
|
|
22
30
|
actual: ['实际结果', '实测结果', '执行实际结果'],
|
|
23
31
|
executor: ['执行人', '测试人'],
|
|
24
32
|
executedAt: ['执行时间', '测试时间'],
|
|
25
33
|
evidence: ['执行证据', '截图日志', '证据'],
|
|
26
34
|
defectNo: ['缺陷编号', '缺陷ID', 'BUG编号', 'bug编号'],
|
|
27
|
-
|
|
35
|
+
defectTitle: ['缺陷标题', 'BUG标题', 'bug标题', '缺陷名称', '缺陷主题'],
|
|
36
|
+
defectUrl: [
|
|
37
|
+
'缺陷信息',
|
|
38
|
+
LEGACY_DEFECT_URL_HEADER,
|
|
39
|
+
'缺陷链接',
|
|
40
|
+
'缺陷URL',
|
|
41
|
+
'BUG地址',
|
|
42
|
+
'bug地址',
|
|
43
|
+
'bug链接',
|
|
44
|
+
],
|
|
28
45
|
};
|
|
29
46
|
|
|
47
|
+
const DEFECT_URL_ALIASES = new Set(ALIASES.defectUrl);
|
|
48
|
+
const DEFECT_TITLE_ALIASES = new Set(ALIASES.defectTitle);
|
|
49
|
+
|
|
50
|
+
function isDefectUrlFieldHeader(header) {
|
|
51
|
+
return header === DEFECT_URL_HEADER || DEFECT_URL_ALIASES.has(header);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isDefectTitleFieldHeader(header) {
|
|
55
|
+
return header === DEFECT_TITLE_HEADER || DEFECT_TITLE_ALIASES.has(header);
|
|
56
|
+
}
|
|
57
|
+
|
|
30
58
|
function text(value, max = 4000) {
|
|
31
59
|
return typeof value === 'string' ? value.trim().slice(0, max) : '';
|
|
32
60
|
}
|
|
@@ -50,7 +78,15 @@ function fieldMap(headers) {
|
|
|
50
78
|
const used = new Set();
|
|
51
79
|
for (const [field, aliases] of Object.entries(ALIASES)) {
|
|
52
80
|
for (const alias of aliases.map(normalizeHeader)) {
|
|
53
|
-
const hit =
|
|
81
|
+
const hit =
|
|
82
|
+
pairs.find((item) => !used.has(item.raw) && item.norm === alias) ||
|
|
83
|
+
pairs.find(
|
|
84
|
+
(item) =>
|
|
85
|
+
!used.has(item.raw) &&
|
|
86
|
+
alias.length >= 2 &&
|
|
87
|
+
item.norm.startsWith(alias) &&
|
|
88
|
+
item.norm.length - alias.length <= 4,
|
|
89
|
+
);
|
|
54
90
|
if (!hit) continue;
|
|
55
91
|
mapped[field] = hit.raw;
|
|
56
92
|
used.add(hit.raw);
|
|
@@ -96,7 +132,7 @@ function walkCaseFiles(root, dir = caseRoot(root), relative = '') {
|
|
|
96
132
|
if (ignored(item.name)) continue;
|
|
97
133
|
const rel = relative ? `${relative}/${item.name}` : item.name;
|
|
98
134
|
if (item.isDirectory()) {
|
|
99
|
-
if (item.name ===
|
|
135
|
+
if (item.name === CASE_BACKUP_DIR_NAME) continue;
|
|
100
136
|
files.push(...walkCaseFiles(root, path.join(dir, item.name), rel));
|
|
101
137
|
continue;
|
|
102
138
|
}
|
|
@@ -316,6 +352,7 @@ function publicRow(parsed, item, index) {
|
|
|
316
352
|
executedAt: rowValue(row, map, 'executedAt'),
|
|
317
353
|
evidence: rowValue(row, map, 'evidence'),
|
|
318
354
|
defectNo: rowValue(row, map, 'defectNo'),
|
|
355
|
+
defectTitle: rowValue(row, map, 'defectTitle'),
|
|
319
356
|
defectUrl: rowValue(row, map, 'defectUrl'),
|
|
320
357
|
fields: parsed.headers
|
|
321
358
|
.filter(Boolean)
|
|
@@ -347,7 +384,7 @@ export async function loadCaseDocument(root, relativePath) {
|
|
|
347
384
|
: missingColumns.length
|
|
348
385
|
? `缺少执行列:${missingColumns.join('、')}`
|
|
349
386
|
: '';
|
|
350
|
-
return {
|
|
387
|
+
return bindCaseIdentities(root, {
|
|
351
388
|
path: relativePath.replaceAll('\\', '/'),
|
|
352
389
|
abs,
|
|
353
390
|
ext,
|
|
@@ -366,6 +403,7 @@ export async function loadCaseDocument(root, relativePath) {
|
|
|
366
403
|
executedAt: map.executedAt || '',
|
|
367
404
|
evidence: map.evidence || '',
|
|
368
405
|
defectNo: map.defectNo || '',
|
|
406
|
+
defectTitle: map.defectTitle || '',
|
|
369
407
|
defectUrl: map.defectUrl || '',
|
|
370
408
|
},
|
|
371
409
|
executable: !executionIssue,
|
|
@@ -374,7 +412,7 @@ export async function loadCaseDocument(root, relativePath) {
|
|
|
374
412
|
statuses: EXECUTION_STATUSES,
|
|
375
413
|
_parsed: parsed,
|
|
376
414
|
_map: map,
|
|
377
|
-
};
|
|
415
|
+
});
|
|
378
416
|
}
|
|
379
417
|
|
|
380
418
|
export async function listCaseDocuments(root) {
|
|
@@ -411,7 +449,10 @@ function stamp(date = new Date()) {
|
|
|
411
449
|
|
|
412
450
|
export function backupCaseDocument(root, relativePath) {
|
|
413
451
|
const abs = safeCasePath(root, relativePath);
|
|
414
|
-
const backupDir = path.join(
|
|
452
|
+
const backupDir = path.join(
|
|
453
|
+
caseRoot(root),
|
|
454
|
+
...backupDirectoryForCasePath(relativePath).split('/'),
|
|
455
|
+
);
|
|
415
456
|
fs.mkdirSync(backupDir, { recursive: true });
|
|
416
457
|
const ext = path.extname(abs);
|
|
417
458
|
const base = path.basename(abs, ext);
|
|
@@ -743,21 +784,49 @@ export async function applyCaseFieldUpdates(
|
|
|
743
784
|
if (!normalized.length) {
|
|
744
785
|
throw Object.assign(new Error('没有需要保存的字段'), { statusCode: 400 });
|
|
745
786
|
}
|
|
787
|
+
for (const update of normalized) {
|
|
788
|
+
if (isDefectUrlFieldHeader(update.header) && document.columns.defectUrl) {
|
|
789
|
+
update.header = document.columns.defectUrl;
|
|
790
|
+
}
|
|
791
|
+
if (isDefectTitleFieldHeader(update.header) && document.columns.defectTitle) {
|
|
792
|
+
update.header = document.columns.defectTitle;
|
|
793
|
+
}
|
|
794
|
+
if (update.header === document.columns.defectUrl || isDefectUrlFieldHeader(update.header)) {
|
|
795
|
+
update.value = validateDefectLinks(update.value);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
746
798
|
let allowed = new Set(document.headers.map((header) => String(header)));
|
|
747
799
|
const unknown = normalized.filter((update) => !allowed.has(update.header));
|
|
748
|
-
|
|
749
|
-
|
|
800
|
+
const unsupported = unknown.filter(
|
|
801
|
+
(update) => !isDefectUrlFieldHeader(update.header) && !isDefectTitleFieldHeader(update.header),
|
|
802
|
+
);
|
|
803
|
+
if (unsupported.length) {
|
|
804
|
+
const first = unsupported[0];
|
|
750
805
|
throw Object.assign(new Error(`用例文件不存在字段:${first?.header || ''}`), {
|
|
751
806
|
statusCode: 400,
|
|
752
807
|
});
|
|
753
808
|
}
|
|
754
809
|
const backup = backupCaseDocument(root, relativePath);
|
|
755
810
|
if (unknown.length) {
|
|
756
|
-
|
|
757
|
-
|
|
811
|
+
const missingHeaders = [
|
|
812
|
+
unknown.some((update) => isDefectUrlFieldHeader(update.header)) ? DEFECT_URL_HEADER : '',
|
|
813
|
+
unknown.some((update) => isDefectTitleFieldHeader(update.header)) ? DEFECT_TITLE_HEADER : '',
|
|
814
|
+
].filter(Boolean);
|
|
815
|
+
for (const header of missingHeaders) {
|
|
816
|
+
await appendCaseHeader(document, header);
|
|
817
|
+
document = await loadCaseDocument(root, relativePath);
|
|
818
|
+
}
|
|
758
819
|
allowed = new Set(document.headers.map((header) => String(header)));
|
|
759
|
-
|
|
760
|
-
|
|
820
|
+
for (const update of normalized) {
|
|
821
|
+
if (allowed.has(update.header)) continue;
|
|
822
|
+
if (isDefectUrlFieldHeader(update.header)) update.header = DEFECT_URL_HEADER;
|
|
823
|
+
else if (isDefectTitleFieldHeader(update.header)) update.header = DEFECT_TITLE_HEADER;
|
|
824
|
+
}
|
|
825
|
+
if (missingHeaders.includes(DEFECT_URL_HEADER) && !allowed.has(DEFECT_URL_HEADER)) {
|
|
826
|
+
throw new Error('缺陷信息字段追加失败');
|
|
827
|
+
}
|
|
828
|
+
if (missingHeaders.includes(DEFECT_TITLE_HEADER) && !allowed.has(DEFECT_TITLE_HEADER)) {
|
|
829
|
+
throw new Error('缺陷标题字段追加失败');
|
|
761
830
|
}
|
|
762
831
|
}
|
|
763
832
|
if (document.ext === '.xlsx') {
|
|
@@ -765,6 +834,10 @@ export async function applyCaseFieldUpdates(
|
|
|
765
834
|
} else {
|
|
766
835
|
patchText(document.abs, document.ext, document._parsed, rowIndex, normalized);
|
|
767
836
|
}
|
|
837
|
+
if (normalized.some((update) => update.header === document.columns.status)) {
|
|
838
|
+
const refreshed = await loadCaseDocument(root, relativePath);
|
|
839
|
+
recordManualVerification(root, refreshed, rowIndex);
|
|
840
|
+
}
|
|
768
841
|
return {
|
|
769
842
|
ok: true,
|
|
770
843
|
path: relativePath,
|
|
@@ -774,4 +847,31 @@ export async function applyCaseFieldUpdates(
|
|
|
774
847
|
};
|
|
775
848
|
}
|
|
776
849
|
|
|
777
|
-
export { EXECUTION_STATUSES };
|
|
850
|
+
export { EXECUTION_STATUSES, fieldMap as caseExecutionFieldMap };
|
|
851
|
+
|
|
852
|
+
export async function prepareExecutionColumns(root, raw) {
|
|
853
|
+
let document = await loadCaseDocument(root, raw.casePath);
|
|
854
|
+
const preview = {
|
|
855
|
+
path: document.path,
|
|
856
|
+
fileHash: document.fileHash,
|
|
857
|
+
missingColumns: document.missingColumns,
|
|
858
|
+
executable: document.executable,
|
|
859
|
+
};
|
|
860
|
+
if (raw.mode !== 'apply') return { ok: true, preview };
|
|
861
|
+
if (document.ext === '.xls')
|
|
862
|
+
throw Object.assign(new Error(document.executionIssue), { statusCode: 422 });
|
|
863
|
+
if (raw.expectedFileHash !== document.fileHash)
|
|
864
|
+
throw Object.assign(new Error('文件已变化,请重新预览'), { statusCode: 409 });
|
|
865
|
+
const backup = document.missingColumns.length ? backupCaseDocument(root, raw.casePath) : '';
|
|
866
|
+
for (const header of document.missingColumns) {
|
|
867
|
+
await appendCaseHeader(document, header);
|
|
868
|
+
document = await loadCaseDocument(root, raw.casePath);
|
|
869
|
+
}
|
|
870
|
+
return {
|
|
871
|
+
ok: true,
|
|
872
|
+
preview,
|
|
873
|
+
backup,
|
|
874
|
+
fileHash: document.fileHash,
|
|
875
|
+
executable: document.executable,
|
|
876
|
+
};
|
|
877
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import { startRun, getRun, stopRun, confirmRun } from './service.mjs';
|
|
5
|
+
import { loadCaseDocument, applyCaseExecutionResult } from './files.mjs';
|
|
6
|
+
import { caseContentFingerprint, recordManualVerification } from './assets.mjs';
|
|
7
|
+
import { isPluginOnInSpace } from '../plugin-prompts.mjs';
|
|
8
|
+
import {
|
|
9
|
+
startAutomationProjectRun,
|
|
10
|
+
stopAutomationProjectRun,
|
|
11
|
+
readAutomationProjectRun,
|
|
12
|
+
} from '../lh-uiauto.mjs';
|
|
13
|
+
|
|
14
|
+
const active = new Map();
|
|
15
|
+
const folder = (root) => path.join(root, '.lantern', 'local', 'case-execution', 'plans');
|
|
16
|
+
const key = (root, id) => `${root}\0${id}`;
|
|
17
|
+
const fail = (message, statusCode = 400) => {
|
|
18
|
+
throw Object.assign(new Error(message), { statusCode });
|
|
19
|
+
};
|
|
20
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
21
|
+
function file(root, id) {
|
|
22
|
+
if (!/^[a-z0-9-]{36}$/.test(id || '')) fail('计划编号无效');
|
|
23
|
+
return path.join(folder(root), id + '.json');
|
|
24
|
+
}
|
|
25
|
+
function save(root, plan) {
|
|
26
|
+
fs.mkdirSync(folder(root), { recursive: true });
|
|
27
|
+
plan.updatedAt = new Date().toISOString();
|
|
28
|
+
fs.writeFileSync(file(root, plan.id) + '.tmp', JSON.stringify(plan, null, 2), { mode: 0o600 });
|
|
29
|
+
fs.renameSync(file(root, plan.id) + '.tmp', file(root, plan.id));
|
|
30
|
+
}
|
|
31
|
+
function view(plan) {
|
|
32
|
+
return { ...plan, storageStatePath: plan.storageStatePath ? '[local]' : '' };
|
|
33
|
+
}
|
|
34
|
+
function read(root, id) {
|
|
35
|
+
let plan;
|
|
36
|
+
try {
|
|
37
|
+
plan = JSON.parse(fs.readFileSync(file(root, id), 'utf8'));
|
|
38
|
+
} catch {
|
|
39
|
+
fail('执行计划不存在', 404);
|
|
40
|
+
}
|
|
41
|
+
if (plan.status === 'running' && !active.has(key(root, id))) {
|
|
42
|
+
plan.status = 'interrupted';
|
|
43
|
+
plan.error = '服务重启导致计划中断;可显式继续未完成项,已完成证据保留';
|
|
44
|
+
plan.items.forEach((item) => {
|
|
45
|
+
if (item.status === 'running') item.status = 'interrupted';
|
|
46
|
+
});
|
|
47
|
+
save(root, plan);
|
|
48
|
+
}
|
|
49
|
+
return plan;
|
|
50
|
+
}
|
|
51
|
+
export function listExecutionPlans(root, casePath = '') {
|
|
52
|
+
if (!fs.existsSync(folder(root))) return [];
|
|
53
|
+
return fs
|
|
54
|
+
.readdirSync(folder(root))
|
|
55
|
+
.filter((name) => name.endsWith('.json'))
|
|
56
|
+
.map((name) => read(root, name.slice(0, -5)))
|
|
57
|
+
.filter((plan) => !casePath || plan.casePath === casePath)
|
|
58
|
+
.sort((a, b) => b.createdAt.localeCompare(a.createdAt))
|
|
59
|
+
.map(view);
|
|
60
|
+
}
|
|
61
|
+
export function getExecutionPlan(root, id) {
|
|
62
|
+
return view(read(root, id));
|
|
63
|
+
}
|
|
64
|
+
export async function createExecutionPlan(root, raw) {
|
|
65
|
+
if (!String(raw.environment?.name || '').trim() || !String(raw.environment?.build || '').trim())
|
|
66
|
+
fail('环境名称与被测构建版本不能为空');
|
|
67
|
+
const document = await loadCaseDocument(root, raw.casePath);
|
|
68
|
+
if (raw.expectedFileHash !== document.fileHash) fail('用例文件已变化,请重新选择计划范围', 409);
|
|
69
|
+
if (document.provenance?.stale) fail('需求基线已变化,请先更新用例', 409);
|
|
70
|
+
const selected = new Set(Array.isArray(raw.caseIds) ? raw.caseIds : []);
|
|
71
|
+
const cases = document.cases.filter((item) => selected.has(item.id));
|
|
72
|
+
if (!cases.length || cases.length !== selected.size) fail('请选择有效的用例范围');
|
|
73
|
+
const engine = raw.engine === 'automation' ? 'automation' : 'browser';
|
|
74
|
+
if (engine === 'browser' && !document.executable) fail(document.executionIssue, 422);
|
|
75
|
+
if (engine === 'browser') {
|
|
76
|
+
const url = new URL(raw.url);
|
|
77
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password)
|
|
78
|
+
fail('目标地址必须为 HTTP / HTTPS');
|
|
79
|
+
}
|
|
80
|
+
if (engine === 'automation' && !String(raw.file || '').trim())
|
|
81
|
+
fail('请选择指定测试文件,避免误运行整个项目');
|
|
82
|
+
if (engine === 'automation' && !raw.projectId) fail('请选择已挂载的自动化项目');
|
|
83
|
+
const plan = {
|
|
84
|
+
version: 1,
|
|
85
|
+
id: crypto.randomUUID(),
|
|
86
|
+
casePath: document.path,
|
|
87
|
+
fileHash: document.fileHash,
|
|
88
|
+
provenance: document.provenance,
|
|
89
|
+
engine,
|
|
90
|
+
url: String(raw.url || ''),
|
|
91
|
+
storageStatePath: String(raw.storageStatePath || ''),
|
|
92
|
+
allowedOrigins: raw.allowedOrigins || [],
|
|
93
|
+
environment: {
|
|
94
|
+
name: String(raw.environment?.name || '').slice(0, 100),
|
|
95
|
+
role: String(raw.environment?.role || '').slice(0, 100),
|
|
96
|
+
build: String(raw.environment?.build || '').slice(0, 200),
|
|
97
|
+
dataNote: String(raw.environment?.dataNote || '').slice(0, 2000),
|
|
98
|
+
},
|
|
99
|
+
projectId: String(raw.projectId || ''),
|
|
100
|
+
taskId: String(raw.taskId || 'full'),
|
|
101
|
+
setupTaskId: String(raw.setupTaskId || ''),
|
|
102
|
+
cleanupTaskId: String(raw.cleanupTaskId || ''),
|
|
103
|
+
file: String(raw.file || ''),
|
|
104
|
+
items: cases.map((item) => ({
|
|
105
|
+
caseId: item.id,
|
|
106
|
+
title: item.title,
|
|
107
|
+
fingerprint: caseContentFingerprint(item),
|
|
108
|
+
status: 'pending',
|
|
109
|
+
runId: '',
|
|
110
|
+
error: '',
|
|
111
|
+
})),
|
|
112
|
+
status: 'draft',
|
|
113
|
+
error: '',
|
|
114
|
+
createdAt: new Date().toISOString(),
|
|
115
|
+
};
|
|
116
|
+
save(root, plan);
|
|
117
|
+
return view(plan);
|
|
118
|
+
}
|
|
119
|
+
async function execute(root, plan, state) {
|
|
120
|
+
try {
|
|
121
|
+
const snapshot = await loadCaseDocument(root, plan.casePath);
|
|
122
|
+
if (
|
|
123
|
+
snapshot.provenance?.stale ||
|
|
124
|
+
snapshot.provenance?.artifactId !== plan.provenance?.artifactId ||
|
|
125
|
+
snapshot.provenance?.analysisRevision !== plan.provenance?.analysisRevision ||
|
|
126
|
+
snapshot.provenance?.baselineId !== plan.provenance?.baselineId ||
|
|
127
|
+
snapshot.provenance?.sourcePath !== plan.provenance?.sourcePath
|
|
128
|
+
)
|
|
129
|
+
fail('计划需求基线已变化,请重新创建计划');
|
|
130
|
+
for (const item of plan.items) {
|
|
131
|
+
const current = snapshot.cases.find((row) => row.id === item.caseId);
|
|
132
|
+
if (!current || caseContentFingerprint(current) !== item.fingerprint)
|
|
133
|
+
fail('计划用例已变化,请重新创建计划');
|
|
134
|
+
}
|
|
135
|
+
if (state.stop) {
|
|
136
|
+
plan.status = 'stopped';
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (plan.engine === 'automation') {
|
|
140
|
+
if (!isPluginOnInSpace('uiAuto', root)) fail('请开启自动化测试插件');
|
|
141
|
+
const runTask = async (taskId, label) => {
|
|
142
|
+
if (state.stop) return null;
|
|
143
|
+
const result = startAutomationProjectRun(root, {
|
|
144
|
+
projectId: plan.projectId,
|
|
145
|
+
taskId,
|
|
146
|
+
file: plan.file,
|
|
147
|
+
});
|
|
148
|
+
if (result.error) fail(result.error);
|
|
149
|
+
state.externalRunId = result.run.id;
|
|
150
|
+
plan.externalRunId = result.run.id;
|
|
151
|
+
plan.taskRuns ||= [];
|
|
152
|
+
plan.taskRuns.push({ label, runId: result.run.id, status: 'running' });
|
|
153
|
+
save(root, plan);
|
|
154
|
+
let run;
|
|
155
|
+
do {
|
|
156
|
+
run = readAutomationProjectRun(root, result.run.id);
|
|
157
|
+
plan.externalResult = {
|
|
158
|
+
id: run.id,
|
|
159
|
+
status: run.status,
|
|
160
|
+
total: run.total,
|
|
161
|
+
passed: run.passed,
|
|
162
|
+
failed: run.failed,
|
|
163
|
+
skipped: run.skipped,
|
|
164
|
+
reportUrl: run.reportUrl,
|
|
165
|
+
logUrl: run.logUrl,
|
|
166
|
+
error: run.error,
|
|
167
|
+
};
|
|
168
|
+
save(root, plan);
|
|
169
|
+
if (state.stop || run.status !== 'running') break;
|
|
170
|
+
await sleep(500);
|
|
171
|
+
} while (true);
|
|
172
|
+
plan.taskRuns[plan.taskRuns.length - 1].status = run.status;
|
|
173
|
+
state.externalRunId = '';
|
|
174
|
+
return run;
|
|
175
|
+
};
|
|
176
|
+
let result;
|
|
177
|
+
try {
|
|
178
|
+
if (plan.setupTaskId) {
|
|
179
|
+
const setup = await runTask(plan.setupTaskId, '准备数据');
|
|
180
|
+
if (setup?.status !== 'passed') fail('准备任务未成功,主测试未执行;请查看项目日志');
|
|
181
|
+
}
|
|
182
|
+
result = await runTask(plan.taskId, '测试执行');
|
|
183
|
+
} finally {
|
|
184
|
+
const primary = plan.externalResult;
|
|
185
|
+
if (plan.cleanupTaskId && !state.stop) {
|
|
186
|
+
const cleanup = await runTask(plan.cleanupTaskId, '清理数据');
|
|
187
|
+
if (cleanup?.status !== 'passed') plan.cleanupWarning = '清理任务未成功,请人工清理数据';
|
|
188
|
+
}
|
|
189
|
+
plan.externalResult = primary;
|
|
190
|
+
}
|
|
191
|
+
if (!result) {
|
|
192
|
+
plan.status = 'stopped';
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
plan.items.forEach((item) => {
|
|
196
|
+
item.status = 'awaiting_confirmation';
|
|
197
|
+
item.externalRunId = result.id;
|
|
198
|
+
});
|
|
199
|
+
plan.note = '自动化项目汇总不等于每条业务用例通过,请核对报告后逐条手动选择结果';
|
|
200
|
+
} else
|
|
201
|
+
for (const item of plan.items.filter((item) =>
|
|
202
|
+
['pending', 'interrupted'].includes(item.status),
|
|
203
|
+
)) {
|
|
204
|
+
if (state.stop) break;
|
|
205
|
+
const document = await loadCaseDocument(root, plan.casePath);
|
|
206
|
+
const row = document.cases.find((row) => row.id === item.caseId);
|
|
207
|
+
if (
|
|
208
|
+
!row ||
|
|
209
|
+
caseContentFingerprint(row) !== item.fingerprint ||
|
|
210
|
+
document.provenance?.stale ||
|
|
211
|
+
document.provenance?.analysisRevision !== plan.provenance?.analysisRevision ||
|
|
212
|
+
document.provenance?.baselineId !== plan.provenance?.baselineId
|
|
213
|
+
)
|
|
214
|
+
fail('用例内容或需求基线已变化,计划已阻塞');
|
|
215
|
+
const run = await startRun(root, {
|
|
216
|
+
casePath: plan.casePath,
|
|
217
|
+
rowIndex: row.rowIndex,
|
|
218
|
+
url: plan.url,
|
|
219
|
+
storageStatePath: plan.storageStatePath,
|
|
220
|
+
allowedOrigins: plan.allowedOrigins,
|
|
221
|
+
environment: plan.environment,
|
|
222
|
+
});
|
|
223
|
+
state.runId = run.id;
|
|
224
|
+
if (state.stop) stopRun(root, run.id);
|
|
225
|
+
item.runId = run.id;
|
|
226
|
+
item.status = 'running';
|
|
227
|
+
save(root, plan);
|
|
228
|
+
let latest = run;
|
|
229
|
+
while (!state.stop && latest.status === 'running') {
|
|
230
|
+
await sleep(500);
|
|
231
|
+
latest = getRun(root, run.id);
|
|
232
|
+
}
|
|
233
|
+
item.status = state.stop ? 'interrupted' : 'awaiting_confirmation';
|
|
234
|
+
item.error = latest.error || '';
|
|
235
|
+
save(root, plan);
|
|
236
|
+
state.runId = '';
|
|
237
|
+
}
|
|
238
|
+
plan.status = state.stop ? 'stopped' : 'awaiting_confirmation';
|
|
239
|
+
} catch (error) {
|
|
240
|
+
plan.status = state.stop ? 'stopped' : 'blocked';
|
|
241
|
+
plan.error = state.stop ? '用户已停止计划;未完成项可显式继续' : error.message;
|
|
242
|
+
} finally {
|
|
243
|
+
save(root, plan);
|
|
244
|
+
active.delete(key(root, plan.id));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
export function startExecutionPlan(root, id) {
|
|
248
|
+
if (active.size) fail('已有执行计划运行中', 409);
|
|
249
|
+
const plan = read(root, id);
|
|
250
|
+
if (!['draft', 'interrupted', 'stopped', 'blocked'].includes(plan.status))
|
|
251
|
+
fail('此计划不可重复启动;重跑请新建计划', 409);
|
|
252
|
+
const state = { stop: false, runId: '', externalRunId: '' };
|
|
253
|
+
active.set(key(root, id), state);
|
|
254
|
+
plan.status = 'running';
|
|
255
|
+
plan.error = '';
|
|
256
|
+
save(root, plan);
|
|
257
|
+
void execute(root, plan, state);
|
|
258
|
+
return view(plan);
|
|
259
|
+
}
|
|
260
|
+
export function stopExecutionPlan(root, id) {
|
|
261
|
+
const state = active.get(key(root, id));
|
|
262
|
+
if (state) {
|
|
263
|
+
state.stop = true;
|
|
264
|
+
if (state.runId) stopRun(root, state.runId);
|
|
265
|
+
if (state.externalRunId) stopAutomationProjectRun(state.externalRunId);
|
|
266
|
+
}
|
|
267
|
+
return view(read(root, id));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export async function verifyExecutionPlanItem(root, id, raw) {
|
|
271
|
+
const plan = read(root, id);
|
|
272
|
+
if (plan.status === 'running' || active.has(key(root, id)))
|
|
273
|
+
fail('计划仍在执行,请结束或停止后验证', 409);
|
|
274
|
+
const item = plan.items.find((item) => item.caseId === raw.caseId);
|
|
275
|
+
if (!item || (!item.runId && !item.externalRunId)) fail('该用例没有本计划的执行记录', 409);
|
|
276
|
+
const document = await loadCaseDocument(root, plan.casePath);
|
|
277
|
+
const row = document.cases.find((row) => row.id === item.caseId);
|
|
278
|
+
if (
|
|
279
|
+
!row ||
|
|
280
|
+
caseContentFingerprint(row) !== item.fingerprint ||
|
|
281
|
+
document.provenance?.stale ||
|
|
282
|
+
document.provenance?.baselineId !== plan.provenance?.baselineId
|
|
283
|
+
)
|
|
284
|
+
fail('计划用例或需求基线已变化,请重新执行', 409);
|
|
285
|
+
if (!String(raw.actualResult || '').trim()) fail('请先填写人工核验的实际结果');
|
|
286
|
+
let applied;
|
|
287
|
+
if (item.runId) {
|
|
288
|
+
applied = await confirmRun(root, item.runId, {
|
|
289
|
+
...raw,
|
|
290
|
+
executor: '人工验证',
|
|
291
|
+
expectedFileHash: raw.expectedFileHash,
|
|
292
|
+
});
|
|
293
|
+
} else {
|
|
294
|
+
applied = await applyCaseExecutionResult(root, {
|
|
295
|
+
path: plan.casePath,
|
|
296
|
+
rowIndex: row.rowIndex,
|
|
297
|
+
expectedFileHash: raw.expectedFileHash,
|
|
298
|
+
status: raw.status,
|
|
299
|
+
actualResult: String(raw.actualResult),
|
|
300
|
+
executor: '人工验证',
|
|
301
|
+
executedAt: new Date().toISOString(),
|
|
302
|
+
evidence: plan.externalResult?.reportUrl || plan.externalResult?.logUrl || '',
|
|
303
|
+
defectNo: row.defectNo,
|
|
304
|
+
});
|
|
305
|
+
recordManualVerification(
|
|
306
|
+
root,
|
|
307
|
+
await loadCaseDocument(root, plan.casePath),
|
|
308
|
+
row.rowIndex,
|
|
309
|
+
plan.environment,
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
item.finalStatus = raw.status;
|
|
313
|
+
item.status = 'verified';
|
|
314
|
+
item.verifiedAt = new Date().toISOString();
|
|
315
|
+
if (plan.items.every((item) => item.status === 'verified')) plan.status = 'completed';
|
|
316
|
+
save(root, plan);
|
|
317
|
+
return { ok: true, plan: view(plan), applied };
|
|
318
|
+
}
|