Simplify the Commander adapter now that behavior can change: dispatch a leading `web` token to its own parser instead of a subcommand of the root program, and read opts()/processedArgs after parse() instead of action closures with a mutable holder. This removes enablePositionalOptions(), the parent-option leak guard, both action closures, and the --resume/--prompt argParser threading. Behavior changes: `dsh -p x web` is a headless prompt (extra positional dropped), `dsh web -p x` fails loud (web has no -p), and a repeated --resume is natural last-wins. The two real fail-loud invariants stay as post-parse checks: an empty --resume= id (agent-loop treats '' as no-resume) and an empty -p task. Trims args.spec.ts to the routing/fail-loud/help behavior that matters; the tui-agent keyless PTY smoke still covers bin.ts dispatch end to end. Net ~114 fewer lines across adapter and tests.
34 lines
1.7 KiB
TypeScript
34 lines
1.7 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { ALL_INTERFACES_HOST, LOOPBACK_HOST, parseDshArgs } from '../src/args.ts'
|
|
|
|
const parse = (argv: string[]) => parseDshArgs(argv, '1.2.3')
|
|
|
|
describe('parseDshArgs', () => {
|
|
it('routes each mode by its shape: default TUI, -p headless, web subcommand', () => {
|
|
expect(parse([])).toEqual({ mode: 'tui' })
|
|
expect(parse(['custom.yml'])).toEqual({ mode: 'tui', config: 'custom.yml' })
|
|
expect(parse(['--resume', 'sess', 'app.yml'])).toEqual({ mode: 'tui', config: 'app.yml', resume: 'sess' })
|
|
expect(parse(['-p', 'do the thing'])).toEqual({ mode: 'headless', prompt: 'do the thing' })
|
|
expect(parse(['web'])).toEqual({ mode: 'web', host: LOOPBACK_HOST, port: 3080 })
|
|
expect(parse(['web', '--host', ALL_INTERFACES_HOST, '--port', '8080']))
|
|
.toEqual({ mode: 'web', host: ALL_INTERFACES_HOST, port: 8080 })
|
|
})
|
|
|
|
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')
|
|
})
|
|
|
|
it('surfaces --help and --version as printable data, not a process exit', () => {
|
|
const help = parse(['--help'])
|
|
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' })
|
|
})
|
|
})
|