| 1 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 2 | import { PRODUCT_SKILLS_ROUTE } from '../../../src/main/product-skills/contract' |
| 3 | |
| 4 | const logMock = vi.hoisted(() => ({ |
| 5 | info: vi.fn(), |
| 6 | })) |
| 7 | |
| 8 | vi.mock('electron-log/main.js', () => ({ |
| 9 | default: logMock, |
| 10 | })) |
| 11 | |
| 12 | describe('logAgentToolEvents', () => { |
| 13 | beforeEach(() => { |
| 14 | logMock.info.mockClear() |
| 15 | }) |
| 16 | |
| 17 | it('logs a dedicated event when read_file opens a product skill file', async () => { |
| 18 | const { logAgentToolEvents } = await import('../../../src/main/utils/agent-tool-logger') |
| 19 | const path = `${PRODUCT_SKILLS_ROUTE}system/oh-my-ppt-data-anim/SKILL.md` |
| 20 | |
| 21 | logAgentToolEvents( |
| 22 | { |
| 23 | model: { |
| 24 | messages: [ |
| 25 | { |
| 26 | additional_kwargs: { |
| 27 | tool_calls: [ |
| 28 | { |
| 29 | id: 'call_1', |
| 30 | function: { |
| 31 | name: 'read_file', |
| 32 | arguments: JSON.stringify({ path }), |
| 33 | }, |
| 34 | }, |
| 35 | ], |
| 36 | }, |
| 37 | }, |
| 38 | ], |
| 39 | }, |
| 40 | }, |
| 41 | new Set<string>(), |
| 42 | { tag: 'deepagent', source: 'updates' } |
| 43 | ) |
| 44 | |
| 45 | expect(logMock.info).toHaveBeenCalledWith( |
| 46 | '[deepagent] product_skill_read_file', |
| 47 | expect.objectContaining({ |
| 48 | source: 'updates', |
| 49 | toolName: 'read_file', |
| 50 | toolCallId: 'call_1', |
| 51 | skillName: 'oh-my-ppt-data-anim', |
| 52 | path, |
| 53 | }) |
| 54 | ) |
| 55 | }) |
| 56 | |
| 57 | it('does not emit product skill read logs for normal project files', async () => { |
| 58 | const { logAgentToolEvents } = await import('../../../src/main/utils/agent-tool-logger') |
| 59 | |
| 60 | logAgentToolEvents( |
| 61 | { |
| 62 | tool_calls: [ |
| 63 | { |
| 64 | id: 'call_2', |
| 65 | name: 'read_file', |
| 66 | args: { path: '/page-1.html' }, |
| 67 | }, |
| 68 | ], |
| 69 | }, |
| 70 | new Set<string>(), |
| 71 | { tag: 'deepagent', source: 'messages' } |
| 72 | ) |
| 73 | |
| 74 | expect( |
| 75 | logMock.info.mock.calls.some(([message]) => message === '[deepagent] product_skill_read_file') |
| 76 | ).toBe(false) |
| 77 | }) |
| 78 | }) |
| 79 |