/** * app.test.ts — app 父命令烟囱测试 */ 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) { const err = e as { stdout?: Buffer | string; status?: number } return (err.stdout?.toString() || '') } } describe('app command tree (W9-D1)', () => { it('app --help 列出 7 个子命令 (v0.9: 归并 login/status/switch/init)', () => { const out = run(['app', '--help']) expect(out).toContain('list') expect(out).toContain('info') expect(out).toContain('init') expect(out).toContain('create') expect(out).toContain('login') expect(out).toContain('status') expect(out).toContain('switch') }) it('app list --ai-help 含 API 路径', () => { const out = run(['app', 'list', '--ai-help']) expect(out).toContain('/api/system/System') }) it('app info --help 包含 --id', () => { const out = run(['app', 'info', '--help']) expect(out).toContain('--id') }) it('app init --help 包含 --appCode 和 --restart (原 initapp, v0.9 简化)', () => { const out = run(['app', 'init', '--help']) expect(out).toContain('--appCode') expect(out).toContain('--restart') }) it('顶层 --help 包含 app', () => { const out = run(['--help']) expect(out).toContain('app') }) })