Path: blob/main/extensions/copilot/test/simulation/workbench/stores/resolvedAMLRun.ts
13399 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 * as fs from 'fs';5import * as mobx from 'mobx';6import * as readline from 'readline';7import { ObservablePromise } from '../utils/utils';8import { parseScoredPredictionsCsv } from './amlResults';9import { AMLProvider, AMLRun } from './amlSimulations';10import { SimulationRunner, TestRuns } from './simulationRunner';111213export class ResolvedAMLRun {1415@mobx.computed16public get tests(): ObservablePromise<TestRuns[]> {17const selected = this.amlProvider.selected;18if (!selected) {19return ObservablePromise.resolve([]);20}21return new ObservablePromise((async () => {22return this.testsForRun(selected);23})(), []);24}2526@mobx.computed27public get testsToCompareAgainst(): ObservablePromise<TestRuns[]> {28const compareAgainstRun = this.amlProvider.compareAgainstRun;29if (!compareAgainstRun) {30return ObservablePromise.resolve([]);31}32return new ObservablePromise((async () => {33return this.testsForRun(compareAgainstRun);34})(), []);35}3637private async testsForRun(run: AMLRun): Promise<TestRuns[]> {38const testRuns = await SimulationRunner.readFromStdoutJSON(run.stdoutPath, run.simulationInputPath);3940if (run.scoredPredictionsJSONL) {41const contents = await this.readContentsLineByLine(run.scoredPredictionsJSONL);42const evals = parseScoredPredictionsCsv(run.kind, contents);4344const testRunsMap = new Map<string, TestRuns>();45for (const testRun of testRuns) {46testRunsMap.set(testRun.name, testRun);47}4849for (const evaluation of evals) {50const testRun = testRunsMap.get(evaluation.caseName);51if (!testRun) {52console.warn(`Could not find test run for ${evaluation.caseName}`);53continue;54}55testRun.activeEditorLanguageId = evaluation.activeEditorLanguageId;56testRun.runs.forEach((run, i) => {57run.pass = evaluation.isEachTestRunSuccess[i];58run.errorsOnlyInBefore = evaluation.errorsOnlyInBefore;59run.errorsOnlyInAfter = evaluation.errorsOnlyInAfter;60run.stdout = evaluation.stdout;61run.stderr = evaluation.stderr;62run.error ??= evaluation.evaluatorError;63if (evaluation.annotations) {64run.annotations.push(...evaluation.annotations);65}66run.generatedTestCaseCount = evaluation.generatedTestCaseCount;67run.generatedAssertCount = evaluation.generatedAssertCount;68run.expectedDiff = evaluation.expectedDiff;69});70}71}7273return testRuns;74}7576private async readContentsLineByLine(filePath: string): Promise<string[]> {77return new Promise((resolve) => {78const contents: string[] = [];79const rd = readline.createInterface({80input: fs.createReadStream(filePath)81});82rd.on('line', function (line) {83contents.push(line);84});85rd.on('close', function () {86resolve(contents);87});88});89}9091constructor(92private readonly amlProvider: AMLProvider93) {94mobx.makeObservable(this);95}96}979899