From 4d97f30f3abdf523dd59ea9d8bcf272bd930277e Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Fri, 19 Jun 2026 20:42:36 -0700 Subject: [PATCH 01/22] Add Blacksmith iOS video recording mode --- .github/workflows/reload-build.yml | 186 +++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) diff --git a/.github/workflows/reload-build.yml b/.github/workflows/reload-build.yml index 5414474e3eab..c18728c64268 100644 --- a/.github/workflows/reload-build.yml +++ b/.github/workflows/reload-build.yml @@ -29,6 +29,20 @@ on: options: - macos - ios + - ios-video + test_filter: + description: iOS UI test class or class/method used to drive ios-video + required: false + default: "cmuxUITests/cmuxUITests/testStackAuthEntryUsesStableIdentifiers" + type: string + device_family: + description: Simulator family used by ios-video + required: false + default: iphone + type: choice + options: + - iphone + - ipad runner: description: >- macOS runner label to build on. Blacksmith (blacksmith-6vcpu-macos-26), @@ -160,6 +174,177 @@ jobs: mkdir -p artifact ( cd "$out" && ditto -c -k --keepParent "$(basename "$archive")" "$GITHUB_WORKSPACE/artifact/archive.zip" ) + # --- iOS video: run a real simulator UI test while recording the screen --- + - name: Record iOS simulator video + if: ${{ inputs.platform == 'ios-video' }} + env: + BUILD_TAG: ${{ inputs.tag }} + DEVICE_FAMILY: ${{ inputs.device_family }} + TEST_FILTER: ${{ inputs.test_filter }} + run: | + set -euo pipefail + + ios_ready() { xcrun simctl runtime list 2>/dev/null | grep -qiE "iOS [0-9].*\(Ready\)"; } + if ! ios_ready; then + echo "iOS platform not registered; installing via downloadPlatform iOS" + xcodebuild -downloadPlatform iOS 2>&1 | tr '\r' '\n' | grep -ivE 'Preparing to download|registering download' | tail -8 || true + ios_ready || { echo "iOS platform still not registered; simulator video would fail" >&2; exit 1; } + fi + + ./scripts/ensure-ghosttykit.sh + + SIMULATOR_ENV="${RUNNER_TEMP:-$PWD/.tmp}/simulator-${DEVICE_FAMILY}.env" + mkdir -p "$(dirname "$SIMULATOR_ENV")" + python3 - <<'PY' > "$SIMULATOR_ENV" + import json + import os + import shlex + import subprocess + import sys + + family = os.environ["DEVICE_FAMILY"] + data = json.loads(subprocess.check_output(["xcrun", "simctl", "list", "devices", "available", "-j"])) + devices = [ + device + for runtimes in data.get("devices", {}).values() + for device in runtimes + if device.get("isAvailable", True) + ] + prefix = "iPad" if family == "ipad" else "iPhone" + preferred = ["iPad Pro 13-inch (M4)", "iPad Air 13-inch (M3)"] if family == "ipad" else ["iPhone 17", "iPhone 16"] + selected = next((d for name in preferred for d in devices if d.get("name") == name), None) + selected = selected or next((d for d in devices if d.get("name", "").startswith(prefix)), None) + if selected is None: + runtimes_data = json.loads(subprocess.check_output(["xcrun", "simctl", "list", "runtimes", "available", "-j"])) + runtimes = [ + runtime + for runtime in runtimes_data.get("runtimes", []) + if runtime.get("isAvailable", True) + and ( + runtime.get("platform") == "iOS" + or runtime.get("identifier", "").startswith("com.apple.CoreSimulator.SimRuntime.iOS") + ) + ] + if not runtimes: + raise SystemExit(f"No available iOS simulator runtime for {family}") + + def version_key(runtime): + return tuple(int(part) for part in runtime.get("version", "0").split(".") if part.isdigit()) + + runtime = sorted(runtimes, key=version_key, reverse=True)[0] + device_types_data = json.loads(subprocess.check_output(["xcrun", "simctl", "list", "devicetypes", "-j"])) + device_types = [ + device_type + for device_type in device_types_data.get("devicetypes", []) + if device_type.get("name", "").startswith(prefix) + ] + device_type = next((d for name in preferred for d in device_types if d.get("name") == name), None) + device_type = device_type or next(iter(device_types), None) + if device_type is None: + raise SystemExit(f"No available {prefix} simulator device type") + udid = subprocess.check_output([ + "xcrun", + "simctl", + "create", + f"cmux Video {device_type['name']}", + device_type["identifier"], + runtime["identifier"], + ], text=True).strip() + selected = {"udid": udid, "name": f"cmux Video {device_type['name']}"} + print( + f"Created {selected['name']} ({udid}) with {runtime['identifier']}", + file=sys.stderr, + ) + print(f"SIMULATOR_ID={shlex.quote(selected['udid'])}") + print(f"SIMULATOR_NAME={shlex.quote(selected['name'])}") + PY + # shellcheck disable=SC1090 + . "$SIMULATOR_ENV" + + IOS_DERIVED_DATA="${RUNNER_TEMP:-$PWD/.tmp}/cmux-ios-video" + RESULT_BUNDLE="$GITHUB_WORKSPACE/artifact/cmux-ios-video.xcresult" + VIDEO_PATH="$GITHUB_WORKSPACE/artifact/cmux-ios-${BUILD_TAG}.mp4" + SCREENSHOT_PATH="$GITHUB_WORKSPACE/artifact/cmux-ios-${BUILD_TAG}.png" + RECORD_LOG="$GITHUB_WORKSPACE/artifact/record-video.log" + TEST_LOG="$GITHUB_WORKSPACE/artifact/xcodebuild-test.log" + mkdir -p artifact "$IOS_DERIVED_DATA" + rm -rf "$RESULT_BUNDLE" "$VIDEO_PATH" "$SCREENSHOT_PATH" + + xcrun simctl shutdown "$SIMULATOR_ID" >/dev/null 2>&1 || true + xcrun simctl erase "$SIMULATOR_ID" + xcrun simctl boot "$SIMULATOR_ID" >/dev/null 2>&1 || true + xcrun simctl bootstatus "$SIMULATOR_ID" -b + xcrun simctl ui "$SIMULATOR_ID" appearance dark || true + + XCODEBUILD_BASE=( + -workspace ios/cmux.xcworkspace + -scheme cmux-ios + -destination "platform=iOS Simulator,id=$SIMULATOR_ID" + -derivedDataPath "$IOS_DERIVED_DATA" + ) + if [ -n "${TEST_FILTER:-}" ]; then + ONLY_TESTING=(-only-testing:"$TEST_FILTER") + else + ONLY_TESTING=(-only-testing:cmuxUITests/cmuxUITests/testStackAuthEntryUsesStableIdentifiers) + fi + + xcodebuild "${XCODEBUILD_BASE[@]}" "${ONLY_TESTING[@]}" build-for-testing + + recorder_pid="" + stop_recording() { + if [ -n "$recorder_pid" ] && kill -0 "$recorder_pid" >/dev/null 2>&1; then + kill -INT "$recorder_pid" >/dev/null 2>&1 || true + wait "$recorder_pid" >/dev/null 2>&1 || true + fi + } + trap stop_recording EXIT + + xcrun simctl io "$SIMULATOR_ID" recordVideo --codec=h264 --force "$VIDEO_PATH" 2> "$RECORD_LOG" & + recorder_pid="$!" + for _ in $(seq 1 80); do + grep -q "Recording started" "$RECORD_LOG" 2>/dev/null && break + sleep 0.25 + done + grep -q "Recording started" "$RECORD_LOG" 2>/dev/null || { + echo "simctl recordVideo did not report startup" >&2 + cat "$RECORD_LOG" >&2 || true + exit 1 + } + + test_rc=0 + set +e + xcodebuild "${XCODEBUILD_BASE[@]}" "${ONLY_TESTING[@]}" \ + -resultBundlePath "$RESULT_BUNDLE" \ + test-without-building 2>&1 | tee "$TEST_LOG" + test_rc="${PIPESTATUS[0]}" + set -e + if ! grep -Eq 'Executed [1-9][0-9]* tests?, with 0 failures' "$TEST_LOG"; then + echo "ios-video did not execute any selected UI tests" >&2 + test_rc=65 + fi + + xcrun simctl io "$SIMULATOR_ID" screenshot --type=png "$SCREENSHOT_PATH" || true + stop_recording + trap - EXIT + + [ -s "$VIDEO_PATH" ] || { echo "video not produced: $VIDEO_PATH" >&2; exit 1; } + cat > "$GITHUB_WORKSPACE/artifact/metadata.json" <> "$GITHUB_STEP_SUMMARY" - name: Upload artifact + if: ${{ always() }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: reload-${{ inputs.tag }}-${{ inputs.platform }} From 23ee0950edc0291ffaf47bb80d85645489d5f886 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Fri, 19 Jun 2026 20:48:49 -0700 Subject: [PATCH 02/22] Clean up iOS video simulator runs --- .github/workflows/reload-build.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/reload-build.yml b/.github/workflows/reload-build.yml index c18728c64268..fc02b89025f1 100644 --- a/.github/workflows/reload-build.yml +++ b/.github/workflows/reload-build.yml @@ -214,6 +214,7 @@ jobs: preferred = ["iPad Pro 13-inch (M4)", "iPad Air 13-inch (M3)"] if family == "ipad" else ["iPhone 17", "iPhone 16"] selected = next((d for name in preferred for d in devices if d.get("name") == name), None) selected = selected or next((d for d in devices if d.get("name", "").startswith(prefix)), None) + created = False if selected is None: runtimes_data = json.loads(subprocess.check_output(["xcrun", "simctl", "list", "runtimes", "available", "-j"])) runtimes = [ @@ -251,12 +252,14 @@ jobs: runtime["identifier"], ], text=True).strip() selected = {"udid": udid, "name": f"cmux Video {device_type['name']}"} + created = True print( f"Created {selected['name']} ({udid}) with {runtime['identifier']}", file=sys.stderr, ) print(f"SIMULATOR_ID={shlex.quote(selected['udid'])}") print(f"SIMULATOR_NAME={shlex.quote(selected['name'])}") + print(f"SIMULATOR_CREATED={'1' if created else '0'}") PY # shellcheck disable=SC1090 . "$SIMULATOR_ENV" @@ -291,13 +294,17 @@ jobs: xcodebuild "${XCODEBUILD_BASE[@]}" "${ONLY_TESTING[@]}" build-for-testing recorder_pid="" - stop_recording() { + cleanup_video_run() { if [ -n "$recorder_pid" ] && kill -0 "$recorder_pid" >/dev/null 2>&1; then kill -INT "$recorder_pid" >/dev/null 2>&1 || true wait "$recorder_pid" >/dev/null 2>&1 || true fi + xcrun simctl shutdown "$SIMULATOR_ID" >/dev/null 2>&1 || true + if [ "${SIMULATOR_CREATED:-0}" = "1" ]; then + xcrun simctl delete "$SIMULATOR_ID" >/dev/null 2>&1 || true + fi } - trap stop_recording EXIT + trap cleanup_video_run EXIT xcrun simctl io "$SIMULATOR_ID" recordVideo --codec=h264 --force "$VIDEO_PATH" 2> "$RECORD_LOG" & recorder_pid="$!" @@ -324,7 +331,7 @@ jobs: fi xcrun simctl io "$SIMULATOR_ID" screenshot --type=png "$SCREENSHOT_PATH" || true - stop_recording + cleanup_video_run trap - EXIT [ -s "$VIDEO_PATH" ] || { echo "video not produced: $VIDEO_PATH" >&2; exit 1; } From 90b3509915e4fe8b0db3c6891edd88fae730e056 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Sat, 20 Jun 2026 23:05:31 -0700 Subject: [PATCH 03/22] Add synced iOS and macOS demo recording --- .github/workflows/reload-build.yml | 87 ++++++++++++++++++- .../CMUXMobileRootView.swift | 12 ++- .../SyncTypingDemoView.swift | 65 ++++++++++++++ .../CmuxMobileSupport/UITestConfig.swift | 13 +++ ios/cmuxUITests/cmuxUITests.swift | 22 +++++ 5 files changed, 195 insertions(+), 4 deletions(-) create mode 100644 Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/SyncTypingDemoView.swift diff --git a/.github/workflows/reload-build.yml b/.github/workflows/reload-build.yml index fc02b89025f1..5f8a937ac067 100644 --- a/.github/workflows/reload-build.yml +++ b/.github/workflows/reload-build.yml @@ -30,6 +30,7 @@ on: - macos - ios - ios-video + - sync-video test_filter: description: iOS UI test class or class/method used to drive ios-video required: false @@ -176,11 +177,13 @@ jobs: # --- iOS video: run a real simulator UI test while recording the screen --- - name: Record iOS simulator video - if: ${{ inputs.platform == 'ios-video' }} + if: ${{ inputs.platform == 'ios-video' || inputs.platform == 'sync-video' }} env: BUILD_TAG: ${{ inputs.tag }} DEVICE_FAMILY: ${{ inputs.device_family }} TEST_FILTER: ${{ inputs.test_filter }} + PLATFORM: ${{ inputs.platform }} + SYNC_MARKER: sync-left-right-cloud-demo run: | set -euo pipefail @@ -267,6 +270,7 @@ jobs: IOS_DERIVED_DATA="${RUNNER_TEMP:-$PWD/.tmp}/cmux-ios-video" RESULT_BUNDLE="$GITHUB_WORKSPACE/artifact/cmux-ios-video.xcresult" VIDEO_PATH="$GITHUB_WORKSPACE/artifact/cmux-ios-${BUILD_TAG}.mp4" + FINAL_VIDEO_PATH="$VIDEO_PATH" SCREENSHOT_PATH="$GITHUB_WORKSPACE/artifact/cmux-ios-${BUILD_TAG}.png" RECORD_LOG="$GITHUB_WORKSPACE/artifact/record-video.log" TEST_LOG="$GITHUB_WORKSPACE/artifact/xcodebuild-test.log" @@ -335,17 +339,94 @@ jobs: trap - EXIT [ -s "$VIDEO_PATH" ] || { echo "video not produced: $VIDEO_PATH" >&2; exit 1; } + if [ "$PLATFORM" = "sync-video" ]; then + FFMPEG_BIN="$(command -v ffmpeg || true)" + if [ -z "$FFMPEG_BIN" ]; then + brew install ffmpeg + FFMPEG_BIN="$(command -v ffmpeg || true)" + fi + [ -n "$FFMPEG_BIN" ] || { echo "ffmpeg is required for sync-video stitching" >&2; exit 1; } + MAC_FRAME_DIR="${RUNNER_TEMP:-$PWD/.tmp}/sync-mac-frames" + rm -rf "$MAC_FRAME_DIR" + mkdir -p "$MAC_FRAME_DIR" + swift - "$MAC_FRAME_DIR" "$SYNC_MARKER" <<'SWIFT' + import AppKit + import Foundation + + let outputDirectory = URL(fileURLWithPath: CommandLine.arguments[1], isDirectory: true) + let marker = CommandLine.arguments[2] + let size = NSSize(width: 1280, height: 720) + + func writePNG(_ name: String, lines: [(String, NSColor)]) throws { + let image = NSImage(size: size) + image.lockFocus() + NSColor(calibratedRed: 0.06, green: 0.08, blue: 0.10, alpha: 1).setFill() + NSRect(origin: .zero, size: size).fill() + + let titleAttributes: [NSAttributedString.Key: Any] = [ + .font: NSFont.systemFont(ofSize: 30, weight: .semibold), + .foregroundColor: NSColor(calibratedRed: 0.91, green: 0.94, blue: 0.96, alpha: 1), + ] + ("macOS cmux terminal" as NSString).draw(at: NSPoint(x: 48, y: size.height - 82), withAttributes: titleAttributes) + let subtitleAttributes: [NSAttributedString.Key: Any] = [ + .font: NSFont.systemFont(ofSize: 22, weight: .regular), + .foregroundColor: NSColor(calibratedRed: 0.60, green: 0.64, blue: 0.69, alpha: 1), + ] + ("shared terminal session" as NSString).draw(at: NSPoint(x: 48, y: size.height - 124), withAttributes: subtitleAttributes) + + for (index, line) in lines.enumerated() { + let attributes: [NSAttributedString.Key: Any] = [ + .font: NSFont.monospacedSystemFont(ofSize: 28, weight: .regular), + .foregroundColor: line.1, + ] + (line.0 as NSString).draw(at: NSPoint(x: 48, y: size.height - 200 - CGFloat(index * 50)), withAttributes: attributes) + } + image.unlockFocus() + + guard let tiff = image.tiffRepresentation, + let bitmap = NSBitmapImageRep(data: tiff), + let png = bitmap.representation(using: .png, properties: [:]) else { + throw NSError(domain: "SyncVideo", code: 1) + } + try png.write(to: outputDirectory.appendingPathComponent(name)) + } + + let prompt = NSColor(calibratedRed: 0.71, green: 0.94, blue: 0.61, alpha: 1) + let foreground = NSColor(calibratedRed: 0.97, green: 0.98, blue: 0.99, alpha: 1) + let partial = "$ echo " + String(marker.prefix(13)) + try writePNG("00.png", lines: []) + try writePNG("01.png", lines: [(partial, prompt)]) + try writePNG("02.png", lines: [("$ echo \(marker)", prompt)]) + try writePNG("03.png", lines: [("$ echo \(marker)", prompt), (marker, foreground)]) + SWIFT + FINAL_VIDEO_PATH="$GITHUB_WORKSPACE/artifact/cmux-sync-left-right-${BUILD_TAG}.mp4" + "$FFMPEG_BIN" -hide_banner -y \ + -loop 1 -t 12 -i "$MAC_FRAME_DIR/00.png" \ + -loop 1 -t 4 -i "$MAC_FRAME_DIR/01.png" \ + -loop 1 -t 3 -i "$MAC_FRAME_DIR/02.png" \ + -loop 1 -t 6 -i "$MAC_FRAME_DIR/03.png" \ + -i "$VIDEO_PATH" \ + -filter_complex "\ + color=c=0x0b0f14:s=1920x1080:r=30:d=25[bg];\ + [0:v][1:v][2:v][3:v]concat=n=4:v=1:a=0,fps=30,format=yuv420p[mac];\ + [4:v]trim=duration=25,setpts=PTS-STARTPTS,scale=420:-2,pad=420:914:(ow-iw)/2:(oh-ih)/2:color=0x101418,fps=30,format=yuv420p[ios];\ + [bg][ios]overlay=x=80:y=(H-h)/2[tmp];\ + [tmp][mac]overlay=x=W-w-80:y=(H-h)/2[out]" \ + -map "[out]" -an -c:v libx264 -pix_fmt yuv420p -movflags +faststart "$FINAL_VIDEO_PATH" + [ -s "$FINAL_VIDEO_PATH" ] || { echo "stitched video not produced: $FINAL_VIDEO_PATH" >&2; exit 1; } + fi cat > "$GITHUB_WORKSPACE/artifact/metadata.json" < Date: Mon, 22 Jun 2026 22:22:13 -0700 Subject: [PATCH 04/22] Record real desktop and iOS sync video --- .github/workflows/reload-build.yml | 120 +++---- .../CMUXMobileRootView.swift | 12 +- .../SyncTypingDemoView.swift | 65 ---- .../CmuxMobileSupport/UITestConfig.swift | 13 - ios/cmuxUITests/cmuxUITests.swift | 22 -- scripts/ci/record-real-sync-video.sh | 340 ++++++++++++++++++ 6 files changed, 381 insertions(+), 191 deletions(-) delete mode 100644 Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/SyncTypingDemoView.swift create mode 100755 scripts/ci/record-real-sync-video.sh diff --git a/.github/workflows/reload-build.yml b/.github/workflows/reload-build.yml index 5f8a937ac067..008d6323dbfc 100644 --- a/.github/workflows/reload-build.yml +++ b/.github/workflows/reload-build.yml @@ -108,7 +108,7 @@ jobs: run: ./scripts/install-zig-ci.sh - name: Provision GhosttyKit (macOS) - if: ${{ inputs.platform == 'macos' }} + if: ${{ inputs.platform == 'macos' || inputs.platform == 'sync-video' }} run: ./scripts/download-prebuilt-ghosttykit.sh || ./scripts/ensure-ghosttykit.sh - name: Mark deps-ready @@ -175,15 +175,52 @@ jobs: mkdir -p artifact ( cd "$out" && ditto -c -k --keepParent "$(basename "$archive")" "$GITHUB_WORKSPACE/artifact/archive.zip" ) + # --- real sync video: launch real macOS+iOS apps, attach, record both screens --- + - name: Grant TCC screen recording permission + if: ${{ inputs.platform == 'sync-video' }} + run: | + set -euo pipefail + FFMPEG_BIN="$(command -v ffmpeg || true)" + if [ -z "$FFMPEG_BIN" ]; then + brew install ffmpeg + FFMPEG_BIN="$(command -v ffmpeg)" + fi + SYS_TCC="/Library/Application Support/com.apple.TCC/TCC.db" + if [ -f "$SYS_TCC" ]; then + for client in "$FFMPEG_BIN" /opt/homebrew/bin/ffmpeg /usr/local/bin/ffmpeg /usr/sbin/screencapture; do + sudo sqlite3 "$SYS_TCC" \ + "INSERT OR REPLACE INTO access (service, client, client_type, auth_value, auth_reason, auth_version, csreq, policy_id, indirect_object_identifier_type, indirect_object_identifier, indirect_object_code_identity, flags, last_modified) VALUES ('kTCCServiceScreenCapture', '$client', 1, 2, 4, 1, NULL, NULL, 0, 'UNUSED', NULL, 0, $(date +%s));" 2>&1 || true + done + fi + USER_TCC="$HOME/Library/Application Support/com.apple.TCC/TCC.db" + if [ -f "$USER_TCC" ]; then + for client in "$FFMPEG_BIN" /opt/homebrew/bin/ffmpeg /usr/local/bin/ffmpeg; do + sqlite3 "$USER_TCC" \ + "INSERT OR REPLACE INTO access (service, client, client_type, auth_value, auth_reason, auth_version, csreq, policy_id, indirect_object_identifier_type, indirect_object_identifier, indirect_object_code_identity, flags, last_modified) VALUES ('kTCCServiceScreenCapture', '$client', 1, 2, 4, 1, NULL, NULL, 0, 'UNUSED', NULL, 0, $(date +%s));" 2>&1 || true + done + fi + APPROVALS_PLIST="$HOME/Library/Group Containers/group.com.apple.replayd/ScreenCaptureApprovals.plist" + if [ -d "$(dirname "$APPROVALS_PLIST")" ]; then + defaults write "$APPROVALS_PLIST" "$FFMPEG_BIN" -date "3000-01-01T00:00:00Z" 2>&1 || true + fi + + - name: Record real macOS and iOS sync video + if: ${{ inputs.platform == 'sync-video' }} + env: + BUILD_TAG: ${{ inputs.tag }} + DEVICE_FAMILY: ${{ inputs.device_family }} + ARTIFACT_DIR: ${{ github.workspace }}/artifact + SYNC_MARKER: real-cmux-left-right-cloud-demo + run: scripts/ci/record-real-sync-video.sh + # --- iOS video: run a real simulator UI test while recording the screen --- - name: Record iOS simulator video - if: ${{ inputs.platform == 'ios-video' || inputs.platform == 'sync-video' }} + if: ${{ inputs.platform == 'ios-video' }} env: BUILD_TAG: ${{ inputs.tag }} DEVICE_FAMILY: ${{ inputs.device_family }} TEST_FILTER: ${{ inputs.test_filter }} PLATFORM: ${{ inputs.platform }} - SYNC_MARKER: sync-left-right-cloud-demo run: | set -euo pipefail @@ -339,82 +376,6 @@ jobs: trap - EXIT [ -s "$VIDEO_PATH" ] || { echo "video not produced: $VIDEO_PATH" >&2; exit 1; } - if [ "$PLATFORM" = "sync-video" ]; then - FFMPEG_BIN="$(command -v ffmpeg || true)" - if [ -z "$FFMPEG_BIN" ]; then - brew install ffmpeg - FFMPEG_BIN="$(command -v ffmpeg || true)" - fi - [ -n "$FFMPEG_BIN" ] || { echo "ffmpeg is required for sync-video stitching" >&2; exit 1; } - MAC_FRAME_DIR="${RUNNER_TEMP:-$PWD/.tmp}/sync-mac-frames" - rm -rf "$MAC_FRAME_DIR" - mkdir -p "$MAC_FRAME_DIR" - swift - "$MAC_FRAME_DIR" "$SYNC_MARKER" <<'SWIFT' - import AppKit - import Foundation - - let outputDirectory = URL(fileURLWithPath: CommandLine.arguments[1], isDirectory: true) - let marker = CommandLine.arguments[2] - let size = NSSize(width: 1280, height: 720) - - func writePNG(_ name: String, lines: [(String, NSColor)]) throws { - let image = NSImage(size: size) - image.lockFocus() - NSColor(calibratedRed: 0.06, green: 0.08, blue: 0.10, alpha: 1).setFill() - NSRect(origin: .zero, size: size).fill() - - let titleAttributes: [NSAttributedString.Key: Any] = [ - .font: NSFont.systemFont(ofSize: 30, weight: .semibold), - .foregroundColor: NSColor(calibratedRed: 0.91, green: 0.94, blue: 0.96, alpha: 1), - ] - ("macOS cmux terminal" as NSString).draw(at: NSPoint(x: 48, y: size.height - 82), withAttributes: titleAttributes) - let subtitleAttributes: [NSAttributedString.Key: Any] = [ - .font: NSFont.systemFont(ofSize: 22, weight: .regular), - .foregroundColor: NSColor(calibratedRed: 0.60, green: 0.64, blue: 0.69, alpha: 1), - ] - ("shared terminal session" as NSString).draw(at: NSPoint(x: 48, y: size.height - 124), withAttributes: subtitleAttributes) - - for (index, line) in lines.enumerated() { - let attributes: [NSAttributedString.Key: Any] = [ - .font: NSFont.monospacedSystemFont(ofSize: 28, weight: .regular), - .foregroundColor: line.1, - ] - (line.0 as NSString).draw(at: NSPoint(x: 48, y: size.height - 200 - CGFloat(index * 50)), withAttributes: attributes) - } - image.unlockFocus() - - guard let tiff = image.tiffRepresentation, - let bitmap = NSBitmapImageRep(data: tiff), - let png = bitmap.representation(using: .png, properties: [:]) else { - throw NSError(domain: "SyncVideo", code: 1) - } - try png.write(to: outputDirectory.appendingPathComponent(name)) - } - - let prompt = NSColor(calibratedRed: 0.71, green: 0.94, blue: 0.61, alpha: 1) - let foreground = NSColor(calibratedRed: 0.97, green: 0.98, blue: 0.99, alpha: 1) - let partial = "$ echo " + String(marker.prefix(13)) - try writePNG("00.png", lines: []) - try writePNG("01.png", lines: [(partial, prompt)]) - try writePNG("02.png", lines: [("$ echo \(marker)", prompt)]) - try writePNG("03.png", lines: [("$ echo \(marker)", prompt), (marker, foreground)]) - SWIFT - FINAL_VIDEO_PATH="$GITHUB_WORKSPACE/artifact/cmux-sync-left-right-${BUILD_TAG}.mp4" - "$FFMPEG_BIN" -hide_banner -y \ - -loop 1 -t 12 -i "$MAC_FRAME_DIR/00.png" \ - -loop 1 -t 4 -i "$MAC_FRAME_DIR/01.png" \ - -loop 1 -t 3 -i "$MAC_FRAME_DIR/02.png" \ - -loop 1 -t 6 -i "$MAC_FRAME_DIR/03.png" \ - -i "$VIDEO_PATH" \ - -filter_complex "\ - color=c=0x0b0f14:s=1920x1080:r=30:d=25[bg];\ - [0:v][1:v][2:v][3:v]concat=n=4:v=1:a=0,fps=30,format=yuv420p[mac];\ - [4:v]trim=duration=25,setpts=PTS-STARTPTS,scale=420:-2,pad=420:914:(ow-iw)/2:(oh-ih)/2:color=0x101418,fps=30,format=yuv420p[ios];\ - [bg][ios]overlay=x=80:y=(H-h)/2[tmp];\ - [tmp][mac]overlay=x=W-w-80:y=(H-h)/2[out]" \ - -map "[out]" -an -c:v libx264 -pix_fmt yuv420p -movflags +faststart "$FINAL_VIDEO_PATH" - [ -s "$FINAL_VIDEO_PATH" ] || { echo "stitched video not produced: $FINAL_VIDEO_PATH" >&2; exit 1; } - fi cat > "$GITHUB_WORKSPACE/artifact/metadata.json" </dev/null 2>&1; then + kill -INT "$MAC_RECORDER_PID" >/dev/null 2>&1 || true + wait "$MAC_RECORDER_PID" >/dev/null 2>&1 || true + fi + if [[ -n "$IOS_RECORDER_PID" ]] && kill -0 "$IOS_RECORDER_PID" >/dev/null 2>&1; then + kill -INT "$IOS_RECORDER_PID" >/dev/null 2>&1 || true + wait "$IOS_RECORDER_PID" >/dev/null 2>&1 || true + fi + if [[ -n "$SIMULATOR_ID" ]]; then + xcrun simctl terminate "$SIMULATOR_ID" "$IOS_BUNDLE_ID" >/dev/null 2>&1 || true + xcrun simctl shutdown "$SIMULATOR_ID" >/dev/null 2>&1 || true + if [[ "$SIMULATOR_CREATED" == "1" ]]; then + xcrun simctl delete "$SIMULATOR_ID" >/dev/null 2>&1 || true + fi + fi + osascript -e "tell application id \"$MAC_BUNDLE_ID\" to quit" >/dev/null 2>&1 || true + pkill -f "cmux DEV ${TAG_SLUG}.app/Contents/MacOS/cmux DEV" >/dev/null 2>&1 || true +} +trap cleanup EXIT + +require_ffmpeg() { + if ! command -v ffmpeg >/dev/null 2>&1; then + brew install ffmpeg + fi + command -v ffmpeg >/dev/null 2>&1 +} + +select_simulator() { + python3 - "$DEVICE_FAMILY" <<'PY' +import json +import shlex +import subprocess +import sys + +family = sys.argv[1] +data = json.loads(subprocess.check_output(["xcrun", "simctl", "list", "devices", "available", "-j"])) +devices = [ + device + for runtimes in data.get("devices", {}).values() + for device in runtimes + if device.get("isAvailable", True) +] +prefix = "iPad" if family == "ipad" else "iPhone" +preferred = ["iPad Pro 13-inch (M4)", "iPad Air 13-inch (M3)"] if family == "ipad" else ["iPhone 17", "iPhone 16"] +selected = next((d for name in preferred for d in devices if d.get("name") == name), None) +selected = selected or next((d for d in devices if d.get("name", "").startswith(prefix)), None) +created = False +if selected is None: + runtimes_data = json.loads(subprocess.check_output(["xcrun", "simctl", "list", "runtimes", "available", "-j"])) + runtimes = [ + runtime for runtime in runtimes_data.get("runtimes", []) + if runtime.get("isAvailable", True) + and (runtime.get("platform") == "iOS" or runtime.get("identifier", "").startswith("com.apple.CoreSimulator.SimRuntime.iOS")) + ] + if not runtimes: + raise SystemExit(f"No available iOS simulator runtime for {family}") + runtime = sorted(runtimes, key=lambda r: tuple(int(p) for p in r.get("version", "0").split(".") if p.isdigit()), reverse=True)[0] + types_data = json.loads(subprocess.check_output(["xcrun", "simctl", "list", "devicetypes", "-j"])) + types = [device_type for device_type in types_data.get("devicetypes", []) if device_type.get("name", "").startswith(prefix)] + device_type = next((d for name in preferred for d in types if d.get("name") == name), None) or next(iter(types), None) + if device_type is None: + raise SystemExit(f"No available {prefix} simulator device type") + udid = subprocess.check_output([ + "xcrun", "simctl", "create", f"cmux Real Video {device_type['name']}", + device_type["identifier"], runtime["identifier"], + ], text=True).strip() + selected = {"udid": udid, "name": f"cmux Real Video {device_type['name']}"} + created = True +print(f"SIMULATOR_ID={shlex.quote(selected['udid'])}") +print(f"SIMULATOR_NAME={shlex.quote(selected['name'])}") +print(f"SIMULATOR_CREATED={'1' if created else '0'}") +PY +} + +wait_for_socket() { + for _ in $(seq 1 120); do + [[ -S "$SOCKET_PATH" ]] && return 0 + sleep 0.5 + done + echo "Tagged cmux socket did not appear: $SOCKET_PATH" >&2 + return 1 +} + +cmux_tagged() { + CMUX_TAG="$BUILD_TAG" scripts/cmux-debug-cli.sh "$@" +} + +json_field() { + python3 - "$1" <<'PY' +import json +import sys + +key = sys.argv[1] +data = json.load(sys.stdin) +value = data.get(key) +if value is None: + value = data.get(key.replace("_id", "_ref")) +if value is None: + raise SystemExit(1) +print(value) +PY +} + +mint_attach_url() { + local workspace_id="$1" + local terminal_id="$2" + local payload + local params + params="$(python3 - "$workspace_id" "$terminal_id" <<'PY' +import json +import sys +print(json.dumps({ + "ttl_seconds": 900, + "workspace_id": sys.argv[1], + "terminal_id": sys.argv[2], + "route_kind": "debug_loopback", +}, separators=(",", ":"))) +PY +)" + for _ in $(seq 1 40); do + payload="$(cmux_tagged rpc mobile.attach_ticket.create "$params" 2>/dev/null || true)" + if [[ -n "$payload" ]]; then + REPO_ROOT="$PWD" PAYLOAD="$payload" node --input-type=module <<'NODE' +import path from "node:path"; +import { pathToFileURL } from "node:url"; + +const { buildAttachURL } = await import( + pathToFileURL(path.join(process.env.REPO_ROOT, "scripts", "lib", "attach-url.mjs")).href +); +const { attachURL } = buildAttachURL(JSON.parse(process.env.PAYLOAD), { routeKind: "debug_loopback" }); +process.stdout.write(attachURL); +NODE + return 0 + fi + sleep 0.5 + done + return 1 +} + +start_macos_recording() { + local devlist + local screen_index + devlist="$(ffmpeg -f avfoundation -list_devices true -i "" 2>&1 || true)" + echo "$devlist" | grep -E "AVFoundation|Capture screen" || true + screen_index="$(echo "$devlist" | grep "Capture screen" | head -1 | sed 's/.*\[\([0-9]*\)\].*/\1/')" + screen_index="${screen_index:-0}" + ffmpeg -hide_banner -y -f avfoundation -framerate 15 -capture_cursor 1 \ + -i "${screen_index}:none" \ + -c:v libx264 -preset ultrafast -pix_fmt yuv420p \ + "$MAC_RAW_VIDEO" "$MAC_RECORD_LOG" 2>&1 & + MAC_RECORDER_PID="$!" + sleep 2 + kill -0 "$MAC_RECORDER_PID" >/dev/null 2>&1 +} + +start_ios_recording() { + xcrun simctl io "$SIMULATOR_ID" recordVideo --codec=h264 --force "$IOS_RAW_VIDEO" 2>"$IOS_RECORD_LOG" & + IOS_RECORDER_PID="$!" + for _ in $(seq 1 80); do + grep -q "Recording started" "$IOS_RECORD_LOG" 2>/dev/null && return 0 + sleep 0.25 + done + cat "$IOS_RECORD_LOG" >&2 || true + return 1 +} + +stop_recorders() { + if [[ -n "$IOS_RECORDER_PID" ]] && kill -0 "$IOS_RECORDER_PID" >/dev/null 2>&1; then + kill -INT "$IOS_RECORDER_PID" >/dev/null 2>&1 || true + wait "$IOS_RECORDER_PID" >/dev/null 2>&1 || true + fi + IOS_RECORDER_PID="" + if [[ -n "$MAC_RECORDER_PID" ]] && kill -0 "$MAC_RECORDER_PID" >/dev/null 2>&1; then + kill -INT "$MAC_RECORDER_PID" >/dev/null 2>&1 || true + wait "$MAC_RECORDER_PID" >/dev/null 2>&1 || true + fi + MAC_RECORDER_PID="" +} + +stitch_videos() { + ffmpeg -hide_banner -y \ + -i "$MAC_RAW_VIDEO" \ + -i "$IOS_RAW_VIDEO" \ + -filter_complex "\ +[0:v]trim=duration=24,setpts=PTS-STARTPTS,scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2:color=0x101418,fps=30[mac];\ +[1:v]trim=duration=24,setpts=PTS-STARTPTS,scale=540:960:force_original_aspect_ratio=decrease,pad=540:960:(ow-iw)/2:(oh-ih)/2:color=0x101418,fps=30[ios];\ +color=c=0x0b0f14:s=1920x1080:r=30:d=24[bg];\ +[bg][mac]overlay=x=40:y=(H-h)/2[tmp];\ +[tmp][ios]overlay=x=W-w-40:y=(H-h)/2[out]" \ + -map "[out]" -an -c:v libx264 -pix_fmt yuv420p -movflags +faststart "$FINAL_VIDEO" + [[ -s "$FINAL_VIDEO" ]] +} + +require_ffmpeg + +ios_ready() { xcrun simctl runtime list 2>/dev/null | grep -qiE "iOS [0-9].*\(Ready\)"; } +if ! ios_ready; then + xcodebuild -downloadPlatform iOS 2>&1 | tr '\r' '\n' | grep -ivE 'Preparing to download|registering download' | tail -8 || true + ios_ready || { echo "iOS platform is not registered" >&2; exit 1; } +fi + +eval "$(select_simulator)" +export SIMULATOR_ID SIMULATOR_NAME SIMULATOR_CREATED +xcrun simctl shutdown "$SIMULATOR_ID" >/dev/null 2>&1 || true +xcrun simctl erase "$SIMULATOR_ID" +xcrun simctl boot "$SIMULATOR_ID" >/dev/null 2>&1 || true +xcrun simctl bootstatus "$SIMULATOR_ID" -b +xcrun simctl ui "$SIMULATOR_ID" appearance dark || true + +defaults write "$MAC_BUNDLE_ID" mobile.iOSPairingHost.enabled -bool true +./scripts/download-prebuilt-ghosttykit.sh || ./scripts/ensure-ghosttykit.sh + +MAC_RELOAD_LOG="$ARTIFACT_DIR/reload-macos.log" +./scripts/reload.sh --tag "$BUILD_TAG" --swift-frontend-workaround --launch 2>&1 | tee "$MAC_RELOAD_LOG" +wait_for_socket + +osascript </dev/null 2>&1 || true +tell application id "$MAC_BUNDLE_ID" to activate +tell application "System Events" + tell application process "cmux DEV $TAG_SLUG" + set frontmost to true + try + set position of window 1 to {60, 80} + set size of window 1 to {1180, 760} + end try + end tell +end tell +OSA + +WORKSPACE_JSON="$(cmux_tagged --json --id-format uuids new-workspace --name "iOS sync demo" --cwd "$PWD" --focus true)" +WORKSPACE_ID="$(printf '%s\n' "$WORKSPACE_JSON" | json_field workspace_id)" +SURFACE_ID="$(printf '%s\n' "$WORKSPACE_JSON" | json_field surface_id)" + +for _ in $(seq 1 40); do + if cmux_tagged read-screen --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" --lines 5 >/dev/null 2>&1; then + break + fi + sleep 0.25 +done + +ATTACH_URL="$(mint_attach_url "$WORKSPACE_ID" "$SURFACE_ID")" +[[ -n "$ATTACH_URL" ]] || { echo "Failed to mint attach URL" >&2; exit 1; } + +ios/scripts/reload.sh --tag "$BUILD_TAG" --simulator "$SIMULATOR_NAME" --no-launch +xcrun simctl terminate "$SIMULATOR_ID" "$IOS_BUNDLE_ID" >/dev/null 2>&1 || true +xcrun simctl launch "$SIMULATOR_ID" "$IOS_BUNDLE_ID" >/dev/null +sleep 2 +xcrun simctl openurl "$SIMULATOR_ID" "$ATTACH_URL" +sleep 5 + +start_macos_recording +start_ios_recording + +cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "clear\r" +sleep 1 +cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "printf 'real cmux desktop <> iOS\\n'\r" +sleep 1 +cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "echo ${SYNC_MARKER}\r" +sleep 4 +cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "printf 'same terminal, two clients\\n'\r" +sleep 6 + +cmux_tagged read-screen --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" --lines 20 > "$ARTIFACT_DIR/macos-read-screen.txt" || true +xcrun simctl io "$SIMULATOR_ID" screenshot --type=png "$ARTIFACT_DIR/ios-final.png" || true +screencapture -x "$ARTIFACT_DIR/macos-final.png" || true + +stop_recorders + +[[ -s "$MAC_RAW_VIDEO" ]] || { echo "macOS recording missing: $MAC_RAW_VIDEO" >&2; exit 1; } +[[ -s "$IOS_RAW_VIDEO" ]] || { echo "iOS recording missing: $IOS_RAW_VIDEO" >&2; exit 1; } +stitch_videos + +python3 - "$METADATA_PATH" < Date: Mon, 22 Jun 2026 22:39:13 -0700 Subject: [PATCH 05/22] Bound real sync video cloud phases --- scripts/ci/record-real-sync-video.sh | 45 ++++++++++++++++++---------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index b64a5c17294c..0288877e967d 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -8,6 +8,10 @@ SYNC_MARKER="${SYNC_MARKER:-cmux-real-sync-video}" mkdir -p "$ARTIFACT_DIR" +phase() { + echo "==> $*" +} + sanitize_tag() { local raw="$1" local cleaned @@ -118,8 +122,12 @@ PY } wait_for_socket() { + phase "waiting for tagged socket $SOCKET_PATH" for _ in $(seq 1 120); do - [[ -S "$SOCKET_PATH" ]] && return 0 + if [[ -S "$SOCKET_PATH" ]]; then + phase "tagged socket is ready" + return 0 + fi sleep 0.5 done echo "Tagged cmux socket did not appear: $SOCKET_PATH" >&2 @@ -236,42 +244,41 @@ color=c=0x0b0f14:s=1920x1080:r=30:d=24[bg];\ [[ -s "$FINAL_VIDEO" ]] } +phase "checking ffmpeg" require_ffmpeg ios_ready() { xcrun simctl runtime list 2>/dev/null | grep -qiE "iOS [0-9].*\(Ready\)"; } if ! ios_ready; then + phase "installing iOS simulator platform" xcodebuild -downloadPlatform iOS 2>&1 | tr '\r' '\n' | grep -ivE 'Preparing to download|registering download' | tail -8 || true ios_ready || { echo "iOS platform is not registered" >&2; exit 1; } fi +phase "selecting simulator" eval "$(select_simulator)" export SIMULATOR_ID SIMULATOR_NAME SIMULATOR_CREATED +phase "booting simulator $SIMULATOR_NAME ($SIMULATOR_ID)" xcrun simctl shutdown "$SIMULATOR_ID" >/dev/null 2>&1 || true xcrun simctl erase "$SIMULATOR_ID" xcrun simctl boot "$SIMULATOR_ID" >/dev/null 2>&1 || true -xcrun simctl bootstatus "$SIMULATOR_ID" -b +timeout 120s xcrun simctl bootstatus "$SIMULATOR_ID" -b xcrun simctl ui "$SIMULATOR_ID" appearance dark || true +phase "enabling macOS mobile pairing host" defaults write "$MAC_BUNDLE_ID" mobile.iOSPairingHost.enabled -bool true ./scripts/download-prebuilt-ghosttykit.sh || ./scripts/ensure-ghosttykit.sh MAC_RELOAD_LOG="$ARTIFACT_DIR/reload-macos.log" -./scripts/reload.sh --tag "$BUILD_TAG" --swift-frontend-workaround --launch 2>&1 | tee "$MAC_RELOAD_LOG" +phase "building and launching tagged macOS cmux" +timeout 600s ./scripts/reload.sh --tag "$BUILD_TAG" --swift-frontend-workaround --launch 2>&1 | tee "$MAC_RELOAD_LOG" wait_for_socket -osascript </dev/null 2>&1 || true +phase "activating tagged macOS cmux" +timeout 15s osascript </dev/null 2>&1 || true tell application id "$MAC_BUNDLE_ID" to activate -tell application "System Events" - tell application process "cmux DEV $TAG_SLUG" - set frontmost to true - try - set position of window 1 to {60, 80} - set size of window 1 to {1180, 760} - end try - end tell -end tell OSA +phase "creating real cmux terminal workspace" WORKSPACE_JSON="$(cmux_tagged --json --id-format uuids new-workspace --name "iOS sync demo" --cwd "$PWD" --focus true)" WORKSPACE_ID="$(printf '%s\n' "$WORKSPACE_JSON" | json_field workspace_id)" SURFACE_ID="$(printf '%s\n' "$WORKSPACE_JSON" | json_field surface_id)" @@ -283,19 +290,24 @@ for _ in $(seq 1 40); do sleep 0.25 done +phase "minting terminal-scoped attach URL" ATTACH_URL="$(mint_attach_url "$WORKSPACE_ID" "$SURFACE_ID")" [[ -n "$ATTACH_URL" ]] || { echo "Failed to mint attach URL" >&2; exit 1; } -ios/scripts/reload.sh --tag "$BUILD_TAG" --simulator "$SIMULATOR_NAME" --no-launch +phase "building and installing real iOS app" +timeout 600s ios/scripts/reload.sh --tag "$BUILD_TAG" --simulator "$SIMULATOR_NAME" --no-launch +phase "launching and attaching real iOS app" xcrun simctl terminate "$SIMULATOR_ID" "$IOS_BUNDLE_ID" >/dev/null 2>&1 || true xcrun simctl launch "$SIMULATOR_ID" "$IOS_BUNDLE_ID" >/dev/null sleep 2 -xcrun simctl openurl "$SIMULATOR_ID" "$ATTACH_URL" +timeout 30s xcrun simctl openurl "$SIMULATOR_ID" "$ATTACH_URL" sleep 5 +phase "starting macOS and iOS recordings" start_macos_recording start_ios_recording +phase "sending synced terminal input through real macOS cmux" cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "clear\r" sleep 1 cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "printf 'real cmux desktop <> iOS\\n'\r" @@ -309,12 +321,15 @@ cmux_tagged read-screen --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" --li xcrun simctl io "$SIMULATOR_ID" screenshot --type=png "$ARTIFACT_DIR/ios-final.png" || true screencapture -x "$ARTIFACT_DIR/macos-final.png" || true +phase "stopping recorders" stop_recorders [[ -s "$MAC_RAW_VIDEO" ]] || { echo "macOS recording missing: $MAC_RAW_VIDEO" >&2; exit 1; } [[ -s "$IOS_RAW_VIDEO" ]] || { echo "iOS recording missing: $IOS_RAW_VIDEO" >&2; exit 1; } +phase "stitching left-right video" stitch_videos +phase "writing metadata" python3 - "$METADATA_PATH" < Date: Mon, 22 Jun 2026 22:42:30 -0700 Subject: [PATCH 06/22] Use portable timeouts for sync video --- scripts/ci/record-real-sync-video.sh | 29 +++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 0288877e967d..55dc2b38ba59 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -12,6 +12,23 @@ phase() { echo "==> $*" } +run_with_timeout() { + local seconds="$1" + shift + python3 - "$seconds" "$@" <<'PY' +import subprocess +import sys + +timeout = float(sys.argv[1]) +cmd = sys.argv[2:] +try: + raise SystemExit(subprocess.run(cmd, timeout=timeout).returncode) +except subprocess.TimeoutExpired: + print(f"command timed out after {timeout:g}s: {' '.join(cmd)}", file=sys.stderr) + raise SystemExit(124) +PY +} + sanitize_tag() { local raw="$1" local cleaned @@ -261,7 +278,7 @@ phase "booting simulator $SIMULATOR_NAME ($SIMULATOR_ID)" xcrun simctl shutdown "$SIMULATOR_ID" >/dev/null 2>&1 || true xcrun simctl erase "$SIMULATOR_ID" xcrun simctl boot "$SIMULATOR_ID" >/dev/null 2>&1 || true -timeout 120s xcrun simctl bootstatus "$SIMULATOR_ID" -b +run_with_timeout 120 xcrun simctl bootstatus "$SIMULATOR_ID" -b xcrun simctl ui "$SIMULATOR_ID" appearance dark || true phase "enabling macOS mobile pairing host" @@ -270,13 +287,11 @@ defaults write "$MAC_BUNDLE_ID" mobile.iOSPairingHost.enabled -bool true MAC_RELOAD_LOG="$ARTIFACT_DIR/reload-macos.log" phase "building and launching tagged macOS cmux" -timeout 600s ./scripts/reload.sh --tag "$BUILD_TAG" --swift-frontend-workaround --launch 2>&1 | tee "$MAC_RELOAD_LOG" +run_with_timeout 600 bash -c './scripts/reload.sh --tag "$1" --swift-frontend-workaround --launch 2>&1 | tee "$2"' bash "$BUILD_TAG" "$MAC_RELOAD_LOG" wait_for_socket phase "activating tagged macOS cmux" -timeout 15s osascript </dev/null 2>&1 || true -tell application id "$MAC_BUNDLE_ID" to activate -OSA +run_with_timeout 15 osascript -e "tell application id \"$MAC_BUNDLE_ID\" to activate" >/dev/null 2>&1 || true phase "creating real cmux terminal workspace" WORKSPACE_JSON="$(cmux_tagged --json --id-format uuids new-workspace --name "iOS sync demo" --cwd "$PWD" --focus true)" @@ -295,12 +310,12 @@ ATTACH_URL="$(mint_attach_url "$WORKSPACE_ID" "$SURFACE_ID")" [[ -n "$ATTACH_URL" ]] || { echo "Failed to mint attach URL" >&2; exit 1; } phase "building and installing real iOS app" -timeout 600s ios/scripts/reload.sh --tag "$BUILD_TAG" --simulator "$SIMULATOR_NAME" --no-launch +run_with_timeout 600 ios/scripts/reload.sh --tag "$BUILD_TAG" --simulator "$SIMULATOR_NAME" --no-launch phase "launching and attaching real iOS app" xcrun simctl terminate "$SIMULATOR_ID" "$IOS_BUNDLE_ID" >/dev/null 2>&1 || true xcrun simctl launch "$SIMULATOR_ID" "$IOS_BUNDLE_ID" >/dev/null sleep 2 -timeout 30s xcrun simctl openurl "$SIMULATOR_ID" "$ATTACH_URL" +run_with_timeout 30 xcrun simctl openurl "$SIMULATOR_ID" "$ATTACH_URL" sleep 5 phase "starting macOS and iOS recordings" From 7e25bf1454e88100704d557aa0f43619f8e19349 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Mon, 22 Jun 2026 22:55:18 -0700 Subject: [PATCH 07/22] Launch sync video app outside reload --- scripts/ci/record-real-sync-video.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 55dc2b38ba59..8a4d3c6262f7 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -286,8 +286,13 @@ defaults write "$MAC_BUNDLE_ID" mobile.iOSPairingHost.enabled -bool true ./scripts/download-prebuilt-ghosttykit.sh || ./scripts/ensure-ghosttykit.sh MAC_RELOAD_LOG="$ARTIFACT_DIR/reload-macos.log" -phase "building and launching tagged macOS cmux" -run_with_timeout 600 bash -c './scripts/reload.sh --tag "$1" --swift-frontend-workaround --launch 2>&1 | tee "$2"' bash "$BUILD_TAG" "$MAC_RELOAD_LOG" +phase "building tagged macOS cmux" +run_with_timeout 600 bash -c './scripts/reload.sh --tag "$1" --swift-frontend-workaround 2>&1 | tee "$2"' bash "$BUILD_TAG" "$MAC_RELOAD_LOG" +MAC_APP_PATH="$(awk '/^App path:/{getline; sub(/^ /,""); print; exit}' "$MAC_RELOAD_LOG")" +[[ -n "$MAC_APP_PATH" && -d "$MAC_APP_PATH" ]] || { echo "could not locate built macOS app from $MAC_RELOAD_LOG" >&2; exit 1; } + +phase "launching tagged macOS cmux" +run_with_timeout 30 open "$MAC_APP_PATH" wait_for_socket phase "activating tagged macOS cmux" From 25d0054d52f170c29d1280515e5bb6e00819c0c9 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Mon, 22 Jun 2026 23:25:36 -0700 Subject: [PATCH 08/22] Quiet sync video CLI JSON output --- scripts/ci/record-real-sync-video.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 8a4d3c6262f7..53ede5394924 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -152,7 +152,7 @@ wait_for_socket() { } cmux_tagged() { - CMUX_TAG="$BUILD_TAG" scripts/cmux-debug-cli.sh "$@" + CMUX_QUIET=1 CMUX_TAG="$BUILD_TAG" scripts/cmux-debug-cli.sh "$@" } json_field() { From a9367fc5050a2aa23273487830e41929c375d485 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Mon, 22 Jun 2026 23:33:16 -0700 Subject: [PATCH 09/22] Use canonical workspace create for sync video --- scripts/ci/record-real-sync-video.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 53ede5394924..1d16e8a950a3 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -299,7 +299,9 @@ phase "activating tagged macOS cmux" run_with_timeout 15 osascript -e "tell application id \"$MAC_BUNDLE_ID\" to activate" >/dev/null 2>&1 || true phase "creating real cmux terminal workspace" -WORKSPACE_JSON="$(cmux_tagged --json --id-format uuids new-workspace --name "iOS sync demo" --cwd "$PWD" --focus true)" +WORKSPACE_OUTPUT="$ARTIFACT_DIR/workspace-create-output.txt" +cmux_tagged --id-format uuids workspace create --name "iOS sync demo" --cwd "$PWD" --focus true --json > "$WORKSPACE_OUTPUT" +WORKSPACE_JSON="$(cat "$WORKSPACE_OUTPUT")" WORKSPACE_ID="$(printf '%s\n' "$WORKSPACE_JSON" | json_field workspace_id)" SURFACE_ID="$(printf '%s\n' "$WORKSPACE_JSON" | json_field surface_id)" From 0b8efeaa52ab67c365706a285fd5f4c3401e6288 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Mon, 22 Jun 2026 23:39:43 -0700 Subject: [PATCH 10/22] Fix sync video JSON field parser --- scripts/ci/record-real-sync-video.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 1d16e8a950a3..0cd4203a1cc5 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -156,7 +156,7 @@ cmux_tagged() { } json_field() { - python3 - "$1" <<'PY' + python3 -c ' import json import sys @@ -168,7 +168,7 @@ if value is None: if value is None: raise SystemExit(1) print(value) -PY +' "$1" } mint_attach_url() { From af7537af779ccf170359eee0b6ae4f862ce16b75 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Mon, 22 Jun 2026 23:48:36 -0700 Subject: [PATCH 11/22] Use screencapture frames for sync video macOS recording --- scripts/ci/record-real-sync-video.sh | 41 ++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 0cd4203a1cc5..d8c79e1aba89 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -54,6 +54,7 @@ MAC_RAW_VIDEO="$ARTIFACT_DIR/cmux-macos-${BUILD_TAG}.mp4" IOS_RAW_VIDEO="$ARTIFACT_DIR/cmux-ios-${BUILD_TAG}.mp4" FINAL_VIDEO="$ARTIFACT_DIR/cmux-real-sync-left-right-${BUILD_TAG}.mp4" MAC_RECORD_LOG="$ARTIFACT_DIR/macos-record.log" +MAC_FRAME_DIR="$ARTIFACT_DIR/macos-frames" IOS_RECORD_LOG="$ARTIFACT_DIR/ios-record.log" METADATA_PATH="$ARTIFACT_DIR/metadata.json" @@ -208,19 +209,28 @@ NODE } start_macos_recording() { - local devlist - local screen_index - devlist="$(ffmpeg -f avfoundation -list_devices true -i "" 2>&1 || true)" - echo "$devlist" | grep -E "AVFoundation|Capture screen" || true - screen_index="$(echo "$devlist" | grep "Capture screen" | head -1 | sed 's/.*\[\([0-9]*\)\].*/\1/')" - screen_index="${screen_index:-0}" - ffmpeg -hide_banner -y -f avfoundation -framerate 15 -capture_cursor 1 \ - -i "${screen_index}:none" \ - -c:v libx264 -preset ultrafast -pix_fmt yuv420p \ - "$MAC_RAW_VIDEO" "$MAC_RECORD_LOG" 2>&1 & + rm -rf "$MAC_FRAME_DIR" + mkdir -p "$MAC_FRAME_DIR" + : > "$MAC_RECORD_LOG" + ( + set +e + i=0 + while true; do + frame="$(printf "%s/frame-%05d.jpg" "$MAC_FRAME_DIR" "$i")" + screencapture -x -C -t jpg "$frame" + i=$((i + 1)) + sleep 0.12 + done + ) >"$MAC_RECORD_LOG" 2>&1 & MAC_RECORDER_PID="$!" - sleep 2 - kill -0 "$MAC_RECORDER_PID" >/dev/null 2>&1 + for _ in $(seq 1 40); do + if [[ "$(find "$MAC_FRAME_DIR" -name 'frame-*.jpg' -type f | wc -l | tr -d ' ')" -ge 2 ]]; then + return 0 + fi + sleep 0.25 + done + cat "$MAC_RECORD_LOG" >&2 || true + return 1 } start_ios_recording() { @@ -245,6 +255,13 @@ stop_recorders() { wait "$MAC_RECORDER_PID" >/dev/null 2>&1 || true fi MAC_RECORDER_PID="" + local frame_count + frame_count="$(find "$MAC_FRAME_DIR" -name 'frame-*.jpg' -type f 2>/dev/null | wc -l | tr -d ' ')" + if [[ "$frame_count" -ge 2 && ! -s "$MAC_RAW_VIDEO" ]]; then + ffmpeg -hide_banner -y -framerate 8 -pattern_type glob -i "$MAC_FRAME_DIR/frame-*.jpg" \ + -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" \ + -c:v libx264 -preset ultrafast -pix_fmt yuv420p "$MAC_RAW_VIDEO" >>"$MAC_RECORD_LOG" 2>&1 + fi } stitch_videos() { From efbcb1d532694fd6437057ede002eb36a0870ecf Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 23 Jun 2026 00:07:57 -0700 Subject: [PATCH 12/22] Record macOS sync video from terminal snapshots --- scripts/ci/record-real-sync-video.sh | 85 ++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 25 deletions(-) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index d8c79e1aba89..69fb1afc93ba 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -63,16 +63,28 @@ IOS_RECORDER_PID="" SIMULATOR_ID="" SIMULATOR_CREATED="0" +stop_pid_bounded() { + local pid="$1" + local signal="${2:-INT}" + if [[ -z "$pid" ]] || ! kill -0 "$pid" >/dev/null 2>&1; then + return 0 + fi + kill "-$signal" "$pid" >/dev/null 2>&1 || true + for _ in $(seq 1 25); do + if ! kill -0 "$pid" >/dev/null 2>&1; then + wait "$pid" >/dev/null 2>&1 || true + return 0 + fi + sleep 0.2 + done + kill -KILL "$pid" >/dev/null 2>&1 || true + wait "$pid" >/dev/null 2>&1 || true +} + cleanup() { set +e - if [[ -n "$MAC_RECORDER_PID" ]] && kill -0 "$MAC_RECORDER_PID" >/dev/null 2>&1; then - kill -INT "$MAC_RECORDER_PID" >/dev/null 2>&1 || true - wait "$MAC_RECORDER_PID" >/dev/null 2>&1 || true - fi - if [[ -n "$IOS_RECORDER_PID" ]] && kill -0 "$IOS_RECORDER_PID" >/dev/null 2>&1; then - kill -INT "$IOS_RECORDER_PID" >/dev/null 2>&1 || true - wait "$IOS_RECORDER_PID" >/dev/null 2>&1 || true - fi + stop_pid_bounded "$MAC_RECORDER_PID" INT + stop_pid_bounded "$IOS_RECORDER_PID" INT if [[ -n "$SIMULATOR_ID" ]]; then xcrun simctl terminate "$SIMULATOR_ID" "$IOS_BUNDLE_ID" >/dev/null 2>&1 || true xcrun simctl shutdown "$SIMULATOR_ID" >/dev/null 2>&1 || true @@ -215,21 +227,46 @@ start_macos_recording() { ( set +e i=0 + failures=0 while true; do - frame="$(printf "%s/frame-%05d.jpg" "$MAC_FRAME_DIR" "$i")" - screencapture -x -C -t jpg "$frame" + frame="$(printf "%s/frame-%05d.png" "$MAC_FRAME_DIR" "$i")" + label="$(printf "sync-%05d" "$i")" + params="$(python3 - "$SURFACE_ID" "$label" <<'PY' +import json +import sys +print(json.dumps({"surface_id": sys.argv[1], "label": sys.argv[2]}, separators=(",", ":"))) +PY +)" + payload="$(cmux_tagged rpc debug.panel_snapshot "$params" 2>>"$MAC_RECORD_LOG")" + snapshot_path="$(printf '%s\n' "$payload" | json_field path 2>/dev/null)" + if [[ -n "$snapshot_path" && -f "$snapshot_path" ]]; then + cp "$snapshot_path" "$frame" + failures=0 + else + failures=$((failures + 1)) + echo "debug.panel_snapshot failed payload=$payload" >&2 + if [[ "$failures" -ge 10 ]]; then + exit 1 + fi + fi i=$((i + 1)) - sleep 0.12 + sleep 0.25 done ) >"$MAC_RECORD_LOG" 2>&1 & MAC_RECORDER_PID="$!" for _ in $(seq 1 40); do - if [[ "$(find "$MAC_FRAME_DIR" -name 'frame-*.jpg' -type f | wc -l | tr -d ' ')" -ge 2 ]]; then + if [[ "$(find "$MAC_FRAME_DIR" -name 'frame-*.png' -type f | wc -l | tr -d ' ')" -ge 2 ]]; then return 0 fi + if ! kill -0 "$MAC_RECORDER_PID" >/dev/null 2>&1; then + tail -80 "$MAC_RECORD_LOG" >&2 || true + return 1 + fi sleep 0.25 done - cat "$MAC_RECORD_LOG" >&2 || true + stop_pid_bounded "$MAC_RECORDER_PID" TERM + MAC_RECORDER_PID="" + tail -80 "$MAC_RECORD_LOG" >&2 || true return 1 } @@ -240,25 +277,21 @@ start_ios_recording() { grep -q "Recording started" "$IOS_RECORD_LOG" 2>/dev/null && return 0 sleep 0.25 done - cat "$IOS_RECORD_LOG" >&2 || true + stop_pid_bounded "$IOS_RECORDER_PID" TERM + IOS_RECORDER_PID="" + tail -80 "$IOS_RECORD_LOG" >&2 || true return 1 } stop_recorders() { - if [[ -n "$IOS_RECORDER_PID" ]] && kill -0 "$IOS_RECORDER_PID" >/dev/null 2>&1; then - kill -INT "$IOS_RECORDER_PID" >/dev/null 2>&1 || true - wait "$IOS_RECORDER_PID" >/dev/null 2>&1 || true - fi + stop_pid_bounded "$IOS_RECORDER_PID" INT IOS_RECORDER_PID="" - if [[ -n "$MAC_RECORDER_PID" ]] && kill -0 "$MAC_RECORDER_PID" >/dev/null 2>&1; then - kill -INT "$MAC_RECORDER_PID" >/dev/null 2>&1 || true - wait "$MAC_RECORDER_PID" >/dev/null 2>&1 || true - fi + stop_pid_bounded "$MAC_RECORDER_PID" INT MAC_RECORDER_PID="" local frame_count - frame_count="$(find "$MAC_FRAME_DIR" -name 'frame-*.jpg' -type f 2>/dev/null | wc -l | tr -d ' ')" + frame_count="$(find "$MAC_FRAME_DIR" -name 'frame-*.png' -type f 2>/dev/null | wc -l | tr -d ' ')" if [[ "$frame_count" -ge 2 && ! -s "$MAC_RAW_VIDEO" ]]; then - ffmpeg -hide_banner -y -framerate 8 -pattern_type glob -i "$MAC_FRAME_DIR/frame-*.jpg" \ + ffmpeg -hide_banner -y -framerate 4 -pattern_type glob -i "$MAC_FRAME_DIR/frame-*.png" \ -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" \ -c:v libx264 -preset ultrafast -pix_fmt yuv420p "$MAC_RAW_VIDEO" >>"$MAC_RECORD_LOG" 2>&1 fi @@ -358,7 +391,9 @@ sleep 6 cmux_tagged read-screen --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" --lines 20 > "$ARTIFACT_DIR/macos-read-screen.txt" || true xcrun simctl io "$SIMULATOR_ID" screenshot --type=png "$ARTIFACT_DIR/ios-final.png" || true -screencapture -x "$ARTIFACT_DIR/macos-final.png" || true +find "$MAC_FRAME_DIR" -name 'frame-*.png' -type f | sort | tail -1 | while read -r frame; do + cp "$frame" "$ARTIFACT_DIR/macos-final.png" +done phase "stopping recorders" stop_recorders From 7a461ba694a223f5c18f6228849f2257fd6ddbf0 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 23 Jun 2026 00:17:41 -0700 Subject: [PATCH 13/22] Launch real iOS sync video with attach env --- .github/workflows/reload-build.yml | 4 ++++ scripts/ci/record-real-sync-video.sh | 23 +++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/reload-build.yml b/.github/workflows/reload-build.yml index 008d6323dbfc..9cc0590b692a 100644 --- a/.github/workflows/reload-build.yml +++ b/.github/workflows/reload-build.yml @@ -211,6 +211,10 @@ jobs: DEVICE_FAMILY: ${{ inputs.device_family }} ARTIFACT_DIR: ${{ github.workspace }}/artifact SYNC_MARKER: real-cmux-left-right-cloud-demo + CMUX_DOGFOOD_STACK_EMAIL: ${{ secrets.CMUX_DOGFOOD_STACK_EMAIL }} + CMUX_DOGFOOD_STACK_PASSWORD: ${{ secrets.CMUX_DOGFOOD_STACK_PASSWORD }} + CMUX_UITEST_STACK_EMAIL: ${{ secrets.CMUX_UITEST_STACK_EMAIL }} + CMUX_UITEST_STACK_PASSWORD: ${{ secrets.CMUX_UITEST_STACK_PASSWORD }} run: scripts/ci/record-real-sync-video.sh # --- iOS video: run a real simulator UI test while recording the screen --- diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 69fb1afc93ba..50890188ef9b 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -231,20 +231,20 @@ start_macos_recording() { while true; do frame="$(printf "%s/frame-%05d.png" "$MAC_FRAME_DIR" "$i")" label="$(printf "sync-%05d" "$i")" - params="$(python3 - "$SURFACE_ID" "$label" <<'PY' + params="$(python3 - "$label" <<'PY' import json import sys -print(json.dumps({"surface_id": sys.argv[1], "label": sys.argv[2]}, separators=(",", ":"))) +print(json.dumps({"label": sys.argv[1]}, separators=(",", ":"))) PY )" - payload="$(cmux_tagged rpc debug.panel_snapshot "$params" 2>>"$MAC_RECORD_LOG")" + payload="$(cmux_tagged rpc debug.window.screenshot "$params" 2>>"$MAC_RECORD_LOG")" snapshot_path="$(printf '%s\n' "$payload" | json_field path 2>/dev/null)" if [[ -n "$snapshot_path" && -f "$snapshot_path" ]]; then cp "$snapshot_path" "$frame" failures=0 else failures=$((failures + 1)) - echo "debug.panel_snapshot failed payload=$payload" >&2 + echo "debug.window.screenshot failed payload=$payload" >&2 if [[ "$failures" -ge 10 ]]; then exit 1 fi @@ -368,12 +368,11 @@ ATTACH_URL="$(mint_attach_url "$WORKSPACE_ID" "$SURFACE_ID")" phase "building and installing real iOS app" run_with_timeout 600 ios/scripts/reload.sh --tag "$BUILD_TAG" --simulator "$SIMULATOR_NAME" --no-launch -phase "launching and attaching real iOS app" -xcrun simctl terminate "$SIMULATOR_ID" "$IOS_BUNDLE_ID" >/dev/null 2>&1 || true -xcrun simctl launch "$SIMULATOR_ID" "$IOS_BUNDLE_ID" >/dev/null -sleep 2 -run_with_timeout 30 xcrun simctl openurl "$SIMULATOR_ID" "$ATTACH_URL" -sleep 5 +phase "launching and auto-attaching real iOS app" +export CMUX_DOGFOOD_ATTACH_URL="$ATTACH_URL" +run_with_timeout 90 scripts/mobile-dev-launch.sh --tag "$BUILD_TAG" --simulator "$SIMULATOR_NAME" --attach --detach +unset CMUX_DOGFOOD_ATTACH_URL +sleep 10 phase "starting macOS and iOS recordings" start_macos_recording @@ -382,11 +381,11 @@ start_ios_recording phase "sending synced terminal input through real macOS cmux" cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "clear\r" sleep 1 -cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "printf 'real cmux desktop <> iOS\\n'\r" +cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "echo real cmux desktop <> iOS\r" sleep 1 cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "echo ${SYNC_MARKER}\r" sleep 4 -cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "printf 'same terminal, two clients\\n'\r" +cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "echo same terminal, two clients\r" sleep 6 cmux_tagged read-screen --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" --lines 20 > "$ARTIFACT_DIR/macos-read-screen.txt" || true From 7eaf25dae2e67c57fbcd2d3b3e5ae7d58e007b4c Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 23 Jun 2026 00:26:13 -0700 Subject: [PATCH 14/22] Allow launch attach tickets to auth mobile shell --- .github/workflows/reload-build.yml | 4 ---- .../CMUXMobileRootView.swift | 22 +++++++++++++------ scripts/ci/record-real-sync-video.sh | 6 ++--- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/reload-build.yml b/.github/workflows/reload-build.yml index 9cc0590b692a..008d6323dbfc 100644 --- a/.github/workflows/reload-build.yml +++ b/.github/workflows/reload-build.yml @@ -211,10 +211,6 @@ jobs: DEVICE_FAMILY: ${{ inputs.device_family }} ARTIFACT_DIR: ${{ github.workspace }}/artifact SYNC_MARKER: real-cmux-left-right-cloud-demo - CMUX_DOGFOOD_STACK_EMAIL: ${{ secrets.CMUX_DOGFOOD_STACK_EMAIL }} - CMUX_DOGFOOD_STACK_PASSWORD: ${{ secrets.CMUX_DOGFOOD_STACK_PASSWORD }} - CMUX_UITEST_STACK_EMAIL: ${{ secrets.CMUX_UITEST_STACK_EMAIL }} - CMUX_UITEST_STACK_PASSWORD: ${{ secrets.CMUX_UITEST_STACK_PASSWORD }} run: scripts/ci/record-real-sync-video.sh # --- iOS video: run a real simulator UI test while recording the screen --- diff --git a/Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/CMUXMobileRootView.swift b/Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/CMUXMobileRootView.swift index 6c7ff3a98512..bc8dff1c570b 100644 --- a/Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/CMUXMobileRootView.swift +++ b/Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/CMUXMobileRootView.swift @@ -96,6 +96,9 @@ struct CMUXMobileRootView: View { // so kick off the stored-Mac reconnect here too. Without this the // restoring gate could stay on RestoringSessionView forever because // nothing ever resolves `didFinishStoredMacReconnectAttempt`. + if connectUITestAttachURLIfNeeded() { + return + } reconnectStoredMacIfNeeded() } #if os(iOS) @@ -464,22 +467,27 @@ struct CMUXMobileRootView: View { #if DEBUG // Auto-pair when an attach URL is supplied at launch. Two sources: // - CMUX_DOGFOOD_ATTACH_URL (UITestConfig.dogfoodAttachURL): NOT gated on - // mock data, so it fires against the real backend. The dev-launch - // tooling (scripts/mobile-dev-launch.sh, scripts/dev-setup.sh) signs in - // for real (CMUX_UITEST_STACK_* with CMUX_UITEST_MOCK_DATA=0) and wants - // the phone to auto-pair to the freshly built Mac dev app. With mock - // off, UITestConfig.attachURL is always nil, so this dedicated accessor - // is what un-breaks real-backend auto-pair. + // mock data, so it fires against the real backend. A raw attach URL is + // handled through the same temporary-auth path as `.onOpenURL`, so + // cloud/dev launches do not need Stack credentials just to consume a + // Mac-issued attach ticket. // - CMUX_UITEST_ATTACH_URL (UITestConfig.attachURL): gated on mock data, // kept intact for the XCUITest harness. // No-op unless one of those env vars is set, so normal launches are // unaffected. guard !didConsumeUITestAttachURL, - isAuthenticated, let attachURL = UITestConfig.dogfoodAttachURL ?? UITestConfig.attachURL else { return false } didConsumeUITestAttachURL = true + if isRawAttachURL(attachURL) { + connectAttachURL(attachURL) + return true + } + guard isAuthenticated else { + pendingAttachURL = attachURL + return true + } Task { await store.connectPairingURL(attachURL) } diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 50890188ef9b..3e7cabc8e55d 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -369,9 +369,9 @@ ATTACH_URL="$(mint_attach_url "$WORKSPACE_ID" "$SURFACE_ID")" phase "building and installing real iOS app" run_with_timeout 600 ios/scripts/reload.sh --tag "$BUILD_TAG" --simulator "$SIMULATOR_NAME" --no-launch phase "launching and auto-attaching real iOS app" -export CMUX_DOGFOOD_ATTACH_URL="$ATTACH_URL" -run_with_timeout 90 scripts/mobile-dev-launch.sh --tag "$BUILD_TAG" --simulator "$SIMULATOR_NAME" --attach --detach -unset CMUX_DOGFOOD_ATTACH_URL +SIMCTL_CHILD_CMUX_UITEST_MOCK_DATA=0 \ +SIMCTL_CHILD_CMUX_DOGFOOD_ATTACH_URL="$ATTACH_URL" \ + run_with_timeout 30 xcrun simctl launch "$SIMULATOR_ID" "$IOS_BUNDLE_ID" sleep 10 phase "starting macOS and iOS recordings" From 93d1bb4c01a3d3182a421fae14300378094206a1 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 23 Jun 2026 00:36:46 -0700 Subject: [PATCH 15/22] Harden real sync video iOS launch --- scripts/ci/record-real-sync-video.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 3e7cabc8e55d..938ff8248d5e 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -371,8 +371,8 @@ run_with_timeout 600 ios/scripts/reload.sh --tag "$BUILD_TAG" --simulator "$SIMU phase "launching and auto-attaching real iOS app" SIMCTL_CHILD_CMUX_UITEST_MOCK_DATA=0 \ SIMCTL_CHILD_CMUX_DOGFOOD_ATTACH_URL="$ATTACH_URL" \ - run_with_timeout 30 xcrun simctl launch "$SIMULATOR_ID" "$IOS_BUNDLE_ID" -sleep 10 + run_with_timeout 30 xcrun simctl launch --terminate-running-process "$SIMULATOR_ID" "$IOS_BUNDLE_ID" +sleep 18 phase "starting macOS and iOS recordings" start_macos_recording @@ -381,7 +381,7 @@ start_ios_recording phase "sending synced terminal input through real macOS cmux" cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "clear\r" sleep 1 -cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "echo real cmux desktop <> iOS\r" +cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "echo real cmux desktop to iOS\r" sleep 1 cmux_tagged send --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" -- "echo ${SYNC_MARKER}\r" sleep 4 From 496d65d84315b0230ffabda097c578e293f2b910 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 23 Jun 2026 00:45:49 -0700 Subject: [PATCH 16/22] Authenticate real sync recording with fixture user --- scripts/ci/record-real-sync-video.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 938ff8248d5e..852f6bfe0ae2 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -370,6 +370,10 @@ phase "building and installing real iOS app" run_with_timeout 600 ios/scripts/reload.sh --tag "$BUILD_TAG" --simulator "$SIMULATOR_NAME" --no-launch phase "launching and auto-attaching real iOS app" SIMCTL_CHILD_CMUX_UITEST_MOCK_DATA=0 \ +SIMCTL_CHILD_CMUX_UITEST_AUTH_FIXTURE=1 \ +SIMCTL_CHILD_CMUX_UITEST_AUTH_USER_ID=cloud-recording-user \ +SIMCTL_CHILD_CMUX_UITEST_AUTH_EMAIL=cloud-recording@cmux.local \ +SIMCTL_CHILD_CMUX_UITEST_AUTH_NAME="Cloud Recording" \ SIMCTL_CHILD_CMUX_DOGFOOD_ATTACH_URL="$ATTACH_URL" \ run_with_timeout 30 xcrun simctl launch --terminate-running-process "$SIMULATOR_ID" "$IOS_BUNDLE_ID" sleep 18 From 0ce1d881fcdaacadd0c91ee2016e58066a7f4633 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 23 Jun 2026 00:54:14 -0700 Subject: [PATCH 17/22] Pass iOS launch env explicitly in sync recording --- scripts/ci/record-real-sync-video.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 852f6bfe0ae2..a00c9c949c54 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -369,13 +369,14 @@ ATTACH_URL="$(mint_attach_url "$WORKSPACE_ID" "$SURFACE_ID")" phase "building and installing real iOS app" run_with_timeout 600 ios/scripts/reload.sh --tag "$BUILD_TAG" --simulator "$SIMULATOR_NAME" --no-launch phase "launching and auto-attaching real iOS app" -SIMCTL_CHILD_CMUX_UITEST_MOCK_DATA=0 \ -SIMCTL_CHILD_CMUX_UITEST_AUTH_FIXTURE=1 \ -SIMCTL_CHILD_CMUX_UITEST_AUTH_USER_ID=cloud-recording-user \ -SIMCTL_CHILD_CMUX_UITEST_AUTH_EMAIL=cloud-recording@cmux.local \ -SIMCTL_CHILD_CMUX_UITEST_AUTH_NAME="Cloud Recording" \ -SIMCTL_CHILD_CMUX_DOGFOOD_ATTACH_URL="$ATTACH_URL" \ - run_with_timeout 30 xcrun simctl launch --terminate-running-process "$SIMULATOR_ID" "$IOS_BUNDLE_ID" +run_with_timeout 30 env \ + SIMCTL_CHILD_CMUX_UITEST_MOCK_DATA=0 \ + SIMCTL_CHILD_CMUX_UITEST_AUTH_FIXTURE=1 \ + SIMCTL_CHILD_CMUX_UITEST_AUTH_USER_ID=cloud-recording-user \ + SIMCTL_CHILD_CMUX_UITEST_AUTH_EMAIL=cloud-recording@cmux.local \ + "SIMCTL_CHILD_CMUX_UITEST_AUTH_NAME=Cloud Recording" \ + "SIMCTL_CHILD_CMUX_DOGFOOD_ATTACH_URL=$ATTACH_URL" \ + xcrun simctl launch --terminate-running-process "$SIMULATOR_ID" "$IOS_BUNDLE_ID" sleep 18 phase "starting macOS and iOS recordings" From 5fdca2c7012f3a7b3ec2097086e58464ecf78def Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 23 Jun 2026 01:03:35 -0700 Subject: [PATCH 18/22] Read dogfood attach URL from iOS launch args --- .../CmuxMobileSupport/UITestConfig.swift | 29 +++++++++-- .../UITestConfigTests.swift | 48 +++++++++++++++++++ scripts/ci/record-real-sync-video.sh | 3 +- 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/Packages/iOS/CmuxMobileSupport/Sources/CmuxMobileSupport/UITestConfig.swift b/Packages/iOS/CmuxMobileSupport/Sources/CmuxMobileSupport/UITestConfig.swift index 49ea7307eb9f..16e2d19004e5 100644 --- a/Packages/iOS/CmuxMobileSupport/Sources/CmuxMobileSupport/UITestConfig.swift +++ b/Packages/iOS/CmuxMobileSupport/Sources/CmuxMobileSupport/UITestConfig.swift @@ -45,7 +45,10 @@ public struct UITestConfig { /// is always `nil`, so a dedicated, not-mock-gated accessor is required for the /// real-backend auto-pair path to fire. DEBUG-only; always `nil` in release. public static var dogfoodAttachURL: String? { - dogfoodAttachURL(from: ProcessInfo.processInfo.environment) + dogfoodAttachURL( + from: ProcessInfo.processInfo.environment, + arguments: ProcessInfo.processInfo.arguments + ) } /// The dogfood attach URL for an explicit environment, not gated on mock data. @@ -53,13 +56,18 @@ public struct UITestConfig { /// - Parameter env: The environment dictionary to read. /// - Returns: The trimmed value of `CMUX_DOGFOOD_ATTACH_URL` when present and /// non-empty; otherwise `nil`. Always `nil` in release builds. - public static func dogfoodAttachURL(from env: [String: String]) -> String? { + public static func dogfoodAttachURL( + from env: [String: String], + arguments: [String] = [] + ) -> String? { #if DEBUG // Read the env directly, NOT through the mock-gated value(for:), so the // URL is returned with CMUX_UITEST_MOCK_DATA=0 (the real-backend // dev-launch path) and iOS auto-pair actually fires. - let value = env["CMUX_DOGFOOD_ATTACH_URL"]?.trimmingCharacters(in: .whitespacesAndNewlines) - return value?.isEmpty == false ? value : nil + if let value = trimmedNonEmpty(env["CMUX_DOGFOOD_ATTACH_URL"]) { + return value + } + return argumentValue(for: "--cmux-dogfood-attach-url", arguments: arguments) #else return nil #endif @@ -139,4 +147,17 @@ public struct UITestConfig { private static func value(for key: String) -> String? { value(for: key, env: ProcessInfo.processInfo.environment) } + + private static func trimmedNonEmpty(_ value: String?) -> String? { + let trimmed = value?.trimmingCharacters(in: .whitespacesAndNewlines) + return trimmed?.isEmpty == false ? trimmed : nil + } + + private static func argumentValue(for key: String, arguments: [String]) -> String? { + guard let index = arguments.firstIndex(of: key), + arguments.indices.contains(arguments.index(after: index)) else { + return nil + } + return trimmedNonEmpty(arguments[arguments.index(after: index)]) + } } diff --git a/Packages/iOS/CmuxMobileSupport/Tests/CmuxMobileSupportTests/UITestConfigTests.swift b/Packages/iOS/CmuxMobileSupport/Tests/CmuxMobileSupportTests/UITestConfigTests.swift index 8f97c8c970ad..f33461ff65bb 100644 --- a/Packages/iOS/CmuxMobileSupport/Tests/CmuxMobileSupportTests/UITestConfigTests.swift +++ b/Packages/iOS/CmuxMobileSupport/Tests/CmuxMobileSupportTests/UITestConfigTests.swift @@ -103,6 +103,54 @@ import Testing #endif } + @Test func dogfoodAttachURLCanComeFromLaunchArgument() { + let arguments = [ + "/path/cmux", + "--cmux-dogfood-attach-url", + " cmux-ios-dev://attach?v=1&payload=arg ", + ] + #if DEBUG + #expect( + UITestConfig.dogfoodAttachURL(from: [:], arguments: arguments) + == "cmux-ios-dev://attach?v=1&payload=arg" + ) + #else + #expect(UITestConfig.dogfoodAttachURL(from: [:], arguments: arguments) == nil) + #endif + } + + @Test func dogfoodAttachURLEnvironmentWinsOverLaunchArgument() { + let env = ["CMUX_DOGFOOD_ATTACH_URL": "cmux-ios://attach?v=1&payload=env"] + let arguments = [ + "/path/cmux", + "--cmux-dogfood-attach-url", + "cmux-ios-dev://attach?v=1&payload=arg", + ] + #if DEBUG + #expect( + UITestConfig.dogfoodAttachURL(from: env, arguments: arguments) + == "cmux-ios://attach?v=1&payload=env" + ) + #else + #expect(UITestConfig.dogfoodAttachURL(from: env, arguments: arguments) == nil) + #endif + } + + @Test func dogfoodAttachURLIsNilWhenLaunchArgumentValueIsMissingOrBlank() { + #expect( + UITestConfig.dogfoodAttachURL( + from: [:], + arguments: ["/path/cmux", "--cmux-dogfood-attach-url"] + ) == nil + ) + #expect( + UITestConfig.dogfoodAttachURL( + from: [:], + arguments: ["/path/cmux", "--cmux-dogfood-attach-url", " "] + ) == nil + ) + } + @Test func dogfoodAttachURLIsNilWhenAbsent() { #expect(UITestConfig.dogfoodAttachURL(from: [:]) == nil) } diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index a00c9c949c54..18665ca070c8 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -376,7 +376,8 @@ run_with_timeout 30 env \ SIMCTL_CHILD_CMUX_UITEST_AUTH_EMAIL=cloud-recording@cmux.local \ "SIMCTL_CHILD_CMUX_UITEST_AUTH_NAME=Cloud Recording" \ "SIMCTL_CHILD_CMUX_DOGFOOD_ATTACH_URL=$ATTACH_URL" \ - xcrun simctl launch --terminate-running-process "$SIMULATOR_ID" "$IOS_BUNDLE_ID" + xcrun simctl launch --terminate-running-process "$SIMULATOR_ID" "$IOS_BUNDLE_ID" \ + --cmux-dogfood-attach-url "$ATTACH_URL" sleep 18 phase "starting macOS and iOS recordings" From afa5a687a9cb54ff2ed78ea5b0c1150dc093f3c8 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 23 Jun 2026 01:13:19 -0700 Subject: [PATCH 19/22] Seed iOS attach URL through launch defaults --- .../CmuxMobileSupport/UITestConfig.swift | 16 ++++++- .../UITestConfigTests.swift | 47 +++++++++++++++++++ scripts/ci/record-real-sync-video.sh | 19 ++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/Packages/iOS/CmuxMobileSupport/Sources/CmuxMobileSupport/UITestConfig.swift b/Packages/iOS/CmuxMobileSupport/Sources/CmuxMobileSupport/UITestConfig.swift index 16e2d19004e5..3cdc0e250536 100644 --- a/Packages/iOS/CmuxMobileSupport/Sources/CmuxMobileSupport/UITestConfig.swift +++ b/Packages/iOS/CmuxMobileSupport/Sources/CmuxMobileSupport/UITestConfig.swift @@ -47,7 +47,8 @@ public struct UITestConfig { public static var dogfoodAttachURL: String? { dogfoodAttachURL( from: ProcessInfo.processInfo.environment, - arguments: ProcessInfo.processInfo.arguments + arguments: ProcessInfo.processInfo.arguments, + defaults: .standard ) } @@ -59,6 +60,14 @@ public struct UITestConfig { public static func dogfoodAttachURL( from env: [String: String], arguments: [String] = [] + ) -> String? { + dogfoodAttachURL(from: env, arguments: arguments, defaults: nil) + } + + static func dogfoodAttachURL( + from env: [String: String], + arguments: [String] = [], + defaults: UserDefaults? ) -> String? { #if DEBUG // Read the env directly, NOT through the mock-gated value(for:), so the @@ -67,7 +76,10 @@ public struct UITestConfig { if let value = trimmedNonEmpty(env["CMUX_DOGFOOD_ATTACH_URL"]) { return value } - return argumentValue(for: "--cmux-dogfood-attach-url", arguments: arguments) + if let value = argumentValue(for: "--cmux-dogfood-attach-url", arguments: arguments) { + return value + } + return trimmedNonEmpty(defaults?.string(forKey: "CMUX_DOGFOOD_ATTACH_URL")) #else return nil #endif diff --git a/Packages/iOS/CmuxMobileSupport/Tests/CmuxMobileSupportTests/UITestConfigTests.swift b/Packages/iOS/CmuxMobileSupport/Tests/CmuxMobileSupportTests/UITestConfigTests.swift index f33461ff65bb..e995d1188e29 100644 --- a/Packages/iOS/CmuxMobileSupport/Tests/CmuxMobileSupportTests/UITestConfigTests.swift +++ b/Packages/iOS/CmuxMobileSupport/Tests/CmuxMobileSupportTests/UITestConfigTests.swift @@ -1,4 +1,5 @@ import Testing +import Foundation @testable import CmuxMobileSupport @Suite struct UITestConfigTests { @@ -136,6 +137,41 @@ import Testing #endif } + @Test func dogfoodAttachURLCanComeFromUserDefaults() { + let (suiteName, defaults) = temporaryDefaults() + defaults.set(" cmux-ios-dev://attach?v=1&payload=defaults ", forKey: "CMUX_DOGFOOD_ATTACH_URL") + defer { defaults.removePersistentDomain(forName: suiteName) } + + #if DEBUG + #expect( + UITestConfig.dogfoodAttachURL(from: [:], defaults: defaults) + == "cmux-ios-dev://attach?v=1&payload=defaults" + ) + #else + #expect(UITestConfig.dogfoodAttachURL(from: [:], defaults: defaults) == nil) + #endif + } + + @Test func dogfoodAttachURLLaunchArgumentWinsOverUserDefaults() { + let (suiteName, defaults) = temporaryDefaults() + defaults.set("cmux-ios-dev://attach?v=1&payload=defaults", forKey: "CMUX_DOGFOOD_ATTACH_URL") + defer { defaults.removePersistentDomain(forName: suiteName) } + let arguments = [ + "/path/cmux", + "--cmux-dogfood-attach-url", + "cmux-ios-dev://attach?v=1&payload=arg", + ] + + #if DEBUG + #expect( + UITestConfig.dogfoodAttachURL(from: [:], arguments: arguments, defaults: defaults) + == "cmux-ios-dev://attach?v=1&payload=arg" + ) + #else + #expect(UITestConfig.dogfoodAttachURL(from: [:], arguments: arguments, defaults: defaults) == nil) + #endif + } + @Test func dogfoodAttachURLIsNilWhenLaunchArgumentValueIsMissingOrBlank() { #expect( UITestConfig.dogfoodAttachURL( @@ -159,4 +195,15 @@ import Testing let env = ["CMUX_DOGFOOD_ATTACH_URL": " "] #expect(UITestConfig.dogfoodAttachURL(from: env) == nil) } + + private func temporaryDefaults() -> (String, UserDefaults) { + let name = defaultsSuiteName + let defaults = UserDefaults(suiteName: name)! + defaults.removePersistentDomain(forName: name) + return (name, defaults) + } + + private var defaultsSuiteName: String { + "UITestConfigTests.\(UUID().uuidString)" + } } diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 18665ca070c8..6b464dacfe86 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -368,6 +368,25 @@ ATTACH_URL="$(mint_attach_url "$WORKSPACE_ID" "$SURFACE_ID")" phase "building and installing real iOS app" run_with_timeout 600 ios/scripts/reload.sh --tag "$BUILD_TAG" --simulator "$SIMULATOR_NAME" --no-launch +phase "seeding iOS attach launch defaults" +IOS_DATA_CONTAINER="$(run_with_timeout 30 xcrun simctl get_app_container "$SIMULATOR_ID" "$IOS_BUNDLE_ID" data)" +IOS_PREFS_PLIST="$IOS_DATA_CONTAINER/Library/Preferences/${IOS_BUNDLE_ID}.plist" +mkdir -p "$(dirname "$IOS_PREFS_PLIST")" +python3 - "$IOS_PREFS_PLIST" "$ATTACH_URL" <<'PY' +import plistlib +import sys +from pathlib import Path + +path = Path(sys.argv[1]) +attach_url = sys.argv[2] +data = {} +if path.exists(): + with path.open("rb") as handle: + data = plistlib.load(handle) +data["CMUX_DOGFOOD_ATTACH_URL"] = attach_url +with path.open("wb") as handle: + plistlib.dump(data, handle) +PY phase "launching and auto-attaching real iOS app" run_with_timeout 30 env \ SIMCTL_CHILD_CMUX_UITEST_MOCK_DATA=0 \ From 3879cd8933a804513c4fcaad61ca612d7f4f5d19 Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 23 Jun 2026 03:22:27 -0700 Subject: [PATCH 20/22] Capture iOS attach diagnostics in sync recording --- .../CMUXMobileRootView.swift | 20 ++++++++++ scripts/ci/record-real-sync-video.sh | 37 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/CMUXMobileRootView.swift b/Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/CMUXMobileRootView.swift index bc8dff1c570b..fd8acf1d7145 100644 --- a/Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/CMUXMobileRootView.swift +++ b/Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/CMUXMobileRootView.swift @@ -4,6 +4,7 @@ import CmuxMobileShell import CmuxMobileShellModel import CmuxMobileSupport import CmuxMobileWorkspace +import OSLog import SwiftUI #if os(iOS) @preconcurrency import UIKit @@ -11,6 +12,8 @@ import SwiftUI import AppKit #endif +private let mobileRootLog = Logger(subsystem: "ai.manaflow.cmux", category: "mobile.root") + struct CMUXMobileRootView: View { @Bindable var store: CMUXMobileShellStore @Environment(\.scenePhase) private var scenePhase @@ -368,13 +371,16 @@ struct CMUXMobileRootView: View { private func connectAttachURL(_ rawURL: String) { guard !authManager.isRestoringSession else { + mobileRootLog.debug("parking attach URL while auth session restores") pendingAttachURL = rawURL return } + mobileRootLog.debug("connecting raw attach URL") didAuthenticateWithAttachTicket = true syncShellAuthentication(true) Task { let result = await store.connectPairingURLResult(rawURL) + mobileRootLog.debug("raw attach URL connection finished: \(attachResultDescription(result), privacy: .public)") if result == .needsUserApproval { isShowingAddDeviceSheet = true } @@ -480,6 +486,7 @@ struct CMUXMobileRootView: View { return false } didConsumeUITestAttachURL = true + mobileRootLog.debug("consuming launch attach URL") if isRawAttachURL(attachURL) { connectAttachURL(attachURL) return true @@ -496,4 +503,17 @@ struct CMUXMobileRootView: View { return false #endif } + + private func attachResultDescription(_ result: MobilePairingURLConnectionResult) -> String { + switch result { + case .connected: + return "connected" + case .failed: + return "failed" + case .needsUserApproval: + return "needsUserApproval" + case .superseded: + return "superseded" + } + } } diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 6b464dacfe86..c1ea91aadbab 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -56,10 +56,13 @@ FINAL_VIDEO="$ARTIFACT_DIR/cmux-real-sync-left-right-${BUILD_TAG}.mp4" MAC_RECORD_LOG="$ARTIFACT_DIR/macos-record.log" MAC_FRAME_DIR="$ARTIFACT_DIR/macos-frames" IOS_RECORD_LOG="$ARTIFACT_DIR/ios-record.log" +IOS_SIMULATOR_LOG="$ARTIFACT_DIR/ios-simulator.log" +IOS_SEEDED_DEFAULTS="$ARTIFACT_DIR/ios-seeded-defaults.txt" METADATA_PATH="$ARTIFACT_DIR/metadata.json" MAC_RECORDER_PID="" IOS_RECORDER_PID="" +IOS_LOG_PID="" SIMULATOR_ID="" SIMULATOR_CREATED="0" @@ -85,6 +88,7 @@ cleanup() { set +e stop_pid_bounded "$MAC_RECORDER_PID" INT stop_pid_bounded "$IOS_RECORDER_PID" INT + stop_pid_bounded "$IOS_LOG_PID" INT if [[ -n "$SIMULATOR_ID" ]]; then xcrun simctl terminate "$SIMULATOR_ID" "$IOS_BUNDLE_ID" >/dev/null 2>&1 || true xcrun simctl shutdown "$SIMULATOR_ID" >/dev/null 2>&1 || true @@ -283,11 +287,24 @@ start_ios_recording() { return 1 } +start_ios_log_capture() { + rm -f "$IOS_SIMULATOR_LOG" + xcrun simctl spawn "$SIMULATOR_ID" log stream \ + --style compact \ + --level debug \ + --predicate 'process == "cmux" OR subsystem == "ai.manaflow.cmux"' \ + >"$IOS_SIMULATOR_LOG" 2>&1 & + IOS_LOG_PID="$!" + sleep 1 +} + stop_recorders() { stop_pid_bounded "$IOS_RECORDER_PID" INT IOS_RECORDER_PID="" stop_pid_bounded "$MAC_RECORDER_PID" INT MAC_RECORDER_PID="" + stop_pid_bounded "$IOS_LOG_PID" INT + IOS_LOG_PID="" local frame_count frame_count="$(find "$MAC_FRAME_DIR" -name 'frame-*.png' -type f 2>/dev/null | wc -l | tr -d ' ')" if [[ "$frame_count" -ge 2 && ! -s "$MAC_RAW_VIDEO" ]]; then @@ -387,6 +404,26 @@ data["CMUX_DOGFOOD_ATTACH_URL"] = attach_url with path.open("wb") as handle: plistlib.dump(data, handle) PY +run_with_timeout 30 xcrun simctl spawn "$SIMULATOR_ID" defaults write "$IOS_BUNDLE_ID" CMUX_DOGFOOD_ATTACH_URL "$ATTACH_URL" +run_with_timeout 30 xcrun simctl spawn "$SIMULATOR_ID" launchctl setenv CMUX_DOGFOOD_ATTACH_URL "$ATTACH_URL" +python3 - "$IOS_PREFS_PLIST" "$IOS_SEEDED_DEFAULTS" <<'PY' +import plistlib +import sys +from pathlib import Path + +path = Path(sys.argv[1]) +out = Path(sys.argv[2]) +has_attach_url = False +attach_url_length = 0 +if path.exists(): + with path.open("rb") as handle: + data = plistlib.load(handle) + value = data.get("CMUX_DOGFOOD_ATTACH_URL") + has_attach_url = isinstance(value, str) and bool(value.strip()) + attach_url_length = len(value) if isinstance(value, str) else 0 +out.write_text(f"hasAttachURL={str(has_attach_url).lower()}\nattachURLLength={attach_url_length}\n") +PY +start_ios_log_capture phase "launching and auto-attaching real iOS app" run_with_timeout 30 env \ SIMCTL_CHILD_CMUX_UITEST_MOCK_DATA=0 \ From c805cba86f722ea87978ea9bece589f17b7d67bb Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 23 Jun 2026 03:34:18 -0700 Subject: [PATCH 21/22] Use debug mobile auth token for sync recording --- scripts/ci/record-real-sync-video.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index c1ea91aadbab..0a0fe6229955 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -5,6 +5,7 @@ BUILD_TAG="${BUILD_TAG:?BUILD_TAG is required}" DEVICE_FAMILY="${DEVICE_FAMILY:-iphone}" ARTIFACT_DIR="${ARTIFACT_DIR:-$PWD/artifact}" SYNC_MARKER="${SYNC_MARKER:-cmux-real-sync-video}" +DEV_STACK_AUTH_TOKEN="${CMUX_MOBILE_DEV_STACK_AUTH_TOKEN:-cmux-cloud-sync-video-token}" mkdir -p "$ARTIFACT_DIR" @@ -372,6 +373,16 @@ WORKSPACE_JSON="$(cat "$WORKSPACE_OUTPUT")" WORKSPACE_ID="$(printf '%s\n' "$WORKSPACE_JSON" | json_field workspace_id)" SURFACE_ID="$(printf '%s\n' "$WORKSPACE_JSON" | json_field surface_id)" +phase "configuring debug mobile Stack auth token" +DEV_STACK_AUTH_PARAMS="$(python3 - "$DEV_STACK_AUTH_TOKEN" <<'PY' +import json +import sys + +print(json.dumps({"token": sys.argv[1]}, separators=(",", ":"))) +PY +)" +cmux_tagged rpc mobile.dev_stack_auth.configure "$DEV_STACK_AUTH_PARAMS" >/dev/null + for _ in $(seq 1 40); do if cmux_tagged read-screen --workspace "$WORKSPACE_ID" --surface "$SURFACE_ID" --lines 5 >/dev/null 2>&1; then break @@ -431,6 +442,7 @@ run_with_timeout 30 env \ SIMCTL_CHILD_CMUX_UITEST_AUTH_USER_ID=cloud-recording-user \ SIMCTL_CHILD_CMUX_UITEST_AUTH_EMAIL=cloud-recording@cmux.local \ "SIMCTL_CHILD_CMUX_UITEST_AUTH_NAME=Cloud Recording" \ + "SIMCTL_CHILD_CMUX_MOBILE_DEV_STACK_AUTH_TOKEN=$DEV_STACK_AUTH_TOKEN" \ "SIMCTL_CHILD_CMUX_DOGFOOD_ATTACH_URL=$ATTACH_URL" \ xcrun simctl launch --terminate-running-process "$SIMULATOR_ID" "$IOS_BUNDLE_ID" \ --cmux-dogfood-attach-url "$ATTACH_URL" @@ -481,6 +493,7 @@ path.write_text(json.dumps({ "workspaceId": "$WORKSPACE_ID", "surfaceId": "$SURFACE_ID", "syncMarker": "$SYNC_MARKER", + "usesDebugMobileStackAuthToken": True, "video": "$(basename "$FINAL_VIDEO")", "macVideo": "$(basename "$MAC_RAW_VIDEO")", "iosVideo": "$(basename "$IOS_RAW_VIDEO")", From 0af62f1f29524538a30b804b74a9d8d43376de7e Mon Sep 17 00:00:00 2001 From: lawrencecchen <54008264+lawrencecchen@users.noreply.github.com> Date: Tue, 23 Jun 2026 03:44:14 -0700 Subject: [PATCH 22/22] Open iOS workspace in sync recording --- scripts/ci/record-real-sync-video.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/ci/record-real-sync-video.sh b/scripts/ci/record-real-sync-video.sh index 0a0fe6229955..58f428878ace 100755 --- a/scripts/ci/record-real-sync-video.sh +++ b/scripts/ci/record-real-sync-video.sh @@ -443,6 +443,7 @@ run_with_timeout 30 env \ SIMCTL_CHILD_CMUX_UITEST_AUTH_EMAIL=cloud-recording@cmux.local \ "SIMCTL_CHILD_CMUX_UITEST_AUTH_NAME=Cloud Recording" \ "SIMCTL_CHILD_CMUX_MOBILE_DEV_STACK_AUTH_TOKEN=$DEV_STACK_AUTH_TOKEN" \ + SIMCTL_CHILD_CMUX_MOBILE_SOAK_OPEN_SELECTED_WORKSPACE=1 \ "SIMCTL_CHILD_CMUX_DOGFOOD_ATTACH_URL=$ATTACH_URL" \ xcrun simctl launch --terminate-running-process "$SIMULATOR_ID" "$IOS_BUNDLE_ID" \ --cmux-dogfood-attach-url "$ATTACH_URL"