Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions extension/src/experiments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ import { createTypedAccumulator } from '../util/object'
import { pickPaths } from '../path/selection/quickPick'
import { Toast } from '../vscode/toast'
import { ConfigKey, getConfigValue, setUserConfigValue } from '../vscode/config'
import { checkSignalFile, pollSignalFileForProcess } from '../fileSystem'
import {
checkSignalFile,
getEntryFromJsonFile,
pollSignalFileForProcess
} from '../fileSystem'
import { DVCLIVE_ONLY_RUNNING_SIGNAL_FILE } from '../cli/dvc/constants'
import { Response } from '../vscode/response'
import { Pipeline } from '../pipeline'
Expand Down Expand Up @@ -599,6 +603,19 @@ export class Experiments extends BaseRepository<TableData> {
return this.webviewMessages.sendWebviewMessage()
}

public hasDvcLiveOnlyRunning() {
return this.experiments.hasDvcLiveOnlyRunning()
}

public checkWorkspaceDuplicated(fetched: string[]) {
const updated = this.experiments.checkWorkspaceDuplicated(fetched)
if (!updated) {
return
}

this.notifyChanged()
}

protected sendInitialWebviewData() {
return this.webviewMessages.sendWebviewMessage()
}
Expand Down Expand Up @@ -683,9 +700,13 @@ export class Experiments extends BaseRepository<TableData> {
}

