fix(agent): prevent passing asset IDs to read_thread and improve tool error messages

This commit is contained in:
yiling
2026-07-29 15:18:30 +08:00
parent 1c7a87488b
commit d267c7de98
2 changed files with 29 additions and 2 deletions
@@ -11,6 +11,9 @@ vi.mock('@shumai/db', async (importOriginal) => {
findUnique: vi.fn(),
findMany: vi.fn(),
},
asset: {
findUnique: vi.fn(),
},
},
}
})
@@ -22,6 +25,7 @@ describe('createReadThreadTool', () => {
it('should return error text when thread root comment is not found', async () => {
vi.mocked(prisma.assetComment.findUnique).mockResolvedValue(null)
vi.mocked(prisma.asset.findUnique).mockResolvedValue(null)
const tool = createReadThreadTool()
const result = await tool.execute('call-1', { threadId: 'non-existent' })
@@ -30,6 +34,18 @@ describe('createReadThreadTool', () => {
expect(textContent).toContain('Comment thread with ID "non-existent" not found.')
})
it('should return specific error text when threadId is an asset ID', async () => {
vi.mocked(prisma.assetComment.findUnique).mockResolvedValue(null)
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mock return
vi.mocked(prisma.asset.findUnique).mockResolvedValue({ id: 'asset-1' } as any)
const tool = createReadThreadTool()
const result = await tool.execute('call-asset', { threadId: 'asset-1' })
const textContent = (result.content[0] as { text: string }).text
expect(textContent).toContain('ID "asset-1" is an Asset ID, not a Comment Thread ID')
})
it('should return thread root message and notice when there are no replies', async () => {
vi.mocked(prisma.assetComment.findUnique).mockResolvedValue({
id: 'root-1',