Skip to content

Commit 5e7223c

Browse files
authored
Merge branch 'master' into master
2 parents 6946578 + e9cc11a commit 5e7223c

File tree

4 files changed

+121
-3
lines changed

4 files changed

+121
-3
lines changed

packages/core/src/shared/telemetry/vscodeTelemetry.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"aws-cli",
1212
"sam-cli",
1313
"docker",
14-
"finch"
14+
"finch",
15+
"path-resolver"
1516
]
1617
},
1718
{

packages/core/src/shared/utilities/cliUtils.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ interface Cli {
5555
exec?: string
5656
}
5757

58-
export type AwsClis = Extract<ToolId, 'session-manager-plugin' | 'aws-cli' | 'sam-cli' | 'docker' | 'finch'>
58+
export type AwsClis = Extract<
59+
ToolId,
60+
'session-manager-plugin' | 'aws-cli' | 'sam-cli' | 'docker' | 'finch' | 'path-resolver'
61+
>
5962

6063
/**
6164
* CLIs and their full filenames and download paths for their respective OSes
@@ -185,6 +188,15 @@ export const awsClis: { [cli in AwsClis]: Cli } = {
185188
manualInstallLink: 'https://runfinch.com/docs/getting-started/installation/',
186189
exec: 'finch',
187190
},
191+
'path-resolver': {
192+
command: {
193+
windows: ['where'],
194+
unix: ['which'],
195+
},
196+
source: {}, // OS utilities used to locate files and executables
197+
name: 'Path resolver',
198+
manualInstallLink: '',
199+
},
188200
}
189201

190202
/**
@@ -579,6 +591,24 @@ export async function updateAwsCli(): Promise<string> {
579591
}
580592

581593
const result = await installCli('aws-cli', false)
594+
595+
// Get the which/ where command, run it to find the AWS CLI path, and display it to the user
596+
const whichCommands = getOsCommands(awsClis['path-resolver'])
597+
if (whichCommands && whichCommands.length > 0) {
598+
const whichCmd = whichCommands[0]
599+
const cliExec = awsClis['aws-cli'].exec
600+
if (cliExec) {
601+
getLogger().info(`Running "${whichCmd} ${cliExec}" to find AWS CLI path`)
602+
const whichResult = await new ChildProcess(whichCmd, [cliExec]).run()
603+
if (whichResult.exitCode === 0 && whichResult.stdout) {
604+
const cliPath = whichResult.stdout.trim().split('\n')[0]
605+
const cliInUseMessage = `Toolkit is using AWS CLI at "${cliPath}".`
606+
getLogger().info(cliInUseMessage)
607+
void vscode.window.showInformationMessage(cliInUseMessage)
608+
}
609+
}
610+
}
611+
582612
return result
583613
}
584614

packages/core/src/test/shared/utilities/cliUtils.test.ts

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@
55

66
import assert from 'assert'
77
import * as path from 'path'
8-
import { installCli } from '../../../shared/utilities/cliUtils'
8+
import sinon from 'sinon'
9+
import { installCli, updateAwsCli } from '../../../shared/utilities/cliUtils'
910
import globals from '../../../shared/extensionGlobals'
1011
import { ChildProcess } from '../../../shared/utilities/processUtils'
1112
import { SeverityLevel } from '../vscode/message'
1213
import { assertTelemetryCurried } from '../../testUtil'
1314
import { getTestWindow } from '../../shared/vscode/window'
1415
import { fs } from '../../../shared'
16+
import { getOpenExternalStub } from '../../globalSetup.test'
1517

1618
describe('cliUtils', async function () {
19+
let sandbox: sinon.SinonSandbox
20+
21+
beforeEach(function () {
22+
sandbox = sinon.createSandbox()
23+
})
24+
1725
afterEach(async function () {
26+
sandbox.restore()
1827
await fs.delete(path.join(globals.context.globalStorageUri.fsPath, 'tools'), { recursive: true, force: true })
1928
})
2029

@@ -61,4 +70,78 @@ describe('cliUtils', async function () {
6170
})
6271
})
6372
})
73+
74+
describe('updateAwsCli', function () {
75+
it('cancels when user does not confirm update', async function () {
76+
getTestWindow().onDidShowMessage((m) => m.close())
77+
78+
await assert.rejects(() => updateAwsCli(), /cancelled/)
79+
})
80+
81+
it('installs CLI and shows path when user confirms', async function () {
82+
let messageCount = 0
83+
getTestWindow().onDidShowMessage((m) => {
84+
messageCount++
85+
if (messageCount === 1 && m.items.some((i) => i.title === 'Update')) {
86+
m.selectItem('Update')
87+
} else if (m.message.includes('not supported')) {
88+
// Toolkit shows "Auto install of AWS CLI is not supported on your platform"
89+
// with "Install manually..." button. We close this message to simulate the user dismissing it.
90+
m.close()
91+
}
92+
})
93+
sandbox.stub(ChildProcess.prototype, 'run').resolves({
94+
exitCode: 0,
95+
stdout: '/usr/local/bin/aws\n',
96+
stderr: '',
97+
} as any)
98+
99+
if (process.platform === 'linux') {
100+
await assert.rejects(() => updateAwsCli(), /cancelled/)
101+
} else {
102+
const result = await updateAwsCli()
103+
assert.ok(result)
104+
const messages = getTestWindow().shownMessages
105+
assert.ok(messages.some((m) => m.message.includes('/usr/local/bin/aws')))
106+
}
107+
})
108+
109+
it('opens manual install link when user selects "Install manually" on Linux', async function () {
110+
let messageCount = 0
111+
const openExternalStub = getOpenExternalStub().resolves(true)
112+
113+
getTestWindow().onDidShowMessage((m) => {
114+
messageCount++
115+
if (messageCount === 1 && m.items.some((i) => i.title === 'Update')) {
116+
m.selectItem('Update')
117+
} else if (m.message.includes('not supported')) {
118+
// Linux: no installer source defined, so auto-install shows "not supported" message.
119+
// Simulate user clicking "Install manually..." button
120+
const manualInstallButton = m.items.find((i) => i.title === 'Install manually...')
121+
if (manualInstallButton) {
122+
m.selectItem(manualInstallButton.title)
123+
}
124+
}
125+
})
126+
127+
if (process.platform === 'linux') {
128+
await assert.rejects(() => updateAwsCli(), /cancelled/)
129+
130+
// Verify the manual install link was opened
131+
assert.ok(openExternalStub.calledOnce)
132+
const openedUrl = openExternalStub.firstCall.args.toString()
133+
assert.ok(openedUrl.includes('getting-started-install.html'))
134+
} else {
135+
// Non-Linux platforms should succeed (existing behavior)
136+
sandbox.stub(ChildProcess.prototype, 'run').resolves({
137+
exitCode: 0,
138+
stdout: '/usr/local/bin/aws',
139+
stderr: '',
140+
} as any)
141+
142+
const result = await updateAwsCli()
143+
assert.ok(result)
144+
}
145+
})
146+
})
64147
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "AWS CLI update success message now shows the actual CLI installation path that the Toolkit uses for console credentials."
4+
}

0 commit comments

Comments
 (0)