lantern-harness 0.1.45 → 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 +242 -0
- package/README.md +25 -8
- package/builtin/case-backup-contract.mjs +27 -0
- package/builtin/case-workflow-contract.mjs +158 -0
- package/builtin/session/lh-fs.mjs +93 -4
- package/builtin/session/lh-nav-groups.mjs +36 -1
- package/builtin/session/mcp-client.mjs +7 -3
- package/builtin/session/session-runs.mjs +5 -1
- package/builtin/session/skill-validation.mjs +72 -0
- package/builtin/session/space-layout.mjs +8 -1
- package/builtin/session/space-skills.mjs +758 -0
- package/cli/data-root.mjs +21 -4
- package/cli/lantern.mjs +26 -1
- package/cli/mcp-server.mjs +3733 -0
- package/cli/server.mjs +10 -2
- package/config/app.defaults.json +4 -2
- package/dist/500.html +14 -6
- package/dist/_astro/Base.BQf1tZMl.css +1 -0
- package/dist/_astro/Base.astro_astro_type_script_index_0_lang.Dm3O_y-S.js +2 -0
- package/dist/_astro/BusinessMapBoard.CYxHcku_.js +5 -0
- package/dist/_astro/CaseExecBoard.CK9aGPmH.js +1 -0
- 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/{ConfirmDialog.DrrPf1MB.js → ConfirmDialog.DQFd6g2r.js} +1 -1
- package/dist/_astro/DashboardBoard.qgc1s7pG.js +5 -0
- package/dist/_astro/{DatePicker.Bkl71M49.js → DatePicker.BRO_CjVQ.js} +1 -1
- package/dist/_astro/DefectSubmitEntry.JI85N1-i.js +2 -0
- package/dist/_astro/DocsFileBrowser.z5JZ74cy.js +1 -0
- package/dist/_astro/{DocsPager.Duf4I68E.js → DocsPager.Dg765uHW.js} +1 -1
- package/dist/_astro/{DrawerField.BH3p4Q4D.js → DrawerField.CLdvmHc6.js} +1 -1
- package/dist/_astro/KnowledgeLibrary.mkShtVun.js +1 -0
- package/dist/_astro/LifeKrTasksBoard.DpAwQffE.js +1 -0
- package/dist/_astro/LifeKrTodosBoard.BIjPiZ8H.js +1 -0
- package/dist/_astro/LifeObjectivesBoard.DYwLHPEG.js +1 -0
- package/dist/_astro/LifePlanTypeSelect.CYaziESp.js +1 -0
- package/dist/_astro/{LifeReviewsBoard.BPXeVpg1.js → LifeReviewsBoard.DIxoWBDA.js} +3 -3
- package/dist/_astro/{LifeShared.tnT7aQON.js → LifeShared.DuFQsMEx.js} +2 -2
- package/dist/_astro/LifeStagesBoard.DtOri9EW.js +1 -0
- package/dist/_astro/LifeYearCycleSelect.ByJ9-PGg.js +1 -0
- package/dist/_astro/LifeYearPlansBoard.BQN07wcv.js +1 -0
- package/dist/_astro/MultiSelectDropdown.D-rbpivp.js +1 -0
- package/dist/_astro/{NamePromptDialog.Csfnh5eM.js → NamePromptDialog.KPCeXmri.js} +1 -1
- package/dist/_astro/NavLibraries.BO4ezcUc.js +1 -0
- package/dist/_astro/PluginsPage.B1VeDtLx.js +18 -0
- package/dist/_astro/PmBugsBoard.Ddl3kqqt.js +1 -0
- package/dist/_astro/PmIterationsBoard.BJN7disI.js +1 -0
- package/dist/_astro/{PmProjectDetail.DneFVBpy.js → PmProjectDetail.D78gWhqk.js} +1 -1
- package/dist/_astro/PmProjectsBoard.Bf8VB3t6.js +1 -0
- package/dist/_astro/PmRequirementsBoard.CDyNHN2a.js +1 -0
- package/dist/_astro/PmRequirementsBoard.DarfGIrL.js +1 -0
- package/dist/_astro/PmShared.TOjBbtV8.js +1 -0
- package/dist/_astro/ReportsPage.BXGduuY3.js +1 -0
- package/dist/_astro/ReqAnalysisBoard.WLtIfBg8.js +39 -0
- package/dist/_astro/RequirementBreakdownLibrary.DMoeTeqX.js +2 -0
- package/dist/_astro/RequirementsLibrary.Iv7zOqWe.js +1 -0
- package/dist/_astro/SearchableSelect.DXclLMJI.js +1 -0
- package/dist/_astro/SelectDropdown.D7IeyHDI.js +1 -0
- package/dist/_astro/SettingsDialog.BvDU9EU6.js +1 -0
- package/dist/_astro/SlideOverDrawer.CvyB-quk.js +1 -0
- package/dist/_astro/SpaceSwitcher.D9bBNQBZ.js +7 -0
- package/dist/_astro/{TableFieldConfig.C7O-mL-p.js → TableFieldConfig.DHj25OKN.js} +1 -1
- package/dist/_astro/{TagSelect.UUXgkMqJ.js → TagSelect.B_r2p0fp.js} +1 -1
- package/dist/_astro/TasksBoard.CXmGdylV.js +1 -0
- package/dist/_astro/TemplatesLibrary.DsL2q-wp.js +1 -0
- package/dist/_astro/TestReportsLibrary.BBC1TYgP.js +1 -0
- package/dist/_astro/TestStatsBoard.VXjP4hu6.js +1 -0
- package/dist/_astro/Toast.BydY-X7T.js +1 -0
- package/dist/_astro/TodosBoard.-yKgp06M.js +1 -0
- 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.D9HCzC_7.js → bash-tools.C4DJiRJs.js} +1 -1
- package/dist/_astro/business-map.BiJ85oxm.js +1 -0
- package/dist/_astro/business-map.DKwdW1VL.css +1 -0
- 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.TdDs1WFM.js → case-review.BodP2jKm.js} +2 -2
- package/dist/_astro/{case-template.Cd2xNbgy.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-submit.Dc49lFjm.css +1 -0
- package/dist/_astro/defect-workbench.DBmohR-y.js +6 -0
- package/dist/_astro/dialog.XgRGNF_Q.js +1 -0
- package/dist/_astro/doc-roots.C-20VD0x.js +1 -0
- package/dist/_astro/{hydrate-cache.B15Nrpq0.js → hydrate-cache.CMMErx63.js} +1 -1
- package/dist/_astro/i18n.CEWjL5GX.js +7 -0
- package/dist/_astro/{llm.DN5S1KBK.js → llm.BCYNgppW.js} +1 -1
- package/dist/_astro/mcp-tools.Kf-lupGn.js +7 -0
- package/dist/_astro/{open-docs-in-session.CRiZT022.js → open-docs-in-session.BoyV6R2A.js} +1 -1
- package/dist/_astro/plugins.ChGmBEkF.js +1 -0
- package/dist/_astro/project-docs.BRgNjXhG.js +1 -0
- package/dist/_astro/prompts-meta.VAjE4OET.js +2 -0
- package/dist/_astro/report-prompt.CwHuOcRN.js +1 -0
- package/dist/_astro/req-analysis.BLvcktvQ.js +31 -0
- package/dist/_astro/requirement-breakdown-library.l0rPd7b3.js +1 -0
- package/dist/_astro/{settings.38J2uD5M.js → settings.BojKNwUC.js} +2 -2
- package/dist/_astro/space-skills.CPucW8zt.js +1 -0
- package/dist/_astro/{spaces-client.DV04tRyD.js → spaces-client.B28rzu8J.js} +1 -1
- package/dist/_astro/story-review.dEBWTeOW.js +7 -0
- package/dist/_astro/test-points.BuNgdNcU.js +8 -0
- package/dist/_astro/test-reports.0gr6-c_0.js +19 -0
- package/dist/_astro/ui-auto-prompt.BmO3ja2m.js +8 -0
- package/dist/_astro/ui-auto.LUcREUMe.js +1 -0
- package/dist/_astro/{view-prefs.DhdLZjGh.js → view-prefs.CWc5cQ2q.js} +1 -1
- package/dist/business-map/index.html +988 -0
- package/dist/case-exec/index.html +15 -7
- package/dist/{prompts → case-execution}/index.html +17 -9
- 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 +14 -6
- package/dist/cases/index.html +1 -1
- package/dist/cases/library/index.html +1 -980
- package/dist/cases/other/index.html +988 -0
- package/dist/cases/performance/index.html +988 -0
- package/dist/dashboard/index.html +15 -7
- package/dist/defect-rules/index.html +695 -0
- package/dist/defect-submit/index.html +695 -0
- package/dist/defect-submit/templates/index.html +695 -0
- package/dist/docs/changelog/index.html +289 -52
- package/dist/docs/install/index.html +50 -12
- package/dist/docs/manual/index.html +230 -82
- package/dist/knowledge/index.html +15 -7
- package/dist/life/kr-tasks/index.html +15 -7
- package/dist/life/kr-todos/index.html +15 -7
- package/dist/life/objectives/index.html +15 -7
- package/dist/life/reviews/index.html +15 -7
- package/dist/life/stages/index.html +15 -7
- package/dist/life/year-plans/index.html +15 -7
- package/dist/plugins/index.html +15 -7
- package/dist/pm/bugs/index.html +15 -7
- package/dist/pm/iterations/index.html +15 -7
- package/dist/pm/projects/detail/index.html +15 -7
- package/dist/pm/projects/index.html +15 -7
- package/dist/pm/requirements/index.html +15 -7
- package/dist/reports/index.html +15 -7
- package/dist/requirement-analysis/index.html +15 -7
- package/dist/requirement-breakdowns/index.html +988 -0
- package/dist/requirements/index.html +15 -7
- package/dist/tasks/index.html +15 -7
- package/dist/templates/index.html +15 -7
- package/dist/test-automation/index.html +15 -7
- package/dist/test-automation/projects/index.html +15 -7
- package/dist/test-reports/index.html +15 -7
- package/dist/test-stats/index.html +15 -7
- package/dist/todos/index.html +15 -7
- package/dist/workbench/index.html +14 -6
- package/docs/Codex-MCP/351/233/206/346/210/220.md +340 -0
- package/docs//344/270/232/345/212/241/345/234/260/345/233/276/350/257/204/344/274/260.md +39 -0
- package/docs//344/270/232/345/212/241/345/234/260/345/233/276/350/257/206/345/210/253/351/207/215/346/236/204/346/226/271/346/241/210.md +88 -0
- package/docs//344/274/232/350/257/235/346/217/222/344/273/266.md +28 -3
- package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +41 -1
- package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +65 -17
- package/docs//346/217/222/344/273/266/344/273/223/345/272/223/344/270/216/346/212/200/350/203/275/346/225/264/345/220/210/346/226/271/346/241/210.md +187 -0
- package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +219 -74
- package/lh-plugins/business-map/assistant.mjs +958 -0
- package/lh-plugins/business-map/auth-paths.mjs +61 -0
- package/lh-plugins/business-map/jobs.mjs +749 -0
- package/lh-plugins/business-map/login.mjs +295 -0
- package/lh-plugins/business-map/sources.mjs +1014 -0
- 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 +829 -0
- package/lh-plugins/case-execution/plans.mjs +318 -0
- package/lh-plugins/case-execution/service.mjs +1026 -0
- package/lh-plugins/case-execution-prompt.mjs +36 -0
- package/lh-plugins/lh-business-map.mjs +2431 -0
- 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 +356 -0
- package/lh-plugins/lh-case-review.mjs +29 -11
- package/lh-plugins/lh-config.mjs +13 -0
- package/lh-plugins/lh-defect-submit.mjs +989 -0
- package/lh-plugins/lh-project-docs.mjs +55 -140
- package/lh-plugins/lh-reports.mjs +29 -57
- package/lh-plugins/lh-req-analysis.mjs +32 -3
- package/lh-plugins/lh-req-breakdown-library.mjs +1084 -0
- package/lh-plugins/lh-uiauto.mjs +625 -24
- package/lh-plugins/plugin-prompts.mjs +20 -15
- package/lh-plugins/req-analysis-revision.mjs +24 -0
- package/lh-plugins/test-points-prompt.mjs +2 -3
- package/lh-plugins/uiauto-adapters/playwright.mjs +44 -4
- package/lh-plugins/uiauto-adapters/shared.mjs +4 -0
- package/lh-plugins/uiauto-auth-setup.mjs +218 -0
- package/lh-plugins/uiauto-explorer/apps.mjs +13 -2
- 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 +80 -5
- package/lh-plugins/uiauto-explorer/sessions.mjs +334 -18
- package/lh-plugins/uiauto-node.mjs +102 -11
- package/lh-plugins/uiauto-prompt.mjs +20 -15
- package/lh-plugins/uiauto-sso.mjs +407 -0
- package/package.json +5 -2
- package/skills/case-automation-bridge/SKILL.md +27 -0
- package/skills/case-execution/SKILL.md +41 -0
- package/skills/lantern-defect-submit/SKILL.md +15 -0
- package/skills/lantern-workflow/SKILL.md +95 -0
- package/skills/office/SKILL.md +26 -0
- package/dist/_astro/Base.Bkt1lrgu.css +0 -1
- package/dist/_astro/Base.astro_astro_type_script_index_0_lang.UKTVQqk7.js +0 -2
- package/dist/_astro/CaseExecBoard.DICluCbK.js +0 -1
- package/dist/_astro/CaseGenerateApp.Be3h5XPG.js +0 -10
- package/dist/_astro/CasesLibrary.Buys7Cy-.js +0 -21
- package/dist/_astro/ChatApp.D3BheKci.js +0 -227
- package/dist/_astro/DashboardBoard.Qvf8o4v1.js +0 -5
- package/dist/_astro/DocsFileBrowser.DwKBffbM.js +0 -1
- package/dist/_astro/KnowledgeLibrary.MDpMqeOd.js +0 -1
- package/dist/_astro/LifeKrTasksBoard.DsvW_S66.js +0 -1
- package/dist/_astro/LifeKrTodosBoard.D2KTqvg1.js +0 -1
- package/dist/_astro/LifeObjectivesBoard.B0cDK934.js +0 -1
- package/dist/_astro/LifePlanTypeSelect.BELDvMWU.js +0 -1
- package/dist/_astro/LifeStagesBoard.CZftLR9K.js +0 -1
- package/dist/_astro/LifeYearCycleSelect.Bw2eRbSm.js +0 -1
- package/dist/_astro/LifeYearPlansBoard.DB-RJFEl.js +0 -1
- package/dist/_astro/MultiSelectDropdown.CBC7aNOv.js +0 -1
- package/dist/_astro/NavLibraries.DdQYsZbe.js +0 -1
- package/dist/_astro/OverflowHint.CHZeFfUj.js +0 -1
- package/dist/_astro/PluginsPage.C1JnInH4.js +0 -17
- package/dist/_astro/PluginsPage.C3eEwy3K.js +0 -1
- package/dist/_astro/PmBugsBoard.CGpXUTPu.js +0 -1
- package/dist/_astro/PmIterationsBoard.BaKiFIam.js +0 -1
- package/dist/_astro/PmProjectsBoard.BxoMF9gK.js +0 -1
- package/dist/_astro/PmRequirementsBoard.-SI8VZXI.js +0 -1
- package/dist/_astro/PmRequirementsBoard.DsK6RF7Q.js +0 -1
- package/dist/_astro/PmShared.BK8kWRSV.js +0 -1
- package/dist/_astro/PromptMountDialog.mrTx3U5T.js +0 -1
- package/dist/_astro/PromptsLibrary.B_SUf47p.js +0 -1
- package/dist/_astro/ReportsPage.B9lGg1_s.js +0 -16
- package/dist/_astro/ReqAnalysisBoard.CIZKnCQH.js +0 -39
- package/dist/_astro/RequirementsLibrary.cJc-bnGQ.js +0 -1
- package/dist/_astro/SearchableSelect.SyLRS-Jj.js +0 -1
- package/dist/_astro/SelectDropdown.T3CKHaLt.js +0 -1
- package/dist/_astro/SettingsDialog.DYdtCvLc.js +0 -1
- package/dist/_astro/SpaceSwitcher.C47_S1g9.js +0 -7
- package/dist/_astro/TasksBoard.BUEg2BYk.js +0 -1
- package/dist/_astro/TemplatesLibrary.BLVIphXO.js +0 -1
- package/dist/_astro/TestReportsLibrary.DVq30Jae.js +0 -1
- package/dist/_astro/TestStatsBoard.-5BWQ6bI.js +0 -1
- package/dist/_astro/Toast.BO2NFckG.js +0 -1
- package/dist/_astro/TodosBoard.DI_lTp2e.js +0 -1
- package/dist/_astro/UiAutoBoard.ChFdgv7s.js +0 -2
- package/dist/_astro/UiAutoEnvPanel.B50q4kYb.js +0 -19
- package/dist/_astro/UiAutoGenerationDialog.CLkFAHrm.js +0 -1
- package/dist/_astro/UiAutoProjectsPage.DCsDeN5d.js +0 -3
- package/dist/_astro/app-config.DkyjuL-S.js +0 -1
- package/dist/_astro/app-version.Cy-5oZO2.js +0 -1
- package/dist/_astro/case-fields.CmePqYfh.js +0 -148
- package/dist/_astro/case-gen-run.BklG1H8k.js +0 -22
- package/dist/_astro/case-types.DlFkbZJN.js +0 -1
- package/dist/_astro/dialog.DZHZCe_T.js +0 -1
- package/dist/_astro/doc-roots.CO3IBiY6.js +0 -1
- package/dist/_astro/i18n.D_aOCHSN.js +0 -7
- package/dist/_astro/markdown-client.BS19nLL3.js +0 -62
- package/dist/_astro/plugins.BRvXWHLe.js +0 -1
- package/dist/_astro/project-docs.CCjtiFjB.js +0 -1
- package/dist/_astro/prompts-meta.BUGutlsk.js +0 -2
- package/dist/_astro/report-prompt.B9C4cv84.js +0 -1
- package/dist/_astro/req-analysis.B12_MGMQ.js +0 -31
- package/dist/_astro/story-review.D2W5tEOY.js +0 -14
- package/dist/_astro/test-reports.CuIjlEyK.js +0 -19
- package/dist/_astro/ui-auto-prompt.H9_yhau9.js +0 -9
- package/dist/_astro/ui-auto.DMv940x4.js +0 -1
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
import { spaceLocalFile } from '../../builtin/session/space-layout.mjs';
|
|
6
|
+
|
|
7
|
+
export const AUTOMATION_STATUSES = [
|
|
8
|
+
'not_configured',
|
|
9
|
+
'automatable',
|
|
10
|
+
'needs_manual',
|
|
11
|
+
'not_automatable',
|
|
12
|
+
'connected',
|
|
13
|
+
'running',
|
|
14
|
+
'passed',
|
|
15
|
+
'failed',
|
|
16
|
+
'partial',
|
|
17
|
+
'stale',
|
|
18
|
+
'not_applicable',
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const rootDir = (root) => path.join(path.resolve(root), '.lantern', 'local', 'case-automation');
|
|
22
|
+
export const linksPath = (root) => path.join(rootDir(root), 'links.json');
|
|
23
|
+
export const assessmentsDir = (root) => path.join(rootDir(root), 'assessments');
|
|
24
|
+
export const batchesDir = (root) => path.join(rootDir(root), 'runs');
|
|
25
|
+
export const projectsMapPath = (root) => spaceLocalFile(root, 'case-automation/projects.json');
|
|
26
|
+
|
|
27
|
+
function readJson(file, fallback) {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
30
|
+
} catch {
|
|
31
|
+
return fallback;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function writeJson(file, value, mode = 0o600) {
|
|
36
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
37
|
+
const tmp = `${file}.${process.pid}.${crypto.randomBytes(4).toString('hex')}.tmp`;
|
|
38
|
+
fs.writeFileSync(tmp, `${JSON.stringify(value, null, 2)}\n`, { mode });
|
|
39
|
+
fs.renameSync(tmp, file);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function readAutomationLinks(root) {
|
|
43
|
+
const data = readJson(linksPath(root), { version: 1, items: [] });
|
|
44
|
+
return Array.isArray(data?.items) ? data : { version: 1, items: [] };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function writeAutomationLinks(root, data) {
|
|
48
|
+
writeJson(linksPath(root), { version: 1, items: data.items || [] });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function upsertAutomationLinks(root, incoming) {
|
|
52
|
+
const store = readAutomationLinks(root);
|
|
53
|
+
const byId = new Map(store.items.map((item) => [item.automationCaseId, item]));
|
|
54
|
+
for (const item of incoming) {
|
|
55
|
+
const previous = byId.get(item.automationCaseId) || {};
|
|
56
|
+
byId.set(item.automationCaseId, {
|
|
57
|
+
...previous,
|
|
58
|
+
...item,
|
|
59
|
+
createdAt: previous.createdAt || item.createdAt || new Date().toISOString(),
|
|
60
|
+
updatedAt: new Date().toISOString(),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const next = { version: 1, items: [...byId.values()] };
|
|
64
|
+
writeAutomationLinks(root, next);
|
|
65
|
+
return next;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function linksForSource(root, casePath, caseId = '') {
|
|
69
|
+
return readAutomationLinks(root).items.filter(
|
|
70
|
+
(item) => item.source?.casePath === casePath && (!caseId || item.source?.caseId === caseId),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function readAssessment(root, id) {
|
|
75
|
+
if (!/^[a-z0-9-]{36}$/i.test(String(id || ''))) return null;
|
|
76
|
+
return readJson(path.join(assessmentsDir(root), `${id}.json`), null);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function writeAssessment(root, record) {
|
|
80
|
+
writeJson(path.join(assessmentsDir(root), `${record.id}.json`), record);
|
|
81
|
+
return record;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function readProjectMap(root) {
|
|
85
|
+
const data = readJson(projectsMapPath(root), { version: 1, files: {} });
|
|
86
|
+
return data && typeof data === 'object' ? data : { version: 1, files: {} };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function rememberProjectSelection(root, casePath, projectId, iteration) {
|
|
90
|
+
const data = readProjectMap(root);
|
|
91
|
+
data.files = data.files || {};
|
|
92
|
+
data.files[casePath] = { projectId, iteration, updatedAt: new Date().toISOString() };
|
|
93
|
+
writeJson(projectsMapPath(root), data);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function readBatch(root, id) {
|
|
97
|
+
if (!/^[a-z0-9-]{36}$/i.test(String(id || ''))) return null;
|
|
98
|
+
return readJson(path.join(batchesDir(root), `${id}.json`), null);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function writeBatch(root, batch) {
|
|
102
|
+
writeJson(path.join(batchesDir(root), `${batch.id}.json`), {
|
|
103
|
+
...batch,
|
|
104
|
+
updatedAt: new Date().toISOString(),
|
|
105
|
+
});
|
|
106
|
+
return batch;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function aggregate(items, assessments) {
|
|
110
|
+
const current = [...items, ...assessments];
|
|
111
|
+
if (!current.length) return { status: 'not_configured', total: 0, passed: 0, failed: 0 };
|
|
112
|
+
if (current.some((item) => item.status === 'stale')) {
|
|
113
|
+
return { status: 'stale', total: items.length, passed: 0, failed: 0 };
|
|
114
|
+
}
|
|
115
|
+
if (current.some((item) => item.status === 'running')) {
|
|
116
|
+
return {
|
|
117
|
+
status: 'running',
|
|
118
|
+
total: items.length,
|
|
119
|
+
passed: items.filter((item) => item.status === 'passed').length,
|
|
120
|
+
failed: items.filter((item) => item.status === 'failed').length,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (items.some((item) => item.status === 'failed')) {
|
|
124
|
+
return {
|
|
125
|
+
status: 'failed',
|
|
126
|
+
total: items.length,
|
|
127
|
+
passed: items.filter((item) => item.status === 'passed').length,
|
|
128
|
+
failed: items.filter((item) => item.status === 'failed').length,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (items.length && items.every((item) => item.status === 'passed')) {
|
|
132
|
+
return { status: 'passed', total: items.length, passed: items.length, failed: 0 };
|
|
133
|
+
}
|
|
134
|
+
if (items.some((item) => item.status === 'passed')) {
|
|
135
|
+
return {
|
|
136
|
+
status: 'partial',
|
|
137
|
+
total: items.length,
|
|
138
|
+
passed: items.filter((item) => item.status === 'passed').length,
|
|
139
|
+
failed: items.filter((item) => item.status === 'failed').length,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (items.length) {
|
|
143
|
+
return {
|
|
144
|
+
status: 'connected',
|
|
145
|
+
total: items.length,
|
|
146
|
+
passed: 0,
|
|
147
|
+
failed: items.filter((item) => item.status === 'failed').length,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (current.every((item) => item.status === 'not_automatable'))
|
|
151
|
+
return { status: 'not_automatable', total: 0, passed: 0, failed: 0 };
|
|
152
|
+
if (current.every((item) => item.status === 'needs_manual'))
|
|
153
|
+
return { status: 'needs_manual', total: 0, passed: 0, failed: 0 };
|
|
154
|
+
if (current.some((item) => item.status === 'automatable'))
|
|
155
|
+
return { status: 'automatable', total: 0, passed: 0, failed: 0 };
|
|
156
|
+
return { status: 'connected', total: 0, passed: 0, failed: 0 };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function automationSummaryForCase(root, casePath, caseId) {
|
|
160
|
+
const links = readAutomationLinks(root).items.filter(
|
|
161
|
+
(item) =>
|
|
162
|
+
(item.source?.casePath === casePath && item.source?.caseId === caseId) ||
|
|
163
|
+
(caseId && item.source?.caseId === caseId),
|
|
164
|
+
);
|
|
165
|
+
const store = readProjectMap(root);
|
|
166
|
+
const assessments = Array.isArray(store.assessments?.[caseId]) ? store.assessments[caseId] : [];
|
|
167
|
+
const summary = aggregate(links, assessments);
|
|
168
|
+
return {
|
|
169
|
+
...summary,
|
|
170
|
+
items: links.map((item) => ({
|
|
171
|
+
automationCaseId: item.automationCaseId,
|
|
172
|
+
title: item.title,
|
|
173
|
+
status: item.status,
|
|
174
|
+
projectId: item.projectId,
|
|
175
|
+
projectName: item.projectName || '',
|
|
176
|
+
framework: item.framework || '',
|
|
177
|
+
iteration: item.iteration || '',
|
|
178
|
+
iterationFile: item.iterationFile || '',
|
|
179
|
+
tag: item.tag || '',
|
|
180
|
+
scriptPath: item.scriptPath || '',
|
|
181
|
+
lastRunId: item.latestRunId || '',
|
|
182
|
+
reportUrl: item.reportUrl || '',
|
|
183
|
+
logUrl: item.logUrl || '',
|
|
184
|
+
error: item.staleReason || item.error || '',
|
|
185
|
+
updatedAt: item.updatedAt || '',
|
|
186
|
+
})),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function automationSummaryForFile(root, casePath) {
|
|
191
|
+
const links = readAutomationLinks(root).items.filter(
|
|
192
|
+
(item) => item.source?.casePath === casePath,
|
|
193
|
+
);
|
|
194
|
+
const data = readProjectMap(root);
|
|
195
|
+
const assessments = Object.values(data.assessments || {})
|
|
196
|
+
.flatMap((items) => (Array.isArray(items) ? items : []))
|
|
197
|
+
.filter((item) => item.sourcePath === casePath);
|
|
198
|
+
if (!links.length && !assessments.length) return null;
|
|
199
|
+
const statuses = [
|
|
200
|
+
...links.map((item) => item.status || 'connected'),
|
|
201
|
+
...assessments.map((item) => item.status || 'needs_manual'),
|
|
202
|
+
];
|
|
203
|
+
let status = 'connected';
|
|
204
|
+
if (statuses.includes('stale')) status = 'stale';
|
|
205
|
+
else if (statuses.includes('running')) status = 'running';
|
|
206
|
+
else if (statuses.includes('failed')) status = 'failed';
|
|
207
|
+
else if (statuses.includes('passed') && statuses.every((value) => value === 'passed'))
|
|
208
|
+
status = 'passed';
|
|
209
|
+
else if (statuses.includes('passed') || statuses.includes('partial')) status = 'partial';
|
|
210
|
+
else if (statuses.includes('needs_manual')) status = 'needs_manual';
|
|
211
|
+
else if (statuses.every((value) => value === 'not_automatable')) status = 'not_automatable';
|
|
212
|
+
return {
|
|
213
|
+
status,
|
|
214
|
+
total: links.length,
|
|
215
|
+
passed: links.filter((item) => item.status === 'passed').length,
|
|
216
|
+
failed: links.filter((item) => item.status === 'failed').length,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function rememberAssessments(root, sourcePath, caseId, entries) {
|
|
221
|
+
const data = readProjectMap(root);
|
|
222
|
+
data.assessments = data.assessments || {};
|
|
223
|
+
data.assessments[caseId] = entries.map((item) => ({
|
|
224
|
+
status: item.decision,
|
|
225
|
+
reason: item.reason || '',
|
|
226
|
+
sourcePath,
|
|
227
|
+
automationCaseId: item.automationCaseId || '',
|
|
228
|
+
updatedAt: new Date().toISOString(),
|
|
229
|
+
}));
|
|
230
|
+
writeJson(projectsMapPath(root), data);
|
|
231
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
function hash(buffer) {
|
|
6
|
+
return crypto.createHash('sha256').update(buffer).digest('hex');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function csvCell(value) {
|
|
10
|
+
const text = String(value ?? '');
|
|
11
|
+
return /[",\n\r]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function mdCell(value) {
|
|
15
|
+
return String(value ?? '')
|
|
16
|
+
.replaceAll('|', '|')
|
|
17
|
+
.replace(/\r?\n/g, '<br>');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function parseMarkdown(text) {
|
|
21
|
+
const lines = String(text || '')
|
|
22
|
+
.replace(/\r\n/g, '\n')
|
|
23
|
+
.split('\n');
|
|
24
|
+
const headerIndex = lines.findIndex((line) => /^\s*\|/.test(line));
|
|
25
|
+
if (headerIndex < 0) return { headers: [], rows: [] };
|
|
26
|
+
const cells = (line) =>
|
|
27
|
+
line
|
|
28
|
+
.trim()
|
|
29
|
+
.replace(/^\|/, '')
|
|
30
|
+
.replace(/\|$/, '')
|
|
31
|
+
.split('|')
|
|
32
|
+
.map((cell) => cell.replace(/<br\s*\/?>/gi, '\n').trim());
|
|
33
|
+
const headers = cells(lines[headerIndex]);
|
|
34
|
+
const rows = [];
|
|
35
|
+
for (let index = headerIndex + 1; index < lines.length; index += 1) {
|
|
36
|
+
if (!/^\s*\|/.test(lines[index])) break;
|
|
37
|
+
if (/^\s*\|?[\s:|-]+\|?\s*$/.test(lines[index])) continue;
|
|
38
|
+
const values = cells(lines[index]);
|
|
39
|
+
const row = {};
|
|
40
|
+
headers.forEach((header, column) => {
|
|
41
|
+
if (header) row[header] = values[column] ?? '';
|
|
42
|
+
});
|
|
43
|
+
if (Object.values(row).some((value) => String(value).trim())) rows.push(row);
|
|
44
|
+
}
|
|
45
|
+
return { headers, rows };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function readTable(file, ext) {
|
|
49
|
+
if (!fs.existsSync(file)) return { headers: [], rows: [] };
|
|
50
|
+
if (ext === '.md') return parseMarkdown(fs.readFileSync(file, 'utf8'));
|
|
51
|
+
const XLSX = await import('xlsx');
|
|
52
|
+
const mod = XLSX.default ?? XLSX;
|
|
53
|
+
const raw = ext === '.csv' ? fs.readFileSync(file, 'utf8') : fs.readFileSync(file);
|
|
54
|
+
const book =
|
|
55
|
+
ext === '.csv'
|
|
56
|
+
? mod.read(String(raw).replace(/^\uFEFF/, ''), { type: 'string' })
|
|
57
|
+
: mod.read(raw, { type: 'buffer' });
|
|
58
|
+
const sheet = book.Sheets[book.SheetNames[0] || ''];
|
|
59
|
+
if (!sheet) return { headers: [], rows: [] };
|
|
60
|
+
const table = mod.utils.sheet_to_json(sheet, { header: 1, defval: '', blankrows: false });
|
|
61
|
+
const headers = (table[0] || []).map((value) => String(value ?? '').trim());
|
|
62
|
+
const rows = table.slice(1).flatMap((values) => {
|
|
63
|
+
const row = {};
|
|
64
|
+
headers.forEach((header, index) => {
|
|
65
|
+
if (header) row[header] = String(values[index] ?? '').trim();
|
|
66
|
+
});
|
|
67
|
+
return Object.values(row).some((value) => value) ? [row] : [];
|
|
68
|
+
});
|
|
69
|
+
return { headers, rows };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function writeTableAtomic(file, ext, headers, rows) {
|
|
73
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
74
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
75
|
+
if (ext === '.xlsx') {
|
|
76
|
+
const XLSX = await import('xlsx');
|
|
77
|
+
const mod = XLSX.default ?? XLSX;
|
|
78
|
+
const sheet = mod.utils.json_to_sheet(rows, { header: headers });
|
|
79
|
+
const book = mod.utils.book_new();
|
|
80
|
+
mod.utils.book_append_sheet(book, sheet, '自动化用例');
|
|
81
|
+
fs.writeFileSync(temp, mod.write(book, { type: 'buffer', bookType: 'xlsx' }));
|
|
82
|
+
} else if (ext === '.csv') {
|
|
83
|
+
const lines = [
|
|
84
|
+
headers.map(csvCell).join(','),
|
|
85
|
+
...rows.map((row) => headers.map((header) => csvCell(row[header])).join(',')),
|
|
86
|
+
];
|
|
87
|
+
fs.writeFileSync(temp, `\uFEFF${lines.join('\n')}`, 'utf8');
|
|
88
|
+
} else if (ext === '.md') {
|
|
89
|
+
const lines = [
|
|
90
|
+
`| ${headers.map(mdCell).join(' | ')} |`,
|
|
91
|
+
`|${headers.map(() => '---').join('|')}|`,
|
|
92
|
+
...rows.map((row) => `| ${headers.map((header) => mdCell(row[header])).join(' | ')} |`),
|
|
93
|
+
];
|
|
94
|
+
fs.writeFileSync(temp, `${lines.join('\n')}\n`, 'utf8');
|
|
95
|
+
} else {
|
|
96
|
+
throw new Error(`不支持的自动化用例格式:${ext}`);
|
|
97
|
+
}
|
|
98
|
+
fs.renameSync(temp, file);
|
|
99
|
+
return { file, fileHash: hash(fs.readFileSync(file)) };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function fileHash(file) {
|
|
103
|
+
return fs.existsSync(file) ? hash(fs.readFileSync(file)) : '';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function backupFile(file) {
|
|
107
|
+
if (!fs.existsSync(file)) return '';
|
|
108
|
+
const ext = path.extname(file);
|
|
109
|
+
const stamp = new Date().toISOString().replace(/\D/g, '').slice(0, 14);
|
|
110
|
+
const dir = path.join(path.dirname(file), '备份列表');
|
|
111
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
112
|
+
const target = path.join(dir, `${path.basename(file, ext)}_bak_${stamp}${ext}`);
|
|
113
|
+
fs.copyFileSync(file, target);
|
|
114
|
+
return target;
|
|
115
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export const CASE_AUTOMATION_PROMPT_FILE = '功能用例转UI自动化提示词.md';
|
|
2
|
+
|
|
3
|
+
export const CASE_AUTOMATION_PROMPT_TEMPLATE = `# 功能用例转 UI 自动化
|
|
4
|
+
|
|
5
|
+
你负责把已经评审过的功能测试用例转换成可进入 UI 自动化探索阶段的自动化用例。原功能用例是业务事实来源;不要改写需求,不要虚构页面、按钮、数据或业务规则。
|
|
6
|
+
|
|
7
|
+
## 判断边界
|
|
8
|
+
|
|
9
|
+
- 只有可通过 Web/浏览器 UI 操作并在页面上观察结果的用例,才标记为 \`automatable\`。
|
|
10
|
+
- 需要人工验证码、短信、扫码、系统原生弹窗、支付确认、文件选择器或不可逆高风险操作,且无法通过已有登录态或项目配置规避时,标记为 \`needs_manual\`。
|
|
11
|
+
- 接口、抓包、Mock、数据库校验、性能压测、App 原生操作等不属于当前 UI 自动化范围,标记为 \`not_automatable\`。
|
|
12
|
+
- 数据不足、预期不可观察或步骤无法执行的,不得猜成可自动化。
|
|
13
|
+
|
|
14
|
+
## 转换要求
|
|
15
|
+
|
|
16
|
+
- 保留来源用例 ID,一个来源用例可以拆成多条独立自动化用例;每条只验证一个结果。
|
|
17
|
+
- 自动化标题写成一句清楚的业务行为。
|
|
18
|
+
- 前置条件只写账号/角色、测试数据、系统状态和依赖;不要混入操作步骤。
|
|
19
|
+
- 自动化步骤用可执行动作描述:打开页面、在“某输入框”输入、点击“某按钮”、等待可见结果、断言页面状态。
|
|
20
|
+
- 使用用户可见的菜单、按钮、输入框和字段名称;禁止生成 CSS、XPath、坐标、定位器和真实凭据。
|
|
21
|
+
- 环境相关的账号、密码、手机号使用 \${ENV_NAME} 占位。
|
|
22
|
+
- 优先级沿用来源用例 P0-P3。
|
|
23
|
+
- plan 只允许 goto / click / fill / select / press / hover / expect / expectUrl / wait;至少包含一个 expect 或 expectUrl。
|
|
24
|
+
|
|
25
|
+
只输出一个 JSON 对象:
|
|
26
|
+
{
|
|
27
|
+
"summary": "一句话",
|
|
28
|
+
"cases": [
|
|
29
|
+
{
|
|
30
|
+
"sourceCaseId": "原用例 ID",
|
|
31
|
+
"decision": "automatable | needs_manual | not_automatable",
|
|
32
|
+
"reason": "判断依据",
|
|
33
|
+
"risks": ["风险"],
|
|
34
|
+
"automationCases": [
|
|
35
|
+
{
|
|
36
|
+
"title": "自动化用例标题",
|
|
37
|
+
"precondition": "前置条件",
|
|
38
|
+
"steps": ["1. ...", "2. ..."],
|
|
39
|
+
"expected": "可观察的预期结果",
|
|
40
|
+
"priority": "P0",
|
|
41
|
+
"plan": [
|
|
42
|
+
{
|
|
43
|
+
"id": "p1",
|
|
44
|
+
"action": "goto",
|
|
45
|
+
"url": "/",
|
|
46
|
+
"target": "目标页面",
|
|
47
|
+
"value": "",
|
|
48
|
+
"note": "为什么做这一步"
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
decision 不是 automatable 时 automationCases 必须为空。`;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { resolveContentRoot } from '../../builtin/session/space-layout.mjs';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import crypto from 'node:crypto';
|
|
5
|
+
import { reqAnalysisStorePath, reqDocsDir } from '../lh-req-analysis.mjs';
|
|
6
|
+
import { analysisRevision } from '../req-analysis-revision.mjs';
|
|
7
|
+
|
|
8
|
+
const storePath = (root) => path.join(root, '.lantern', 'local', 'case-workflow', 'assets.json');
|
|
9
|
+
export const fingerprint = (value) =>
|
|
10
|
+
crypto.createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
11
|
+
export function readWorkflowAssets(root) {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(fs.readFileSync(storePath(root), 'utf8'));
|
|
14
|
+
} catch {
|
|
15
|
+
return { version: 1, artifacts: [] };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function saveWorkflowAssets(root, store) {
|
|
19
|
+
const file = storePath(root);
|
|
20
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
21
|
+
fs.writeFileSync(file + '.tmp', JSON.stringify(store, null, 2), { mode: 0o600 });
|
|
22
|
+
fs.renameSync(file + '.tmp', file);
|
|
23
|
+
}
|
|
24
|
+
export function analysisSnapshot(root, analysisId) {
|
|
25
|
+
let docs;
|
|
26
|
+
try {
|
|
27
|
+
docs = JSON.parse(fs.readFileSync(reqAnalysisStorePath(root), 'utf8')).docs || [];
|
|
28
|
+
} catch {
|
|
29
|
+
docs = [];
|
|
30
|
+
}
|
|
31
|
+
const doc = docs.find((item) => item.id === analysisId);
|
|
32
|
+
if (!doc) throw Object.assign(new Error('需求分析不存在'), { statusCode: 404 });
|
|
33
|
+
return doc;
|
|
34
|
+
}
|
|
35
|
+
export function sourceFileHash(root, sourcePath) {
|
|
36
|
+
if (!sourcePath) return '';
|
|
37
|
+
const base = path.resolve(reqDocsDir(root)),
|
|
38
|
+
abs = path.resolve(base, sourcePath);
|
|
39
|
+
if (!abs.startsWith(base + path.sep) || !fs.existsSync(abs)) return '';
|
|
40
|
+
return fingerprint(fs.readFileSync(abs).toString('base64'));
|
|
41
|
+
}
|
|
42
|
+
export function artifactStaleness(root, artifact) {
|
|
43
|
+
if (!artifact) return { stale: false, tracked: false, reasons: ['历史文件尚未关联需求基线'] };
|
|
44
|
+
const reasons = [];
|
|
45
|
+
if (artifact.analysisId) {
|
|
46
|
+
try {
|
|
47
|
+
if (
|
|
48
|
+
analysisRevision(analysisSnapshot(root, artifact.analysisId)) !== artifact.analysisRevision
|
|
49
|
+
)
|
|
50
|
+
reasons.push('需求分析已变化');
|
|
51
|
+
} catch {
|
|
52
|
+
reasons.push('来源需求分析已删除');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (
|
|
56
|
+
artifact.sourceFileHash &&
|
|
57
|
+
sourceFileHash(root, artifact.sourcePath) !== artifact.sourceFileHash
|
|
58
|
+
)
|
|
59
|
+
reasons.push('需求源文件已变化或缺失');
|
|
60
|
+
return {
|
|
61
|
+
stale: !!reasons.length,
|
|
62
|
+
tracked: !!(artifact.analysisId || artifact.sourcePath),
|
|
63
|
+
reasons,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function caseContentFingerprint(item) {
|
|
67
|
+
return fingerprint([
|
|
68
|
+
item.title,
|
|
69
|
+
item.precondition,
|
|
70
|
+
item.steps,
|
|
71
|
+
item.expected,
|
|
72
|
+
(item.fields || [])
|
|
73
|
+
.filter((field) => /需求|requirement|reqcite|reqpoint|outline/i.test(field.name))
|
|
74
|
+
.map((field) => [field.name, field.value]),
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
export function bindCaseIdentities(root, document) {
|
|
78
|
+
const store = readWorkflowAssets(root);
|
|
79
|
+
const caseDir = resolveContentRoot(root, '用例管理').abs;
|
|
80
|
+
const moved = (item) => !fs.existsSync(path.join(caseDir, item.path));
|
|
81
|
+
let artifact =
|
|
82
|
+
store.artifacts.find((item) => item.path === document.path) ||
|
|
83
|
+
store.artifacts.find(
|
|
84
|
+
(item) =>
|
|
85
|
+
moved(item) && (item.fileHash === document.fileHash || item.paths?.includes(document.path)),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
if (!artifact) {
|
|
89
|
+
artifact = {
|
|
90
|
+
id: crypto.randomUUID(),
|
|
91
|
+
baselineId: crypto.randomUUID(),
|
|
92
|
+
path: document.path,
|
|
93
|
+
paths: [],
|
|
94
|
+
fileHash: document.fileHash,
|
|
95
|
+
bindings: [],
|
|
96
|
+
};
|
|
97
|
+
store.artifacts.push(artifact);
|
|
98
|
+
}
|
|
99
|
+
if (artifact.path !== document.path) {
|
|
100
|
+
artifact.paths = [...new Set([...(artifact.paths || []), artifact.path])];
|
|
101
|
+
artifact.path = document.path;
|
|
102
|
+
}
|
|
103
|
+
artifact.baselineId ||= crypto.randomUUID();
|
|
104
|
+
const used = new Set();
|
|
105
|
+
document.cases.forEach((item) => {
|
|
106
|
+
const contentHash = caseContentFingerprint(item);
|
|
107
|
+
const noUnique = item.no && document.cases.filter((row) => row.no === item.no).length === 1;
|
|
108
|
+
let binding = artifact.bindings.find(
|
|
109
|
+
(old) => !used.has(old.id) && old.contentHash === contentHash && old.no === item.no,
|
|
110
|
+
);
|
|
111
|
+
if (!binding && noUnique)
|
|
112
|
+
binding = artifact.bindings.find((old) => !used.has(old.id) && old.no === item.no);
|
|
113
|
+
if (!binding) binding = { id: crypto.randomUUID(), no: item.no, contentHash };
|
|
114
|
+
used.add(binding.id);
|
|
115
|
+
item.id = binding.id;
|
|
116
|
+
item.contentFingerprint = contentHash;
|
|
117
|
+
binding.no = item.no;
|
|
118
|
+
binding.contentHash = contentHash;
|
|
119
|
+
if (!artifact.bindings.some((old) => old.id === binding.id)) artifact.bindings.push(binding);
|
|
120
|
+
});
|
|
121
|
+
artifact.fileHash = document.fileHash;
|
|
122
|
+
saveWorkflowAssets(root, store);
|
|
123
|
+
document.provenance = {
|
|
124
|
+
artifactId: artifact.id,
|
|
125
|
+
baselineId: artifact.baselineId,
|
|
126
|
+
sourceFileHash: artifact.sourceFileHash || '',
|
|
127
|
+
analysisId: artifact.analysisId || '',
|
|
128
|
+
analysisRevision: artifact.analysisRevision || '',
|
|
129
|
+
sourcePath: artifact.sourcePath || '',
|
|
130
|
+
...artifactStaleness(root, artifact),
|
|
131
|
+
};
|
|
132
|
+
for (const item of document.cases) {
|
|
133
|
+
const verification = artifact.verifications?.[item.id];
|
|
134
|
+
const invalid =
|
|
135
|
+
document.provenance.stale ||
|
|
136
|
+
artifact.needsReview?.includes(item.id) ||
|
|
137
|
+
(verification && verification.contentFingerprint !== item.contentFingerprint);
|
|
138
|
+
if (invalid) {
|
|
139
|
+
item.storedStatus = item.status;
|
|
140
|
+
item.status = '待验证';
|
|
141
|
+
item.resultStale = true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return document;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function linkCaseArtifact(root, document, source = {}) {
|
|
148
|
+
const store = readWorkflowAssets(root),
|
|
149
|
+
artifact = store.artifacts.find((item) => item.id === document.provenance.artifactId);
|
|
150
|
+
if (!artifact) throw new Error('用例资产未登记');
|
|
151
|
+
Object.assign(artifact, source, {
|
|
152
|
+
baselineId: crypto.randomUUID(),
|
|
153
|
+
createdAt: artifact.createdAt || new Date().toISOString(),
|
|
154
|
+
});
|
|
155
|
+
saveWorkflowAssets(root, store);
|
|
156
|
+
return artifact;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function recordManualVerification(root, document, rowIndex, environment) {
|
|
160
|
+
const item = document.cases[rowIndex];
|
|
161
|
+
const store = readWorkflowAssets(root),
|
|
162
|
+
artifact = store.artifacts.find((asset) => asset.id === document.provenance.artifactId);
|
|
163
|
+
if (!artifact || !item) return;
|
|
164
|
+
artifact.verifications ||= {};
|
|
165
|
+
artifact.verifications[item.id] = {
|
|
166
|
+
at: new Date().toISOString(),
|
|
167
|
+
source: 'manual',
|
|
168
|
+
contentFingerprint: caseContentFingerprint(item),
|
|
169
|
+
analysisRevision: artifact.analysisRevision || '',
|
|
170
|
+
baselineId: artifact.baselineId,
|
|
171
|
+
sourceFileHash: artifact.sourceFileHash || '',
|
|
172
|
+
status: item.storedStatus || item.status,
|
|
173
|
+
environment: environment || artifact.verifications[item.id]?.environment || {},
|
|
174
|
+
};
|
|
175
|
+
artifact.verificationHistory ||= [];
|
|
176
|
+
artifact.verificationHistory.push({ caseId: item.id, ...artifact.verifications[item.id] });
|
|
177
|
+
artifact.verificationHistory = artifact.verificationHistory.slice(-10000);
|
|
178
|
+
artifact.needsReview = (artifact.needsReview || []).filter((id) => id !== item.id);
|
|
179
|
+
saveWorkflowAssets(root, store);
|
|
180
|
+
}
|