@@ -150,17 +150,101 @@ const CAPTURE_NETWORK_UNADMITTED_MESSAGE =
150150 '--capture-network is supported only for a local iOS simulator app launch; this session owner cannot inject the capture probe' ;
151151
152152/**
153- * One admission step for the launch-only open options, called by every `openApplication` entry
154- * before the lifecycle touches the device. `--launch-console` and `--capture-network` need an owner
155- * that declared it can read simctl's console PTY or inject the capture probe; every other owner —
156- * any provider, any non-iOS-simulator device — is refused with `UNSUPPORTED_OPERATION` and a typed
157- * reason before its relaunch close, runner stop, or runtime-hint write runs. This is the whole
158- * admission rule for those options (ADR 0037): the canonical open keeps only positional, URL, and
159- * argument-shape checks.
153+ * The request-shape rule for the launch-only open options: what only `positionals` and `execution`
154+ * can answer, checked once and enforced twice — by {@link assertOpenAdmitted} before the lifecycle
155+ * touches the device, and by {@link invokeApplicationOpen} for its own folded and follow-up calls.
156+ * One helper per positional shape: no app target, a URL pair, or a single deep-link app target.
157+ * `--launch-console`, `--capture-network` and `--clear-app-state` act on the app the open launches,
158+ * so they refuse every shape but a direct app target, before any close, clear, or launch runs.
159+ */
160+ function assertOpenRequestShape (
161+ positionals : readonly string [ ] ,
162+ execution : ApplicationLifecycleExecution ,
163+ ) : void {
164+ if ( positionals . length > 2 ) {
165+ throw new AppError ( 'INVALID_ARGS' , 'open accepts at most two arguments: <app|url> [url]' ) ;
166+ }
167+ const app = positionals [ 0 ] ;
168+ const url = positionals [ 1 ] ;
169+ if ( app === undefined ) {
170+ assertOpenDeviceOnlyRequest ( execution ) ;
171+ return ;
172+ }
173+ if ( url !== undefined ) {
174+ assertOpenUrlPairRequest ( app , url , execution ) ;
175+ return ;
176+ }
177+ if ( isDeepLinkTarget ( app ) ) {
178+ assertOpenDeepLinkAppRequest ( execution ) ;
179+ }
180+ }
181+
182+ function assertOpenDeviceOnlyRequest ( execution : ApplicationLifecycleExecution ) : void {
183+ if ( execution . launchConsole ) {
184+ throw new AppError ( 'INVALID_ARGS' , '--launch-console requires an app target' ) ;
185+ }
186+ if ( execution . networkCapturePath ) {
187+ throw new AppError ( 'INVALID_ARGS' , CAPTURE_NETWORK_DIRECT_APP_ONLY_MESSAGE ) ;
188+ }
189+ if ( execution . launchArgs && execution . launchArgs . length > 0 ) {
190+ throw new AppError ( 'INVALID_ARGS' , '--launch-args requires an app target' ) ;
191+ }
192+ }
193+
194+ function assertOpenUrlPairRequest (
195+ app : string ,
196+ url : string ,
197+ execution : ApplicationLifecycleExecution ,
198+ ) : void {
199+ if ( isDeepLinkTarget ( app ) ) {
200+ throw new AppError (
201+ 'INVALID_ARGS' ,
202+ 'open <app> <url> requires an app target as the first argument' ,
203+ ) ;
204+ }
205+ if ( ! isDeepLinkTarget ( url ) ) {
206+ throw new AppError ( 'INVALID_ARGS' , 'open <app> <url> requires a valid URL target' ) ;
207+ }
208+ if ( execution . launchConsole ) {
209+ throw new AppError ( 'INVALID_ARGS' , LAUNCH_CONSOLE_DIRECT_APP_ONLY_MESSAGE ) ;
210+ }
211+ if ( execution . networkCapturePath ) {
212+ throw new AppError ( 'INVALID_ARGS' , CAPTURE_NETWORK_DIRECT_APP_ONLY_MESSAGE ) ;
213+ }
214+ }
215+
216+ function assertOpenDeepLinkAppRequest ( execution : ApplicationLifecycleExecution ) : void {
217+ if ( execution . launchConsole ) {
218+ throw new AppError ( 'INVALID_ARGS' , LAUNCH_CONSOLE_DIRECT_APP_ONLY_MESSAGE ) ;
219+ }
220+ if ( execution . networkCapturePath ) {
221+ throw new AppError ( 'INVALID_ARGS' , CAPTURE_NETWORK_DIRECT_APP_ONLY_MESSAGE ) ;
222+ }
223+ if ( execution . clearAppState ) {
224+ throw new AppError (
225+ 'INVALID_ARGS' ,
226+ 'Clearing app state requires an app target, not a deep link.' ,
227+ ) ;
228+ }
229+ }
230+
231+ /**
232+ * One admission step for the open command, called by every `openApplication` entry before the
233+ * lifecycle touches the device. It enforces the owner capability and the request shape of the
234+ * launch-only options: `--launch-console` and `--capture-network` need an owner that declared it
235+ * can read simctl's console PTY or inject the capture probe, and every other owner — any provider,
236+ * any non-iOS-simulator device — is refused with `UNSUPPORTED_OPERATION` and a typed reason; the
237+ * positional and URL-pair checks in {@link assertOpenRequestShape} then refuse a launch-only option
238+ * on a request that cannot carry one, with `INVALID_ARGS`. The owner answers first because where an
239+ * option works at all is the more actionable refusal. So no refusal — of an owner that cannot honor
240+ * an option or of a malformed launch-only request — ever follows a relaunch close, a runner stop,
241+ * or a runtime-hint write (ADR 0037). The canonical open keeps the same shape rule for its own
242+ * folded and follow-up dispatches, plus the one refusal that needs the platform itself.
160243 */
161244export function assertOpenAdmitted (
162245 binding : Pick < ApplicationLifecycleInteractorBinding , 'device' | 'supportsLocalSimulatorLaunch' > ,
163246 execution : ApplicationLifecycleExecution ,
247+ positionals : readonly string [ ] ,
164248) : void {
165249 if ( execution . launchConsole && ! binding . supportsLocalSimulatorLaunch ) {
166250 throw new AppError ( 'UNSUPPORTED_OPERATION' , LAUNCH_CONSOLE_UNADMITTED_MESSAGE , {
@@ -174,6 +258,7 @@ export function assertOpenAdmitted(
174258 deviceId : binding . device . id ,
175259 } ) ;
176260 }
261+ assertOpenRequestShape ( positionals , execution ) ;
177262}
178263
179264/**
@@ -191,11 +276,11 @@ export async function invokeApplicationOpen(
191276 } > ,
192277) : Promise < ApplicationLaunchReport | void > {
193278 const { device, positionals, execution } = params ;
194- assertOpenPositionals ( positionals ) ;
279+ assertOpenRequestShape ( positionals , execution ) ;
195280 const app = positionals [ 0 ] ;
196281 const url = positionals [ 1 ] ;
197282 if ( ! app ) {
198- await invokeDeviceOpen ( params ) ;
283+ await params . interactor . openDevice ( ) ;
199284 return ;
200285 }
201286 assertOpenDeviceSupport ( device , execution ) ;
@@ -212,31 +297,12 @@ type DirectOpenParameters = Readonly<{
212297 terminateRunningApp ?: boolean ;
213298} > ;
214299
215- function assertOpenPositionals ( positionals : readonly string [ ] ) : void {
216- if ( positionals . length > 2 ) {
217- throw new AppError ( 'INVALID_ARGS' , 'open accepts at most two arguments: <app|url> [url]' ) ;
218- }
219- }
220-
221- async function invokeDeviceOpen ( params : DirectOpenParameters ) : Promise < void > {
222- if ( params . execution . launchConsole ) {
223- throw new AppError ( 'INVALID_ARGS' , '--launch-console requires an app target' ) ;
224- }
225- if ( params . execution . networkCapturePath ) {
226- throw new AppError ( 'INVALID_ARGS' , CAPTURE_NETWORK_DIRECT_APP_ONLY_MESSAGE ) ;
227- }
228- if ( params . execution . launchArgs && params . execution . launchArgs . length > 0 ) {
229- throw new AppError ( 'INVALID_ARGS' , '--launch-args requires an app target' ) ;
230- }
231- await params . interactor . openDevice ( ) ;
232- }
233-
234300function assertOpenDeviceSupport (
235301 device : DeviceInfo ,
236302 execution : ApplicationLifecycleExecution ,
237303) : void {
238- // The launch-only options were admitted by owner before this point (assertOpenAdmitted); what
239- // remains here is what only the canonical open can see: the target shape of the request .
304+ // The launch-only options were admitted by shape and by owner before this point
305+ // (assertOpenAdmitted); what remains here is the one refusal that needs the platform itself .
240306 if ( device . platform === 'linux' && execution . launchArgs && execution . launchArgs . length > 0 ) {
241307 throw new AppError ( 'UNSUPPORTED_OPERATION' , '--launch-args is not supported on Linux.' ) ;
242308 }
@@ -247,21 +313,6 @@ async function invokeApplicationUrlOpen(
247313 app : string ,
248314 url : string ,
249315) : Promise < ApplicationLaunchReport | void > {
250- if ( isDeepLinkTarget ( app ) ) {
251- throw new AppError (
252- 'INVALID_ARGS' ,
253- 'open <app> <url> requires an app target as the first argument' ,
254- ) ;
255- }
256- if ( ! isDeepLinkTarget ( url ) ) {
257- throw new AppError ( 'INVALID_ARGS' , 'open <app> <url> requires a valid URL target' ) ;
258- }
259- if ( params . execution . launchConsole ) {
260- throw new AppError ( 'INVALID_ARGS' , LAUNCH_CONSOLE_DIRECT_APP_ONLY_MESSAGE ) ;
261- }
262- if ( params . execution . networkCapturePath ) {
263- throw new AppError ( 'INVALID_ARGS' , CAPTURE_NETWORK_DIRECT_APP_ONLY_MESSAGE ) ;
264- }
265316 return await params . interactor . open ( app , {
266317 activity : params . execution . activity ,
267318 appBundleId : params . appBundleId ,
@@ -276,16 +327,7 @@ async function invokeApplicationTargetOpen(
276327 app : string ,
277328) : Promise < ApplicationLaunchReport | void > {
278329 const { execution, interactor } = params ;
279- if ( execution . launchConsole && isDeepLinkTarget ( app ) ) {
280- throw new AppError ( 'INVALID_ARGS' , LAUNCH_CONSOLE_DIRECT_APP_ONLY_MESSAGE ) ;
281- }
282330 if ( execution . clearAppState ) {
283- if ( isDeepLinkTarget ( app ) ) {
284- throw new AppError (
285- 'INVALID_ARGS' ,
286- 'Clearing app state requires an app target, not a deep link.' ,
287- ) ;
288- }
289331 await interactor . setSetting ( 'clear-app-state' , 'clear' , app ) ;
290332 }
291333 return await interactor . open ( app , {
@@ -355,7 +397,7 @@ async function openDirectApplication(
355397 input : OpenApplicationInput ,
356398) : Promise < OpenApplicationOutcome > {
357399 const { binding } = params ;
358- assertOpenAdmitted ( binding , input . execution ) ;
400+ assertOpenAdmitted ( binding , input . execution , input . positionals ) ;
359401 const interactor = await binding . resolveInteractor ( input . execution , input . appBundleId ) ;
360402 if ( params . closeBeforeRelaunch && input . relaunch && input . target !== undefined ) {
361403 await invokeApplicationClose ( {
0 commit comments