(
run: (ctx: { device: DeviceInfo; argsLogPath: string }) => Promise<void>,
)
| 128 | } |
| 129 | |
| 130 | async function withMockedXcrun( |
| 131 | run: (ctx: { device: DeviceInfo; argsLogPath: string }) => Promise<void>, |
| 132 | ): Promise<void> { |
| 133 | const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'agent-device-runtime-hints-ios-')); |
| 134 | const xcrunPath = path.join(tmpDir, 'xcrun'); |
| 135 | const argsLogPath = path.join(tmpDir, 'args.log'); |
| 136 | await fs.writeFile( |
| 137 | xcrunPath, |
| 138 | ['#!/bin/sh', 'printf "%s\\n" "$*" >> "$AGENT_DEVICE_TEST_ARGS_FILE"', 'exit 0', ''].join('\n'), |
| 139 | 'utf8', |
| 140 | ); |
| 141 | await fs.chmod(xcrunPath, 0o755); |
| 142 | |
| 143 | const previousPath = process.env.PATH; |
| 144 | const previousArgsFile = process.env.AGENT_DEVICE_TEST_ARGS_FILE; |
| 145 | process.env.PATH = `${tmpDir}${path.delimiter}${previousPath ?? ''}`; |
| 146 | process.env.AGENT_DEVICE_TEST_ARGS_FILE = argsLogPath; |
| 147 | |
| 148 | const device: DeviceInfo = { |
| 149 | platform: 'apple', |
| 150 | id: 'sim-1', |
| 151 | name: 'iPhone 17 Pro', |
| 152 | kind: 'simulator', |
| 153 | booted: true, |
| 154 | }; |
| 155 | |
| 156 | try { |
| 157 | await run({ device, argsLogPath }); |
| 158 | } finally { |
| 159 | process.env.PATH = previousPath; |
| 160 | restoreEnv('AGENT_DEVICE_TEST_ARGS_FILE', previousArgsFile); |
| 161 | await fs.rm(tmpDir, { recursive: true, force: true }); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | function restoreEnv(key: string, value: string | undefined): void { |
| 166 | if (value === undefined) { |
no test coverage detected