lantern-harness 0.1.8 → 0.1.10

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 (183) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +7 -7
  3. package/builtin/session/lh-fs.mjs +32 -14
  4. package/cli/server.mjs +2 -0
  5. package/config/app.defaults.json +1 -0
  6. package/dist/500.html +258 -22
  7. package/dist/_astro/Base.BOY6F0mi.css +1 -0
  8. package/dist/_astro/Base.astro_astro_type_script_index_0_lang.C30xtpc6.js +1 -0
  9. package/dist/_astro/CaseExecBoard.Dttqp0wg.js +1 -0
  10. package/dist/_astro/CaseGenerateApp.DqW_nWMc.js +9 -0
  11. package/dist/_astro/CasesLibrary.8aMUUGp_.js +1 -0
  12. package/dist/_astro/ChatApp.BLxf0h1d.js +219 -0
  13. package/dist/_astro/ColumnResize.BEkEW7qw.js +1 -0
  14. package/dist/_astro/{ConfirmDialog.CBVsDJ8f.js → ConfirmDialog.BZzZWDci.js} +1 -1
  15. package/dist/_astro/{DashboardBoard.Bd3eUPwZ.js → DashboardBoard.CkSbhEDI.js} +3 -3
  16. package/dist/_astro/DatePicker.Bkl71M49.js +1 -0
  17. package/dist/_astro/DocsFileBrowser.MKVCfZrE.js +1 -0
  18. package/dist/_astro/DocsPager.DJY4foYL.js +1 -0
  19. package/dist/_astro/{DrawerField.CWMLhcPX.js → DrawerField.CHRg77LG.js} +1 -1
  20. package/dist/_astro/{ExcelFieldTags.B_XMwNNx.js → ExcelFieldTags.DXMeaDa5.js} +4 -4
  21. package/dist/_astro/KnowledgeLibrary.B-p1aoQN.js +1 -0
  22. package/dist/_astro/NamePromptDialog.Wa9O530a.js +1 -0
  23. package/dist/_astro/NavLibraries.C6LImMO_.js +1 -0
  24. package/dist/_astro/OverflowHint.D6v4Uj2N.js +1 -0
  25. package/dist/_astro/PluginsPage.-97n3x2U.js +39 -0
  26. package/dist/_astro/PluginsPage.DkmRPfbU.js +1 -0
  27. package/dist/_astro/PmBugsBoard.CMT4-eoB.js +1 -0
  28. package/dist/_astro/PmIterationsBoard.BQM_dzdZ.js +1 -0
  29. package/dist/_astro/PmProjectDetail.CzU80pat.js +1 -0
  30. package/dist/_astro/PmProjectsBoard.Cxsa7SYQ.js +1 -0
  31. package/dist/_astro/PmRequirementsBoard.4_JMDDN0.js +1 -0
  32. package/dist/_astro/PmRequirementsBoard.B8HL07cw.js +1 -0
  33. package/dist/_astro/PmShared.Ca2Ao7v_.js +1 -0
  34. package/dist/_astro/PromptsLibrary.C9BcIxKK.js +1 -0
  35. package/dist/_astro/ReportsPage.Fh5DRKLT.js +1 -0
  36. package/dist/_astro/RequirementsLibrary.CBkuWE8X.js +1 -0
  37. package/dist/_astro/SearchableSelect.DnjoSslK.js +1 -0
  38. package/dist/_astro/SelectDropdown.CuuDHa8s.js +1 -0
  39. package/dist/_astro/SettingsDialog.CJvBRcs9.js +1 -0
  40. package/dist/_astro/SlideOverDrawer.B7B5Wu8I.js +1 -0
  41. package/dist/_astro/{SpaceSwitcher.BEJo5KFi.js → SpaceSwitcher.BVQLt_tL.js} +2 -2
  42. package/dist/_astro/TagSelect.CuN5RdF4.js +1 -0
  43. package/dist/_astro/TasksBoard.Bu-fpIZ7.js +1 -0
  44. package/dist/_astro/TemplatesLibrary.DSylQGlN.js +1 -0
  45. package/dist/_astro/TestStatsBoard.CPyKW4wc.js +1 -0
  46. package/dist/_astro/Toast.R8_2OWRX.js +1 -0
  47. package/dist/_astro/TodosBoard.8kvRTEW-.js +1 -0
  48. package/dist/_astro/UiAutoBoard.DFTiDqCp.js +9 -0
  49. package/dist/_astro/active-element-history.CED-m1Zp.js +1 -0
  50. package/dist/_astro/app-config.BUPzGl9f.js +1 -0
  51. package/dist/_astro/{client.Be_SakrB.js → client.BHNTqLjv.js} +3 -3
  52. package/dist/_astro/dialog.BAPTk9a_.js +1 -0
  53. package/dist/_astro/hydrate-cache.BXX604Bw.js +1 -0
  54. package/dist/_astro/i18n.BGPnP1Bg.js +7 -0
  55. package/dist/_astro/index.astro_astro_type_script_index_0_lang.LPL9mPQY.js +1 -0
  56. package/dist/_astro/jsx-runtime.DUg_B_vD.js +1 -0
  57. package/dist/_astro/{lib.DJNDi_Ht.js → lib.CgXLzMMd.js} +15 -15
  58. package/dist/_astro/listbox.C96OCanh.js +1 -0
  59. package/dist/_astro/markdown-client.DRva7DS9.js +58 -0
  60. package/dist/_astro/menu.IPWdRoNM.js +1 -0
  61. package/dist/_astro/{open-docs-in-session.B0ZdZNj2.js → open-docs-in-session.CyFNgh1I.js} +1 -1
  62. package/dist/_astro/{plugins.D5ypJIXn.js → plugins.C2BMfzv1.js} +1 -1
  63. package/dist/_astro/{pm.BsnTv63L.js → pm.CagBA-ht.js} +4 -4
  64. package/dist/_astro/{portal.Cm9XlIPf.js → portal.C0hAhXDF.js} +2 -2
  65. package/dist/_astro/prompts-meta.Bua-j14I.js +2 -0
  66. package/dist/_astro/react-dom.DLW9pGCF.js +1 -0
  67. package/dist/_astro/{react-dom.CqAxpHMt.js → react.Blvh0GOs.js} +1 -1
  68. package/dist/_astro/report-prompt.CAfZ6RIo.js +1 -0
  69. package/dist/_astro/{settings.CnDCvwnQ.js → settings.Ceefeil5.js} +2 -2
  70. package/dist/_astro/{spaces-client.Cai2tHEI.js → spaces-client.BocUabwy.js} +1 -1
  71. package/dist/_astro/ui-auto-prompt.CX8fju7r.js +3 -0
  72. package/dist/_astro/ui-auto.BmC9JJ_X.js +1 -0
  73. package/dist/_astro/update.CvfIVwnq.js +1 -0
  74. package/dist/_astro/use-text-value.DBQvHeNl.js +1 -0
  75. package/dist/_astro/use-tree-walker.DFU2AaAP.js +1 -0
  76. package/dist/_astro/useListAnim.BoerpmsB.js +1 -0
  77. package/dist/_astro/{view-prefs.HCowOWXL.js → view-prefs.BEAZRcxF.js} +1 -1
  78. package/dist/case-exec/index.html +458 -22
  79. package/dist/cases/generate/index.html +258 -22
  80. package/dist/cases/library/index.html +458 -22
  81. package/dist/dashboard/index.html +458 -22
  82. package/dist/docs/changelog/index.html +389 -23
  83. package/dist/docs/install/index.html +258 -22
  84. package/dist/docs/manual/index.html +324 -27
  85. package/dist/index.html +2 -281
  86. package/dist/knowledge/index.html +458 -22
  87. package/dist/knowledge//345/212/237/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/347/274/226/345/206/231/350/247/204/350/214/203/index.html +258 -22
  88. package/dist/plugins/index.html +258 -22
  89. package/dist/pm/bugs/index.html +458 -22
  90. package/dist/pm/iterations/index.html +458 -22
  91. package/dist/pm/projects/detail/index.html +458 -22
  92. package/dist/pm/projects/index.html +458 -22
  93. package/dist/pm/requirements/index.html +458 -22
  94. package/dist/prompts/index.html +458 -22
  95. package/dist/reports/index.html +458 -22
  96. package/dist/requirements/index.html +458 -22
  97. package/dist/tasks/index.html +458 -22
  98. package/dist/templates/index.html +458 -22
  99. package/dist/templates//345/212/237/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212//345/212/237/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +258 -22
  100. package/dist/templates//346/200/247/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212//346/200/247/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +258 -22
  101. package/dist/templates//346/200/247/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213//346/200/247/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/346/250/241/346/235/277/index.html +258 -22
  102. package/dist/templates//346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212//346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +258 -22
  103. package/dist/templates//350/207/252/345/212/250/345/214/226/346/265/213/350/257/225/347/224/250/344/276/213//350/207/252/345/212/250/345/214/226/346/265/213/350/257/225/347/224/250/344/276/213/346/250/241/346/235/277/index.html +258 -22
  104. package/dist/test-automation/index.html +717 -0
  105. package/dist/test-stats/index.html +458 -22
  106. package/dist/todos/index.html +458 -22
  107. package/dist/workbench/index.html +517 -0
  108. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +85 -34
  109. package/lh-plugins/lh-project-docs.mjs +14 -0
  110. package/lh-plugins/lh-uiauto.mjs +2296 -0
  111. package/lh-plugins/plugin-prompts.mjs +200 -0
  112. package/lh-plugins/storage-domain.mjs +13 -0
  113. package/lh-plugins/uiauto-adapters/index.mjs +57 -0
  114. package/lh-plugins/uiauto-adapters/playwright.mjs +215 -0
  115. package/lh-plugins/uiauto-adapters/pytest.mjs +151 -0
  116. package/lh-plugins/uiauto-adapters/selenium.mjs +163 -0
  117. package/lh-plugins/uiauto-adapters/shared.mjs +371 -0
  118. package/lh-plugins/uiauto-adapters/tasks.mjs +369 -0
  119. package/lh-plugins/uiauto-argv-guard.cjs +41 -0
  120. package/lh-plugins/uiauto-explorer/apps.mjs +332 -0
  121. package/lh-plugins/uiauto-explorer/diff.mjs +159 -0
  122. package/lh-plugins/uiauto-explorer/emit-files.mjs +506 -0
  123. package/lh-plugins/uiauto-explorer/emit-python.mjs +160 -0
  124. package/lh-plugins/uiauto-explorer/emit-ts.mjs +118 -0
  125. package/lh-plugins/uiauto-explorer/emit.mjs +15 -0
  126. package/lh-plugins/uiauto-explorer/ir.mjs +114 -0
  127. package/lh-plugins/uiauto-explorer/locators.mjs +267 -0
  128. package/lh-plugins/uiauto-explorer/merge.mjs +235 -0
  129. package/lh-plugins/uiauto-explorer/plan.mjs +165 -0
  130. package/lh-plugins/uiauto-explorer/runner.mjs +370 -0
  131. package/lh-plugins/uiauto-explorer/sessions.mjs +1373 -0
  132. package/lh-plugins/uiauto-explorer/snapshot.mjs +492 -0
  133. package/lh-plugins/uiauto-prompt.mjs +122 -0
  134. package/lh-plugins/uiauto-report.mjs +111 -0
  135. package/package.json +1 -1
  136. package/dist/_astro/Base.DjIEQkT7.css +0 -1
  137. package/dist/_astro/Base.astro_astro_type_script_index_0_lang.D0snmAJ_.js +0 -1
  138. package/dist/_astro/CaseExecBoard.BAV4EE3o.js +0 -1
  139. package/dist/_astro/CaseGenerateApp.Bz4ryNJG.js +0 -9
  140. package/dist/_astro/CasesLibrary.BPifyHUA.js +0 -1
  141. package/dist/_astro/ChatApp.DLo31SYZ.js +0 -276
  142. package/dist/_astro/ColumnResize.Bs6GL3DJ.js +0 -1
  143. package/dist/_astro/DatePicker.CMfX7F6z.js +0 -1
  144. package/dist/_astro/DocsFileBrowser.D3cKurQE.js +0 -1
  145. package/dist/_astro/DocsPager.rzu4mnzw.js +0 -1
  146. package/dist/_astro/KnowledgeLibrary.B0sO4QR1.js +0 -1
  147. package/dist/_astro/NamePromptDialog.Dl5kSnQI.js +0 -1
  148. package/dist/_astro/NavLibraries.Cvg3wery.js +0 -1
  149. package/dist/_astro/OverflowHint.lzmplP5j.js +0 -1
  150. package/dist/_astro/PluginsPage.DIltPILi.js +0 -39
  151. package/dist/_astro/PluginsPage.uvmSuXzi.js +0 -1
  152. package/dist/_astro/PmBugsBoard.CiaIhCHv.js +0 -1
  153. package/dist/_astro/PmIterationsBoard.H67QwKFw.js +0 -1
  154. package/dist/_astro/PmProjectDetail.DqDoIg8a.js +0 -1
  155. package/dist/_astro/PmProjectsBoard.nOC1Hugt.js +0 -1
  156. package/dist/_astro/PmRequirementsBoard.BPjZ7khP.js +0 -1
  157. package/dist/_astro/PmRequirementsBoard.CanxvcKg.js +0 -1
  158. package/dist/_astro/PmShared.CZnXaUq-.js +0 -1
  159. package/dist/_astro/PromptsLibrary.DU9EuSim.js +0 -1
  160. package/dist/_astro/ReportsPage.Cr88iz8c.js +0 -1
  161. package/dist/_astro/RequirementsLibrary.BwriF8F0.js +0 -1
  162. package/dist/_astro/SearchableSelect.Ctg8V1Z1.js +0 -1
  163. package/dist/_astro/SelectDropdown.Buv7rQJ_.js +0 -1
  164. package/dist/_astro/SettingsDialog.DEgsVfaL.js +0 -1
  165. package/dist/_astro/SlideOverDrawer.TPbGEoWn.js +0 -1
  166. package/dist/_astro/TagSelect.u8DTop7v.js +0 -1
  167. package/dist/_astro/TasksBoard.BZi_GBPG.js +0 -1
  168. package/dist/_astro/TemplatesLibrary.T4K9jUex.js +0 -1
  169. package/dist/_astro/TestStatsBoard.Dd1Kcmx6.js +0 -1
  170. package/dist/_astro/TodosBoard.C4yd_JFb.js +0 -1
  171. package/dist/_astro/active-element-history.CeefGkFQ.js +0 -1
  172. package/dist/_astro/app-config.DKMxjv3g.js +0 -1
  173. package/dist/_astro/dialog.DXHznyjD.js +0 -1
  174. package/dist/_astro/i18n.BXeGGutk.js +0 -7
  175. package/dist/_astro/jsx-runtime.BUXbF_vF.js +0 -1
  176. package/dist/_astro/listbox.Di-t5U37.js +0 -1
  177. package/dist/_astro/menu.Bkluqxic.js +0 -1
  178. package/dist/_astro/prompts-meta.F4wwkjUA.js +0 -2
  179. package/dist/_astro/report-prompt.Cmw4XzfY.js +0 -1
  180. package/dist/_astro/update.DXCPfU4a.js +0 -1
  181. package/dist/_astro/use-text-value.BuY0Cm1z.js +0 -1
  182. package/dist/_astro/use-tree-walker.CfTHFX43.js +0 -1
  183. package/dist/_astro/useListAnim.CpGB1cft.js +0 -1
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Selenium 适配器:Java(Maven / Gradle)与 Node(selenium-webdriver)项目。
3
+ *
4
+ * - Python + selenium 由 pytest 适配器覆盖(跑的是 pytest,结果也走 JUnit XML)。
5
+ * - 判定顺序:pom.xml → build.gradle → package.json(selenium-webdriver)。
6
+ * - 结果统一解析 JUnit / surefire XML;HTML 报告有就快照,没有就只给汇总。
7
+ */
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+
11
+ import {
12
+ emptySummary,
13
+ listFiles,
14
+ mergeSummaries,
15
+ parseJUnitXml,
16
+ readSmall,
17
+ text,
18
+ } from './shared.mjs';
19
+
20
+ export const id = 'selenium';
21
+ export const label = 'Selenium';
22
+ export const kind = 'ui';
23
+ export const controls = ['file', 'grep'];
24
+
25
+ const NODE_DEPS = ['selenium-webdriver', 'webdriverio'];
26
+
27
+ function findFlavor(probe) {
28
+ if (probe.hasPom) {
29
+ const pom = probe.readRel('pom.xml');
30
+ if (/selenium/i.test(pom)) return { flavor: 'maven', evidence: ['pom.xml: selenium'] };
31
+ }
32
+ if (probe.hasGradle) {
33
+ const gradle = probe.readRel('build.gradle') || probe.readRel('build.gradle.kts');
34
+ if (/selenium/i.test(gradle)) return { flavor: 'gradle', evidence: ['build.gradle: selenium'] };
35
+ }
36
+ for (const name of NODE_DEPS) {
37
+ if (probe.nodeDeps.has(name)) {
38
+ return { flavor: 'node', evidence: [`package.json: ${name}`] };
39
+ }
40
+ }
41
+ return null;
42
+ }
43
+
44
+ export function detect(probe) {
45
+ const found = findFlavor(probe);
46
+ if (!found) return null;
47
+ const score = found.flavor === 'maven' ? 96 : found.flavor === 'gradle' ? 92 : 86;
48
+ return { score, evidence: found.evidence };
49
+ }
50
+
51
+ function executable(dir, wrapper, fallback) {
52
+ const abs = path.join(dir, wrapper);
53
+ if (fs.existsSync(abs)) return abs;
54
+ return fallback;
55
+ }
56
+
57
+ export function ready(probe) {
58
+ if (probe.hasPom) return true;
59
+ if (probe.hasGradle) return true;
60
+ return typeof probe.pkg?.scripts?.test === 'string';
61
+ }
62
+
63
+ export function readyHint(probe) {
64
+ return `未找到可用的测试命令:Java 项目需要 mvn / gradle(或项目自带的 mvnw / gradlew),Node 项目需要在 package.json 里配置 scripts.test。`;
65
+ }
66
+
67
+ /** src/test/java/com/foo/LoginTest.java → LoginTest */
68
+ function javaClassName(rel) {
69
+ const base = path.basename(rel);
70
+ return base.replace(/\.(java|kt)$/i, '');
71
+ }
72
+
73
+ export function resolve(ctx) {
74
+ const found = findFlavor(ctx.probe);
75
+ const flavor = found?.flavor ?? 'maven';
76
+ const file = text(ctx.args.file, 1024);
77
+ const grep = text(ctx.args.grep, 200);
78
+
79
+ if (flavor === 'maven') {
80
+ const surefireDir = path.join(ctx.resultDirAbs, `${ctx.runId}-surefire`);
81
+ const args = ['-q', '-B', 'test', `-Dsurefire.reportsDirectory=${surefireDir}`];
82
+ const className = file ? javaClassName(file) : '';
83
+ if (className && grep) args.push(`-Dtest=${className}#${grep}`);
84
+ else if (className) args.push(`-Dtest=${className}`);
85
+ else if (grep) args.push(`-Dtest=${grep}`);
86
+ return {
87
+ command: executable(ctx.dir, 'mvnw', 'mvn'),
88
+ args,
89
+ env: { MAVEN_OPTS: process.env.MAVEN_OPTS ?? '-Dfile.encoding=UTF-8' },
90
+ };
91
+ }
92
+
93
+ if (flavor === 'gradle') {
94
+ const args = ['test', '--console=plain'];
95
+ const pattern = file ? javaClassName(file) : grep;
96
+ if (pattern) args.push('--tests', pattern);
97
+ return { command: executable(ctx.dir, 'gradlew', 'gradle'), args };
98
+ }
99
+
100
+ const pm = ctx.probe.packageManager;
101
+ const command = pm === 'pnpm' ? 'pnpm' : pm === 'yarn' ? 'yarn' : 'npm';
102
+ return { command, args: ['test'], env: { FORCE_COLOR: '0' } };
103
+ }
104
+
105
+ function parseXmlFiles(files) {
106
+ const summaries = files.map((file) => parseJUnitXml(readSmall(file.abs, 8 * 1024 * 1024)));
107
+ const merged = mergeSummaries(summaries);
108
+ return merged.total ? merged : emptySummary();
109
+ }
110
+
111
+ export function parse(ctx) {
112
+ const found = findFlavor(ctx.probe);
113
+ const flavor = found?.flavor ?? 'maven';
114
+ const minMtime = Date.parse(ctx.startedAt) || 0;
115
+
116
+ if (flavor === 'maven') {
117
+ const dir = path.join(ctx.resultDirAbs, `${ctx.runId}-surefire`);
118
+ return parseXmlFiles(listFiles(dir, { pattern: /\.xml$/i, maxDepth: 2 }));
119
+ }
120
+ if (flavor === 'gradle') {
121
+ const dir = path.join(ctx.dir, 'build', 'test-results', 'test');
122
+ return parseXmlFiles(listFiles(dir, { pattern: /\.xml$/i, minMtime, maxDepth: 3 }));
123
+ }
124
+ const candidates = [
125
+ path.join(ctx.dir, 'test-results'),
126
+ path.join(ctx.dir, 'reports'),
127
+ path.join(ctx.dir, 'build', 'test-results'),
128
+ ].filter((dir) => fs.existsSync(dir));
129
+ const files = candidates.flatMap((dir) =>
130
+ listFiles(dir, { pattern: /\.xml$/i, minMtime, maxDepth: 3 }),
131
+ );
132
+ return parseXmlFiles(files);
133
+ }
134
+
135
+ export function describeArgs(args) {
136
+ const parts = [];
137
+ if (args.file) parts.push(args.file);
138
+ if (args.grep) parts.push(args.grep);
139
+ return parts.length ? parts.join(' · ') : '全量';
140
+ }
141
+
142
+ /** 项目里可能存在的 HTML 报告目录(项目相对路径) */
143
+ export function reportDirs(probe) {
144
+ const found = findFlavor(probe);
145
+ if (found?.flavor === 'gradle') return ['build/reports/tests/test'];
146
+ if (found?.flavor === 'maven') return ['target/site', 'target/surefire-reports'];
147
+ return ['test-results', 'reports', 'mochawesome-report'];
148
+ }
149
+
150
+ export function hintFromLog(log) {
151
+ if (
152
+ /command not found: (mvn|gradle)|not recognized as an internal or external command/i.test(log)
153
+ ) {
154
+ return '本机找不到 Maven / Gradle:请先安装,或使用项目自带的 mvnw / gradlew。';
155
+ }
156
+ if (/Could not resolve dependencies|Non-resolvable parent POM/i.test(log)) {
157
+ return 'Maven 依赖下载失败:请检查网络 / 私服配置后再重试(插件不会自动安装依赖)。';
158
+ }
159
+ if (/Missing script: "test"/i.test(log)) {
160
+ return 'package.json 里没有 test 脚本:先补一个 scripts.test 再运行。';
161
+ }
162
+ return '';
163
+ }
@@ -0,0 +1,371 @@
1
+ /**
2
+ * 自动化测试适配器的公共工具:项目探针、JUnit XML 解析、文本小工具。
3
+ *
4
+ * 适配器只依赖这里的纯函数与 `fs`,不依赖插件本体,便于单测。
5
+ */
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+
9
+ export function text(value, max) {
10
+ if (typeof value !== 'string' && typeof value !== 'number') return '';
11
+ return String(value).trim().slice(0, max);
12
+ }
13
+
14
+ export function intOr(value, fallback, min, max) {
15
+ const n = Number(value);
16
+ if (!Number.isFinite(n)) return fallback;
17
+ return Math.min(max, Math.max(min, Math.trunc(n)));
18
+ }
19
+
20
+ export function toPosix(p) {
21
+ return p.split(path.sep).join('/');
22
+ }
23
+
24
+ /** 目录树 / 报告快照里一律跳过的名字(依赖、构建产物、缓存) */
25
+ export const IGNORED_NAMES = new Set([
26
+ 'node_modules',
27
+ '.git',
28
+ '.svn',
29
+ '.hg',
30
+ 'test-results',
31
+ 'playwright-report',
32
+ 'blob-report',
33
+ 'dist',
34
+ 'coverage',
35
+ '.next',
36
+ '.nuxt',
37
+ '.cache',
38
+ '.turbo',
39
+ '.DS_Store',
40
+ '__pycache__',
41
+ '.pytest_cache',
42
+ '.mypy_cache',
43
+ '.idea',
44
+ '.gradle',
45
+ '.venv',
46
+ 'venv',
47
+ ]);
48
+
49
+ /** 快照报告时额外跳过的文件后缀(体积大且对阅读报告没帮助) */
50
+ export const SNAPSHOT_SKIP_EXT = new Set(['.webm', '.mp4', '.zip', '.gz', '.tar']);
51
+
52
+ export function readSmall(abs, max = 256 * 1024) {
53
+ try {
54
+ const stat = fs.statSync(abs);
55
+ if (!stat.isFile()) return '';
56
+ const size = Math.min(stat.size, max);
57
+ const buffer = Buffer.alloc(size);
58
+ const fd = fs.openSync(abs, 'r');
59
+ try {
60
+ fs.readSync(fd, buffer, 0, size, 0);
61
+ } finally {
62
+ fs.closeSync(fd);
63
+ }
64
+ return buffer.toString('utf8');
65
+ } catch {
66
+ return '';
67
+ }
68
+ }
69
+
70
+ export function isDir(abs) {
71
+ try {
72
+ return fs.statSync(abs).isDirectory();
73
+ } catch {
74
+ return false;
75
+ }
76
+ }
77
+
78
+ function normalizeDepName(name) {
79
+ return String(name).trim().toLowerCase().replace(/_/g, '-');
80
+ }
81
+
82
+ /** requirements*.txt / Pipfile / pyproject.toml 里能认出来的 Python 依赖名 */
83
+ export function collectPythonDeps(dir) {
84
+ const deps = new Set();
85
+ const addLine = (line) => {
86
+ const clean = line.split('#')[0].trim();
87
+ if (!clean || clean.startsWith('-') || /^[.[]/.test(clean)) return;
88
+ const name = clean.split(/[<>=!~;\s[]/)[0].trim();
89
+ if (name) deps.add(normalizeDepName(name));
90
+ };
91
+ const readReqs = (file) => {
92
+ for (const line of readSmall(file).split(/\r?\n/)) addLine(line);
93
+ };
94
+
95
+ let names = [];
96
+ try {
97
+ names = fs.readdirSync(dir);
98
+ } catch {
99
+ names = [];
100
+ }
101
+ for (const name of names) {
102
+ if (name.endsWith('.txt') && /requirements/i.test(name)) readReqs(path.join(dir, name));
103
+ }
104
+ // requirements/ 子目录里常见的拆分写法
105
+ const nested = path.join(dir, 'requirements');
106
+ if (isDir(nested)) {
107
+ try {
108
+ for (const name of fs.readdirSync(nested)) {
109
+ if (name.endsWith('.txt')) readReqs(path.join(nested, name));
110
+ }
111
+ } catch {
112
+ // ignore
113
+ }
114
+ }
115
+
116
+ const pyproject = readSmall(path.join(dir, 'pyproject.toml'));
117
+ if (pyproject) {
118
+ // PEP 621 / dependency-groups 里是带引号的依赖字符串,例如 "pytest>=8.3.0",
119
+ // 允许行尾注释与 extras,只取包名,避免把 markers / 表键当成依赖
120
+ const quotedRe = /"([A-Za-z0-9][A-Za-z0-9_.-]*)\s*(?:\[[^\]]*\])?\s*(?:[<>=!~][^"]*)?"/g;
121
+ let match;
122
+ while ((match = quotedRe.exec(pyproject))) {
123
+ const name = normalizeDepName(match[1]);
124
+ // 过滤 ruff 的 "E" / "F" 与纯版本号,减少误报
125
+ if (name.length < 2 || /^\d/.test(name)) continue;
126
+ deps.add(name);
127
+ }
128
+
129
+ // Poetry 用表格式依赖(selenium = "^4"),只在 dependencies 段里认
130
+ let inPoetryDeps = false;
131
+ for (const line of pyproject.split(/\r?\n/)) {
132
+ const header = /^\s*\[([^\]]+)\]\s*$/.exec(line);
133
+ if (header) {
134
+ inPoetryDeps = /^tool\.poetry(\.group\.[^.]+)?\.(dev-)?dependencies$/.test(header[1]);
135
+ continue;
136
+ }
137
+ if (!inPoetryDeps) continue;
138
+ const kv = /^\s*([A-Za-z0-9_.-]+)\s*=/i.exec(line);
139
+ if (kv) deps.add(normalizeDepName(kv[1]));
140
+ }
141
+ }
142
+
143
+ const pipfile = readSmall(path.join(dir, 'Pipfile'));
144
+ if (pipfile) {
145
+ let inPackages = false;
146
+ for (const line of pipfile.split(/\r?\n/)) {
147
+ const header = /^\s*\[([^\]]+)\]\s*$/.exec(line);
148
+ if (header) {
149
+ inPackages = /^(packages|dev-packages)$/i.test(header[1]);
150
+ continue;
151
+ }
152
+ if (!inPackages) continue;
153
+ const match = /^\s*([A-Za-z0-9_.-]+)\s*=/i.exec(line);
154
+ if (match) deps.add(normalizeDepName(match[1]));
155
+ }
156
+ }
157
+ return deps;
158
+ }
159
+
160
+ /** 目录里是否存在匹配的文件名(最多走 depth 层) */
161
+ export function hasFileMatching(dir, pattern, depth = 3, limit = 2000) {
162
+ let seen = 0;
163
+ const walk = (abs, level) => {
164
+ if (level > depth) return false;
165
+ let items;
166
+ try {
167
+ items = fs.readdirSync(abs, { withFileTypes: true });
168
+ } catch {
169
+ return false;
170
+ }
171
+ for (const item of items) {
172
+ if (IGNORED_NAMES.has(item.name)) continue;
173
+ seen += 1;
174
+ if (seen > limit) return false;
175
+ if (item.isDirectory()) {
176
+ if (walk(path.join(abs, item.name), level + 1)) return true;
177
+ } else if (pattern.test(item.name)) {
178
+ return true;
179
+ }
180
+ }
181
+ return false;
182
+ };
183
+ return walk(dir, 0);
184
+ }
185
+
186
+ /**
187
+ * 一次性收集识别框架需要的证据,避免每个适配器各扫一遍目录。
188
+ * @param {string} dir
189
+ */
190
+ export function buildProbe(dir) {
191
+ const exists = isDir(dir);
192
+ const existsRel = (rel) => Boolean(exists && fs.existsSync(path.join(dir, rel)));
193
+ const readRel = (rel, max) => (exists ? readSmall(path.join(dir, rel), max) : '');
194
+
195
+ let pkg = null;
196
+ const pkgText = readRel('package.json');
197
+ if (pkgText) {
198
+ try {
199
+ pkg = JSON.parse(pkgText);
200
+ } catch {
201
+ pkg = null;
202
+ }
203
+ }
204
+
205
+ const nodeDeps = new Set();
206
+ for (const key of ['dependencies', 'devDependencies', 'peerDependencies']) {
207
+ for (const name of Object.keys(pkg?.[key] ?? {})) nodeDeps.add(name);
208
+ }
209
+
210
+ let packageManager = '';
211
+ if (typeof pkg?.packageManager === 'string' && pkg.packageManager) {
212
+ packageManager = pkg.packageManager.split('@')[0] || '';
213
+ }
214
+ if (!packageManager && existsRel('pnpm-lock.yaml')) packageManager = 'pnpm';
215
+ else if (!packageManager && existsRel('yarn.lock')) packageManager = 'yarn';
216
+ else if (!packageManager && existsRel('package-lock.json')) packageManager = 'npm';
217
+
218
+ const pythonDeps = exists ? collectPythonDeps(dir) : new Set();
219
+ const hasPythonTests = exists && hasFileMatching(dir, /^(test_.*|.*_test)\.py$/);
220
+
221
+ return {
222
+ dir,
223
+ exists,
224
+ existsRel,
225
+ readRel,
226
+ pkg,
227
+ nodeDeps,
228
+ pythonDeps,
229
+ hasPythonTests,
230
+ packageManager,
231
+ hasPom: existsRel('pom.xml'),
232
+ hasGradle: existsRel('build.gradle') || existsRel('build.gradle.kts'),
233
+ };
234
+ }
235
+
236
+ function decodeXml(value) {
237
+ return value
238
+ .replace(/&lt;/g, '<')
239
+ .replace(/&gt;/g, '>')
240
+ .replace(/&quot;/g, '"')
241
+ .replace(/&#39;|&apos;/g, "'")
242
+ .replace(/&#(\d+);/g, (_, code) => String.fromCharCode(Number(code)))
243
+ .replace(/&amp;/g, '&');
244
+ }
245
+
246
+ function parseAttrs(raw) {
247
+ const attrs = {};
248
+ const re = /([\w:-]+)\s*=\s*"([^"]*)"/g;
249
+ let match;
250
+ while ((match = re.exec(raw))) attrs[match[1]] = decodeXml(match[2]);
251
+ return attrs;
252
+ }
253
+
254
+ export function emptySummary() {
255
+ return {
256
+ total: 0,
257
+ passed: 0,
258
+ failed: 0,
259
+ skipped: 0,
260
+ flaky: 0,
261
+ durationMs: 0,
262
+ errors: [],
263
+ failedTests: [],
264
+ projectNames: [],
265
+ };
266
+ }
267
+
268
+ /**
269
+ * 解析 JUnit XML(pytest --junitxml、Maven surefire、Gradle test、mocha junit reporter 通用)。
270
+ * @param {string} xml
271
+ */
272
+ export function parseJUnitXml(xml) {
273
+ const summary = emptySummary();
274
+ if (typeof xml !== 'string' || !xml.trim()) return summary;
275
+
276
+ const re = /<testcase\b([^>]*?)(?:\/>|>([\s\S]*?)<\/testcase>)/g;
277
+ let match;
278
+ let durationMs = 0;
279
+ let seen = 0;
280
+ while ((match = re.exec(xml))) {
281
+ seen += 1;
282
+ if (seen > 50_000) break;
283
+ const attrs = parseAttrs(match[1]);
284
+ const body = match[2] || '';
285
+ summary.total += 1;
286
+
287
+ const seconds = Number(attrs.time);
288
+ if (Number.isFinite(seconds) && seconds > 0) durationMs += seconds * 1000;
289
+
290
+ if (/<skipped\b/.test(body)) {
291
+ summary.skipped += 1;
292
+ continue;
293
+ }
294
+ if (/<(failure|error)\b/.test(body)) {
295
+ summary.failed += 1;
296
+ const title = [attrs.classname, attrs.name].filter(Boolean).join(' › ') || '未命名用例';
297
+ if (summary.failedTests.length < 50) {
298
+ summary.failedTests.push({ title, file: attrs.file || '' });
299
+ }
300
+ if (/<error\b/.test(body) && summary.errors.length < 20) {
301
+ const tag = /<(?:failure|error)\b([^>]*)>([\s\S]{0,2000})/.exec(body);
302
+ const message = tag ? text(tag[1].match(/message\s*=\s*"([^"]*)"/)?.[1], 2000) : '';
303
+ const detail = tag ? text(decodeXml(tag[2]).split(/\r?\n/)[0], 2000) : '';
304
+ const value = message || detail;
305
+ if (value) summary.errors.push(value);
306
+ }
307
+ continue;
308
+ }
309
+ summary.passed += 1;
310
+ }
311
+ summary.durationMs = Math.round(durationMs);
312
+ return summary;
313
+ }
314
+
315
+ /** 把多个 JUnit 文件的结果合并成一个汇总(按 testcase 计,不重复) */
316
+ export function mergeSummaries(list) {
317
+ const out = emptySummary();
318
+ for (const item of list) {
319
+ if (!item) continue;
320
+ out.total += item.total;
321
+ out.passed += item.passed;
322
+ out.failed += item.failed;
323
+ out.skipped += item.skipped;
324
+ out.flaky += item.flaky;
325
+ out.durationMs += item.durationMs;
326
+ for (const err of item.errors ?? []) {
327
+ if (out.errors.length < 20) out.errors.push(err);
328
+ }
329
+ for (const failed of item.failedTests ?? []) {
330
+ if (out.failedTests.length < 50) out.failedTests.push(failed);
331
+ }
332
+ for (const name of item.projectNames ?? []) {
333
+ if (!out.projectNames.includes(name)) out.projectNames.push(name);
334
+ }
335
+ }
336
+ return out;
337
+ }
338
+
339
+ /** 列出目录里符合条件的文件(新→旧),供解析报告 / 结果用 */
340
+ export function listFiles(dir, { pattern, minMtime = 0, maxDepth = 4, limit = 200 } = {}) {
341
+ const out = [];
342
+ const walk = (abs, level) => {
343
+ if (level > maxDepth || out.length >= limit) return;
344
+ let items;
345
+ try {
346
+ items = fs.readdirSync(abs, { withFileTypes: true });
347
+ } catch {
348
+ return;
349
+ }
350
+ for (const item of items) {
351
+ if (out.length >= limit) return;
352
+ if (IGNORED_NAMES.has(item.name)) continue;
353
+ const child = path.join(abs, item.name);
354
+ if (item.isDirectory()) {
355
+ walk(child, level + 1);
356
+ continue;
357
+ }
358
+ if (pattern && !pattern.test(item.name)) continue;
359
+ let stat;
360
+ try {
361
+ stat = fs.statSync(child);
362
+ } catch {
363
+ continue;
364
+ }
365
+ if (stat.mtimeMs < minMtime) continue;
366
+ out.push({ abs: child, mtimeMs: stat.mtimeMs, size: stat.size });
367
+ }
368
+ };
369
+ walk(dir, 0);
370
+ return out.sort((a, b) => b.mtimeMs - a.mtimeMs);
371
+ }