

























1+// iOS run tests cover simulator launch orchestration without touching Xcode.
2+import { execFileSync } from "node:child_process";
3+import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4+import os from "node:os";
5+import path from "node:path";
6+import { afterEach, describe, expect, it } from "vitest";
7+8+const SCRIPT = path.join(process.cwd(), "scripts", "ios-run.sh");
9+const BASH_BIN = process.platform === "win32" ? "bash" : "/bin/bash";
10+11+const tempDirs: string[] = [];
12+13+function bashArgs(scriptPath: string): string[] {
14+return process.platform === "win32" ? [scriptPath] : ["--noprofile", "--norc", scriptPath];
15+}
16+17+function writeExecutable(filePath: string, body: string): void {
18+writeFileSync(filePath, body, "utf8");
19+chmodSync(filePath, 0o755);
20+}
21+22+function makeFixture(bundleId: string): { root: string; script: string; logFile: string } {
23+const root = mkdtempSync(path.join(os.tmpdir(), "openclaw-ios-run-"));
24+tempDirs.push(root);
25+26+const scriptsDir = path.join(root, "scripts");
27+const iosDir = path.join(root, "apps", "ios");
28+const binDir = path.join(root, "bin");
29+const logFile = path.join(root, "commands.log");
30+mkdirSync(scriptsDir, { recursive: true });
31+mkdirSync(iosDir, { recursive: true });
32+mkdirSync(binDir, { recursive: true });
33+34+const script = path.join(scriptsDir, "ios-run.sh");
35+writeFileSync(script, readFileSync(SCRIPT, "utf8"), "utf8");
36+chmodSync(script, 0o755);
37+38+writeExecutable(
39+path.join(scriptsDir, "ios-configure-signing.sh"),
40+`#!/usr/bin/env bash
41+set -euo pipefail
42+`,
43+);
44+writeExecutable(
45+path.join(scriptsDir, "ios-write-version-xcconfig.sh"),
46+`#!/usr/bin/env bash
47+set -euo pipefail
48+`,
49+);
50+writeExecutable(
51+path.join(binDir, "xcodegen"),
52+`#!/usr/bin/env bash
53+set -euo pipefail
54+printf 'xcodegen %s\\n' "$*" >>"${logFile}"
55+`,
56+);
57+writeExecutable(
58+path.join(binDir, "xcodebuild"),
59+`#!/usr/bin/env bash
60+set -euo pipefail
61+printf 'xcodebuild %s\\n' "$*" >>"${logFile}"
62+derived=""
63+configuration="Debug"
64+while [[ $# -gt 0 ]]; do
65+ case "$1" in
66+ -derivedDataPath)
67+ derived="$2"
68+ shift 2
69+ ;;
70+ -configuration)
71+ configuration="$2"
72+ shift 2
73+ ;;
74+ *)
75+ shift
76+ ;;
77+ esac
78+done
79+app_dir="$derived/Build/Products/$configuration-iphonesimulator/OpenClaw.app"
80+mkdir -p "$app_dir"
81+cat >"$app_dir/Info.plist" <<'PLIST'
82+<?xml version="1.0" encoding="UTF-8"?>
83+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
84+<plist version="1.0"><dict><key>CFBundleIdentifier</key><string>${bundleId}</string></dict></plist>
85+PLIST
86+`,
87+);
88+writeExecutable(
89+path.join(binDir, "simctl"),
90+`#!/usr/bin/env bash
91+set -euo pipefail
92+printf 'simctl %s\\n' "$*" >>"${logFile}"
93+if [[ "$1" == "boot" ]]; then
94+ if [[ "\${SIMCTL_BOOT_MODE:-}" == "booted" ]]; then
95+ echo "Unable to boot device in current state: Booted" >&2
96+ exit 1
97+ fi
98+ if [[ "\${SIMCTL_BOOT_MODE:-}" == "fail" ]]; then
99+ echo "Unable to boot device in current state: Shutdown" >&2
100+ exit 1
101+ fi
102+fi
103+`,
104+);
105+writeExecutable(
106+path.join(binDir, "plistbuddy"),
107+`#!/usr/bin/env bash
108+set -euo pipefail
109+sed -n 's:.*<key>CFBundleIdentifier</key><string>\\([^<]*\\)</string>.*:\\1:p' "$3"
110+`,
111+);
112+113+return { root, script, logFile };
114+}
115+116+function runIosRun(fixture: { root: string; script: string }, extraEnv = {}): string {
117+return execFileSync(BASH_BIN, bashArgs(fixture.script), {
118+env: {
119+ ...process.env,
120+IOS_DERIVED_DATA_DIR: path.join(fixture.root, "DerivedData"),
121+IOS_RUN_XCODEBUILD_BIN: path.join(fixture.root, "bin", "xcodebuild"),
122+IOS_RUN_XCODEGEN_BIN: path.join(fixture.root, "bin", "xcodegen"),
123+IOS_RUN_SIMCTL_BIN: path.join(fixture.root, "bin", "simctl"),
124+IOS_RUN_PLIST_BUDDY_BIN: path.join(fixture.root, "bin", "plistbuddy"),
125+ ...extraEnv,
126+},
127+encoding: "utf8",
128+stdio: ["ignore", "pipe", "pipe"],
129+});
130+}
131+132+describe("scripts/ios-run.sh", () => {
133+afterEach(() => {
134+for (const dir of tempDirs.splice(0)) {
135+rmSync(dir, { recursive: true, force: true });
136+}
137+});
138+139+it("installs and launches the configured app bundle identifier", () => {
140+const fixture = makeFixture("ai.openclawfoundation.app");
141+142+runIosRun(fixture, { SIMCTL_BOOT_MODE: "booted" });
143+144+expect(readFileSync(fixture.logFile, "utf8")).toContain(
145+"simctl launch iPhone 17 ai.openclawfoundation.app",
146+);
147+});
148+149+it("does not ignore simulator boot failures other than already booted", () => {
150+const fixture = makeFixture("ai.openclawfoundation.app");
151+152+expect(() => runIosRun(fixture, { SIMCTL_BOOT_MODE: "fail" })).toThrow();
153+expect(readFileSync(fixture.logFile, "utf8")).not.toContain("simctl launch");
154+});
155+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。