@@ -120,6 +120,50 @@ describe("runWindowsElevated spawn contract", () => {
120120 await expect ( runWindowsElevated ( "schtasks.exe" , [ "/create" ] ) ) . resolves . toBe ( 1 ) ;
121121 } ) ;
122122
123+ test ( "keeps scheduled-task elevation arguments in one Start-Process statement" , async ( ) => {
124+ let commandScript = "" ;
125+ setWindowsElevationSpawnForTests ( ( (
126+ _cmd : string ,
127+ args : ReadonlyArray < string > ,
128+ ) => {
129+ commandScript = String ( args [ args . length - 1 ] ?? "" ) ;
130+ const child = new EventEmitter ( ) as EventEmitter & {
131+ stdout : EventEmitter & { setEncoding ?: ( enc : string ) => void } ;
132+ stderr : EventEmitter & { setEncoding ?: ( enc : string ) => void } ;
133+ kill : ReturnType < typeof mock > ;
134+ } ;
135+ child . stdout = new EventEmitter ( ) ;
136+ child . stderr = new EventEmitter ( ) ;
137+ child . stdout . setEncoding = ( ) => undefined ;
138+ child . stderr . setEncoding = ( ) => undefined ;
139+ child . kill = mock ( ( ) => true ) ;
140+ queueMicrotask ( ( ) => child . emit ( "close" , 0 , null ) ) ;
141+ return child as never ;
142+ } ) as never ) ;
143+
144+ await expect ( runWindowsElevatedScheduledTaskRegistration (
145+ "opencodex-proxy" ,
146+ "<Task />" ,
147+ ) ) . resolves . toBe ( 0 ) ;
148+
149+ const startProcessIndex = commandScript . indexOf ( "Start-Process" ) ;
150+ const filePathIndex = commandScript . indexOf ( " -FilePath " ) ;
151+ const argumentListIndex = commandScript . indexOf ( " -ArgumentList " ) ;
152+ const verbIndex = commandScript . indexOf ( " -Verb RunAs " ) ;
153+ const waitIndex = commandScript . indexOf ( " -Wait" ) ;
154+ const firstTerminator = commandScript . indexOf ( ";" ) ;
155+
156+ expect ( startProcessIndex ) . toBeGreaterThanOrEqual ( 0 ) ;
157+ expect ( filePathIndex ) . toBeGreaterThan ( startProcessIndex ) ;
158+ expect ( argumentListIndex ) . toBeGreaterThan ( filePathIndex ) ;
159+ expect ( verbIndex ) . toBeGreaterThan ( argumentListIndex ) ;
160+ expect ( waitIndex ) . toBeGreaterThan ( verbIndex ) ;
161+ expect ( firstTerminator ) . toBeGreaterThan ( waitIndex ) ;
162+ expect ( commandScript . match ( / S t a r t - P r o c e s s / g) ) . toHaveLength ( 1 ) ;
163+ expect ( commandScript ) . not . toMatch ( / p o w e r s h e l l \. e x e ' ; \s + - A r g u m e n t L i s t / i) ;
164+ expect ( commandScript ) . not . toMatch ( / - A r g u m e n t L i s t \s + ' [ ^ ' ] * ' ; \s + - V e r b R u n A s / ) ;
165+ } ) ;
166+
123167 test ( "scheduled-task registration embeds immutable XML bytes instead of a file path" , async ( ) => {
124168 let commandScript = "" ;
125169 setWindowsElevationSpawnForTests ( ( (
0 commit comments