@@ -17,13 +17,15 @@ async function withMockedAdb(
1717 argsLogPath : string ;
1818 readFilePath : string ;
1919 scriptFilePath : string ;
20+ stdinFilePath : string ;
2021 } ) => Promise < void > ,
2122) : Promise < void > {
2223 const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'agent-device-runtime-hints-android-' ) ) ;
2324 const adbPath = path . join ( tmpDir , 'adb' ) ;
2425 const argsLogPath = path . join ( tmpDir , 'args.log' ) ;
2526 const readFilePath = path . join ( tmpDir , 'existing.xml' ) ;
2627 const scriptFilePath = path . join ( tmpDir , 'write-script.sh' ) ;
28+ const stdinFilePath = path . join ( tmpDir , 'write-stdin.xml' ) ;
2729 await fs . writeFile (
2830 adbPath ,
2931 [
@@ -52,6 +54,7 @@ async function withMockedAdb(
5254 ' exit "${AGENT_DEVICE_TEST_RUN_AS_ID_EXIT_CODE:-0}"' ,
5355 'fi' ,
5456 'if [ "$1" = "shell" ] && [ "$2" = "run-as" ] && [ "$4" = "sh" ] && [ "$5" = "-c" ]; then' ,
57+ ' cat > "$AGENT_DEVICE_TEST_STDIN_FILE"' ,
5558 ' if [ -n "$AGENT_DEVICE_TEST_RUN_AS_WRITE_STDOUT" ]; then' ,
5659 ' printf "%s" "$AGENT_DEVICE_TEST_RUN_AS_WRITE_STDOUT"' ,
5760 ' fi' ,
@@ -76,6 +79,7 @@ async function withMockedAdb(
7679 const previousArgsFile = process . env . AGENT_DEVICE_TEST_ARGS_FILE ;
7780 const previousReadFile = process . env . AGENT_DEVICE_TEST_READ_FILE ;
7881 const previousScriptFile = process . env . AGENT_DEVICE_TEST_SCRIPT_FILE ;
82+ const previousStdinFile = process . env . AGENT_DEVICE_TEST_STDIN_FILE ;
7983 const previousRunAsIdExitCode = process . env . AGENT_DEVICE_TEST_RUN_AS_ID_EXIT_CODE ;
8084 const previousRunAsIdStdout = process . env . AGENT_DEVICE_TEST_RUN_AS_ID_STDOUT ;
8185 const previousRunAsIdStderr = process . env . AGENT_DEVICE_TEST_RUN_AS_ID_STDERR ;
@@ -86,6 +90,7 @@ async function withMockedAdb(
8690 process . env . AGENT_DEVICE_TEST_ARGS_FILE = argsLogPath ;
8791 process . env . AGENT_DEVICE_TEST_READ_FILE = readFilePath ;
8892 process . env . AGENT_DEVICE_TEST_SCRIPT_FILE = scriptFilePath ;
93+ process . env . AGENT_DEVICE_TEST_STDIN_FILE = stdinFilePath ;
8994
9095 const device : DeviceInfo = {
9196 platform : 'android' ,
@@ -96,12 +101,13 @@ async function withMockedAdb(
96101 } ;
97102
98103 try {
99- await run ( { device, argsLogPath, readFilePath, scriptFilePath } ) ;
104+ await run ( { device, argsLogPath, readFilePath, scriptFilePath, stdinFilePath } ) ;
100105 } finally {
101106 process . env . PATH = previousPath ;
102107 restoreEnv ( 'AGENT_DEVICE_TEST_ARGS_FILE' , previousArgsFile ) ;
103108 restoreEnv ( 'AGENT_DEVICE_TEST_READ_FILE' , previousReadFile ) ;
104109 restoreEnv ( 'AGENT_DEVICE_TEST_SCRIPT_FILE' , previousScriptFile ) ;
110+ restoreEnv ( 'AGENT_DEVICE_TEST_STDIN_FILE' , previousStdinFile ) ;
105111 restoreEnv ( 'AGENT_DEVICE_TEST_RUN_AS_ID_EXIT_CODE' , previousRunAsIdExitCode ) ;
106112 restoreEnv ( 'AGENT_DEVICE_TEST_RUN_AS_ID_STDOUT' , previousRunAsIdStdout ) ;
107113 restoreEnv ( 'AGENT_DEVICE_TEST_RUN_AS_ID_STDERR' , previousRunAsIdStderr ) ;
@@ -175,7 +181,7 @@ test('resolveRuntimeTransportHints derives host, port, and scheme from bundle UR
175181} ) ;
176182
177183test ( 'applyRuntimeHintsToApp writes React Native Android dev prefs' , async ( ) => {
178- await withMockedAdb ( async ( { device, argsLogPath, readFilePath, scriptFilePath } ) => {
184+ await withMockedAdb ( async ( { device, argsLogPath, readFilePath, scriptFilePath, stdinFilePath } ) => {
179185 await fs . writeFile (
180186 readFilePath ,
181187 [
@@ -199,11 +205,13 @@ test('applyRuntimeHintsToApp writes React Native Android dev prefs', async () =>
199205
200206 const loggedArgs = await fs . readFile ( argsLogPath , 'utf8' ) ;
201207 const script = await fs . readFile ( scriptFilePath , 'utf8' ) ;
208+ const stdinPayload = await fs . readFile ( stdinFilePath , 'utf8' ) ;
202209 assert . match ( loggedArgs , / s h e l l r u n - a s c o m \. e x a m p l e \. d e m o c a t s h a r e d _ p r e f s \/ R e a c t N a t i v e D e v P r e f s \. x m l / ) ;
203210 assert . match ( loggedArgs , / s h e l l r u n - a s c o m \. e x a m p l e \. d e m o s h - c / ) ;
204- assert . match ( script , / < s t r i n g n a m e = " k e e p " > v a l u e < \/ s t r i n g > / ) ;
205- assert . match ( script , / < s t r i n g n a m e = " d e b u g _ h t t p _ h o s t " > 1 0 \. 0 \. 0 \. 1 0 : 8 0 8 2 < \/ s t r i n g > / ) ;
206- assert . match ( script , / < b o o l e a n n a m e = " d e v _ s e r v e r _ h t t p s " v a l u e = " t r u e " \/ > / ) ;
211+ assert . equal ( script , 'mkdir -p shared_prefs && cat > shared_prefs/ReactNativeDevPrefs.xml' ) ;
212+ assert . match ( stdinPayload , / < s t r i n g n a m e = " k e e p " > v a l u e < \/ s t r i n g > / ) ;
213+ assert . match ( stdinPayload , / < s t r i n g n a m e = " d e b u g _ h t t p _ h o s t " > 1 0 \. 0 \. 0 \. 1 0 : 8 0 8 2 < \/ s t r i n g > / ) ;
214+ assert . match ( stdinPayload , / < b o o l e a n n a m e = " d e v _ s e r v e r _ h t t p s " v a l u e = " t r u e " \/ > / ) ;
207215 } ) ;
208216} ) ;
209217
@@ -278,7 +286,7 @@ test('applyRuntimeHintsToApp preserves write failures after a successful run-as
278286} ) ;
279287
280288test ( 'clearRuntimeHintsFromApp removes managed Android runtime prefs but preserves unrelated entries' , async ( ) => {
281- await withMockedAdb ( async ( { device, readFilePath, scriptFilePath } ) => {
289+ await withMockedAdb ( async ( { device, readFilePath, stdinFilePath } ) => {
282290 await fs . writeFile (
283291 readFilePath ,
284292 [
@@ -298,10 +306,10 @@ test('clearRuntimeHintsFromApp removes managed Android runtime prefs but preserv
298306 appId : 'com.example.demo' ,
299307 } ) ;
300308
301- const script = await fs . readFile ( scriptFilePath , 'utf8' ) ;
302- assert . match ( script , / < s t r i n g n a m e = " k e e p " > v a l u e < \/ s t r i n g > / ) ;
303- assert . doesNotMatch ( script , / d e b u g _ h t t p _ h o s t / ) ;
304- assert . doesNotMatch ( script , / d e v _ s e r v e r _ h t t p s / ) ;
309+ const stdinPayload = await fs . readFile ( stdinFilePath , 'utf8' ) ;
310+ assert . match ( stdinPayload , / < s t r i n g n a m e = " k e e p " > v a l u e < \/ s t r i n g > / ) ;
311+ assert . doesNotMatch ( stdinPayload , / d e b u g _ h t t p _ h o s t / ) ;
312+ assert . doesNotMatch ( stdinPayload , / d e v _ s e r v e r _ h t t p s / ) ;
305313 } ) ;
306314} ) ;
307315
0 commit comments