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
|
@@ -13,6 +13,11 @@ import fs from 'node:fs';
|
|
|
13
13
|
import path from 'node:path';
|
|
14
14
|
import crypto from 'node:crypto';
|
|
15
15
|
|
|
16
|
+
import {
|
|
17
|
+
migratedPromptPath,
|
|
18
|
+
migrateSpaceSkills,
|
|
19
|
+
touchMigratedSkill,
|
|
20
|
+
} from '../builtin/session/space-skills.mjs';
|
|
16
21
|
import { getDataRoot } from '../builtin/session/space-context.mjs';
|
|
17
22
|
import { resolveContentRoot, spaceLocalFile } from '../builtin/session/space-layout.mjs';
|
|
18
23
|
|
|
@@ -59,10 +64,13 @@ export const PLUGIN_PROMPT_FILES = Object.freeze({
|
|
|
59
64
|
'自动化项目提示词.md': 'uiAuto',
|
|
60
65
|
'需求分析提示词.md': 'reqAnalysis',
|
|
61
66
|
'原文结构提示词.md': 'reqAnalysis',
|
|
67
|
+
'业务地图识别提示词.md': 'businessMap',
|
|
62
68
|
'用户故事审查提示词.md': 'storyReview',
|
|
63
69
|
'测试点生成提示词.md': 'testPoints',
|
|
64
70
|
'用例质量评审提示词.md': 'caseReview',
|
|
65
71
|
'场景遗漏补全提示词.md': 'caseBlindspot',
|
|
72
|
+
'用例执行提示词.md': 'caseExecution',
|
|
73
|
+
'功能用例转UI自动化提示词.md': 'uiAuto',
|
|
66
74
|
'功能测试报告提示词.md': 'testReports',
|
|
67
75
|
'接口测试报告提示词.md': 'testReports',
|
|
68
76
|
'性能测试报告提示词.md': 'testReports',
|
|
@@ -97,6 +105,7 @@ export const STORY_REVIEW_PROMPT_FILE = '用户故事审查提示词.md';
|
|
|
97
105
|
export const TEST_POINTS_PROMPT_FILE = '测试点生成提示词.md';
|
|
98
106
|
export const CASE_REVIEW_PROMPT_FILE = '用例质量评审提示词.md';
|
|
99
107
|
export const BLINDSPOT_PROMPT_FILE = '场景遗漏补全提示词.md';
|
|
108
|
+
export const CASE_EXECUTION_PROMPT_FILE = '用例执行提示词.md';
|
|
100
109
|
|
|
101
110
|
/** 当前空间的提示词目录(可能被归进分组文件夹) */
|
|
102
111
|
export function promptsDir(spaceDir = getDataRoot()) {
|
|
@@ -105,7 +114,7 @@ export function promptsDir(spaceDir = getDataRoot()) {
|
|
|
105
114
|
|
|
106
115
|
/** 空间里某份插件提示词的绝对路径 */
|
|
107
116
|
export function pluginPromptPath(name, spaceDir = getDataRoot()) {
|
|
108
|
-
return path.join(promptsDir(spaceDir), name);
|
|
117
|
+
return migratedPromptPath(spaceDir, name) || path.join(promptsDir(spaceDir), name);
|
|
109
118
|
}
|
|
110
119
|
|
|
111
120
|
/** 读插件提示词正文;不存在返回空串 */
|
|
@@ -139,6 +148,13 @@ export function migrateLegacyPluginPrompts(spaceDir = getDataRoot()) {
|
|
|
139
148
|
if (!fs.existsSync(src) || fs.existsSync(dest)) continue;
|
|
140
149
|
try {
|
|
141
150
|
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
151
|
+
const canonical = migratedPromptPath(spaceDir, from);
|
|
152
|
+
if (canonical) {
|
|
153
|
+
fs.copyFileSync(canonical, dest);
|
|
154
|
+
migrateSpaceSkills(spaceDir);
|
|
155
|
+
moved.push({ from, to });
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
142
158
|
fs.renameSync(src, dest);
|
|
143
159
|
const state = readSeedState(spaceDir);
|
|
144
160
|
if (state[from]) {
|
|
@@ -173,6 +189,7 @@ export function ensurePluginPrompt(name, template, spaceDir = getDataRoot()) {
|
|
|
173
189
|
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
174
190
|
fs.writeFileSync(dest, rendered, 'utf8');
|
|
175
191
|
writeSeedState(spaceDir, { ...state, [name]: renderedHash });
|
|
192
|
+
migrateSpaceSkills(spaceDir);
|
|
176
193
|
return { created: true, updated: false, exists: true, file: name };
|
|
177
194
|
} catch {
|
|
178
195
|
return { created: false, updated: false, exists: false, file: name };
|
|
@@ -203,6 +220,7 @@ export function ensurePluginPrompt(name, template, spaceDir = getDataRoot()) {
|
|
|
203
220
|
try {
|
|
204
221
|
fs.writeFileSync(dest, rendered, 'utf8');
|
|
205
222
|
writeSeedState(spaceDir, { ...state, [name]: renderedHash });
|
|
223
|
+
touchMigratedSkill(spaceDir, name);
|
|
206
224
|
return { created: false, updated: true, exists: true, file: name };
|
|
207
225
|
} catch {
|
|
208
226
|
return { created: false, updated: false, exists: true, file: name };
|
|
@@ -223,6 +241,7 @@ export function resetPluginPrompt(name, template, spaceDir = getDataRoot()) {
|
|
|
223
241
|
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
224
242
|
fs.writeFileSync(dest, rendered, 'utf8');
|
|
225
243
|
writeSeedState(spaceDir, { ...readSeedState(spaceDir), [name]: digest(rendered) });
|
|
244
|
+
touchMigratedSkill(spaceDir, name);
|
|
226
245
|
return { ok: true, file: name };
|
|
227
246
|
} catch {
|
|
228
247
|
return { ok: false, file: name };
|
|
@@ -259,17 +278,3 @@ export function isPluginOnInSpace(pluginId, spaceDir = getDataRoot()) {
|
|
|
259
278
|
const local = readJsonOr(spaceLocalFile(spaceDir, 'app.config.json'), {})?.plugins ?? {};
|
|
260
279
|
return (local[pluginId] ?? defaults[pluginId]) === true;
|
|
261
280
|
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* 这份提示词当前是否被某个「开启中」的插件锁定(不可删除 / 改名)。
|
|
265
|
-
* @returns {string} 锁定原因;未锁定时为空串
|
|
266
|
-
*/
|
|
267
|
-
export function pluginPromptLock(name, spaceDir = getDataRoot()) {
|
|
268
|
-
const base = String(name ?? '')
|
|
269
|
-
.split('/')
|
|
270
|
-
.pop();
|
|
271
|
-
const owner = PLUGIN_PROMPT_FILES[base];
|
|
272
|
-
if (!owner) return '';
|
|
273
|
-
if (!isPluginOnInSpace(owner, spaceDir)) return '';
|
|
274
|
-
return '插件开启中,这份提示词由插件引用;先在「我的插件」里关闭对应插件再删除';
|
|
275
|
-
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
function stableValue(value) {
|
|
4
|
+
if (Array.isArray(value)) return value.map(stableValue);
|
|
5
|
+
if (!value || typeof value !== 'object') return value;
|
|
6
|
+
const out = {};
|
|
7
|
+
for (const key of Object.keys(value).sort()) {
|
|
8
|
+
if (key === 'updatedAt' || key === 'revision') continue;
|
|
9
|
+
out[key] = stableValue(value[key]);
|
|
10
|
+
}
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 需求分析内容指纹:忽略顶层 updatedAt,用于 Codex / 页面并发写入保护。
|
|
16
|
+
* 同一份内容无论对象键顺序如何都得到同一 revision。
|
|
17
|
+
*/
|
|
18
|
+
export function analysisRevision(doc) {
|
|
19
|
+
if (!doc || typeof doc !== 'object') return '';
|
|
20
|
+
return crypto
|
|
21
|
+
.createHash('sha256')
|
|
22
|
+
.update(JSON.stringify(stableValue(doc)), 'utf8')
|
|
23
|
+
.digest('hex');
|
|
24
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 「生成测试点」的提示词文件:种子正文 + 分段解析。
|
|
3
3
|
*
|
|
4
4
|
* 文件放在当前空间的「提示词管理/测试点生成提示词.md」,由插件开关联动:
|
|
5
|
-
*
|
|
5
|
+
* 打开插件时缺就补种子(没人改过时会跟着内置模板升级)。
|
|
6
6
|
* 每次生成前读一次,改完提示词不用重启服务。
|
|
7
7
|
*
|
|
8
8
|
* 文件用一级标题分一段:
|
|
@@ -19,8 +19,7 @@ export const GENERATE_SECTION = '生成';
|
|
|
19
19
|
|
|
20
20
|
export const TEST_POINTS_PROMPT_TEMPLATE = `# 测试点生成提示词
|
|
21
21
|
|
|
22
|
-
>
|
|
23
|
-
> 插件开启期间不能删除本文件;关闭插件后可以删掉,再次打开会重新生成。
|
|
22
|
+
> 由「生成测试点」插件关联。
|
|
24
23
|
> 本文件不使用占位符:分析标题、需求条目与用户故事由运行时以「## 分析标题」「## 需求条目」「## 用户故事」三个小节拼在用户消息里。
|
|
25
24
|
|
|
26
25
|
## 生成
|
|
@@ -118,23 +118,62 @@ export function parsePlaywrightReport(raw) {
|
|
|
118
118
|
.slice(0, 20)
|
|
119
119
|
: [];
|
|
120
120
|
const failedTests = [];
|
|
121
|
+
const tests = [];
|
|
121
122
|
const walk = (suite, trail) => {
|
|
122
123
|
if (!suite || typeof suite !== 'object') return;
|
|
123
124
|
const file = text(suite.file, 1024);
|
|
124
125
|
const own = text(suite.title, 500);
|
|
125
126
|
const nextTrail = own ? [...trail, own] : trail;
|
|
126
127
|
for (const spec of Array.isArray(suite.specs) ? suite.specs : []) {
|
|
127
|
-
const
|
|
128
|
-
const
|
|
128
|
+
const specTests = Array.isArray(spec?.tests) ? spec.tests : [];
|
|
129
|
+
const title = [...nextTrail, text(spec?.title, 500)].filter(Boolean).join(' › ');
|
|
130
|
+
const specAnnotations = Array.isArray(spec?.annotations) ? spec.annotations : [];
|
|
131
|
+
const tags = Array.isArray(spec?.tags) ? spec.tags.map((tag) => text(tag, 100)) : [];
|
|
132
|
+
for (const test of specTests.length ? specTests : [{}]) {
|
|
133
|
+
const annotations = [
|
|
134
|
+
...specAnnotations,
|
|
135
|
+
...(Array.isArray(test?.annotations) ? test.annotations : []),
|
|
136
|
+
]
|
|
137
|
+
.map((item) => ({
|
|
138
|
+
type: text(item?.type, 200),
|
|
139
|
+
description: text(item?.description, 2000),
|
|
140
|
+
}))
|
|
141
|
+
.filter((item) => item.type);
|
|
142
|
+
const results = Array.isArray(test?.results) ? test.results : [];
|
|
143
|
+
const status = text(test?.status, 40) || (results[0] ? text(results[0].status, 40) : '');
|
|
144
|
+
const errors = results
|
|
145
|
+
.flatMap((result) => (Array.isArray(result?.errors) ? result.errors : []))
|
|
146
|
+
.map((item) => text(item?.message || item?.stack, 2000))
|
|
147
|
+
.filter(Boolean)
|
|
148
|
+
.slice(0, 20);
|
|
149
|
+
const durationMs = results.reduce(
|
|
150
|
+
(sum, result) => sum + intOr(result?.duration, 0, 0, Number.MAX_SAFE_INTEGER),
|
|
151
|
+
0,
|
|
152
|
+
);
|
|
153
|
+
const automation = annotations.find((item) => item.type === 'com.lantern.automationCaseId');
|
|
154
|
+
tests.push({
|
|
155
|
+
title,
|
|
156
|
+
file,
|
|
157
|
+
line: intOr(spec?.line, 0, 0, Number.MAX_SAFE_INTEGER),
|
|
158
|
+
tags,
|
|
159
|
+
annotations,
|
|
160
|
+
automationCaseId: automation?.description || '',
|
|
161
|
+
status,
|
|
162
|
+
durationMs,
|
|
163
|
+
errors,
|
|
164
|
+
});
|
|
165
|
+
if (tests.length >= 5000) break;
|
|
166
|
+
}
|
|
167
|
+
const unmatched = specTests.some(
|
|
129
168
|
(t) =>
|
|
130
169
|
t?.status === 'unexpected' ||
|
|
131
170
|
t?.status === 'timedOut' ||
|
|
132
171
|
(Array.isArray(t?.results) &&
|
|
133
172
|
t.results.some((r) => r?.status === 'unexpected' || r?.status === 'timedOut')),
|
|
134
173
|
);
|
|
135
|
-
if (!
|
|
174
|
+
if (!unmatched) continue;
|
|
136
175
|
failedTests.push({
|
|
137
|
-
title
|
|
176
|
+
title,
|
|
138
177
|
file,
|
|
139
178
|
});
|
|
140
179
|
if (failedTests.length >= 50) return;
|
|
@@ -151,6 +190,7 @@ export function parsePlaywrightReport(raw) {
|
|
|
151
190
|
durationMs: intOr(stats.duration, 0, 0, Number.MAX_SAFE_INTEGER),
|
|
152
191
|
errors,
|
|
153
192
|
failedTests,
|
|
193
|
+
tests,
|
|
154
194
|
projectNames,
|
|
155
195
|
};
|
|
156
196
|
}
|
|
@@ -261,6 +261,7 @@ export function emptySummary() {
|
|
|
261
261
|
durationMs: 0,
|
|
262
262
|
errors: [],
|
|
263
263
|
failedTests: [],
|
|
264
|
+
tests: [],
|
|
264
265
|
projectNames: [],
|
|
265
266
|
};
|
|
266
267
|
}
|
|
@@ -329,6 +330,9 @@ export function mergeSummaries(list) {
|
|
|
329
330
|
for (const failed of item.failedTests ?? []) {
|
|
330
331
|
if (out.failedTests.length < 50) out.failedTests.push(failed);
|
|
331
332
|
}
|
|
333
|
+
for (const test of item.tests ?? []) {
|
|
334
|
+
if (out.tests.length < 5000) out.tests.push(test);
|
|
335
|
+
}
|
|
332
336
|
for (const name of item.projectNames ?? []) {
|
|
333
337
|
if (!out.projectNames.includes(name)) out.projectNames.push(name);
|
|
334
338
|
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 项目内 auth.setup / Playwright setup 工程:探测 + 无头跑一遍产出 storageState。
|
|
3
|
+
* 登录墙自动链在 SSO 不可用或失败时回落走这里;不扫任意业务 *login*.spec。
|
|
4
|
+
*
|
|
5
|
+
* 跑 setup 时会把项目 .env 注入子进程,并把 LOGIN_API_URL 等别名回填为
|
|
6
|
+
* LOGIN_API_PATH,避免项目里的 tryApiLogin 只认 PATH 而空跑。
|
|
7
|
+
*/
|
|
8
|
+
import { spawn } from 'node:child_process';
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
|
|
12
|
+
import { resolvePackageManager } from './uiauto-pm.mjs';
|
|
13
|
+
import { withProjectNode } from './uiauto-node.mjs';
|
|
14
|
+
import { detectStorageState, findPlaywrightConfig } from './uiauto-explorer/sessions.mjs';
|
|
15
|
+
import { readProjectEnvMap, resolveLoginApiEndpoint } from './uiauto-sso.mjs';
|
|
16
|
+
|
|
17
|
+
const AUTH_SETUP_FILES = [
|
|
18
|
+
'tests/auth.setup.ts',
|
|
19
|
+
'tests/auth.setup.js',
|
|
20
|
+
'auth.setup.ts',
|
|
21
|
+
'auth.setup.js',
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const SETUP_TIMEOUT_MS = 120_000;
|
|
25
|
+
|
|
26
|
+
function readText(file) {
|
|
27
|
+
try {
|
|
28
|
+
return fs.readFileSync(file, 'utf8');
|
|
29
|
+
} catch {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function existsFile(root, rel) {
|
|
35
|
+
try {
|
|
36
|
+
return fs.statSync(path.join(root, rel)).isFile();
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** playwright.config 里是否声明了 name: 'setup' / "setup" 的 project */
|
|
43
|
+
export function playwrightHasSetupProject(dir) {
|
|
44
|
+
const root = String(dir || '');
|
|
45
|
+
if (!root) return false;
|
|
46
|
+
const configName = findPlaywrightConfig(root);
|
|
47
|
+
if (!configName) return false;
|
|
48
|
+
const content = readText(path.join(root, configName));
|
|
49
|
+
if (!content) return false;
|
|
50
|
+
// name: 'setup' | name: "setup" | name: `setup`
|
|
51
|
+
return /\bname\s*:\s*(['"`])setup\1/.test(content);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 命中的 auth.setup 相对路径;没有则空串 */
|
|
55
|
+
export function findAuthSetupFile(dir) {
|
|
56
|
+
const root = String(dir || '');
|
|
57
|
+
if (!root) return '';
|
|
58
|
+
for (const rel of AUTH_SETUP_FILES) {
|
|
59
|
+
if (existsFile(root, rel)) return rel.replace(/\\/g, '/');
|
|
60
|
+
}
|
|
61
|
+
// 挂载项目常见 tests/auth-unit.setup.ts、tests/xxx.auth.setup.ts
|
|
62
|
+
try {
|
|
63
|
+
const names = fs.readdirSync(path.join(root, 'tests'));
|
|
64
|
+
const hit = names
|
|
65
|
+
.filter((name) => /\.setup\.(ts|js|mjs|cjs)$/i.test(name) && /auth/i.test(name))
|
|
66
|
+
.sort();
|
|
67
|
+
if (hit.length) return path.posix.join('tests', hit[0]);
|
|
68
|
+
} catch {
|
|
69
|
+
// no tests/
|
|
70
|
+
}
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 项目是否具备可跑的登录态 setup(文件或 setup 工程)。
|
|
76
|
+
*/
|
|
77
|
+
export function projectHasAuthSetup(dir) {
|
|
78
|
+
const root = String(dir || '');
|
|
79
|
+
if (!root || !fs.existsSync(root)) return false;
|
|
80
|
+
return Boolean(findAuthSetupFile(root) || playwrightHasSetupProject(root));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 决定怎么调 Playwright:优先 --project=setup,否则跑 auth.setup 文件。
|
|
85
|
+
* @returns {{ mode: 'project'|'file', target: string, command: string } | null}
|
|
86
|
+
*/
|
|
87
|
+
export function resolveAuthSetupCommand(dir) {
|
|
88
|
+
const root = String(dir || '');
|
|
89
|
+
if (!root) return null;
|
|
90
|
+
const { commands } = resolvePackageManager({ dir: root });
|
|
91
|
+
const hasProject = playwrightHasSetupProject(root);
|
|
92
|
+
const file = findAuthSetupFile(root);
|
|
93
|
+
if (hasProject) {
|
|
94
|
+
return {
|
|
95
|
+
mode: 'project',
|
|
96
|
+
target: 'setup',
|
|
97
|
+
command: commands.exec('playwright', ['test', '--project=setup']),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if (file) {
|
|
101
|
+
return {
|
|
102
|
+
mode: 'file',
|
|
103
|
+
target: file,
|
|
104
|
+
command: commands.exec('playwright', ['test', file]),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function runShell(command, cwd, env, timeoutMs) {
|
|
111
|
+
return new Promise((resolve) => {
|
|
112
|
+
let output = '';
|
|
113
|
+
let done = false;
|
|
114
|
+
const finish = (code, extra = '') => {
|
|
115
|
+
if (done) return;
|
|
116
|
+
done = true;
|
|
117
|
+
resolve({ code, output: `${output}${extra}`.slice(-20_000) });
|
|
118
|
+
};
|
|
119
|
+
let child;
|
|
120
|
+
try {
|
|
121
|
+
child = spawn(command, {
|
|
122
|
+
cwd,
|
|
123
|
+
shell: true,
|
|
124
|
+
env: { ...env, FORCE_COLOR: '0', CI: '1' },
|
|
125
|
+
});
|
|
126
|
+
} catch (error) {
|
|
127
|
+
finish(
|
|
128
|
+
-1,
|
|
129
|
+
`\n[lantern] 启动失败:${error instanceof Error ? error.message : String(error)}\n`,
|
|
130
|
+
);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const push = (chunk) => {
|
|
134
|
+
output += String(chunk);
|
|
135
|
+
if (output.length > 40_000) output = output.slice(-20_000);
|
|
136
|
+
};
|
|
137
|
+
child.stdout?.setEncoding('utf8');
|
|
138
|
+
child.stderr?.setEncoding('utf8');
|
|
139
|
+
child.stdout?.on('data', push);
|
|
140
|
+
child.stderr?.on('data', push);
|
|
141
|
+
const timer = setTimeout(() => {
|
|
142
|
+
try {
|
|
143
|
+
child.kill('SIGTERM');
|
|
144
|
+
} catch {
|
|
145
|
+
// ignore
|
|
146
|
+
}
|
|
147
|
+
finish(-1, `\n[lantern] auth.setup 超过 ${Math.round(timeoutMs / 1000)} 秒,已终止。\n`);
|
|
148
|
+
}, timeoutMs);
|
|
149
|
+
timer.unref?.();
|
|
150
|
+
child.on('error', (error) => {
|
|
151
|
+
clearTimeout(timer);
|
|
152
|
+
finish(-1, `\n[lantern] ${error instanceof Error ? error.message : String(error)}\n`);
|
|
153
|
+
});
|
|
154
|
+
child.on('close', (code) => {
|
|
155
|
+
clearTimeout(timer);
|
|
156
|
+
finish(typeof code === 'number' ? code : -1);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 无头跑 auth.setup,成功后探测 storageState。
|
|
163
|
+
* @returns {{ ok: true, storageState: string, command: string, output: string } | { ok: false, error: string, output?: string }}
|
|
164
|
+
*/
|
|
165
|
+
export async function runAuthSetupAndSave({ dir, envName = '' }) {
|
|
166
|
+
const root = String(dir || '');
|
|
167
|
+
if (!root || !fs.existsSync(root)) {
|
|
168
|
+
return { ok: false, error: '项目目录不存在' };
|
|
169
|
+
}
|
|
170
|
+
const plan = resolveAuthSetupCommand(root);
|
|
171
|
+
if (!plan) {
|
|
172
|
+
return { ok: false, error: '未检测到 auth.setup 文件或 Playwright setup 工程' };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const projectEnv = readProjectEnvMap(root, envName);
|
|
176
|
+
const endpoint = resolveLoginApiEndpoint(projectEnv);
|
|
177
|
+
// 项目代码多半只读 LOGIN_API_PATH:把 URL 等别名回填进去
|
|
178
|
+
const aliasPath =
|
|
179
|
+
endpoint.value && !String(projectEnv.LOGIN_API_PATH || '').trim()
|
|
180
|
+
? { LOGIN_API_PATH: endpoint.value }
|
|
181
|
+
: {};
|
|
182
|
+
const env = withProjectNode(
|
|
183
|
+
{
|
|
184
|
+
...process.env,
|
|
185
|
+
...projectEnv,
|
|
186
|
+
...aliasPath,
|
|
187
|
+
...(envName ? { ENV: String(envName) } : {}),
|
|
188
|
+
CI: '1',
|
|
189
|
+
},
|
|
190
|
+
root,
|
|
191
|
+
);
|
|
192
|
+
const { code, output } = await runShell(plan.command, root, env, SETUP_TIMEOUT_MS);
|
|
193
|
+
if (code !== 0) {
|
|
194
|
+
const tail = String(output || '')
|
|
195
|
+
.trim()
|
|
196
|
+
.slice(-500);
|
|
197
|
+
return {
|
|
198
|
+
ok: false,
|
|
199
|
+
error: `auth.setup 未成功(exit ${code})${tail ? `:${tail}` : ''}`,
|
|
200
|
+
output,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const storageState = detectStorageState(root);
|
|
205
|
+
if (!storageState) {
|
|
206
|
+
const text = String(output || '');
|
|
207
|
+
const skipped = /\bskipped\b|\b跳过\b|未配置.*账号/i.test(text);
|
|
208
|
+
const hint = skipped
|
|
209
|
+
? '用例可能被 skip(检查 ADMIN_USERNAME / ADMIN_PASSWORD)。'
|
|
210
|
+
: '若 setup 走 UI 登录且有验证码,无头跑会写不出登录态。';
|
|
211
|
+
return {
|
|
212
|
+
ok: false,
|
|
213
|
+
error: `auth.setup 已执行(${plan.command}),但项目里仍未找到 .auth / storageState 文件。${hint}`,
|
|
214
|
+
output,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
return { ok: true, storageState, command: plan.command, output };
|
|
218
|
+
}
|
|
@@ -306,12 +306,23 @@ export async function openWith({ abs, dir, app, line }) {
|
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
// editor:CLI 优先(能带行号),否则交给 open -a
|
|
309
|
+
// 有项目目录时先带上 dir,避免只开单个草稿文件、看起来像「孤立文件」
|
|
309
310
|
if (cli) {
|
|
310
|
-
const
|
|
311
|
-
|
|
311
|
+
const fileArg = abs && line ? `${abs}:${line}` : abs || '';
|
|
312
|
+
if (dir && fileArg && path.resolve(fileArg.split(':')[0]) !== path.resolve(dir)) {
|
|
313
|
+
await execFileAsync(cli, [dir, '-g', fileArg], { timeout: 10000 });
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
await execFileAsync(cli, ['-g', fileArg || dir], { timeout: 10000 });
|
|
312
317
|
return;
|
|
313
318
|
}
|
|
314
319
|
if (process.platform === 'darwin' && appPath) {
|
|
320
|
+
if (dir && abs && path.resolve(abs) !== path.resolve(dir)) {
|
|
321
|
+
// 先开项目目录进工作区,再定位到文件
|
|
322
|
+
await execFileAsync('open', ['-a', appPath, dir], { timeout: 10000 });
|
|
323
|
+
await execFileAsync('open', ['-a', appPath, abs], { timeout: 10000 });
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
315
326
|
await execFileAsync('open', ['-a', appPath, abs || dir], { timeout: 10000 });
|
|
316
327
|
return;
|
|
317
328
|
}
|
|
@@ -202,6 +202,8 @@ export function renderTsPage(page) {
|
|
|
202
202
|
/** TS spec:导航留在用例里,元素操作调 page object */
|
|
203
203
|
export function renderTsSpec(ir, pages, options = {}) {
|
|
204
204
|
const title = ir.title || 'AI 生成用例';
|
|
205
|
+
const automationCaseId = String(ir.automationCaseId || '').replace(/[^A-Za-z0-9_-]/g, '');
|
|
206
|
+
const automationTag = automationCaseId ? `@lantern-${automationCaseId.toLowerCase()}` : '';
|
|
205
207
|
const lines = [];
|
|
206
208
|
lines.push('/**');
|
|
207
209
|
lines.push(` * ${title}`);
|
|
@@ -211,7 +213,7 @@ export function renderTsSpec(ir, pages, options = {}) {
|
|
|
211
213
|
}
|
|
212
214
|
}
|
|
213
215
|
lines.push(' */');
|
|
214
|
-
lines.push(
|
|
216
|
+
lines.push(`import { test, expect } from '${options.testImport || '@playwright/test'}';`);
|
|
215
217
|
// 页面对象可能在根级 pages/(企业级骨架)或 tests/pages/(老布局),import 按实际相对位置算
|
|
216
218
|
const pagesImport = options.pagesImport || './pages';
|
|
217
219
|
for (const page of pages) {
|
|
@@ -232,10 +234,20 @@ export function renderTsSpec(ir, pages, options = {}) {
|
|
|
232
234
|
lines.push('');
|
|
233
235
|
}
|
|
234
236
|
|
|
237
|
+
if (automationCaseId) lines.push(`/* lantern-automation:start ${automationCaseId} */`);
|
|
235
238
|
lines.push(`test.describe(${q(title)}, () => {`);
|
|
239
|
+
const tags = [
|
|
240
|
+
normalizeTag(ir.tag) || normalizeTag(options.tag) || DEFAULT_TEST_TAG,
|
|
241
|
+
...(automationTag ? [automationTag] : []),
|
|
242
|
+
];
|
|
236
243
|
lines.push(
|
|
237
|
-
` test(${q(title)}, { tag: [${
|
|
244
|
+
` test(${q(title)}, { tag: [${tags.map((tag) => q(tag)).join(', ')}] }, async ({ page }, testInfo) => {`,
|
|
238
245
|
);
|
|
246
|
+
if (automationCaseId) {
|
|
247
|
+
lines.push(
|
|
248
|
+
` testInfo.annotations.push({ type: 'com.lantern.automationCaseId', description: ${q(automationCaseId)} });`,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
239
251
|
if (ir.baseURL) lines.push(` // baseURL: ${ir.baseURL}`);
|
|
240
252
|
for (const page of pages) {
|
|
241
253
|
lines.push(` const ${varName(page.name)} = new ${page.name}(page);`);
|
|
@@ -281,6 +293,7 @@ export function renderTsSpec(ir, pages, options = {}) {
|
|
|
281
293
|
}
|
|
282
294
|
lines.push(' });');
|
|
283
295
|
lines.push('});');
|
|
296
|
+
if (automationCaseId) lines.push(`/* lantern-automation:end ${automationCaseId} */`);
|
|
284
297
|
lines.push('');
|
|
285
298
|
return lines.join('\n');
|
|
286
299
|
}
|
|
@@ -488,6 +501,7 @@ export function emitFiles(rawIr, target, options = {}) {
|
|
|
488
501
|
fixtureImport,
|
|
489
502
|
pagesImport: relativeImport(testDir, pagesDir),
|
|
490
503
|
tag: options.tag,
|
|
504
|
+
testImport: options.testImport,
|
|
491
505
|
}),
|
|
492
506
|
language: 'ts',
|
|
493
507
|
role: 'spec',
|
|
@@ -71,6 +71,9 @@ export function normalizeIr(raw, fallback = {}) {
|
|
|
71
71
|
target: (source.target ?? fallback.target) === 'python' ? 'python' : 'ts',
|
|
72
72
|
baseURL: String(source.baseURL ?? fallback.baseURL ?? ''),
|
|
73
73
|
storageState: String(source.storageState ?? fallback.storageState ?? ''),
|
|
74
|
+
automationCaseId: String(source.automationCaseId ?? fallback.automationCaseId ?? '')
|
|
75
|
+
.replace(/[^A-Za-z0-9_-]/g, '')
|
|
76
|
+
.slice(0, 80),
|
|
74
77
|
// 分级标签:为空表示用缺省级别(出码时补 @regression)
|
|
75
78
|
tag: normalizeTag(source.tag ?? fallback.tag),
|
|
76
79
|
source: String(source.source ?? fallback.source ?? '').slice(0, 2000),
|
|
@@ -114,6 +114,42 @@ export function mergeSpec(existing, incoming, lang) {
|
|
|
114
114
|
return { content, unchanged: false };
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* 合并带 automationCaseId 边界的 TS 测试块。
|
|
119
|
+
* 同一自动化用例重新生成时只替换自己的块,保留 iteration 文件里的其它测试。
|
|
120
|
+
*/
|
|
121
|
+
export function mergeAutomationSpecBlock(existing, incoming, lang = 'ts') {
|
|
122
|
+
if (lang !== 'ts') return mergeSpec(existing, incoming, lang);
|
|
123
|
+
const id = /\/\* lantern-automation:start ([A-Za-z0-9_-]+) \*\//.exec(incoming)?.[1] || '';
|
|
124
|
+
if (!id) return mergeSpec(existing, incoming, lang);
|
|
125
|
+
const start = `/* lantern-automation:start ${id} */`;
|
|
126
|
+
const end = `/* lantern-automation:end ${id} */`;
|
|
127
|
+
const incStart = incoming.indexOf(start);
|
|
128
|
+
const incEnd = incoming.indexOf(end, incStart);
|
|
129
|
+
if (incStart < 0 || incEnd < 0) return null;
|
|
130
|
+
const incomingBlock = incoming.slice(incStart, incEnd + end.length);
|
|
131
|
+
const oldStart = existing.indexOf(start);
|
|
132
|
+
if (oldStart < 0) return mergeSpec(existing, incoming, lang);
|
|
133
|
+
if (existing.indexOf(start, oldStart + 1) >= 0 || existing.indexOf(end, oldStart) < 0)
|
|
134
|
+
return null;
|
|
135
|
+
const oldEnd = existing.indexOf(end, oldStart);
|
|
136
|
+
const next = existing.slice(0, oldStart) + incomingBlock + existing.slice(oldEnd + end.length);
|
|
137
|
+
const incLines = incoming.split('\n');
|
|
138
|
+
const [, incLastImport] = importRange(incLines, lang);
|
|
139
|
+
const existingSet = new Set(next.split('\n').map((line) => line.trim()));
|
|
140
|
+
const missing = [];
|
|
141
|
+
for (let index = 0; index <= incLastImport; index += 1) {
|
|
142
|
+
const line = incLines[index];
|
|
143
|
+
if (!isImportLine(line, lang)) continue;
|
|
144
|
+
const trimmed = line.trim();
|
|
145
|
+
if (!existingSet.has(trimmed)) missing.push(trimmed);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
content: insertImports(next, missing, lang),
|
|
149
|
+
unchanged: next === existing && !missing.length,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
117
153
|
/** TS page object 里的方法块(2 空格缩进,按大括号配平取方法体) */
|
|
118
154
|
function tsMethods(text) {
|
|
119
155
|
const lines = text.split('\n');
|
|
@@ -227,7 +263,7 @@ export function mergeGeneratedFile(existing, incoming, options = {}) {
|
|
|
227
263
|
if (before.trim() === after.trim()) return { content: before, unchanged: true };
|
|
228
264
|
|
|
229
265
|
const lang = guessLang(after, filePath);
|
|
230
|
-
if (role === 'spec') return
|
|
266
|
+
if (role === 'spec') return mergeAutomationSpecBlock(before, after, lang);
|
|
231
267
|
if (role === 'page')
|
|
232
268
|
return lang === 'python' ? mergePyPage(before, after) : mergeTsPage(before, after);
|
|
233
269
|
if (role === 'fixture') return mergeFixture(before, after);
|