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.
Files changed (179) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +7 -7
  3. package/builtin/case-backup-contract.mjs +27 -0
  4. package/builtin/case-workflow-contract.mjs +158 -0
  5. package/builtin/session/lh-nav-groups.mjs +33 -1
  6. package/builtin/session/space-layout.mjs +8 -1
  7. package/builtin/session/space-skills.mjs +8 -1
  8. package/cli/mcp-server.mjs +1211 -72
  9. package/cli/server.mjs +2 -0
  10. package/dist/500.html +9 -4
  11. package/dist/_astro/Base.ANghvs5L.css +1 -0
  12. 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
  13. package/dist/_astro/{BusinessMapBoard.mRxl2G3D.js → BusinessMapBoard.CYxHcku_.js} +1 -1
  14. package/dist/_astro/{CaseExecBoard.Cqkxuf5c.js → CaseExecBoard.CK9aGPmH.js} +1 -1
  15. package/dist/_astro/CaseExecutionBoard.p6Y23xyH.js +4 -0
  16. package/dist/_astro/CaseGenerateApp.D5uj5bSb.js +10 -0
  17. package/dist/_astro/CasesLibrary.CY1PRdzc.js +21 -0
  18. package/dist/_astro/ChatApp.BnV7drSC.js +1 -0
  19. package/dist/_astro/ChatApp.CqyrMX90.js +262 -0
  20. package/dist/_astro/{DashboardBoard.CAJVE2G4.js → DashboardBoard.qgc1s7pG.js} +1 -1
  21. package/dist/_astro/{DefectSubmitEntry.BzKXJ-zq.js → DefectSubmitEntry.JI85N1-i.js} +1 -1
  22. package/dist/_astro/{DocsFileBrowser.apKMbGVf.js → DocsFileBrowser.z5JZ74cy.js} +1 -1
  23. package/dist/_astro/{DocsPager.DMN9-Tjg.js → DocsPager.Dg765uHW.js} +1 -1
  24. package/dist/_astro/{KnowledgeLibrary.BcoMQeUd.js → KnowledgeLibrary.mkShtVun.js} +1 -1
  25. package/dist/_astro/{LifeKrTasksBoard.DJU0-QI-.js → LifeKrTasksBoard.DpAwQffE.js} +1 -1
  26. package/dist/_astro/{LifeKrTodosBoard.GK7KRAO3.js → LifeKrTodosBoard.BIjPiZ8H.js} +1 -1
  27. package/dist/_astro/{LifeObjectivesBoard.DuKa6Q3k.js → LifeObjectivesBoard.DYwLHPEG.js} +1 -1
  28. package/dist/_astro/{LifePlanTypeSelect.Cm2lUmnH.js → LifePlanTypeSelect.CYaziESp.js} +1 -1
  29. package/dist/_astro/{LifeReviewsBoard.BWOOVMtz.js → LifeReviewsBoard.DIxoWBDA.js} +1 -1
  30. package/dist/_astro/{LifeShared.bY2l01Ha.js → LifeShared.DuFQsMEx.js} +1 -1
  31. package/dist/_astro/{LifeStagesBoard.CIzxPOJB.js → LifeStagesBoard.DtOri9EW.js} +1 -1
  32. package/dist/_astro/{LifeYearCycleSelect.BlsyPmmI.js → LifeYearCycleSelect.ByJ9-PGg.js} +1 -1
  33. package/dist/_astro/{LifeYearPlansBoard.DaA9O08j.js → LifeYearPlansBoard.BQN07wcv.js} +1 -1
  34. package/dist/_astro/NavLibraries.BO4ezcUc.js +1 -0
  35. package/dist/_astro/{PluginsPage.B063QIlQ.js → PluginsPage.Cb6977dz.js} +2 -2
  36. package/dist/_astro/{PmBugsBoard.Cu-v0Gfd.js → PmBugsBoard.Ddl3kqqt.js} +1 -1
  37. package/dist/_astro/{PmIterationsBoard.CgRzkP-j.js → PmIterationsBoard.BJN7disI.js} +1 -1
  38. package/dist/_astro/{PmProjectDetail.DVCEh0Lm.js → PmProjectDetail.D78gWhqk.js} +1 -1
  39. package/dist/_astro/{PmProjectsBoard.z-bQa98r.js → PmProjectsBoard.Bf8VB3t6.js} +1 -1
  40. package/dist/_astro/PmRequirementsBoard.CDyNHN2a.js +1 -0
  41. package/dist/_astro/{PmRequirementsBoard.CyfBI0u_.js → PmRequirementsBoard.DarfGIrL.js} +1 -1
  42. package/dist/_astro/{PmShared.BQVzwsiz.js → PmShared.TOjBbtV8.js} +1 -1
  43. package/dist/_astro/{ReportsPage.najSzJeT.js → ReportsPage.BXGduuY3.js} +1 -1
  44. package/dist/_astro/{ReqAnalysisBoard.BQb8dHFD.js → ReqAnalysisBoard.C7V_fEh9.js} +1 -1
  45. package/dist/_astro/{RequirementBreakdownLibrary.Cn6OV6xt.js → RequirementBreakdownLibrary.DMoeTeqX.js} +1 -1
  46. package/dist/_astro/{RequirementsLibrary.CqKNFVsP.js → RequirementsLibrary.Iv7zOqWe.js} +1 -1
  47. package/dist/_astro/{SettingsDialog.db3BpFw0.js → SettingsDialog.CRbfEiyw.js} +1 -1
  48. package/dist/_astro/SlideOverDrawer.CvyB-quk.js +1 -0
  49. package/dist/_astro/{SpaceSwitcher.DSUVAPOi.js → SpaceSwitcher.D9bBNQBZ.js} +1 -1
  50. package/dist/_astro/{TableFieldConfig.72AL-8p-.js → TableFieldConfig.DHj25OKN.js} +1 -1
  51. package/dist/_astro/{TasksBoard.CCDhCSR7.js → TasksBoard.CXmGdylV.js} +1 -1
  52. package/dist/_astro/TemplatesLibrary.DsL2q-wp.js +1 -0
  53. package/dist/_astro/{TestReportsLibrary.fWiEyCRx.js → TestReportsLibrary.BBC1TYgP.js} +1 -1
  54. package/dist/_astro/{TestStatsBoard.BSUBsWSu.js → TestStatsBoard.VXjP4hu6.js} +1 -1
  55. package/dist/_astro/{TodosBoard.By5YdlUe.js → TodosBoard.-yKgp06M.js} +1 -1
  56. package/dist/_astro/UiAutoBoard.BZkPzwi8.js +3 -0
  57. package/dist/_astro/UiAutoEnvPanel.DrHUOlmH.js +10 -0
  58. package/dist/_astro/UiAutoGenerationDialog.gypq1zP9.js +12 -0
  59. package/dist/_astro/UiAutoProjectsPage.Dhzr09E9.js +3 -0
  60. package/dist/_astro/app-config.BSO5r82v.js +1 -0
  61. package/dist/_astro/app-version.B7nd7uBP.js +1 -0
  62. package/dist/_astro/{bash-tools.CS2w8LOb.js → bash-tools.C4DJiRJs.js} +1 -1
  63. package/dist/_astro/case-fields.C03NY3zC.js +148 -0
  64. package/dist/_astro/case-gen-run.DQR6uvH5.js +26 -0
  65. package/dist/_astro/case-prompt.ByLTgz4r.js +2 -0
  66. package/dist/_astro/{case-review.DFWZkoR9.js → case-review.BodP2jKm.js} +1 -1
  67. package/dist/_astro/{case-template.Clb7HrDB.js → case-template.CC2eXegU.js} +2 -2
  68. package/dist/_astro/case-types.BjF1BivA.js +1 -0
  69. package/dist/_astro/case-workflow-contract.BBQ9bbKL.js +1 -0
  70. package/dist/_astro/{defect-workbench.CjTb4FDv.js → defect-workbench.DBmohR-y.js} +1 -1
  71. package/dist/_astro/{hydrate-cache.O4CIma9y.js → hydrate-cache.CMMErx63.js} +1 -1
  72. package/dist/_astro/{i18n.Cp4so7KR.js → i18n.CEWjL5GX.js} +2 -2
  73. package/dist/_astro/{open-docs-in-session.BpcAcBSI.js → open-docs-in-session.BoyV6R2A.js} +1 -1
  74. package/dist/_astro/plugins.ChGmBEkF.js +1 -0
  75. package/dist/_astro/{project-docs.bB9lQ1Ki.js → project-docs.BRgNjXhG.js} +1 -1
  76. package/dist/_astro/{req-analysis.C_gARMrB.js → req-analysis.efWkT7Gv.js} +1 -1
  77. package/dist/_astro/{settings.D02wZj3w.js → settings.BojKNwUC.js} +2 -2
  78. package/dist/_astro/{spaces-client.BAtG6PkW.js → spaces-client.B28rzu8J.js} +1 -1
  79. package/dist/_astro/{story-review.DTN91Vl9.js → story-review.Dm9VcR6v.js} +1 -1
  80. package/dist/_astro/{test-points.C7ZgggQT.js → test-points.BSfPfq8z.js} +1 -1
  81. package/dist/_astro/ui-auto.LUcREUMe.js +1 -0
  82. package/dist/_astro/{view-prefs.COAKEQtZ.js → view-prefs.CWc5cQ2q.js} +1 -1
  83. package/dist/business-map/index.html +10 -5
  84. package/dist/case-exec/index.html +10 -5
  85. package/dist/case-execution/index.html +10 -5
  86. package/dist/cases/api/index.html +988 -0
  87. package/dist/cases/automation/index.html +988 -0
  88. package/dist/cases/functional/index.html +988 -0
  89. package/dist/cases/generate/index.html +10 -5
  90. package/dist/cases/index.html +1 -1
  91. package/dist/cases/library/index.html +1 -983
  92. package/dist/cases/other/index.html +988 -0
  93. package/dist/cases/performance/index.html +988 -0
  94. package/dist/dashboard/index.html +10 -5
  95. package/dist/defect-rules/index.html +10 -5
  96. package/dist/defect-submit/index.html +10 -5
  97. package/dist/defect-submit/templates/index.html +10 -5
  98. package/dist/docs/changelog/index.html +105 -58
  99. package/dist/docs/install/index.html +12 -6
  100. package/dist/docs/manual/index.html +62 -40
  101. package/dist/knowledge/index.html +10 -5
  102. package/dist/life/kr-tasks/index.html +10 -5
  103. package/dist/life/kr-todos/index.html +10 -5
  104. package/dist/life/objectives/index.html +10 -5
  105. package/dist/life/reviews/index.html +10 -5
  106. package/dist/life/stages/index.html +10 -5
  107. package/dist/life/year-plans/index.html +10 -5
  108. package/dist/plugins/index.html +10 -5
  109. package/dist/pm/bugs/index.html +10 -5
  110. package/dist/pm/iterations/index.html +10 -5
  111. package/dist/pm/projects/detail/index.html +10 -5
  112. package/dist/pm/projects/index.html +10 -5
  113. package/dist/pm/requirements/index.html +10 -5
  114. package/dist/reports/index.html +10 -5
  115. package/dist/requirement-analysis/index.html +10 -5
  116. package/dist/requirement-breakdowns/index.html +10 -5
  117. package/dist/requirements/index.html +10 -5
  118. package/dist/tasks/index.html +10 -5
  119. package/dist/templates/index.html +10 -5
  120. package/dist/test-automation/index.html +10 -5
  121. package/dist/test-automation/projects/index.html +10 -5
  122. package/dist/test-reports/index.html +10 -5
  123. package/dist/test-stats/index.html +10 -5
  124. package/dist/todos/index.html +10 -5
  125. package/dist/workbench/index.html +10 -5
  126. package/docs/Codex-MCP/351/233/206/346/210/220.md +117 -53
  127. package/docs//344/274/232/350/257/235/346/217/222/344/273/266.md +14 -1
  128. package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +5 -1
  129. package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +4 -2
  130. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +45 -36
  131. package/lh-plugins/case-automation/service.mjs +927 -0
  132. package/lh-plugins/case-automation/store.mjs +231 -0
  133. package/lh-plugins/case-automation/tables.mjs +115 -0
  134. package/lh-plugins/case-automation-prompt.mjs +57 -0
  135. package/lh-plugins/case-execution/assets.mjs +180 -0
  136. package/lh-plugins/case-execution/files.mjs +123 -23
  137. package/lh-plugins/case-execution/plans.mjs +318 -0
  138. package/lh-plugins/case-execution/service.mjs +80 -13
  139. package/lh-plugins/case-execution-prompt.mjs +4 -1
  140. package/lh-plugins/lh-case-automation.mjs +169 -0
  141. package/lh-plugins/lh-case-design.mjs +456 -0
  142. package/lh-plugins/lh-case-execution.mjs +53 -1
  143. package/lh-plugins/lh-case-review.mjs +29 -11
  144. package/lh-plugins/lh-project-docs.mjs +24 -0
  145. package/lh-plugins/lh-stats.mjs +65 -4
  146. package/lh-plugins/lh-uiauto.mjs +111 -2
  147. package/lh-plugins/plugin-prompts.mjs +1 -0
  148. package/lh-plugins/uiauto-adapters/playwright.mjs +44 -4
  149. package/lh-plugins/uiauto-adapters/shared.mjs +4 -0
  150. package/lh-plugins/uiauto-explorer/emit-files.mjs +16 -2
  151. package/lh-plugins/uiauto-explorer/ir.mjs +3 -0
  152. package/lh-plugins/uiauto-explorer/merge.mjs +37 -1
  153. package/lh-plugins/uiauto-explorer/navigation-guard.mjs +255 -0
  154. package/lh-plugins/uiauto-explorer/runner.mjs +65 -3
  155. package/lh-plugins/uiauto-explorer/sessions.mjs +29 -1
  156. package/package.json +1 -1
  157. package/skills/case-automation-bridge/SKILL.md +27 -0
  158. package/skills/case-execution/SKILL.md +19 -2
  159. package/skills/lantern-workflow/SKILL.md +39 -1
  160. package/dist/_astro/Base.Du_-4L-4.css +0 -1
  161. package/dist/_astro/CaseExecutionBoard.CjX4CoKd.js +0 -5
  162. package/dist/_astro/CaseGenerateApp.acgnxl79.js +0 -10
  163. package/dist/_astro/CasesLibrary.zmzOQwdn.js +0 -21
  164. package/dist/_astro/ChatApp.Ben9LFra.js +0 -1
  165. package/dist/_astro/ChatApp.DBi6q7Qv.js +0 -262
  166. package/dist/_astro/NavLibraries.DVR5Ua-S.js +0 -1
  167. package/dist/_astro/PmRequirementsBoard.B0W6bsW2.js +0 -1
  168. package/dist/_astro/SlideOverDrawer.BMg2tce6.js +0 -1
  169. package/dist/_astro/TemplatesLibrary.peYzrHZ2.js +0 -1
  170. package/dist/_astro/UiAutoBoard.BGdlp5Sr.js +0 -3
  171. package/dist/_astro/UiAutoEnvPanel.BUASgPLB.js +0 -10
  172. package/dist/_astro/UiAutoGenerationDialog.D1PyCgrD.js +0 -12
  173. package/dist/_astro/UiAutoProjectsPage.B6A9NlVK.js +0 -3
  174. package/dist/_astro/app-config.Dvfzl5_N.js +0 -1
  175. package/dist/_astro/app-version.CNpnKIb9.js +0 -1
  176. package/dist/_astro/case-fields.CmePqYfh.js +0 -148
  177. package/dist/_astro/case-gen-run.Cvvdv_kv.js +0 -26
  178. package/dist/_astro/case-prompt.CZ3vWUju.js +0 -2
  179. package/dist/_astro/plugins.Db9xoFZb.js +0 -1
