dsh-sansheng-liubu/sansheng/test/shangshu-summary.test.js

64 lines
2.8 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { setupService, seatById } from './helpers.js'
import { createSeatToolDefinitions } from '../src/host/tools.js'
import { createApiHandler } from '../src/host/api.js'
function toolsOf(env) {
const defs = createSeatToolDefinitions({ store: env.store, service: env.service })
return Object.fromEntries(defs.map(def => [def.name, def]))
}
test('尚书汇总:丞相直派不被拦截,汇总请求发送到尚书真实会话', async () => {
const env = await setupService({ prompt: true })
const opened = await env.service.open({ path: '/shangshu-summary', name: '尚书汇总项目' })
const id = opened.project.id
const leadView = await env.service.enableSeat(id, 'lead')
const gongView = await env.service.enableSeat(id, 'gongbu')
const leadSessionId = seatById(leadView, 'lead').sessionId
const gongSessionId = seatById(gongView, 'gongbu').sessionId
const leadExec = { agent: env.fake.sessions.get(leadSessionId) }
const dispatched = await toolsOf(env).sansheng_dispatch_task.execute({
targetSeatId: 'gongbu',
title: '写页面',
goal: '完成页面',
requirement: '保留标题',
}, leadExec)
assert.equal(dispatched.ok, true, '丞相直派仍然成功')
assert.equal(dispatched.sessionId, gongSessionId)
assert.equal(dispatched.targetLabel, '工部')
const before = await env.service.tasks(id)
const result = await env.service.shangshuSummary(id)
const after = await env.service.tasks(id)
assert.equal(after.tasks.length, before.tasks.length, '汇总不能创建新任务')
assert.equal(result.summary.total, 1)
assert.equal(result.summary.statusCounts.dispatched, 1)
assert.equal(result.summary.tasks[0].ownerLabel, '工部')
assert.equal(result.summary.tasks[0].title, '写页面')
const shang = seatById(await env.service.project(id), 'shangshu')
assert.equal(shang.status, 'bound', '汇总会按需开启尚书会话')
assert.equal(result.sessionId, shang.sessionId)
const promptCall = env.fake.calls.prompt.at(-1)
assert.equal(promptCall.sessionId, shang.sessionId, '汇总请求必须发到尚书会话')
const text = promptCall.content[0].text
assert.match(text, /【尚书汇总】/)
assert.match(text, /写页面/)
assert.match(text, /已派工/)
assert.match(text, /不拦截丞相直接派工/)
})
test('尚书汇总 API 返回尚书会话和真实任务汇总', async () => {
const env = await setupService({ prompt: true })
const opened = await env.service.open({ path: '/shangshu-api', name: '尚书接口项目' })
const id = opened.project.id
await env.service.enableSeat(id, 'lead')
const handler = createApiHandler(env.service)
const out = await handler('shangshuSummary', { projectId: id })
assert.equal(out.ok, true)
assert.ok(out.value.sessionId)
assert.equal(out.value.summary.total, 0)
})