@@ -6,12 +6,6 @@ import * as fs from 'fs'
66import type { CLIContext , CLIProcess , ExecResult } from './cli.js'
77import type { BrowserContext } from './browser.js'
88
9- // Env override applied to all CLI helpers — strips CLIENT_ID so commands use the app's own toml.
10- // NOTE: Do NOT add SHOPIFY_CLI_PARTNERS_TOKEN here. The partners token overrides OAuth in the
11- // CLI's auth priority, and the App Management API token it exchanges to lacks permissions to
12- // create apps (403). OAuth provides the full set of required permissions.
13- const FRESH_APP_ENV = { SHOPIFY_FLAG_CLIENT_ID : undefined }
14-
159// ---------------------------------------------------------------------------
1610// CLI helpers — thin wrappers around cli.exec()
1711// ---------------------------------------------------------------------------
@@ -46,8 +40,8 @@ export async function createApp(ctx: {
4640 if ( ctx . flavor ) args . push ( '--flavor' , ctx . flavor )
4741
4842 const result = await cli . execCreateApp ( args , {
49- // Strip CLIENT_ID so the CLI creates a new app instead of linking to a pre-existing one
50- env : { FORCE_COLOR : '0' , ... FRESH_APP_ENV } ,
43+ // Disable color output and strip CLIENT_ID to prevent leaking from parent process.env
44+ env : { FORCE_COLOR : '0' , SHOPIFY_FLAG_CLIENT_ID : undefined } ,
5145 timeout : 5 * 60 * 1000 ,
5246 } )
5347
@@ -82,6 +76,33 @@ export async function createApp(ctx: {
8276 return { ...result , appDir}
8377}
8478
79+ // ---------------------------------------------------------------------------
80+ // Fixture helpers — TOML manipulation for test setup
81+ // ---------------------------------------------------------------------------
82+
83+ /**
84+ * Read the client_id from a shopify.app.toml file.
85+ */
86+ export function extractClientId ( appDir : string ) : string {
87+ const toml = fs . readFileSync ( path . join ( appDir , 'shopify.app.toml' ) , 'utf8' )
88+ const match = toml . match ( / c l i e n t _ i d \s * = \s * " ( [ ^ " ] + ) " / )
89+ if ( ! match ?. [ 1 ] ) {
90+ throw new Error ( `Could not find client_id in ${ path . join ( appDir , 'shopify.app.toml' ) } ` )
91+ }
92+ return match [ 1 ]
93+ }
94+
95+ /**
96+ * Overwrite a created app's shopify.app.toml with a fixture TOML template.
97+ * The template should contain `__CLIENT_ID__` and `__NAME__` placeholders which get
98+ * replaced with the app's real client_id and the provided name.
99+ */
100+ export function injectFixtureToml ( appDir : string , fixtureTomlContent : string , name : string ) : void {
101+ const clientId = extractClientId ( appDir )
102+ const toml = fixtureTomlContent . replace ( / _ _ C L I E N T _ I D _ _ / g, clientId ) . replace ( / _ _ N A M E _ _ / g, name )
103+ fs . writeFileSync ( path . join ( appDir , 'shopify.app.toml' ) , toml )
104+ }
105+
85106export async function generateExtension (
86107 ctx : CLIContext & {
87108 name : string
@@ -91,11 +112,11 @@ export async function generateExtension(
91112) : Promise < ExecResult > {
92113 const args = [ 'app' , 'generate' , 'extension' , '--name' , ctx . name , '--path' , ctx . appDir , '--template' , ctx . template ]
93114 if ( ctx . flavor ) args . push ( '--flavor' , ctx . flavor )
94- return ctx . cli . exec ( args , { env : FRESH_APP_ENV , timeout : 5 * 60 * 1000 } )
115+ return ctx . cli . exec ( args , { timeout : 5 * 60 * 1000 } )
95116}
96117
97118export async function buildApp ( ctx : CLIContext ) : Promise < ExecResult > {
98- return ctx . cli . exec ( [ 'app' , 'build' , '--path' , ctx . appDir ] , { env : FRESH_APP_ENV , timeout : 5 * 60 * 1000 } )
119+ return ctx . cli . exec ( [ 'app' , 'build' , '--path' , ctx . appDir ] , { timeout : 5 * 60 * 1000 } )
99120}
100121
101122export async function deployApp (
@@ -113,7 +134,7 @@ export async function deployApp(
113134 if ( ctx . version ) args . push ( '--version' , ctx . version )
114135 if ( ctx . message ) args . push ( '--message' , ctx . message )
115136 if ( ctx . config ) args . push ( '--config' , ctx . config )
116- return ctx . cli . exec ( args , { env : FRESH_APP_ENV , timeout : 5 * 60 * 1000 } )
137+ return ctx . cli . exec ( args , { timeout : 5 * 60 * 1000 } )
117138}
118139
119140export async function appInfo ( ctx : CLIContext ) : Promise < {
@@ -125,15 +146,15 @@ export async function appInfo(ctx: CLIContext): Promise<{
125146 entrySourceFilePath : string
126147 } [ ]
127148} > {
128- const result = await ctx . cli . exec ( [ 'app' , 'info' , '--path' , ctx . appDir , '--json' ] , { env : FRESH_APP_ENV } )
149+ const result = await ctx . cli . exec ( [ 'app' , 'info' , '--path' , ctx . appDir , '--json' ] )
129150 if ( result . exitCode !== 0 ) {
130151 throw new Error ( `app info failed (exit ${ result . exitCode } ):\nstdout: ${ result . stdout } \nstderr: ${ result . stderr } ` )
131152 }
132153 return JSON . parse ( result . stdout )
133154}
134155
135156export async function functionBuild ( ctx : CLIContext ) : Promise < ExecResult > {
136- return ctx . cli . exec ( [ 'app' , 'function' , 'build' , '--path' , ctx . appDir ] , { env : FRESH_APP_ENV , timeout : 3 * 60 * 1000 } )
157+ return ctx . cli . exec ( [ 'app' , 'function' , 'build' , '--path' , ctx . appDir ] , { timeout : 3 * 60 * 1000 } )
137158}
138159
139160export async function functionRun (
@@ -142,14 +163,12 @@ export async function functionRun(
142163 } ,
143164) : Promise < ExecResult > {
144165 return ctx . cli . exec ( [ 'app' , 'function' , 'run' , '--path' , ctx . appDir , '--input' , ctx . inputPath ] , {
145- env : FRESH_APP_ENV ,
146166 timeout : 60 * 1000 ,
147167 } )
148168}
149169
150170export async function versionsList ( ctx : CLIContext ) : Promise < ExecResult > {
151171 return ctx . cli . exec ( [ 'app' , 'versions' , 'list' , '--path' , ctx . appDir , '--json' ] , {
152- env : FRESH_APP_ENV ,
153172 timeout : 60 * 1000 ,
154173 } )
155174}
@@ -160,7 +179,6 @@ export async function configLink(
160179 } ,
161180) : Promise < ExecResult > {
162181 return ctx . cli . exec ( [ 'app' , 'config' , 'link' , '--path' , ctx . appDir , '--client-id' , ctx . clientId ] , {
163- env : FRESH_APP_ENV ,
164182 timeout : 2 * 60 * 1000 ,
165183 } )
166184}
@@ -375,13 +393,9 @@ export async function teardownApp(
375393// ---------------------------------------------------------------------------
376394
377395export const appTestFixture = authFixture . extend < { authReady : void } > ( {
378- // Auto-trigger authLogin and strip CLIENT_ID so tests create their own apps
396+ // Auto-trigger authLogin so the OAuth session is available for all app tests
379397 authReady : [
380- async (
381- { authLogin : _authLogin , env} : { authLogin : void ; env : import ( './env.js' ) . E2EEnv } ,
382- use : ( ) => Promise < void > ,
383- ) => {
384- delete env . processEnv . SHOPIFY_FLAG_CLIENT_ID
398+ async ( { authLogin : _authLogin } : { authLogin : void } , use : ( ) => Promise < void > ) => {
385399 await use ( )
386400 } ,
387401 { auto : true } ,
0 commit comments