mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 21:05:51 +00:00
* feat: 适配 zed acp 协议 * docs: 完善 acp 文档 * feat: integrate feature branches + daemon/job 命令层级化 + 跨平台后台引擎 Cherry-picked from origin/lint/preview (637c908), excluding lint-only changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: correct detectMimeFromBase64 to decode raw bytes from base64 Cherry-picked from origin/lint/preview (ee36954). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: daemon 子进程 spawn 跨平台修复 + CliLaunchSpec 集中化重构 Cherry-picked from origin/lint/preview (c5f52cd), excluding lint-only formatting changes. - 新建 src/utils/cliLaunch.ts: 集中化 CLI 子进程启动层 - 修复 --daemon-worker=kind 等号格式解析 - 修复 daemon/bg fast path 缺少 setShellIfWindows() - 修复 checkPathExists 用 existsSync 替代 execSync('dir') - 7 个 spawn 站点迁移到 CliLaunchSpec Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: merge tsconfig.base.json into tsconfig.json with full compiler options The cherry-pick from637c908dropped jsx/strict/etc settings when removing tsconfig.base.json. This commit restores them in a single tsconfig.json. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: merge tsconfig.base.json into tsconfig.json with full compiler options The cherry-pick from637c908dropped jsx/strict/etc settings when removing tsconfig.base.json. This commit restores them in a single tsconfig.json. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
101 lines
3.3 KiB
TypeScript
101 lines
3.3 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
import { Command } from '@commander-js/extra-typings'
|
|
|
|
// Test Commander.js option parsing independently from main.tsx initialization.
|
|
// main.tsx has heavy bootstrap dependencies; we test the CLI argument parsing
|
|
// patterns it uses to ensure correct behavior.
|
|
|
|
function createTestProgram(): Command {
|
|
const program = new Command()
|
|
program
|
|
.name('claude-code')
|
|
.description('CLI test')
|
|
.exitOverride() // prevent process.exit during tests
|
|
.configureOutput({ writeErr: () => {}, writeOut: () => {} })
|
|
.option('-p, --print', 'pipe mode')
|
|
.option('--resume', 'resume session')
|
|
.option('-v, --verbose', 'verbose output')
|
|
.option('--model <model>', 'model to use')
|
|
.option('--system-prompt <prompt>', 'system prompt')
|
|
.option('--allowedTools <tools...>', 'allowed tools')
|
|
.option('--max-turns <n>', 'max conversation turns', parseInt)
|
|
.version('1.0.0', '-V, --version', 'display version')
|
|
return program
|
|
}
|
|
|
|
describe('CLI arguments: option parsing', () => {
|
|
test('no flags returns empty opts', () => {
|
|
const program = createTestProgram()
|
|
program.parse(['node', 'test'])
|
|
expect(program.opts()).toEqual({})
|
|
})
|
|
|
|
test('-p sets print flag', () => {
|
|
const program = createTestProgram()
|
|
program.parse(['node', 'test', '-p'])
|
|
expect(program.opts().print).toBe(true)
|
|
})
|
|
|
|
test('--print is equivalent to -p', () => {
|
|
const program = createTestProgram()
|
|
program.parse(['node', 'test', '--print'])
|
|
expect(program.opts().print).toBe(true)
|
|
})
|
|
|
|
test('--resume sets resume flag', () => {
|
|
const program = createTestProgram()
|
|
program.parse(['node', 'test', '--resume'])
|
|
expect(program.opts().resume).toBe(true)
|
|
})
|
|
|
|
test('-v sets verbose flag', () => {
|
|
const program = createTestProgram()
|
|
program.parse(['node', 'test', '-v'])
|
|
expect(program.opts().verbose).toBe(true)
|
|
})
|
|
|
|
test('--model captures string value', () => {
|
|
const program = createTestProgram()
|
|
program.parse(['node', 'test', '--model', 'claude-opus-4-6'])
|
|
expect(program.opts().model).toBe('claude-opus-4-6')
|
|
})
|
|
|
|
test('--system-prompt captures string value', () => {
|
|
const program = createTestProgram()
|
|
program.parse(['node', 'test', '--system-prompt', 'Be concise'])
|
|
expect(program.opts().systemPrompt).toBe('Be concise')
|
|
})
|
|
|
|
test('--max-turns parses integer value', () => {
|
|
const program = createTestProgram()
|
|
program.parse(['node', 'test', '--max-turns', '10'])
|
|
expect(program.opts().maxTurns).toBe(10)
|
|
})
|
|
|
|
test('multiple flags can be combined', () => {
|
|
const program = createTestProgram()
|
|
program.parse(['node', 'test', '-p', '-v', '--model', 'opus'])
|
|
expect(program.opts().print).toBe(true)
|
|
expect(program.opts().verbose).toBe(true)
|
|
expect(program.opts().model).toBe('opus')
|
|
})
|
|
|
|
test('--version throws Commander.CommandError with exit code 0', () => {
|
|
const program = createTestProgram()
|
|
let error: any
|
|
try {
|
|
program.parse(['node', 'test', '--version'])
|
|
} catch (e) {
|
|
error = e
|
|
}
|
|
expect(error).toBeDefined()
|
|
expect(error.code).toBe('commander.version')
|
|
expect(error.exitCode).toBe(0)
|
|
})
|
|
|
|
test('unknown flags throw CommanderError', () => {
|
|
const program = createTestProgram()
|
|
expect(() => program.parse(['node', 'test', '--nonexistent'])).toThrow()
|
|
})
|
|
})
|