Files
deepseek-harness/packages/skill/skill-office/tests/render-context.spec.ts
T
yudshj edd38f1d66 refactor(office): office 工具拆成 office_render/office_convert/office_recalculate,加载 Office 技能后按需声明
- tool-office 注册三个工具,参数规则由各自 schema 表达,运行时拒绝其他工具的参数
- 三个工具共用 when:本 agent 成功加载过 activationSkills 中的技能(内存标记),或上一次请求头已声明 office_*;加载后下一步声明,之后不移除
- Office 技能改用新工具名,加入工具不可用时重新加载 office 的说明和旧格式先转换的说明
- Client 卡片按工具名分派,图片子槽改为 tool.call.office_render.images
- 删除未发布 office 工具的两份升级指南,新增 office-operation-tools 指南,只记录已发布版本的变化
- 刷新 catalog、snapshot、SDK expected 与 Agent Note
2026-11-04 18:17:59 +08:00

46 lines
2.3 KiB
TypeScript

/** Render detection uses recorded tool names, not JSON spelling or quoted skill instructions. */
import { createUserMessage, ToolCallId } from '@deepseek-ai/dsh-llm'
import { Session, SessionId } from '@deepseek-ai/dsh-session'
import { expect, it } from 'vitest'
import { expectNoRenderContext, officeCalls } from './fixtures/real-office.ts'
it.each([undefined, 2])('rejects a native render with JSON indentation %s', (indent) => {
const session = Session.create(SessionId('native-render'))
session.append('tool/call', {
turn: 1, step: 1, callId: ToolCallId('render'), name: 'office_render',
arguments: JSON.stringify({ input: 'input.docx' }, null, indent),
})
expect(officeCalls(session.snapshotEvents())).toEqual([
{ callId: 'render', name: 'office_render', args: { input: 'input.docx' } },
])
expect(() => { expectNoRenderContext(session.snapshotEvents()) }).toThrow()
})
it('rejects a PTC render even without a model-visible PTC result', () => {
const session = Session.create(SessionId('ptc-render'))
session.append('tool/ptc-dispatch', {
rootCallId: ToolCallId('program'), parentCallId: ToolCallId('program'), subCallId: ToolCallId('program:1'),
name: 'office_render', arguments: { input: 'input.docx' }, isError: false, content: [],
})
expect(session.deriveMessages()).toEqual([])
expect(officeCalls(session.snapshotEvents())).toEqual([
{ callId: 'program:1', name: 'office_render', args: { input: 'input.docx' } },
])
expect(() => { expectNoRenderContext(session.snapshotEvents()) }).toThrow()
})
it.each(['office_convert', 'office_recalculate'])('accepts %s and quoted render instructions without a render call', (name) => {
const session = Session.create(SessionId('pdf-conversion'))
session.append('user/message', createUserMessage({
content: [{ type: 'text', text: 'For visual inspection use office_render.' }], source: { kind: 'user' },
}), { surfaceOp: 'append' })
session.append('tool/call', {
turn: 1, step: 1, callId: ToolCallId('output'), name,
arguments: JSON.stringify({ input: 'input.xlsx', format: 'xlsx' }),
})
expect(officeCalls(session.snapshotEvents())).toEqual([
{ callId: 'output', name, args: { input: 'input.xlsx', format: 'xlsx' } },
])
expectNoRenderContext(session.snapshotEvents())
})