Skip to content

Commit a09c1e2

Browse files
authored
Do not go into pipeline stage creation mode if dvc.yaml is invalid (#3368)
* Do not go into pipeline stage creation mode if dvc.yaml is invalid * Add tests * Apply review comment
1 parent ba4482b commit a09c1e2

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

extension/src/experiments/workspace.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { OutputChannel } from '../vscode/outputChannel'
1414
import { Title } from '../vscode/title'
1515
import { Args } from '../cli/dvc/constants'
1616
import { findOrCreateDvcYamlFile, getFileExtension } from '../fileSystem'
17+
import { Toast } from '../vscode/toast'
1718

1819
const mockedShowWebview = jest.fn()
1920
const mockedDisposable = jest.mocked(Disposable)
@@ -595,5 +596,38 @@ describe('Experiments', () => {
595596
mockedDvcRoot
596597
)
597598
})
599+
600+
it('should show a toast if the dvc.yaml file is invalid', async () => {
601+
const showErrorSpy = jest.spyOn(Toast, 'showError')
602+
603+
mockedQuickPickOne.mockResolvedValueOnce(mockedDvcRoot)
604+
mockedListStages.mockResolvedValueOnce(undefined)
605+
606+
await workspaceExperiments.getCwdThenRun(mockedCommandId)
607+
608+
expect(showErrorSpy).toHaveBeenCalledWith(
609+
'Cannot perform task. Your dvc.yaml file is invalid.'
610+
)
611+
})
612+
613+
it('should not ask to create a stage if the dvc.yaml file is invalid', async () => {
614+
mockedQuickPickOne.mockResolvedValueOnce(mockedDvcRoot)
615+
mockedListStages.mockResolvedValueOnce(undefined)
616+
617+
await workspaceExperiments.getCwdThenRun(mockedCommandId)
618+
619+
expect(mockedGetValidInput).not.toHaveBeenCalled()
620+
})
621+
622+
it('should not show a toast if the dvc.yaml file is valid', async () => {
623+
const showErrorSpy = jest.spyOn(Toast, 'showError')
624+
625+
mockedQuickPickOne.mockResolvedValueOnce(mockedDvcRoot)
626+
mockedListStages.mockResolvedValueOnce('train')
627+
628+
await workspaceExperiments.getCwdThenRun(mockedCommandId)
629+
630+
expect(showErrorSpy).not.toHaveBeenCalled()
631+
})
598632
})
599633
})

extension/src/experiments/workspace.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -444,18 +444,30 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
444444
cwd
445445
)
446446

447+
if (stages === undefined) {
448+
await Toast.showError(
449+
'Cannot perform task. Your dvc.yaml file is invalid.'
450+
)
451+
return false
452+
}
453+
447454
if (!stages) {
448-
const stageName = await this.askForStageName()
449-
if (!stageName) {
450-
return false
451-
}
455+
return this.addPipeline(cwd)
456+
}
457+
return true
458+
}
452459

453-
const { trainingScript, command } = await this.askForTrainingScript()
454-
if (!trainingScript) {
455-
return false
456-
}
457-
void findOrCreateDvcYamlFile(cwd, trainingScript, stageName, command)
460+
private async addPipeline(cwd: string) {
461+
const stageName = await this.askForStageName()
462+
if (!stageName) {
463+
return false
464+
}
465+
466+
const { trainingScript, command } = await this.askForTrainingScript()
467+
if (!trainingScript) {
468+
return false
458469
}
470+
void findOrCreateDvcYamlFile(cwd, trainingScript, stageName, command)
459471
return true
460472
}
461473

0 commit comments

Comments
 (0)