mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-08-29 04:26:38 +00:00
The adapter no longer validates --host/--port or declares the allowed set: LOOPBACK_HOST/ALL_INTERFACES_HOST leave args.ts. --host/--port are now unvalidated pass-through overrides — the adapter only Number-coerces the port string (the dsh-host-webserver schema wants a number). That schema (host a 127.0.0.1/0.0.0.0 literal union, port a natural <= 65535) is the single source of both the default (the shipped cordis.yml webserver row) and validity; AppCLIEntry patches an explicit flag into that row, so a bad host/port fails loud at the schema on boot (verified: `dsh web --host 9.9.9.9` and `--port abc` both exit 1 with the schema's ValidationError). web.ts keeps two display-only literals (the printed loopback URL, the all-interfaces LAN-detection check), commented as mirrors of the schema, not a source of truth. Agent Note + Chinese pair and README updated; the args spec drops the host/port exit-code cases (now the schema's job, covered by the web smoke on boot).
57 lines
2.4 KiB
TypeScript
57 lines
2.4 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { parseDshArgs } from '../src/args.ts'
|
|
|
|
const parse = (argv: string[]) => parseDshArgs(argv, '1.2.3')
|
|
|
|
/**
|
|
* `parseDshArgs` calls `process.exit` for `--help`/`--version`/errors and lets
|
|
* Commander print to the real streams; capture the exit code and mute output.
|
|
*/
|
|
function exitCode(argv: string[]): number {
|
|
const exit = vi.spyOn(process, 'exit').mockImplementation(() => { throw new Error('exit') })
|
|
vi.spyOn(process.stdout, 'write').mockReturnValue(true)
|
|
vi.spyOn(process.stderr, 'write').mockReturnValue(true)
|
|
try {
|
|
parse(argv)
|
|
throw new Error(`expected ${JSON.stringify(argv)} to exit`)
|
|
} catch {
|
|
return exit.mock.calls.at(-1)?.[0] as number
|
|
} finally {
|
|
vi.restoreAllMocks()
|
|
}
|
|
}
|
|
|
|
afterEach(() => { vi.restoreAllMocks() })
|
|
|
|
describe('parseDshArgs', () => {
|
|
it('routes each mode by its shape: default TUI, -p headless, web subcommand', () => {
|
|
expect(parse([])).toEqual({ mode: 'tui' })
|
|
expect(parse(['--config', 'custom.yml'])).toEqual({ mode: 'tui', config: 'custom.yml' })
|
|
expect(parse(['--resume', 'sess', '--config', 'app.yml'])).toEqual({ mode: 'tui', config: 'app.yml', resume: 'sess' })
|
|
expect(parse(['-p', 'do the thing'])).toEqual({ mode: 'headless', prompt: 'do the thing' })
|
|
// Bare `web` carries no host/port: the shipped cordis.yml owns the default.
|
|
expect(parse(['web'])).toEqual({ mode: 'web', dev: false })
|
|
// Host/port are unvalidated pass-throughs (the webserver schema gates them
|
|
// at boot); the adapter only coerces the port string to a number.
|
|
expect(parse(['web', '--host', '0.0.0.0', '--port', '8080', '--dev']))
|
|
.toEqual({ mode: 'web', host: '0.0.0.0', port: 8080, dev: true })
|
|
})
|
|
|
|
it('exits nonzero instead of silently starting fresh or dropping inputs', () => {
|
|
// Empty resume/prompt would be swallowed downstream; --prompt mixed with
|
|
// TUI inputs must not lose them. (Bad host/port are gated by the webserver
|
|
// schema at boot, not here.)
|
|
expect(exitCode(['--resume='])).toBe(1)
|
|
expect(exitCode(['-p', ''])).toBe(1)
|
|
expect(exitCode(['-p', 'x', '--config', 'c.yml'])).toBe(1)
|
|
expect(exitCode(['-p', 'x', '--resume', 's'])).toBe(1)
|
|
expect(exitCode(['--bogus'])).toBe(1)
|
|
expect(exitCode(['bogus-positional'])).toBe(1)
|
|
})
|
|
|
|
it('exits 0 for --help (disclosing web) and --version', () => {
|
|
expect(exitCode(['--help'])).toBe(0)
|
|
expect(exitCode(['--version'])).toBe(0)
|
|
})
|
|
})
|