Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/workbench/stores/resolvedAMLRun.ts
13399 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 * as fs from 'fs';
6
import * as mobx from 'mobx';
7
import * as readline from 'readline';
8
import { ObservablePromise } from '../utils/utils';
9
import { parseScoredPredictionsCsv } from './amlResults';
10
import { AMLProvider, AMLRun } from './amlSimulations';
11
import { SimulationRunner, TestRuns } from './simulationRunner';
12
13
14
export class ResolvedAMLRun {
15
16
@mobx.computed
17
public get tests(): ObservablePromise<TestRuns[]> {
18
const selected = this.amlProvider.selected;
19
if (!selected) {
20
return ObservablePromise.resolve([]);
21
}
22
return new ObservablePromise((async () => {
23
return this.testsForRun(selected);
24
})(), []);
25
}
26
27
@mobx.computed
28
public get testsToCompareAgainst(): ObservablePromise<TestRuns[]> {
29
const compareAgainstRun = this.amlProvider.compareAgainstRun;
30
if (!compareAgainstRun) {
31
return ObservablePromise.resolve([]);
32
}
33
return new ObservablePromise((async () => {
34
return this.testsForRun(compareAgainstRun);
35
})(), []);
36
}
37
38
private async testsForRun(run: AMLRun): Promise<TestRuns[]> {
39
const testRuns = await SimulationRunner.readFromStdoutJSON(run.stdoutPath, run.simulationInputPath);
40
41
if (run.scoredPredictionsJSONL) {
42
const contents = await this.readContentsLineByLine(run.scoredPredictionsJSONL);
43
const evals = parseScoredPredictionsCsv(run.kind, contents);
44
45
const testRunsMap = new Map<string, TestRuns>();
46
for (const testRun of testRuns) {
47
testRunsMap.set(testRun.name, testRun);
48
}
49
50
for (const evaluation of evals) {
51
const testRun = testRunsMap.get(evaluation.caseName);
52
if (!testRun) {
53
console.warn(`Could not find test run for ${evaluation.caseName}`);
54
continue;
55
}
56
testRun.activeEditorLanguageId = evaluation.activeEditorLanguageId;
57
testRun.runs.forEach((run, i) => {
58
run.pass = evaluation.isEachTestRunSuccess[i];
59
run.errorsOnlyInBefore = evaluation.errorsOnlyInBefore;
60
run.errorsOnlyInAfter = evaluation.errorsOnlyInAfter;
61
run.stdout = evaluation.stdout;
62
run.stderr = evaluation.stderr;
63
run.error ??= evaluation.evaluatorError;
64
if (evaluation.annotations) {
65
run.annotations.push(...evaluation.annotations);
66
}
67
run.generatedTestCaseCount = evaluation.generatedTestCaseCount;
68
run.generatedAssertCount = evaluation.generatedAssertCount;
69
run.expectedDiff = evaluation.expectedDiff;
70
});
71
}
72
}
73
74
return testRuns;
75
}
76
77
private async readContentsLineByLine(filePath: string): Promise<string[]> {
78
return new Promise((resolve) => {
79
const contents: string[] = [];
80
const rd = readline.createInterface({
81
input: fs.createReadStream(filePath)
82
});
83
rd.on('line', function (line) {
84
contents.push(line);
85
});
86
rd.on('close', function () {
87
resolve(contents);
88
});
89
});
90
}
91
92
constructor(
93
private readonly amlProvider: AMLProvider
94
) {
95
mobx.makeObservable(this);
96
}
97
}
98
99