@@ -0,0 +1,231 @@
1
+ import crypto from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+
5
+ import { spaceLocalFile } from '../../builtin/session/space-layout.mjs';
6
+
7
+ export const AUTOMATION_STATUSES = [
8
+ 'not_configured',
9
+ 'automatable',
10
+ 'needs_manual',
11
+ 'not_automatable',
12
+ 'connected',
13
+ 'running',
14
+ 'passed',
15
+ 'failed',
16
+ 'partial',
17
+ 'stale',
18
+ 'not_applicable',
19
+ ];
20
+
21
+ const rootDir = (root) => path.join(path.resolve(root), '.lantern', 'local', 'case-automation');
22
+ export const linksPath = (root) => path.join(rootDir(root), 'links.json');
23
+ export const assessmentsDir = (root) => path.join(rootDir(root), 'assessments');
24
+ export const batchesDir = (root) => path.join(rootDir(root), 'runs');
25
+ export const projectsMapPath = (root) => spaceLocalFile(root, 'case-automation/projects.json');
26
+
27
+ function readJson(file, fallback) {
28
+ try {
29
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
30
+ } catch {
31
+ return fallback;
32
+ }
33
+ }
34
+
35
+ function writeJson(file, value, mode = 0o600) {
36
+ fs.mkdirSync(path.dirname(file), { recursive: true });
37
+ const tmp = `${file}.${process.pid}.${crypto.randomBytes(4).toString('hex')}.tmp`;
38
+ fs.writeFileSync(tmp, `${JSON.stringify(value, null, 2)}\n`, { mode });
39
+ fs.renameSync(tmp, file);
40
+ }
41
+
42
+ export function readAutomationLinks(root) {
43
+ const data = readJson(linksPath(root), { version: 1, items: [] });
44
+ return Array.isArray(data?.items) ? data : { version: 1, items: [] };
45
+ }
46
+
47
+ export function writeAutomationLinks(root, data) {
48
+ writeJson(linksPath(root), { version: 1, items: data.items || [] });
49
+ }
50
+
51
+ export function upsertAutomationLinks(root, incoming) {
52
+ const store = readAutomationLinks(root);
53
+ const byId = new Map(store.items.map((item) => [item.automationCaseId, item]));
54
+ for (const item of incoming) {
55
+ const previous = byId.get(item.automationCaseId) || {};
56
+ byId.set(item.automationCaseId, {
57
+ ...previous,
58
+ ...item,
59
+ createdAt: previous.createdAt || item.createdAt || new Date().toISOString(),
60
+ updatedAt: new Date().toISOString(),
61
+ });
62
+ }
63
+ const next = { version: 1, items: [...byId.values()] };
64
+ writeAutomationLinks(root, next);
65
+ return next;
66
+ }
67
+
68
+ export function linksForSource(root, casePath, caseId = '') {
69
+ return readAutomationLinks(root).items.filter(
70
+ (item) => item.source?.casePath === casePath && (!caseId || item.source?.caseId === caseId),
71
+ );
72
+ }
73
+
74
+ export function readAssessment(root, id) {
75
+ if (!/^[a-z0-9-]{36}$/i.test(String(id || ''))) return null;
76
+ return readJson(path.join(assessmentsDir(root), `${id}.json`), null);
77
+ }
78
+
79
+ export function writeAssessment(root, record) {
80
+ writeJson(path.join(assessmentsDir(root), `${record.id}.json`), record);
81
+ return record;
82
+ }
83
+
84
+ export function readProjectMap(root) {
85
+ const data = readJson(projectsMapPath(root), { version: 1, files: {} });
86
+ return data && typeof data === 'object' ? data : { version: 1, files: {} };
87
+ }
88
+
89
+ export function rememberProjectSelection(root, casePath, projectId, iteration) {
90
+ const data = readProjectMap(root);
91
+ data.files = data.files || {};
92
+ data.files[casePath] = { projectId, iteration, updatedAt: new Date().toISOString() };
93
+ writeJson(projectsMapPath(root), data);
94
+ }
95
+
96
+ export function readBatch(root, id) {
97
+ if (!/^[a-z0-9-]{36}$/i.test(String(id || ''))) return null;
98
+ return readJson(path.join(batchesDir(root), `${id}.json`), null);
99
+ }
100
+
101
+ export function writeBatch(root, batch) {
102
+ writeJson(path.join(batchesDir(root), `${batch.id}.json`), {
103
+ ...batch,
104
+ updatedAt: new Date().toISOString(),
105
+ });
106
+ return batch;
107
+ }
108
+
109
+ function aggregate(items, assessments) {
110
+ const current = [...items, ...assessments];
111
+ if (!current.length) return { status: 'not_configured', total: 0, passed: 0, failed: 0 };
112
+ if (current.some((item) => item.status === 'stale')) {
113
+ return { status: 'stale', total: items.length, passed: 0, failed: 0 };
114
+ }
115
+ if (current.some((item) => item.status === 'running')) {
116
+ return {
117
+ status: 'running',
118
+ total: items.length,
119
+ passed: items.filter((item) => item.status === 'passed').length,
120
+ failed: items.filter((item) => item.status === 'failed').length,
121
+ };
122
+ }
123
+ if (items.some((item) => item.status === 'failed')) {
124
+ return {
125
+ status: 'failed',
126
+ total: items.length,
127
+ passed: items.filter((item) => item.status === 'passed').length,
128
+ failed: items.filter((item) => item.status === 'failed').length,
129
+ };
130
+ }
131
+ if (items.length && items.every((item) => item.status === 'passed')) {
132
+ return { status: 'passed', total: items.length, passed: items.length, failed: 0 };
133
+ }
134
+ if (items.some((item) => item.status === 'passed')) {
135
+ return {
136
+ status: 'partial',
137
+ total: items.length,
138
+ passed: items.filter((item) => item.status === 'passed').length,
139
+ failed: items.filter((item) => item.status === 'failed').length,
140
+ };
141
+ }
142
+ if (items.length) {
143
+ return {
144
+ status: 'connected',
145
+ total: items.length,
146
+ passed: 0,
147
+ failed: items.filter((item) => item.status === 'failed').length,
148
+ };
149
+ }
150
+ if (current.every((item) => item.status === 'not_automatable'))
151
+ return { status: 'not_automatable', total: 0, passed: 0, failed: 0 };
152
+ if (current.every((item) => item.status === 'needs_manual'))
153
+ return { status: 'needs_manual', total: 0, passed: 0, failed: 0 };
154
+ if (current.some((item) => item.status === 'automatable'))
155
+ return { status: 'automatable', total: 0, passed: 0, failed: 0 };
156
+ return { status: 'connected', total: 0, passed: 0, failed: 0 };
157
+ }
158
+
159
+ export function automationSummaryForCase(root, casePath, caseId) {
160
+ const links = readAutomationLinks(root).items.filter(
161
+ (item) =>
162
+ (item.source?.casePath === casePath && item.source?.caseId === caseId) ||
163
+ (caseId && item.source?.caseId === caseId),
164
+ );
165
+ const store = readProjectMap(root);
166
+ const assessments = Array.isArray(store.assessments?.[caseId]) ? store.assessments[caseId] : [];
167
+ const summary = aggregate(links, assessments);
168
+ return {
169
+ ...summary,
170
+ items: links.map((item) => ({
171
+ automationCaseId: item.automationCaseId,
172
+ title: item.title,
173
+ status: item.status,
174
+ projectId: item.projectId,
175
+ projectName: item.projectName || '',
176
+ framework: item.framework || '',
177
+ iteration: item.iteration || '',
178
+ iterationFile: item.iterationFile || '',
179
+ tag: item.tag || '',
180
+ scriptPath: item.scriptPath || '',
181
+ lastRunId: item.latestRunId || '',
182
+ reportUrl: item.reportUrl || '',
183
+ logUrl: item.logUrl || '',
184
+ error: item.staleReason || item.error || '',
185
+ updatedAt: item.updatedAt || '',
186
+ })),
187
+ };
188
+ }
189
+
190
+ export function automationSummaryForFile(root, casePath) {
191
+ const links = readAutomationLinks(root).items.filter(
192
+ (item) => item.source?.casePath === casePath,
193
+ );
194
+ const data = readProjectMap(root);
195
+ const assessments = Object.values(data.assessments || {})
196
+ .flatMap((items) => (Array.isArray(items) ? items : []))
197
+ .filter((item) => item.sourcePath === casePath);
198
+ if (!links.length && !assessments.length) return null;
199
+ const statuses = [
200
+ ...links.map((item) => item.status || 'connected'),
201
+ ...assessments.map((item) => item.status || 'needs_manual'),
202
+ ];
203
+ let status = 'connected';
204
+ if (statuses.includes('stale')) status = 'stale';
205
+ else if (statuses.includes('running')) status = 'running';
206
+ else if (statuses.includes('failed')) status = 'failed';
207
+ else if (statuses.includes('passed') && statuses.every((value) => value === 'passed'))
208
+ status = 'passed';
209
+ else if (statuses.includes('passed') || statuses.includes('partial')) status = 'partial';
210
+ else if (statuses.includes('needs_manual')) status = 'needs_manual';
211
+ else if (statuses.every((value) => value === 'not_automatable')) status = 'not_automatable';
212
+ return {
213
+ status,
214
+ total: links.length,
215
+ passed: links.filter((item) => item.status === 'passed').length,
216
+ failed: links.filter((item) => item.status === 'failed').length,
217
+ };
218
+ }
219
+
220
+ export function rememberAssessments(root, sourcePath, caseId, entries) {
221
+ const data = readProjectMap(root);
222
+ data.assessments = data.assessments || {};
223
+ data.assessments[caseId] = entries.map((item) => ({
224
+ status: item.decision,
225
+ reason: item.reason || '',
226
+ sourcePath,
227
+ automationCaseId: item.automationCaseId || '',
228
+ updatedAt: new Date().toISOString(),
229
+ }));
230
+ writeJson(projectsMapPath(root), data);
231
+ }
@@ -0,0 +1,115 @@
1
+ import crypto from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+
5
+ function hash(buffer) {
6
+ return crypto.createHash('sha256').update(buffer).digest('hex');
7
+ }
8
+
9
+ function csvCell(value) {
10
+ const text = String(value ?? '');
11
+ return /[",\n\r]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
12
+ }
13
+
14
+ function mdCell(value) {
15
+ return String(value ?? '')
16
+ .replaceAll('|', '|')
17
+ .replace(/\r?\n/g, '<br>');
18
+ }
19
+
20
+ function parseMarkdown(text) {
21
+ const lines = String(text || '')
22
+ .replace(/\r\n/g, '\n')
23
+ .split('\n');
24
+ const headerIndex = lines.findIndex((line) => /^\s*\|/.test(line));
25
+ if (headerIndex < 0) return { headers: [], rows: [] };
26
+ const cells = (line) =>
27
+ line
28
+ .trim()
29
+ .replace(/^\|/, '')
30
+ .replace(/\|$/, '')
31
+ .split('|')
32
+ .map((cell) => cell.replace(/<br\s*\/?>/gi, '\n').trim());
33
+ const headers = cells(lines[headerIndex]);
34
+ const rows = [];
35
+ for (let index = headerIndex + 1; index < lines.length; index += 1) {
36
+ if (!/^\s*\|/.test(lines[index])) break;
37
+ if (/^\s*\|?[\s:|-]+\|?\s*$/.test(lines[index])) continue;
38
+ const values = cells(lines[index]);
39
+ const row = {};
40
+ headers.forEach((header, column) => {
41
+ if (header) row[header] = values[column] ?? '';
42
+ });
43
+ if (Object.values(row).some((value) => String(value).trim())) rows.push(row);
44
+ }
45
+ return { headers, rows };
46
+ }
47
+
48
+ export async function readTable(file, ext) {
49
+ if (!fs.existsSync(file)) return { headers: [], rows: [] };
50
+ if (ext === '.md') return parseMarkdown(fs.readFileSync(file, 'utf8'));
51
+ const XLSX = await import('xlsx');
52
+ const mod = XLSX.default ?? XLSX;
53
+ const raw = ext === '.csv' ? fs.readFileSync(file, 'utf8') : fs.readFileSync(file);
54
+ const book =
55
+ ext === '.csv'
56
+ ? mod.read(String(raw).replace(/^\uFEFF/, ''), { type: 'string' })
57
+ : mod.read(raw, { type: 'buffer' });
58
+ const sheet = book.Sheets[book.SheetNames[0] || ''];
59
+ if (!sheet) return { headers: [], rows: [] };
60
+ const table = mod.utils.sheet_to_json(sheet, { header: 1, defval: '', blankrows: false });
61
+ const headers = (table[0] || []).map((value) => String(value ?? '').trim());
62
+ const rows = table.slice(1).flatMap((values) => {
63
+ const row = {};
64
+ headers.forEach((header, index) => {
65
+ if (header) row[header] = String(values[index] ?? '').trim();
66
+ });
67
+ return Object.values(row).some((value) => value) ? [row] : [];
68
+ });
69
+ return { headers, rows };
70
+ }
71
+
72
+ export async function writeTableAtomic(file, ext, headers, rows) {
73
+ fs.mkdirSync(path.dirname(file), { recursive: true });
74
+ const temp = `${file}.${process.pid}.tmp`;
75
+ if (ext === '.xlsx') {
76
+ const XLSX = await import('xlsx');
77
+ const mod = XLSX.default ?? XLSX;
78
+ const sheet = mod.utils.json_to_sheet(rows, { header: headers });
79
+ const book = mod.utils.book_new();
80
+ mod.utils.book_append_sheet(book, sheet, '自动化用例');
81
+ fs.writeFileSync(temp, mod.write(book, { type: 'buffer', bookType: 'xlsx' }));
82
+ } else if (ext === '.csv') {
83
+ const lines = [
84
+ headers.map(csvCell).join(','),
85
+ ...rows.map((row) => headers.map((header) => csvCell(row[header])).join(',')),
86
+ ];
87
+ fs.writeFileSync(temp, `\uFEFF${lines.join('\n')}`, 'utf8');
88
+ } else if (ext === '.md') {
89
+ const lines = [
90
+ `| ${headers.map(mdCell).join(' | ')} |`,
91
+ `|${headers.map(() => '---').join('|')}|`,
92
+ ...rows.map((row) => `| ${headers.map((header) => mdCell(row[header])).join(' | ')} |`),
93
+ ];
94
+ fs.writeFileSync(temp, `${lines.join('\n')}\n`, 'utf8');
95
+ } else {
96
+ throw new Error(`不支持的自动化用例格式:${ext}`);
97
+ }
98
+ fs.renameSync(temp, file);
99
+ return { file, fileHash: hash(fs.readFileSync(file)) };
100
+ }
101
+
102
+ export function fileHash(file) {
103
+ return fs.existsSync(file) ? hash(fs.readFileSync(file)) : '';
104
+ }
105
+
106
+ export function backupFile(file) {
107
+ if (!fs.existsSync(file)) return '';
108
+ const ext = path.extname(file);
109
+ const stamp = new Date().toISOString().replace(/\D/g, '').slice(0, 14);
110
+ const dir = path.join(path.dirname(file), '备份列表');
111
+ fs.mkdirSync(dir, { recursive: true });
112
+ const target = path.join(dir, `${path.basename(file, ext)}_bak_${stamp}${ext}`);
113
+ fs.copyFileSync(file, target);
114
+ return target;
115
+ }
@@ -0,0 +1,57 @@
1
+ export const CASE_AUTOMATION_PROMPT_FILE = '功能用例转UI自动化提示词.md';
2
+
3
+ export const CASE_AUTOMATION_PROMPT_TEMPLATE = `# 功能用例转 UI 自动化
4
+
5
+ 你负责把已经评审过的功能测试用例转换成可进入 UI 自动化探索阶段的自动化用例。原功能用例是业务事实来源;不要改写需求,不要虚构页面、按钮、数据或业务规则。
6
+
7
+ ## 判断边界
8
+
9
+ - 只有可通过 Web/浏览器 UI 操作并在页面上观察结果的用例,才标记为 \`automatable\`。
10
+ - 需要人工验证码、短信、扫码、系统原生弹窗、支付确认、文件选择器或不可逆高风险操作,且无法通过已有登录态或项目配置规避时,标记为 \`needs_manual\`。
11
+ - 接口、抓包、Mock、数据库校验、性能压测、App 原生操作等不属于当前 UI 自动化范围,标记为 \`not_automatable\`。
12
+ - 数据不足、预期不可观察或步骤无法执行的,不得猜成可自动化。
13
+
14
+ ## 转换要求
15
+
16
+ - 保留来源用例 ID,一个来源用例可以拆成多条独立自动化用例;每条只验证一个结果。
17
+ - 自动化标题写成一句清楚的业务行为。
18
+ - 前置条件只写账号/角色、测试数据、系统状态和依赖;不要混入操作步骤。
19
+ - 自动化步骤用可执行动作描述:打开页面、在“某输入框”输入、点击“某按钮”、等待可见结果、断言页面状态。
20
+ - 使用用户可见的菜单、按钮、输入框和字段名称;禁止生成 CSS、XPath、坐标、定位器和真实凭据。
21
+ - 环境相关的账号、密码、手机号使用 \${ENV_NAME} 占位。
22
+ - 优先级沿用来源用例 P0-P3。
23
+ - plan 只允许 goto / click / fill / select / press / hover / expect / expectUrl / wait;至少包含一个 expect 或 expectUrl。
24
+
25
+ 只输出一个 JSON 对象:
26
+ {
27
+ "summary": "一句话",
28
+ "cases": [
29
+ {
30
+ "sourceCaseId": "原用例 ID",
31
+ "decision": "automatable | needs_manual | not_automatable",
32
+ "reason": "判断依据",
33
+ "risks": ["风险"],
34
+ "automationCases": [
35
+ {
36
+ "title": "自动化用例标题",
37
+ "precondition": "前置条件",
38
+ "steps": ["1. ...", "2. ..."],
39
+ "expected": "可观察的预期结果",
40
+ "priority": "P0",
41
+ "plan": [
42
+ {
43
+ "id": "p1",
44
+ "action": "goto",
45
+ "url": "/",
46
+ "target": "目标页面",
47
+ "value": "",
48
+ "note": "为什么做这一步"
49
+ }
50
+ ]
51
+ }
52
+ ]
53
+ }
54
+ ]
55
+ }
56
+
57
+ decision 不是 automatable 时 automationCases 必须为空。`;
@@ -0,0 +1,180 @@
1
+ import { resolveContentRoot } from '../../builtin/session/space-layout.mjs';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import crypto from 'node:crypto';
5
+ import { reqAnalysisStorePath, reqDocsDir } from '../lh-req-analysis.mjs';
6
+ import { analysisRevision } from '../req-analysis-revision.mjs';
7
+
8
+ const storePath = (root) => path.join(root, '.lantern', 'local', 'case-workflow', 'assets.json');
9
+ export const fingerprint = (value) =>
10
+ crypto.createHash('sha256').update(JSON.stringify(value)).digest('hex');
11
+ export function readWorkflowAssets(root) {
12
+ try {
13
+ return JSON.parse(fs.readFileSync(storePath(root), 'utf8'));
14
+ } catch {
15
+ return { version: 1, artifacts: [] };
16
+ }
17
+ }
18
+ export function saveWorkflowAssets(root, store) {
19
+ const file = storePath(root);
20
+ fs.mkdirSync(path.dirname(file), { recursive: true });
21
+ fs.writeFileSync(file + '.tmp', JSON.stringify(store, null, 2), { mode: 0o600 });
22
+ fs.renameSync(file + '.tmp', file);
23
+ }
24
+ export function analysisSnapshot(root, analysisId) {
25
+ let docs;
26
+ try {
27
+ docs = JSON.parse(fs.readFileSync(reqAnalysisStorePath(root), 'utf8')).docs || [];
28
+ } catch {
29
+ docs = [];
30
+ }
31
+ const doc = docs.find((item) => item.id === analysisId);
32
+ if (!doc) throw Object.assign(new Error('需求分析不存在'), { statusCode: 404 });
33
+ return doc;
34
+ }
35
+ export function sourceFileHash(root, sourcePath) {
36
+ if (!sourcePath) return '';
37
+ const base = path.resolve(reqDocsDir(root)),
38
+ abs = path.resolve(base, sourcePath);
39
+ if (!abs.startsWith(base + path.sep) || !fs.existsSync(abs)) return '';
40
+ return fingerprint(fs.readFileSync(abs).toString('base64'));
41
+ }
42
+ export function artifactStaleness(root, artifact) {
43
+ if (!artifact) return { stale: false, tracked: false, reasons: ['历史文件尚未关联需求基线'] };
44
+ const reasons = [];
45
+ if (artifact.analysisId) {
46
+ try {
47
+ if (
48
+ analysisRevision(analysisSnapshot(root, artifact.analysisId)) !== artifact.analysisRevision
49
+ )
50
+ reasons.push('需求分析已变化');
51
+ } catch {
52
+ reasons.push('来源需求分析已删除');
53
+ }
54
+ }
55
+ if (
56
+ artifact.sourceFileHash &&
57
+ sourceFileHash(root, artifact.sourcePath) !== artifact.sourceFileHash
58
+ )
59
+ reasons.push('需求源文件已变化或缺失');
60
+ return {
61
+ stale: !!reasons.length,
62
+ tracked: !!(artifact.analysisId || artifact.sourcePath),
63
+ reasons,
64
+ };
65
+ }
66
+ export function caseContentFingerprint(item) {
67
+ return fingerprint([
68
+ item.title,
69
+ item.precondition,
70
+ item.steps,
71
+ item.expected,
72
+ (item.fields || [])
73
+ .filter((field) => /需求|requirement|reqcite|reqpoint|outline/i.test(field.name))
74
+ .map((field) => [field.name, field.value]),
75
+ ]);
76
+ }
77
+ export function bindCaseIdentities(root, document) {
78
+ const store = readWorkflowAssets(root);
79
+ const caseDir = resolveContentRoot(root, '用例管理').abs;
80
+ const moved = (item) => !fs.existsSync(path.join(caseDir, item.path));
81
+ let artifact =
82
+ store.artifacts.find((item) => item.path === document.path) ||
83
+ store.artifacts.find(
84
+ (item) =>
85
+ moved(item) && (item.fileHash === document.fileHash || item.paths?.includes(document.path)),
86
+ );
87
+
88
+ if (!artifact) {
89
+ artifact = {
90
+ id: crypto.randomUUID(),
91
+ baselineId: crypto.randomUUID(),
92
+ path: document.path,
93
+ paths: [],
94
+ fileHash: document.fileHash,
95
+ bindings: [],
96
+ };
97
+ store.artifacts.push(artifact);
98
+ }
99
+ if (artifact.path !== document.path) {
100
+ artifact.paths = [...new Set([...(artifact.paths || []), artifact.path])];
101
+ artifact.path = document.path;
102
+ }
103
+ artifact.baselineId ||= crypto.randomUUID();
104
+ const used = new Set();
105
+ document.cases.forEach((item) => {
106
+ const contentHash = caseContentFingerprint(item);
107
+ const noUnique = item.no && document.cases.filter((row) => row.no === item.no).length === 1;
108
+ let binding = artifact.bindings.find(
109
+ (old) => !used.has(old.id) && old.contentHash === contentHash && old.no === item.no,
110
+ );
111
+ if (!binding && noUnique)
112
+ binding = artifact.bindings.find((old) => !used.has(old.id) && old.no === item.no);
113
+ if (!binding) binding = { id: crypto.randomUUID(), no: item.no, contentHash };
114
+ used.add(binding.id);
115
+ item.id = binding.id;
116
+ item.contentFingerprint = contentHash;
117
+ binding.no = item.no;
118
+ binding.contentHash = contentHash;
119
+ if (!artifact.bindings.some((old) => old.id === binding.id)) artifact.bindings.push(binding);
120
+ });
121
+ artifact.fileHash = document.fileHash;
122
+ saveWorkflowAssets(root, store);
123
+ document.provenance = {
124
+ artifactId: artifact.id,
125
+ baselineId: artifact.baselineId,
126
+ sourceFileHash: artifact.sourceFileHash || '',
127
+ analysisId: artifact.analysisId || '',
128
+ analysisRevision: artifact.analysisRevision || '',
129
+ sourcePath: artifact.sourcePath || '',
130
+ ...artifactStaleness(root, artifact),
131
+ };
132
+ for (const item of document.cases) {
133
+ const verification = artifact.verifications?.[item.id];
134
+ const invalid =
135
+ document.provenance.stale ||
136
+ artifact.needsReview?.includes(item.id) ||
137
+ (verification && verification.contentFingerprint !== item.contentFingerprint);
138
+ if (invalid) {
139
+ item.storedStatus = item.status;
140
+ item.status = '待验证';
141
+ item.resultStale = true;
142
+ }
143
+ }
144
+ return document;
145
+ }
146
+
147
+ export function linkCaseArtifact(root, document, source = {}) {
148
+ const store = readWorkflowAssets(root),
149
+ artifact = store.artifacts.find((item) => item.id === document.provenance.artifactId);
150
+ if (!artifact) throw new Error('用例资产未登记');
151
+ Object.assign(artifact, source, {
152
+ baselineId: crypto.randomUUID(),
153
+ createdAt: artifact.createdAt || new Date().toISOString(),
154
+ });
155
+ saveWorkflowAssets(root, store);
156
+ return artifact;
157
+ }
158
+
159
+ export function recordManualVerification(root, document, rowIndex, environment) {
160
+ const item = document.cases[rowIndex];
161
+ const store = readWorkflowAssets(root),
162
+ artifact = store.artifacts.find((asset) => asset.id === document.provenance.artifactId);
163
+ if (!artifact || !item) return;
164
+ artifact.verifications ||= {};
165
+ artifact.verifications[item.id] = {
166
+ at: new Date().toISOString(),
167
+ source: 'manual',
168
+ contentFingerprint: caseContentFingerprint(item),
169
+ analysisRevision: artifact.analysisRevision || '',
170
+ baselineId: artifact.baselineId,
171
+ sourceFileHash: artifact.sourceFileHash || '',
172
+ status: item.storedStatus || item.status,
173
+ environment: environment || artifact.verifications[item.id]?.environment || {},
174
+ };
175
+ artifact.verificationHistory ||= [];
176
+ artifact.verificationHistory.push({ caseId: item.id, ...artifact.verifications[item.id] });
177
+ artifact.verificationHistory = artifact.verificationHistory.slice(-10000);
178
+ artifact.needsReview = (artifact.needsReview || []).filter((id) => id !== item.id);
179
+ saveWorkflowAssets(root, store);
180
+ }