lantern-harness 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +7 -7
- package/builtin/case-backup-contract.mjs +27 -0
- package/builtin/case-workflow-contract.mjs +158 -0
- package/builtin/session/lh-nav-groups.mjs +33 -1
- package/builtin/session/space-layout.mjs +8 -1
- package/builtin/session/space-skills.mjs +8 -1
- package/cli/mcp-server.mjs +1211 -72
- package/cli/server.mjs +2 -0
- package/dist/500.html +9 -4
- package/dist/_astro/Base.ANghvs5L.css +1 -0
- package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.XUV2H6ea.js → Base.astro_astro_type_script_index_0_lang.f7BIL9Qf.js} +1 -1
- package/dist/_astro/{BusinessMapBoard.mRxl2G3D.js → BusinessMapBoard.CYxHcku_.js} +1 -1
- package/dist/_astro/{CaseExecBoard.Cqkxuf5c.js → CaseExecBoard.CK9aGPmH.js} +1 -1
- package/dist/_astro/CaseExecutionBoard.p6Y23xyH.js +4 -0
- package/dist/_astro/CaseGenerateApp.D5uj5bSb.js +10 -0
- package/dist/_astro/CasesLibrary.CY1PRdzc.js +21 -0
- package/dist/_astro/ChatApp.BnV7drSC.js +1 -0
- package/dist/_astro/ChatApp.CqyrMX90.js +262 -0
- package/dist/_astro/{DashboardBoard.CAJVE2G4.js → DashboardBoard.qgc1s7pG.js} +1 -1
- package/dist/_astro/{DefectSubmitEntry.BzKXJ-zq.js → DefectSubmitEntry.JI85N1-i.js} +1 -1
- package/dist/_astro/{DocsFileBrowser.apKMbGVf.js → DocsFileBrowser.z5JZ74cy.js} +1 -1
- package/dist/_astro/{DocsPager.DMN9-Tjg.js → DocsPager.Dg765uHW.js} +1 -1
- package/dist/_astro/{KnowledgeLibrary.BcoMQeUd.js → KnowledgeLibrary.mkShtVun.js} +1 -1
- package/dist/_astro/{LifeKrTasksBoard.DJU0-QI-.js → LifeKrTasksBoard.DpAwQffE.js} +1 -1
- package/dist/_astro/{LifeKrTodosBoard.GK7KRAO3.js → LifeKrTodosBoard.BIjPiZ8H.js} +1 -1
- package/dist/_astro/{LifeObjectivesBoard.DuKa6Q3k.js → LifeObjectivesBoard.DYwLHPEG.js} +1 -1
- package/dist/_astro/{LifePlanTypeSelect.Cm2lUmnH.js → LifePlanTypeSelect.CYaziESp.js} +1 -1
- package/dist/_astro/{LifeReviewsBoard.BWOOVMtz.js → LifeReviewsBoard.DIxoWBDA.js} +1 -1
- package/dist/_astro/{LifeShared.bY2l01Ha.js → LifeShared.DuFQsMEx.js} +1 -1
- package/dist/_astro/{LifeStagesBoard.CIzxPOJB.js → LifeStagesBoard.DtOri9EW.js} +1 -1
- package/dist/_astro/{LifeYearCycleSelect.BlsyPmmI.js → LifeYearCycleSelect.ByJ9-PGg.js} +1 -1
- package/dist/_astro/{LifeYearPlansBoard.DaA9O08j.js → LifeYearPlansBoard.BQN07wcv.js} +1 -1
- package/dist/_astro/NavLibraries.BO4ezcUc.js +1 -0
- package/dist/_astro/{PluginsPage.B063QIlQ.js → PluginsPage.Cb6977dz.js} +2 -2
- package/dist/_astro/{PmBugsBoard.Cu-v0Gfd.js → PmBugsBoard.Ddl3kqqt.js} +1 -1
- package/dist/_astro/{PmIterationsBoard.CgRzkP-j.js → PmIterationsBoard.BJN7disI.js} +1 -1
- package/dist/_astro/{PmProjectDetail.DVCEh0Lm.js → PmProjectDetail.D78gWhqk.js} +1 -1
- package/dist/_astro/{PmProjectsBoard.z-bQa98r.js → PmProjectsBoard.Bf8VB3t6.js} +1 -1
- package/dist/_astro/PmRequirementsBoard.CDyNHN2a.js +1 -0
- package/dist/_astro/{PmRequirementsBoard.CyfBI0u_.js → PmRequirementsBoard.DarfGIrL.js} +1 -1
- package/dist/_astro/{PmShared.BQVzwsiz.js → PmShared.TOjBbtV8.js} +1 -1
- package/dist/_astro/{ReportsPage.najSzJeT.js → ReportsPage.BXGduuY3.js} +1 -1
- package/dist/_astro/{ReqAnalysisBoard.BQb8dHFD.js → ReqAnalysisBoard.C7V_fEh9.js} +1 -1
- package/dist/_astro/{RequirementBreakdownLibrary.Cn6OV6xt.js → RequirementBreakdownLibrary.DMoeTeqX.js} +1 -1
- package/dist/_astro/{RequirementsLibrary.CqKNFVsP.js → RequirementsLibrary.Iv7zOqWe.js} +1 -1
- package/dist/_astro/{SettingsDialog.db3BpFw0.js → SettingsDialog.CRbfEiyw.js} +1 -1
- package/dist/_astro/SlideOverDrawer.CvyB-quk.js +1 -0
- package/dist/_astro/{SpaceSwitcher.DSUVAPOi.js → SpaceSwitcher.D9bBNQBZ.js} +1 -1
- package/dist/_astro/{TableFieldConfig.72AL-8p-.js → TableFieldConfig.DHj25OKN.js} +1 -1
- package/dist/_astro/{TasksBoard.CCDhCSR7.js → TasksBoard.CXmGdylV.js} +1 -1
- package/dist/_astro/TemplatesLibrary.DsL2q-wp.js +1 -0
- package/dist/_astro/{TestReportsLibrary.fWiEyCRx.js → TestReportsLibrary.BBC1TYgP.js} +1 -1
- package/dist/_astro/{TestStatsBoard.BSUBsWSu.js → TestStatsBoard.VXjP4hu6.js} +1 -1
- package/dist/_astro/{TodosBoard.By5YdlUe.js → TodosBoard.-yKgp06M.js} +1 -1
- package/dist/_astro/UiAutoBoard.BZkPzwi8.js +3 -0
- package/dist/_astro/UiAutoEnvPanel.DrHUOlmH.js +10 -0
- package/dist/_astro/UiAutoGenerationDialog.gypq1zP9.js +12 -0
- package/dist/_astro/UiAutoProjectsPage.Dhzr09E9.js +3 -0
- package/dist/_astro/app-config.BSO5r82v.js +1 -0
- package/dist/_astro/app-version.B7nd7uBP.js +1 -0
- package/dist/_astro/{bash-tools.CS2w8LOb.js → bash-tools.C4DJiRJs.js} +1 -1
- package/dist/_astro/case-fields.C03NY3zC.js +148 -0
- package/dist/_astro/case-gen-run.DQR6uvH5.js +26 -0
- package/dist/_astro/case-prompt.ByLTgz4r.js +2 -0
- package/dist/_astro/{case-review.DFWZkoR9.js → case-review.BodP2jKm.js} +1 -1
- package/dist/_astro/{case-template.Clb7HrDB.js → case-template.CC2eXegU.js} +2 -2
- package/dist/_astro/case-types.BjF1BivA.js +1 -0
- package/dist/_astro/case-workflow-contract.BBQ9bbKL.js +1 -0
- package/dist/_astro/{defect-workbench.CjTb4FDv.js → defect-workbench.DBmohR-y.js} +1 -1
- package/dist/_astro/{hydrate-cache.O4CIma9y.js → hydrate-cache.CMMErx63.js} +1 -1
- package/dist/_astro/{i18n.Cp4so7KR.js → i18n.CEWjL5GX.js} +2 -2
- package/dist/_astro/{open-docs-in-session.BpcAcBSI.js → open-docs-in-session.BoyV6R2A.js} +1 -1
- package/dist/_astro/plugins.ChGmBEkF.js +1 -0
- package/dist/_astro/{project-docs.bB9lQ1Ki.js → project-docs.BRgNjXhG.js} +1 -1
- package/dist/_astro/{req-analysis.C_gARMrB.js → req-analysis.efWkT7Gv.js} +1 -1
- package/dist/_astro/{settings.D02wZj3w.js → settings.BojKNwUC.js} +2 -2
- package/dist/_astro/{spaces-client.BAtG6PkW.js → spaces-client.B28rzu8J.js} +1 -1
- package/dist/_astro/{story-review.DTN91Vl9.js → story-review.Dm9VcR6v.js} +1 -1
- package/dist/_astro/{test-points.C7ZgggQT.js → test-points.BSfPfq8z.js} +1 -1
- package/dist/_astro/ui-auto.LUcREUMe.js +1 -0
- package/dist/_astro/{view-prefs.COAKEQtZ.js → view-prefs.CWc5cQ2q.js} +1 -1
- package/dist/business-map/index.html +10 -5
- package/dist/case-exec/index.html +10 -5
- package/dist/case-execution/index.html +10 -5
- package/dist/cases/api/index.html +988 -0
- package/dist/cases/automation/index.html +988 -0
- package/dist/cases/functional/index.html +988 -0
- package/dist/cases/generate/index.html +10 -5
- package/dist/cases/index.html +1 -1
- package/dist/cases/library/index.html +1 -983
- package/dist/cases/other/index.html +988 -0
- package/dist/cases/performance/index.html +988 -0
- package/dist/dashboard/index.html +10 -5
- package/dist/defect-rules/index.html +10 -5
- package/dist/defect-submit/index.html +10 -5
- package/dist/defect-submit/templates/index.html +10 -5
- package/dist/docs/changelog/index.html +105 -58
- package/dist/docs/install/index.html +12 -6
- package/dist/docs/manual/index.html +62 -40
- package/dist/knowledge/index.html +10 -5
- package/dist/life/kr-tasks/index.html +10 -5
- package/dist/life/kr-todos/index.html +10 -5
- package/dist/life/objectives/index.html +10 -5
- package/dist/life/reviews/index.html +10 -5
- package/dist/life/stages/index.html +10 -5
- package/dist/life/year-plans/index.html +10 -5
- package/dist/plugins/index.html +10 -5
- package/dist/pm/bugs/index.html +10 -5
- package/dist/pm/iterations/index.html +10 -5
- package/dist/pm/projects/detail/index.html +10 -5
- package/dist/pm/projects/index.html +10 -5
- package/dist/pm/requirements/index.html +10 -5
- package/dist/reports/index.html +10 -5
- package/dist/requirement-analysis/index.html +10 -5
- package/dist/requirement-breakdowns/index.html +10 -5
- package/dist/requirements/index.html +10 -5
- package/dist/tasks/index.html +10 -5
- package/dist/templates/index.html +10 -5
- package/dist/test-automation/index.html +10 -5
- package/dist/test-automation/projects/index.html +10 -5
- package/dist/test-reports/index.html +10 -5
- package/dist/test-stats/index.html +10 -5
- package/dist/todos/index.html +10 -5
- package/dist/workbench/index.html +10 -5
- package/docs/Codex-MCP/351/233/206/346/210/220.md +117 -53
- package/docs//344/274/232/350/257/235/346/217/222/344/273/266.md +14 -1
- package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +5 -1
- package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +4 -2
- package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +45 -36
- package/lh-plugins/case-automation/service.mjs +927 -0
- package/lh-plugins/case-automation/store.mjs +231 -0
- package/lh-plugins/case-automation/tables.mjs +115 -0
- package/lh-plugins/case-automation-prompt.mjs +57 -0
- package/lh-plugins/case-execution/assets.mjs +180 -0
- package/lh-plugins/case-execution/files.mjs +123 -23
- package/lh-plugins/case-execution/plans.mjs +318 -0
- package/lh-plugins/case-execution/service.mjs +80 -13
- package/lh-plugins/case-execution-prompt.mjs +4 -1
- package/lh-plugins/lh-case-automation.mjs +169 -0
- package/lh-plugins/lh-case-design.mjs +456 -0
- package/lh-plugins/lh-case-execution.mjs +53 -1
- package/lh-plugins/lh-case-review.mjs +29 -11
- package/lh-plugins/lh-project-docs.mjs +24 -0
- package/lh-plugins/lh-stats.mjs +65 -4
- package/lh-plugins/lh-uiauto.mjs +111 -2
- package/lh-plugins/plugin-prompts.mjs +1 -0
- package/lh-plugins/uiauto-adapters/playwright.mjs +44 -4
- package/lh-plugins/uiauto-adapters/shared.mjs +4 -0
- package/lh-plugins/uiauto-explorer/emit-files.mjs +16 -2
- package/lh-plugins/uiauto-explorer/ir.mjs +3 -0
- package/lh-plugins/uiauto-explorer/merge.mjs +37 -1
- package/lh-plugins/uiauto-explorer/navigation-guard.mjs +255 -0
- package/lh-plugins/uiauto-explorer/runner.mjs +65 -3
- package/lh-plugins/uiauto-explorer/sessions.mjs +29 -1
- package/package.json +1 -1
- package/skills/case-automation-bridge/SKILL.md +27 -0
- package/skills/case-execution/SKILL.md +19 -2
- package/skills/lantern-workflow/SKILL.md +39 -1
- package/dist/_astro/Base.Du_-4L-4.css +0 -1
- package/dist/_astro/CaseExecutionBoard.CjX4CoKd.js +0 -5
- package/dist/_astro/CaseGenerateApp.acgnxl79.js +0 -10
- package/dist/_astro/CasesLibrary.zmzOQwdn.js +0 -21
- package/dist/_astro/ChatApp.Ben9LFra.js +0 -1
- package/dist/_astro/ChatApp.DBi6q7Qv.js +0 -262
- package/dist/_astro/NavLibraries.DVR5Ua-S.js +0 -1
- package/dist/_astro/PmRequirementsBoard.B0W6bsW2.js +0 -1
- package/dist/_astro/SlideOverDrawer.BMg2tce6.js +0 -1
- package/dist/_astro/TemplatesLibrary.peYzrHZ2.js +0 -1
- package/dist/_astro/UiAutoBoard.BGdlp5Sr.js +0 -3
- package/dist/_astro/UiAutoEnvPanel.BUASgPLB.js +0 -10
- package/dist/_astro/UiAutoGenerationDialog.D1PyCgrD.js +0 -12
- package/dist/_astro/UiAutoProjectsPage.B6A9NlVK.js +0 -3
- package/dist/_astro/app-config.Dvfzl5_N.js +0 -1
- package/dist/_astro/app-version.CNpnKIb9.js +0 -1
- package/dist/_astro/case-fields.CmePqYfh.js +0 -148
- package/dist/_astro/case-gen-run.Cvvdv_kv.js +0 -26
- package/dist/_astro/case-prompt.CZ3vWUju.js +0 -2
- package/dist/_astro/plugins.Db9xoFZb.js +0 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { caseContentFingerprint, recordManualVerification } from './assets.mjs';
|
|
2
|
+
import { assertTargetUrl, assessExecutionEvidence } from '../../builtin/case-workflow-contract.mjs';
|
|
1
3
|
import crypto from 'node:crypto';
|
|
2
4
|
import fs from 'node:fs';
|
|
3
5
|
import path from 'node:path';
|
|
@@ -194,7 +196,7 @@ function listRuns(root, casePath = '') {
|
|
|
194
196
|
.filter((run) => !casePath || run.casePath === casePath)
|
|
195
197
|
.sort((left, right) => String(right.createdAt).localeCompare(String(left.createdAt)))
|
|
196
198
|
.slice(0, 200)
|
|
197
|
-
.map(publicRun);
|
|
199
|
+
.map((run) => publicRun(loadRun(root, run.id)));
|
|
198
200
|
}
|
|
199
201
|
|
|
200
202
|
function shotsDir(root, runId) {
|
|
@@ -442,7 +444,11 @@ async function callModel(settings, messages, signal) {
|
|
|
442
444
|
async function executeTool(root, run, name, args) {
|
|
443
445
|
if (name === 'case_browser_open') {
|
|
444
446
|
const result = await callExplorer(run.id, 'open', {
|
|
445
|
-
url:
|
|
447
|
+
url: assertTargetUrl(
|
|
448
|
+
str(args.url, 2000) || run.target.url,
|
|
449
|
+
run.target.url,
|
|
450
|
+
run.target.allowedOrigins || [],
|
|
451
|
+
),
|
|
446
452
|
settle: 450,
|
|
447
453
|
});
|
|
448
454
|
return {
|
|
@@ -536,7 +542,7 @@ async function executeRun(root, run, skill, settings, signal) {
|
|
|
536
542
|
saveRun(root, run);
|
|
537
543
|
appendEvent(run, { type: 'status', title: '开始执行', detail: run.case.title }, root);
|
|
538
544
|
fs.mkdirSync(caseExecutionRoot(root), { recursive: true });
|
|
539
|
-
if (
|
|
545
|
+
if (run.target.authPath && !fs.existsSync(run.target.authPath)) {
|
|
540
546
|
throw new Error('目标登录态不存在,请先填写登录态文件或完成手动登录');
|
|
541
547
|
}
|
|
542
548
|
await startExplorer({
|
|
@@ -546,6 +552,7 @@ async function executeRun(root, run, skill, settings, signal) {
|
|
|
546
552
|
baseURL: run.target.url,
|
|
547
553
|
headed: true,
|
|
548
554
|
storageState: run.target.authPath,
|
|
555
|
+
allowedOrigins: [new URL(run.target.url).origin, ...(run.target.allowedOrigins || [])],
|
|
549
556
|
});
|
|
550
557
|
fs.mkdirSync(shotsDir(root, run.id), { recursive: true });
|
|
551
558
|
const messages = modelMessages(skill, run);
|
|
@@ -638,6 +645,24 @@ async function executeRun(root, run, skill, settings, signal) {
|
|
|
638
645
|
);
|
|
639
646
|
try {
|
|
640
647
|
const output = await executeTool(root, run, name, args);
|
|
648
|
+
if (output.snapshot) {
|
|
649
|
+
const snapshot = String(output.snapshot)
|
|
650
|
+
.replace(/(Bearer\s+)[A-Za-z0-9._~+\/=-]+/gi, '$1[已隐藏]')
|
|
651
|
+
.replace(
|
|
652
|
+
/((?:password|token|api[_-]?key|authorization)\s*[:=]\s*)[^\s,;]+/gi,
|
|
653
|
+
'$1[已隐藏]',
|
|
654
|
+
);
|
|
655
|
+
appendEvent(
|
|
656
|
+
run,
|
|
657
|
+
{
|
|
658
|
+
type: 'observation',
|
|
659
|
+
title: '页面观察证据',
|
|
660
|
+
url: output.url || '',
|
|
661
|
+
detail: clip(snapshot, 12000),
|
|
662
|
+
},
|
|
663
|
+
root,
|
|
664
|
+
);
|
|
665
|
+
}
|
|
641
666
|
messages.push({
|
|
642
667
|
role: 'tool',
|
|
643
668
|
tool_call_id: str(call?.id, 200),
|
|
@@ -679,6 +704,12 @@ async function executeRun(root, run, skill, settings, signal) {
|
|
|
679
704
|
if (!run.result && !result.actualResult) {
|
|
680
705
|
result.actualResult = result.blocker || result.rationale || '未完成用例执行';
|
|
681
706
|
}
|
|
707
|
+
run.evidenceAssessment = assessExecutionEvidence(result, run.events);
|
|
708
|
+
if (result.status === '通过' && !run.evidenceAssessment.sufficient) {
|
|
709
|
+
result.status = '阻塞';
|
|
710
|
+
result.blocker = '证据不足:' + run.evidenceAssessment.issues.join(';');
|
|
711
|
+
result.unverified = [...new Set([...result.unverified, ...run.evidenceAssessment.issues])];
|
|
712
|
+
}
|
|
682
713
|
run.result = result;
|
|
683
714
|
run.status = 'awaiting_confirmation';
|
|
684
715
|
run.progress.label = '执行完成,等待确认';
|
|
@@ -741,15 +772,13 @@ export function startRun(root, raw) {
|
|
|
741
772
|
const rowIndex = Number(raw.rowIndex);
|
|
742
773
|
const url = targetUrl(raw.url || raw.targetUrl);
|
|
743
774
|
const authPath = str(raw.storageStatePath, 2000) || savedAuthPath(root, url) || '';
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
}
|
|
747
|
-
const authAbs = path.resolve(authPath);
|
|
748
|
-
if (!fs.existsSync(authAbs) || !fs.statSync(authAbs).isFile()) {
|
|
775
|
+
const authAbs = authPath ? path.resolve(authPath) : '';
|
|
776
|
+
if (authAbs && (!fs.existsSync(authAbs) || !fs.statSync(authAbs).isFile()))
|
|
749
777
|
throw Object.assign(new Error('登录态文件不存在'), { statusCode: 400 });
|
|
750
|
-
}
|
|
751
778
|
return (async () => {
|
|
752
779
|
const document = await loadCaseDocument(root, casePath);
|
|
780
|
+
if (ACTIVE.size)
|
|
781
|
+
throw Object.assign(new Error('已有用例正在执行,请等待结束'), { statusCode: 409 });
|
|
753
782
|
if (!document.executable) {
|
|
754
783
|
throw Object.assign(new Error(document.executionIssue), {
|
|
755
784
|
statusCode: 422,
|
|
@@ -767,6 +796,22 @@ export function startRun(root, raw) {
|
|
|
767
796
|
target: url,
|
|
768
797
|
authPath: authAbs,
|
|
769
798
|
});
|
|
799
|
+
run.target.allowedOrigins = (Array.isArray(raw.allowedOrigins) ? raw.allowedOrigins : [])
|
|
800
|
+
.slice(0, 20)
|
|
801
|
+
.map((value) => new URL(targetUrl(value)).origin);
|
|
802
|
+
run.environment = {
|
|
803
|
+
name: str(raw.environment?.name, 100),
|
|
804
|
+
role: str(raw.environment?.role, 100),
|
|
805
|
+
build: str(raw.environment?.build, 200),
|
|
806
|
+
dataNote: str(raw.environment?.dataNote, 2000),
|
|
807
|
+
};
|
|
808
|
+
run.caseId = caseData.id;
|
|
809
|
+
run.caseFingerprint = caseContentFingerprint(caseData);
|
|
810
|
+
run.provenance = document.provenance;
|
|
811
|
+
if (document.provenance?.stale)
|
|
812
|
+
throw Object.assign(new Error('需求基线已变化,请重新生成或重新关联用例后执行'), {
|
|
813
|
+
statusCode: 409,
|
|
814
|
+
});
|
|
770
815
|
const settings = resolveModelForSpace(root);
|
|
771
816
|
if (!settings.baseURL || !settings.apiKey || !settings.model) {
|
|
772
817
|
throw Object.assign(new Error('请先在模型设置中配置可用模型'), { statusCode: 400 });
|
|
@@ -815,21 +860,43 @@ export async function confirmRun(root, runId, raw) {
|
|
|
815
860
|
if (!actualResult) {
|
|
816
861
|
throw Object.assign(new Error('实际结果不能为空'), { statusCode: 400 });
|
|
817
862
|
}
|
|
863
|
+
const currentDocument = await loadCaseDocument(root, run.casePath);
|
|
864
|
+
const currentCase = run.caseId
|
|
865
|
+
? currentDocument.cases.find((item) => item.id === run.caseId)
|
|
866
|
+
: currentDocument.cases[run.rowIndex];
|
|
867
|
+
if (
|
|
868
|
+
!currentCase ||
|
|
869
|
+
(run.caseFingerprint && caseContentFingerprint(currentCase) !== run.caseFingerprint) ||
|
|
870
|
+
currentDocument.provenance?.stale ||
|
|
871
|
+
(run.provenance?.baselineId &&
|
|
872
|
+
currentDocument.provenance?.baselineId !== run.provenance.baselineId)
|
|
873
|
+
) {
|
|
874
|
+
throw Object.assign(new Error('用例内容或需求基线已变化,请重新执行;历史结果保留'), {
|
|
875
|
+
statusCode: 409,
|
|
876
|
+
});
|
|
877
|
+
}
|
|
818
878
|
const applied = await applyCaseExecutionResult(root, {
|
|
819
879
|
path: run.casePath,
|
|
820
|
-
expectedFileHash: run.fileHash,
|
|
821
|
-
rowIndex:
|
|
880
|
+
expectedFileHash: raw.expectedFileHash || run.fileHash,
|
|
881
|
+
rowIndex: currentCase.rowIndex,
|
|
822
882
|
status,
|
|
823
883
|
actualResult,
|
|
824
|
-
executor: str(raw.executor, 200) || '
|
|
884
|
+
executor: str(raw.executor, 200) || '人工验证',
|
|
825
885
|
executedAt: now().replace('T', ' ').slice(0, 19),
|
|
826
886
|
evidence: run.events
|
|
827
887
|
.filter((event) => event.type === 'screenshot')
|
|
828
888
|
.map((event) => event.url)
|
|
829
889
|
.slice(-8)
|
|
830
890
|
.join('\n'),
|
|
831
|
-
defectNo: str(raw.defectNo, 200),
|
|
891
|
+
defectNo: raw.defectNo === undefined ? currentCase.defectNo : str(raw.defectNo, 200),
|
|
832
892
|
});
|
|
893
|
+
recordManualVerification(
|
|
894
|
+
root,
|
|
895
|
+
await loadCaseDocument(root, run.casePath),
|
|
896
|
+
currentCase.rowIndex,
|
|
897
|
+
run.environment,
|
|
898
|
+
);
|
|
899
|
+
run.fileHash = applied.fileHash;
|
|
833
900
|
run.status = 'confirmed';
|
|
834
901
|
run.confirmed = {
|
|
835
902
|
status,
|
|
@@ -13,7 +13,10 @@ export const CASE_EXECUTION_PROMPT_TEMPLATE = `# 用例执行
|
|
|
13
13
|
5. 用例缺少可执行步骤、预期不可判定或存在歧义时判定“阻塞”,并说明缺少什么。
|
|
14
14
|
6. 对关键结果、失败位置和阻塞位置保留截图;同时检查控制台错误和失败网络请求。
|
|
15
15
|
7. 用例要求的文件上传、系统原生弹窗、支付、短信验证码或不可逆高风险动作无法通过浏览器工具完成时,返回“阻塞”。
|
|
16
|
-
8.
|
|
16
|
+
8. 不直接修改用例文件、不创建缺陷、不更新统计。只提交执行结论,保留为待验证建议。由用户核对证据后手动选择最终执行状态;不得自动写入通过或伪称人工确认。
|
|
17
|
+
|
|
18
|
+
9. 访问地址必须在本次授权的目标 origin 或明确允许的登录 origin 中。脚本跳转、弹窗和 301 / 302 / 303 / 307 / 308 的每一跳都受此限制;导航被拦截时立即返回“阻塞”,说明目标地址,不得继续猜测页面内容。
|
|
19
|
+
10. 每个步骤必须包含实际观察及证据,存在未验证步骤或证据不足时不得建议通过。
|
|
17
20
|
|
|
18
21
|
## 输出要求
|
|
19
22
|
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { getDataRoot } from '../builtin/session/space-context.mjs';
|
|
2
|
+
import {
|
|
3
|
+
CASE_AUTOMATION_PROMPT_FILE,
|
|
4
|
+
CASE_AUTOMATION_PROMPT_TEMPLATE,
|
|
5
|
+
} from './case-automation-prompt.mjs';
|
|
6
|
+
import {
|
|
7
|
+
assessCases,
|
|
8
|
+
applyAssessment,
|
|
9
|
+
getBatch,
|
|
10
|
+
listIterations,
|
|
11
|
+
projectSelection,
|
|
12
|
+
refreshAutomationFile,
|
|
13
|
+
startBatch,
|
|
14
|
+
sourceDocument,
|
|
15
|
+
statuses,
|
|
16
|
+
stopBatch,
|
|
17
|
+
} from './case-automation/service.mjs';
|
|
18
|
+
import { ensurePluginPrompt, isPluginOnInSpace } from './plugin-prompts.mjs';
|
|
19
|
+
import { automationSummaryForFile } from './case-automation/store.mjs';
|
|
20
|
+
|
|
21
|
+
const PREFIX = '/__tb_case_automation';
|
|
22
|
+
|
|
23
|
+
function sendJson(res, status, body) {
|
|
24
|
+
res.statusCode = status;
|
|
25
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
26
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
27
|
+
res.end(JSON.stringify(body));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function readBody(req) {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const chunks = [];
|
|
33
|
+
let size = 0;
|
|
34
|
+
req.on('data', (chunk) => {
|
|
35
|
+
size += chunk.length;
|
|
36
|
+
if (size > 2 * 1024 * 1024) {
|
|
37
|
+
reject(Object.assign(new Error('请求内容过大'), { statusCode: 413 }));
|
|
38
|
+
req.destroy();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
chunks.push(Buffer.from(chunk));
|
|
42
|
+
});
|
|
43
|
+
req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
|
44
|
+
req.on('error', reject);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function sameOrigin(req) {
|
|
49
|
+
if (!req.headers.origin) return true;
|
|
50
|
+
try {
|
|
51
|
+
return new URL(req.headers.origin).host === req.headers.host;
|
|
52
|
+
} catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function lhCaseAutomationPlugin() {
|
|
58
|
+
return {
|
|
59
|
+
name: 'lh-case-automation',
|
|
60
|
+
configureServer(server) {
|
|
61
|
+
server.middlewares.use(async (req, res, next) => {
|
|
62
|
+
const parsed = new URL(req.url || '/', 'http://127.0.0.1');
|
|
63
|
+
if (!parsed.pathname.startsWith(PREFIX)) return next();
|
|
64
|
+
const tail = parsed.pathname.slice(PREFIX.length) || '/';
|
|
65
|
+
const method = req.method || 'GET';
|
|
66
|
+
try {
|
|
67
|
+
const root = getDataRoot();
|
|
68
|
+
const enabled = isPluginOnInSpace('cases', root) && isPluginOnInSpace('uiAuto', root);
|
|
69
|
+
if (parsed.pathname === `${PREFIX}/health`)
|
|
70
|
+
return sendJson(res, 200, {
|
|
71
|
+
ok: true,
|
|
72
|
+
enabled,
|
|
73
|
+
cases: isPluginOnInSpace('cases', root),
|
|
74
|
+
uiAuto: isPluginOnInSpace('uiAuto', root),
|
|
75
|
+
});
|
|
76
|
+
if (!enabled) {
|
|
77
|
+
return sendJson(res, 403, {
|
|
78
|
+
ok: false,
|
|
79
|
+
error: '功能用例转 UI 自动化需要开启「用例管理」和「自动化测试」',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (method !== 'GET' && !sameOrigin(req)) {
|
|
83
|
+
return sendJson(res, 403, {
|
|
84
|
+
ok: false,
|
|
85
|
+
error: '请求必须来自当前 Lantern 页面',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
ensurePluginPrompt(CASE_AUTOMATION_PROMPT_FILE, CASE_AUTOMATION_PROMPT_TEMPLATE, root);
|
|
89
|
+
if (method === 'GET' && tail === '/iterations') {
|
|
90
|
+
return sendJson(
|
|
91
|
+
res,
|
|
92
|
+
200,
|
|
93
|
+
listIterations(
|
|
94
|
+
root,
|
|
95
|
+
parsed.searchParams.get('projectId') || '',
|
|
96
|
+
parsed.searchParams.get('casePath') || '',
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
if (method === 'GET' && tail === '/cases') {
|
|
101
|
+
return sendJson(res, 200, {
|
|
102
|
+
ok: true,
|
|
103
|
+
document: await sourceDocument(root, parsed.searchParams.get('path') || ''),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (method === 'GET' && tail === '/selection') {
|
|
107
|
+
return sendJson(res, 200, {
|
|
108
|
+
ok: true,
|
|
109
|
+
selection: projectSelection(root, parsed.searchParams.get('casePath') || ''),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (method === 'GET' && tail === '/status') {
|
|
113
|
+
return sendJson(res, 200, {
|
|
114
|
+
ok: true,
|
|
115
|
+
statuses: await statuses(root, parsed.searchParams.get('casePath') || ''),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (method === 'GET' && tail.startsWith('/runs/')) {
|
|
119
|
+
const id = tail.split('/')[2] || '';
|
|
120
|
+
return sendJson(res, 200, { ok: true, batch: getBatch(root, id) });
|
|
121
|
+
}
|
|
122
|
+
if (method === 'POST' && tail === '/assess') {
|
|
123
|
+
return sendJson(
|
|
124
|
+
res,
|
|
125
|
+
200,
|
|
126
|
+
await assessCases(root, JSON.parse((await readBody(req)) || '{}')),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
if (method === 'POST' && tail === '/summaries') {
|
|
130
|
+
const body = JSON.parse((await readBody(req)) || '{}');
|
|
131
|
+
const paths = Array.isArray(body.paths) ? body.paths.map(String) : [];
|
|
132
|
+
await Promise.all(paths.map((casePath) => refreshAutomationFile(root, casePath)));
|
|
133
|
+
return sendJson(res, 200, {
|
|
134
|
+
ok: true,
|
|
135
|
+
summaries: Object.fromEntries(
|
|
136
|
+
paths.map((casePath) => [casePath, automationSummaryForFile(root, casePath)]),
|
|
137
|
+
),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (method === 'POST' && tail === '/apply') {
|
|
141
|
+
return sendJson(
|
|
142
|
+
res,
|
|
143
|
+
200,
|
|
144
|
+
await applyAssessment(root, JSON.parse((await readBody(req)) || '{}')),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
if (method === 'POST' && tail === '/runs') {
|
|
148
|
+
return sendJson(res, 200, {
|
|
149
|
+
ok: true,
|
|
150
|
+
batch: startBatch(root, JSON.parse((await readBody(req)) || '{}')),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (method === 'POST' && tail.endsWith('/stop') && tail.startsWith('/runs/')) {
|
|
154
|
+
return sendJson(res, 200, {
|
|
155
|
+
ok: true,
|
|
156
|
+
batch: stopBatch(root, tail.split('/')[2] || ''),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return sendJson(res, 404, { ok: false, error: '接口不存在' });
|
|
160
|
+
} catch (error) {
|
|
161
|
+
return sendJson(res, error.statusCode || 500, {
|
|
162
|
+
ok: false,
|
|
163
|
+
error: error instanceof Error ? error.message : String(error),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|