78 lines
2.7 KiB
JavaScript
78 lines
2.7 KiB
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
|
|
import { parseArgs, loadConfig } from '../src/config.mjs'
|
|
|
|
test('parseArgs handles the new safety/verification flags', () => {
|
|
const out = parseArgs([
|
|
'--max-cost',
|
|
'1.25',
|
|
'--max-tokens',
|
|
'500000',
|
|
'--max-stale-iterations',
|
|
'3',
|
|
'--verify-timeout-minutes',
|
|
'5',
|
|
'--auto-fresh-tokens',
|
|
'90000',
|
|
'--max-guard-blocks',
|
|
'2',
|
|
'--no-checkpoint',
|
|
'--no-guard',
|
|
'--no-redact',
|
|
'--no-sync-goal',
|
|
])
|
|
assert.equal(out.maxCost, 1.25)
|
|
assert.equal(out.maxTokens, 500000)
|
|
assert.equal(out.maxStaleIterations, 3)
|
|
assert.equal(out.maxGuardBlocks, 2)
|
|
assert.equal(out.verifyTimeoutMinutes, 5)
|
|
assert.equal(out.autoFreshTokens, 90000)
|
|
assert.equal(out.checkpoint, false)
|
|
assert.equal(out.guard, false)
|
|
assert.equal(out.redact, false)
|
|
assert.equal(out.syncGoal, false)
|
|
})
|
|
|
|
test('parseArgs handles --guard-stop', () => {
|
|
assert.equal(parseArgs(['--guard-stop']).guardStop, true)
|
|
assert.equal(parseArgs(['--no-guard-stop']).guardStop, false)
|
|
})
|
|
|
|
test('--lan binds all interfaces; --local and --host override it', () => {
|
|
assert.equal(loadConfig(['--goal-text', 'x']).host, '127.0.0.1')
|
|
assert.equal(loadConfig(['--goal-text', 'x']).lan, false)
|
|
assert.equal(loadConfig(['--goal-text', 'x', '--lan']).host, '0.0.0.0')
|
|
assert.equal(loadConfig(['--goal-text', 'x', '--lan']).lan, true)
|
|
assert.equal(loadConfig(['--goal-text', 'x', '--lan', '--local']).host, '127.0.0.1')
|
|
assert.equal(loadConfig(['--goal-text', 'x', '--lan', '--local']).lan, false)
|
|
assert.equal(loadConfig(['--goal-text', 'x', '--lan', '--host', '192.168.1.9']).host, '192.168.1.9')
|
|
})
|
|
|
|
test('parseArgs rejects negative and non-numeric budgets', () => {
|
|
assert.throws(() => parseArgs(['--max-cost', '-1']), /Invalid number/)
|
|
assert.throws(() => parseArgs(['--max-tokens', 'abc']), /Invalid number/)
|
|
})
|
|
|
|
test('loadConfig exposes safe defaults for the new options', () => {
|
|
const config = loadConfig(['--goal-text', 'x'])
|
|
assert.equal(config.verify, '')
|
|
assert.equal(config.maxCost, 0)
|
|
assert.equal(config.maxTokens, 0)
|
|
assert.equal(config.maxStaleIterations, 0)
|
|
assert.equal(config.checkpoint, true)
|
|
assert.equal(config.guard, true)
|
|
assert.equal(config.guardStop, false)
|
|
assert.equal(config.maxGuardBlocks, 3)
|
|
assert.equal(config.redact, true)
|
|
assert.equal(config.review, false)
|
|
assert.equal(config.autoFreshTokens, 0)
|
|
assert.equal(config.syncGoal, true)
|
|
})
|
|
|
|
test('loadConfig defaults reviewAgent to the run agent when review is on', () => {
|
|
const config = loadConfig(['--goal-text', 'x', '--review', '--agent', 'code'])
|
|
assert.equal(config.review, true)
|
|
assert.equal(config.reviewAgent, 'code')
|
|
})
|