Path: blob/main/extensions/copilot/src/extension/byok/vscode-node/test/azureProvider.spec.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';6import { BlockedExtensionService, IBlockedExtensionService } from '../../../../platform/chat/common/blockedExtensionService';7import { DisposableStore } from '../../../../util/vs/base/common/lifecycle';8import { SyncDescriptor } from '../../../../util/vs/platform/instantiation/common/descriptors';9import { createExtensionUnitTestingServices } from '../../../test/node/services';10import { resolveAzureUrl } from '../azureProvider';1112describe('AzureBYOKModelProvider', () => {13const disposables = new DisposableStore();1415beforeEach(() => {16const testingServiceCollection = createExtensionUnitTestingServices();1718// Add IBlockedExtensionService which is required by CopilotLanguageModelWrapper19testingServiceCollection.define(IBlockedExtensionService, new SyncDescriptor(BlockedExtensionService));20});2122afterEach(() => {23disposables.clear();24vi.restoreAllMocks();25});2627describe('resolveAzureUrl', () => {28it('should handle Azure AI Foundry (models.ai.azure.com) URLs', () => {29const url = 'https://my-endpoint.models.ai.azure.com';30const result = resolveAzureUrl('gpt-4', url);31expect(result).toBe('https://my-endpoint.models.ai.azure.com/v1/chat/completions');32});3334it('should handle Azure ML (inference.ml.azure.com) URLs', () => {35const url = 'https://my-endpoint.inference.ml.azure.com';36const result = resolveAzureUrl('gpt-4', url);37expect(result).toBe('https://my-endpoint.inference.ml.azure.com/v1/chat/completions');38});3940it('should handle Azure OpenAI (openai.azure.com) URLs with deployment name', () => {41const url = 'https://my-resource.openai.azure.com';42const result = resolveAzureUrl('gpt-4-deployment', url);43expect(result).toBe('https://my-resource.openai.azure.com/openai/deployments/gpt-4-deployment/chat/completions?api-version=2025-01-01-preview');44});4546it('should return URL unchanged if it already has explicit API path', () => {47const url = 'https://my-endpoint.example.com/v1/chat/completions';48const result = resolveAzureUrl('gpt-4', url);49expect(result).toBe(url);50});5152it('should remove trailing slash before processing', () => {53const url = 'https://my-endpoint.models.ai.azure.com/';54const result = resolveAzureUrl('gpt-4', url);55expect(result).toBe('https://my-endpoint.models.ai.azure.com/v1/chat/completions');56});5758it('should remove /v1 suffix before processing', () => {59const url = 'https://my-endpoint.models.ai.azure.com/v1';60const result = resolveAzureUrl('gpt-4', url);61expect(result).toBe('https://my-endpoint.models.ai.azure.com/v1/chat/completions');62});6364it('should throw error for unrecognized Azure URL', () => {65const url = 'https://unknown.example.com';66expect(() => resolveAzureUrl('gpt-4', url)).toThrow('Unrecognized Azure deployment URL');67});68});6970});717273