@@ -365,6 +365,45 @@ describe('runList', () => {
365365 expect ( seen [ 0 ] ) . toContain ( 'createdFrom=portal' ) ;
366366 } ) ;
367367
368+ it ( 'uses TESTSPRITE_PROJECT_ID when --project is omitted' , async ( ) => {
369+ const { credentialsPath } = makeCreds ( ) ;
370+ const seen : string [ ] = [ ] ;
371+ const fetchImpl = makeFetch ( url => {
372+ seen . push ( url ) ;
373+ return { body : { items : [ FE_TEST ] , nextToken : null } } ;
374+ } ) ;
375+ await runList (
376+ { profile : 'default' , output : 'json' , debug : false } ,
377+ {
378+ credentialsPath,
379+ env : { TESTSPRITE_PROJECT_ID : 'project_env' } as NodeJS . ProcessEnv ,
380+ fetchImpl,
381+ stdout : ( ) => undefined ,
382+ } ,
383+ ) ;
384+ expect ( seen [ 0 ] ) . toContain ( 'projectId=project_env' ) ;
385+ } ) ;
386+
387+ it ( 'prefers explicit --project over TESTSPRITE_PROJECT_ID' , async ( ) => {
388+ const { credentialsPath } = makeCreds ( ) ;
389+ const seen : string [ ] = [ ] ;
390+ const fetchImpl = makeFetch ( url => {
391+ seen . push ( url ) ;
392+ return { body : { items : [ FE_TEST ] , nextToken : null } } ;
393+ } ) ;
394+ await runList (
395+ { profile : 'default' , output : 'json' , debug : false , projectId : 'project_flag' } ,
396+ {
397+ credentialsPath,
398+ env : { TESTSPRITE_PROJECT_ID : 'project_env' } as NodeJS . ProcessEnv ,
399+ fetchImpl,
400+ stdout : ( ) => undefined ,
401+ } ,
402+ ) ;
403+ expect ( seen [ 0 ] ) . toContain ( 'projectId=project_flag' ) ;
404+ expect ( seen [ 0 ] ) . not . toContain ( 'projectId=project_env' ) ;
405+ } ) ;
406+
368407 it ( 'accepts --created-from cli and passes createdFrom=cli to the wire (dogfood 2026-06-04)' , async ( ) => {
369408 // End-to-end through parseEnumFlag: backend now stamps createFrom='cli'
370409 // on `testsprite test create` rows, so the filter must accept 'cli'.
@@ -4847,7 +4886,7 @@ describe('runCreate', () => {
48474886 ...SAMPLE_RESPONSE ,
48484887 type : 'backend' ,
48494888 warnings : [
4850- 'This test appears to hardcode an auth credential — read auth from __AUTH_HEADERS__.' ,
4889+ 'This test appears to hardcode an auth credential - read auth from __AUTH_HEADERS__.' ,
48514890 ] ,
48524891 } ,
48534892 } ;
@@ -4873,10 +4912,43 @@ describe('runCreate', () => {
48734912 ) ;
48744913 // Warning lands on stderr, prefixed `[warn]`.
48754914 expect ( err . some ( l => l . includes ( '[warn]' ) && l . includes ( '__AUTH_HEADERS__' ) ) ) . toBe ( true ) ;
4876- // stdout stays the parseable wire object — no warning noise.
4915+ // stdout stays the parseable wire object - no warning noise.
48774916 expect ( out . join ( '\n' ) ) . not . toContain ( '[warn]' ) ;
48784917 } ) ;
48794918
4919+ it ( 'uses TESTSPRITE_PROJECT_ID for create when --project is omitted' , async ( ) => {
4920+ const { credentialsPath } = makeCreds ( ) ;
4921+ const codeFile = writeCodeFile ( 'code body' ) ;
4922+ type Captured = { method : string ; body : unknown ; url : string } ;
4923+ const captured : Captured [ ] = [ ] ;
4924+ const fetchImpl = makeFetch ( ( url , init ) => {
4925+ const method = init . method ?? 'GET' ;
4926+ captured . push ( { url, method, body : init . body ? JSON . parse ( init . body as string ) : undefined } ) ;
4927+ if ( method === 'GET' ) return { status : 200 , body : { items : [ ] } } ;
4928+ return { status : 200 , body : SAMPLE_RESPONSE } ;
4929+ } ) ;
4930+ await runCreate (
4931+ {
4932+ profile : 'default' ,
4933+ output : 'json' ,
4934+ debug : false ,
4935+ type : 'frontend' ,
4936+ name : 'n' ,
4937+ codeFile,
4938+ } ,
4939+ {
4940+ credentialsPath,
4941+ env : { TESTSPRITE_PROJECT_ID : 'project_env' } as NodeJS . ProcessEnv ,
4942+ fetchImpl,
4943+ stdout : ( ) => undefined ,
4944+ } ,
4945+ ) ;
4946+ expect ( captured . some ( c => c . method === 'GET' && c . url . includes ( 'projectId=project_env' ) ) ) . toBe (
4947+ true ,
4948+ ) ;
4949+ const post = captured . find ( c => c . method === 'POST' ) ! ;
4950+ expect ( post . body ) . toMatchObject ( { projectId : 'project_env' } ) ;
4951+ } ) ;
48804952 it ( 'respects a caller-supplied --idempotency-key (for safe retries)' , async ( ) => {
48814953 const { credentialsPath } = makeCreds ( ) ;
48824954 const codeFile = writeCodeFile ( 'code body' ) ;
@@ -5030,7 +5102,6 @@ describe('runCreate', () => {
50305102 profile : 'default' ,
50315103 output : 'json' ,
50325104 debug : false ,
5033- // @ts -expect-error — exercising the runtime gate
50345105 projectId : undefined ,
50355106 type : 'frontend' ,
50365107 name : 'n' ,
0 commit comments