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