Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/byok/vscode-node/test/azureProvider.spec.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
import { BlockedExtensionService, IBlockedExtensionService } from '../../../../platform/chat/common/blockedExtensionService';
8
import { DisposableStore } from '../../../../util/vs/base/common/lifecycle';
9
import { SyncDescriptor } from '../../../../util/vs/platform/instantiation/common/descriptors';
10
import { createExtensionUnitTestingServices } from '../../../test/node/services';
11
import { resolveAzureUrl } from '../azureProvider';
12
13
describe('AzureBYOKModelProvider', () => {
14
const disposables = new DisposableStore();
15
16
beforeEach(() => {
17
const testingServiceCollection = createExtensionUnitTestingServices();
18
19
// Add IBlockedExtensionService which is required by CopilotLanguageModelWrapper
20
testingServiceCollection.define(IBlockedExtensionService, new SyncDescriptor(BlockedExtensionService));
21
});
22
23
afterEach(() => {
24
disposables.clear();
25
vi.restoreAllMocks();
26
});
27
28
describe('resolveAzureUrl', () => {
29
it('should handle Azure AI Foundry (models.ai.azure.com) URLs', () => {
30
const url = 'https://my-endpoint.models.ai.azure.com';
31
const result = resolveAzureUrl('gpt-4', url);
32
expect(result).toBe('https://my-endpoint.models.ai.azure.com/v1/chat/completions');
33
});
34
35
it('should handle Azure ML (inference.ml.azure.com) URLs', () => {
36
const url = 'https://my-endpoint.inference.ml.azure.com';
37
const result = resolveAzureUrl('gpt-4', url);
38
expect(result).toBe('https://my-endpoint.inference.ml.azure.com/v1/chat/completions');
39
});
40
41
it('should handle Azure OpenAI (openai.azure.com) URLs with deployment name', () => {
42
const url = 'https://my-resource.openai.azure.com';
43
const result = resolveAzureUrl('gpt-4-deployment', url);
44
expect(result).toBe('https://my-resource.openai.azure.com/openai/deployments/gpt-4-deployment/chat/completions?api-version=2025-01-01-preview');
45
});
46
47
it('should return URL unchanged if it already has explicit API path', () => {
48
const url = 'https://my-endpoint.example.com/v1/chat/completions';
49
const result = resolveAzureUrl('gpt-4', url);
50
expect(result).toBe(url);
51
});
52
53
it('should remove trailing slash before processing', () => {
54
const url = 'https://my-endpoint.models.ai.azure.com/';
55
const result = resolveAzureUrl('gpt-4', url);
56
expect(result).toBe('https://my-endpoint.models.ai.azure.com/v1/chat/completions');
57
});
58
59
it('should remove /v1 suffix before processing', () => {
60
const url = 'https://my-endpoint.models.ai.azure.com/v1';
61
const result = resolveAzureUrl('gpt-4', url);
62
expect(result).toBe('https://my-endpoint.models.ai.azure.com/v1/chat/completions');
63
});
64
65
it('should throw error for unrecognized Azure URL', () => {
66
const url = 'https://unknown.example.com';
67
expect(() => resolveAzureUrl('gpt-4', url)).toThrow('Unrecognized Azure deployment URL');
68
});
69
});
70
71
});
72
73