Branchwell

PulseCanvas / app · pulsecanvas.ai / scripts / test-updater.sh

Raw 2.9 KB on 32796b3b2cff314d20e7c78bdc17d74e2eace8c1
1#!/bin/bash
2set -euo pipefail
3cd "$(dirname "$0")/.."
4test_root="$PWD/.build/updater-smoke"
5mkdir -p "$test_root/feed"
6python3 - "$test_root" <<'PY'
7from pathlib import Path
8import json, plistlib, sys, uuid
9root = Path(sys.argv[1])
10config = json.loads(Path('macOS/DirectRelease.json').read_text())
11for 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>''')
25PY
26python3 -m http.server 3277 --bind 127.0.0.1 --directory "$test_root/feed" > "$test_root/server.log" 2>&1 &
27server_pid=$!
28trap 'kill "$server_pid" 2>/dev/null || true' EXIT
29xcrun 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"
33for 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"
37done
38python3 - "$test_root/server.log" <<'PY'
39from pathlib import Path
40import sys
41log = Path(sys.argv[1]).read_text()
42assert 'GET /available.xml' in log, log
43assert 'GET /current.xml' in log, log
44assert 'GET /disabled.xml' not in log, log
45print('PASS request policy: silent discovery/current-version checks; disabled automatic checks send no request')
46PY