import test from 'node:test' import assert from 'node:assert/strict' import { apply, name, inject } from '../index.js' import { createFakeHost, tempStateFile } from './fake-ctx.js' test('apply 注册提示词与 /api/sansheng 路由并可处理请求', async () => { const fake = createFakeHost() const statePath = await tempStateFile() const ctx = new Proxy(fake.ctx, { get(target, property, receiver) { if (typeof property === 'string' && !(property in target) && property !== 'on' && property !== 'get') { throw new Error(`cannot get property "${property}" without inject`) } return Reflect.get(target, property, receiver) }, }) await apply(ctx, { statePath, globalSettingPath: statePath + '.global.json' }) assert.equal(name, 'sansheng') assert.ok(inject.includes('connection')) assert.ok(fake.getPromptSection(), '应注册 systemPrompt section') const route = fake.getRoute() assert.equal(route.path, '/api/sansheng') assert.deepEqual(route.methods, ['POST']) const res = await route.fetch({ json: async () => ({ endpoint: 'open', payload: { path: '/w', name: '接线项目' } }) }) const body = await res.json() assert.ok(body.ok) assert.equal(body.value.project.seats.length, 10) })