mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
The other tests happen to go inside the block that was setting `request.response`, so add a test that restores a response that has markdown content but no references
This commit is contained in:
+84
@@ -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: [ ]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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());
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user