diff --git a/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatService_can_deserialize_with_response.0.snap b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatService_can_deserialize_with_response.0.snap new file mode 100644 index 00000000000..08839ed2bf7 --- /dev/null +++ b/src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatService_can_deserialize_with_response.0.snap @@ -0,0 +1,84 @@ +{ + requesterUsername: "test", + requesterAvatarIconUri: undefined, + responderUsername: "", + responderAvatarIconUri: undefined, + initialLocation: "panel", + requests: [ + { + message: { + text: "@ChatProviderWithUsedContext test request", + parts: [ + { + range: { + start: 0, + endExclusive: 28 + }, + editorRange: { + startLineNumber: 1, + startColumn: 1, + endLineNumber: 1, + endColumn: 29 + }, + agent: { + name: "ChatProviderWithUsedContext", + id: "ChatProviderWithUsedContext", + extensionId: { + value: "nullExtensionDescription", + _lower: "nullextensiondescription" + }, + extensionPublisherId: "", + publisherDisplayName: "", + extensionDisplayName: "", + locations: [ "panel" ], + metadata: { }, + slashCommands: [ ], + disambiguation: [ ] + }, + kind: "agent" + }, + { + range: { + start: 28, + endExclusive: 41 + }, + editorRange: { + startLineNumber: 1, + startColumn: 29, + endLineNumber: 1, + endColumn: 42 + }, + text: " test request", + kind: "text" + } + ] + }, + variableData: { variables: [ ] }, + response: [ ], + result: { errorDetails: { message: "No activated agent with id \"ChatProviderWithUsedContext\"" } }, + followups: undefined, + isCanceled: false, + vote: undefined, + voteDownReason: undefined, + agent: { + name: "ChatProviderWithUsedContext", + id: "ChatProviderWithUsedContext", + extensionId: { + value: "nullExtensionDescription", + _lower: "nullextensiondescription" + }, + extensionPublisherId: "", + publisherDisplayName: "", + extensionDisplayName: "", + locations: [ "panel" ], + metadata: { }, + slashCommands: [ ], + disambiguation: [ ] + }, + slashCommand: undefined, + usedContext: undefined, + contentReferences: [ ], + codeCitations: [ ] + } + ] +} \ No newline at end of file diff --git a/src/vs/workbench/contrib/chat/test/common/chatService.test.ts b/src/vs/workbench/contrib/chat/test/common/chatService.test.ts index d4960113662..393c3813b83 100644 --- a/src/vs/workbench/contrib/chat/test/common/chatService.test.ts +++ b/src/vs/workbench/contrib/chat/test/common/chatService.test.ts @@ -33,6 +33,7 @@ import { NullWorkbenchAssignmentService } from '../../../../services/assignment/ import { IExtensionService, nullExtensionDescription } from '../../../../services/extensions/common/extensions.js'; import { IViewsService } from '../../../../services/views/common/viewsService.js'; import { TestContextService, TestExtensionService, TestStorageService } from '../../../../test/common/workbenchTestServices.js'; +import { MarkdownString } from '../../../../../base/common/htmlContent.js'; const chatAgentWithUsedContextId = 'ChatProviderWithUsedContext'; const chatAgentWithUsedContext: IChatAgent = { @@ -67,6 +68,27 @@ const chatAgentWithUsedContext: IChatAgent = { }, }; +const chatAgentWithMarkdownId = 'ChatProviderWithMarkdown'; +const chatAgentWithMarkdown: IChatAgent = { + id: chatAgentWithMarkdownId, + name: chatAgentWithMarkdownId, + extensionId: nullExtensionDescription.identifier, + publisherDisplayName: '', + extensionPublisherId: '', + extensionDisplayName: '', + locations: [ChatAgentLocation.Panel], + metadata: {}, + slashCommands: [], + disambiguation: [], + async invoke(request, progress, history, token) { + progress({ kind: 'markdownContent', content: new MarkdownString('test') }); + return { metadata: { metadataKey: 'value' } }; + }, + async provideFollowups(sessionId, token) { + return []; + }, +}; + function getAgentData(id: string) { return { name: id, @@ -116,6 +138,7 @@ suite('ChatService', () => { }; testDisposables.add(chatAgentService.registerAgent('testAgent', { ...getAgentData('testAgent'), isDefault: true })); testDisposables.add(chatAgentService.registerAgent(chatAgentWithUsedContextId, getAgentData(chatAgentWithUsedContextId))); + testDisposables.add(chatAgentService.registerAgent(chatAgentWithMarkdownId, getAgentData(chatAgentWithMarkdownId))); testDisposables.add(chatAgentService.registerAgentImplementation('testAgent', agent)); chatAgentService.updateAgent('testAgent', { requester: { name: 'test' } }); }); @@ -253,4 +276,32 @@ suite('ChatService', () => { await assertSnapshot(chatModel2.toExport()); }); + + test('can deserialize with response', async () => { + let serializedChatData: ISerializableChatData; + testDisposables.add(chatAgentService.registerAgentImplementation(chatAgentWithMarkdownId, chatAgentWithMarkdown)); + + { + const testService = testDisposables.add(instantiationService.createInstance(ChatService)); + + const chatModel1 = testDisposables.add(testService.startSession(ChatAgentLocation.Panel, CancellationToken.None)); + assert.strictEqual(chatModel1.getRequests().length, 0); + + const response = await testService.sendRequest(chatModel1.sessionId, `@${chatAgentWithUsedContextId} test request`); + assert(response); + + await response.responseCompletePromise; + + serializedChatData = JSON.parse(JSON.stringify(chatModel1)); + } + + // try deserializing the state into a new service + + const testService2 = testDisposables.add(instantiationService.createInstance(ChatService)); + + const chatModel2 = testService2.loadSessionFromContent(serializedChatData); + assert(chatModel2); + + await assertSnapshot(chatModel2.toExport()); + }); });