@@ -145,6 +145,67 @@ test('writeReplayScript escapes device labels with quotes and backslashes', () =
145145 ) ;
146146} ) ;
147147
148+ test ( 'writeReplayScript preserves significant whitespace and empty string arguments' , ( ) => {
149+ const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'agent-device-replay-script-whitespace-' ) ) ;
150+ const replayPath = path . join ( root , 'flow.ad' ) ;
151+ const actions : SessionAction [ ] = [
152+ {
153+ ts : Date . now ( ) ,
154+ command : 'type' ,
155+ positionals : [ ' leading\ttrailing ' ] ,
156+ flags : { } ,
157+ } ,
158+ {
159+ ts : Date . now ( ) ,
160+ command : 'fill' ,
161+ positionals : [ '@e2' , '' ] ,
162+ flags : { } ,
163+ } ,
164+ {
165+ ts : Date . now ( ) ,
166+ command : 'screenshot' ,
167+ positionals : [ ' ./screens/final.png ' ] ,
168+ flags : { } ,
169+ } ,
170+ {
171+ ts : Date . now ( ) ,
172+ command : 'screenshot' ,
173+ positionals : [ 'foo\\nbar.png' ] ,
174+ flags : { } ,
175+ } ,
176+ {
177+ ts : Date . now ( ) ,
178+ command : 'open' ,
179+ positionals : [ 'Demo' ] ,
180+ runtime : {
181+ platform : 'android' ,
182+ metroHost : ' host\t' ,
183+ launchUrl : 'myapp://dev ' ,
184+ } ,
185+ flags : { } ,
186+ } ,
187+ ] ;
188+
189+ writeReplayScript ( replayPath , actions , makeSession ( ) ) ;
190+ const script = fs . readFileSync ( replayPath , 'utf8' ) ;
191+
192+ assert . match ( script , / t y p e " l e a d i n g \\ t t r a i l i n g " / ) ;
193+ assert . match ( script , / f i l l @ e 2 " " / ) ;
194+ assert . match ( script , / s c r e e n s h o t " \. \/ s c r e e n s \/ f i n a l \. p n g " / ) ;
195+ assert . match ( script , / s c r e e n s h o t " f o o \\ \\ n b a r \. p n g " / ) ;
196+ assert . match ( script , / - - m e t r o - h o s t " h o s t \\ t " - - l a u n c h - u r l " m y a p p : \/ \/ d e v " / ) ;
197+ const parsed = parseReplayScript ( script ) ;
198+ assert . deepEqual ( parsed [ 0 ] ?. positionals , [ ' leading\ttrailing ' ] ) ;
199+ assert . deepEqual ( parsed [ 1 ] ?. positionals , [ '@e2' , '' ] ) ;
200+ assert . deepEqual ( parsed [ 2 ] ?. positionals , [ ' ./screens/final.png ' ] ) ;
201+ assert . deepEqual ( parsed [ 3 ] ?. positionals , [ 'foo\\nbar.png' ] ) ;
202+ assert . deepEqual ( parsed [ 4 ] ?. runtime , {
203+ platform : 'android' ,
204+ metroHost : ' host\t' ,
205+ launchUrl : 'myapp://dev ' ,
206+ } ) ;
207+ } ) ;
208+
148209test ( 'readReplayScriptMetadata extracts platform from context header' , ( ) => {
149210 const metadata = readReplayScriptMetadata (
150211 '# comment\n\ncontext platform=android device="Pixel 9 Pro"\nopen "Demo"\n' ,
0 commit comments