import test from 'node:test' import assert from 'node:assert/strict' import { setupService, seatById } from './helpers.js' import { createApiHandler } from '../src/host/api.js' 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') assert.ok(seatById(leadView, 'lead').sessionId) assert.ok(seatById(gongView, 'gongbu').sessionId) const created = await env.service.taskCreate(id, { title: '写页面', goal: '完成页面', requirement: '保留标题', ownerSeatId: 'gongbu', }) await env.service.taskDispatch(id, created.task.id) 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 lastDelivery = env.fake.calls.followup.at(-1) assert.equal(lastDelivery.sessionId, shang.sessionId, '汇总请求必须发到尚书会话') const text = lastDelivery.message.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) })