Path: blob/main/extensions/copilot/test/testVisualizationRunnerSTestRunner.ts
13383 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*--------------------------------------------------------------------------------------------*/4import { VisualizationTestRun } from '../src/extension/inlineChat/node/rendererVisualization';5import '../src/extension/intents/node/allIntents';6import { ISimulationTestContext, NulSimulationTestContext } from '../src/platform/simulationTestContext/common/simulationTestContext';7import { NullTestProvider } from '../src/platform/testing/common/nullTestProvider';8import { ITestProvider } from '../src/platform/testing/common/testProvider';9import { IDebugValueEditorGlobals } from '../src/util/common/debugValueEditorGlobals';10import { ChatMLSQLiteCache } from './base/chatMLCache';11import { TestingCacheSalts } from './base/salts';12import { CacheMode, createSimulationAccessor, createSimulationChatModelThrottlingTaskLaunchers, CurrentTestRunInfo, SimulationServicesOptions } from './base/simulationContext';13import { FetchRequestCollector } from './base/spyingChatMLFetcher';14import { ISimulationTestRuntime, SimulationTestRuntime, SimulationTestsRegistry } from './base/stest';15import { IJSONOutputPrinter } from './jsonOutputPrinter';1617const g = globalThis as any as IDebugValueEditorGlobals;1819export async function run(fullPath: string, testFullName: string) {20SimulationTestsRegistry.allowTestReregistration();21VisualizationTestRun.startRun();2223require(fullPath);2425const tests = SimulationTestsRegistry.getAllTests();26const test = tests.find(t => t.fullName === testFullName)!;2728if (!test) {29console.error('Test not found', testFullName);30return;31}3233const currentTestRunInfo: CurrentTestRunInfo = {34test,35testRunNumber: 0,36fetchRequestCollector: new FetchRequestCollector(),37isInRealExtensionHost: false,38};39const simulationServicesOptions: SimulationServicesOptions = {40chatModelThrottlingTaskLaunchers: createSimulationChatModelThrottlingTaskLaunchers(false),41createChatMLCache: (info: CurrentTestRunInfo) => new ChatMLSQLiteCache(TestingCacheSalts.requestCacheSalt, info),42isNoFetchModeEnabled: false,43languageModelCacheMode: CacheMode.Default,44resourcesCacheMode: CacheMode.Default,45disabledTools: new Set(),46swebenchPrompt: false,47summarizeHistory: true,48useExperimentalCodeSearchService: false,49configs: undefined,50};51const testingServiceCollection = await createSimulationAccessor(52{ chatModel: test.model, embeddingType: test.embeddingType },53simulationServicesOptions,54currentTestRunInfo55);56testingServiceCollection.define(IJSONOutputPrinter, {57print(obj: any) {58console.log(obj);59},60_serviceBrand: undefined,61});62testingServiceCollection.define(ITestProvider, new NullTestProvider());63testingServiceCollection.define(ISimulationTestRuntime, new SimulationTestRuntime('./', './.simulation/visualization-out', 1));64testingServiceCollection.define(ISimulationTestContext, new NulSimulationTestContext());6566try {67const startTime = Date.now();68g.$$debugValueEditor_properties = [];69await test?.run(testingServiceCollection);70const endTime = Date.now();71const duration = endTime - startTime;72console.log('> Test finished (' + duration + 'ms).');73} catch (e) {74console.error('Test failed:', e);75} finally {76testingServiceCollection.dispose();77}78}7980console.log('> Playground runner ready.');818283