Skip to content

Commit e2ee91c

Browse files
authored
Fix dvc details version incorrectly showing "Not Found" (#3787)
* Try to fix DVC Details version showng "Not Found" * Add test * Fix typo * Add cliVerson var to setup * Delete no longer needed test lines
1 parent 2b9f6a7 commit e2ee91c

File tree

6 files changed

+26
-22
lines changed

6 files changed

+26
-22
lines changed

extension/src/cli/dvc/discovery.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ const warnUser = (
105105
type CanRunCli = {
106106
isAvailable: boolean
107107
isCompatible: boolean | undefined
108+
version: string | undefined
108109
}
109110

110111
export const isCliCompatible = (
@@ -146,7 +147,8 @@ const processVersionDetails = (
146147
warnUser(setup, cliCompatible, version)
147148
return {
148149
isAvailable,
149-
isCompatible
150+
isCompatible,
151+
version
150152
}
151153
}
152154

@@ -171,7 +173,7 @@ const tryGlobalFallbackVersion = async (
171173
setup.unsetPythonBinPath()
172174
}
173175

174-
return { isAvailable, isCompatible }
176+
return { isAvailable, isCompatible, version }
175177
}
176178

177179
const extensionCanAutoRunCli = async (

extension/src/interfaces.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export interface IExtensionSetup {
1717

1818
setAvailable: (available: boolean) => void
1919
getAvailable: () => boolean
20-
setCliCompatible: (compatible: boolean | undefined) => void
20+
setCliCompatibleAndVersion: (
21+
compatible: boolean | undefined,
22+
version: string | undefined
23+
) => void
2124
setRoots: () => Promise<void>
2225
unsetPythonBinPath: () => void
2326
}

extension/src/setup/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class Setup
8686

8787
private cliAccessible = false
8888
private cliCompatible: boolean | undefined
89+
private cliVersion: string | undefined
8990

9091
private dotFolderWatcher?: Disposer
9192

@@ -225,8 +226,12 @@ export class Setup
225226
return available
226227
}
227228

228-
public setCliCompatible(compatible: boolean | undefined) {
229+
public setCliCompatibleAndVersion(
230+
compatible: boolean | undefined,
231+
version: string | undefined
232+
) {
229233
this.cliCompatible = compatible
234+
this.cliVersion = version
230235
void this.updateIsStudioConnected()
231236
const incompatible = compatible === undefined ? undefined : !compatible
232237
void setContextValue(ContextKey.CLI_INCOMPATIBLE, incompatible)
@@ -369,7 +374,7 @@ export class Setup
369374
return this.sendDataToWebview()
370375
}
371376

372-
public async getDvcCliDetails(): Promise<DvcCliDetails> {
377+
public getDvcCliDetails(): DvcCliDetails {
373378
const dvcPath = this.config.getCliPath()
374379
const pythonBinPath = this.config.getPythonBinPath()
375380
const cwd = getFirstWorkspaceFolder()
@@ -380,7 +385,7 @@ export class Setup
380385

381386
return {
382387
command,
383-
version: cwd ? await this.getCliVersion(cwd) : undefined
388+
version: this.cliVersion
384389
}
385390
}
386391

@@ -407,12 +412,10 @@ export class Setup
407412

408413
const pythonBinPath = await findPythonBinForInstall()
409414

410-
const dvcCliDetails = await this.getDvcCliDetails()
411-
412415
this.webviewMessages.sendWebviewMessage({
413416
canGitInitialize,
414417
cliCompatible: this.getCliCompatible(),
415-
dvcCliDetails,
418+
dvcCliDetails: this.getDvcCliDetails(),
416419
hasData,
417420
isPythonExtensionUsed:
418421
!this.isDVCBeingUsedGlobally() && isPythonExtensionUsed,

extension/src/setup/runner.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const mockedInitialize = jest.fn()
7474
const mockedIsPythonExtensionUsed = jest.fn()
7575
const mockedResetMembers = jest.fn()
7676
const mockedSetAvailable = jest.fn()
77-
const mockedSetCliCompatible = jest.fn()
77+
const mockedSetCliCompatibleAndVersion = jest.fn()
7878
const mockedSetRoots = jest.fn()
7979
const mockedShowSetup = jest.fn()
8080
const mockedShouldWarnUserIfCLIUnavailable = jest.fn()
@@ -280,7 +280,7 @@ describe('run', () => {
280280
isPythonExtensionUsed: mockedIsPythonExtensionUsed,
281281
resetMembers: mockedResetMembers,
282282
setAvailable: mockedSetAvailable,
283-
setCliCompatible: mockedSetCliCompatible,
283+
setCliCompatibleAndVersion: mockedSetCliCompatibleAndVersion,
284284
setRoots: mockedSetRoots,
285285
shouldWarnUserIfCLIUnavailable: mockedShouldWarnUserIfCLIUnavailable,
286286
showSetup: mockedShowSetup,
@@ -617,7 +617,7 @@ describe('runWithRecheck', () => {
617617
isPythonExtensionUsed: mockedIsPythonExtensionUsed,
618618
resetMembers: mockedResetMembers,
619619
setAvailable: mockedSetAvailable,
620-
setCliCompatible: mockedSetCliCompatible,
620+
setCliCompatibleAndVersion: mockedSetCliCompatibleAndVersion,
621621
setRoots: mockedSetRoots,
622622
shouldWarnUserIfCLIUnavailable: mockedShouldWarnUserIfCLIUnavailable,
623623
showSetup: mockedShowSetup,

extension/src/setup/runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ export const checkAvailable = async (
179179
setup: IExtensionSetup,
180180
dvcRootOrFirstFolder: string
181181
) => {
182-
const { isAvailable, isCompatible } = await extensionCanRunCli(
182+
const { isAvailable, version, isCompatible } = await extensionCanRunCli(
183183
setup,
184184
dvcRootOrFirstFolder
185185
)
186186

187-
setup.setCliCompatible(isCompatible)
187+
setup.setCliCompatibleAndVersion(isCompatible, version)
188188
setup.setAvailable(isAvailable)
189189

190190
if (setup.hasRoots() && isAvailable) {

extension/src/test/suite/setup/index.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,9 @@ suite('Setup Test Suite', () => {
215215

216216
await config.isReady()
217217

218-
setup.setCliCompatible(undefined)
218+
setup.setCliCompatibleAndVersion(undefined, undefined)
219219
setup.setAvailable(false)
220220
await setup.setRoots()
221-
stub(setup, 'getCliVersion').resolves(undefined)
222221

223222
messageSpy.restore()
224223
const mockSendMessage = stub(BaseWebview.prototype, 'show')
@@ -257,7 +256,7 @@ suite('Setup Test Suite', () => {
257256

258257
await config.isReady()
259258

260-
setup.setCliCompatible(true)
259+
setup.setCliCompatibleAndVersion(true, MIN_CLI_VERSION)
261260
setup.setAvailable(true)
262261
await setup.setRoots()
263262

@@ -304,7 +303,7 @@ suite('Setup Test Suite', () => {
304303

305304
await config.isReady()
306305

307-
setup.setCliCompatible(true)
306+
setup.setCliCompatibleAndVersion(true, MIN_CLI_VERSION)
308307
setup.setAvailable(true)
309308
await setup.setRoots()
310309

@@ -354,7 +353,7 @@ suite('Setup Test Suite', () => {
354353

355354
await config.isReady()
356355

357-
setup.setCliCompatible(true)
356+
setup.setCliCompatibleAndVersion(true, MIN_CLI_VERSION)
358357
setup.setAvailable(true)
359358
await setup.setRoots()
360359

@@ -579,7 +578,6 @@ suite('Setup Test Suite', () => {
579578
mockRunSetup.restore()
580579
stub(config, 'isPythonExtensionUsed').returns(false)
581580
stub(config, 'getPythonBinPath').resolves(join('python'))
582-
stub(setup, 'getDvcCliDetails').resolves(undefined)
583581

584582
mockVersion.resetBehavior()
585583
mockVersion
@@ -639,7 +637,6 @@ suite('Setup Test Suite', () => {
639637
mockExecuteCommand.restore()
640638
mockRunSetup.restore()
641639
stub(config, 'isPythonExtensionUsed').returns(true)
642-
stub(setup, 'getDvcCliDetails').resolves(undefined)
643640

644641
mockVersion.resetBehavior()
645642
mockVersion.rejects(new Error('no CLI here'))
@@ -759,7 +756,6 @@ suite('Setup Test Suite', () => {
759756
const mockUpdate = stub()
760757

761758
stub(workspace, 'getConfiguration').returns({
762-
get: stub(),
763759
update: mockUpdate
764760
} as unknown as WorkspaceConfiguration)
765761

0 commit comments

Comments
 (0)