Skip to content

Commit d6f7d90

Browse files
committed
change env var gate and move some logic to cli kit for others to use
1 parent ae8b6b5 commit d6f7d90

File tree

13 files changed

+92
-72
lines changed

13 files changed

+92
-72
lines changed

packages/cli-kit/src/private/node/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const environmentVariables = {
1616
alwaysLogAnalytics: 'SHOPIFY_CLI_ALWAYS_LOG_ANALYTICS',
1717
alwaysLogMetrics: 'SHOPIFY_CLI_ALWAYS_LOG_METRICS',
1818
deviceAuth: 'SHOPIFY_CLI_DEVICE_AUTH',
19+
doctor: 'SHOPIFY_CLI_DOCTOR',
1920
enableCliRedirect: 'SHOPIFY_CLI_ENABLE_CLI_REDIRECT',
2021
env: 'SHOPIFY_CLI_ENV',
2122
firstPartyDev: 'SHOPIFY_CLI_1P_DEV',

packages/cli-kit/src/public/node/context/local.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ export function firstPartyDev(env = process.env): boolean {
112112
return isTruthy(env[environmentVariables.firstPartyDev])
113113
}
114114

115+
/**
116+
* Returns true if the CLI can run the "doctor-release" command.
117+
*
118+
* @param env - The environment variables from the environment of the current process.
119+
* @returns True if the CLI can run the "doctor-release" command.
120+
*/
121+
export function canRunDoctorRelease(env = process.env): boolean {
122+
return isTruthy(env[environmentVariables.doctor])
123+
}
124+
115125
/**
116126
* Return gitpodURL if we are running in gitpod.
117127
* Https://www.gitpod.io/docs/environment-variables#default-environment-variables.

packages/cli/src/cli/services/doctor-release/framework.test.ts renamed to packages/cli-kit/src/public/node/doctor/framework.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ import {DoctorSuite} from './framework.js'
22
import {describe, expect, test, vi, beforeEach} from 'vitest'
33
import type {DoctorContext} from './types.js'
44

5-
vi.mock('@shopify/cli-kit/node/fs')
6-
vi.mock('@shopify/cli-kit/node/system')
5+
vi.mock('../fs.js')
6+
vi.mock('../system.js')
77

88
/**
99
* Creates a minimal DoctorContext for testing
1010
*/
1111
function createTestContext(overrides?: Partial<DoctorContext>): DoctorContext {
1212
return {
1313
workingDirectory: '/test/dir',
14-
environment: 'test',
1514
data: {},
1615
...overrides,
1716
}

packages/cli/src/cli/services/doctor-release/framework.ts renamed to packages/cli-kit/src/public/node/doctor/framework.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {fileExists, readFile} from '@shopify/cli-kit/node/fs'
2-
import {isAbsolutePath, joinPath, relativePath} from '@shopify/cli-kit/node/path'
3-
import {execCommand, captureCommandWithExitCode} from '@shopify/cli-kit/node/system'
1+
import {fileExists, readFile} from '../fs.js'
2+
import {isAbsolutePath, joinPath, relativePath} from '../path.js'
3+
import {execCommand, captureCommandWithExitCode} from '../system.js'
44
import type {DoctorContext, TestResult, AssertionResult} from './types.js'
55

66
/**
@@ -52,17 +52,17 @@ interface RegisteredTest {
5252
* }
5353
* ```
5454
*/
55-
export abstract class DoctorSuite {
55+
export abstract class DoctorSuite<TContext extends DoctorContext = DoctorContext> {
5656
static description = 'Doctor test suite'
5757

58-
protected context!: DoctorContext
58+
protected context!: TContext
5959
private assertions: AssertionResult[] = []
6060
private registeredTests: RegisteredTest[] = []
6161

6262
/**
6363
* Run the entire test suite
6464
*/
65-
async runSuite(context: DoctorContext): Promise<TestResult[]> {
65+
async runSuite(context: TContext): Promise<TestResult[]> {
6666
this.context = context
6767
this.registeredTests = []
6868
const results: TestResult[] = []

packages/cli/src/cli/services/doctor-release/reporter.ts renamed to packages/cli-kit/src/public/node/doctor/reporter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import colors from '@shopify/cli-kit/node/colors'
2-
import {outputInfo} from '@shopify/cli-kit/node/output'
3-
import {relativizePath} from '@shopify/cli-kit/node/path'
1+
import colors from '../colors.js'
2+
import {outputInfo} from '../output.js'
3+
import {relativizePath} from '../path.js'
44
import type {TestResult, AssertionResult} from './types.js'
55

66
const log = (message: string) => outputInfo(message)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
type TestStatus = 'passed' | 'failed' | 'skipped'
2+
3+
export interface AssertionResult {
4+
description: string
5+
passed: boolean
6+
expected?: unknown
7+
actual?: unknown
8+
}
9+
10+
export interface TestResult {
11+
name: string
12+
status: TestStatus
13+
duration: number
14+
assertions: AssertionResult[]
15+
error?: Error
16+
}
17+
18+
export interface DoctorContext {
19+
workingDirectory: string
20+
data: Record<string, unknown>
21+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import Command from '@shopify/cli-kit/node/base-command'
2-
import {firstPartyDev} from '@shopify/cli-kit/node/context/local'
2+
import {canRunDoctorRelease} from '@shopify/cli-kit/node/context/local'
33
import {renderInfo} from '@shopify/cli-kit/node/ui'
44

55
export default class DoctorRelease extends Command {
66
static description = 'Run CLI doctor-release tests'
77
static hidden = true
88

99
async run(): Promise<void> {
10-
if (!firstPartyDev()) {
10+
if (!canRunDoctorRelease()) {
1111
return
1212
}
1313

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Command from '@shopify/cli-kit/node/base-command'
33
import {globalFlags} from '@shopify/cli-kit/node/cli'
44
import {Flags} from '@oclif/core'
55
import {resolvePath, cwd} from '@shopify/cli-kit/node/path'
6-
import {firstPartyDev} from '@shopify/cli-kit/node/context/local'
6+
import {canRunDoctorRelease} from '@shopify/cli-kit/node/context/local'
77

88
export default class DoctorReleaseTheme extends Command {
99
static description = 'Run all theme command doctor-release tests'
@@ -36,7 +36,7 @@ export default class DoctorReleaseTheme extends Command {
3636
}
3737

3838
async run(): Promise<void> {
39-
if (!firstPartyDev()) {
39+
if (!canRunDoctorRelease()) {
4040
return
4141
}
4242

packages/cli/src/cli/services/doctor-release/context.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
import {cwd} from '@shopify/cli-kit/node/path'
2-
import type {DoctorContext, ThemeDoctorOptions} from './types.js'
2+
import type {DoctorContext} from '@shopify/cli-kit/node/doctor/types'
33

4-
export function createDoctorContext(options: ThemeDoctorOptions): DoctorContext {
4+
export interface ThemeDoctorContext extends DoctorContext {
5+
// Environment name from shopify.theme.toml (required)
6+
environment: string
7+
// Store URL (from environment or flags)
8+
store?: string
9+
// Password/token for Theme Access app
10+
password?: string
11+
// Theme name created during init
12+
themeName?: string
13+
// Theme path after init
14+
themePath?: string
15+
// Theme ID after push
16+
themeId?: string
17+
}
18+
19+
export interface ThemeDoctorOptions {
20+
// Working directory (defaults to cwd)
21+
path?: string
22+
// Environment name from shopify.theme.toml (required)
23+
environment: string
24+
// Store URL (overrides environment)
25+
store?: string
26+
// Password/token (overrides environment)
27+
password?: string
28+
}
29+
30+
export function createDoctorContext(options: ThemeDoctorOptions): ThemeDoctorContext {
531
return {
632
workingDirectory: options.path ?? cwd(),
733
environment: options.environment,

packages/cli/src/cli/services/doctor-release/theme/runner.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import ThemeInitTests from './tests/init.js'
22
import ThemePushTests from './tests/push.js'
33
import {createDoctorContext} from '../context.js'
4-
import {reportTestStart, reportTestResult, reportSuiteStart, reportSummary, initReporter} from '../reporter.js'
5-
import {DoctorSuite} from '../framework.js'
6-
import type {TestResult, ThemeDoctorOptions} from '../types.js'
4+
import {
5+
reportTestStart,
6+
reportTestResult,
7+
reportSuiteStart,
8+
reportSummary,
9+
initReporter,
10+
} from '@shopify/cli-kit/node/doctor/reporter'
11+
import {DoctorSuite} from '@shopify/cli-kit/node/doctor/framework'
12+
import type {ThemeDoctorContext, ThemeDoctorOptions} from '../context.js'
13+
import type {TestResult} from '@shopify/cli-kit/node/doctor/types'
714

815
// Test suites run in order. If a test relies on another, ensure that test runs after it's dependency.
9-
const themeSuites: (new () => DoctorSuite)[] = [ThemeInitTests, ThemePushTests]
16+
const themeSuites: (new () => DoctorSuite<ThemeDoctorContext>)[] = [ThemeInitTests, ThemePushTests]
1017

1118
/**
1219
* Run all theme doctor tests.

0 commit comments

Comments
 (0)