22 * @vitest -environment node
33 */
44
5- import { describe , expect , it , vi } from 'vitest'
5+ import { beforeEach , describe , expect , it , vi } from 'vitest'
66
77const { toolCallsAdd, toolDurationRecord } = vi . hoisted ( ( ) => ( {
88 toolCallsAdd : vi . fn ( ) ,
@@ -24,8 +24,30 @@ import { TraceAttr } from '@/lib/copilot/generated/trace-attributes-v1'
2424import { recordSimToolMetric } from '@/lib/copilot/request/metrics'
2525
2626describe ( 'recordSimToolMetric' , ( ) => {
27- it ( 'attributes call counts to the agent without adding it to duration' , ( ) => {
28- recordSimToolMetric ( 'read' , 'workflow' , 'success' , 125 )
27+ beforeEach ( ( ) => {
28+ vi . clearAllMocks ( )
29+ } )
30+
31+ it . each ( [ 'main' , 'workflow' ] ) (
32+ 'attributes call counts to the registered %s agent without adding it to duration' ,
33+ ( agentId ) => {
34+ recordSimToolMetric ( 'read' , agentId , 'success' , 125 )
35+
36+ const baseAttributes = {
37+ [ TraceAttr . ToolName ] : 'read' ,
38+ [ TraceAttr . ToolExecutor ] : 'sim' ,
39+ [ TraceAttr . ToolOutcome ] : 'success' ,
40+ }
41+ expect ( toolCallsAdd ) . toHaveBeenCalledWith ( 1 , {
42+ ...baseAttributes ,
43+ [ TraceAttr . GenAiAgentName ] : agentId ,
44+ } )
45+ expect ( toolDurationRecord ) . toHaveBeenCalledWith ( 125 , baseAttributes )
46+ }
47+ )
48+
49+ it ( 'collapses unknown agent IDs to the bounded fallback' , ( ) => {
50+ recordSimToolMetric ( 'read' , 'tenant-defined-agent' , 'success' , 125 )
2951
3052 const baseAttributes = {
3153 [ TraceAttr . ToolName ] : 'read' ,
@@ -34,7 +56,7 @@ describe('recordSimToolMetric', () => {
3456 }
3557 expect ( toolCallsAdd ) . toHaveBeenCalledWith ( 1 , {
3658 ...baseAttributes ,
37- [ TraceAttr . GenAiAgentName ] : 'workflow ' ,
59+ [ TraceAttr . GenAiAgentName ] : 'other ' ,
3860 } )
3961 expect ( toolDurationRecord ) . toHaveBeenCalledWith ( 125 , baseAttributes )
4062 } )
0 commit comments