( executor: CommandExecutor, )
| 46 | type StopAppSimResult = StopResultDomainResult; |
| 47 | |
| 48 | export function createStopAppSimExecutor( |
| 49 | executor: CommandExecutor, |
| 50 | ): NonStreamingExecutor<ResolvedStopAppSimParams, StopAppSimResult> { |
| 51 | return async (params) => { |
| 52 | const simulatorId = params.simulatorId; |
| 53 | const artifacts = { simulatorId, bundleId: params.bundleId }; |
| 54 | |
| 55 | try { |
| 56 | const terminateResult = await executor( |
| 57 | ['xcrun', 'simctl', 'terminate', simulatorId, params.bundleId], |
| 58 | 'Stop App in Simulator', |
| 59 | false, |
| 60 | ); |
| 61 | const cleanupResult = await stopSimulatorLaunchOsLogSessionsForApp( |
| 62 | simulatorId, |
| 63 | params.bundleId, |
| 64 | 1000, |
| 65 | ); |
| 66 | |
| 67 | const diagnosticMessages: string[] = []; |
| 68 | if (!terminateResult.success) { |
| 69 | diagnosticMessages.push(terminateResult.error ?? 'Unknown simulator terminate error'); |
| 70 | } |
| 71 | if (cleanupResult.errorCount > 0) { |
| 72 | diagnosticMessages.push(`OSLog cleanup failed: ${cleanupResult.errors.join('; ')}`); |
| 73 | } |
| 74 | |
| 75 | if (diagnosticMessages.length > 0) { |
| 76 | return buildStopFailure( |
| 77 | artifacts, |
| 78 | `Stop app in simulator operation failed: ${diagnosticMessages.join(' | ')}`, |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | return buildStopSuccess(artifacts); |
| 83 | } catch (error) { |
| 84 | const diagnosticMessage = toErrorMessage(error); |
| 85 | return buildStopFailure( |
| 86 | artifacts, |
| 87 | `Stop app in simulator operation failed: ${diagnosticMessage}`, |
| 88 | ); |
| 89 | } |
| 90 | }; |
| 91 | } |
| 92 | |
| 93 | export async function stop_app_simLogic( |
| 94 | params: StopAppSimParams, |
no test coverage detected