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,369 @@
1
+ /**
2
+ * 「运行任务」发现。
3
+ *
4
+ * 对齐 Jenkins 的参数化构建:项目里本来就声明好的跑法(`package.json` 的 scripts、
5
+ * `Makefile` 的 target、pytest 的 markers、Maven 的 profiles)直接整理成下拉候选,
6
+ * 而不是替用户猜一条命令。纯函数,方便单测。
7
+ *
8
+ * 每个任务统一成:
9
+ * { id, label, display, base, args, hint, kind, failureFlags, custom }
10
+ * - `base` + `args` 拼出实际命令(走 shell 执行)
11
+ * - `failureFlags` 表示这条任务能不能追加「仅上次失败 / 遇到失败即停」
12
+ */
13
+ import fs from 'node:fs';
14
+ import path from 'node:path';
15
+
16
+ import { text } from './shared.mjs';
17
+
18
+ export const MAX_RUN_TASKS = 20;
19
+ export const CUSTOM_TASK_LIMIT = 20;
20
+
21
+ /** 要跑哪些 script:名字像测试的;排除 lint / format / 打开报告这类 */
22
+ const NODE_SCRIPT_ALLOW =
23
+ /^(test|tests|e2e|ui|api|smoke|regression|edge|sanity|spec|allure|report)([:._-].*)?$/i;
24
+ const NODE_SCRIPT_DENY =
25
+ /(lint|format|prepare|husky|install|build|serve|start|dev|watch|debug|open|show|clean|postinstall|pretest)/i;
26
+ /** 交互式命令挂后台会一直不退出,直接跳过 */
27
+ const INTERACTIVE = /(--ui\b|--debug\b|--watch\b|show-report|allure open|--headed\b)/;
28
+
29
+ /** Makefile 里要的目标 / 明显不是测试的目标 */
30
+ const MAKE_ALLOW = /(test|spec|smoke|regress|e2e|sanity|unit|contract|integration|api|ui|p0|p1)/i;
31
+ const MAKE_DENY =
32
+ /^(all|help|install|build|clean|lint|format|format-check|type|check|deps|lock|docker|dev|run|serve|export|version|pre-commit)$/i;
33
+
34
+ const PYTEST_TASK_MARKER = /^[\w.:-]+$/;
35
+
36
+ export function quoteIfNeeded(value) {
37
+ const raw = String(value ?? '');
38
+ return /\s/.test(raw) ? `"${raw.replace(/"/g, '\\"')}"` : raw;
39
+ }
40
+
41
+ /** 包管理器的 `run`:pnpm / yarn / npm,未知按 npm */
42
+ export function packageManagerRunner(packageManager) {
43
+ if (packageManager === 'pnpm') return { command: 'pnpm', args: ['run'] };
44
+ if (packageManager === 'yarn') return { command: 'yarn', args: ['run'] };
45
+ return { command: 'npm', args: ['run'] };
46
+ }
47
+
48
+ /** package.json 里哪些 script 值得放出来 */
49
+ export function pickRunScripts(scripts) {
50
+ const entries = scripts && typeof scripts === 'object' ? Object.entries(scripts) : [];
51
+ const picked = [];
52
+ for (const [name, body] of entries) {
53
+ if (!NODE_SCRIPT_ALLOW.test(name)) continue;
54
+ if (NODE_SCRIPT_DENY.test(name)) continue;
55
+ if (typeof body !== 'string') continue;
56
+ if (INTERACTIVE.test(body)) continue;
57
+ picked.push({ name, body });
58
+ }
59
+ // test 永远是第一个,其余按名字排序,避免每次刷新顺序都变
60
+ picked.sort((a, b) => {
61
+ if (a.name === 'test') return -1;
62
+ if (b.name === 'test') return 1;
63
+ return a.name.localeCompare(b.name);
64
+ });
65
+ return picked;
66
+ }
67
+
68
+ export function discoverNodeScripts(probe) {
69
+ const runner = packageManagerRunner(probe.packageManager);
70
+ return pickRunScripts(probe.pkg?.scripts).map(({ name, body }) => {
71
+ const isPlaywright = /playwright/i.test(body);
72
+ const label = `${runner.command} run ${name}`;
73
+ return {
74
+ id: `script:${name}`,
75
+ label,
76
+ display: name,
77
+ base: label,
78
+ // npm / pnpm / yarn 都能把 `--` 之后的参数透传给脚本;
79
+ // Playwright 脚本追加 reporters 才拿得到 JSON 汇总
80
+ args: isPlaywright ? ['--', '--reporter=list,json,html'] : [],
81
+ hint: body.trim().slice(0, 120),
82
+ kind: 'script',
83
+ failureFlags: isPlaywright,
84
+ custom: false,
85
+ };
86
+ });
87
+ }
88
+
89
+ /** 解析 Makefile:`target: ## 说明`,只取像测试的目标 */
90
+ export function parseMakeTargets(raw) {
91
+ const text_ = String(raw ?? '');
92
+ const out = [];
93
+ const seen = new Set();
94
+ for (const line of text_.split(/\r?\n/)) {
95
+ const match = /^([A-Za-z0-9][\w.-]*)\s*:(?!=)/.exec(line);
96
+ if (!match) continue;
97
+ const name = match[1];
98
+ if (seen.has(name)) continue;
99
+ if (!MAKE_ALLOW.test(name) || MAKE_DENY.test(name)) continue;
100
+ seen.add(name);
101
+ const hint = /##\s*(.+)$/.exec(line)?.[1]?.trim() ?? '';
102
+ out.push({ name, hint });
103
+ }
104
+ return out;
105
+ }
106
+
107
+ export function discoverMakeTargets(probe) {
108
+ const makefile = probe.readRel('Makefile', 64 * 1024) || probe.readRel('makefile', 64 * 1024);
109
+ if (!makefile) return [];
110
+ return parseMakeTargets(makefile).map(({ name, hint }) => ({
111
+ id: `make:${name}`,
112
+ label: `make ${name}`,
113
+ display: name,
114
+ base: `make ${name}`,
115
+ args: [],
116
+ hint,
117
+ kind: 'make',
118
+ // make 目标里怎么跑由项目自己决定,不往里追加参数
119
+ failureFlags: false,
120
+ custom: false,
121
+ }));
122
+ }
123
+
124
+ /** pytest markers:`[tool.pytest.ini_options] markers = [...]` 或 pytest.ini 的 `markers =` */
125
+ export function parsePytestMarkers({ pyproject = '', ini = '' } = {}) {
126
+ const out = [];
127
+ const seen = new Set();
128
+ const push = (name, hint) => {
129
+ const marker = name.trim();
130
+ if (!marker || seen.has(marker) || !PYTEST_TASK_MARKER.test(marker)) return;
131
+ seen.add(marker);
132
+ out.push({ name: marker, hint: hint.trim().slice(0, 80) });
133
+ };
134
+
135
+ // pyproject:markers = ["smoke: 核心主流程", ...](可能跨行)
136
+ const block = /\[tool\.pytest\.ini_options\]([\s\S]*?)(?:\n\[|$)/.exec(pyproject)?.[1] ?? '';
137
+ const arrayMatch = /markers\s*=\s*\[([\s\S]*?)\]/.exec(block);
138
+ if (arrayMatch) {
139
+ for (const item of arrayMatch[1].matchAll(/["']([^"']+)["']/g)) {
140
+ const [name, ...rest] = item[1].split(':');
141
+ push(name, rest.join(':'));
142
+ }
143
+ }
144
+
145
+ // pytest.ini / setup.cfg:markers = 后每行 `name: 说明`
146
+ const iniBlock = /(?:^|\n)markers\s*=\s*\n((?:[ \t]+.+\n?)+)/.exec(ini)?.[1] ?? '';
147
+ for (const line of iniBlock.split(/\r?\n/)) {
148
+ const trimmed = line.trim();
149
+ if (!trimmed) continue;
150
+ const [name, ...rest] = trimmed.split(':');
151
+ push(name, rest.join(':'));
152
+ }
153
+ return out;
154
+ }
155
+
156
+ /**
157
+ * Python 解释器:与 pytest 适配器同一套顺序(虚拟环境 → uv / poetry → python3),
158
+ * 这里单独实现一份,免得 tasks 反向依赖适配器。
159
+ */
160
+ export function detectPythonCommand(dir) {
161
+ const win = process.platform === 'win32';
162
+ const venv = win
163
+ ? ['.venv/Scripts/python.exe', 'venv/Scripts/python.exe']
164
+ : ['.venv/bin/python', 'venv/bin/python', '.venv/bin/python3', 'venv/bin/python3'];
165
+ for (const rel of venv) {
166
+ if (fs.existsSync(path.join(dir, rel))) return `${quoteIfNeeded(rel)} -m pytest`;
167
+ }
168
+ if (fs.existsSync(path.join(dir, 'uv.lock'))) return 'uv run python -m pytest';
169
+ if (fs.existsSync(path.join(dir, 'poetry.lock'))) return 'poetry run python -m pytest';
170
+ return `${win ? 'python' : 'python3'} -m pytest`;
171
+ }
172
+
173
+ export function discoverPytestMarkers(probe) {
174
+ const markers = parsePytestMarkers({
175
+ pyproject: probe.readRel('pyproject.toml', 128 * 1024),
176
+ ini: probe.readRel('pytest.ini', 64 * 1024) || probe.readRel('setup.cfg', 64 * 1024),
177
+ });
178
+ const interpreter = detectPythonCommand(probe.dir);
179
+ return markers.map(({ name, hint }) => ({
180
+ id: `marker:${name}`,
181
+ label: `pytest -m ${name}`,
182
+ display: name,
183
+ base: interpreter,
184
+ args: ['-m', name],
185
+ hint,
186
+ kind: 'pytest',
187
+ failureFlags: true,
188
+ custom: false,
189
+ }));
190
+ }
191
+
192
+ /** Maven profiles:`mvn test -P<id>` */
193
+ export function parseMavenProfiles(raw) {
194
+ const out = [];
195
+ const seen = new Set();
196
+ const xml = String(raw ?? '');
197
+ for (const block of xml.matchAll(/<profile>([\s\S]*?)<\/profile>/g)) {
198
+ const id = /<id>\s*([^<]+?)\s*<\/id>/.exec(block[1])?.[1]?.trim();
199
+ if (!id || seen.has(id)) continue;
200
+ // `-P` 只接受简单标识,带空格 / 中文的 profile 名跳过
201
+ if (!/^[\w.-]+$/.test(id)) continue;
202
+ seen.add(id);
203
+ out.push({ id });
204
+ }
205
+ return out;
206
+ }
207
+
208
+ export function discoverMavenTasks(probe) {
209
+ const pom = probe.readRel('pom.xml', 256 * 1024);
210
+ if (!pom) return [];
211
+ const mvn = fs.existsSync(path.join(probe.dir, 'mvnw')) ? './mvnw' : 'mvn';
212
+ return parseMavenProfiles(pom).map(({ id }) => ({
213
+ id: `profile:${id}`,
214
+ label: `${mvn} test -P${id}`,
215
+ display: id,
216
+ base: `${mvn} test`,
217
+ args: [`-P${id}`],
218
+ hint: `Maven profile ${id}`,
219
+ kind: 'maven',
220
+ failureFlags: false,
221
+ custom: false,
222
+ }));
223
+ }
224
+
225
+ /**
226
+ * 一个项目能跑的「任务」清单(不含「全量运行」,那项固定排第一,由调用方补)。
227
+ * @param {object} probe buildProbe 的结果
228
+ * @param {string} framework playwright / pytest / selenium
229
+ */
230
+ export function discoverRunTasks(probe, framework) {
231
+ if (!probe?.exists) return [];
232
+ let tasks = [];
233
+ if (framework === 'pytest') {
234
+ tasks = [...discoverMakeTargets(probe), ...discoverPytestMarkers(probe)];
235
+ } else if (framework === 'selenium' && (probe.hasPom || probe.hasGradle)) {
236
+ tasks = discoverMavenTasks(probe);
237
+ } else {
238
+ tasks = discoverNodeScripts(probe);
239
+ }
240
+ // 同一个 label 只留第一条(Makefile 和 marker 常常同名)
241
+ const seen = new Set();
242
+ return tasks
243
+ .filter((task) => {
244
+ if (seen.has(task.label)) return false;
245
+ seen.add(task.label);
246
+ return true;
247
+ })
248
+ .slice(0, MAX_RUN_TASKS);
249
+ }
250
+
251
+ /** 自定义任务:只保留名称 + 命令,走 shell 执行(名称为空时下拉里直接显示命令) */
252
+ export function normalizeCustomTasks(raw) {
253
+ if (!Array.isArray(raw)) return [];
254
+ const out = [];
255
+ for (const item of raw.slice(0, CUSTOM_TASK_LIMIT)) {
256
+ if (!item || typeof item !== 'object') continue;
257
+ const command = text(item.command, 1000).trim();
258
+ if (!command) continue;
259
+ const name = text(item.name, 60).trim();
260
+ const id = text(item.id, 64) || `ut_${out.length}_${Math.random().toString(36).slice(2, 8)}`;
261
+ out.push({ id, name, command });
262
+ }
263
+ return out;
264
+ }
265
+
266
+ /** 自定义任务 → 下拉里的任务(base 就是用户写的命令本身) */
267
+ export function customToTasks(customTasks) {
268
+ return normalizeCustomTasks(customTasks).map(({ id, name, command }) => ({
269
+ id,
270
+ // 有名称显示「名称(命令)」,没名称就直接显示命令
271
+ label: name ? `${name}(${command})` : command,
272
+ display: name || command,
273
+ base: command,
274
+ args: [],
275
+ hint: name ? command : '',
276
+ kind: 'custom',
277
+ failureFlags: false,
278
+ custom: true,
279
+ }));
280
+ }
281
+
282
+ /** 用户对自动发现任务的改动(名称 / 命令),按任务 id 存 */
283
+ export function normalizeTaskOverrides(raw) {
284
+ if (!Array.isArray(raw)) return [];
285
+ const out = [];
286
+ for (const item of raw.slice(0, MAX_RUN_TASKS)) {
287
+ if (!item || typeof item !== 'object') continue;
288
+ const id = text(item.id, 64);
289
+ if (!id || id === 'full') continue;
290
+ out.push({
291
+ id,
292
+ name: text(item.name, 60).trim(),
293
+ command: text(item.command, 1000).trim(),
294
+ });
295
+ }
296
+ return out;
297
+ }
298
+
299
+ /** 隐藏掉的自动发现任务 id(用户在运行配置里删掉的) */
300
+ export function normalizeHiddenTaskIds(raw) {
301
+ if (!Array.isArray(raw)) return [];
302
+ const seen = new Set();
303
+ const out = [];
304
+ for (const item of raw) {
305
+ const id = text(item, 64);
306
+ if (!id || id === 'full' || seen.has(id)) continue;
307
+ seen.add(id);
308
+ out.push(id);
309
+ }
310
+ return out.slice(0, MAX_RUN_TASKS);
311
+ }
312
+
313
+ /**
314
+ * 把用户对自动发现任务的改动套上去:
315
+ * - 删掉的直接不返回;
316
+ * - 改过命令的换成原样的 shell 命令,不再追加框架参数(`--lf` 之类塞给自定义命令没意义);
317
+ * - 改过名称的只换显示名,命令保持原样。
318
+ */
319
+ export function applyTaskOverrides(tasks, overrides, hiddenIds) {
320
+ const edits = new Map(normalizeTaskOverrides(overrides).map((item) => [item.id, item]));
321
+ const hidden = new Set(normalizeHiddenTaskIds(hiddenIds));
322
+ const out = [];
323
+ for (const task of tasks) {
324
+ if (hidden.has(task.id)) continue;
325
+ const edit = edits.get(task.id);
326
+ if (!edit) {
327
+ out.push(task);
328
+ continue;
329
+ }
330
+ const command = edit.command || taskCommandLine(task);
331
+ const name = edit.name || task.display || '';
332
+ out.push({
333
+ ...task,
334
+ base: command,
335
+ args: [],
336
+ failureFlags: false,
337
+ display: name,
338
+ label: name ? `${name}(${command})` : command,
339
+ hint: edit.name ? command : task.hint,
340
+ edited: true,
341
+ });
342
+ }
343
+ return out;
344
+ }
345
+
346
+ /** 任务最终执行的命令行(shell 用) */
347
+ export function taskCommandLine(task, flags = {}) {
348
+ const parts = [task.base, ...(task.args ?? [])];
349
+ if (task.failureFlags) {
350
+ if (flags.lastFailed) parts.push(task.kind === 'pytest' ? '--lf' : '--last-failed');
351
+ if (flags.bail) parts.push(task.kind === 'pytest' ? '-x' : '--max-failures=1');
352
+ }
353
+ return parts.filter(Boolean).join(' ');
354
+ }
355
+
356
+ /** 给前端看的任务(去掉执行细节,只留能显示 / 能选的部分) */
357
+ export function taskView(task) {
358
+ return {
359
+ id: task.id,
360
+ label: task.label,
361
+ display: task.display,
362
+ hint: task.hint,
363
+ kind: task.kind,
364
+ failureFlags: task.failureFlags,
365
+ custom: task.custom,
366
+ edited: Boolean(task.edited),
367
+ command: taskCommandLine(task),
368
+ };
369
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 预加载守卫(`NODE_OPTIONS=--require`):给 Playwright 的 `--project` 参数让路。
3
+ *
4
+ * 有些项目的 playwright.config 会 `import 'tsconfig-paths/register'`;这个包在注册时会用
5
+ * minimist 解析 `process.argv` 的 `--project/-P`,把项目名当成 tsconfig 路径,
6
+ * 直接 `ENOENT: stat 'chromium-admin'` 崩掉(Playwright 自己其实解析得很好)。
7
+ *
8
+ * 这里只在加载 tsconfig-paths 注册器的那一瞬间把那两个参数从 argv 里摘掉,加载完立刻还原,
9
+ * 不影响 Playwright 自己读参数。
10
+ */
11
+ 'use strict';
12
+
13
+ const Module = require('module');
14
+ const originalLoad = Module._load;
15
+
16
+ function stripProjectFlag(argv) {
17
+ const out = [];
18
+ for (let i = 0; i < argv.length; i += 1) {
19
+ const arg = String(argv[i]);
20
+ if (arg === '--project' || arg === '-P') {
21
+ i += 1;
22
+ continue;
23
+ }
24
+ if (arg.startsWith('--project=')) continue;
25
+ out.push(argv[i]);
26
+ }
27
+ return out;
28
+ }
29
+
30
+ Module._load = function load(request, parent, isMain) {
31
+ if (typeof request === 'string' && /(^|[\\/])tsconfig-paths[\\/]register(\.js)?$/.test(request)) {
32
+ const saved = process.argv.slice();
33
+ process.argv = stripProjectFlag(process.argv);
34
+ try {
35
+ return originalLoad.call(this, request, parent, isMain);
36
+ } finally {
37
+ process.argv = saved;
38
+ }
39
+ }
40
+ return originalLoad.call(this, request, parent, isMain);
41
+ };