mirror of
https://github.com/stablyai/orca.git
synced 2026-10-27 08:02:51 +00:00
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { parseArgs } from './daemon-entry'
|
|
|
|
describe('daemon-entry parseArgs', () => {
|
|
it('parses --socket and --token flags', () => {
|
|
const result = parseArgs(['--socket', '/tmp/test.sock', '--token', '/tmp/test.token'])
|
|
expect(result).toEqual({
|
|
socketPath: '/tmp/test.sock',
|
|
tokenPath: '/tmp/test.token'
|
|
})
|
|
})
|
|
|
|
it('handles flags in any order', () => {
|
|
const result = parseArgs(['--token', '/tmp/t.token', '--socket', '/tmp/t.sock'])
|
|
expect(result).toEqual({
|
|
socketPath: '/tmp/t.sock',
|
|
tokenPath: '/tmp/t.token'
|
|
})
|
|
})
|
|
|
|
it('throws when --socket is missing', () => {
|
|
expect(() => parseArgs(['--token', '/tmp/t.token'])).toThrow('Usage:')
|
|
})
|
|
|
|
it('throws when --token is missing', () => {
|
|
expect(() => parseArgs(['--socket', '/tmp/t.sock'])).toThrow('Usage:')
|
|
})
|
|
|
|
it('throws with no args', () => {
|
|
expect(() => parseArgs([])).toThrow('Usage:')
|
|
})
|
|
|
|
it('omits logFilePath when --log-file is absent (adopted old daemons)', () => {
|
|
const result = parseArgs(['--socket', '/tmp/t.sock', '--token', '/tmp/t.token'])
|
|
expect(result).not.toHaveProperty('logFilePath')
|
|
})
|
|
|
|
it('parses --log-file when present', () => {
|
|
const result = parseArgs([
|
|
'--socket',
|
|
'/tmp/t.sock',
|
|
'--token',
|
|
'/tmp/t.token',
|
|
'--log-file',
|
|
'/tmp/daemon.log'
|
|
])
|
|
expect(result).toEqual({
|
|
socketPath: '/tmp/t.sock',
|
|
tokenPath: '/tmp/t.token',
|
|
logFilePath: '/tmp/daemon.log'
|
|
})
|
|
})
|
|
|
|
it('still requires --socket and --token when --log-file is given', () => {
|
|
expect(() => parseArgs(['--log-file', '/tmp/daemon.log'])).toThrow('Usage:')
|
|
})
|
|
})
|