@@ -69,6 +69,7 @@ describe("FunctionsEmulator", () => {
6969 expect ( shim ) . to . include ( "PathFinder.find_spec(" ) ;
7070 expect ( shim ) . to . include ( '"sitecustomize", _firebase_remaining_paths' ) ;
7171 expect ( shim ) . to . include ( "module_from_spec" ) ;
72+ expect ( shim ) . to . include ( 'sys.modules["sitecustomize"] = _firebase_user_sitecustomize_module' ) ;
7273 expect ( shim ) . to . include ( "exec_module" ) ;
7374 expect ( logLabeled ) . to . have . been . calledOnceWith (
7475 "BULLET" ,
@@ -156,10 +157,12 @@ describe("FunctionsEmulator", () => {
156157 expect ( log ) . to . not . have . been . called ;
157158 } ) ;
158159
159- it ( "should log a debug message and continue shutdown when shim dir cleanup fails " , async ( ) => {
160+ it ( "should recreate the shim dir after cleanup fails with a non-ENOENT error " , async ( ) => {
160161 sandbox . stub ( portfinder , "getPortPromise" ) . resolves ( 9595 ) ;
161- sandbox . stub ( functionsPython , "runWithVirtualEnv" ) . returns ( { } as any ) ;
162- sandbox . stub ( fs , "mkdtempSync" ) . returns ( "/tmp/firebase-tools-python-shim-error" ) ;
162+ const runWithVirtualEnv = sandbox . stub ( functionsPython , "runWithVirtualEnv" ) . returns ( { } as any ) ;
163+ const mkdtempSync = sandbox . stub ( fs , "mkdtempSync" ) ;
164+ mkdtempSync . onFirstCall ( ) . returns ( "/tmp/firebase-tools-python-shim-error" ) ;
165+ mkdtempSync . onSecondCall ( ) . returns ( "/tmp/firebase-tools-python-shim-recreated" ) ;
163166 sandbox . stub ( fs , "writeFileSync" ) ;
164167 const rmSync = sandbox . stub ( fs , "rmSync" ) . throws ( new Error ( "permission denied" ) ) ;
165168
@@ -168,10 +171,15 @@ describe("FunctionsEmulator", () => {
168171
169172 await ( emulator as any ) . startPython ( makePythonBackend ( ) , { } ) ;
170173 await emulator . stop ( ) ;
174+ await ( emulator as any ) . startPython ( makePythonBackend ( ) , { } ) ;
171175
172176 expect ( rmSync ) . to . have . been . calledOnceWith ( "/tmp/firebase-tools-python-shim-error" , {
173177 recursive : true ,
174178 } ) ;
179+ expect ( mkdtempSync ) . to . have . been . calledTwice ;
180+ expect ( runWithVirtualEnv . secondCall . args [ 2 ] . PYTHONPATH ) . to . equal (
181+ "/tmp/firebase-tools-python-shim-recreated" ,
182+ ) ;
175183 expect ( log ) . to . have . been . calledWith (
176184 "DEBUG" ,
177185 sinon . match ( "Failed to clean up python-disable-gunicorn shim dir" ) ,
0 commit comments