v1.1.0: composer advisor picker (model + effort submenu, off/same-as-agent), live settings route, tests

This commit is contained in:
Agent committed 2026-10-11 00:42:38 +00:00
1 parent a47bcb03ab
commit 22dcc3a29c
4 files changed
+417 -12

No files matched your search

+61 -2
View File
@@ -1,8 +1,19 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { Readable } from 'node:stream'
import * as plugin from '../index.js'
// Settings persist to <DSH_PROFILE_DIR>/omp-advisor.json; keep tests away from the real profile.
const PROFILE = fs.mkdtempSync(path.join(os.tmpdir(), 'omp-advisor-test-'))
process.env.DSH_PROFILE_DIR = PROFILE
const SETTINGS = path.join(PROFILE, 'omp-advisor.json')
test.after(() => fs.rmSync(PROFILE, { recursive: true, force: true }))
function harness(replies, config = {}) {
fs.rmSync(SETTINGS, { force: true }) // live settings load in apply(): never leak between tests
const listeners = new Map()
const on = (n, f) => { listeners.set(n, [...(listeners.get(n) ?? []), f]); return () => listeners.set(n, listeners.get(n).filter((x) => x !== f)) }
const prompts = []
@@ -24,7 +35,13 @@ function harness(replies, config = {}) {
}
const steered = []
const agent = { session, ctx: { on }, steer: (m) => steered.push(m) }
const ctx = { agents: { list: () => [] }, llm, on, effect() {} }
const routes = new Map()
const webServer = { register: (r) => { routes.set(r.path, r.handler); return () => routes.delete(r.path) } }
const connection = { requestRejection: (req) => (req.headers?.['x-reject'] ? 401 : undefined) }
const ctx = {
agents: { list: () => [] }, llm, on, effect(fn) { return typeof fn === 'function' ? fn() : undefined },
inject: (_deps, fn) => fn({ webServer, connection, effect: (f) => f() }),
}
plugin.apply(ctx, { minLevel: 'note', blocking: true, ...config })
for (const f of listeners.get('agent/created') ?? []) f({ agent })
const preStep = async (step) => {
@@ -34,7 +51,18 @@ function harness(replies, config = {}) {
}
const stopTurn = async () => { for (const f of listeners.get('agent/turn-stopping') ?? []) await f({ agent, turn: 1 }) }
const add = (role, content) => events.push({ msg: { role, content } })
return { preStep, stopTurn, add, steered, prompts }
/** Call the settings route like the web client does. */
const http = async (method, body, headers = {}) => {
const handler = routes.get('/omp-advisor/settings')
const req = Readable.from(body === undefined ? [] : [JSON.stringify(body)])
req.method = method
req.headers = headers
let status = 200; let out = ''
const res = { statusCode: 200, setHeader() {}, end: (s) => { status = res.statusCode; out = s ?? '' } }
await handler(req, res)
return { status, json: out ? JSON.parse(out) : null }
}
return { preStep, stopTurn, add, steered, prompts, http }
}
test('parseVerdict', () => {
@@ -82,3 +110,34 @@ test('minLevel filters notes and duplicates are suppressed', async () => {
assert.equal((await h.preStep(3)).messages.length, 1) // concern (blocking review) delivered
assert.equal((await h.preStep(4)).messages.length, 0) // identical concern suppressed
})
test('settings route: GET/POST, rejection, persistence', async () => {
fs.rmSync(SETTINGS, { force: true })
const h = harness([])
assert.equal((await h.http('GET', undefined, { 'x-reject': '1' })).status, 401)
const g = await h.http('GET')
assert.equal(g.status, 200)
assert.equal(g.json.enabled, true)
const p = await h.http('POST', { enabled: true, provider: 'omni', model: 'cheap-model', reasoningEffort: 'low' })
assert.equal(p.json.model, 'cheap-model')
assert.equal(p.json.reasoningEffort, 'low')
assert.deepEqual(JSON.parse(fs.readFileSync(SETTINGS, 'utf8')), { enabled: true, provider: 'omni', model: 'cheap-model', reasoningEffort: 'low' })
assert.equal((await h.http('PUT', {})).status, 405)
})
test('UI choice applies on the next review without restart; off disables reviews', async () => {
fs.rmSync(SETTINGS, { force: true })
const h = harness(['{"verdict":"ok","message":""}', '{"verdict":"ok","message":""}'])
h.add('user', [{ type: 'text', text: 'task' }])
await h.http('POST', { enabled: true, provider: 'omni', model: 'cheap-model', reasoningEffort: 'low' })
await h.preStep(2)
assert.equal(h.prompts[0].model, 'cheap-model')
assert.equal(h.prompts[0].reasoningEffort, 'low')
await h.http('POST', { provider: '', model: '', reasoningEffort: null }) // same as agent
await h.preStep(3)
assert.equal(h.prompts[1].model, 'main-model')
assert.equal(h.prompts[1].reasoningEffort, undefined)
await h.http('POST', { enabled: false })
await h.preStep(4)
assert.equal(h.prompts.length, 2) // no review while off
})