@@ -87,6 +87,18 @@ describe('session-set-defaults tool', () => {
8787 expect ( result . content [ 0 ] . text ) . toContain ( 'useLatestOS' ) ;
8888 } ) ;
8989
90+ it ( 'should reject env values that are not strings' , async ( ) => {
91+ const result = await handler ( {
92+ env : {
93+ STAGING_ENABLED : 1 as unknown as string ,
94+ } ,
95+ } ) ;
96+
97+ expect ( result . isError ) . toBe ( true ) ;
98+ expect ( result . content [ 0 ] . text ) . toContain ( 'Parameter validation failed' ) ;
99+ expect ( result . content [ 0 ] . text ) . toContain ( 'env' ) ;
100+ } ) ;
101+
90102 it ( 'should clear workspacePath when projectPath is set' , async ( ) => {
91103 sessionStore . setDefaults ( { workspacePath : '/old/App.xcworkspace' } ) ;
92104 const result = await sessionSetDefaultsLogic (
@@ -358,6 +370,48 @@ describe('session-set-defaults tool', () => {
358370 expect ( parsed . activeSessionDefaultsProfile ) . toBe ( 'ios' ) ;
359371 } ) ;
360372
373+ it ( 'should store env as a Record<string, string> default' , async ( ) => {
374+ const envVars = { STAGING_ENABLED : '1' , DEBUG : 'true' } ;
375+ const result = await sessionSetDefaultsLogic ( { env : envVars } , createContext ( ) ) ;
376+
377+ expect ( result . isError ) . toBe ( false ) ;
378+ expect ( sessionStore . getAll ( ) . env ) . toEqual ( envVars ) ;
379+ } ) ;
380+
381+ it ( 'should persist env to config when persist is true' , async ( ) => {
382+ const yaml = [ 'schemaVersion: 1' , 'sessionDefaults: {}' , '' ] . join ( '\n' ) ;
383+
384+ const writes : { path : string ; content : string } [ ] = [ ] ;
385+ const fs = createMockFileSystemExecutor ( {
386+ existsSync : ( targetPath : string ) => targetPath === configPath ,
387+ readFile : async ( targetPath : string ) => {
388+ if ( targetPath !== configPath ) {
389+ throw new Error ( `Unexpected readFile path: ${ targetPath } ` ) ;
390+ }
391+ return yaml ;
392+ } ,
393+ writeFile : async ( targetPath : string , content : string ) => {
394+ writes . push ( { path : targetPath , content } ) ;
395+ } ,
396+ } ) ;
397+
398+ await initConfigStore ( { cwd, fs } ) ;
399+
400+ const envVars = { API_URL : 'https://staging.example.com' } ;
401+ const result = await sessionSetDefaultsLogic (
402+ { env : envVars , persist : true } ,
403+ createContext ( ) ,
404+ ) ;
405+
406+ expect ( result . content [ 0 ] . text ) . toContain ( 'Persisted defaults to' ) ;
407+ expect ( writes . length ) . toBe ( 1 ) ;
408+
409+ const parsed = parseYaml ( writes [ 0 ] . content ) as {
410+ sessionDefaults ?: Record < string , unknown > ;
411+ } ;
412+ expect ( parsed . sessionDefaults ?. env ) . toEqual ( envVars ) ;
413+ } ) ;
414+
361415 it ( 'should not persist when persist is true but no defaults were provided' , async ( ) => {
362416 const result = await sessionSetDefaultsLogic ( { persist : true } , createContext ( ) ) ;
363417
0 commit comments