Skip to content

Commit 121f651

Browse files
authored
Extract workspace constant (#2889)
1 parent 8ca380e commit 121f651

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+13298
-13113
lines changed

extension/src/cli/dvc/contract.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export enum ExperimentStatus {
5151
SUCCESS = 'Success'
5252
}
5353

54+
export const EXPERIMENT_WORKSPACE_ID = 'workspace'
55+
5456
export interface BaseExperimentFields {
5557
name?: string
5658
timestamp?: string | null
@@ -85,7 +87,7 @@ export interface ExperimentsBranchOutput {
8587

8688
export interface ExperimentsOutput {
8789
[name: string]: ExperimentsBranchOutput
88-
workspace: {
90+
[EXPERIMENT_WORKSPACE_ID]: {
8991
baseline: ExperimentFieldsOrError
9092
}
9193
}

extension/src/cli/dvc/reader.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { join } from 'path'
22
import { EventEmitter } from 'vscode'
33
import { Disposable, Disposer } from '@hediet/std/disposable'
44
import { UNEXPECTED_ERROR_CODE } from './constants'
5+
import { EXPERIMENT_WORKSPACE_ID } from './contract'
56
import { DvcReader } from './reader'
67
import { CliResult, CliStarted } from '..'
78
import { MaybeConsoleError } from '../error'
@@ -91,7 +92,7 @@ describe('CliReader', () => {
9192

9293
const cliOutput = await dvcReader.expShow(cwd)
9394
expect(cliOutput).toStrictEqual({
94-
workspace: {
95+
[EXPERIMENT_WORKSPACE_ID]: {
9596
baseline: { error: { msg: unexpectedStderr, type: 'Caught error' } }
9697
}
9798
})
@@ -104,7 +105,9 @@ describe('CliReader', () => {
104105
)
105106

106107
const cliOutput = await dvcReader.expShow(cwd)
107-
expect(cliOutput).toStrictEqual({ workspace: { baseline: {} } })
108+
expect(cliOutput).toStrictEqual({
109+
[EXPERIMENT_WORKSPACE_ID]: { baseline: {} }
110+
})
108111
})
109112
})
110113

extension/src/cli/dvc/reader.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
DataStatusOutput,
1414
DvcError,
1515
ExperimentsOutput,
16+
EXPERIMENT_WORKSPACE_ID,
1617
PlotsOutput,
1718
PlotsOutputOrError
1819
} from './contract'
@@ -23,7 +24,7 @@ import { Logger } from '../../common/logger'
2324
import { parseNonStandardJson } from '../../util/json'
2425

2526
const defaultExperimentsOutput: ExperimentsOutput = {
26-
workspace: { baseline: {} }
27+
[EXPERIMENT_WORKSPACE_ID]: { baseline: {} }
2728
}
2829

2930
export const isDvcError = <
@@ -74,7 +75,9 @@ export class DvcReader extends DvcCli {
7475
Flag.JSON
7576
)
7677
if (isDvcError(output) || isEmpty(output)) {
77-
return { workspace: { baseline: output as DvcError | {} } }
78+
return {
79+
[EXPERIMENT_WORKSPACE_ID]: { baseline: output as DvcError | {} }
80+
}
7881
}
7982
return output
8083
}

extension/src/experiments/columns/collect/index.test.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import uncommittedDepsFixture from '../../../test/fixtures/expShow/uncommittedDe
1111
import {
1212
ExperimentsOutput,
1313
ExperimentStatus,
14+
EXPERIMENT_WORKSPACE_ID,
1415
ValueTree
1516
} from '../../../cli/dvc/contract'
1617
import { getConfigValue } from '../../../vscode/config'
@@ -28,7 +29,7 @@ describe('collectColumns', () => {
2829

2930
it('should output both params and metrics when both are present', () => {
3031
const columns = collectColumns({
31-
workspace: {
32+
[EXPERIMENT_WORKSPACE_ID]: {
3233
baseline: {
3334
data: {
3435
metrics: {
@@ -55,7 +56,7 @@ describe('collectColumns', () => {
5556

5657
it('should omit params when none exist in the source data', () => {
5758
const columns = collectColumns({
58-
workspace: {
59+
[EXPERIMENT_WORKSPACE_ID]: {
5960
baseline: {
6061
data: {
6162
metrics: {
@@ -75,7 +76,7 @@ describe('collectColumns', () => {
7576

7677
it('should return an empty array if no params and metrics are provided', () => {
7778
const columns = collectColumns({
78-
workspace: {
79+
[EXPERIMENT_WORKSPACE_ID]: {
7980
baseline: {}
8081
}
8182
})
@@ -115,7 +116,7 @@ describe('collectColumns', () => {
115116
}
116117
}
117118
},
118-
workspace: {
119+
[EXPERIMENT_WORKSPACE_ID]: {
119120
baseline: {
120121
data: {
121122
params: {
@@ -192,7 +193,7 @@ describe('collectColumns', () => {
192193
}
193194
}
194195
},
195-
workspace: {
196+
[EXPERIMENT_WORKSPACE_ID]: {
196197
baseline: {}
197198
}
198199
})
@@ -236,7 +237,7 @@ describe('collectColumns', () => {
236237
}
237238
}
238239
},
239-
workspace: {
240+
[EXPERIMENT_WORKSPACE_ID]: {
240241
baseline: {}
241242
}
242243
})
@@ -298,7 +299,7 @@ describe('collectColumns', () => {
298299
}
299300
}
300301
},
301-
workspace: {
302+
[EXPERIMENT_WORKSPACE_ID]: {
302303
baseline: {
303304
data: {
304305
params: {
@@ -327,7 +328,7 @@ describe('collectColumns', () => {
327328

328329
it('should create concatenated columns for nesting deeper than 5', () => {
329330
const columns = collectColumns({
330-
workspace: {
331+
[EXPERIMENT_WORKSPACE_ID]: {
331332
baseline: {
332333
data: {
333334
params: {
@@ -380,7 +381,7 @@ describe('collectColumns', () => {
380381

381382
it('should not report types for params and metrics without primitives or children for params and metrics without objects', () => {
382383
const columns = collectColumns({
383-
workspace: {
384+
[EXPERIMENT_WORKSPACE_ID]: {
384385
baseline: {
385386
data: {
386387
params: {
@@ -557,7 +558,7 @@ describe('collectChanges', () => {
557558

558559
it('should not fail when the workspace does not have metrics but a previous commit does', () => {
559560
const data: ExperimentsOutput = {
560-
workspace: {
561+
[EXPERIMENT_WORKSPACE_ID]: {
561562
baseline: {
562563
data: {
563564
params: mockedExperimentData.baseline.data.params
@@ -660,7 +661,7 @@ describe('collectChanges', () => {
660661
it('should work for missing nested arrays', () => {
661662
expect(
662663
collectChanges({
663-
workspace: {
664+
[EXPERIMENT_WORKSPACE_ID]: {
664665
baseline: {
665666
data: {
666667
timestamp: null,
@@ -738,7 +739,7 @@ describe('collectChanges', () => {
738739

739740
it('should not fail when there is no commit data', () => {
740741
const data: ExperimentsOutput = {
741-
workspace: {
742+
[EXPERIMENT_WORKSPACE_ID]: {
742743
baseline: {
743744
data: {
744745
params: mockedExperimentData.baseline.data.params

extension/src/experiments/columns/model.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import survivalOutputFixture from '../../test/fixtures/expShow/survival/output'
2222
import survivalColumnsFixture from '../../test/fixtures/expShow/survival/columns'
2323
import { getConfigValue } from '../../vscode/config'
2424
import { buildMockedEventEmitter } from '../../test/util/jest'
25+
import { EXPERIMENT_WORKSPACE_ID } from '../../cli/dvc/contract'
2526

2627
jest.mock('../../vscode/config')
2728
jest.mock('@hediet/std/disposable')
@@ -165,7 +166,7 @@ describe('ColumnsModel', () => {
165166
)
166167
const testParamPath = appendColumnToPath(paramsDotYamlPath, 'testparam')
167168
const exampleData = {
168-
workspace: {
169+
[EXPERIMENT_WORKSPACE_ID]: {
169170
baseline: {
170171
data: {
171172
params: {

extension/src/experiments/data/collect.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { join } from 'path'
22
import { collectFiles } from './collect'
3-
import { ExperimentsOutput, ExperimentStatus } from '../../cli/dvc/contract'
3+
import {
4+
ExperimentsOutput,
5+
ExperimentStatus,
6+
EXPERIMENT_WORKSPACE_ID
7+
} from '../../cli/dvc/contract'
48
import expShowFixture from '../../test/fixtures/expShow/base/output'
59

610
describe('collectFiles', () => {
@@ -14,7 +18,7 @@ describe('collectFiles', () => {
1418

1519
it('should handle an error being returned', () => {
1620
const workspace = {
17-
workspace: {
21+
[EXPERIMENT_WORKSPACE_ID]: {
1822
baseline: {
1923
error: { msg: 'bad things are happening', type: 'today' }
2024
}
@@ -26,7 +30,7 @@ describe('collectFiles', () => {
2630

2731
it('should handle a missing params key', () => {
2832
const workspace = {
29-
workspace: {
33+
[EXPERIMENT_WORKSPACE_ID]: {
3034
baseline: {
3135
data: {
3236
metrics: {
@@ -42,7 +46,7 @@ describe('collectFiles', () => {
4246

4347
it('should handle a missing metrics key', () => {
4448
const workspace = {
45-
workspace: {
49+
[EXPERIMENT_WORKSPACE_ID]: {
4650
baseline: {
4751
data: {
4852
params: {
@@ -58,7 +62,7 @@ describe('collectFiles', () => {
5862

5963
it('should collect all of the available files from a more complex example', () => {
6064
const workspace = {
61-
workspace: {
65+
[EXPERIMENT_WORKSPACE_ID]: {
6266
baseline: {
6367
data: {
6468
metrics: {
@@ -88,10 +92,10 @@ describe('collectFiles', () => {
8892

8993
it('should not remove a previously collected file if it is deleted (removal breaks live updates logged by dvclive)', () => {
9094
const workspace = {
91-
workspace: {
95+
[EXPERIMENT_WORKSPACE_ID]: {
9296
baseline: {
9397
data: {
94-
executor: 'workspace',
98+
executor: EXPERIMENT_WORKSPACE_ID,
9599
metrics: {},
96100
params: {
97101
'params.yaml': {

extension/src/experiments/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { DecorationProvider } from './model/decorationProvider'
3030
import { starredFilter } from './model/filterBy/constants'
3131
import { ResourceLocator } from '../resourceLocator'
3232
import { AvailableCommands, InternalCommands } from '../commands/internal'
33-
import { ExperimentsOutput } from '../cli/dvc/contract'
33+
import { ExperimentsOutput, EXPERIMENT_WORKSPACE_ID } from '../cli/dvc/contract'
3434
import { ViewKey } from '../webview/constants'
3535
import { BaseRepository } from '../webview/repository'
3636
import { FileSystemData } from '../fileSystem/data'
@@ -197,9 +197,9 @@ export class Experiments extends BaseRepository<TableData> {
197197
id: string
198198
): Color | typeof UNSELECTED | undefined {
199199
if (this.experiments.isRunningInWorkspace(id)) {
200-
return this.experiments.isSelected('workspace')
200+
return this.experiments.isSelected(EXPERIMENT_WORKSPACE_ID)
201201
? undefined
202-
: this.toggleExperimentStatus('workspace')
202+
: this.toggleExperimentStatus(EXPERIMENT_WORKSPACE_ID)
203203
}
204204

205205
const selected = this.experiments.isSelected(id)

extension/src/experiments/model/accumulator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { EXPERIMENT_WORKSPACE_ID } from '../../cli/dvc/contract'
12
import { Experiment, isRunning, RunningExperiment } from '../webview/contract'
23

34
export class ExperimentsAccumulator {
@@ -13,7 +14,10 @@ export class ExperimentsAccumulator {
1314
}
1415
this.runningExperiments = []
1516
if (isRunning(workspace?.status)) {
16-
this.runningExperiments.push({ executor: 'workspace', id: 'workspace' })
17+
this.runningExperiments.push({
18+
executor: EXPERIMENT_WORKSPACE_ID,
19+
id: EXPERIMENT_WORKSPACE_ID
20+
})
1721
}
1822
}
1923
}

0 commit comments

Comments
 (0)