Skip to content

Commit

Permalink
use exp push to share experiments to Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Apr 19, 2023
1 parent 932951b commit 386e939
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 439 deletions.
1 change: 1 addition & 0 deletions extension/src/cli/dvc/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export enum ExperimentSubCommand {
APPLY = 'apply',
BRANCH = 'branch',
GARBAGE_COLLECT = 'gc',
PUSH = 'push',
REMOVE = 'remove',
RUN = 'run'
}
Expand Down
18 changes: 18 additions & 0 deletions extension/src/cli/dvc/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,24 @@ describe('CliExecutor', () => {
})
})

describe('experimentPush', () => {
it('should call createProcess with the correct parameters to push an existing experiment to the remote', async () => {
const cwd = __dirname
const stdout = ''
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))

const output = await dvcExecutor.experimentPush(cwd, 'toric-sail')
expect(output).toStrictEqual(stdout)

expect(mockedCreateProcess).toHaveBeenCalledWith({
args: ['exp', 'push', 'origin', 'toric-sail'],
cwd,
env: mockedEnv,
executable: 'dvc'
})
})
})

describe('experimentRemove', () => {
it('should call createProcess with the correct parameters to remove an existing experiment from the workspace', async () => {
const cwd = __dirname
Expand Down
11 changes: 11 additions & 0 deletions extension/src/cli/dvc/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { addStudioAccessToken } from './options'
import { CliResult, CliStarted, typeCheckCommands } from '..'
import { ContextKey, setContextValue } from '../../vscode/context'
import { Config } from '../../config'
import { DEFAULT_REMOTE } from '../git/constants'

export const autoRegisteredCommands = {
ADD: 'add',
Expand All @@ -21,6 +22,7 @@ export const autoRegisteredCommands = {
EXPERIMENT_APPLY: 'experimentApply',
EXPERIMENT_BRANCH: 'experimentBranch',
EXPERIMENT_GARBAGE_COLLECT: 'experimentGarbageCollect',
EXPERIMENT_PUSH: 'experimentPush',
EXPERIMENT_QUEUE: 'experimentRunQueue',
EXPERIMENT_REMOVE: 'experimentRemove',
EXPERIMENT_REMOVE_QUEUE: 'experimentRemoveQueue',
Expand Down Expand Up @@ -104,6 +106,15 @@ export class DvcExecutor extends DvcCli {
)
}

public experimentPush(cwd: string, id: string) {
return this.executeExperimentProcess(
cwd,
ExperimentSubCommand.PUSH,
DEFAULT_REMOTE,
id
)
}

public experimentRemove(cwd: string, ...experimentNames: string[]) {
return this.executeExperimentProcess(
cwd,
Expand Down
1 change: 1 addition & 0 deletions extension/src/commands/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum RegisteredCliCommands {

EXPERIMENT_VIEW_APPLY = 'dvc.views.experiments.applyExperiment',
EXPERIMENT_VIEW_BRANCH = 'dvc.views.experiments.branchExperiment',
EXPERIMENT_VIEW_PUSH = 'dvc.views.experiments.pushExperiment',
EXPERIMENT_VIEW_REMOVE = 'dvc.views.experiments.removeExperiment',
EXPERIMENT_VIEW_SHARE_AS_BRANCH = 'dvc.views.experiments.shareExperimentAsBranch',
EXPERIMENT_VIEW_SHARE_AS_COMMIT = 'dvc.views.experiments.shareExperimentAsCommit',
Expand Down
24 changes: 18 additions & 6 deletions extension/src/experiments/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,22 @@ export const getShareExperimentToStudioCommand =
return commands.executeCommand(RegisteredCommands.SETUP_SHOW)
}

return internalCommands.executeCommand(
AvailableCommands.EXP_PUSH,
studioAccessToken,
dvcRoot,
id
)
return Toast.showProgress('Pushing Experiment', async progress => {
progress.report({ increment: 0 })

progress.report({ increment: 25, message: 'Pushing experiment...' })

await Toast.runCommandAndIncrementProgress(
() =>
internalCommands.executeCommand(
AvailableCommands.EXPERIMENT_PUSH,
dvcRoot,
id
),
progress,
75
)

return Toast.delayProgressClosing()
})
}
2 changes: 0 additions & 2 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import { stopProcesses } from './process/execution'
import { Flag } from './cli/dvc/constants'
import { LanguageClient } from './languageClient'
import { collectRunningExperimentPids } from './experiments/processExecution/collect'
import { registerPatchCommand } from './patch'
import { DvcViewer } from './cli/dvc/viewer'
import { registerSetupCommands } from './setup/register'
import { Status } from './status'
Expand Down Expand Up @@ -201,7 +200,6 @@ export class Extension extends Disposable {
)
)

registerPatchCommand(this.internalCommands)
registerExperimentCommands(
this.experiments,
this.internalCommands,
Expand Down
209 changes: 0 additions & 209 deletions extension/src/patch.ts

This file was deleted.

1 change: 1 addition & 0 deletions extension/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export interface IEventNamePropertyMapping {
[EventName.EXPERIMENT_TOGGLE]: undefined
[EventName.EXPERIMENT_VIEW_APPLY]: undefined
[EventName.EXPERIMENT_VIEW_BRANCH]: undefined
[EventName.EXPERIMENT_VIEW_PUSH]: undefined
[EventName.EXPERIMENT_VIEW_REMOVE]: undefined
[EventName.EXPERIMENT_VIEW_SHARE_AS_BRANCH]: undefined
[EventName.EXPERIMENT_VIEW_SHARE_AS_COMMIT]: undefined
Expand Down
31 changes: 29 additions & 2 deletions extension/src/test/suite/experiments/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ suite('Experiments Test Suite', () => {
'getStudioAccessToken'
)

const tokenAccessed = new Promise(resolve =>
const tokenNotFound = new Promise(resolve =>
mockGetStudioAccessToken.callsFake(() => {
resolve(undefined)
return undefined
Expand All @@ -662,11 +662,38 @@ suite('Experiments Test Suite', () => {
type: MessageFromWebviewType.SHARE_EXPERIMENT_TO_STUDIO
})

await tokenAccessed
await tokenNotFound

expect(executeCommandSpy).to.be.calledWithExactly(
RegisteredCommands.SETUP_SHOW
)

mockGetStudioAccessToken.resetBehavior()

const tokenFound = new Promise(resolve =>
mockGetStudioAccessToken.callsFake(() => {
resolve(undefined)
return 'isat_token'
})
)
const mockExperimentPush = stub(DvcExecutor.prototype, 'experimentPush')
const commandExecuted = new Promise(resolve =>
mockExperimentPush.callsFake(() => {
resolve(undefined)
return Promise.resolve(
`Pushed experiment ${mockExpId} to Git remote 'origin'`
)
})
)

mockMessageReceived.fire({
payload: mockExpId,
type: MessageFromWebviewType.SHARE_EXPERIMENT_TO_STUDIO
})

await Promise.all([tokenFound, commandExecuted])

expect(mockExperimentPush).to.be.calledWithExactly(dvcDemoPath, mockExpId)
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should handle a message to share an experiment as a new branch', async () => {
Expand Down
Loading

0 comments on commit 386e939

Please sign in to comment.