Limit chat history to messages with the current participant (#209898)

* Limit chat history to messages with the current participant

* Fix build error

* Fix build for real
This commit is contained in:
Rob Lourens
2024-04-09 12:56:52 -03:00
committed by GitHub
parent 923c0a87ca
commit eb736c18c2
5 changed files with 40 additions and 12 deletions

View File

@@ -6,7 +6,7 @@
import * as assert from 'assert';
import 'mocha';
import { ChatContext, ChatRequest, ChatResult, ChatVariableLevel, Disposable, Event, EventEmitter, chat, commands } from 'vscode';
import { DeferredPromise, assertNoRpc, closeAllEditors, disposeAll } from '../utils';
import { DeferredPromise, asPromise, assertNoRpc, closeAllEditors, disposeAll } from '../utils';
suite('chat', () => {
@@ -28,11 +28,12 @@ suite('chat', () => {
return deferred;
}
function setupParticipant(): Event<{ request: ChatRequest; context: ChatContext }> {
function setupParticipant(second?: boolean): Event<{ request: ChatRequest; context: ChatContext }> {
const emitter = new EventEmitter<{ request: ChatRequest; context: ChatContext }>();
disposables.push(emitter);
const participant = chat.createChatParticipant('api-test.participant', (request, context, _progress, _token) => {
const id = second ? 'api-test.participant2' : 'api-test.participant';
const participant = chat.createChatParticipant(id, (request, context, _progress, _token) => {
emitter.fire({ request, context });
});
participant.isDefault = true;
@@ -101,4 +102,25 @@ suite('chat', () => {
const result = await deferred.p;
assert.deepStrictEqual(result.metadata, { key: 'value' });
});
test('isolated participant history', async () => {
const onRequest = setupParticipant();
const onRequest2 = setupParticipant(true);
commands.executeCommand('workbench.action.chat.open', { query: '@participant hi' });
await asPromise(onRequest);
// Request is still being handled at this point, wait for it to end
setTimeout(() => {
commands.executeCommand('workbench.action.chat.open', { query: '@participant2 hi' });
}, 0);
const request2 = await asPromise(onRequest2);
assert.strictEqual(request2.context.history.length, 0);
setTimeout(() => {
commands.executeCommand('workbench.action.chat.open', { query: '@participant2 hi' });
}, 0);
const request3 = await asPromise(onRequest2);
assert.strictEqual(request3.context.history.length, 2); // request + response = 2
});
});