@@ -522,3 +522,95 @@ function isStringArray(value: unknown): value is string[] {
522522function readStringArray ( value : unknown ) : string [ ] | undefined {
523523 return isStringArray ( value ) ? value : undefined ;
524524}
525+
526+ // A sensitive fill's literal is redacted by exact match, but a backend also reads the field back,
527+ // and the field may hold a reformatted or partly dropped form of it. The owner that knows the fill
528+ // is sensitive replaces every read-back value outright instead of matching altered forms.
529+ type ReadBackRecord = Record < string , unknown > ;
530+
531+ /** The fields `FillUnconfirmedVerification` carries as text. A null read-back reveals nothing. */
532+ const UNCONFIRMED_READ_BACK_FIELDS = [ 'requested' , 'before' , 'after' ] as const ;
533+
534+ /** The text fields of an Android fill failure's `details`, and of its two observed input nodes. */
535+ const FAILURE_READ_BACK_FIELDS = [ 'expected' , 'actual' ] as const ;
536+ const FAILURE_INPUT_NODE_FIELDS = [ 'targetInput' , 'actualInput' ] as const ;
537+
538+ /**
539+ * Replaces the text a sensitive fill's response read back from the field: the unconfirmed
540+ * evidence, and the diff lines and tail labels of a `--settle` observation. Refs, counts and
541+ * summaries stay. This runs before literal parameterization, so a short literal cannot rewrite
542+ * the `verification` discriminator this checks.
543+ */
544+ export function redactFillReadBack < TPayload extends ReadBackRecord | undefined > (
545+ payload : TPayload ,
546+ placeholder : string ,
547+ ) : TPayload {
548+ if ( ! payload ) return payload ;
549+ const unconfirmed =
550+ payload . verification === 'unconfirmed'
551+ ? placeholderFields ( payload , UNCONFIRMED_READ_BACK_FIELDS , placeholder )
552+ : { } ;
553+ return {
554+ ...payload ,
555+ ...unconfirmed ,
556+ ...( isRecord ( payload . settle )
557+ ? { settle : redactSettleReadBack ( payload . settle , placeholder ) }
558+ : { } ) ,
559+ } ;
560+ }
561+
562+ function redactSettleReadBack ( settle : ReadBackRecord , placeholder : string ) : ReadBackRecord {
563+ const { diff, tail } = settle ;
564+ return {
565+ ...settle ,
566+ ...( isRecord ( diff ) && Array . isArray ( diff . lines )
567+ ? {
568+ diff : {
569+ ...diff ,
570+ lines : diff . lines . map ( ( line ) => redactTextField ( line , 'text' , placeholder ) ) ,
571+ } ,
572+ }
573+ : { } ) ,
574+ ...( Array . isArray ( tail )
575+ ? { tail : tail . map ( ( entry ) => redactTextField ( entry , 'label' , placeholder ) ) }
576+ : { } ) ,
577+ } ;
578+ }
579+
580+ function redactTextField ( entry : unknown , field : string , placeholder : string ) : unknown {
581+ return isRecord ( entry ) ? { ...entry , ...placeholderFields ( entry , [ field ] , placeholder ) } : entry ;
582+ }
583+
584+ /** A backend fill failure is typed by `failureReason`; only that shape carries read-back text. */
585+ export function redactFillFailureReadBack ( details : unknown , placeholder : string ) : unknown {
586+ if ( ! isRecord ( details ) || typeof details . failureReason !== 'string' ) return details ;
587+ const nodes = Object . fromEntries (
588+ FAILURE_INPUT_NODE_FIELDS . flatMap ( ( field ) => {
589+ const node = details [ field ] ;
590+ return isRecord ( node )
591+ ? [ [ field , { ...node , ...placeholderFields ( node , [ 'text' ] , placeholder ) } ] ]
592+ : [ ] ;
593+ } ) ,
594+ ) ;
595+ return {
596+ ...details ,
597+ ...placeholderFields ( details , FAILURE_READ_BACK_FIELDS , placeholder ) ,
598+ ...nodes ,
599+ } ;
600+ }
601+
602+ function placeholderFields (
603+ record : ReadBackRecord ,
604+ fields : readonly string [ ] ,
605+ placeholder : string ,
606+ ) : ReadBackRecord {
607+ return Object . fromEntries (
608+ fields
609+ . filter ( ( field ) => typeof record [ field ] === 'string' )
610+ . map ( ( field ) => [ field , placeholder ] ) ,
611+ ) ;
612+ }
613+
614+ function isRecord ( value : unknown ) : value is ReadBackRecord {
615+ return typeof value === 'object' && value !== null && ! Array . isArray ( value ) ;
616+ }
0 commit comments