add sync vs async test case for error'ing provideLanguageModelResponse calls (#239676)

https://github.com/microsoft/vscode/issues/235322
This commit is contained in:
Johannes Rieken
2025-02-05 12:26:25 +01:00
committed by GitHub
parent 0185e3b037
commit 057edbab16
3 changed files with 63 additions and 29 deletions

View File

@@ -139,11 +139,11 @@ suite('lm', function () {
}
});
test('LanguageModelError instance is not thrown to extensions#235322', async function () {
test('LanguageModelError instance is not thrown to extensions#235322 (SYNC)', async function () {
disposables.push(vscode.lm.registerChatModelProvider('test-lm', {
async provideLanguageModelResponse(_messages, _options, _extensionId, _progress, _token) {
throw vscode.LanguageModelError.Blocked('You have been blocked');
provideLanguageModelResponse(_messages, _options, _extensionId, _progress, _token) {
throw vscode.LanguageModelError.Blocked('You have been blocked SYNC');
},
async provideTokenCount(_text, _token) {
return 1;
@@ -153,17 +153,41 @@ suite('lm', function () {
const models = await vscode.lm.selectChatModels({ id: 'test-lm' });
assert.strictEqual(models.length, 1);
let output = '';
try {
const response = await models[0].sendRequest([vscode.LanguageModelChatMessage.User('Hello')]);
assert.ok(response);
await models[0].sendRequest([vscode.LanguageModelChatMessage.User('Hello')]);
assert.ok(false, 'EXPECTED error');
} catch (error) {
assert.ok(error instanceof vscode.LanguageModelError);
assert.strictEqual(error.message, 'You have been blocked SYNC');
}
});
test('LanguageModelError instance is not thrown to extensions#235322 (ASYNC)', async function () {
disposables.push(vscode.lm.registerChatModelProvider('test-lm', {
async provideLanguageModelResponse(_messages, _options, _extensionId, _progress, _token) {
throw vscode.LanguageModelError.Blocked('You have been blocked ASYNC');
},
async provideTokenCount(_text, _token) {
return 1;
}
}, testProviderOptions));
const models = await vscode.lm.selectChatModels({ id: 'test-lm' });
assert.strictEqual(models.length, 1);
const response = await models[0].sendRequest([vscode.LanguageModelChatMessage.User('Hello')]);
assert.ok(response);
let output = '';
try {
for await (const thing of response.text) {
output += thing;
}
} catch (error) {
assert.ok(error instanceof vscode.LanguageModelError);
assert.strictEqual(error.message, 'You have been blocked');
assert.strictEqual(error.message, 'You have been blocked ASYNC');
}
assert.strictEqual(output, '');
});