ai-chatbot/services/pascal-editor/apps/editor/lib/pascal-agent-intent.test.ts

62 lines
1.7 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { pascalAgentStepPolicy, requiresPascalMutation } from './pascal-agent-intent'
describe('Pascal agent intent', () => {
test('requires a write operation for design requests', () => {
expect(
requiresPascalMutation([
{
role: 'user',
parts: [{ type: 'text', text: '设计一个紧凑的两室一厅住宅' }],
},
]),
).toBe(true)
})
test('allows read-only inspection requests to finish without a write', () => {
expect(
requiresPascalMutation([
{
role: 'user',
parts: [{ type: 'text', text: '列出当前场景的所有楼层' }],
},
]),
).toBe(false)
})
test('uses the latest user message', () => {
expect(
requiresPascalMutation([
{ role: 'user', parts: [{ type: 'text', text: '创建一个房间' }] },
{ role: 'assistant', parts: [{ type: 'text', text: '已完成' }] },
{ role: 'user', parts: [{ type: 'text', text: '现在只检查楼层' }] },
]),
).toBe(false)
})
test('forces a mutation after two inspection steps', () => {
expect(
pascalAgentStepPolicy({
hasMutation: false,
mutationRequired: true,
mutationToolNames: ['create_room', 'add_door'],
stepNumber: 2,
}),
).toEqual({
activeTools: ['create_room', 'add_door'],
toolChoice: 'required',
})
})
test('returns to automatic tool selection after a write succeeds', () => {
expect(
pascalAgentStepPolicy({
hasMutation: true,
mutationRequired: true,
mutationToolNames: ['create_room'],
stepNumber: 3,
}),
).toEqual({ toolChoice: 'auto' })
})
})