1- import { expect , test } from 'vitest' ;
1+ import { beforeEach , expect , test , vi } from 'vitest' ;
22import { makeIosSession } from '../../../__tests__/test-utils/session-factories.ts' ;
33import { makeSessionStore } from '../../../__tests__/test-utils/store-factory.ts' ;
4+ import { attachRefs , type RawSnapshotNode } from '../../../kernel/snapshot.ts' ;
5+ import type { CommandFlags } from '../../../core/dispatch.ts' ;
6+ import { handleInteractionCommands } from '../interaction.ts' ;
47import { finalizeTouchInteraction } from '../interaction-common.ts' ;
58
9+ vi . mock ( '../../../core/dispatch.ts' , async ( importOriginal ) => {
10+ const actual = await importOriginal < typeof import ( '../../../core/dispatch.ts' ) > ( ) ;
11+ return {
12+ ...actual ,
13+ dispatchCommand : vi . fn ( async ( ) => ( { } ) ) ,
14+ } ;
15+ } ) ;
16+
17+ import { dispatchCommand } from '../../../core/dispatch.ts' ;
18+ const mockDispatch = vi . mocked ( dispatchCommand ) ;
19+ const contextFromFlags = ( _flags : CommandFlags | undefined ) => ( { } ) ;
20+
21+ beforeEach ( ( ) => {
22+ mockDispatch . mockReset ( ) ;
23+ mockDispatch . mockResolvedValue ( { } ) ;
24+ } ) ;
25+
626test ( 'parameterized fill scrubs backend and nested settle echoes at the response boundary' , ( ) => {
727 const secret = 'OpaqueValue1348' ;
828 const placeholder = '${PASSWORD}' ;
@@ -12,13 +32,22 @@ test('parameterized fill scrubs backend and nested settle echoes at the response
1232 sessionStore . set ( session . name , session ) ;
1333 const payload = {
1434 text : secret ,
15- message : `Backend filled ${ secret } ` ,
35+ message : `prefix${ secret } suffix` ,
36+ refLabel : `prefix${ secret } suffix` ,
1637 selector : 'id="password"' ,
17- selectorChain : [ 'id="password"' , `value="${ secret } " editable=true` ] ,
38+ selectorChain : [
39+ 'id="password"' ,
40+ `value="prefix${ secret } suffix" editable=true` ,
41+ `label="${ secret } 4"` ,
42+ ] ,
1843 backendEcho : {
1944 id : secret ,
20- status : `accepted ${ secret } ` ,
45+ status : `accepted${ secret } suffix ` ,
2146 nested : { kind : secret } ,
47+ [ secret ] : true ,
48+ [ `prefix${ secret } suffix` ] : {
49+ [ `${ secret } 4` ] : true ,
50+ } ,
2251 } ,
2352 settle : {
2453 settled : true ,
@@ -28,9 +57,14 @@ test('parameterized fill scrubs backend and nested settle echoes at the response
2857 timeoutMs : 100 ,
2958 diff : {
3059 summary : { additions : 1 , removals : 0 , unchanged : 0 } ,
31- lines : [ { kind : 'added' , text : `TextField value=${ secret } ` } ] ,
60+ lines : [ { kind : 'added' , text : `TextField value=prefix${ secret } suffix` } ] ,
61+ } ,
62+ hint : `Observed ${ secret } 4` ,
63+ [ `echo${ secret } key` ] : true ,
64+ backendEcho : {
65+ id : secret ,
66+ [ `key${ secret } ` ] : `value${ secret } ` ,
3267 } ,
33- hint : `Observed ${ secret } ` ,
3468 } ,
3569 } ;
3670
@@ -50,19 +84,29 @@ test('parameterized fill scrubs backend and nested settle echoes at the response
5084 if ( ! response . ok ) return ;
5185 expect ( response . data ) . toMatchObject ( {
5286 text : placeholder ,
53- message : `Backend filled ${ placeholder } ` ,
87+ message : `prefix${ placeholder } suffix` ,
88+ refLabel : `prefix${ placeholder } suffix` ,
5489 selector : 'id="password"' ,
5590 selectorChain : [ 'id="password"' ] ,
5691 backendEcho : {
5792 id : placeholder ,
58- status : `accepted ${ placeholder } ` ,
93+ status : `accepted${ placeholder } suffix ` ,
5994 nested : { kind : placeholder } ,
95+ [ placeholder ] : true ,
96+ [ `prefix${ placeholder } suffix` ] : {
97+ [ `${ placeholder } 4` ] : true ,
98+ } ,
6099 } ,
61100 settle : {
62101 diff : {
63- lines : [ { kind : 'added' , text : `TextField value=${ placeholder } ` } ] ,
102+ lines : [ { kind : 'added' , text : `TextField value=prefix${ placeholder } suffix` } ] ,
103+ } ,
104+ hint : `Observed ${ placeholder } 4` ,
105+ [ `echo${ placeholder } key` ] : true ,
106+ backendEcho : {
107+ id : placeholder ,
108+ [ `key${ placeholder } ` ] : `value${ placeholder } ` ,
64109 } ,
65- hint : `Observed ${ placeholder } ` ,
66110 } ,
67111 } ) ;
68112 expect ( JSON . stringify ( response . data ) ) . not . toContain ( secret ) ;
@@ -71,3 +115,67 @@ test('parameterized fill scrubs backend and nested settle echoes at the response
71115 expect ( recordedResult ) . toEqual ( response . data ) ;
72116 expect ( JSON . stringify ( recordedResult ) ) . not . toContain ( secret ) ;
73117} ) ;
118+
119+ test ( 'parameterized fill scrubs concatenated backend values and object keys through the handler route' , async ( ) => {
120+ const secret = 'TOKEN123' ;
121+ const placeholder = '${PASSWORD}' ;
122+ const sessionStore = makeSessionStore ( ) ;
123+ const sessionName = 'parameterized-fill-handler-route' ;
124+ const session = makeIosSession ( sessionName , { appBundleId : 'com.example.app' } ) ;
125+ const nodes : RawSnapshotNode [ ] = [
126+ {
127+ index : 0 ,
128+ type : 'XCUIElementTypeTextField' ,
129+ identifier : 'password' ,
130+ label : 'Password' ,
131+ rect : { x : 20 , y : 40 , width : 200 , height : 44 } ,
132+ enabled : true ,
133+ hittable : true ,
134+ } ,
135+ ] ;
136+ session . recordSession = true ;
137+ session . snapshot = {
138+ nodes : attachRefs ( nodes ) ,
139+ createdAt : Date . now ( ) ,
140+ backend : 'xctest' ,
141+ } ;
142+ sessionStore . set ( sessionName , session ) ;
143+ mockDispatch . mockImplementation ( async ( _device , command ) =>
144+ command === 'fill'
145+ ? {
146+ message : `prefix${ secret } suffix` ,
147+ [ `prefix${ secret } suffix` ] : {
148+ [ `${ secret } 4` ] : `echo${ secret } ` ,
149+ } ,
150+ }
151+ : { } ,
152+ ) ;
153+
154+ const response = await handleInteractionCommands ( {
155+ req : {
156+ token : 't' ,
157+ session : sessionName ,
158+ command : 'fill' ,
159+ positionals : [ '@e1' , secret ] ,
160+ flags : { recordAs : 'PASSWORD' } ,
161+ } ,
162+ sessionName,
163+ sessionStore,
164+ contextFromFlags,
165+ } ) ;
166+
167+ expect ( response , JSON . stringify ( response ) ) . toMatchObject ( { ok : true } ) ;
168+ if ( ! response ?. ok ) return ;
169+ expect ( response . data ) . toMatchObject ( {
170+ message : 'Filled 8 chars' ,
171+ [ `prefix${ placeholder } suffix` ] : {
172+ [ `${ placeholder } 4` ] : `echo${ placeholder } ` ,
173+ } ,
174+ ref : 'e1' ,
175+ text : placeholder ,
176+ } ) ;
177+ expect ( JSON . stringify ( response . data ) ) . not . toContain ( secret ) ;
178+ expect ( JSON . stringify ( session . actions ) ) . not . toContain ( secret ) ;
179+ expect ( mockDispatch . mock . calls [ 0 ] ?. [ 1 ] ) . toBe ( 'fill' ) ;
180+ expect ( mockDispatch . mock . calls [ 0 ] ?. [ 2 ] ) . toContain ( secret ) ;
181+ } ) ;
0 commit comments