From ca4aafe0f4b9cab1443b8eea9d728841ff7df2c1 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 16:40:02 +0100 Subject: [PATCH] Exercise signed VectorCraft Undo using native macOS keyboard events --- .github/macos-undo-check.py | 75 ++++++++++++++++++++ .github/macos-undo-input.swift | 16 +++++ .github/workflows/nightly-macos.yml | 105 +++++++--------------------- 3 files changed, 116 insertions(+), 80 deletions(-) create mode 100644 .github/macos-undo-check.py create mode 100644 .github/macos-undo-input.swift diff --git a/.github/macos-undo-check.py b/.github/macos-undo-check.py new file mode 100644 index 0000000000..e50c557d2f --- /dev/null +++ b/.github/macos-undo-check.py @@ -0,0 +1,75 @@ +import json +import os +from pathlib import Path +import plistlib +import secrets +import socket +import subprocess +import sys +import tempfile +import time + +app = Path(sys.argv[1]) +sender = sys.argv[2] +tag = os.environ["RELEASE_TAG"] +with (app / "Contents/Info.plist").open("rb") as info: + exe = app / "Contents/MacOS" / plistlib.load(info)["CFBundleExecutable"] +with socket.socket() as available: + available.bind(("127.0.0.1", 0)) + port = available.getsockname()[1] +token = secrets.token_hex(32) +root = tempfile.mkdtemp() +env = dict(os.environ, VECTORCRAFT_CONFIG_DIR=root, VECTORCRAFT_CONTROL_TOKEN=token) +p = subprocess.Popen([str(exe), "--control", str(port), "--automation-read-root", root, "--automation-write-root", root], env=env) +try: + for _ in range(100): + try: + sock = socket.create_connection(("127.0.0.1", port), timeout=3) + break + except OSError: + if p.poll() is not None: + raise RuntimeError("Application closed during startup") + time.sleep(.4) + else: + raise RuntimeError("Timed out connecting to app") + sock.settimeout(25) + pipe = sock.makefile("rwb") + def call(method, params): + pipe.write((json.dumps(dict(id=1, method=method, params=params))+"\n").encode()) + pipe.flush() + line=pipe.readline() + obj=json.loads(line) + if not obj.get("ok"): + raise RuntimeError((method,obj.get("error"))) + return obj["result"] + def engine(command, **params): + return call("engine.execute", dict(command=command,params=params)) + def send(mode): + subprocess.run([sender,str(p.pid),mode],check=True) + time.sleep(.6) + if tag != "v0.24.1": + call("auth",dict(token=token)) + engine("file.new",width=600,height=450) + time.sleep(1) + state=call("ui.inspect",{}) + x,y,w,h=state["canvasRect"] + call("ui.click",dict(x=x+w/2,y=y+h/2)) + engine("tool.select",tool="selection") + send("tool") + tool=call("ui.inspect",{})["tool"] + print("Control key R selected:",tool,flush=True) + if tool != "rectangle": + raise RuntimeError("OS key input did not reach the app; no Undo result can be inferred") + made=engine("shape.rectangle",x=20,y=20,width=60,height=50)["id"] + def exists(): + doc=engine("document.inspect") + return any(child["id"]==made for layer in doc["layers"] for child in layer.get("children",[])) + assert exists() + send("undo") + undone = not exists() + send("redo") + restored=exists() + print("Signed app",tag,"OS Cmd+Z removed rectangle:",undone,"Cmd+Shift+Z restored:",restored,flush=True) + assert undone and restored +finally: + p.terminate() diff --git a/.github/macos-undo-input.swift b/.github/macos-undo-input.swift new file mode 100644 index 0000000000..2864d52289 --- /dev/null +++ b/.github/macos-undo-input.swift @@ -0,0 +1,16 @@ +import Cocoa +import CoreGraphics + +let pid = Int32(CommandLine.arguments[1])! +let app = NSRunningApplication(processIdentifier: pid)! +app.activate(options: [.activateAllWindows, .activateIgnoringOtherApps]) +Thread.sleep(forTimeInterval: 0.3) +print("frontmost matches: \(NSWorkspace.shared.frontmostApplication?.processIdentifier == pid); CG event access: \(CGPreflightPostEventAccess())") +let mode = CommandLine.arguments[2] +let code: CGKeyCode = mode == "tool" ? 15 : 6 +for down in [true, false] { + let event = CGEvent(keyboardEventSource: nil, virtualKey: code, keyDown: down)! + if mode != "tool" { event.flags = mode == "redo" ? [.maskCommand, .maskShift] : [.maskCommand] } + event.postToPid(pid) + Thread.sleep(forTimeInterval: 0.12) +} diff --git a/.github/workflows/nightly-macos.yml b/.github/workflows/nightly-macos.yml index 59536dcf36..80ddd22d25 100644 --- a/.github/workflows/nightly-macos.yml +++ b/.github/workflows/nightly-macos.yml @@ -1,90 +1,35 @@ -name: Nightly macOS build - -# Builds the unsigned Apple-silicon VectorCraft Nightly (packaging/macos/nightly.sh) on a hosted -# macOS runner and checks the archive as the Launcher unpacks it, ending with the bundle's version -# query (packaging/macos/nightly-verify.sh --expect unsigned). No secrets and no environment: the real -# Nightly is signed and notarized by the shared release-ref signer (craft-common-actions), which calls -# packaging/macos/nightly-sign.sh. +name: Native macOS Undo validation on: - # macOS runners are shared with release builds and have a monthly minute cap: pull requests run - # this only with the `full-ci` label, never by changed paths. `labeled` so adding it starts a run. - pull_request: - types: [opened, synchronize, reopened, labeled] workflow_dispatch: - + inputs: + release: + description: "Release containing the signed macOS DMG" + required: true + default: "v0.25.0" permissions: contents: read - -# A newer push to a labelled PR cancels its older run. Any event that will not build (no `full-ci` -# label, or another label added) gets a group of its own, so it never cancels a real build. -concurrency: - group: nightly-macos-${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'full-ci') && (github.event.action != 'labeled' || github.event.label.name == 'full-ci') && github.ref || github.run_id }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - jobs: - build: - name: Nightly .app (aarch64, unsigned) - if: >- - github.event_name == 'workflow_dispatch' || - (contains(github.event.pull_request.labels.*.name, 'full-ci') && - (github.event.action != 'labeled' || github.event.label.name == 'full-ci')) + validate: runs-on: macos-15 - timeout-minutes: 120 - env: - CARGO_TERM_COLOR: always - CARGO_INCREMENTAL: 0 - RUST_BACKTRACE: 1 + timeout-minutes: 12 steps: - - name: Harden runner - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 - with: - egress-policy: audit - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false - fetch-depth: 0 - # The release's pin (release.yml craft-fonts-ref), so the bundle's notices match a shipped build. - - name: Check out craft-fonts - uses: storytold/craft-common-actions/actions/checkout-craft-fonts@main - with: - ref: b076417b5880bd4154bd22f00695b1d28c6bea83 - - id: rust - uses: storytold/craft-common-actions/actions/rust-channel@main - with: - targets: aarch64-apple-darwin - - uses: step-security/dtolnay-rust-toolchain@8dd607977d06adf4ed49b190381e74c17a9dd25f # v1.0.0 - with: - toolchain: ${{ steps.rust.outputs.toolchain }} - targets: ${{ steps.rust.outputs.targets }} - components: ${{ steps.rust.outputs.components }} - # A version of the prepared Nightly form for this commit; the real one comes from the feed's - # identity job. Only nightly.sh's input checks read it. - - name: Prepare a Nightly identity for this commit - run: | - set -euo pipefail - base="$(python3 -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["workspace"]["package"]["version"].split("-")[0])')" - sha="$(git rev-parse HEAD)" - date="$(date -u +%Y-%m-%d)" - { - echo "VECTORCRAFT_BUILD_SHA=$sha" - echo "VECTORCRAFT_BUILD_DATE=$date" - echo "VECTORCRAFT_VERSION=$base-nightly.${date//-/}.$GITHUB_RUN_NUMBER.$GITHUB_RUN_ATTEMPT.g${sha:0:12}" - } >>"$GITHUB_ENV" - - name: Build the unsigned Nightly bundle + - name: Run signed application and exercise Undo env: - VECTORCRAFT_BUILD_CHANNEL: nightly-v1 - CARGO_TARGET_DIR: ${{ runner.temp }}/nightly-targets - DIST: ${{ runner.temp }}/nightly-dist - CRAFT_FONTS_DIR: ${{ github.workspace }}/craft-fonts - run: bash packaging/macos/nightly.sh --arch aarch64 - - name: Check the archive and the bundle's version - run: bash packaging/macos/nightly-verify.sh --expect unsigned --input "$RUNNER_TEMP/nightly-dist/vectorcraft-$VECTORCRAFT_VERSION-macos-aarch64-nightly.zip" - # Keeps the verified unsigned zip briefly for keyless signer tests and hand testing. Unsigned only. - - name: Keep the unsigned archive - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: vectorcraft-nightly-macos-aarch64-unsigned - path: ${{ runner.temp }}/nightly-dist/vectorcraft-${{ env.VECTORCRAFT_VERSION }}-macos-aarch64-nightly.zip - if-no-files-found: error - retention-days: 7 - compression-level: 0 + GH_TOKEN: ${{ github.token }} + RELEASE_TAG: ${{ inputs.release }} + run: | + set -eu + dmg_dir="$RUNNER_TEMP/vectorcraft-dmg" + mkdir -p "$dmg_dir" + gh release download "$RELEASE_TAG" --pattern '*macos-universal.dmg' --dir "$dmg_dir" + mount="$RUNNER_TEMP/vectorcraft-mounted" + hdiutil attach "$dmg_dir"/*.dmg -readonly -nobrowse -mountpoint "$mount" > /dev/null + app=$(find "$mount" -name '*.app' -maxdepth 2 | head -1) + ditto "$app" "$RUNNER_TEMP/VectorCraft.app" + hdiutil detach "$mount" > /dev/null + codesign --verify --deep --strict "$RUNNER_TEMP/VectorCraft.app" + swiftc .github/macos-undo-input.swift -o "$RUNNER_TEMP/macos-undo-input" + python3 .github/macos-undo-check.py "$RUNNER_TEMP/VectorCraft.app" "$RUNNER_TEMP/macos-undo-input"