@@ -74,6 +74,12 @@ function createFakeCodexBin(rootDir: string): string {
7474 return fakeBin ;
7575}
7676
77+ function createCustomFakeCodexBin ( rootDir : string , lines : string [ ] ) : string {
78+ const fakeBin = join ( rootDir , `fake-codex-${ createdDirs . length } .js` ) ;
79+ writeFileSync ( fakeBin , lines . join ( "\n" ) , "utf8" ) ;
80+ return fakeBin ;
81+ }
82+
7783function runWrapper (
7884 fixtureRoot : string ,
7985 args : string [ ] ,
@@ -226,6 +232,43 @@ describe("codex bin wrapper", () => {
226232 expect ( result . stdout ) . not . toContain ( 'cli_auth_credentials_store="file"' ) ;
227233 } ) ;
228234
235+ it ( "does not double-inject file auth store when caller already set it" , ( ) => {
236+ const fixtureRoot = createWrapperFixture ( ) ;
237+ const fakeBin = createFakeCodexBin ( fixtureRoot ) ;
238+ const result = runWrapper (
239+ fixtureRoot ,
240+ [ "exec" , "status" , "-c" , 'cli_auth_credentials_store="keychain"' ] ,
241+ {
242+ CODEX_MULTI_AUTH_REAL_CODEX_BIN : fakeBin ,
243+ } ,
244+ ) ;
245+
246+ expect ( result . status ) . toBe ( 0 ) ;
247+ expect ( result . stdout ) . toContain (
248+ 'FORWARDED:exec status -c cli_auth_credentials_store="keychain"' ,
249+ ) ;
250+ expect (
251+ result . stdout . match ( / c l i _ a u t h _ c r e d e n t i a l s _ s t o r e = / g) ?? [ ] ,
252+ ) . toHaveLength ( 1 ) ;
253+ } ) ;
254+
255+ it ( "propagates downstream file-store write errors from forwarded wrapper execution" , ( ) => {
256+ const fixtureRoot = createWrapperFixture ( ) ;
257+ const fakeBin = createCustomFakeCodexBin ( fixtureRoot , [
258+ "#!/usr/bin/env node" ,
259+ "const forwarded = process.argv.slice(2);" ,
260+ "if (!forwarded.includes('cli_auth_credentials_store=\"file\"')) process.exit(99);" ,
261+ 'process.stderr.write("EPERM: locked auth store\\n");' ,
262+ "process.exit(13);" ,
263+ ] ) ;
264+ const result = runWrapper ( fixtureRoot , [ "exec" , "status" ] , {
265+ CODEX_MULTI_AUTH_REAL_CODEX_BIN : fakeBin ,
266+ } ) ;
267+
268+ expect ( result . status ) . toBe ( 13 ) ;
269+ expect ( combinedOutput ( result ) ) . toContain ( "EPERM: locked auth store" ) ;
270+ } ) ;
271+
229272 it ( "installs Windows codex shell guards to survive shim takeover" , ( ) => {
230273 if ( process . platform !== "win32" ) {
231274 return ;
0 commit comments