lantern-harness 0.1.9 → 0.1.11
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 +90 -0
- package/README.md +6 -6
- package/builtin/session/lh-fs.mjs +32 -14
- package/dist/500.html +258 -22
- package/dist/_astro/Base.Bgxs1QQl.css +1 -0
- package/dist/_astro/Base.astro_astro_type_script_index_0_lang.CvbRi7Tl.js +1 -0
- package/dist/_astro/CaseExecBoard.Dttqp0wg.js +1 -0
- package/dist/_astro/CaseGenerateApp.DqW_nWMc.js +9 -0
- package/dist/_astro/CasesLibrary.8aMUUGp_.js +1 -0
- package/dist/_astro/ChatApp.BLxf0h1d.js +219 -0
- package/dist/_astro/ColumnResize.BEkEW7qw.js +1 -0
- package/dist/_astro/{ConfirmDialog.CBVsDJ8f.js → ConfirmDialog.BZzZWDci.js} +1 -1
- package/dist/_astro/{DashboardBoard.DCtfrrJz.js → DashboardBoard.CkSbhEDI.js} +3 -3
- package/dist/_astro/DatePicker.Bkl71M49.js +1 -0
- package/dist/_astro/DocsFileBrowser.MKVCfZrE.js +1 -0
- package/dist/_astro/DocsPager.DJY4foYL.js +1 -0
- package/dist/_astro/{DrawerField.CWMLhcPX.js → DrawerField.CHRg77LG.js} +1 -1
- package/dist/_astro/{ExcelFieldTags.B_XMwNNx.js → ExcelFieldTags.DXMeaDa5.js} +4 -4
- package/dist/_astro/KnowledgeLibrary.B-p1aoQN.js +1 -0
- package/dist/_astro/NamePromptDialog.Wa9O530a.js +1 -0
- package/dist/_astro/NavLibraries.C6LImMO_.js +1 -0
- package/dist/_astro/OverflowHint.D6v4Uj2N.js +1 -0
- package/dist/_astro/PluginsPage.-97n3x2U.js +39 -0
- package/dist/_astro/PluginsPage.DkmRPfbU.js +1 -0
- package/dist/_astro/PmBugsBoard.CMT4-eoB.js +1 -0
- package/dist/_astro/PmIterationsBoard.BQM_dzdZ.js +1 -0
- package/dist/_astro/PmProjectDetail.CzU80pat.js +1 -0
- package/dist/_astro/PmProjectsBoard.Cxsa7SYQ.js +1 -0
- package/dist/_astro/PmRequirementsBoard.4_JMDDN0.js +1 -0
- package/dist/_astro/PmRequirementsBoard.B8HL07cw.js +1 -0
- package/dist/_astro/PmShared.Ca2Ao7v_.js +1 -0
- package/dist/_astro/PromptsLibrary.C9BcIxKK.js +1 -0
- package/dist/_astro/ReportsPage.Fh5DRKLT.js +1 -0
- package/dist/_astro/RequirementsLibrary.CBkuWE8X.js +1 -0
- package/dist/_astro/SearchableSelect.DnjoSslK.js +1 -0
- package/dist/_astro/SelectDropdown.CuuDHa8s.js +1 -0
- package/dist/_astro/SettingsDialog.CVB5Gtk4.js +1 -0
- package/dist/_astro/SlideOverDrawer.B7B5Wu8I.js +1 -0
- package/dist/_astro/{SpaceSwitcher.CI3KDBOA.js → SpaceSwitcher.BVQLt_tL.js} +2 -2
- package/dist/_astro/TagSelect.CuN5RdF4.js +1 -0
- package/dist/_astro/TasksBoard.Bu-fpIZ7.js +1 -0
- package/dist/_astro/TemplatesLibrary.DSylQGlN.js +1 -0
- package/dist/_astro/TestStatsBoard.CPyKW4wc.js +1 -0
- package/dist/_astro/Toast.R8_2OWRX.js +1 -0
- package/dist/_astro/TodosBoard.8kvRTEW-.js +1 -0
- package/dist/_astro/UiAutoBoard.DFTiDqCp.js +9 -0
- package/dist/_astro/active-element-history.CED-m1Zp.js +1 -0
- package/dist/_astro/app-config.BUPzGl9f.js +1 -0
- package/dist/_astro/{client.Be_SakrB.js → client.BHNTqLjv.js} +3 -3
- package/dist/_astro/dialog.BAPTk9a_.js +1 -0
- package/dist/_astro/hydrate-cache.BXX604Bw.js +1 -0
- package/dist/_astro/{i18n.B52gLzii.js → i18n.BGPnP1Bg.js} +1 -1
- package/dist/_astro/index.astro_astro_type_script_index_0_lang.LPL9mPQY.js +1 -0
- package/dist/_astro/jsx-runtime.DUg_B_vD.js +1 -0
- package/dist/_astro/{lib.DJNDi_Ht.js → lib.CgXLzMMd.js} +15 -15
- package/dist/_astro/listbox.C96OCanh.js +1 -0
- package/dist/_astro/markdown-client.DRva7DS9.js +58 -0
- package/dist/_astro/menu.IPWdRoNM.js +1 -0
- package/dist/_astro/{open-docs-in-session.Xg3OSOfc.js → open-docs-in-session.CyFNgh1I.js} +1 -1
- package/dist/_astro/{plugins.BDZqJNOy.js → plugins.C2BMfzv1.js} +1 -1
- package/dist/_astro/{pm.Bl3hz9fF.js → pm.CagBA-ht.js} +2 -2
- package/dist/_astro/{portal.Cm9XlIPf.js → portal.C0hAhXDF.js} +2 -2
- package/dist/_astro/prompts-meta.Bua-j14I.js +2 -0
- package/dist/_astro/react-dom.DLW9pGCF.js +1 -0
- package/dist/_astro/{react-dom.CqAxpHMt.js → react.Blvh0GOs.js} +1 -1
- package/dist/_astro/report-prompt.CAfZ6RIo.js +1 -0
- package/dist/_astro/{settings.C6NWuiFO.js → settings.Ceefeil5.js} +2 -2
- package/dist/_astro/{spaces-client.k_ciWMai.js → spaces-client.BocUabwy.js} +1 -1
- package/dist/_astro/ui-auto-prompt.CX8fju7r.js +3 -0
- package/dist/_astro/ui-auto.BmC9JJ_X.js +1 -0
- package/dist/_astro/update.CtF8vsag.js +1 -0
- package/dist/_astro/use-text-value.DBQvHeNl.js +1 -0
- package/dist/_astro/use-tree-walker.DFU2AaAP.js +1 -0
- package/dist/_astro/useListAnim.BoerpmsB.js +1 -0
- package/dist/_astro/{view-prefs.Dyu_lmN2.js → view-prefs.BEAZRcxF.js} +1 -1
- package/dist/case-exec/index.html +458 -22
- package/dist/cases/generate/index.html +258 -22
- package/dist/cases/library/index.html +458 -22
- package/dist/dashboard/index.html +458 -22
- package/dist/docs/changelog/index.html +373 -23
- package/dist/docs/install/index.html +258 -22
- package/dist/docs/manual/index.html +314 -35
- package/dist/index.html +2 -281
- package/dist/knowledge/index.html +458 -22
- 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
- package/dist/plugins/index.html +258 -22
- package/dist/pm/bugs/index.html +458 -22
- package/dist/pm/iterations/index.html +458 -22
- package/dist/pm/projects/detail/index.html +458 -22
- package/dist/pm/projects/index.html +458 -22
- package/dist/pm/requirements/index.html +458 -22
- package/dist/prompts/index.html +458 -22
- package/dist/reports/index.html +458 -22
- package/dist/requirements/index.html +458 -22
- package/dist/tasks/index.html +458 -22
- package/dist/templates/index.html +458 -22
- 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
- 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
- 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
- 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
- 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
- package/dist/test-automation/index.html +717 -0
- package/dist/test-stats/index.html +458 -22
- package/dist/todos/index.html +458 -22
- package/dist/workbench/index.html +517 -0
- package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +80 -43
- package/lh-plugins/lh-project-docs.mjs +14 -0
- package/lh-plugins/lh-uiauto.mjs +1445 -386
- package/lh-plugins/plugin-prompts.mjs +200 -0
- package/lh-plugins/storage-domain.mjs +6 -0
- package/lh-plugins/uiauto-adapters/index.mjs +57 -0
- package/lh-plugins/uiauto-adapters/playwright.mjs +215 -0
- package/lh-plugins/uiauto-adapters/pytest.mjs +151 -0
- package/lh-plugins/uiauto-adapters/selenium.mjs +163 -0
- package/lh-plugins/uiauto-adapters/shared.mjs +371 -0
- package/lh-plugins/uiauto-adapters/tasks.mjs +369 -0
- package/lh-plugins/uiauto-explorer/apps.mjs +332 -0
- package/lh-plugins/uiauto-explorer/diff.mjs +159 -0
- package/lh-plugins/uiauto-explorer/emit-files.mjs +506 -0
- package/lh-plugins/uiauto-explorer/emit-python.mjs +160 -0
- package/lh-plugins/uiauto-explorer/emit-ts.mjs +118 -0
- package/lh-plugins/uiauto-explorer/emit.mjs +15 -0
- package/lh-plugins/uiauto-explorer/ir.mjs +114 -0
- package/lh-plugins/uiauto-explorer/locators.mjs +267 -0
- package/lh-plugins/uiauto-explorer/merge.mjs +235 -0
- package/lh-plugins/uiauto-explorer/plan.mjs +165 -0
- package/lh-plugins/uiauto-explorer/runner.mjs +370 -0
- package/lh-plugins/uiauto-explorer/sessions.mjs +1373 -0
- package/lh-plugins/uiauto-explorer/snapshot.mjs +492 -0
- package/lh-plugins/uiauto-prompt.mjs +122 -0
- package/lh-plugins/uiauto-report.mjs +111 -0
- package/package.json +1 -1
- package/dist/_astro/Base.4X_wsSoR.css +0 -1
- package/dist/_astro/Base.astro_astro_type_script_index_0_lang.Dy7fJoxu.js +0 -1
- package/dist/_astro/CaseExecBoard.DKdfW5fM.js +0 -1
- package/dist/_astro/CaseGenerateApp.Bm8AyH9s.js +0 -9
- package/dist/_astro/CasesLibrary.CvVJZ74h.js +0 -1
- package/dist/_astro/ChatApp.BS-wLBRa.js +0 -276
- package/dist/_astro/ColumnResize.Bs6GL3DJ.js +0 -1
- package/dist/_astro/DatePicker.CMfX7F6z.js +0 -1
- package/dist/_astro/DocsFileBrowser.BtRoZ787.js +0 -1
- package/dist/_astro/DocsPager.C20ue_JZ.js +0 -1
- package/dist/_astro/KnowledgeLibrary.CV4DyStj.js +0 -1
- package/dist/_astro/NamePromptDialog.Dl5kSnQI.js +0 -1
- package/dist/_astro/NavLibraries.DmD2lZBZ.js +0 -1
- package/dist/_astro/OverflowHint.lzmplP5j.js +0 -1
- package/dist/_astro/PluginsPage.B59AMDrB.js +0 -1
- package/dist/_astro/PluginsPage.BEAPymNL.js +0 -39
- package/dist/_astro/PmBugsBoard.CPEyBp0l.js +0 -1
- package/dist/_astro/PmIterationsBoard.zCeLpcBo.js +0 -1
- package/dist/_astro/PmProjectDetail.ejIam5sD.js +0 -1
- package/dist/_astro/PmProjectsBoard.DbXzir8o.js +0 -1
- package/dist/_astro/PmRequirementsBoard.CynewRfv.js +0 -1
- package/dist/_astro/PmRequirementsBoard.D9eUMJWI.js +0 -1
- package/dist/_astro/PmShared.BxTHKdjY.js +0 -1
- package/dist/_astro/PromptsLibrary.Bkruu80b.js +0 -1
- package/dist/_astro/ReportsPage.BoBQshMQ.js +0 -1
- package/dist/_astro/RequirementsLibrary.BC0A8qdk.js +0 -1
- package/dist/_astro/SearchableSelect.CXa1hiDd.js +0 -1
- package/dist/_astro/SelectDropdown.Buv7rQJ_.js +0 -1
- package/dist/_astro/SettingsDialog.Dc-9QNJI.js +0 -1
- package/dist/_astro/SlideOverDrawer.TPbGEoWn.js +0 -1
- package/dist/_astro/TagSelect.u8DTop7v.js +0 -1
- package/dist/_astro/TasksBoard.Bb--oVV8.js +0 -1
- package/dist/_astro/TemplatesLibrary.D1wZq94E.js +0 -1
- package/dist/_astro/TestStatsBoard.DlVezlXl.js +0 -1
- package/dist/_astro/TodosBoard.S84wqcWY.js +0 -1
- package/dist/_astro/UiAutoBoard.BKp9ifxg.js +0 -1
- package/dist/_astro/active-element-history.CeefGkFQ.js +0 -1
- package/dist/_astro/app-config.DUyozIL9.js +0 -1
- package/dist/_astro/dialog.DXHznyjD.js +0 -1
- package/dist/_astro/jsx-runtime.BUXbF_vF.js +0 -1
- package/dist/_astro/listbox.Di-t5U37.js +0 -1
- package/dist/_astro/menu.Bkluqxic.js +0 -1
- package/dist/_astro/prompts-meta.F4wwkjUA.js +0 -2
- package/dist/_astro/report-prompt.Cmw4XzfY.js +0 -1
- package/dist/_astro/update.Bl_HfSe6.js +0 -1
- package/dist/_astro/use-text-value.BuY0Cm1z.js +0 -1
- package/dist/_astro/use-tree-walker.CfTHFX43.js +0 -1
- package/dist/_astro/useListAnim.CpGB1cft.js +0 -1
- package/dist/ui-automation/index.html +0 -281
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件自带的提示词文件:落在当前空间的「提示词管理」里,插件运行时引用。
|
|
3
|
+
*
|
|
4
|
+
* 规则(全局):
|
|
5
|
+
* - 打开插件时补一份种子提示词(已存在就不覆盖,用户改过的内容优先);
|
|
6
|
+
* - 插件开启期间,这份提示词在「提示词管理」里不允许删除 / 改名;
|
|
7
|
+
* - 关闭插件只停用,文件保留;下次打开仍引用同一份,不会重新盖一份;
|
|
8
|
+
* - 文件被删掉后再打开插件,会重新生成种子。
|
|
9
|
+
*
|
|
10
|
+
* 文件名与所属插件的对应关系在前端 `src/lib/prompts-meta.ts` 里也有一份,两处要一致。
|
|
11
|
+
*/
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import crypto from 'node:crypto';
|
|
15
|
+
|
|
16
|
+
import { getDataRoot } from '../builtin/session/space-context.mjs';
|
|
17
|
+
import { resolveContentRoot, spaceLocalFile } from '../builtin/session/space-layout.mjs';
|
|
18
|
+
|
|
19
|
+
/** 与 DOC_ROOT_DIRS.prompts.dirName 一致;这里写死避免与 lh-project-docs.mjs 形成循环依赖 */
|
|
20
|
+
const PROMPTS_DIR_NAME = '提示词管理';
|
|
21
|
+
|
|
22
|
+
/** 种子账本:记下「上次由插件写入的内容指纹」,用来判断这份文件有没有被人改过 */
|
|
23
|
+
const SEED_STATE_FILE = 'plugin-prompts.json';
|
|
24
|
+
|
|
25
|
+
const digest = (text) =>
|
|
26
|
+
crypto
|
|
27
|
+
.createHash('sha256')
|
|
28
|
+
.update(String(text ?? ''), 'utf8')
|
|
29
|
+
.digest('hex')
|
|
30
|
+
.slice(0, 32);
|
|
31
|
+
|
|
32
|
+
function seedStatePath(spaceDir) {
|
|
33
|
+
return spaceLocalFile(spaceDir, SEED_STATE_FILE);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function readSeedState(spaceDir) {
|
|
37
|
+
try {
|
|
38
|
+
const parsed = JSON.parse(fs.readFileSync(seedStatePath(spaceDir), 'utf8'));
|
|
39
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
40
|
+
} catch {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function writeSeedState(spaceDir, state) {
|
|
46
|
+
try {
|
|
47
|
+
const file = seedStatePath(spaceDir);
|
|
48
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
49
|
+
fs.writeFileSync(file, `${JSON.stringify(state, null, 2)}\n`, 'utf8');
|
|
50
|
+
} catch {
|
|
51
|
+
// 账本写不进去只影响「自动升级」,不影响正常使用
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 提示词文件名 → 所属插件 id */
|
|
56
|
+
export const PLUGIN_PROMPT_FILES = Object.freeze({
|
|
57
|
+
'工作汇报提示词.md': 'reports',
|
|
58
|
+
'Playwright提示词.md': 'uiAuto',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const UI_AUTO_PROMPT_FILE = 'Playwright提示词.md';
|
|
62
|
+
|
|
63
|
+
/** 当前空间的提示词目录(可能被归进分组文件夹) */
|
|
64
|
+
export function promptsDir(spaceDir = getDataRoot()) {
|
|
65
|
+
return resolveContentRoot(spaceDir, PROMPTS_DIR_NAME).abs;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 空间里某份插件提示词的绝对路径 */
|
|
69
|
+
export function pluginPromptPath(name, spaceDir = getDataRoot()) {
|
|
70
|
+
return path.join(promptsDir(spaceDir), name);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 读插件提示词正文;不存在返回空串 */
|
|
74
|
+
export function readPluginPrompt(name, spaceDir = getDataRoot()) {
|
|
75
|
+
try {
|
|
76
|
+
return fs.readFileSync(pluginPromptPath(name, spaceDir), 'utf8');
|
|
77
|
+
} catch {
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 缺就补种子;已存在时:
|
|
84
|
+
* - 内容仍与上次插件写入的一致(没人改过)→ 跟内置模板对齐,自动升级到新版本;
|
|
85
|
+
* - 内容被人改过 → 一个字都不动,改动优先;
|
|
86
|
+
* - 老版本留下的种子(没有账本)→ 只登记指纹,不覆盖。
|
|
87
|
+
*
|
|
88
|
+
* @returns {{ created: boolean, updated: boolean, exists: boolean, file: string }}
|
|
89
|
+
*/
|
|
90
|
+
export function ensurePluginPrompt(name, template, spaceDir = getDataRoot()) {
|
|
91
|
+
const dest = pluginPromptPath(name, spaceDir);
|
|
92
|
+
const state = readSeedState(spaceDir);
|
|
93
|
+
const rendered = String(template ?? '');
|
|
94
|
+
const renderedHash = digest(rendered);
|
|
95
|
+
|
|
96
|
+
if (!fs.existsSync(dest)) {
|
|
97
|
+
try {
|
|
98
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
99
|
+
fs.writeFileSync(dest, rendered, 'utf8');
|
|
100
|
+
writeSeedState(spaceDir, { ...state, [name]: renderedHash });
|
|
101
|
+
return { created: true, updated: false, exists: true, file: name };
|
|
102
|
+
} catch {
|
|
103
|
+
return { created: false, updated: false, exists: false, file: name };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let current = '';
|
|
108
|
+
try {
|
|
109
|
+
current = fs.readFileSync(dest, 'utf8');
|
|
110
|
+
} catch {
|
|
111
|
+
return { created: false, updated: false, exists: true, file: name };
|
|
112
|
+
}
|
|
113
|
+
const currentHash = digest(current);
|
|
114
|
+
|
|
115
|
+
// 没有账本:老种子或用户自己写的,先只登记,不冒险覆盖
|
|
116
|
+
if (!state[name]) {
|
|
117
|
+
writeSeedState(spaceDir, { ...state, [name]: currentHash });
|
|
118
|
+
return { created: false, updated: false, exists: true, file: name };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 有人改过(当前内容已不是插件上次写的)→ 保持原样
|
|
122
|
+
if (state[name] !== currentHash) {
|
|
123
|
+
return { created: false, updated: false, exists: true, file: name };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 没人改过但内置模板变了 → 自动升级
|
|
127
|
+
if (currentHash !== renderedHash) {
|
|
128
|
+
try {
|
|
129
|
+
fs.writeFileSync(dest, rendered, 'utf8');
|
|
130
|
+
writeSeedState(spaceDir, { ...state, [name]: renderedHash });
|
|
131
|
+
return { created: false, updated: true, exists: true, file: name };
|
|
132
|
+
} catch {
|
|
133
|
+
return { created: false, updated: false, exists: true, file: name };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return { created: false, updated: false, exists: true, file: name };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 显式把这份提示词恢复成插件内置版本(用户在界面上确认过才调用)。
|
|
142
|
+
* @returns {{ ok: boolean, file: string }}
|
|
143
|
+
*/
|
|
144
|
+
export function resetPluginPrompt(name, template, spaceDir = getDataRoot()) {
|
|
145
|
+
const dest = pluginPromptPath(name, spaceDir);
|
|
146
|
+
const rendered = String(template ?? '');
|
|
147
|
+
try {
|
|
148
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
149
|
+
fs.writeFileSync(dest, rendered, 'utf8');
|
|
150
|
+
writeSeedState(spaceDir, { ...readSeedState(spaceDir), [name]: digest(rendered) });
|
|
151
|
+
return { ok: true, file: name };
|
|
152
|
+
} catch {
|
|
153
|
+
return { ok: false, file: name };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** 这份提示词是否已经和插件内置版本不一致(给人看「可同步」提示用) */
|
|
158
|
+
export function pluginPromptDiffers(name, template, spaceDir = getDataRoot()) {
|
|
159
|
+
const dest = pluginPromptPath(name, spaceDir);
|
|
160
|
+
let current = '';
|
|
161
|
+
try {
|
|
162
|
+
current = fs.readFileSync(dest, 'utf8');
|
|
163
|
+
} catch {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
return digest(current) !== digest(template);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function readJsonOr(file, fallback) {
|
|
170
|
+
try {
|
|
171
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
172
|
+
} catch {
|
|
173
|
+
return fallback;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 空间里某个插件的开关状态:本机配置优先,其次空间内默认配置。
|
|
179
|
+
* 与 lh-project-docs.mjs 的 isContentRootEnabled 同一口径。
|
|
180
|
+
*/
|
|
181
|
+
export function isPluginOnInSpace(pluginId, spaceDir = getDataRoot()) {
|
|
182
|
+
if (!pluginId) return false;
|
|
183
|
+
const defaults = readJsonOr(spaceLocalFile(spaceDir, 'app.defaults.json'), {})?.plugins ?? {};
|
|
184
|
+
const local = readJsonOr(spaceLocalFile(spaceDir, 'app.config.json'), {})?.plugins ?? {};
|
|
185
|
+
return (local[pluginId] ?? defaults[pluginId]) === true;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 这份提示词当前是否被某个「开启中」的插件锁定(不可删除 / 改名)。
|
|
190
|
+
* @returns {string} 锁定原因;未锁定时为空串
|
|
191
|
+
*/
|
|
192
|
+
export function pluginPromptLock(name, spaceDir = getDataRoot()) {
|
|
193
|
+
const base = String(name ?? '')
|
|
194
|
+
.split('/')
|
|
195
|
+
.pop();
|
|
196
|
+
const owner = PLUGIN_PROMPT_FILES[base];
|
|
197
|
+
if (!owner) return '';
|
|
198
|
+
if (!isPluginOnInSpace(owner, spaceDir)) return '';
|
|
199
|
+
return '插件开启中,这份提示词由插件引用;先在「我的插件」里关闭对应插件再删除';
|
|
200
|
+
}
|
|
@@ -63,6 +63,12 @@ export const KNOWN_STORAGE_DOMAINS = [
|
|
|
63
63
|
kind: 'file',
|
|
64
64
|
roleZh: '自动化测试项目与运行记录',
|
|
65
65
|
},
|
|
66
|
+
{
|
|
67
|
+
id: 'uiAutoCache',
|
|
68
|
+
rel: `${LOCAL_REL}/uiauto`,
|
|
69
|
+
kind: 'dir',
|
|
70
|
+
roleZh: '自动化测试生成会话与应用图标缓存(本机)',
|
|
71
|
+
},
|
|
66
72
|
{
|
|
67
73
|
id: 'reports',
|
|
68
74
|
rel: `${LOCAL_REL}/reports.json`,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 适配器注册表:识别项目、按 id 取适配器。
|
|
3
|
+
*
|
|
4
|
+
* 新增框架只需要写一个模块并加进 ADAPTERS,插件本体不感知具体框架。
|
|
5
|
+
*/
|
|
6
|
+
import { buildProbe } from './shared.mjs';
|
|
7
|
+
|
|
8
|
+
import * as playwright from './playwright.mjs';
|
|
9
|
+
import * as pytest from './pytest.mjs';
|
|
10
|
+
import * as selenium from './selenium.mjs';
|
|
11
|
+
|
|
12
|
+
/** 顺序只影响同分时的展示顺序 */
|
|
13
|
+
export const ADAPTERS = [playwright, pytest, selenium];
|
|
14
|
+
|
|
15
|
+
export const ADAPTER_IDS = ADAPTERS.map((adapter) => adapter.id);
|
|
16
|
+
|
|
17
|
+
export function getAdapter(id) {
|
|
18
|
+
return ADAPTERS.find((adapter) => adapter.id === id) ?? null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 给前端「框架」下拉用的清单(不做项目识别,纯静态) */
|
|
22
|
+
export function adapterOptions() {
|
|
23
|
+
return ADAPTERS.map((adapter) => ({ id: adapter.id, label: adapter.label, kind: adapter.kind }));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 识别目录里可能是什么框架,按分数从高到低。
|
|
28
|
+
* @param {ReturnType<typeof buildProbe>} probe
|
|
29
|
+
*/
|
|
30
|
+
export function detectCandidates(probe) {
|
|
31
|
+
if (!probe?.exists) return [];
|
|
32
|
+
const list = [];
|
|
33
|
+
for (const adapter of ADAPTERS) {
|
|
34
|
+
let result = null;
|
|
35
|
+
try {
|
|
36
|
+
result = adapter.detect(probe);
|
|
37
|
+
} catch {
|
|
38
|
+
result = null;
|
|
39
|
+
}
|
|
40
|
+
if (!result || !result.score) continue;
|
|
41
|
+
list.push({
|
|
42
|
+
id: adapter.id,
|
|
43
|
+
label: adapter.label,
|
|
44
|
+
kind: result.kind ?? adapter.kind,
|
|
45
|
+
score: result.score,
|
|
46
|
+
evidence: result.evidence ?? [],
|
|
47
|
+
controls: adapter.controls,
|
|
48
|
+
ready: adapter.ready ? Boolean(adapter.ready(probe)) : true,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return list.sort((a, b) => b.score - a.score);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 识别阈值:低于这个分数视为「不像」,不给挂载 */
|
|
55
|
+
export const MIN_DETECT_SCORE = 50;
|
|
56
|
+
|
|
57
|
+
export { buildProbe };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Playwright 适配器:JS / TS 项目,跑 `playwright test`。
|
|
3
|
+
*
|
|
4
|
+
* - 报告与项目的 playwright.config 保持一致:不覆盖 outputFolder,
|
|
5
|
+
* 运行结束后由插件把 playwright-report/ 快照到空间目录。
|
|
6
|
+
* - 唯一写进空间的是 JSON reporter 结果(我们自己解析用)。
|
|
7
|
+
*/
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
|
|
11
|
+
import { emptySummary, intOr, parseJUnitXml, readSmall, text } from './shared.mjs';
|
|
12
|
+
|
|
13
|
+
export const id = 'playwright';
|
|
14
|
+
export const label = 'Playwright';
|
|
15
|
+
export const kind = 'ui';
|
|
16
|
+
export const controls = ['file', 'grep', 'project', 'workers', 'headed', 'lastFailed'];
|
|
17
|
+
export const configFiles = [
|
|
18
|
+
'playwright.config.ts',
|
|
19
|
+
'playwright.config.js',
|
|
20
|
+
'playwright.config.mjs',
|
|
21
|
+
'playwright.config.cjs',
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
export function detect(probe) {
|
|
25
|
+
const config = configFiles.find((name) => probe.existsRel(name));
|
|
26
|
+
if (config) return { score: 100, evidence: [config] };
|
|
27
|
+
if (probe.nodeDeps.has('@playwright/test')) {
|
|
28
|
+
return { score: 92, evidence: ['package.json: @playwright/test'] };
|
|
29
|
+
}
|
|
30
|
+
if (probe.nodeDeps.has('playwright')) {
|
|
31
|
+
return { score: 86, evidence: ['package.json: playwright'] };
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function findCommand(dir) {
|
|
37
|
+
const bin = process.platform === 'win32' ? 'playwright.cmd' : 'playwright';
|
|
38
|
+
const local = path.join(dir, 'node_modules', '.bin', bin);
|
|
39
|
+
if (fs.existsSync(local)) return { command: local, prefix: [] };
|
|
40
|
+
if (fs.existsSync(path.join(dir, 'node_modules', '@playwright', 'test'))) {
|
|
41
|
+
return {
|
|
42
|
+
command: process.platform === 'win32' ? 'npx.cmd' : 'npx',
|
|
43
|
+
prefix: ['--no-install', 'playwright'],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function ready(probe) {
|
|
50
|
+
return Boolean(findCommand(probe.dir));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function readyHint(probe) {
|
|
54
|
+
const runner =
|
|
55
|
+
probe.packageManager === 'pnpm'
|
|
56
|
+
? 'pnpm install'
|
|
57
|
+
: probe.packageManager === 'yarn'
|
|
58
|
+
? 'yarn'
|
|
59
|
+
: 'npm install';
|
|
60
|
+
const browsers =
|
|
61
|
+
probe.packageManager === 'pnpm'
|
|
62
|
+
? 'pnpm exec playwright install'
|
|
63
|
+
: probe.packageManager === 'yarn'
|
|
64
|
+
? 'yarn playwright install'
|
|
65
|
+
: 'npx playwright install';
|
|
66
|
+
return `未找到 Playwright:请先在 ${probe.dir} 运行「${runner}」,首次使用再运行「${browsers}」。`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 拼 Playwright 运行参数(纯函数,便于单测) */
|
|
70
|
+
export function buildPlaywrightArgs(options = {}) {
|
|
71
|
+
const args = ['test', '--reporter=list,json,html'];
|
|
72
|
+
const file = text(options.file, 1024);
|
|
73
|
+
if (file) args.push(file.replace(/\\/g, '/'));
|
|
74
|
+
const grep = text(options.grep, 500);
|
|
75
|
+
if (grep) args.push('--grep', grep);
|
|
76
|
+
const project = text(options.project, 100);
|
|
77
|
+
if (project) args.push(`--project=${project}`);
|
|
78
|
+
if (options.headed === true) args.push('--headed');
|
|
79
|
+
const workers = intOr(options.workers, 0, 0, 32);
|
|
80
|
+
if (workers > 0) args.push(`--workers=${workers}`);
|
|
81
|
+
if (options.lastFailed === true) args.push('--last-failed');
|
|
82
|
+
if (options.bail === true) args.push('--max-failures=1');
|
|
83
|
+
return args;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function resolve(ctx) {
|
|
87
|
+
const command = findCommand(ctx.dir);
|
|
88
|
+
if (!command) return { error: readyHint(ctx.probe) };
|
|
89
|
+
const env = { PLAYWRIGHT_JSON_OUTPUT_NAME: ctx.resultAbs };
|
|
90
|
+
// 有些项目的 config 会 import tsconfig-paths/register,它把 `--project` 当成 tsconfig 路径;
|
|
91
|
+
// 预加载守卫只在加载它的瞬间摘掉这两个参数,避免 ENOENT(见 uiauto-argv-guard.cjs)
|
|
92
|
+
if (ctx.args.project && ctx.guardPath && fs.existsSync(ctx.guardPath)) {
|
|
93
|
+
const requireFlag = `--require ${JSON.stringify(ctx.guardPath)}`;
|
|
94
|
+
env.NODE_OPTIONS = process.env.NODE_OPTIONS
|
|
95
|
+
? `${process.env.NODE_OPTIONS} ${requireFlag}`
|
|
96
|
+
: requireFlag;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
command: command.command,
|
|
100
|
+
args: [...command.prefix, ...buildPlaywrightArgs(ctx.args)],
|
|
101
|
+
env,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 解析 Playwright JSON reporter 的结果(纯函数) */
|
|
106
|
+
export function parsePlaywrightReport(raw) {
|
|
107
|
+
const empty = emptySummary();
|
|
108
|
+
if (!raw || typeof raw !== 'object') return empty;
|
|
109
|
+
const stats = raw.stats && typeof raw.stats === 'object' ? raw.stats : {};
|
|
110
|
+
const projectNames = Array.isArray(raw.config?.projects)
|
|
111
|
+
? raw.config.projects
|
|
112
|
+
.map((item) => text(item?.name, 100))
|
|
113
|
+
.filter(Boolean)
|
|
114
|
+
.slice(0, 50)
|
|
115
|
+
: [];
|
|
116
|
+
const expected = intOr(stats.expected, 0, 0, 1_000_000);
|
|
117
|
+
const unexpected = intOr(stats.unexpected, 0, 0, 1_000_000);
|
|
118
|
+
const skipped = intOr(stats.skipped, 0, 0, 1_000_000);
|
|
119
|
+
const flaky = intOr(stats.flaky, 0, 0, 1_000_000);
|
|
120
|
+
const errors = Array.isArray(raw.errors)
|
|
121
|
+
? raw.errors
|
|
122
|
+
.map((item) => text(typeof item === 'string' ? item : item?.message, 2000))
|
|
123
|
+
.filter(Boolean)
|
|
124
|
+
.slice(0, 20)
|
|
125
|
+
: [];
|
|
126
|
+
const failedTests = [];
|
|
127
|
+
const walk = (suite, trail) => {
|
|
128
|
+
if (!suite || typeof suite !== 'object') return;
|
|
129
|
+
const file = text(suite.file, 1024);
|
|
130
|
+
const own = text(suite.title, 500);
|
|
131
|
+
const nextTrail = own ? [...trail, own] : trail;
|
|
132
|
+
for (const spec of Array.isArray(suite.specs) ? suite.specs : []) {
|
|
133
|
+
const tests = Array.isArray(spec?.tests) ? spec.tests : [];
|
|
134
|
+
const bad = tests.some(
|
|
135
|
+
(t) =>
|
|
136
|
+
t?.status === 'unexpected' ||
|
|
137
|
+
t?.status === 'timedOut' ||
|
|
138
|
+
(Array.isArray(t?.results) &&
|
|
139
|
+
t.results.some((r) => r?.status === 'unexpected' || r?.status === 'timedOut')),
|
|
140
|
+
);
|
|
141
|
+
if (!bad) continue;
|
|
142
|
+
failedTests.push({
|
|
143
|
+
title: [...nextTrail, text(spec?.title, 500)].filter(Boolean).join(' › '),
|
|
144
|
+
file,
|
|
145
|
+
});
|
|
146
|
+
if (failedTests.length >= 50) return;
|
|
147
|
+
}
|
|
148
|
+
for (const child of Array.isArray(suite.suites) ? suite.suites : []) walk(child, nextTrail);
|
|
149
|
+
};
|
|
150
|
+
for (const suite of Array.isArray(raw.suites) ? raw.suites : []) walk(suite, []);
|
|
151
|
+
return {
|
|
152
|
+
total: expected + unexpected + skipped + flaky,
|
|
153
|
+
passed: expected,
|
|
154
|
+
failed: unexpected,
|
|
155
|
+
skipped,
|
|
156
|
+
flaky,
|
|
157
|
+
durationMs: intOr(stats.duration, 0, 0, Number.MAX_SAFE_INTEGER),
|
|
158
|
+
errors,
|
|
159
|
+
failedTests,
|
|
160
|
+
projectNames,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** 项目里可能的 HTML 报告目录(项目相对路径),运行后取有 index.html 的那个:
|
|
165
|
+
* 先认 config 里显式写的 outputFolder,再退回官方默认目录 */
|
|
166
|
+
export function reportDirs(probe) {
|
|
167
|
+
const dirs = new Set(['playwright-report']);
|
|
168
|
+
for (const name of configFiles) {
|
|
169
|
+
const content = probe.readRel(name);
|
|
170
|
+
if (!content) continue;
|
|
171
|
+
const re = /outputFolder\s*:\s*['"]([^'"]+)['"]/g;
|
|
172
|
+
let match;
|
|
173
|
+
while ((match = re.exec(content))) {
|
|
174
|
+
const rel = match[1].replace(/\\/g, '/').replace(/^\.\//, '');
|
|
175
|
+
if (!rel || rel.includes('..') || path.isAbsolute(rel)) continue;
|
|
176
|
+
dirs.add(rel);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return [...dirs];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function parse(ctx) {
|
|
183
|
+
const raw = readSmall(ctx.resultAbs, 32 * 1024 * 1024);
|
|
184
|
+
if (!raw) return emptySummary();
|
|
185
|
+
try {
|
|
186
|
+
return parsePlaywrightReport(JSON.parse(raw));
|
|
187
|
+
} catch {
|
|
188
|
+
return emptySummary();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** 运行失败且解析不到结果时,从日志里给一条可操作的提示 */
|
|
193
|
+
export function hintFromLog(log) {
|
|
194
|
+
if (
|
|
195
|
+
/Executable doesn't exist|Please run the following command to download new browsers/i.test(log)
|
|
196
|
+
) {
|
|
197
|
+
return '缺少浏览器内核:请在项目目录运行 playwright install(或 npx playwright install)后重试。';
|
|
198
|
+
}
|
|
199
|
+
if (/Cannot find module ['"]@playwright\/test['"]/i.test(log)) {
|
|
200
|
+
return '项目里没有安装 @playwright/test:先在项目目录安装依赖再运行。';
|
|
201
|
+
}
|
|
202
|
+
return '';
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function describeArgs(args) {
|
|
206
|
+
const parts = [];
|
|
207
|
+
if (args.file) parts.push(args.file);
|
|
208
|
+
if (args.grep) parts.push(`grep: ${args.grep}`);
|
|
209
|
+
if (args.project) parts.push(args.project);
|
|
210
|
+
if (args.headed) parts.push('headed');
|
|
211
|
+
if (args.workers > 0) parts.push(`workers=${args.workers}`);
|
|
212
|
+
if (args.lastFailed) parts.push('--last-failed');
|
|
213
|
+
if (args.bail) parts.push('--max-failures=1');
|
|
214
|
+
return parts.length ? parts.join(' · ') : '全量';
|
|
215
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pytest 适配器:Python 项目,接口(requests / httpx)与 UI(selenium / playwright)都用它跑。
|
|
3
|
+
*
|
|
4
|
+
* - 解释器按本地虚拟环境 → uv / poetry → python3 的顺序找,不自动安装任何东西。
|
|
5
|
+
* - 结果统一走 `--junitxml`,解析成和 Playwright 相同的汇总结构。
|
|
6
|
+
* - HTML 报告只在项目声明了 pytest-html 时生成,直接写进空间目录(不污染项目)。
|
|
7
|
+
*/
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
|
|
11
|
+
import { intOr, parseJUnitXml, readSmall, text } from './shared.mjs';
|
|
12
|
+
|
|
13
|
+
export const id = 'pytest';
|
|
14
|
+
export const label = 'pytest';
|
|
15
|
+
export const controls = ['file', 'grep'];
|
|
16
|
+
|
|
17
|
+
const UI_DEPS = ['selenium', 'playwright', 'appium-python-client', 'playwright-stealth'];
|
|
18
|
+
const API_DEPS = ['requests', 'httpx', 'jsonschema', 'tavern', 'schemathesis'];
|
|
19
|
+
|
|
20
|
+
function pytestEvidence(probe) {
|
|
21
|
+
const evidence = [];
|
|
22
|
+
if (probe.existsRel('pytest.ini')) evidence.push('pytest.ini');
|
|
23
|
+
if (probe.existsRel('conftest.py')) evidence.push('conftest.py');
|
|
24
|
+
const pyproject = probe.readRel('pyproject.toml');
|
|
25
|
+
if (pyproject && /\[tool\.pytest\.ini_options\]/.test(pyproject)) {
|
|
26
|
+
evidence.push('pyproject.toml: [tool.pytest.ini_options]');
|
|
27
|
+
}
|
|
28
|
+
const setupCfg = probe.readRel('setup.cfg');
|
|
29
|
+
if (setupCfg && /\[tool:pytest\]/.test(setupCfg)) evidence.push('setup.cfg: [tool:pytest]');
|
|
30
|
+
if (probe.pythonDeps.has('pytest')) evidence.push('依赖: pytest');
|
|
31
|
+
return evidence;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function detectKind(probe) {
|
|
35
|
+
if (UI_DEPS.some((name) => probe.pythonDeps.has(name))) return 'ui';
|
|
36
|
+
if (API_DEPS.some((name) => probe.pythonDeps.has(name))) return 'api';
|
|
37
|
+
return 'test';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function detect(probe) {
|
|
41
|
+
const evidence = pytestEvidence(probe);
|
|
42
|
+
let score = 0;
|
|
43
|
+
if (probe.existsRel('pytest.ini')) score = 100;
|
|
44
|
+
else if (
|
|
45
|
+
evidence.some((item) => item.startsWith('pyproject.toml') || item.startsWith('setup.cfg'))
|
|
46
|
+
) {
|
|
47
|
+
score = 96;
|
|
48
|
+
} else if (probe.existsRel('conftest.py')) score = 90;
|
|
49
|
+
else if (probe.pythonDeps.has('pytest')) score = 84;
|
|
50
|
+
else if (probe.hasPythonTests) score = 70;
|
|
51
|
+
|
|
52
|
+
// Python + selenium 但没有 pytest 配置:仍然用 pytest 跑(Python 生态最常见),分数压低
|
|
53
|
+
if (!score && probe.pythonDeps.has('selenium')) {
|
|
54
|
+
return { score: 58, evidence: ['依赖: selenium'], kind: 'ui' };
|
|
55
|
+
}
|
|
56
|
+
if (!score) return null;
|
|
57
|
+
if (probe.hasPythonTests) evidence.push('tests: test_*.py');
|
|
58
|
+
return { score, evidence, kind: detectKind(probe) };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 本地解释器:虚拟环境优先,其次 uv / poetry,最后系统 python3 */
|
|
62
|
+
function findInterpreter(dir) {
|
|
63
|
+
const win = process.platform === 'win32';
|
|
64
|
+
const venvCandidates = win
|
|
65
|
+
? ['.venv/Scripts/python.exe', 'venv/Scripts/python.exe']
|
|
66
|
+
: ['.venv/bin/python', 'venv/bin/python', '.venv/bin/python3', 'venv/bin/python3'];
|
|
67
|
+
for (const rel of venvCandidates) {
|
|
68
|
+
const abs = path.join(dir, rel);
|
|
69
|
+
if (fs.existsSync(abs)) return { command: abs, prefix: ['-m', 'pytest'], source: rel };
|
|
70
|
+
}
|
|
71
|
+
if (fs.existsSync(path.join(dir, 'uv.lock'))) {
|
|
72
|
+
return { command: 'uv', prefix: ['run', 'python', '-m', 'pytest'], source: 'uv.lock' };
|
|
73
|
+
}
|
|
74
|
+
if (fs.existsSync(path.join(dir, 'poetry.lock'))) {
|
|
75
|
+
return { command: 'poetry', prefix: ['run', 'python', '-m', 'pytest'], source: 'poetry.lock' };
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
command: win ? 'python' : 'python3',
|
|
79
|
+
prefix: ['-m', 'pytest'],
|
|
80
|
+
source: win ? 'python' : 'python3',
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function ready() {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function readyHint(probe) {
|
|
89
|
+
return `未找到 Python 解释器:请在 ${probe.dir} 建一个虚拟环境(python3 -m venv .venv)并安装依赖后再运行。`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function resolve(ctx) {
|
|
93
|
+
const interpreter = findInterpreter(ctx.dir);
|
|
94
|
+
const args = [...interpreter.prefix, '-q', `--junitxml=${ctx.resultAbs}`];
|
|
95
|
+
|
|
96
|
+
const file = text(ctx.args.file, 1024);
|
|
97
|
+
if (file) args.push(file.replace(/\\/g, '/'));
|
|
98
|
+
|
|
99
|
+
// pytest 里最贴近「按名字筛」的是 -k 表达式
|
|
100
|
+
const grep = text(ctx.args.grep, 500);
|
|
101
|
+
if (grep) args.push('-k', grep);
|
|
102
|
+
|
|
103
|
+
const marker = text(ctx.args.marker, 200);
|
|
104
|
+
if (marker) args.push('-m', marker);
|
|
105
|
+
|
|
106
|
+
if (ctx.args.lastFailed === true) args.push('--lf');
|
|
107
|
+
if (ctx.args.bail === true) args.push('-x');
|
|
108
|
+
|
|
109
|
+
const maxFail = intOr(ctx.args.maxFail, 0, 0, 10_000);
|
|
110
|
+
if (maxFail > 0) args.push(`--maxfail=${maxFail}`);
|
|
111
|
+
|
|
112
|
+
const hasHtml = ctx.probe.pythonDeps.has('pytest-html');
|
|
113
|
+
if (hasHtml) {
|
|
114
|
+
args.push(`--html=${path.join(ctx.reportAbs, 'index.html')}`, '--self-contained-html');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { command: interpreter.command, args, env: { PYTHONUNBUFFERED: '1' } };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function parse(ctx) {
|
|
121
|
+
const xml = readSmall(ctx.resultAbs, 32 * 1024 * 1024);
|
|
122
|
+
return xml ? parseJUnitXml(xml) : parseJUnitXml('');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function describeArgs(args) {
|
|
126
|
+
const parts = [];
|
|
127
|
+
if (args.file) parts.push(args.file);
|
|
128
|
+
if (args.grep) parts.push(`-k ${args.grep}`);
|
|
129
|
+
if (args.marker) parts.push(`-m ${args.marker}`);
|
|
130
|
+
if (args.lastFailed) parts.push('--lf');
|
|
131
|
+
if (args.bail) parts.push('-x');
|
|
132
|
+
if (args.maxFail > 0) parts.push(`--maxfail=${args.maxFail}`);
|
|
133
|
+
return parts.length ? parts.join(' · ') : '全量';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function hintFromLog(log) {
|
|
137
|
+
if (/No module named ['"]?pytest/i.test(log)) {
|
|
138
|
+
return '当前 Python 环境没有 pytest:请在项目里安装依赖(pip install -r requirements.txt)后重试。';
|
|
139
|
+
}
|
|
140
|
+
if (/No module named ['"]?allure/i.test(log)) {
|
|
141
|
+
return '缺少 allure-pytest:先在项目里安装该插件,或从 pytest 配置的 addopts 里移除 --alluredir。';
|
|
142
|
+
}
|
|
143
|
+
if (/ERROR: file or directory not found/i.test(log)) {
|
|
144
|
+
return '指定的测试文件不存在:清空「文件」筛选后重试,或先在项目里创建该文件。';
|
|
145
|
+
}
|
|
146
|
+
return '';
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function reportDirs() {
|
|
150
|
+
return [];
|
|
151
|
+
}
|