Skip to content

Commit

Permalink
Rename exp commands to closer match CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Apr 28, 2023
1 parent 3b1c372 commit 4ca4b37
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 101 deletions.
28 changes: 14 additions & 14 deletions extension/src/cli/dvc/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ describe('CliExecutor', () => {
})
})

describe('experimentApply', () => {
describe('expApply', () => {
it('should call createProcess with the correct parameters to apply an existing experiment to the workspace', async () => {
const cwd = ''
const stdout = 'Test output that will be passed along'
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))

const output = await dvcExecutor.experimentApply(cwd, 'exp-test')
const output = await dvcExecutor.expApply(cwd, 'exp-test')
expect(output).toStrictEqual(stdout)

expect(mockedCreateProcess).toHaveBeenCalledWith({
Expand All @@ -256,7 +256,7 @@ describe('CliExecutor', () => {
})
})

describe('experimentBranch', () => {
describe('expBranch', () => {
it('should call createProcess with the correct parameters to create a new branch from an existing experiment', async () => {
const cwd = __dirname
const stdout =
Expand All @@ -265,7 +265,7 @@ describe('CliExecutor', () => {
'\t\tgit checkout some-branch'
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))

const output = await dvcExecutor.experimentBranch(
const output = await dvcExecutor.expBranch(
cwd,
'exp-0898f',
'some-branch'
Expand All @@ -281,7 +281,7 @@ describe('CliExecutor', () => {
})
})

describe('experimentGarbageCollect', () => {
describe('expGarbageCollect', () => {
it('should call createProcess with the correct parameters to garbage collect experiments', async () => {
const cwd = __dirname
const stdout =
Expand All @@ -290,7 +290,7 @@ describe('CliExecutor', () => {
"Removed 45 experiments. To remove unused cache files use 'dvc gc'. "
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))

const output = await dvcExecutor.experimentGarbageCollect(
const output = await dvcExecutor.expGarbageCollect(
cwd,
GcPreserveFlag.WORKSPACE,
GcPreserveFlag.QUEUED
Expand All @@ -306,13 +306,13 @@ describe('CliExecutor', () => {
})
})

describe('experimentPush', () => {
describe('expPush', () => {
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')
const output = await dvcExecutor.expPush(cwd, 'toric-sail')
expect(output).toStrictEqual(stdout)

expect(mockedCreateProcess).toHaveBeenCalledWith({
Expand All @@ -324,13 +324,13 @@ describe('CliExecutor', () => {
})
})

describe('experimentRemove', () => {
describe('expRemove', () => {
it('should call createProcess with the correct parameters to remove an existing experiment from the workspace', async () => {
const cwd = __dirname
const stdout = ''
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))

const output = await dvcExecutor.experimentRemove(cwd, 'exp-dfd12')
const output = await dvcExecutor.expRemove(cwd, 'exp-dfd12')
expect(output).toStrictEqual(stdout)

expect(mockedCreateProcess).toHaveBeenCalledWith({
Expand All @@ -342,13 +342,13 @@ describe('CliExecutor', () => {
})
})

describe('experimentRemoveQueue', () => {
describe('expRemoveQueue', () => {
it('should call createProcess with the correct parameters to remove all existing queued experiments from the workspace', async () => {
const cwd = __dirname
const stdout = ''
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))

const output = await dvcExecutor.experimentRemoveQueue(cwd)
const output = await dvcExecutor.expRemoveQueue(cwd)
expect(output).toStrictEqual(stdout)

expect(mockedCreateProcess).toHaveBeenCalledWith({
Expand All @@ -360,13 +360,13 @@ describe('CliExecutor', () => {
})
})

describe('experimentRunQueue', () => {
describe('expRunQueue', () => {
it('should call createProcess with the correct parameters to queue an experiment for later execution', async () => {
const cwd = __dirname
const stdout = "Queued experiment 'bbf5c01' for future execution."
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))

const output = await dvcExecutor.experimentRunQueue(cwd)
const output = await dvcExecutor.expRunQueue(cwd)
expect(output).toStrictEqual(stdout)

expect(mockedCreateProcess).toHaveBeenCalledWith({
Expand Down
37 changes: 15 additions & 22 deletions extension/src/cli/dvc/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export const autoRegisteredCommands = {
CHECKOUT: 'checkout',
COMMIT: 'commit',
CONFIG: 'config',
EXPERIMENT_APPLY: 'experimentApply',
EXPERIMENT_BRANCH: 'experimentBranch',
EXPERIMENT_GARBAGE_COLLECT: 'experimentGarbageCollect',
EXPERIMENT_PUSH: 'experimentPush',
EXPERIMENT_QUEUE: 'experimentRunQueue',
EXPERIMENT_REMOVE: 'experimentRemove',
EXPERIMENT_REMOVE_QUEUE: 'experimentRemoveQueue',
EXP_APPLY: 'expApply',
EXP_BRANCH: 'expBranch',
EXP_GARBAGE_COLLECT: 'expGarbageCollect',
EXP_PUSH: 'expPush',
EXP_QUEUE: 'expRunQueue',
EXP_REMOVE: 'expRemove',
EXP_REMOVE_QUEUE: 'expRemoveQueue',
INIT: 'init',
IS_SCM_COMMAND_RUNNING: 'isScmCommandRunning',
MOVE: 'move',
Expand Down Expand Up @@ -78,19 +78,15 @@ export class DvcExecutor extends DvcCli {
return this.executeDvcProcess(cwd, Command.CONFIG, ...args)
}

public experimentApply(cwd: string, experimentName: string) {
public expApply(cwd: string, experimentName: string) {
return this.executeExperimentProcess(
cwd,
ExperimentSubCommand.APPLY,
experimentName
)
}

public experimentBranch(
cwd: string,
experimentName: string,
branchName: string
) {
public expBranch(cwd: string, experimentName: string, branchName: string) {
return this.executeExperimentProcess(
cwd,
ExperimentSubCommand.BRANCH,
Expand All @@ -99,10 +95,7 @@ export class DvcExecutor extends DvcCli {
)
}

public experimentGarbageCollect(
cwd: string,
...preserveFlags: GcPreserveFlag[]
) {
public expGarbageCollect(cwd: string, ...preserveFlags: GcPreserveFlag[]) {
return this.executeExperimentProcess(
cwd,
ExperimentSubCommand.GARBAGE_COLLECT,
Expand All @@ -111,7 +104,7 @@ export class DvcExecutor extends DvcCli {
)
}

public experimentPush(cwd: string, id: string) {
public expPush(cwd: string, id: string) {
return this.executeExperimentProcess(
cwd,
ExperimentSubCommand.PUSH,
Expand All @@ -120,19 +113,19 @@ export class DvcExecutor extends DvcCli {
)
}

public experimentRemove(cwd: string, ...experimentNames: string[]) {
public expRemove(cwd: string, ...experimentNames: string[]) {
return this.executeExperimentProcess(
cwd,
ExperimentSubCommand.REMOVE,
...experimentNames
)
}

public experimentRemoveQueue(cwd: string) {
return this.experimentRemove(cwd, ExperimentFlag.QUEUE)
public expRemoveQueue(cwd: string) {
return this.expRemove(cwd, ExperimentFlag.QUEUE)
}

public experimentRunQueue(cwd: string, ...args: Args) {
public expRunQueue(cwd: string, ...args: Args) {
return this.executeExperimentProcess(
cwd,
ExperimentSubCommand.RUN,
Expand Down
9 changes: 2 additions & 7 deletions extension/src/experiments/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import { RegisteredCommands } from '../../commands/external'
export const getBranchExperimentCommand =
(experiments: WorkspaceExperiments) =>
(cwd: string, name: string, input: string) =>
experiments.runCommand(
AvailableCommands.EXPERIMENT_BRANCH,
cwd,
name,
input
)
experiments.runCommand(AvailableCommands.EXP_BRANCH, cwd, name, input)

export const getShareExperimentToStudioCommand =
(internalCommands: InternalCommands, setup: Setup) =>
Expand All @@ -31,7 +26,7 @@ export const getShareExperimentToStudioCommand =
await Toast.runCommandAndIncrementProgress(
() =>
internalCommands.executeCommand(
AvailableCommands.EXPERIMENT_PUSH,
AvailableCommands.EXP_PUSH,
dvcRoot,
id
),
Expand Down
18 changes: 6 additions & 12 deletions extension/src/experiments/commands/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const registerExperimentCwdCommands = (
RegisteredCliCommands.QUEUE_EXPERIMENT,
() =>
experiments.pauseUpdatesThenRun(() =>
experiments.getCwdThenReport(AvailableCommands.EXPERIMENT_QUEUE)
experiments.getCwdThenReport(AvailableCommands.EXP_QUEUE)
)
)

Expand Down Expand Up @@ -110,8 +110,7 @@ const registerExperimentCwdCommands = (

internalCommands.registerExternalCliCommand(
RegisteredCliCommands.EXPERIMENT_REMOVE_QUEUE,
() =>
experiments.getCwdThenReport(AvailableCommands.EXPERIMENT_REMOVE_QUEUE)
() => experiments.getCwdThenReport(AvailableCommands.EXP_REMOVE_QUEUE)
)
}

Expand All @@ -121,24 +120,19 @@ const registerExperimentNameCommands = (
): void => {
internalCommands.registerExternalCliCommand(
RegisteredCliCommands.EXPERIMENT_APPLY,
() =>
experiments.getCwdAndExpNameThenRun(AvailableCommands.EXPERIMENT_APPLY)
() => experiments.getCwdAndExpNameThenRun(AvailableCommands.EXP_APPLY)
)

internalCommands.registerExternalCliCommand(
RegisteredCliCommands.EXPERIMENT_VIEW_APPLY,
({ dvcRoot, id }: ExperimentDetails) =>
experiments.runCommand(AvailableCommands.EXPERIMENT_APPLY, dvcRoot, id)
experiments.runCommand(AvailableCommands.EXP_APPLY, dvcRoot, id)
)

internalCommands.registerExternalCliCommand(
RegisteredCliCommands.EXPERIMENT_VIEW_REMOVE,
({ dvcRoot, ids }: { dvcRoot: string; ids: string[] }) =>
experiments.runCommand(
AvailableCommands.EXPERIMENT_REMOVE,
dvcRoot,
...ids
)
experiments.runCommand(AvailableCommands.EXP_REMOVE, dvcRoot, ...ids)
)
}

Expand Down Expand Up @@ -175,7 +169,7 @@ const registerExperimentQuickPickCommands = (
RegisteredCliCommands.EXPERIMENT_GARBAGE_COLLECT,
() =>
experiments.getCwdAndQuickPickThenRun(
AvailableCommands.EXPERIMENT_GARBAGE_COLLECT,
AvailableCommands.EXP_GARBAGE_COLLECT,
pickGarbageCollectionFlags
)
)
Expand Down
2 changes: 1 addition & 1 deletion extension/src/experiments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export class Experiments extends BaseRepository<TableData> {

await Toast.showOutput(
this.internalCommands.executeCommand<string>(
AvailableCommands.EXPERIMENT_QUEUE,
AvailableCommands.EXP_QUEUE,
this.dvcRoot,
...paramsToModify
)
Expand Down
6 changes: 1 addition & 5 deletions extension/src/experiments/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,7 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
return
}

return this.runCommand(
AvailableCommands.EXPERIMENT_REMOVE,
cwd,
...experimentIds
)
return this.runCommand(AvailableCommands.EXP_REMOVE, cwd, ...experimentIds)
}

public async modifyExperimentParamsAndRun(
Expand Down
19 changes: 9 additions & 10 deletions extension/src/test/suite/experiments/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ suite('Experiments Test Suite', () => {

const mockExperimentApply = stub(
DvcExecutor.prototype,
'experimentApply'
'expApply'
).resolves(undefined)

stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)
Expand All @@ -577,7 +577,7 @@ suite('Experiments Test Suite', () => {

const mockExperimentBranch = stub(
DvcExecutor.prototype,
'experimentBranch'
'expBranch'
).resolves('undefined')

stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)
Expand Down Expand Up @@ -675,9 +675,9 @@ suite('Experiments Test Suite', () => {
return 'isat_token'
})
)
const mockExperimentPush = stub(DvcExecutor.prototype, 'experimentPush')
const mockexpPush = stub(DvcExecutor.prototype, 'expPush')
const commandExecuted = new Promise(resolve =>
mockExperimentPush.callsFake(() => {
mockexpPush.callsFake(() => {
resolve(undefined)
return Promise.resolve(
`Pushed experiment ${mockExpId} to Git remote 'origin'`
Expand All @@ -692,7 +692,7 @@ suite('Experiments Test Suite', () => {

await Promise.all([tokenFound, commandExecuted])

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

it("should be able to handle a message to modify an experiment's params and queue an experiment", async () => {
Expand All @@ -709,10 +709,9 @@ suite('Experiments Test Suite', () => {
stubWorkspaceExperimentsGetters(dvcDemoPath, experiments)

stub(experiments, 'pickAndModifyParams').resolves(mockModifiedParams)
const mockQueueExperiment = stub(
dvcExecutor,
'experimentRunQueue'
).resolves(undefined)
const mockQueueExperiment = stub(dvcExecutor, 'expRunQueue').resolves(
undefined
)

const webview = await experiments.showWebview()
const mockMessageReceived = getMessageReceivedEmitter(webview)
Expand Down Expand Up @@ -817,7 +816,7 @@ suite('Experiments Test Suite', () => {

const mockExperimentRemove = stub(
DvcExecutor.prototype,
'experimentRemove'
'expRemove'
).resolves(undefined)

mockMessageReceived.fire({
Expand Down
Loading

0 comments on commit 4ca4b37

Please sign in to comment.