@@ -9,7 +9,10 @@ import { buildRequestFinishedEvent } from '@agent-device/session-journal/session
99import { HEAL_COMPLETE_SENTINEL } from '../session-script-writer.ts' ;
1010import { parseReplayScriptDetailed } from '@agent-device/ad-script' ;
1111import type { TargetAnnotationV1 } from '@agent-device/contracts/replay' ;
12- import { repairPublication } from '../../__tests__/test-utils/session-factories.ts' ;
12+ import {
13+ makeMacOsSession ,
14+ repairPublication ,
15+ } from '../../__tests__/test-utils/session-factories.ts' ;
1316
1417import { mkdtempForTestSync } from '../../__tests__/test-utils/tmp-dir.ts' ;
1518
@@ -187,6 +190,36 @@ test('recordAction writes a paged session event log', async () => {
187190 assert . equal ( secondPage . nextCursor , undefined ) ;
188191} ) ;
189192
193+ test . each ( [ 'app' , 'frontmost-app' , 'desktop' , 'menubar' , undefined ] as const ) (
194+ 'recordAction preserves an explicit macOS surface %s in events and saved open scripts' ,
195+ async ( surface ) => {
196+ const fixture = makeFixture ( 'agent-device-session-macos-surface-' ) ;
197+ fixture . session = makeMacOsSession ( 'default' ) ;
198+ recordOpen ( fixture . store , fixture . session , {
199+ platform : 'macos' ,
200+ saveScript : true ,
201+ ...( surface === undefined ? { } : { surface } ) ,
202+ } ) ;
203+ await fixture . store . flushEvents ( fixture . session . name ) ;
204+
205+ const event = fixture . store . readEvents ( fixture . session . name ) . events [ 0 ] ;
206+ assert . equal ( event ?. kind , 'action.recorded' ) ;
207+ assert . deepEqual ( event ?. details ?. flags , {
208+ platform : 'macos' ,
209+ ...( surface === undefined ? { } : { surface } ) ,
210+ } ) ;
211+
212+ recordClose ( fixture . store , fixture . session ) ;
213+ const script = writeScript ( fixture ) ;
214+ const open = parseReplayScriptDetailed ( script ) . actions . find (
215+ ( action ) => action . command === 'open' ,
216+ ) ;
217+ assert . equal ( open ?. flags . surface , surface ) ;
218+ assert . deepEqual ( open ?. positionals , [ 'Settings' ] ) ;
219+ assert . equal ( script . includes ( '--surface' ) , surface !== undefined ) ;
220+ } ,
221+ ) ;
222+
190223test ( 'recordAction event log redacts typed text and its length from display positionals' , async ( ) => {
191224 const { store, session } = makeFixture ( 'agent-device-session-events-redaction-' ) ;
192225 store . recordAction ( storeSessionForTest ( store , session ) , {
0 commit comments