(
run: (ctx: {
device: DeviceInfo;
argsLogPath: string;
readFilePath: string;
stdinFilePath: string;
}) => Promise<void>,
)
| 12 | import type { DeviceInfo } from '../../kernel/device.ts'; |
| 13 | |
| 14 | async function withMockedAdb( |
| 15 | run: (ctx: { |
| 16 | device: DeviceInfo; |
| 17 | argsLogPath: string; |
| 18 | readFilePath: string; |
| 19 | stdinFilePath: string; |
| 20 | }) => Promise<void>, |
| 21 | ): Promise<void> { |
| 22 | const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'agent-device-runtime-hints-android-')); |
| 23 | const adbPath = path.join(tmpDir, 'adb'); |
| 24 | const argsLogPath = path.join(tmpDir, 'args.log'); |
| 25 | const readFilePath = path.join(tmpDir, 'existing.xml'); |
| 26 | const stdinFilePath = path.join(tmpDir, 'write-stdin.xml'); |
| 27 | await fs.writeFile( |
| 28 | adbPath, |
| 29 | [ |
| 30 | '#!/bin/sh', |
| 31 | 'if [ "$1" = "-s" ]; then', |
| 32 | ' shift', |
| 33 | ' shift', |
| 34 | 'fi', |
| 35 | 'printf "%s\\n" "$*" >> "$AGENT_DEVICE_TEST_ARGS_FILE"', |
| 36 | 'if [ "$1" = "shell" ] && [ "$2" = "run-as" ] && [ "$4" = "cat" ]; then', |
| 37 | ' if [ -f "$AGENT_DEVICE_TEST_READ_FILE" ]; then', |
| 38 | ' cat "$AGENT_DEVICE_TEST_READ_FILE"', |
| 39 | ' exit 0', |
| 40 | ' fi', |
| 41 | ' exit 1', |
| 42 | 'fi', |
| 43 | 'if [ "$1" = "shell" ] && [ "$2" = "run-as" ] && [ "$4" = "id" ]; then', |
| 44 | ' if [ -n "$AGENT_DEVICE_TEST_RUN_AS_ID_STDOUT" ]; then', |
| 45 | ' printf "%s" "$AGENT_DEVICE_TEST_RUN_AS_ID_STDOUT"', |
| 46 | ' else', |
| 47 | ' printf "%s\\n" "uid=10162(u0_a162) gid=10162(u0_a162) groups=10162(u0_a162)"', |
| 48 | ' fi', |
| 49 | ' if [ -n "$AGENT_DEVICE_TEST_RUN_AS_ID_STDERR" ]; then', |
| 50 | ' printf "%s" "$AGENT_DEVICE_TEST_RUN_AS_ID_STDERR" >&2', |
| 51 | ' fi', |
| 52 | ' exit "${AGENT_DEVICE_TEST_RUN_AS_ID_EXIT_CODE:-0}"', |
| 53 | 'fi', |
| 54 | 'if [ "$1" = "shell" ] && [ "$2" = "run-as" ] && [ "$4" = "mkdir" ] && [ "$5" = "-p" ] && [ "$6" = "shared_prefs" ]; then', |
| 55 | ' if [ -n "$AGENT_DEVICE_TEST_RUN_AS_MKDIR_STDOUT" ]; then', |
| 56 | ' printf "%s" "$AGENT_DEVICE_TEST_RUN_AS_MKDIR_STDOUT"', |
| 57 | ' fi', |
| 58 | ' if [ -n "$AGENT_DEVICE_TEST_RUN_AS_MKDIR_STDERR" ]; then', |
| 59 | ' printf "%s" "$AGENT_DEVICE_TEST_RUN_AS_MKDIR_STDERR" >&2', |
| 60 | ' fi', |
| 61 | ' exit "${AGENT_DEVICE_TEST_RUN_AS_MKDIR_EXIT_CODE:-0}"', |
| 62 | 'fi', |
| 63 | 'if [ "$1" = "shell" ] && [ "$2" = "run-as" ] && [ "$4" = "tee" ] && [ "$5" = "shared_prefs/ReactNativeDevPrefs.xml" ]; then', |
| 64 | ' cat > "$AGENT_DEVICE_TEST_STDIN_FILE"', |
| 65 | ' if [ -n "$AGENT_DEVICE_TEST_RUN_AS_WRITE_STDOUT" ]; then', |
| 66 | ' printf "%s" "$AGENT_DEVICE_TEST_RUN_AS_WRITE_STDOUT"', |
| 67 | ' fi', |
| 68 | ' if [ -n "$AGENT_DEVICE_TEST_RUN_AS_WRITE_STDERR" ]; then', |
| 69 | ' printf "%s" "$AGENT_DEVICE_TEST_RUN_AS_WRITE_STDERR" >&2', |
| 70 | ' fi', |
| 71 | ' if [ -n "$AGENT_DEVICE_TEST_RUN_AS_WRITE_EXIT_CODE" ] && [ "$AGENT_DEVICE_TEST_RUN_AS_WRITE_EXIT_CODE" != "0" ]; then', |
no test coverage detected