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
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import { getDataRoot } from '../builtin/session/space-context.mjs';
|
|
5
|
+
import { resolveContentRoot } from '../builtin/session/space-layout.mjs';
|
|
6
|
+
import { executionHeaders, normalizeExecutionStatus } from '../builtin/case-workflow-contract.mjs';
|
|
7
|
+
import {
|
|
8
|
+
analysisSnapshot,
|
|
9
|
+
sourceFileHash,
|
|
10
|
+
linkCaseArtifact,
|
|
11
|
+
readWorkflowAssets,
|
|
12
|
+
caseContentFingerprint,
|
|
13
|
+
} from './case-execution/assets.mjs';
|
|
14
|
+
import { loadCaseDocument, caseExecutionFieldMap } from './case-execution/files.mjs';
|
|
15
|
+
import { analysisRevision } from './req-analysis-revision.mjs';
|
|
16
|
+
import { readReqSourceFile } from './lh-req-analysis.mjs';
|
|
17
|
+
import { isPluginOnInSpace, readPluginPrompt } from './plugin-prompts.mjs';
|
|
18
|
+
|
|
19
|
+
const PREFIX = '/__tb_case_design';
|
|
20
|
+
const defaultHeaders = [
|
|
21
|
+
'用例编号',
|
|
22
|
+
'需求编号',
|
|
23
|
+
'用例标题',
|
|
24
|
+
'前置条件',
|
|
25
|
+
'测试步骤',
|
|
26
|
+
'预期结果',
|
|
27
|
+
'优先级',
|
|
28
|
+
'引用需求点',
|
|
29
|
+
'备注',
|
|
30
|
+
];
|
|
31
|
+
const fail = (message, statusCode = 400) => {
|
|
32
|
+
throw Object.assign(new Error(message), { statusCode });
|
|
33
|
+
};
|
|
34
|
+
const clean = (value) => (typeof value === 'string' ? value.trim() : '');
|
|
35
|
+
function flatten(items) {
|
|
36
|
+
return (items || []).flatMap((item) => [item, ...flatten(item.children)]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function caseDesignContext(root, raw) {
|
|
40
|
+
const analysis = raw.analysisId ? analysisSnapshot(root, raw.analysisId) : null;
|
|
41
|
+
const sourcePath = analysis?.sourcePath || clean(raw.sourcePath);
|
|
42
|
+
const source = sourcePath ? await readReqSourceFile(root, sourcePath) : null;
|
|
43
|
+
if (!analysis && !source) fail('请选择需求分析或需求来源');
|
|
44
|
+
const skillPath = clean(raw.skillPath) || '功能测试用例提示词.md';
|
|
45
|
+
const skill = readPluginPrompt(skillPath, root).trim();
|
|
46
|
+
if (!skill) fail('请先在插件仓库准备对应的用例生成技能', 422);
|
|
47
|
+
return {
|
|
48
|
+
ok: true,
|
|
49
|
+
analysis,
|
|
50
|
+
revision: analysis ? analysisRevision(analysis) : '',
|
|
51
|
+
source,
|
|
52
|
+
sourcePath,
|
|
53
|
+
sourceFileHash: sourceFileHash(root, sourcePath),
|
|
54
|
+
skill,
|
|
55
|
+
headers: executionHeaders(raw.headers?.length ? raw.headers : defaultHeaders),
|
|
56
|
+
outputContract: {
|
|
57
|
+
rows: '数组:按 headers 输出字符串字段;需求编号使用 US,引用需求点使用 RO / TP,禁止编造引用',
|
|
58
|
+
finalStatus: '待验证;实际结果必须留空',
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** @param {any} raw @param {any} [analysis] */
|
|
64
|
+
export function validateCaseDesign(raw, analysis = null) {
|
|
65
|
+
const headers = executionHeaders(
|
|
66
|
+
Array.isArray(raw.headers) && raw.headers.length
|
|
67
|
+
? [...new Set(raw.headers.map(String))]
|
|
68
|
+
: defaultHeaders,
|
|
69
|
+
);
|
|
70
|
+
const rows = Array.isArray(raw.rows) ? raw.rows : [];
|
|
71
|
+
const issues = [];
|
|
72
|
+
if (!rows.length || rows.length > 10000) issues.push('用例数量必须在 1 到 10000 条之间');
|
|
73
|
+
const outline = flatten(analysis?.outline);
|
|
74
|
+
const roAll = new Set(outline.map((item) => item.id));
|
|
75
|
+
const childTargets = outline.filter((item) => item.kind && item.parentId);
|
|
76
|
+
const ro = new Set(
|
|
77
|
+
(childTargets.length ? childTargets : outline.filter((item) => !item.parentId)).map(
|
|
78
|
+
(item) => item.id,
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
const us = new Set((analysis?.stories || []).map((item) => item.id));
|
|
82
|
+
const tp = new Set((analysis?.testPoints?.points || []).map((item) => item.id));
|
|
83
|
+
const covered = { RO: new Set(), US: new Set(), TP: new Set() };
|
|
84
|
+
const mapped = caseExecutionFieldMap(headers);
|
|
85
|
+
const titleHeader = mapped.title,
|
|
86
|
+
stepsHeader = mapped.steps,
|
|
87
|
+
expectedHeader = mapped.expected;
|
|
88
|
+
rows.forEach((row, index) => {
|
|
89
|
+
for (const [label, header] of [
|
|
90
|
+
['标题', titleHeader],
|
|
91
|
+
['步骤', stepsHeader],
|
|
92
|
+
['预期结果', expectedHeader],
|
|
93
|
+
]) {
|
|
94
|
+
if (!header || !clean(row?.[header])) issues.push(`第 ${index + 1} 条缺少${label}`);
|
|
95
|
+
}
|
|
96
|
+
const cite = headers
|
|
97
|
+
.filter((h) => /需求编号|引用需求点|关联需求|需求id/i.test(h))
|
|
98
|
+
.map((h) => String(row?.[h] || ''))
|
|
99
|
+
.join(' ');
|
|
100
|
+
for (const match of cite.matchAll(/\b(RO-[A-Za-z0-9_-]+|US-\d+|TP-\d+)\b/g)) {
|
|
101
|
+
const id = match[1],
|
|
102
|
+
group = id.slice(0, 2),
|
|
103
|
+
valid = group === 'RO' ? roAll : group === 'US' ? us : tp;
|
|
104
|
+
if (analysis && !valid.has(id)) issues.push(`第 ${index + 1} 条引用了不存在的 ${id}`);
|
|
105
|
+
else covered[group].add(id);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const coverage = Object.fromEntries(
|
|
109
|
+
[
|
|
110
|
+
['RO', ro],
|
|
111
|
+
['US', us],
|
|
112
|
+
['TP', tp],
|
|
113
|
+
].map(([kind, ids]) => {
|
|
114
|
+
const missing = [...ids].filter((id) => !covered[kind].has(id));
|
|
115
|
+
return [
|
|
116
|
+
kind,
|
|
117
|
+
{
|
|
118
|
+
targets: [...ids],
|
|
119
|
+
total: ids.size,
|
|
120
|
+
covered: ids.size - missing.length,
|
|
121
|
+
rate: ids.size ? Math.round(((ids.size - missing.length) / ids.size) * 100) : null,
|
|
122
|
+
missing,
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
}),
|
|
126
|
+
);
|
|
127
|
+
return { ok: !issues.length, headers, issues: issues.slice(0, 200), coverage };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function saveCaseDesign(root, raw) {
|
|
131
|
+
const analysis = raw.analysisId ? analysisSnapshot(root, raw.analysisId) : null;
|
|
132
|
+
if (analysis && raw.expectedRevision !== analysisRevision(analysis))
|
|
133
|
+
fail('需求分析已变化,请重新读取后生成', 409);
|
|
134
|
+
const sourcePath = analysis?.sourcePath || clean(raw.sourcePath);
|
|
135
|
+
if (raw.expectedSourceFileHash && raw.expectedSourceFileHash !== sourceFileHash(root, sourcePath))
|
|
136
|
+
fail('需求源文件已变化,请重新读取后生成', 409);
|
|
137
|
+
if (sourcePath && !raw.expectedSourceFileHash)
|
|
138
|
+
fail('保存前必须读取需求基线并携带 sourceFileHash', 409);
|
|
139
|
+
const checked = validateCaseDesign(raw, analysis);
|
|
140
|
+
if (!checked.ok) fail(checked.issues.join(';'), 422);
|
|
141
|
+
const headers = checked.headers;
|
|
142
|
+
const executionMap = caseExecutionFieldMap(headers);
|
|
143
|
+
const statusHeader = executionMap.status,
|
|
144
|
+
actualHeader = executionMap.actual;
|
|
145
|
+
const rows = raw.rows.map((row, index) =>
|
|
146
|
+
Object.fromEntries(
|
|
147
|
+
headers.map((h) => [
|
|
148
|
+
h,
|
|
149
|
+
h === statusHeader
|
|
150
|
+
? '待验证'
|
|
151
|
+
: h === actualHeader
|
|
152
|
+
? ''
|
|
153
|
+
: String(row[h] ?? (h === '用例编号' ? index + 1 : '')),
|
|
154
|
+
]),
|
|
155
|
+
),
|
|
156
|
+
);
|
|
157
|
+
const ext = ['xlsx', 'csv', 'md'].includes(raw.format) ? raw.format : 'xlsx';
|
|
158
|
+
const base = clean(raw.title || analysis?.title || '测试用例')
|
|
159
|
+
.replace(/[\\/:*?"<>|]/g, '_')
|
|
160
|
+
.slice(0, 100);
|
|
161
|
+
const folder = clean(raw.folder)
|
|
162
|
+
.replace(/[\\/:*?"<>|]/g, '_')
|
|
163
|
+
.replace(/^\.+|\.+$/g, '')
|
|
164
|
+
.slice(0, 80);
|
|
165
|
+
const rel = `${folder ? `${folder}/` : ''}${base}_${Date.now()}_${crypto.randomUUID().slice(0, 6)}.${ext}`;
|
|
166
|
+
const dir = path.join(resolveContentRoot(root, '用例管理').abs, folder);
|
|
167
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
168
|
+
const abs = path.join(resolveContentRoot(root, '用例管理').abs, rel);
|
|
169
|
+
if (ext === 'xlsx') {
|
|
170
|
+
const XLSX = await import('xlsx');
|
|
171
|
+
const sheet = XLSX.utils.json_to_sheet(rows, { header: headers });
|
|
172
|
+
const workbook = XLSX.utils.book_new();
|
|
173
|
+
XLSX.utils.book_append_sheet(workbook, sheet, '测试用例');
|
|
174
|
+
fs.writeFileSync(abs, XLSX.write(workbook, { type: 'buffer', bookType: 'xlsx' }), {
|
|
175
|
+
flag: 'wx',
|
|
176
|
+
});
|
|
177
|
+
} else if (ext === 'csv') {
|
|
178
|
+
const cell = (value) => '"' + String(value).replaceAll('"', '""') + '"';
|
|
179
|
+
fs.writeFileSync(
|
|
180
|
+
abs,
|
|
181
|
+
'\uFEFF' +
|
|
182
|
+
[headers, ...rows.map((row) => headers.map((h) => row[h]))]
|
|
183
|
+
.map((row) => row.map(cell).join(','))
|
|
184
|
+
.join('\n'),
|
|
185
|
+
{ flag: 'wx' },
|
|
186
|
+
);
|
|
187
|
+
} else {
|
|
188
|
+
const cell = (value) => String(value).replaceAll('|', '|').replace(/\r?\n/g, '<br>');
|
|
189
|
+
fs.writeFileSync(
|
|
190
|
+
abs,
|
|
191
|
+
[headers, headers.map(() => '---'), ...rows.map((row) => headers.map((h) => row[h]))]
|
|
192
|
+
.map((row) => '| ' + row.map(cell).join(' | ') + ' |')
|
|
193
|
+
.join('\n'),
|
|
194
|
+
{ flag: 'wx' },
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
const document = await loadCaseDocument(root, rel);
|
|
198
|
+
const artifact = linkCaseArtifact(root, document, {
|
|
199
|
+
analysisId: analysis?.id || '',
|
|
200
|
+
analysisRevision: analysis ? analysisRevision(analysis) : '',
|
|
201
|
+
sourcePath,
|
|
202
|
+
sourceFileHash: sourceFileHash(root, sourcePath),
|
|
203
|
+
coverage: checked.coverage,
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
ok: true,
|
|
207
|
+
path: rel,
|
|
208
|
+
artifactId: artifact.id,
|
|
209
|
+
caseCount: rows.length,
|
|
210
|
+
coverage: checked.coverage,
|
|
211
|
+
executable: document.executable,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export async function caseAcceptance(root, casePath, environmentKey = '') {
|
|
216
|
+
const document = await loadCaseDocument(root, casePath);
|
|
217
|
+
const artifact = readWorkflowAssets(root).artifacts.find(
|
|
218
|
+
(item) => item.id === document.provenance.artifactId,
|
|
219
|
+
);
|
|
220
|
+
const history = artifact?.verificationHistory || [];
|
|
221
|
+
const envKey = (env) => JSON.stringify([env?.name || '', env?.role || '', env?.build || '']);
|
|
222
|
+
const envs = new Map();
|
|
223
|
+
history.forEach((item) => {
|
|
224
|
+
if (item.baselineId === artifact?.baselineId)
|
|
225
|
+
envs.set(envKey(item.environment), item.environment);
|
|
226
|
+
});
|
|
227
|
+
const runsFolder = path.join(root, '.lantern', 'local', 'case-execution', 'runs');
|
|
228
|
+
if (fs.existsSync(runsFolder))
|
|
229
|
+
for (const file of fs.readdirSync(runsFolder).filter((name) => name.endsWith('.json'))) {
|
|
230
|
+
try {
|
|
231
|
+
const run = JSON.parse(fs.readFileSync(path.join(runsFolder, file), 'utf8'));
|
|
232
|
+
if (
|
|
233
|
+
run.provenance?.artifactId === artifact?.id &&
|
|
234
|
+
run.provenance?.baselineId === artifact?.baselineId &&
|
|
235
|
+
run.environment
|
|
236
|
+
)
|
|
237
|
+
envs.set(envKey(run.environment), run.environment);
|
|
238
|
+
} catch {
|
|
239
|
+
/* Ignore incomplete runtime records. */
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const plansFolder = path.join(root, '.lantern', 'local', 'case-execution', 'plans');
|
|
243
|
+
if (fs.existsSync(plansFolder))
|
|
244
|
+
for (const file of fs.readdirSync(plansFolder).filter((name) => name.endsWith('.json'))) {
|
|
245
|
+
try {
|
|
246
|
+
const plan = JSON.parse(fs.readFileSync(path.join(plansFolder, file), 'utf8'));
|
|
247
|
+
if (
|
|
248
|
+
plan.provenance?.artifactId === artifact?.id &&
|
|
249
|
+
plan.provenance?.baselineId === artifact?.baselineId &&
|
|
250
|
+
plan.environment
|
|
251
|
+
)
|
|
252
|
+
envs.set(envKey(plan.environment), plan.environment);
|
|
253
|
+
} catch {
|
|
254
|
+
/* Ignore incomplete plans. */
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const environments = [...envs.entries()].map(([key, env]) => ({
|
|
258
|
+
key,
|
|
259
|
+
label: [env?.name, env?.role, env?.build].filter(Boolean).join(' / ') || '未标注环境',
|
|
260
|
+
}));
|
|
261
|
+
if (environmentKey) {
|
|
262
|
+
for (const item of document.cases) {
|
|
263
|
+
const verified = history
|
|
264
|
+
.filter(
|
|
265
|
+
(entry) =>
|
|
266
|
+
entry.caseId === item.id &&
|
|
267
|
+
envKey(entry.environment) === environmentKey &&
|
|
268
|
+
entry.baselineId === artifact?.baselineId &&
|
|
269
|
+
entry.sourceFileHash === (artifact?.sourceFileHash || '') &&
|
|
270
|
+
entry.contentFingerprint === caseContentFingerprint(item),
|
|
271
|
+
)
|
|
272
|
+
.at(-1);
|
|
273
|
+
item.status =
|
|
274
|
+
verified && !document.provenance.stale && !artifact?.needsReview?.includes(item.id)
|
|
275
|
+
? verified.status
|
|
276
|
+
: '待验证';
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const analysis = document.provenance.analysisId
|
|
280
|
+
? analysisSnapshot(root, document.provenance.analysisId)
|
|
281
|
+
: null;
|
|
282
|
+
const rows = document.cases.map((item) =>
|
|
283
|
+
Object.fromEntries((item.fields || []).map((f) => [f.name, f.value])),
|
|
284
|
+
);
|
|
285
|
+
const design = validateCaseDesign({ rows, headers: document.headers }, analysis);
|
|
286
|
+
const statuses = document.cases.map((item) => normalizeExecutionStatus(item.status));
|
|
287
|
+
const progressCoverage = Object.fromEntries(
|
|
288
|
+
Object.entries(design.coverage).map(([kind, value]) => {
|
|
289
|
+
const refs = new Map();
|
|
290
|
+
document.cases.forEach((item) => {
|
|
291
|
+
const text = (item.fields || [])
|
|
292
|
+
.filter((field) => /需求编号|引用需求点|关联需求|需求id/i.test(field.name))
|
|
293
|
+
.map((field) => field.value)
|
|
294
|
+
.join(' ');
|
|
295
|
+
for (const match of text.matchAll(/\b(RO-[A-Za-z0-9_-]+|US-\d+|TP-\d+)\b/g)) {
|
|
296
|
+
if (!match[1].startsWith(kind + '-')) continue;
|
|
297
|
+
const states = refs.get(match[1]) || [];
|
|
298
|
+
states.push(normalizeExecutionStatus(item.status));
|
|
299
|
+
refs.set(match[1], states);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
const validStates = [...refs.entries()]
|
|
303
|
+
.filter(([id]) => value.targets.includes(id))
|
|
304
|
+
.map(([, states]) => states);
|
|
305
|
+
const executed = validStates.filter((states) =>
|
|
306
|
+
states.every((status) => status !== '待验证'),
|
|
307
|
+
).length;
|
|
308
|
+
const passed = validStates.filter((states) =>
|
|
309
|
+
states.every((status) => status === '通过'),
|
|
310
|
+
).length;
|
|
311
|
+
return [
|
|
312
|
+
kind,
|
|
313
|
+
{
|
|
314
|
+
total: value.total,
|
|
315
|
+
executed,
|
|
316
|
+
passed,
|
|
317
|
+
executionRate: value.total ? Math.round((executed / value.total) * 100) : null,
|
|
318
|
+
passRate: value.total ? Math.round((passed / value.total) * 100) : null,
|
|
319
|
+
},
|
|
320
|
+
];
|
|
321
|
+
}),
|
|
322
|
+
);
|
|
323
|
+
const passed = statuses.filter((status) => status === '通过').length;
|
|
324
|
+
const pending = statuses.filter((status) => status === '待验证').length;
|
|
325
|
+
const failed = statuses.filter((status) => status === '不通过').length;
|
|
326
|
+
const blocked = statuses.filter((status) => status === '阻塞').length;
|
|
327
|
+
const skipped = statuses.filter((status) => status === '跳过').length;
|
|
328
|
+
const reasons = [...document.provenance.reasons];
|
|
329
|
+
if (!environmentKey && environments.length > 1)
|
|
330
|
+
reasons.push('包含多个环境或构建的验证记录,请选择具体环境查看验收');
|
|
331
|
+
if (!design.ok) reasons.push('用例字段或需求引用校验未通过');
|
|
332
|
+
if (pending) reasons.push(`${pending} 条待验证`);
|
|
333
|
+
if (failed || blocked) reasons.push(`${failed} 条不通过,${blocked} 条阻塞`);
|
|
334
|
+
if (skipped) reasons.push(`${skipped} 条跳过,需说明接受风险`);
|
|
335
|
+
if (!analysis) reasons.push('未关联需求分析,无法核验需求覆盖');
|
|
336
|
+
if (Object.values(design.coverage).some((item) => item.total && item.missing.length))
|
|
337
|
+
reasons.push('存在未覆盖需求或测试点');
|
|
338
|
+
return {
|
|
339
|
+
ok: true,
|
|
340
|
+
path: casePath,
|
|
341
|
+
provenance: document.provenance,
|
|
342
|
+
environments,
|
|
343
|
+
environmentKey,
|
|
344
|
+
designCoverage: design.coverage,
|
|
345
|
+
progressCoverage,
|
|
346
|
+
total: statuses.length,
|
|
347
|
+
passed,
|
|
348
|
+
pending,
|
|
349
|
+
failed,
|
|
350
|
+
blocked,
|
|
351
|
+
skipped,
|
|
352
|
+
executionRate: statuses.length
|
|
353
|
+
? Math.round(((statuses.length - pending) / statuses.length) * 100)
|
|
354
|
+
: 0,
|
|
355
|
+
acceptance: { ready: !!statuses.length && !reasons.length, reasons },
|
|
356
|
+
note: '仅汇总用户手动判定状态;不包含缺陷平台状态或性能测试,不替代项目最终准出审批',
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export async function linkCaseBaseline(root, raw) {
|
|
361
|
+
const document = await loadCaseDocument(root, raw.casePath);
|
|
362
|
+
const analysis = analysisSnapshot(root, raw.analysisId);
|
|
363
|
+
const revision = analysisRevision(analysis);
|
|
364
|
+
const preview = {
|
|
365
|
+
fileHash: document.fileHash,
|
|
366
|
+
revision,
|
|
367
|
+
affected: document.cases.map((item) => ({ id: item.id, title: item.title })),
|
|
368
|
+
note: '关联或更新基线后,历史结果保留但需逐条人工复核,未复核结果不计为通过',
|
|
369
|
+
};
|
|
370
|
+
if (raw.mode !== 'apply') return { ok: true, preview };
|
|
371
|
+
if (raw.expectedFileHash !== document.fileHash || raw.expectedRevision !== revision)
|
|
372
|
+
fail('文件或需求已变化,请重新预览', 409);
|
|
373
|
+
linkCaseArtifact(root, document, {
|
|
374
|
+
analysisId: analysis.id,
|
|
375
|
+
analysisRevision: revision,
|
|
376
|
+
sourcePath: analysis.sourcePath,
|
|
377
|
+
sourceFileHash: sourceFileHash(root, analysis.sourcePath),
|
|
378
|
+
needsReview: document.cases.map((item) => item.id),
|
|
379
|
+
});
|
|
380
|
+
return { ok: true, preview };
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export function lhCaseDesignPlugin() {
|
|
384
|
+
return {
|
|
385
|
+
name: 'lh-case-design',
|
|
386
|
+
configureServer(server) {
|
|
387
|
+
server.middlewares.use(async (req, res, next) => {
|
|
388
|
+
const url = new URL(req.url || '/', 'http://localhost');
|
|
389
|
+
if (!url.pathname.startsWith(PREFIX + '/')) return next();
|
|
390
|
+
const send = (code, value) => {
|
|
391
|
+
res.statusCode = code;
|
|
392
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
393
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
394
|
+
res.end(JSON.stringify(value));
|
|
395
|
+
};
|
|
396
|
+
try {
|
|
397
|
+
const root = getDataRoot(),
|
|
398
|
+
action = url.pathname.slice(PREFIX.length),
|
|
399
|
+
method = req.method || 'GET';
|
|
400
|
+
if (!isPluginOnInSpace('cases', root)) fail('请开启用例管理', 403);
|
|
401
|
+
if (
|
|
402
|
+
method !== 'GET' &&
|
|
403
|
+
req.headers.origin &&
|
|
404
|
+
new URL(req.headers.origin).host !== req.headers.host
|
|
405
|
+
)
|
|
406
|
+
fail('请求来源不匹配', 403);
|
|
407
|
+
if (action === '/acceptance' && method === 'GET')
|
|
408
|
+
return send(
|
|
409
|
+
200,
|
|
410
|
+
await caseAcceptance(
|
|
411
|
+
root,
|
|
412
|
+
url.searchParams.get('casePath') || '',
|
|
413
|
+
url.searchParams.get('environmentKey') || '',
|
|
414
|
+
),
|
|
415
|
+
);
|
|
416
|
+
if (action !== '/link' && !isPluginOnInSpace('caseGen', root))
|
|
417
|
+
fail('请开启用例生成', 403);
|
|
418
|
+
let body = {};
|
|
419
|
+
if (method === 'POST') {
|
|
420
|
+
const chunks = [];
|
|
421
|
+
let size = 0;
|
|
422
|
+
for await (const chunk of req) {
|
|
423
|
+
size += chunk.length;
|
|
424
|
+
if (size > 10 * 1024 * 1024) fail('请求超过 10MB', 413);
|
|
425
|
+
chunks.push(chunk);
|
|
426
|
+
}
|
|
427
|
+
body = JSON.parse(Buffer.concat(chunks).toString() || '{}');
|
|
428
|
+
}
|
|
429
|
+
if (action === '/link' && method === 'POST')
|
|
430
|
+
return send(200, await linkCaseBaseline(root, body));
|
|
431
|
+
if (action === '/context')
|
|
432
|
+
return send(
|
|
433
|
+
200,
|
|
434
|
+
await caseDesignContext(
|
|
435
|
+
root,
|
|
436
|
+
method === 'GET' ? Object.fromEntries(url.searchParams) : body,
|
|
437
|
+
),
|
|
438
|
+
);
|
|
439
|
+
if (action === '/validate' && method === 'POST')
|
|
440
|
+
return send(
|
|
441
|
+
200,
|
|
442
|
+
validateCaseDesign(
|
|
443
|
+
body,
|
|
444
|
+
body.analysisId ? analysisSnapshot(root, body.analysisId) : null,
|
|
445
|
+
),
|
|
446
|
+
);
|
|
447
|
+
if (action === '/save' && method === 'POST')
|
|
448
|
+
return send(200, await saveCaseDesign(root, body));
|
|
449
|
+
return send(404, { ok: false, error: '接口不存在' });
|
|
450
|
+
} catch (error) {
|
|
451
|
+
return send(error.statusCode || 500, { ok: false, error: error.message });
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
},
|
|
455
|
+
};
|
|
456
|
+
}
|
|
@@ -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;
|