60 lines
2.4 KiB
JavaScript
60 lines
2.4 KiB
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
|
|
import { parseArgs, loadConfig } from '../src/config.mjs'
|
|
|
|
test('parseArgs handles long flags, =value and short flags', () => {
|
|
const out = parseArgs(['--goal', 'g.json', '--iterations=7', '-C', '/tmp', '--no-color', '--dry-run'])
|
|
assert.equal(out.goal, 'g.json')
|
|
assert.equal(out.iterations, 7)
|
|
assert.equal(out.project, '/tmp')
|
|
assert.equal(out.color, false)
|
|
assert.equal(out.dryRun, true)
|
|
})
|
|
|
|
test('parseArgs coerces numeric flags', () => {
|
|
const out = parseArgs(['--port', '8123', '--context-warn-tokens', '90000'])
|
|
assert.equal(out.port, 8123)
|
|
assert.equal(out.contextWarnTokens, 90000)
|
|
})
|
|
|
|
test('parseArgs rejects unknown flags', () => {
|
|
assert.throws(() => parseArgs(['--nope', '1']), /Unknown option/)
|
|
})
|
|
|
|
test('loadConfig opens the launcher when no goal is given', () => {
|
|
const config = loadConfig(['--project', '/tmp'])
|
|
assert.equal(config.launcher, true)
|
|
assert.equal(config.goal, '')
|
|
assert.equal(loadConfig(['--goal-text', 'x']).launcher, undefined)
|
|
})
|
|
|
|
test('loadConfig validates session-mode and hitl', () => {
|
|
assert.throws(() => loadConfig(['--goal-text', 'x', '--session-mode', 'wat']), /session-mode/)
|
|
assert.throws(() => loadConfig(['--goal-text', 'x', '--hitl', 'wat']), /hitl/)
|
|
})
|
|
|
|
test('parseArgs handles --shared-context / --no-shared-context', () => {
|
|
assert.equal(parseArgs(['--shared-context']).sharedContext, true)
|
|
assert.equal(parseArgs(['--no-shared-context']).sharedContext, false)
|
|
})
|
|
|
|
test('loadConfig defaults to fresh sessions and maps the legacy session-mode', () => {
|
|
const defaults = loadConfig(['--goal-text', 'x'])
|
|
assert.equal(defaults.sharedContext, false)
|
|
assert.equal(defaults.sessionMode, 'fresh')
|
|
|
|
const shared = loadConfig(['--goal-text', 'x', '--shared-context'])
|
|
assert.equal(shared.sharedContext, true)
|
|
assert.equal(shared.sessionMode, 'continue')
|
|
|
|
assert.equal(loadConfig(['--goal-text', 'x', '--session-mode', 'continue']).sharedContext, true)
|
|
assert.equal(loadConfig(['--goal-text', 'x', '--session-mode', 'fresh']).sharedContext, false)
|
|
})
|
|
|
|
test('loadConfig: pre-flight confirm is on by default, --yes/--no-confirm disable it', () => {
|
|
assert.equal(loadConfig(['--goal-text', 'x']).confirm, true)
|
|
assert.equal(loadConfig(['--goal-text', 'x', '--no-confirm']).confirm, false)
|
|
assert.equal(loadConfig(['--goal-text', 'x', '--yes']).confirm, false)
|
|
})
|