Files
superwork/vscode/test/cc/ccCommand.test.ts
T

53 lines
1.8 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { buildCcArgv } from '../../src/cc/ccCommand'
vi.mock('../../src/cc/claudeBin', () => ({
resolveClaudeBin: () => '/Users/me/My Apps/claude',
}))
const BASE = ['/Users/me/My Apps/claude', '--dangerously-skip-permissions', '--settings', '/p.json']
describe('buildCcArgv', () => {
it('appends the prompt as a positional arg for a fresh session', () => {
expect(buildCcArgv({ profilePath: '/p.json', prompt: 'hello' }))
.toEqual([...BASE, 'hello'])
})
it('resumes without a prompt when only a session id is given', () => {
expect(buildCcArgv({ profilePath: '/p.json', resumeSessionId: 'abc' }))
.toEqual([...BASE, '--resume', 'abc'])
})
it('resumes and hands the prompt to the restored session', () => {
expect(buildCcArgv({ profilePath: '/p.json', resumeSessionId: 'abc', prompt: 'go on' }))
.toEqual([...BASE, '--resume', 'abc', 'go on'])
})
it('puts effort first and keeps quotes / $ / newlines in paths and prompt as-is', () => {
const prompt = 'don\'t $touch\n"this"'
expect(buildCcArgv({ profilePath: '/it\'s/p.json', effort: 'high', prompt })).toEqual([
'/Users/me/My Apps/claude',
'--effort',
'high',
'--dangerously-skip-permissions',
'--settings',
'/it\'s/p.json',
prompt,
])
})
})
describe('new session identity', () => {
const sessionId = '5a749776-d1c8-4cf0-8f85-3b8d7b804498'
it('passes the allocated identity before the prompt', () => {
expect(buildCcArgv({ profilePath: '/p.json', sessionId, prompt: 'create issue' }))
.toEqual([...BASE, '--session-id', sessionId, 'create issue'])
})
it('rejects a new identity combined with resuming another session', () => {
expect(() => buildCcArgv({ profilePath: '/p.json', sessionId, resumeSessionId: 'existing' }))
.toThrow('sessionId')
})
})