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,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
|
+
}
|