dsh-sansheng-liubu/sansheng/test/prompt.test.js

62 lines
2.7 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { installPromptSection } from '../src/host/prompt.js'
import { setupService, seatById } from './helpers.js'
test('只对十席会话注入角色提示', async () => {
const { service, store, fake } = await setupService()
installPromptSection(fake.ctx, { store })
const section = fake.getPromptSection()
assert.ok(section)
assert.equal(section.name, 'sansheng')
const opened = await service.open({ path: '/pp', name: '提示项目' })
await service.enable(opened.project.id)
const p = await service.project(opened.project.id)
const seat = seatById(p, 'gongbu')
const text = section.text({ agent: { id: seat.sessionId } })
assert.match(text, /工部/)
assert.match(text, /代码实现与工程产出/)
const bySession = section.text({ agent: { id: 'runtime-agent-id', session: { id: seat.sessionId } } })
assert.match(bySession, /工部/)
assert.equal(section.text({ agent: { id: 'other-session' } }), '')
assert.equal(section.text({}), '')
})
test('补充说明出现在提示里', async () => {
const { service, store, fake } = await setupService()
installPromptSection(fake.ctx, { store })
const opened = await service.open({ path: '/pp2', name: 'p' })
await service.enable(opened.project.id)
await service.configure(opened.project.id, 'libu', { instructions: '先问清目标' })
const p = await service.project(opened.project.id)
const text = fake.getPromptSection().text({ agent: { id: seatById(p, 'libu').sessionId } })
assert.match(text, /先问清目标/)
})
test('丞相提示包含 Grill Me 规则,其他九席不注入', async () => {
const { service, store, fake } = await setupService()
installPromptSection(fake.ctx, { store })
const opened = await service.open({ path: '/pp3', name: 'Grill 项目' })
await service.enable(opened.project.id)
const p = await service.project(opened.project.id)
const section = fake.getPromptSection()
const leadText = section.text({ agent: { id: seatById(p, 'lead').sessionId } })
assert.match(leadText, /Grill Me 需求澄清规则/)
assert.ok(leadText.includes('skill({ name: "grilling" })'))
assert.match(leadText, /expectedRevision/)
assert.match(leadText, /不创建任务、不派工、不生成批准凭证/)
assert.match(leadText, /不得假装使用 grill-me\/grilling/)
assert.match(leadText, /发布 R-xxx 给中书/)
for (const seatId of ['zhongshu', 'menxia', 'shangshu', 'libu', 'hubu', 'lipu', 'bingbu', 'xingbu', 'gongbu']) {
const text = section.text({ agent: { id: seatById(p, seatId).sessionId } })
assert.doesNotMatch(text, /Grill Me/)
assert.ok(!text.includes('skill({ name: "grilling" })'))
}
})