Skip to content

Commit ddeabf9

Browse files
committed
Add warning and confirmation before running theme doctor
1 parent 97da1b4 commit ddeabf9

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import DoctorReleaseTheme from './index.js'
2+
import {runThemeDoctor} from '../../../services/doctor-release/theme/runner.js'
3+
import {renderConfirmationPrompt} from '@shopify/cli-kit/node/ui'
4+
import {afterEach, expect, test, vi} from 'vitest'
5+
6+
vi.mock('@shopify/cli-kit/node/ui')
7+
vi.mock('../../../services/doctor-release/theme/runner.js')
8+
9+
afterEach(() => {
10+
vi.unstubAllEnvs()
11+
})
12+
13+
test('does not run theme doctor when user cancels', async () => {
14+
// Given
15+
vi.stubEnv('SHOPIFY_CLI_DOCTOR', '1')
16+
vi.mocked(renderConfirmationPrompt).mockResolvedValue(false)
17+
18+
// When
19+
await DoctorReleaseTheme.run(['--environment', 'test'])
20+
21+
// Then
22+
expect(runThemeDoctor).not.toHaveBeenCalled()
23+
})
24+
25+
test('runs theme doctor when user confirms', async () => {
26+
// Given
27+
vi.stubEnv('SHOPIFY_CLI_DOCTOR', '1')
28+
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true)
29+
vi.mocked(runThemeDoctor).mockResolvedValue([])
30+
31+
// When
32+
await DoctorReleaseTheme.run(['--environment', 'test'])
33+
34+
// Then
35+
expect(runThemeDoctor).toHaveBeenCalled()
36+
})
37+
38+
test('does not run theme doctor when environment variable is not set', async () => {
39+
// Given - no SHOPIFY_CLI_DOCTOR env var set
40+
41+
// When
42+
await DoctorReleaseTheme.run(['--environment', 'test'])
43+
44+
// Then - neither prompt nor doctor should be called
45+
expect(renderConfirmationPrompt).not.toHaveBeenCalled()
46+
expect(runThemeDoctor).not.toHaveBeenCalled()
47+
})

packages/cli/src/cli/commands/doctor-release/theme/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {globalFlags} from '@shopify/cli-kit/node/cli'
44
import {Flags} from '@oclif/core'
55
import {resolvePath, cwd} from '@shopify/cli-kit/node/path'
66
import {canRunDoctorRelease} from '@shopify/cli-kit/node/context/local'
7+
import {renderConfirmationPrompt, RenderConfirmationPromptOptions} from '@shopify/cli-kit/node/ui'
78

89
export default class DoctorReleaseTheme extends Command {
910
static description = 'Run all theme command doctor-release tests'
@@ -39,7 +40,16 @@ export default class DoctorReleaseTheme extends Command {
3940
if (!canRunDoctorRelease()) {
4041
return
4142
}
43+
const promptOptions: RenderConfirmationPromptOptions = {
44+
message: `This will run automated theme commands against your shop. It will modify remote themes. Please confirm before running.`,
45+
confirmationMessage: 'Yes I understand',
46+
cancellationMessage: 'No, cancel the command',
47+
}
48+
const confirmed = await renderConfirmationPrompt(promptOptions)
4249

50+
if (!confirmed) {
51+
return
52+
}
4353
const {flags} = await this.parse(DoctorReleaseTheme)
4454

4555
const results = await runThemeDoctor({

0 commit comments

Comments
 (0)