(params: {
req: DaemonRequest;
session: SessionState;
sessionName: string;
logPath: string;
sessionStore: SessionStore;
contextFromFlags: (
flags: CommandFlags | undefined,
appBundleId?: string,
traceLogPath?: string,
) => DaemonCommandContext;
})
| 38 | }; |
| 39 | |
| 40 | export async function dispatchGenericCommand(params: { |
| 41 | req: DaemonRequest; |
| 42 | session: SessionState; |
| 43 | sessionName: string; |
| 44 | logPath: string; |
| 45 | sessionStore: SessionStore; |
| 46 | contextFromFlags: ( |
| 47 | flags: CommandFlags | undefined, |
| 48 | appBundleId?: string, |
| 49 | traceLogPath?: string, |
| 50 | ) => DaemonCommandContext; |
| 51 | }): Promise<DaemonResponse> { |
| 52 | const { req, session, logPath, sessionStore, contextFromFlags } = params; |
| 53 | const commandResolution = resolveDispatchCommand(req); |
| 54 | if (!commandResolution.ok) { |
| 55 | return { |
| 56 | ok: false, |
| 57 | error: { |
| 58 | code: 'INVALID_ARGS', |
| 59 | message: commandResolution.message, |
| 60 | }, |
| 61 | }; |
| 62 | } |
| 63 | const { platformCommand, dispatchRequest, recordedCommand } = commandResolution; |
| 64 | |
| 65 | const readinessResponse = await ensureGenericCommandReady(session, platformCommand); |
| 66 | if (readinessResponse) return readinessResponse; |
| 67 | const preflightReadiness = await ensureNoAndroidBlockingDialogReady(session, platformCommand); |
| 68 | if ('response' in preflightReadiness) return preflightReadiness.response; |
| 69 | |
| 70 | const { resolvedPositionals, resolvedOut, recordedPositionals, recordedFlags } = |
| 71 | resolveCommandPositionals(dispatchRequest); |
| 72 | |
| 73 | const actionStartedAt = Date.now(); |
| 74 | const dispatchContext = { |
| 75 | ...contextFromFlags(req.flags, session.appBundleId, session.trace?.outPath), |
| 76 | surface: session.surface, |
| 77 | }; |
| 78 | let data = await executeGenericPlatformCommand({ |
| 79 | session, |
| 80 | sessionName: params.sessionName, |
| 81 | logPath, |
| 82 | command: platformCommand, |
| 83 | request: dispatchRequest, |
| 84 | positionals: resolvedPositionals, |
| 85 | out: resolvedOut, |
| 86 | dispatchContext, |
| 87 | }); |
| 88 | const postflightReadiness = await ensureNoAndroidBlockingDialogReady( |
| 89 | session, |
| 90 | platformCommand, |
| 91 | 'after-command', |
| 92 | ); |
| 93 | if ('response' in postflightReadiness) return postflightReadiness.response; |
| 94 | if ( |
| 95 | 'status' in preflightReadiness && |
| 96 | preflightReadiness.status === 'recovered' && |
| 97 | (!data || typeof data === 'object') |
no test coverage detected