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