参考 boot/ 仓库结构初始化, 同步到 gitea:3000/ssw/dacli (private). 包括: - src/ 8 父命令 (form/menu/dm/dict/di/apis/doc/workflow + login/status) + core (client/crypto/help/log/types/config) - src/schema/ FieldBuilder (从 JNPF web 源码提取, 避免 53 个手写 builder) - tests/ vitest 单元 + playwright E2E (含 workSystem/developSystem baseline regression) - scripts/ extract-all.mjs (从 jnpf-web 源码生成 schema) + seed-tds-baseline.ts - doc/ architecture/plan/api/extractors/baseline/RESUME/help-system + v0.6/v0.7 changelog - .claude/skills/dacli-ts/ Claude 集成 skill (SKILL.md + 5 references + 7 examples + 3 baseline) - CLAUDE.md (项目说明) + README.md + prompt.md (开发任务说明书) - 配置文件: package.json/lock, tsconfig, vitest.config, playwright.config
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
/**
|
|
* cli-help.test.ts — CLI --help / --version 烟囱测试
|
|
*
|
|
* 不依赖 JNPF, 只验证 commander 能解析命令树
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import { execFileSync } from 'node:child_process'
|
|
import { resolve } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
|
const CLI = resolve(__dirname, '../../src/cli.ts')
|
|
|
|
function run(args: string[]): string {
|
|
try {
|
|
return execFileSync('npx', ['tsx', CLI, ...args], {
|
|
encoding: 'utf-8',
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
timeout: 30_000,
|
|
})
|
|
} catch (e) {
|
|
// help/version 可能 exit non-zero, 取 stdout
|
|
const err = e as { stdout?: Buffer | string; status?: number }
|
|
return (err.stdout?.toString() || '')
|
|
}
|
|
}
|
|
|
|
describe('cli help', () => {
|
|
it('--version 输出 0.1.0', () => {
|
|
const out = run(['--version'])
|
|
expect(out).toContain('0.1.0')
|
|
})
|
|
|
|
it('--help 列出顶层命令', () => {
|
|
const out = run(['--help'])
|
|
expect(out).toContain('login')
|
|
expect(out).toContain('status')
|
|
expect(out).toContain('switch-app')
|
|
expect(out).toContain('form')
|
|
})
|
|
|
|
it('form --help 列出子命令', () => {
|
|
const out = run(['form', '--help'])
|
|
expect(out).toContain('list')
|
|
expect(out).toContain('info')
|
|
expect(out).toContain('create')
|
|
expect(out).toContain('release')
|
|
expect(out).toContain('clone')
|
|
expect(out).toContain('export')
|
|
expect(out).toContain('import')
|
|
expect(out).toContain('validate')
|
|
})
|
|
|
|
it('login --ai-help 输出 markdown', () => {
|
|
const out = run(['login', '--ai-help'])
|
|
expect(out).toContain('# dacli login')
|
|
expect(out).toContain('## 用途')
|
|
expect(out).toContain('admin')
|
|
})
|
|
|
|
it('form create --example 输出可执行命令', () => {
|
|
const out = run(['form', 'create', '--example'])
|
|
expect(out).toContain('dacli form create')
|
|
})
|
|
})
|