From e8415a0d58d6b9de603c2a88c4e60016fb517d90 Mon Sep 17 00:00:00 2001 From: Matt Seddon Date: Tue, 11 Apr 2023 16:24:15 +1000 Subject: [PATCH] duplicate functions out to reader (tests will break) --- extension/src/cli/dvc/contract.ts | 2 +- extension/src/cli/dvc/reader.ts | 34 +++- extension/src/data/index.ts | 4 +- .../src/experiments/columns/collect/index.ts | 76 ++++++++- extension/src/experiments/columns/model.ts | 39 ++++- .../src/experiments/data/collect.test.ts | 150 +++++++++--------- extension/src/experiments/data/collect.ts | 13 +- extension/src/experiments/data/index.ts | 14 +- extension/src/experiments/index.ts | 34 +++- extension/src/experiments/model/collect.ts | 2 +- extension/src/plots/index.ts | 31 ++-- .../test/suite/experiments/data/index.test.ts | 37 +++-- extension/src/test/suite/experiments/util.ts | 9 +- 13 files changed, 312 insertions(+), 133 deletions(-) diff --git a/extension/src/cli/dvc/contract.ts b/extension/src/cli/dvc/contract.ts index ceb91bef2c..c005c4d07c 100644 --- a/extension/src/cli/dvc/contract.ts +++ b/extension/src/cli/dvc/contract.ts @@ -100,7 +100,7 @@ export interface ExperimentsOutput { type ValueTreeOrError_ = { data: ValueTree } | DvcError type MetricsOrParams = RelPathObject -type ExpStateData = { +export type ExpStateData = { rev: string timestamp: string | null params: MetricsOrParams | null diff --git a/extension/src/cli/dvc/reader.ts b/extension/src/cli/dvc/reader.ts index e2b18091f8..f8cbd427d4 100644 --- a/extension/src/cli/dvc/reader.ts +++ b/extension/src/cli/dvc/reader.ts @@ -15,7 +15,8 @@ import { EXPERIMENT_WORKSPACE_ID, PlotsOutput, PlotsOutputOrError, - RawPlotsOutput + RawPlotsOutput, + ExpShowOutput } from './contract' import { getOptions } from './options' import { typeCheckCommands } from '..' @@ -29,7 +30,11 @@ const defaultExperimentsOutput: ExperimentsOutput = { } export const isDvcError = < - T extends ExperimentsOutput | DataStatusOutput | RawPlotsOutput + T extends + | ExperimentsOutput + | ExpShowOutput + | DataStatusOutput + | RawPlotsOutput >( dataOrError: T | DvcError ): dataOrError is DvcError => @@ -38,6 +43,7 @@ export const isDvcError = < export const autoRegisteredCommands = { DATA_STATUS: 'dataStatus', EXP_SHOW: 'expShow', + EXP_SHOW_: 'expShow_', GLOBAL_VERSION: 'globalVersion', PLOTS_DIFF: 'plotsDiff', ROOT: 'root', @@ -65,6 +71,24 @@ export class DvcReader extends DvcCli { ) } + public async expShow_( + cwd: string, + ...flags: (ExperimentFlag | string)[] + ): Promise { + const output = await this.readProcess( + cwd, + JSON.stringify([]), + Command.EXPERIMENT, + SubCommand.SHOW, + ...flags, + Flag.JSON + ) + if (isDvcError(output) || isEmpty(output)) { + return [{ rev: EXPERIMENT_WORKSPACE_ID, ...(output as DvcError) }] + } + return output + } + public async expShow( cwd: string, ...flags: (ExperimentFlag | string)[] @@ -150,7 +174,11 @@ export class DvcReader extends DvcCli { } private async readProcess< - T extends DataStatusOutput | ExperimentsOutput | RawPlotsOutput + T extends + | DataStatusOutput + | ExperimentsOutput + | ExpShowOutput + | RawPlotsOutput >(cwd: string, defaultValue: string, ...args: Args): Promise { try { const output = diff --git a/extension/src/data/index.ts b/extension/src/data/index.ts index 46fb99282d..7277b1dd94 100644 --- a/extension/src/data/index.ts +++ b/extension/src/data/index.ts @@ -4,13 +4,13 @@ import { getRelativePattern } from '../fileSystem/relativePattern' import { createFileSystemWatcher } from '../fileSystem/watcher' import { ProcessManager } from '../process/manager' import { InternalCommands } from '../commands/internal' -import { ExperimentsOutput, PlotsOutputOrError } from '../cli/dvc/contract' +import { ExpShowOutput, PlotsOutputOrError } from '../cli/dvc/contract' import { uniqueValues } from '../util/array' import { DeferredDisposable } from '../class/deferred' import { isSameOrChild } from '../fileSystem' export abstract class BaseData< - T extends { data: PlotsOutputOrError; revs: string[] } | ExperimentsOutput + T extends { data: PlotsOutputOrError; revs: string[] } | ExpShowOutput > extends DeferredDisposable { public readonly onDidUpdate: Event diff --git a/extension/src/experiments/columns/collect/index.ts b/extension/src/experiments/columns/collect/index.ts index 18f2cbcc9e..b5d9fac494 100644 --- a/extension/src/experiments/columns/collect/index.ts +++ b/extension/src/experiments/columns/collect/index.ts @@ -8,6 +8,10 @@ import { } from './metricsAndParams' import { Column } from '../../webview/contract' import { + ExpRange, + ExpShowOutput, + ExpState, + ExpStateData, ExperimentFields, ExperimentFieldsOrError, ExperimentsCommitOutput, @@ -16,7 +20,7 @@ import { import { standardizePath } from '../../../fileSystem/path' import { timestampColumn } from '../constants' import { sortCollectedArray } from '../../../util/array' -import { isCheckpoint } from '../../model/collect' +import { hasError, isCheckpoint } from '../../model/collect' const collectFromExperiment = ( acc: ColumnAccumulator, @@ -59,6 +63,38 @@ export const collectColumns = (data: ExperimentsOutput): Column[] => { return hasNoData ? [] : columns } +const collectFromExperiments = ( + acc: ColumnAccumulator, + experiments?: ExpRange[] | null +) => { + if (!experiments) { + return + } + for (const { revs } of experiments) { + collectFromExperiment(acc, revs[0]) + } +} + +export const collectColumns_ = (output: ExpShowOutput): Column[] => { + const acc: ColumnAccumulator = {} + + acc.timestamp = timestampColumn + + for (const expState of output) { + if (hasError(expState)) { + continue + } + + collectFromExperiment(acc, expState) + collectFromExperiments(acc, expState.experiments) + } + + const columns = Object.values(acc) + const hasNoData = isEqual(columns, [timestampColumn]) + + return hasNoData ? [] : columns +} + const getData = (value?: { baseline?: ExperimentFieldsOrError }): ExperimentFields | undefined => value?.baseline?.data @@ -80,6 +116,30 @@ export const collectChanges = (data: ExperimentsOutput): string[] => { return sortCollectedArray(changes) } +export const getData_ = (expState: ExpState): ExpStateData | undefined => { + if (hasError(expState)) { + return + } + return expState?.data +} + +export const collectChanges_ = (output: ExpShowOutput): string[] => { + const changes: string[] = [] + + const [workspaceData, currentCommitData] = output + const workspace = getData_(workspaceData) + const currentCommit = getData_(currentCommitData) + + if (!(workspace && currentCommit)) { + return changes + } + + collectMetricAndParamChanges(changes, workspace, currentCommit) + collectDepChanges(changes, workspace, currentCommit) + + return sortCollectedArray(changes) +} + export const collectParamsFiles = ( dvcRoot: string, data: ExperimentsOutput @@ -89,3 +149,17 @@ export const collectParamsFiles = ( .map(file => standardizePath(join(dvcRoot, file))) return new Set(files) } + +export const collectParamsFiles_ = ( + dvcRoot: string, + output: ExpShowOutput +): Set => { + const [workspace] = output + if (hasError(workspace)) { + return new Set() + } + const files = Object.keys(workspace.data.params || {}) + .filter(Boolean) + .map(file => standardizePath(join(dvcRoot, file))) + return new Set(files) +} diff --git a/extension/src/experiments/columns/model.ts b/extension/src/experiments/columns/model.ts index 2638db5be7..bec9f068c2 100644 --- a/extension/src/experiments/columns/model.ts +++ b/extension/src/experiments/columns/model.ts @@ -1,8 +1,15 @@ import { EventEmitter, Memento } from 'vscode' -import { collectChanges, collectColumns, collectParamsFiles } from './collect' +import { + collectChanges, + collectChanges_, + collectColumns, + collectColumns_, + collectParamsFiles, + collectParamsFiles_ +} from './collect' import { EXPERIMENT_COLUMN_ID, timestampColumn } from './constants' import { Column, ColumnType } from '../webview/contract' -import { ExperimentsOutput } from '../../cli/dvc/contract' +import { ExpShowOutput, ExperimentsOutput } from '../../cli/dvc/contract' import { PersistenceKey } from '../../persistence/constants' import { PathSelectionModel, Status } from '../../path/selection/model' @@ -59,6 +66,13 @@ export class ColumnsModel extends PathSelectionModel { ]) } + public transformAndSet_(data: ExpShowOutput) { + return Promise.all([ + this.transformAndSetColumns_(data), + this.transformAndSetChanges_(data) + ]) + } + public getChanges() { return this.columnsChanges } @@ -170,7 +184,28 @@ export class ColumnsModel extends PathSelectionModel { this.paramsFiles = paramsFiles } + private async transformAndSetColumns_(data: ExpShowOutput) { + const [columns, paramsFiles] = await Promise.all([ + collectColumns_(data), + collectParamsFiles_(this.dvcRoot, data) + ]) + + this.setNewStatuses(columns) + + this.data = columns + + if (this.columnOrderState.length === 0) { + this.setColumnOrder(this.getColumnOrderFromData()) + } + + this.paramsFiles = paramsFiles + } + private transformAndSetChanges(data: ExperimentsOutput) { this.columnsChanges = collectChanges(data) } + + private transformAndSetChanges_(data: ExpShowOutput) { + this.columnsChanges = collectChanges_(data) + } } diff --git a/extension/src/experiments/data/collect.test.ts b/extension/src/experiments/data/collect.test.ts index 11f4b2e89b..2ba3df1957 100644 --- a/extension/src/experiments/data/collect.test.ts +++ b/extension/src/experiments/data/collect.test.ts @@ -1,11 +1,7 @@ import { join } from 'path' import { collectFiles } from './collect' -import { - ExperimentsOutput, - ExperimentStatus, - EXPERIMENT_WORKSPACE_ID -} from '../../cli/dvc/contract' -import expShowFixture from '../../test/fixtures/expShow/base/output' +import { EXPERIMENT_WORKSPACE_ID } from '../../cli/dvc/contract' +import expShowFixture from '../../test/fixtures/expShow/base/output_' describe('collectFiles', () => { it('should collect all of the available files from the test fixture', () => { @@ -17,70 +13,81 @@ describe('collectFiles', () => { }) it('should handle an error being returned', () => { - const workspace = { - [EXPERIMENT_WORKSPACE_ID]: { - baseline: { - error: { msg: 'bad things are happening', type: 'today' } - } + const workspaceOnly = [ + { + error: { msg: 'bad things are happening', type: 'today' }, + rev: EXPERIMENT_WORKSPACE_ID } - } + ] - expect(collectFiles(workspace, [])).toStrictEqual([]) + expect(collectFiles(workspaceOnly, [])).toStrictEqual([]) }) it('should handle a missing params key', () => { - const workspace = { - [EXPERIMENT_WORKSPACE_ID]: { - baseline: { - data: { - metrics: { - 'logs.json': {} - } - } - } + const workspaceOnly = [ + { + data: { + deps: null, + meta: { has_checkpoints: false }, + metrics: { + 'logs.json': { data: {} } + }, + outs: null, + params: null, + rev: EXPERIMENT_WORKSPACE_ID, + timestamp: null + }, + rev: EXPERIMENT_WORKSPACE_ID } - } + ] - expect(collectFiles(workspace, [])).toStrictEqual(['logs.json']) + expect(collectFiles(workspaceOnly, [])).toStrictEqual(['logs.json']) }) it('should handle a missing metrics key', () => { - const workspace = { - [EXPERIMENT_WORKSPACE_ID]: { - baseline: { - data: { - params: { - 'params.yaml': {} - } - } - } + const workspaceOnly = [ + { + data: { + deps: null, + meta: { has_checkpoints: false }, + metrics: null, + outs: null, + params: { 'params.yaml': { data: {} } }, + rev: EXPERIMENT_WORKSPACE_ID, + timestamp: null + }, + rev: EXPERIMENT_WORKSPACE_ID } - } + ] - expect(collectFiles(workspace, [])).toStrictEqual(['params.yaml']) + expect(collectFiles(workspaceOnly, [])).toStrictEqual(['params.yaml']) }) it('should collect all of the available files from a more complex example', () => { - const workspace = { - [EXPERIMENT_WORKSPACE_ID]: { - baseline: { - data: { - metrics: { - 'logs.json': {}, - 'metrics.json': {}, - 'summary.json': {} - }, - params: { - 'further/nested/params.yaml': {}, - 'nested/params.yaml': {}, - 'params.yaml': {} - } - } - } + const workspaceOnly = [ + { + data: { + deps: null, + meta: { has_checkpoints: false }, + metrics: { + 'logs.json': { data: {} }, + 'metrics.json': { data: {} }, + 'summary.json': { data: {} } + }, + outs: null, + params: { + 'further/nested/params.yaml': { data: {} }, + 'nested/params.yaml': { data: {} }, + 'params.yaml': { data: {} } + }, + rev: EXPERIMENT_WORKSPACE_ID, + timestamp: null + }, + rev: EXPERIMENT_WORKSPACE_ID } - } as ExperimentsOutput + ] - const files = collectFiles(workspace, []) + const files = collectFiles(workspaceOnly, []) files.sort() expect(files).toStrictEqual([ @@ -94,27 +101,28 @@ describe('collectFiles', () => { }) it('should not remove a previously collected file if it is deleted (removal breaks live updates logged by dvclive)', () => { - const workspace = { - [EXPERIMENT_WORKSPACE_ID]: { - baseline: { - data: { - executor: EXPERIMENT_WORKSPACE_ID, - metrics: {}, - params: { - 'params.yaml': { - data: { - epochs: 100 - } + const workspaceOnly = [ + { + data: { + deps: null, + meta: { has_checkpoints: false }, + metrics: null, + outs: null, + params: { + 'params.yaml': { + data: { + epochs: 100 } - }, - status: ExperimentStatus.RUNNING, - timestamp: null - } - } + } + }, + rev: EXPERIMENT_WORKSPACE_ID, + timestamp: null + }, + rev: EXPERIMENT_WORKSPACE_ID } - } as ExperimentsOutput + ] - expect(collectFiles(workspace, ['dvclive.json'])).toStrictEqual([ + expect(collectFiles(workspaceOnly, ['dvclive.json'])).toStrictEqual([ 'params.yaml', 'dvclive.json' ]) diff --git a/extension/src/experiments/data/collect.ts b/extension/src/experiments/data/collect.ts index a2cdb7a8bf..38f505601c 100644 --- a/extension/src/experiments/data/collect.ts +++ b/extension/src/experiments/data/collect.ts @@ -1,14 +1,19 @@ -import { ExperimentsOutput } from '../../cli/dvc/contract' +import { ExpShowOutput } from '../../cli/dvc/contract' import { uniqueValues } from '../../util/array' +import { getData_ } from '../columns/collect' export const collectFiles = ( - data: ExperimentsOutput, + output: ExpShowOutput, existingFiles: string[] ): string[] => { + const [workspace] = output + + const data = getData_(workspace) + return uniqueValues([ ...Object.keys({ - ...data?.workspace.baseline?.data?.params, - ...data?.workspace.baseline?.data?.metrics + ...data?.params, + ...data?.metrics }).filter(Boolean), ...existingFiles ]) diff --git a/extension/src/experiments/data/index.ts b/extension/src/experiments/data/index.ts index 24e0c3f099..a4209c60e2 100644 --- a/extension/src/experiments/data/index.ts +++ b/extension/src/experiments/data/index.ts @@ -9,7 +9,7 @@ import { import { getRelativePattern } from '../../fileSystem/relativePattern' import { createFileSystemWatcher } from '../../fileSystem/watcher' import { AvailableCommands, InternalCommands } from '../../commands/internal' -import { ExperimentsOutput } from '../../cli/dvc/contract' +import { ExpShowOutput } from '../../cli/dvc/contract' import { BaseData } from '../../data' import { DOT_DVC, ExperimentFlag } from '../../cli/dvc/constants' import { gitPath } from '../../cli/git/constants' @@ -18,7 +18,7 @@ import { ExperimentsModel } from '../model' export const QUEUED_EXPERIMENT_PATH = join(DOT_DVC, 'tmp', 'exps') -export class ExperimentsData extends BaseData { +export class ExperimentsData extends BaseData { private readonly experiments: ExperimentsModel constructor( @@ -43,8 +43,8 @@ export class ExperimentsData extends BaseData { this.experiments = experiments - void this.watchExpGitRefs() - void this.managedUpdate(QUEUED_EXPERIMENT_PATH) + void this.watchExpGitRefs() // drop all refs that aren't HEAD + void this.managedUpdate(QUEUED_EXPERIMENT_PATH) // can also drop full vs partial updates (https://github.com/iterative/dvc/pull/9170#issuecomment-1467937058) } public managedUpdate(path?: string) { @@ -65,8 +65,8 @@ export class ExperimentsData extends BaseData { ExperimentFlag.NUM_COMMIT, this.experiments.getNbOfCommitsToShow().toString() ] - const data = await this.internalCommands.executeCommand( - AvailableCommands.EXP_SHOW, + const data = await this.internalCommands.executeCommand( + AvailableCommands.EXP_SHOW_, this.dvcRoot, ...flags, ...args @@ -77,7 +77,7 @@ export class ExperimentsData extends BaseData { return this.notifyChanged(data) } - protected collectFiles(data: ExperimentsOutput) { + protected collectFiles(data: ExpShowOutput) { this.collectedFiles = collectFiles(data, this.collectedFiles) } diff --git a/extension/src/experiments/index.ts b/extension/src/experiments/index.ts index 076c8e3f36..053ed8a49f 100644 --- a/extension/src/experiments/index.ts +++ b/extension/src/experiments/index.ts @@ -37,7 +37,11 @@ import { DecorationProvider } from './model/decorationProvider' import { starredFilter } from './model/filterBy/constants' import { ResourceLocator } from '../resourceLocator' import { AvailableCommands, InternalCommands } from '../commands/internal' -import { ExperimentsOutput, EXPERIMENT_WORKSPACE_ID } from '../cli/dvc/contract' +import { + ExperimentsOutput, + EXPERIMENT_WORKSPACE_ID, + ExpShowOutput +} from '../cli/dvc/contract' import { ViewKey } from '../webview/constants' import { BaseRepository } from '../webview/repository' import { FileSystemData } from '../fileSystem/data' @@ -64,7 +68,7 @@ export type ModifiedExperimentAndRunCommandId = export class Experiments extends BaseRepository { public readonly onDidChangeIsParamsFileFocused: Event - public readonly onDidChangeExperiments: Event + public readonly onDidChangeExperiments: Event public readonly onDidChangeColumns: Event public readonly onDidChangeColumnOrderOrStatus: Event public readonly onDidChangeCheckpoints: Event @@ -83,7 +87,7 @@ export class Experiments extends BaseRepository { ) private readonly experimentsChanged = this.dispose.track( - new EventEmitter() + new EventEmitter() ) private readonly checkpointsChanged = this.dispose.track( @@ -161,7 +165,7 @@ export class Experiments extends BaseRepository { fileSystemData || new FileSystemData(dvcRoot) ) - this.dispose.track(this.cliData.onDidUpdate(data => this.setState(data))) + this.dispose.track(this.cliData.onDidUpdate(data => this.setState_(data))) this.dispose.track( this.fileSystemData.onDidUpdate(data => { const hadCheckpoints = this.hasCheckpoints() @@ -203,7 +207,23 @@ export class Experiments extends BaseRepository { this.experiments.transformAndSet(data, dvcLiveOnly, commitsOutput) ]) - return this.notifyChanged(data) + return this.notifyChanged() + } + + public async setState_(data: ExpShowOutput) { + const dvcLiveOnly = await this.checkSignalFile() + const [lastCommit] = data.slice(-1) + const commitsOutput = await this.internalCommands.executeCommand( + AvailableCommands.GIT_GET_COMMIT_MESSAGES, + this.dvcRoot, + lastCommit.rev + ) + await Promise.all([ + this.columns.transformAndSet_(data), + this.experiments.transformAndSet_(data, dvcLiveOnly, commitsOutput) + ]) + + return this.notifyChanged() } public hasCheckpoints() { @@ -543,13 +563,13 @@ export class Experiments extends BaseRepository { ) } - private notifyChanged(data?: ExperimentsOutput) { + private notifyChanged() { this.decorationProvider.setState( this.experiments.getLabels(), this.experiments.getLabelsToDecorate(), this.experiments.getErrors() ) - this.experimentsChanged.fire(data) + this.experimentsChanged.fire() this.notifyColumnsChanged() } diff --git a/extension/src/experiments/model/collect.ts b/extension/src/experiments/model/collect.ts index f98d6ab204..15a0baa9a8 100644 --- a/extension/src/experiments/model/collect.ts +++ b/extension/src/experiments/model/collect.ts @@ -335,7 +335,7 @@ export const collectExperiments = ( return acc } -const hasError = (expState: ExpState): expState is ExpWithError => +export const hasError = (expState: ExpState): expState is ExpWithError => !!(expState as { error?: unknown }).error const transformExpState = (experiment: Experiment, expState: ExpState) => { diff --git a/extension/src/plots/index.ts b/extension/src/plots/index.ts index 3a15923a17..e9d1b19964 100644 --- a/extension/src/plots/index.ts +++ b/extension/src/plots/index.ts @@ -220,27 +220,28 @@ export class Plots extends BaseRepository { private waitForInitialData(experiments: Experiments) { const waitForInitialExpData = this.dispose.track( - experiments.onDidChangeExperiments(data => { - if (data) { - this.dispose.untrack(waitForInitialExpData) - waitForInitialExpData.dispose() - this.data.setMetricFiles(data) - this.setupExperimentsListener(experiments) - void this.initializeData() - } + experiments.onDidChangeExperiments(() => { + // if (data) { + this.dispose.untrack(waitForInitialExpData) + waitForInitialExpData.dispose() + // get this from experiments, do not recalc + // this.data.setMetricFiles(data) + this.setupExperimentsListener(experiments) + void this.initializeData() + // } }) ) } private setupExperimentsListener(experiments: Experiments) { this.dispose.track( - experiments.onDidChangeExperiments(async data => { - if (data) { - await Promise.all([ - this.plots.transformAndSetExperiments(), - this.data.setMetricFiles(data) - ]) - } + experiments.onDidChangeExperiments(async () => { + // if (data) { + await Promise.all([ + this.plots.transformAndSetExperiments() // should be renamed + // this.data.setMetricFiles(data) + ]) + // } this.notifyChanged() }) diff --git a/extension/src/test/suite/experiments/data/index.test.ts b/extension/src/test/suite/experiments/data/index.test.ts index 7970e61ce4..2707d1642d 100644 --- a/extension/src/test/suite/experiments/data/index.test.ts +++ b/extension/src/test/suite/experiments/data/index.test.ts @@ -31,6 +31,7 @@ import { EXPERIMENTS_GIT_LOGS_REFS } from '../../../../experiments/data/constant import { gitPath } from '../../../../cli/git/constants' import * as FileSystem from '../../../../fileSystem' import { ExperimentsModel } from '../../../../experiments/model' +import { EXPERIMENT_WORKSPACE_ID } from '../../../../cli/dvc/contract' const MOCK_WORKSPACE_GIT_FOLDER = join(dvcDemoPath, '.mock-git') @@ -52,7 +53,7 @@ suite('Experiments Data Test Suite', () => { }) it('should debounce all calls to update that are made within 200ms', async () => { - const { data, mockExperimentShow } = buildExperimentsData(disposable) + const { data, mockExpShow } = buildExperimentsData(disposable) await Promise.all([ data.managedUpdate(), @@ -63,16 +64,16 @@ suite('Experiments Data Test Suite', () => { data.managedUpdate() ]) - expect(mockExperimentShow).to.be.calledOnce + expect(mockExpShow).to.be.calledOnce }) it('should call the updater function on setup', async () => { - const { data, mockCreateFileSystemWatcher, mockExperimentShow } = + const { data, mockCreateFileSystemWatcher, mockExpShow } = buildExperimentsData(disposable) await data.isReady() - expect(mockExperimentShow).to.be.calledOnce + expect(mockExpShow).to.be.calledOnce expect(mockCreateFileSystemWatcher).to.be.calledOnce expect(getArgOfCall(mockCreateFileSystemWatcher, 0, 2)).to.deep.equal( @@ -93,6 +94,9 @@ suite('Experiments Data Test Suite', () => { if (command === AvailableCommands.GIT_GET_REPOSITORY_ROOT) { return Promise.resolve(gitRoot) } + if (command === AvailableCommands.EXP_SHOW_) { + return Promise.resolve([{ rev: EXPERIMENT_WORKSPACE_ID }]) + } } } as unknown as InternalCommands, disposable.track(new EventEmitter()), @@ -146,6 +150,9 @@ suite('Experiments Data Test Suite', () => { if (command === AvailableCommands.GIT_GET_REPOSITORY_ROOT) { return Promise.resolve(gitRoot) } + if (command === AvailableCommands.EXP_SHOW_) { + return Promise.resolve([{ rev: EXPERIMENT_WORKSPACE_ID }]) + } } } as unknown as InternalCommands, disposable.track(new EventEmitter()), @@ -177,7 +184,7 @@ suite('Experiments Data Test Suite', () => { it('should not use exp show to fetch git refs external to the workspace if the path is not from a temp workspace', async () => { const mockNow = getMockNow() - const { data, mockExperimentShow } = buildExperimentsData(disposable) + const { data, mockExpShow } = buildExperimentsData(disposable) await data.isReady() bypassProcessManagerDebounce(mockNow) @@ -187,13 +194,13 @@ suite('Experiments Data Test Suite', () => { 'isOngoingOrQueued' ).returns(false) - mockExperimentShow.resetHistory() + mockExpShow.resetHistory() await data.managedUpdate() expect(mockIsOngoingOrQueued).to.be.calledWith('fullUpdate') - expect(mockExperimentShow).to.be.calledOnce - expect(mockExperimentShow).to.be.calledWithExactly( + expect(mockExpShow).to.be.calledOnce + expect(mockExpShow).to.be.calledWithExactly( dvcDemoPath, ExperimentFlag.NUM_COMMIT, DEFAULT_NUM_OF_COMMITS_TO_SHOW.toString(), @@ -201,12 +208,12 @@ suite('Experiments Data Test Suite', () => { ) bypassProcessManagerDebounce(mockNow, 2) - mockExperimentShow.resetHistory() + mockExpShow.resetHistory() await data.managedUpdate(EXPERIMENTS_GIT_LOGS_REFS) - expect(mockExperimentShow).to.be.calledOnce - expect(mockExperimentShow).to.be.calledWithExactly( + expect(mockExpShow).to.be.calledOnce + expect(mockExpShow).to.be.calledWithExactly( dvcDemoPath, ExperimentFlag.NUM_COMMIT, DEFAULT_NUM_OF_COMMITS_TO_SHOW.toString(), @@ -216,16 +223,16 @@ suite('Experiments Data Test Suite', () => { it('should use exp show to fetch external git refs if the path to a temporary workspace (queued experiment) is provided', async () => { const mockNow = getMockNow() - const { data, mockExperimentShow } = buildExperimentsData(disposable) + const { data, mockExpShow } = buildExperimentsData(disposable) await data.isReady() bypassProcessManagerDebounce(mockNow) - mockExperimentShow.resetHistory() + mockExpShow.resetHistory() await data.managedUpdate(QUEUED_EXPERIMENT_PATH) - expect(mockExperimentShow).to.be.calledOnce - expect(mockExperimentShow).to.be.calledWithExactly( + expect(mockExpShow).to.be.calledOnce + expect(mockExpShow).to.be.calledWithExactly( dvcDemoPath, ExperimentFlag.NUM_COMMIT, DEFAULT_NUM_OF_COMMITS_TO_SHOW.toString() diff --git a/extension/src/test/suite/experiments/util.ts b/extension/src/test/suite/experiments/util.ts index 6fa31d206c..66b868dbee 100644 --- a/extension/src/test/suite/experiments/util.ts +++ b/extension/src/test/suite/experiments/util.ts @@ -5,6 +5,7 @@ import { WorkspaceExperiments } from '../../../experiments/workspace' import { Experiments } from '../../../experiments' import { Disposer } from '../../../extension' import expShowFixture from '../../fixtures/expShow/base/output' +import expShowFixture_ from '../../fixtures/expShow/base/output_' import { buildMockMemento, dvcDemoPath } from '../../util' import { buildDependencies, @@ -183,12 +184,12 @@ const buildExperimentsDataDependencies = (disposer: Disposer) => { ).returns(undefined) const { dvcReader, internalCommands } = buildInternalCommands(disposer) - const mockExperimentShow = stub(dvcReader, 'expShow').resolves(expShowFixture) - return { internalCommands, mockCreateFileSystemWatcher, mockExperimentShow } + const mockExpShow = stub(dvcReader, 'expShow_').resolves(expShowFixture_) + return { internalCommands, mockCreateFileSystemWatcher, mockExpShow } } export const buildExperimentsData = (disposer: SafeWatcherDisposer) => { - const { internalCommands, mockExperimentShow, mockCreateFileSystemWatcher } = + const { internalCommands, mockExpShow, mockCreateFileSystemWatcher } = buildExperimentsDataDependencies(disposer) const data = disposer.track( @@ -203,7 +204,7 @@ export const buildExperimentsData = (disposer: SafeWatcherDisposer) => { ) ) - return { data, mockCreateFileSystemWatcher, mockExperimentShow } + return { data, mockCreateFileSystemWatcher, mockExpShow } } export const stubWorkspaceExperimentsGetters = (