2026-07-24 19:43:59 +08:00
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
|
import { ALL_INTERFACES_HOST, LOOPBACK_HOST, parseDshArgs } from '../src/args.ts'
|
|
|
|
|
|
2026-07-24 20:01:38 +08:00
|
|
|
const parse = (argv: string[]) => parseDshArgs(argv, '1.2.3')
|
2026-07-24 19:43:59 +08:00
|
|
|
|
2026-07-24 20:01:38 +08:00
|
|
|
describe('parseDshArgs', () => {
|
|
|
|
|
it('routes each mode by its shape: default TUI, -p headless, web subcommand', () => {
|
2026-07-24 19:43:59 +08:00
|
|
|
expect(parse([])).toEqual({ mode: 'tui' })
|
|
|
|
|
expect(parse(['custom.yml'])).toEqual({ mode: 'tui', config: 'custom.yml' })
|
2026-07-24 20:01:38 +08:00
|
|
|
expect(parse(['--resume', 'sess', 'app.yml'])).toEqual({ mode: 'tui', config: 'app.yml', resume: 'sess' })
|
2026-07-24 19:43:59 +08:00
|
|
|
expect(parse(['-p', 'do the thing'])).toEqual({ mode: 'headless', prompt: 'do the thing' })
|
2026-07-25 12:02:28 +08:00
|
|
|
expect(parse(['web'])).toEqual({ mode: 'web', host: LOOPBACK_HOST, port: 3080, dev: false })
|
2026-07-24 19:43:59 +08:00
|
|
|
expect(parse(['web', '--host', ALL_INTERFACES_HOST, '--port', '8080']))
|
2026-07-25 12:02:28 +08:00
|
|
|
.toEqual({ mode: 'web', host: ALL_INTERFACES_HOST, port: 8080, dev: false })
|
|
|
|
|
expect(parse(['web', '--dev'])).toEqual({ mode: 'web', host: LOOPBACK_HOST, port: 3080, dev: true })
|
2026-07-24 19:43:59 +08:00
|
|
|
})
|
|
|
|
|
|
2026-07-24 20:01:38 +08:00
|
|
|
it('fails loud instead of silently starting fresh or serving on bad input', () => {
|
|
|
|
|
// An empty resume/prompt would otherwise be swallowed (agent-loop treats an
|
|
|
|
|
// empty resume id as no-resume); a bad host/port must not reach the listener.
|
|
|
|
|
expect(parse(['--resume=']).mode).toBe('error')
|
|
|
|
|
expect(parse(['-p', '']).mode).toBe('error')
|
|
|
|
|
expect(parse(['web', '--host', '10.0.0.1']).mode).toBe('error')
|
|
|
|
|
expect(parse(['web', '--port', 'abc']).mode).toBe('error')
|
|
|
|
|
expect(parse(['--bogus']).mode).toBe('error')
|
2026-07-24 19:43:59 +08:00
|
|
|
})
|
|
|
|
|
|
2026-07-24 20:01:38 +08:00
|
|
|
it('surfaces --help and --version as printable data, not a process exit', () => {
|
2026-07-24 19:43:59 +08:00
|
|
|
const help = parse(['--help'])
|
2026-07-24 20:01:38 +08:00
|
|
|
expect(help).toMatchObject({ mode: 'help' })
|
|
|
|
|
if (help.mode === 'help') expect(help.text).toContain('Usage: dsh')
|
|
|
|
|
expect(parse(['--version'])).toEqual({ mode: 'version', text: '1.2.3\n' })
|
2026-07-24 19:43:59 +08:00
|
|
|
})
|
|
|
|
|
})
|