PulseCanvas / app · pulsecanvas.ai / scripts / test-updater.sh
| 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | cd "$(dirname "$0")/.." |
| 4 | test_root="$PWD/.build/updater-smoke" |
| 5 | mkdir -p "$test_root/feed" |
| 6 | python3 - "$test_root" <<'PY' |
| 7 | from pathlib import Path |
| 8 | import json, plistlib, sys, uuid |
| 9 | root = Path(sys.argv[1]) |
| 10 | config = json.loads(Path('macOS/DirectRelease.json').read_text()) |
| 11 | for name, build, enabled, expected in [('available', '1', True, '2.0'), ('current', '999999', True, None), ('disabled', '1', False, None)]: |
| 12 | app = root / (name + '.app') |
| 13 | (app / 'Contents/MacOS').mkdir(parents=True, exist_ok=True) |
| 14 | info = dict(CFBundleIdentifier='com.protomota.pulsecanvas.updater-test.' + name + '.' + uuid.uuid4().hex, |
| 15 | CFBundleExecutable='UpdaterSmoke', CFBundleName='Updater Test', CFBundlePackageType='APPL', |
| 16 | CFBundleVersion=build, CFBundleShortVersionString=build, |
| 17 | SUFeedURL='http://127.0.0.1:3277/' + name + '.xml', |
| 18 | SUPublicEDKey=config['sparklePublicKey'], SUEnableAutomaticChecks=enabled, |
| 19 | SUAutomaticallyUpdate=False, SUSendsSystemProfile=False, |
| 20 | NSAppTransportSecurity={'NSAllowsLocalNetworking': True}) |
| 21 | if expected: info['UpdaterExpectedVersion'] = expected |
| 22 | (app / 'Contents/Info.plist').write_bytes(plistlib.dumps(info)) |
| 23 | # No update is installed: the fixtures exercise real Sparkle selection/probing only. |
| 24 | (root / 'feed' / (name + '.xml')).write_text('''<?xml version="1.0"?><rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"><channel><title>Local updater test</title><item><title>2.0</title><sparkle:minimumSystemVersion>14.0</sparkle:minimumSystemVersion><enclosure url="https://pulsecanvas.si/downloads/PulseCanvas-Studio-1.1.1-18.dmg" length="37221463" type="application/octet-stream" sparkle:version="2" sparkle:shortVersionString="2.0" /></item></channel></rss>''') |
| 25 | PY |
| 26 | python3 -m http.server 3277 --bind 127.0.0.1 --directory "$test_root/feed" > "$test_root/server.log" 2>&1 & |
| 27 | server_pid=$! |
| 28 | trap 'kill "$server_pid" 2>/dev/null || true' EXIT |
| 29 | xcrun swiftc -O -suppress-warnings -swift-version 5 -D DIRECT_BUILD -parse-as-library \ |
| 30 | -F .build/sparkle -framework Sparkle -Xlinker -rpath -Xlinker "$PWD/.build/sparkle" \ |
| 31 | Sources/PulseCanvas/AppUpdater.swift Sources/PulseCanvas/StudioControls.swift scripts/UpdaterSmoke.swift \ |
| 32 | -o "$test_root/UpdaterSmoke" |
| 33 | for mode in available current disabled; do |
| 34 | cp "$test_root/UpdaterSmoke" "$test_root/$mode.app/Contents/MacOS/UpdaterSmoke" |
| 35 | codesign --force --sign - "$test_root/$mode.app" |
| 36 | "$test_root/$mode.app/Contents/MacOS/UpdaterSmoke" |
| 37 | done |
| 38 | python3 - "$test_root/server.log" <<'PY' |
| 39 | from pathlib import Path |
| 40 | import sys |
| 41 | log = Path(sys.argv[1]).read_text() |
| 42 | assert 'GET /available.xml' in log, log |
| 43 | assert 'GET /current.xml' in log, log |
| 44 | assert 'GET /disabled.xml' not in log, log |
| 45 | print('PASS request policy: silent discovery/current-version checks; disabled automatic checks send no request') |
| 46 | PY |