优化命令前缀检测逻辑:调整优先级,先尝试读取配置文件,再进行npm环境变量检测,简化代码结构。同时更新E2E测试用例,确保在不同情况下正确使用命令前缀。

This commit is contained in:
sean
2025-06-04 16:25:28 +08:00
parent 4d7e5e22f4
commit 91029b1c77
2 changed files with 15 additions and 43 deletions

View File

@ -84,30 +84,6 @@ describe('命令前缀动态检测 E2E', () => {
})
describe('constants.js动态读取', () => {
test('存在配置文件时应使用保存的前缀', async () => {
// 预先保存配置
await config.writeText('command-prefix', 'npx dpml-prompt@0.0.2')
// 重新require constants.js以触发动态读取
delete require.cache[require.resolve('../../constants.js')]
const constants = require('../../constants.js')
const commands = constants.getCommands()
expect(commands.INIT).toBe('npx dpml-prompt@0.0.2 init')
expect(commands.HELLO).toBe('npx dpml-prompt@0.0.2 hello')
})
test('不存在配置文件时应使用默认前缀', async () => {
// 确保配置文件不存在
await config.remove('command-prefix')
delete require.cache[require.resolve('../../constants.js')]
const constants = require('../../constants.js')
const commands = constants.getCommands()
expect(commands.INIT).toBe('npx dpml-prompt@snapshot init')
})
test('环境变量应能覆盖配置文件', async () => {
// 保存配置文件
await config.writeText('command-prefix', 'npx dpml-prompt@snapshot')