private async checkSignalFile() {
const dvcLiveOnly = await checkSignalFile(this.dvcLiveOnlySignalFile)
const running = await checkSignalFile(this.dvcLiveOnlySignalFile)

if (dvcLiveOnly && !this.dvcLiveOnlyCleanupInitialized) {
if (!running) {
return { running }
}

if (!this.dvcLiveOnlyCleanupInitialized) {
this.dvcLiveOnlyCleanupInitialized = true
void pollSignalFileForProcess(this.dvcLiveOnlySignalFile, () => {
this.dvcLiveOnlyCleanupInitialized = false
Expand All @@ -694,7 +715,9 @@ export class Experiments extends BaseRepository<TableData> {
}
})
}
return dvcLiveOnly
const expName = getEntryFromJsonFile(this.dvcLiveOnlySignalFile, 'exp_name')

return { expName, running }
}

private async informMaxSelected() {
Expand Down
24 changes: 13 additions & 11 deletions extension/src/experiments/model/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ beforeEach(() => {

const DEFAULT_DATA: [
string,
boolean,
{ running: boolean; expName?: string },
{ branch: string; sha: string }[],
{ [branch: string]: number }
] = ['', false, [], { main: 2000 }]
] = ['', { running: false }, [], { main: 2000 }]

type TransformAndSetInputs = [ExpShowOutput, ...typeof DEFAULT_DATA]

Expand All @@ -52,7 +52,7 @@ describe('ExperimentsModel', () => {
model.transformAndSetLocal(
outputFixture,
gitLogFixture,
false,
{ running: false },
rowOrderFixture,
{ main: 6 }
)
Expand All @@ -65,7 +65,7 @@ describe('ExperimentsModel', () => {
model.transformAndSetLocal(
survivalOutputFixture,
'',
false,
{ running: false },
[
{ branch: 'main', sha: '3d5adcb974bb2c85917a5d61a489b933adaa2b7f' },
{ branch: 'main', sha: 'a49e03966a1f9f1299ec222ebc4bed8625d2c54d' },
Expand Down Expand Up @@ -107,7 +107,9 @@ describe('ExperimentsModel', () => {
}
)

model.transformAndSetLocal(dvcLiveOnly, '', true, [], { main: 2000 })
model.transformAndSetLocal(dvcLiveOnly, '', { running: true }, [], {
main: 2000
})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const runningWorkspace = (model as any).workspace
expect(runningWorkspace?.executor).toStrictEqual(EXPERIMENT_WORKSPACE_ID)
Expand Down Expand Up @@ -203,7 +205,7 @@ describe('ExperimentsModel', () => {
model.transformAndSetLocal(
deeplyNestedOutputFixture,
'',
false,
{ running: false },
[{ branch: 'main', sha: '53c3851f46955fa3e2b8f6e1c52999acc8c9ea77' }],
{ main: 10 }
)
Expand All @@ -217,7 +219,7 @@ describe('ExperimentsModel', () => {
model.transformAndSetLocal(
dataTypesOutputFixture,
'',
false,
{ running: false },
[{ branch: 'main', sha: '53c3851f46955fa3e2b8f6e1c52999acc8c9ea77' }],
{ main: 10 }
)
Expand Down Expand Up @@ -483,7 +485,7 @@ describe('ExperimentsModel', () => {
const runningExperimentData: TransformAndSetInputs = [
outputFixture,
gitLogFixture,
false,
{ running: false },
[],
{
main: 2000
Expand All @@ -504,7 +506,7 @@ describe('ExperimentsModel', () => {
} as ExpWithError
],
gitLogFixture,
false,
{ running: false },
[],
{
main: 2000
Expand Down Expand Up @@ -586,7 +588,7 @@ describe('ExperimentsModel', () => {
error: { msg: errorMsg, type: 'caught error' }
}
]
model.transformAndSetLocal(data, gitLogFixture, false, [], {
model.transformAndSetLocal(data, gitLogFixture, { running: false }, [], {
main: 6
})

Expand All @@ -595,7 +597,7 @@ describe('ExperimentsModel', () => {
model.transformAndSetLocal(
outputFixture,
gitLogFixture,
false,
{ running: false },
rowOrderFixture,
{ main: 6 }
)
Expand Down
42 changes: 38 additions & 4 deletions extension/src/experiments/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ import {
WORKSPACE_BRANCH
} from '../webview/contract'
import { reorderListSubset } from '../../util/array'
import { Executor, ExpShowOutput, ExecutorStatus } from '../../cli/dvc/contract'
import {
Executor,
ExpShowOutput,
ExecutorStatus,
EXPERIMENT_WORKSPACE_ID
} from '../../cli/dvc/contract'
import { flattenMapValues } from '../../util/map'
import { ModelWithPersistence } from '../../persistence/model'
import { PersistenceKey } from '../../persistence/constants'
Expand Down Expand Up @@ -81,6 +86,8 @@ export class ExperimentsModel extends ModelWithPersistence {
private running: RunningExperiment[] = []
private startedRunning: Set<string> = new Set()

private dvcLiveOnlyExpName: string | undefined

constructor(dvcRoot: string, workspaceState: Memento) {
super(dvcRoot, workspaceState)

Expand Down Expand Up @@ -126,7 +133,7 @@ export class ExperimentsModel extends ModelWithPersistence {
public transformAndSetLocal(
expShow: ExpShowOutput,
gitLog: string,
dvcLiveOnly: boolean,
dvcLiveOnly: { running: boolean; expName?: string },
rowOrder: { branch: string; sha: string }[],
availableNbCommits: { [branch: string]: number }
) {
Expand All @@ -137,7 +144,11 @@ export class ExperimentsModel extends ModelWithPersistence {
hasCheckpoints,
runningExperiments,
workspace
} = collectExperiments(expShow, gitLog, dvcLiveOnly)
} = collectExperiments(expShow, gitLog, dvcLiveOnly.running)

if (dvcLiveOnly.expName) {
this.dvcLiveOnlyExpName = dvcLiveOnly.expName
}

const { hasMoreCommits, isShowingMoreCommits } =
collectAddRemoveCommitsDetails(availableNbCommits, (branch: string) =>
Expand Down Expand Up @@ -528,6 +539,28 @@ export class ExperimentsModel extends ModelWithPersistence {
return this.availableBranchesToSelect
}

public hasDvcLiveOnlyRunning() {
return !!this.dvcLiveOnlyExpName
}

public checkWorkspaceDuplicated(fetched: string[]) {
if (!this.dvcLiveOnlyExpName) {
return false
}

const newExperimentFetched = fetched.includes(this.dvcLiveOnlyExpName)
const workspaceSelectionDuplicated =
this.coloredStatus[EXPERIMENT_WORKSPACE_ID] ===
this.coloredStatus[this.dvcLiveOnlyExpName]

if (newExperimentFetched && workspaceSelectionDuplicated) {
this.coloredStatus[EXPERIMENT_WORKSPACE_ID] = UNSELECTED
this.dvcLiveOnlyExpName = undefined
this.persistStatus()
return true
}
}

private findIndexByPath(pathToRemove: string) {
return this.currentSorts.findIndex(({ path }) => path === pathToRemove)
}
Expand Down Expand Up @@ -590,7 +623,8 @@ export class ExperimentsModel extends ModelWithPersistence {
this.experimentsByCommit,
this.coloredStatus,
this.availableColors,
this.startedRunning
this.startedRunning,
this.dvcLiveOnlyExpName
)
this.startedRunning = new Set()

Expand Down
65 changes: 57 additions & 8 deletions extension/src/experiments/model/status/collect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe('collectColoredStatus', () => {
new Map(),
{},
copyOriginalColors(),
new Set()
new Set(),
undefined
)

expect(availableColors).toStrictEqual(colors)
Expand All @@ -48,7 +49,8 @@ describe('collectColoredStatus', () => {
new Map(),
{},
copyOriginalColors(),
new Set()
new Set(),
undefined
)

expect(availableColors).toStrictEqual(colors)
Expand All @@ -74,7 +76,8 @@ describe('collectColoredStatus', () => {
exp7: colors[6]
},
[],
new Set(['exp8'])
new Set(['exp8']),
undefined
)

expect(availableColors).toStrictEqual([])
Expand Down Expand Up @@ -107,7 +110,8 @@ describe('collectColoredStatus', () => {
exp8: UNSELECTED
},
copyOriginalColors().slice(3),
new Set(['exp1'])
new Set(['exp1']),
undefined
)

expect(coloredStatus).toStrictEqual({ exp1: colors[0] })
Expand All @@ -129,7 +133,8 @@ describe('collectColoredStatus', () => {
exp9: colors[1]
},
unassignedColors,
new Set()
new Set(),
undefined
)

expect(coloredStatus).toStrictEqual({
Expand Down Expand Up @@ -157,7 +162,8 @@ describe('collectColoredStatus', () => {
new Map(),
{ exp9: colors[0] },
unassignColors,
new Set()
new Set(),
undefined
)

expect(availableColors).toStrictEqual(unassignColors)
Expand Down Expand Up @@ -190,7 +196,8 @@ describe('collectColoredStatus', () => {
exp9: colors[5]
},
copyOriginalColors().slice(6),
new Set(['exp1', 'exp2', 'exp3'])
new Set(['exp1', 'exp2', 'exp3']),
undefined
)

expect(availableColors).toStrictEqual([])
Expand Down Expand Up @@ -228,7 +235,8 @@ describe('collectColoredStatus', () => {
workspace: UNSELECTED
},
colors,
new Set()
new Set(),
undefined
)
expect(coloredStatus).toStrictEqual({
'exp-1': selectedColor,
Expand All @@ -240,4 +248,45 @@ describe('collectColoredStatus', () => {
colors.filter(color => color !== selectedColor)
)
})

it("should duplicate the workspace's color when a new experiment is provided that has the same name as found in the DVCLive only signal file", () => {
const colors = copyOriginalColors()
const selectedColor = colors[2]
const { availableColors, coloredStatus } = collectColoredStatus(
[
{
executor: null,
executorStatus: ExecutorStatus.SUCCESS,
id: 'exp-1'
},
{
id: EXPERIMENT_WORKSPACE_ID
},
{ id: 'main' },
{
executor: null,
executorStatus: ExecutorStatus.SUCCESS,
id: 'exp-2'
}
] as Experiment[],
new Map(),
{
'exp-1': UNSELECTED,
workspace: selectedColor
},
colors,
new Set(),
'exp-2'
)
expect(coloredStatus).toStrictEqual({
[EXPERIMENT_WORKSPACE_ID]: selectedColor,
'exp-1': UNSELECTED,
'exp-2': selectedColor,
main: UNSELECTED
})

expect(availableColors).toStrictEqual(
colors.filter(color => color !== selectedColor)
)
})
})
Loading