dsh-better-chat/tests/host-activation.test.ts

50 lines
1.9 KiB
TypeScript

import assert from 'node:assert/strict'
import { test } from 'vitest'
import { Context } from '@deepseek-ai/cordis'
import * as host from '../src/host.js'
/**
* Regression: dsh-better-chat 1.0.1 read `ctx.permissionPresets` before declaring
* it in `inject`. Cordis throws `cannot get property "permissionPresets" without
* inject` on that read, so a clean profile (§ only provides webServer) failed the
* host activation with "1 entry did not activate". The plugin must activate and
* leave the auto-review wiring to a scoped `ctx.inject` callback.
*/
function createContext(services: Record<string, unknown>): Context {
const ctx = new Context()
for (const [name, value] of Object.entries(services)) {
ctx.provide(name as never)
ctx.set(name as never, value as never)
}
return ctx
}
test('host plugin activates when permissionPresets/agents are absent', async () => {
const ctx = createContext({ webServer: { register: () => () => undefined } })
const fiber = ctx.plugin(host as never)
await fiber
assert.equal(fiber.state, 2, 'fiber should be ACTIVE, not FAILED/PENDING')
})
test('host plugin wires the auto-review default through inject', async () => {
const setCalls: Array<[string, string]> = []
const ctx = createContext({
webServer: { register: () => () => undefined },
permissionPresets: {
names: ['read-only', 'auto'],
current: () => 'workspace-write',
set: (session: { id: string }, name: string) => setCalls.push([session.id, name]),
},
agents: {
list: () => [{
session: { id: 'fresh-1', header: { id: 'fresh-1' }, snapshotEvents: () => [] },
}],
},
})
const fiber = ctx.plugin(host as never)
await fiber
assert.equal(fiber.state, 2)
await new Promise(resolve => setTimeout(resolve, 50))
assert.deepEqual(setCalls, [['fresh-1', 'auto']], 'blank top-level session should default to auto review')
})