Files
2026-11-17 12:10:05 +08:00

28 lines
1.1 KiB
JavaScript

// 命令冒烟测试:注册 /github,并检查 status / 空输入 / 非法子命令的返回。
import { mkdtempSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
process.env.DSH_HOME = mkdtempSync(join(tmpdir(), 'gs-home-'))
const { apply } = await import('../index.js')
let def
const ctx = { commands: { register: (d) => { def = d; return () => {} } }, get: () => undefined }
apply(ctx)
const inv = { agent: { session: { header: { cwd: process.cwd() } } }, rawInput: 'status' }
const cases = [
['注册', def?.name === 'github', `命令名 ${def?.name}`],
['status', (await def.handler(inv)).text.includes('令牌'), ''],
['空输入(无令牌应报令牌提示)', (await def.handler({ ...inv, rawInput: '' })).text.includes('令牌'), ''],
['非法子命令回用法', (await def.handler({ ...inv, rawInput: 'nonsense' })).text.includes('用法'), ''],
]
let bad = 0
for (const [name, pass, detail] of cases) {
console.log(`${pass ? '✓' : '✗'} ${name}${detail ? ` — ${detail}` : ''}`)
if (!pass) bad += 1
}
process.exitCode = bad === 0 ? 0 : 1