@@ -321,7 +321,7 @@ test('a whitespace-only --text-stdin value collapses the error text it appears i
321321const FILL_TARGET = {
322322 resourceId : 'otp' ,
323323 className : 'android.widget.EditText' ,
324- packageName : 'com.example ' ,
324+ packageName : 'com.test ' ,
325325 rect : { x : 0 , y : 0 , width : 100 , height : 40 } ,
326326} ;
327327
@@ -379,30 +379,100 @@ test('an unrecorded fill that settles on a formatted value still returns its rea
379379 if ( result . ok ) expect ( result . data ) . toMatchObject ( { after : '00 062 91 77' } ) ;
380380} ) ;
381381
382- test ( 'a --text-stdin fill failure that reports an altered read-back returns no part of it' , async ( ) => {
383- const { response } = fillWithStdinText (
384- makeSession ( 'web' , { device : WEB_DESKTOP_DEVICE } ) ,
385- { } ,
386- ( text ) =>
382+ const ALTERED_READ_BACK_FAILURE = ( text : string ) =>
383+ new AppError ( 'COMMAND_FAILED' , 'Android fill verification failed' , {
384+ failureReason : 'text_mismatch' ,
385+ expected : text ,
386+ actual : '00 062 91 77' ,
387+ targetInput : { text : '000 62' , className : 'android.widget.EditText' } ,
388+ actualInput : { text : '00 062 91 77' , className : 'android.widget.EditText' } ,
389+ } ) ;
390+
391+ test . each ( [
392+ [ 'an unrecorded' , { } , '[REDACTED]' , makeSession ] ,
393+ [ 'a --record-as' , { recordAs : 'CODE' } , '${CODE}' , makeAuthoringSession ] ,
394+ ] ) (
395+ '%s --text-stdin fill failure that reports an altered read-back returns no part of it' ,
396+ async ( _name , flags , placeholder , sessionFor ) => {
397+ const { response } = fillWithStdinText (
398+ sessionFor ( 'web' , { device : WEB_DESKTOP_DEVICE } ) ,
399+ flags ,
400+ ALTERED_READ_BACK_FAILURE ,
401+ '000629177' ,
402+ ) ;
403+
404+ const result = await response ;
405+ expect ( result . ok ) . toBe ( false ) ;
406+ if ( result . ok ) return ;
407+ expect ( result . error . details ) . toMatchObject ( {
408+ failureReason : 'text_mismatch' ,
409+ expected : placeholder ,
410+ actual : placeholder ,
411+ targetInput : { text : placeholder , className : 'android.widget.EditText' } ,
412+ actualInput : { text : placeholder , className : 'android.widget.EditText' } ,
413+ } ) ;
414+ expect ( JSON . stringify ( result ) ) . not . toContain ( '062 91' ) ;
415+ } ,
416+ ) ;
417+
418+ test ( 'an empty --record-as fill that fails to clear returns no part of the residual field text' , async ( ) => {
419+ const { response } = sendToWebSession (
420+ makeAuthoringSession ( 'web' , { device : WEB_DESKTOP_DEVICE } ) ,
421+ { command : 'fill' , positionals : [ '10' , '20' , '' ] , flags : { recordAs : 'CODE' } } ,
422+ ( ) =>
387423 new AppError ( 'COMMAND_FAILED' , 'Android fill verification failed' , {
388424 failureReason : 'text_mismatch' ,
389- expected : text ,
390- actual : '00 062 91 77 ' ,
391- targetInput : { text : '000 62 ' , className : 'android.widget.EditText' } ,
392- actualInput : { text : '00 062 91 77 ' , className : 'android.widget.EditText' } ,
425+ expected : '' ,
426+ actual : 'residual-4471 ' ,
427+ targetInput : { text : 'residual-4471 ' , className : 'android.widget.EditText' } ,
428+ actualInput : { text : 'residual-4471 ' , className : 'android.widget.EditText' } ,
393429 } ) ,
394- '000629177' ,
395430 ) ;
396431
397432 const result = await response ;
398433 expect ( result . ok ) . toBe ( false ) ;
399434 if ( result . ok ) return ;
400435 expect ( result . error . details ) . toMatchObject ( {
401- failureReason : 'text_mismatch' ,
402- expected : '[REDACTED]' ,
403- actual : '[REDACTED]' ,
404- targetInput : { text : '[REDACTED]' , className : 'android.widget.EditText' } ,
405- actualInput : { text : '[REDACTED]' , className : 'android.widget.EditText' } ,
436+ actual : '${CODE}' ,
437+ targetInput : { text : '${CODE}' } ,
438+ actualInput : { text : '${CODE}' } ,
406439 } ) ;
407- expect ( JSON . stringify ( result ) ) . not . toContain ( '062 91 ' ) ;
440+ expect ( JSON . stringify ( result ) ) . not . toContain ( 'residual-4471 ' ) ;
408441} ) ;
442+
443+ test . each ( [
444+ [ 'a one-letter value' , 'a' ] ,
445+ [ 'a value that is the verification discriminator' , 'unconfirmed' ] ,
446+ [ 'a value that is a response key' , 'target' ] ,
447+ ] ) (
448+ 'a --record-as fill of %s keeps the unconfirmed structure and redacts its read-back' ,
449+ async ( _name , text ) => {
450+ const { response, sessionStore } = fillWithStdinText (
451+ makeAuthoringSession ( 'web' , { device : WEB_DESKTOP_DEVICE } ) ,
452+ { recordAs : 'CODE' } ,
453+ undefined ,
454+ text ,
455+ {
456+ verification : 'unconfirmed' ,
457+ requested : text ,
458+ before : 'zq7' ,
459+ after : 'Q7z' ,
460+ target : FILL_TARGET ,
461+ } ,
462+ ) ;
463+
464+ const result = await response ;
465+ expect ( result . ok ) . toBe ( true ) ;
466+ if ( ! result . ok ) return ;
467+ const unconfirmed = {
468+ verification : 'unconfirmed' ,
469+ requested : '${CODE}' ,
470+ before : '${CODE}' ,
471+ after : '${CODE}' ,
472+ target : FILL_TARGET ,
473+ } ;
474+ expect ( result . data ) . toMatchObject ( unconfirmed ) ;
475+ expect ( sessionStore . get ( 'web' ) ?. actions [ 0 ] ?. result ) . toMatchObject ( unconfirmed ) ;
476+ expect ( JSON . stringify ( sessionStore . get ( 'web' ) ?. actions ) ) . not . toMatch ( / z q 7 | Q 7 z / ) ;
477+ } ,
478+ ) ;
0 commit comments