Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/test/browser/chatDebugEventDetailRenderer.test.ts
13406 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
8
import { URI } from '../../../../../base/common/uri.js';
9
import { ChatDebugLogLevel, IChatDebugAgentResponseEvent, IChatDebugGenericEvent, IChatDebugModelTurnEvent, IChatDebugSubagentInvocationEvent, IChatDebugToolCallEvent, IChatDebugUserMessageEvent } from '../../common/chatDebugService.js';
10
import { formatEventDetail } from '../../browser/chatDebug/chatDebugEventDetailRenderer.js';
11
12
suite('formatEventDetail', () => {
13
ensureNoDisposablesAreLeakedInTestSuite();
14
15
test('toolCall - minimal', () => {
16
const event: IChatDebugToolCallEvent = {
17
kind: 'toolCall',
18
sessionResource: URI.parse('test://s1'),
19
created: new Date(),
20
toolName: 'readFile',
21
};
22
const result = formatEventDetail(event);
23
assert.ok(result.includes('readFile'));
24
});
25
26
test('toolCall - with all fields', () => {
27
const event: IChatDebugToolCallEvent = {
28
kind: 'toolCall',
29
sessionResource: URI.parse('test://s1'),
30
created: new Date(),
31
toolName: 'grep_search',
32
toolCallId: 'tc-123',
33
input: '{"query": "test"}',
34
output: '5 results',
35
result: 'success',
36
durationInMillis: 250,
37
};
38
const result = formatEventDetail(event);
39
assert.ok(result.includes('grep_search'));
40
assert.ok(result.includes('tc-123'));
41
assert.ok(result.includes('success'));
42
assert.ok(result.includes('250'));
43
assert.ok(result.includes('{"query": "test"}'));
44
assert.ok(result.includes('5 results'));
45
});
46
47
test('modelTurn - minimal', () => {
48
const event: IChatDebugModelTurnEvent = {
49
kind: 'modelTurn',
50
sessionResource: URI.parse('test://s1'),
51
created: new Date(),
52
};
53
const result = formatEventDetail(event);
54
assert.ok(result.length > 0);
55
});
56
57
test('modelTurn - with all fields', () => {
58
const event: IChatDebugModelTurnEvent = {
59
kind: 'modelTurn',
60
sessionResource: URI.parse('test://s1'),
61
created: new Date(),
62
model: 'gpt-4o',
63
inputTokens: 100,
64
outputTokens: 50,
65
totalTokens: 150,
66
durationInMillis: 320,
67
};
68
const result = formatEventDetail(event);
69
assert.ok(result.includes('gpt-4o'));
70
assert.ok(result.includes('100'));
71
assert.ok(result.includes('50'));
72
assert.ok(result.includes('150'));
73
assert.ok(result.includes('320'));
74
});
75
76
test('generic event', () => {
77
const event: IChatDebugGenericEvent = {
78
kind: 'generic',
79
sessionResource: URI.parse('test://s1'),
80
created: new Date(),
81
name: 'Discovery Start',
82
details: 'Loading instructions',
83
level: ChatDebugLogLevel.Info,
84
};
85
const result = formatEventDetail(event);
86
assert.ok(result.includes('Discovery Start'));
87
assert.ok(result.includes('Loading instructions'));
88
});
89
90
test('generic event without details', () => {
91
const event: IChatDebugGenericEvent = {
92
kind: 'generic',
93
sessionResource: URI.parse('test://s1'),
94
created: new Date(),
95
name: 'Something',
96
level: ChatDebugLogLevel.Trace,
97
};
98
const result = formatEventDetail(event);
99
assert.ok(result.includes('Something'));
100
});
101
102
test('subagentInvocation - minimal', () => {
103
const event: IChatDebugSubagentInvocationEvent = {
104
kind: 'subagentInvocation',
105
sessionResource: URI.parse('test://s1'),
106
created: new Date(),
107
agentName: 'Explore',
108
};
109
const result = formatEventDetail(event);
110
assert.ok(result.includes('Explore'));
111
});
112
113
test('subagentInvocation - with all fields', () => {
114
const event: IChatDebugSubagentInvocationEvent = {
115
kind: 'subagentInvocation',
116
sessionResource: URI.parse('test://s1'),
117
created: new Date(),
118
agentName: 'Data',
119
description: 'Querying KQL',
120
status: 'completed',
121
durationInMillis: 500,
122
toolCallCount: 3,
123
modelTurnCount: 2,
124
};
125
const result = formatEventDetail(event);
126
assert.ok(result.includes('Data'));
127
assert.ok(result.includes('Querying KQL'));
128
assert.ok(result.includes('completed'));
129
assert.ok(result.includes('500'));
130
assert.ok(result.includes('3'));
131
assert.ok(result.includes('2'));
132
});
133
134
test('userMessage', () => {
135
const event: IChatDebugUserMessageEvent = {
136
kind: 'userMessage',
137
sessionResource: URI.parse('test://s1'),
138
created: new Date(),
139
message: 'Help me fix this bug',
140
sections: [
141
{ name: 'System Prompt', content: 'You are a helpful assistant.' },
142
{ name: 'Context', content: 'file.ts attached' },
143
],
144
};
145
const result = formatEventDetail(event);
146
assert.ok(result.includes('Help me fix this bug'));
147
assert.ok(result.includes('System Prompt'));
148
assert.ok(result.includes('You are a helpful assistant.'));
149
assert.ok(result.includes('Context'));
150
assert.ok(result.includes('file.ts attached'));
151
});
152
153
test('userMessage with empty sections', () => {
154
const event: IChatDebugUserMessageEvent = {
155
kind: 'userMessage',
156
sessionResource: URI.parse('test://s1'),
157
created: new Date(),
158
message: 'Simple prompt',
159
sections: [],
160
};
161
const result = formatEventDetail(event);
162
assert.ok(result.includes('Simple prompt'));
163
});
164
165
test('agentResponse', () => {
166
const event: IChatDebugAgentResponseEvent = {
167
kind: 'agentResponse',
168
sessionResource: URI.parse('test://s1'),
169
created: new Date(),
170
message: 'Here is the fix',
171
sections: [
172
{ name: 'Code', content: 'const x = 1;' },
173
],
174
};
175
const result = formatEventDetail(event);
176
assert.ok(result.includes('Here is the fix'));
177
assert.ok(result.includes('Code'));
178
assert.ok(result.includes('const x = 1;'));
179
});
180
});
181
182