(options: {
command: string;
flags: CliFlags;
client: AgentDeviceClient;
state: RemoteConnectionState;
nextState: RemoteConnectionState;
runtime?: SessionRuntimeHints;
positionals?: string[];
batchSteps?: BatchStep[];
forceRuntimePrepare?: boolean;
})
| 164 | } |
| 165 | |
| 166 | async function prepareRuntimeForCommand(options: { |
| 167 | command: string; |
| 168 | flags: CliFlags; |
| 169 | client: AgentDeviceClient; |
| 170 | state: RemoteConnectionState; |
| 171 | nextState: RemoteConnectionState; |
| 172 | runtime?: SessionRuntimeHints; |
| 173 | positionals?: string[]; |
| 174 | batchSteps?: BatchStep[]; |
| 175 | forceRuntimePrepare?: boolean; |
| 176 | }): Promise<{ |
| 177 | state: RemoteConnectionState; |
| 178 | runtime?: SessionRuntimeHints; |
| 179 | changed: boolean; |
| 180 | metroCleanupToStop?: RemoteConnectionState['metro']; |
| 181 | preparedMetroCleanupOnFailure?: RemoteConnectionState['metro']; |
| 182 | }> { |
| 183 | const { command, flags, state, client } = options; |
| 184 | let nextState = ensureRuntimeLeaseState(options.nextState, flags); |
| 185 | const nextRuntime = options.runtime; |
| 186 | if ( |
| 187 | !shouldPrepareRuntimeForCommand(command, flags, options.batchSteps, options.positionals) || |
| 188 | !hasDeferredMetroConfig(flags) || |
| 189 | !shouldPrepareRuntime(options.forceRuntimePrepare, nextRuntime, flags.platform) |
| 190 | ) { |
| 191 | return { state: nextState, runtime: nextRuntime, changed: false }; |
| 192 | } |
| 193 | if (!nextState.leaseId) { |
| 194 | throw new AppError( |
| 195 | 'INVALID_ARGS', |
| 196 | `${command} requires a resolved remote lease before Metro runtime can be prepared.`, |
| 197 | ); |
| 198 | } |
| 199 | const prepared = await prepareConnectedMetro( |
| 200 | flags, |
| 201 | client, |
| 202 | state.remoteConfigPath, |
| 203 | state.session, |
| 204 | { |
| 205 | tenantId: state.tenant, |
| 206 | runId: state.runId, |
| 207 | leaseId: nextState.leaseId, |
| 208 | }, |
| 209 | ); |
| 210 | const replacesExistingMetroCleanup = !isSameMetroCleanup(nextState.metro, prepared.cleanup); |
| 211 | nextState = { |
| 212 | ...nextState, |
| 213 | runtime: prepared.runtime, |
| 214 | metro: prepared.cleanup, |
| 215 | updatedAt: new Date().toISOString(), |
| 216 | }; |
| 217 | return { |
| 218 | state: nextState, |
| 219 | runtime: prepared.runtime, |
| 220 | changed: true, |
| 221 | metroCleanupToStop: replacesExistingMetroCleanup ? options.nextState.metro : undefined, |
| 222 | preparedMetroCleanupOnFailure: replacesExistingMetroCleanup ? prepared.cleanup : undefined, |
| 223 | }; |
no test coverage detected