#!/usr/bin/env python3 """Authored Foundation-only bundle fixtures; no NSApplication, UI, sockets or personal data.""" from pathlib import Path import os, plistlib, shutil, subprocess, tempfile repo = Path(__file__).resolve().parents[3] with tempfile.TemporaryDirectory(prefix="vcc-cv-", dir="/private/tmp") as folder: work = Path(folder) env = dict(os.environ, DEVELOPER_DIR=os.environ.get("DEVELOPER_DIR", "/Applications/Xcode.app/Contents/Developer")) def compile(name, debug): target = work / name command = ["xcrun", "swiftc", "-swift-version", "6", "-strict-concurrency=complete", "-module-cache-path", str(work / "module-cache"), "-parse-as-library"] if debug: command += ["-D", "DEBUG"] command += [str(repo / "platforms/macos/Companion/CompanionTransport.swift"), str(repo / "platforms/macos/Companion/CompanionValidation.swift"), str(repo / "tests/macos/companion/ValidationChecks.swift"), "-o", str(target)] subprocess.run(command, env=env, check=True) return target debug, release = compile("debug", True), compile("release", False) def bundle(name, identifier, executable=debug): root = work / (name + ".app") contents = root / "Contents" (contents / "MacOS").mkdir(parents=True) (contents / "Info.plist").write_bytes(plistlib.dumps({"CFBundleIdentifier": identifier, "CFBundleExecutable": "check", "CFBundlePackageType": "APPL"})) shutil.copyfile(executable, contents / "MacOS/check") (contents / "MacOS/check").chmod(0o700) return root vcc = bundle("VCC", "com.brianholman.vccplus.oss.mac.uitesting") dw = bundle("DriveWire", "com.brianholman.vccplus.oss.drivewire.companionpreview") production = bundle("Production", "com.brianholman.vccplus.oss.mac") rel = bundle("Release", "com.brianholman.vccplus.oss.mac.uitesting", release) private = work / "private"; private.mkdir(mode=0o700) public = work / "public"; public.mkdir(mode=0o755) symlink = work / "linked"; symlink.symlink_to(private) base = ["--companion-validation-root", str(private)] def run(app, args): subprocess.run([str(app / "Contents/MacOS/check")] + args, check=True) run(vcc, base + ["--expect-enabled"]) run(dw, base + ["--expect-enabled", "--companion-validation-peer", str(vcc)]) run(vcc, []) run(production, []) run(production, base) run(rel, base) run(vcc, ["--companion-validation-root", str(public)]) run(vcc, ["--companion-validation-root", str(symlink)]) run(vcc, ["--companion-validation-root"]) run(vcc, base + base) run(dw, base + ["--companion-validation-peer", str(production)])