115 lines
3.1 KiB
TypeScript
115 lines
3.1 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('does not treat a negated mutation as permission to write', () => {
|
|
expect(
|
|
requiresPascalMutation([
|
|
{
|
|
role: 'user',
|
|
parts: [
|
|
{
|
|
type: 'text',
|
|
text: '请只读取当前场景并汇总元素数量,不要修改任何模型。',
|
|
},
|
|
],
|
|
},
|
|
]),
|
|
).toBe(false)
|
|
|
|
expect(
|
|
requiresPascalMutation([
|
|
{
|
|
role: 'user',
|
|
parts: [{ type: 'text', text: 'Inspect this scene, but do not modify the model.' }],
|
|
},
|
|
]),
|
|
).toBe(false)
|
|
})
|
|
|
|
test('keeps other requested mutations after removing a negated action', () => {
|
|
expect(
|
|
requiresPascalMutation([
|
|
{
|
|
role: 'user',
|
|
parts: [{ type: 'text', text: '不要删除现有墙体,只添加一扇窗。' }],
|
|
},
|
|
]),
|
|
).toBe(true)
|
|
})
|
|
|
|
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 the first inspection step', () => {
|
|
expect(
|
|
pascalAgentStepPolicy({
|
|
hasMutation: false,
|
|
mutationRequired: true,
|
|
mutationToolNames: ['create_room', 'add_door'],
|
|
readOnlyToolNames: ['read_scene'],
|
|
stepNumber: 1,
|
|
}),
|
|
).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'],
|
|
readOnlyToolNames: ['read_scene'],
|
|
stepNumber: 3,
|
|
}),
|
|
).toEqual({ toolChoice: 'auto' })
|
|
})
|
|
|
|
test('only exposes inspection tools for read-only requests', () => {
|
|
expect(
|
|
pascalAgentStepPolicy({
|
|
hasMutation: false,
|
|
mutationRequired: false,
|
|
mutationToolNames: ['apply_patch', 'save_scene'],
|
|
readOnlyToolNames: ['read_scene', 'list_levels'],
|
|
stepNumber: 0,
|
|
}),
|
|
).toEqual({
|
|
activeTools: ['read_scene', 'list_levels'],
|
|
toolChoice: 'auto',
|
|
})
|
|
})
|
|
})
|