@trillboards/edge-sdk 0.2.193 → 0.2.195

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/deploy/detector/pyproject.toml +1 -1
  2. package/deploy/detector/tests/test_loader.py +1 -1
  3. package/deploy/detector/tests/test_vehicle_end.py +215 -0
  4. package/deploy/detector/trillboards_detector/_version.py +2 -2
  5. package/deploy/detector/trillboards_detector/loader.py +6 -0
  6. package/deploy/detector/trillboards_detector/registry.py +30 -1
  7. package/deploy/detector/trillboards_detector/server.py +39 -0
  8. package/deploy/detector/trillboards_detector/tasks.py +8 -1
  9. package/deploy/detector/trillboards_detector/vehicle_end.py +154 -0
  10. package/deploy/macos/apply-update.sh +254 -104
  11. package/deploy/macos/ci/connector-stand-in.js +42 -0
  12. package/deploy/macos/ci/helper-stand-in.sh +23 -0
  13. package/deploy/macos/ci/launchd-matrix.js +39 -0
  14. package/deploy/macos/ci/lib.sh +339 -0
  15. package/deploy/macos/ci/test-field-self-update.sh +153 -0
  16. package/deploy/macos/ci/test-update-launchd-boundary.sh +260 -0
  17. package/deploy/systemd/trillboards-detector.service +10 -3
  18. package/dist/DetectorFields.d.ts +121 -1
  19. package/dist/DetectorFields.d.ts.map +1 -1
  20. package/dist/DetectorFields.js +123 -3
  21. package/dist/DetectorFields.js.map +1 -1
  22. package/dist/EdgeAgent.js +1 -1
  23. package/dist/LocalDetectorClient.d.ts +21 -0
  24. package/dist/LocalDetectorClient.d.ts.map +1 -1
  25. package/dist/LocalDetectorClient.js +44 -0
  26. package/dist/LocalDetectorClient.js.map +1 -1
  27. package/dist/ScopedVlmReview.d.ts +19 -4
  28. package/dist/ScopedVlmReview.d.ts.map +1 -1
  29. package/dist/ScopedVlmReview.js +83 -20
  30. package/dist/ScopedVlmReview.js.map +1 -1
  31. package/dist/SensingProfileClient.d.ts.map +1 -1
  32. package/dist/SensingProfileClient.js +2 -0
  33. package/dist/SensingProfileClient.js.map +1 -1
  34. package/dist/connectorUpdate.d.ts.map +1 -1
  35. package/dist/connectorUpdate.js +19 -0
  36. package/dist/connectorUpdate.js.map +1 -1
  37. package/dist/diagnose.d.ts +1 -1
  38. package/dist/diagnose.js +1 -1
  39. package/dist/localSensing.d.ts +4 -1
  40. package/dist/localSensing.d.ts.map +1 -1
  41. package/dist/localSensing.js +12 -8
  42. package/dist/localSensing.js.map +1 -1
  43. package/package.json +1 -1
@@ -0,0 +1,339 @@
1
+ #!/bin/bash
2
+ # lib.sh — shared rig for the macOS update qualifications. Sourced by
3
+ # test-update-launchd-boundary.sh and test-field-self-update.sh; runs only on a
4
+ # fresh GitHub-hosted macOS runner (both callers check before sourcing).
5
+ # Compatible with /bin/bash 3.2.
6
+
7
+ ORIGIN='https://tbstaticweb51dac4.blob.core.windows.net/screen'
8
+ LIVE_MANIFEST_URL='https://screen.trillboards.com/connector/trillboards-connector-macos.version.json'
9
+ EDGE="$HOME/Library/Trillboards/edge"
10
+ UPD="$HOME/Library/Trillboards/.edge-auto-update"
11
+ EDGE_PLIST="$HOME/Library/LaunchAgents/com.trillboards.edge.plist"
12
+ EDGE_SERVICE="gui/$(id -u)/com.trillboards.edge"
13
+ CFG_DIR="$HOME/Library/Application Support/Trillboards"
14
+ CFG="$CFG_DIR/trillboards.config.json"
15
+ LOG_DIR="$HOME/Library/Logs/Trillboards"
16
+ # The Gemma export each connector generation shipped. Through 0.2.141 the full
17
+ # package bundled Hugging Face `main` (the May 2026 upload); from 0.2.142 it is
18
+ # pinned to the April export the pilot evaluated.
19
+ MODEL_REV_SEPTEMBER='6e5c4f1e395deb959c494953478fa5cec4b8008f'
20
+ MODEL_SHA_SEPTEMBER='181938105e0eefd105961417e8da75903eacda102c4fce9ce90f50b97139a63c'
21
+ MODEL_REV_APPROVED='84b6978eff6e4eea02825bc2ee4ea48579f13109'
22
+ MODEL_SHA_APPROVED='ab7838cdfc8f77e54d8ca45eadceb20452d9f01e4bfade03e5dce27911b27e42'
23
+ STUB_PORT=47391
24
+ RTSP_PORT=8554
25
+ MEDIAMTX_API_PORT=9997
26
+
27
+ rig_init() {
28
+ OUT="${RUNNER_TEMP:?}/tb-$1-$(date -u +%H%M%S)"
29
+ mkdir -p "$OUT"
30
+ RIG_START_LOG="$(date '+%Y-%m-%d %H:%M:%S')"
31
+ RIG_PIDS=''
32
+ [ -n "${GITHUB_OUTPUT:-}" ] && echo "artifact_path=$OUT" >> "$GITHUB_OUTPUT"
33
+ note "rig at $OUT on $(sw_vers -productName) $(sw_vers -productVersion) ($(uname -m)), session $(launchctl managername 2>/dev/null)"
34
+ }
35
+ note() { local l; l="$(date -u +%H:%M:%S) $*"; echo "$l"; echo "$l" >> "$OUT/timeline.log"; }
36
+ rig_track() { RIG_PIDS="$RIG_PIDS $1"; }
37
+ rig_teardown() {
38
+ local p
39
+ for p in $RIG_PIDS; do kill "$p" 2>/dev/null || true; done
40
+ launchctl unsetenv NODE_EXTRA_CA_CERTS 2>/dev/null || true
41
+ }
42
+ sha256_of() { /usr/bin/shasum -a 256 "$1" | /usr/bin/awk '{print $1}'; }
43
+ json_get() { node -e 'const v = require(process.argv[1])[process.argv[2]]; if (v !== undefined) process.stdout.write(String(v));' "$1" "$2"; }
44
+ version_lt() { # a < b
45
+ node -e 'const v = s => s.split(".").map(Number); const [a, b] = [v(process.argv[1]), v(process.argv[2])];
46
+ process.exit((a[0] - b[0] || a[1] - b[1] || a[2] - b[2]) < 0 ? 0 : 1);' "$1" "$2"
47
+ }
48
+ run_bounded() { # seconds command...
49
+ local secs="$1"; shift
50
+ "$@" & local pid=$!
51
+ ( sleep "$secs"; kill -TERM "$pid" 2>/dev/null; sleep 2; kill -KILL "$pid" 2>/dev/null ) >/dev/null 2>&1 &
52
+ local w=$!
53
+ wait "$pid"; local rc=$?
54
+ kill "$w" 2>/dev/null; wait "$w" 2>/dev/null
55
+ return "$rc"
56
+ }
57
+
58
+ fetch_live_manifest() {
59
+ curl -fsS --retry 3 -H 'Cache-Control: no-cache' "$LIVE_MANIFEST_URL" -o "$OUT/live-manifest.json" || return 1
60
+ node -e 'const m = require(process.argv[1]); if (!/^\d+\.\d+\.\d+$/.test(m.connectorVersion)) process.exit(1);' "$OUT/live-manifest.json" || return 1
61
+ note "live manifest root $(json_get "$OUT/live-manifest.json" connectorVersion) published $(json_get "$OUT/live-manifest.json" publishedAt)"
62
+ }
63
+
64
+ pkg_version() { # the component version a flat package installs
65
+ local d="$OUT/pkgver-$$-$RANDOM"
66
+ /usr/sbin/pkgutil --expand "$1" "$d" >/dev/null 2>&1 || return 1
67
+ /usr/bin/sed -n 's/.*<pkg-info[^>]* version="\([0-9][0-9.]*\)".*/\1/p' "$d"/*/PackageInfo | head -1
68
+ rm -rf "$d"
69
+ }
70
+
71
+ # ---- a customer Mac has no developer tools -----------------------------------
72
+ hide_developer_tools() {
73
+ local stash="$RUNNER_TEMP/hidden-developer-tools" app moved=0
74
+ sudo mkdir -p "$stash"
75
+ readlink /var/db/xcode_select_link > "$OUT/xcode-select-link.before" 2>/dev/null || true
76
+ for app in /Applications/Xcode*.app; do
77
+ [ -e "$app" ] || [ -L "$app" ] || continue
78
+ sudo mv "$app" "$stash/" && moved=$((moved + 1))
79
+ done
80
+ [ -d /Library/Developer/CommandLineTools ] && sudo mv /Library/Developer/CommandLineTools "$stash/CommandLineTools"
81
+ sudo rm -f /var/db/xcode_select_link
82
+ unset DEVELOPER_DIR
83
+ launchctl unsetenv DEVELOPER_DIR 2>/dev/null || true
84
+ note "developer tools moved aside ($moved Xcode bundles, Command Line Tools, xcode-select link)"
85
+ }
86
+ prove_developer_tools_hidden() {
87
+ local out rc ok=0
88
+ out="$(run_bounded 30 /usr/bin/xcode-select -p 2>&1)"; rc=$?
89
+ note "proof: xcode-select -p -> exit $rc: $(printf '%s' "$out" | head -1)"; [ "$rc" -ne 0 ] || ok=1
90
+ out="$(run_bounded 30 /usr/bin/xcrun --find stapler 2>&1)"; rc=$?
91
+ note "proof: xcrun --find stapler -> exit $rc: $(printf '%s' "$out" | head -1)"; [ "$rc" -ne 0 ] || ok=1
92
+ if ls -d /Applications/Xcode*.app /Library/Developer/CommandLineTools >/dev/null 2>&1; then ok=1; fi
93
+ [ "$ok" -eq 0 ] && note 'PROVEN: no developer tools are reachable, as on a customer Mac'
94
+ return "$ok"
95
+ }
96
+
97
+ # ---- the paired machine ------------------------------------------------------
98
+ start_stub_api() {
99
+ cat > "$OUT/stub-api.js" <<'JS'
100
+ const http = require('node:http'); const fs = require('node:fs');
101
+ const [port, log] = process.argv.slice(2);
102
+ http.createServer((req, res) => { const c = []; req.on('data', d => c.push(d)); req.on('end', () => {
103
+ fs.appendFileSync(log, JSON.stringify({ at: new Date().toISOString(), method: req.method, url: req.url,
104
+ body: Buffer.concat(c).toString('utf8').slice(0, 16384) }) + '\n');
105
+ res.writeHead(200, { 'content-type': 'application/json' }); res.end('{"success":true,"data":{}}'); }); })
106
+ .listen(Number(port), '127.0.0.1');
107
+ JS
108
+ # The runner's own Node: the swap replaces everything under the install root.
109
+ nohup node "$OUT/stub-api.js" "$STUB_PORT" "$OUT/stub-requests.jsonl" > "$OUT/stub-api.log" 2>&1 &
110
+ rig_track $!
111
+ }
112
+
113
+ # Written BEFORE the package installs, so postinstall treats this as the paired
114
+ # machine it becomes and never opens setup (which would talk to production).
115
+ write_paired_config() {
116
+ mkdir -p "$CFG_DIR"; chmod 700 "$CFG_DIR"
117
+ local t1 t2; t1="$(openssl rand -hex 32)"; t2="$(openssl rand -hex 32)"
118
+ cat > "$CFG" <<JSON
119
+ {
120
+ "apiBaseUrl": "http://127.0.0.1:$STUB_PORT",
121
+ "deviceToken": "$t1",
122
+ "cameras": [ { "deviceToken": "$t2", "screenId": "tb-e2e-mac-field-update", "rtspUrl": "rtsp://127.0.0.1:$RTSP_PORT/cam", "sourceType": "direct_url", "transport": "tcp" } ],
123
+ "cloudSensing": { "candidateBuffer": { "continuousReview": { "enabled": false } } }
124
+ }
125
+ JSON
126
+ chmod 600 "$CFG"
127
+ }
128
+
129
+ # The full first-install package carries the model in share/models; the
130
+ # code-only package does not. Placing the same file there first makes the
131
+ # code-only install provision local AI exactly as the full package does.
132
+ stage_bundled_model() { # revision sha
133
+ mkdir -p "$EDGE/share/models"
134
+ note "fetching the bundled model (Hugging Face revision $1)"
135
+ curl -fsSL --retry 3 -o "$EDGE/share/models/gemma-4-E2B-it.litertlm" \
136
+ "https://huggingface.co/litert-community/gemma-4-E2B-it-litert-lm/resolve/$1/gemma-4-E2B-it.litertlm" || return 1
137
+ [ "$(sha256_of "$EDGE/share/models/gemma-4-E2B-it.litertlm")" = "$2" ] || { note 'model hash mismatch'; return 1; }
138
+ printf '%s gemma-4-E2B-it.litertlm\n' "$2" > "$EDGE/share/models/gemma-4-E2B-it.litertlm.sha256"
139
+ }
140
+
141
+ install_pkg() { # pkg label
142
+ local t0 rc; t0="$(date +%s)"
143
+ /usr/sbin/installer -pkg "$1" -target CurrentUserHomeDirectory -verboseR > "$OUT/$2.log" 2>&1; rc=$?
144
+ note "installer $2: exit $rc in $(( $(date +%s) - t0 ))s; installed $(installed_version)"
145
+ cp "$LOG_DIR/litertlm-setup.log" "$OUT/litertlm-setup-$2.log" 2>/dev/null || true
146
+ return "$rc"
147
+ }
148
+ installed_version() { node -p 'require(process.argv[1]).version' "$EDGE/lib/edge-sdk/package.json" 2>/dev/null; }
149
+ local_ai_ready() {
150
+ local models; models="$(curl -fsS --max-time 5 http://127.0.0.1:9379/v1/models 2>/dev/null)"
151
+ note "local AI: $(printf '%s' "$models" | tr -d '\n ' | cut -c1-160)"
152
+ printf '%s' "$models" | grep -q 'gemma-4-E2B-it.litertlm'
153
+ }
154
+
155
+ start_camera() {
156
+ local rig="$OUT/camera" frame="$PKGROOT/deploy/windows/e2e/fixtures/person.jpg" i
157
+ mkdir -p "$rig"
158
+ curl -fsSL --retry 3 -o "$rig/mediamtx.tgz" https://github.com/bluenviron/mediamtx/releases/download/v1.21.2/mediamtx_v1.21.2_darwin_arm64.tar.gz || return 1
159
+ # The official v1.21.2 checksum, the same release test-recorder-family.ps1 pins.
160
+ [ "$(sha256_of "$rig/mediamtx.tgz")" = 7d0d0c5c11527cbd10bde1c3d728864eb0334a9b653566cd73c0259750cbf093 ] || { note 'MediaMTX checksum mismatch'; return 1; }
161
+ tar -xzf "$rig/mediamtx.tgz" -C "$rig"
162
+ cat > "$rig/mediamtx.yml" <<YML
163
+ logLevel: warn
164
+ rtspAddress: 127.0.0.1:$RTSP_PORT
165
+ rtspTransports: [tcp]
166
+ rtmp: no
167
+ hls: no
168
+ webrtc: no
169
+ srt: no
170
+ api: yes
171
+ apiAddress: 127.0.0.1:$MEDIAMTX_API_PORT
172
+ authInternalUsers:
173
+ - user: any
174
+ pass: ""
175
+ ips: [127.0.0.1]
176
+ permissions:
177
+ - action: publish
178
+ - action: read
179
+ - action: api
180
+ paths:
181
+ cam:
182
+ YML
183
+ ( cd "$rig" && nohup ./mediamtx "$rig/mediamtx.yml" > "$OUT/mediamtx.log" 2>&1 & echo $! > "$rig/mediamtx.pid" )
184
+ rig_track "$(cat "$rig/mediamtx.pid")"
185
+ sleep 2
186
+ # A COPY of the shipped ffmpeg: the swap replaces the install root, and the
187
+ # camera must outlive it. A still scene has no motion to review, so the
188
+ # connector reaches its safe point the way a quiet store does after hours.
189
+ cp "$EDGE/bin/ffmpeg" "$rig/camera-ffmpeg"
190
+ nohup "$rig/camera-ffmpeg" -hide_banner -loglevel error -re -loop 1 -framerate 4 -i "$frame" -an -c:v libx264 \
191
+ -preset ultrafast -tune zerolatency -pix_fmt yuv420p -r 4 -g 8 -threads 1 -f rtsp -rtsp_transport tcp \
192
+ "rtsp://127.0.0.1:$RTSP_PORT/cam" > "$OUT/camera.log" 2>&1 &
193
+ rig_track $!
194
+ for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
195
+ sleep 2
196
+ if curl -fsS "http://127.0.0.1:$MEDIAMTX_API_PORT/v3/paths/list" 2>/dev/null | grep -q '"ready":true'; then
197
+ note "camera live at rtsp://127.0.0.1:$RTSP_PORT/cam"; return 0
198
+ fi
199
+ done
200
+ return 1
201
+ }
202
+
203
+ # Answers screen.trillboards.com on this machine only, with the live manifest
204
+ # aged past the bake window. The connector trusts the rig CA through
205
+ # NODE_EXTRA_CA_CERTS in its launchd domain; its update package still comes
206
+ # from the Blob origin over a real TLS chain.
207
+ serve_aged_manifest() { # live manifest
208
+ local rig="$OUT/manifest"; mkdir -p "$rig"
209
+ openssl req -x509 -newkey rsa:2048 -nodes -keyout "$rig/ca.key" -out "$rig/ca.pem" -days 2 -subj '/CN=Trillboards field rig CA' \
210
+ -extensions v3_ca -config <(printf '[req]\ndistinguished_name=dn\n[dn]\n[v3_ca]\nbasicConstraints=critical,CA:true\nkeyUsage=critical,keyCertSign,cRLSign\nsubjectKeyIdentifier=hash\n') >/dev/null 2>&1 || return 1
211
+ openssl req -newkey rsa:2048 -nodes -keyout "$rig/srv.key" -out "$rig/srv.csr" -subj '/CN=screen.trillboards.com' >/dev/null 2>&1 || return 1
212
+ openssl x509 -req -in "$rig/srv.csr" -CA "$rig/ca.pem" -CAkey "$rig/ca.key" -CAcreateserial -out "$rig/srv.pem" -days 2 \
213
+ -extfile <(printf 'subjectAltName=DNS:screen.trillboards.com\nbasicConstraints=CA:false\nkeyUsage=digitalSignature,keyEncipherment\nextendedKeyUsage=serverAuth\n') >/dev/null 2>&1 || return 1
214
+ node -e '
215
+ const fs = require("fs"); const origin = process.argv[2]; const pub = "https://screen.trillboards.com/";
216
+ const m = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
217
+ const aged = new Date(Date.now() - (6 * 3600 + 600) * 1000).toISOString().replace(/\.\d+Z$/, "Z");
218
+ for (const e of [m, ...(m.releaseHistory || [])]) {
219
+ if (e.updateUrl && e.updateUrl.startsWith(pub)) e.updateUrl = origin + "/" + e.updateUrl.slice(pub.length);
220
+ if (Date.parse(e.publishedAt) > Date.parse(aged)) { e.rigPublishedAt = e.publishedAt; e.publishedAt = aged; }
221
+ }
222
+ fs.writeFileSync(process.argv[3], JSON.stringify(m, null, 2));' "$1" "$ORIGIN" "$rig/served-manifest.json" || return 1
223
+ cat > "$rig/server.js" <<'JS'
224
+ const https = require('node:https'); const fs = require('node:fs');
225
+ const [key, cert, manifest, log] = process.argv.slice(2);
226
+ https.createServer({ key: fs.readFileSync(key), cert: fs.readFileSync(cert) }, (req, res) => {
227
+ fs.appendFileSync(log, `${new Date().toISOString()} ${req.method} ${req.url}\n`);
228
+ if (req.url.split('?')[0] === '/connector/trillboards-connector-macos.version.json') {
229
+ res.writeHead(200, { 'content-type': 'application/json', 'cache-control': 'no-store' }); res.end(fs.readFileSync(manifest));
230
+ } else { res.writeHead(404); res.end('not served by the rig\n'); }
231
+ }).listen(443, '127.0.0.1');
232
+ JS
233
+ sudo nohup "$(command -v node)" "$rig/server.js" "$rig/srv.key" "$rig/srv.pem" "$rig/served-manifest.json" "$OUT/manifest-requests.log" > "$OUT/manifest-server.log" 2>&1 &
234
+ echo '127.0.0.1 screen.trillboards.com' | sudo tee -a /etc/hosts >/dev/null
235
+ sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder 2>/dev/null || true
236
+ sleep 2
237
+ curl -fsS --cacert "$rig/ca.pem" "$LIVE_MANIFEST_URL" >/dev/null 2>&1 || return 1
238
+ launchctl setenv NODE_EXTRA_CA_CERTS "$rig/ca.pem"
239
+ note "screen.trillboards.com answered locally with the live manifest aged past the bake (served-manifest.json)"
240
+ }
241
+
242
+ expected_target() { # manifest from-version
243
+ node -e '
244
+ const m = require(process.argv[1]); const from = process.argv[2];
245
+ const v = s => s.split(".").map(Number); const cmp = (a, b) => { const x = v(a), y = v(b); return x[0] - y[0] || x[1] - y[1] || x[2] - y[2]; };
246
+ const choices = cmp(from, "0.2.176") >= 0 ? [m, ...(m.releaseHistory || [])] : [m];
247
+ const ok = choices.filter(e => e.updateUrl && e.updateSha256 && e.updateSizeBytes && cmp(e.connectorVersion, from) > 0
248
+ && Date.now() - Date.parse(e.publishedAt) >= 6 * 3600 * 1000).sort((a, b) => cmp(b.connectorVersion, a.connectorVersion));
249
+ if (ok[0]) process.stdout.write(ok[0].connectorVersion);' "$1" "$2"
250
+ }
251
+
252
+ # pair.command's bootstrap_agent, verbatim in effect.
253
+ bootstrap_connector_agent() {
254
+ mkdir -p "$LOG_DIR" "$(dirname "$EDGE_PLIST")"
255
+ /usr/bin/sed -e "s|__LAUNCHER__|$EDGE/bin/trillboards-edge|g" -e "s|__CONFIG__|$CFG|g" -e "s|__LOG_DIR__|$LOG_DIR|g" \
256
+ "$EDGE/share/com.trillboards.edge.plist" > "$EDGE_PLIST"
257
+ launchctl bootout "$EDGE_SERVICE" >/dev/null 2>&1 || true
258
+ launchctl bootstrap "gui/$(id -u)" "$EDGE_PLIST" || return 1
259
+ launchctl kickstart -k "$EDGE_SERVICE" >/dev/null 2>&1 || true
260
+ sleep 3
261
+ launchctl print "$EDGE_SERVICE" 2>/dev/null | grep -q 'state = running' || return 1
262
+ note "com.trillboards.edge running in gui/$(id -u) ($(installed_version))"
263
+ }
264
+
265
+ last_report() { # version= available= outcome= updater=
266
+ node -e '
267
+ const fs = require("fs"); let last = null;
268
+ try { for (const l of fs.readFileSync(process.argv[1], "utf8").trim().split("\n")) {
269
+ const o = JSON.parse(l); if (o.url.includes("connector-status") && o.body) { const b = JSON.parse(o.body); if (b.connectorVersion) last = b; } } } catch {}
270
+ if (last) process.stdout.write(`version=${last.connectorVersion} available=${last.availableVersion} outcome=${JSON.stringify(last.updateOutcome || null)} updater=${JSON.stringify(last.updater || null)}`);
271
+ ' "$OUT/stub-requests.jsonl" 2>/dev/null
272
+ }
273
+ update_processes() {
274
+ ps -axo pid,ppid,command | grep -E 'apply-update\.sh|edge-sdk/dist/cli\.js|/usr/sbin/installer|setup-litertlm' | grep -v grep \
275
+ | awk '{c=""; for (i=3;i<=NF&&i<=6;i++) c=c" "$i; print $1"<"$2 c}' | tr '\n' ';'
276
+ }
277
+
278
+ # Follows one update to its end. Returns 0 on PASS; otherwise sets WATCH_VERDICT.
279
+ WATCH_VERDICT=''
280
+ watch_update() { # from target deadline_min
281
+ local from="$1" target="$2" deadline=$(( $(date +%s) + $3 * 60 )) seen_out=0 seen_err=0
282
+ local last_files='' last_procs='' last_job='' last_report_line='' staging_at=0 settle_at=0 f n new
283
+ while [ "$(date +%s)" -lt "$deadline" ]; do
284
+ sleep 5
285
+ for f in "$LOG_DIR/edge.out.log" "$LOG_DIR/edge.err.log"; do
286
+ [ -f "$f" ] || continue
287
+ n="$(wc -l < "$f" | tr -d ' ')"
288
+ if [ "$f" = "$LOG_DIR/edge.out.log" ]; then new=$seen_out; else new=$seen_err; fi
289
+ [ "$n" -lt "$new" ] && new=0
290
+ if [ "$n" -gt "$new" ]; then
291
+ tail -n "+$((new + 1))" "$f" | head -n $((n - new)) | grep -E '\[update\]|uncaught|Fatal error' | cut -c1-300 | while read -r line; do note "connector: $line"; done
292
+ tail -n "+$((new + 1))" "$f" | head -n $((n - new)) | grep -q '\[update\] staging' && staging_at="$(date +%s)"
293
+ fi
294
+ if [ "$f" = "$LOG_DIR/edge.out.log" ]; then seen_out=$n; else seen_err=$n; fi
295
+ done
296
+ local files; files="$(ls -A "$UPD" 2>/dev/null | tr '\n' ' ')"
297
+ if [ "$files" != "$last_files" ]; then
298
+ note ".edge-auto-update: [$files]"
299
+ [ -f "$UPD/staged.json" ] && note " staged.json $(cat "$UPD/staged.json")"
300
+ [ -f "$UPD/outcome.json" ] && note " outcome.json $(cat "$UPD/outcome.json")"
301
+ last_files="$files"
302
+ fi
303
+ local p; p="$(update_processes)"
304
+ [ "$p" != "$last_procs" ] && { note "processes: ${p:-(none)}"; last_procs="$p"; }
305
+ local j; j="$(launchctl print "$EDGE_SERVICE" 2>&1 | grep -E '^\s*(state|pid|last exit code) =' | tr -s ' \t\n' ' ')"
306
+ [ "$j" != "$last_job" ] && { note "com.trillboards.edge:${j:- not loaded}"; last_job="$j"; }
307
+ local r; r="$(last_report)"
308
+ [ "$r" != "$last_report_line" ] && { note "status report: $r"; last_report_line="$r"; }
309
+ if [ "$(installed_version)" = "$target" ] && printf '%s' "$r" | grep -q "^version=$target " \
310
+ && launchctl print "$EDGE_SERVICE" 2>/dev/null | grep -q 'state = running'; then
311
+ return 0
312
+ fi
313
+ if [ -f "$UPD/outcome.json" ] && ! grep -q '"result":"success"' "$UPD/outcome.json" && [ "$settle_at" -eq 0 ]; then
314
+ settle_at=$(( $(date +%s) + 240 )); note 'a failed outcome was recorded; watching four more minutes for the relaunch report'
315
+ fi
316
+ if [ "$settle_at" -gt 0 ] && [ "$(date +%s)" -gt "$settle_at" ]; then
317
+ WATCH_VERDICT="the update failed: $(cat "$UPD/outcome.json" 2>/dev/null)"; return 1
318
+ fi
319
+ if [ "$staging_at" -gt 0 ] && [ ! -f "$UPD/staged.json" ] && [ ! -f "$UPD/outcome.json" ] \
320
+ && ! printf '%s' "$p" | grep -q 'apply-update' && [ $(( $(date +%s) - staging_at )) -gt 300 ]; then
321
+ WATCH_VERDICT='staging began five minutes ago; no helper runs, nothing is staged and no outcome was written (the silent failure)'; return 1
322
+ fi
323
+ done
324
+ WATCH_VERDICT="no update within the deadline (installed $(installed_version), last report: $last_report_line)"
325
+ return 1
326
+ }
327
+
328
+ collect_evidence() {
329
+ local ev="$OUT/evidence"; mkdir -p "$ev"
330
+ [ -d "$UPD" ] && find "$UPD" -maxdepth 1 -type f -size -2M -exec cp {} "$ev/" \; 2>/dev/null
331
+ [ -d "$LOG_DIR" ] && cp -R "$LOG_DIR" "$ev/trillboards-logs" 2>/dev/null
332
+ cp "$EDGE_PLIST" "$ev/" 2>/dev/null || true
333
+ launchctl print "$EDGE_SERVICE" > "$ev/edge-service.txt" 2>&1 || true
334
+ launchctl print "gui/$(id -u)/com.trillboards.edge.update" > "$ev/update-service.txt" 2>&1 || true
335
+ /usr/bin/log show --start "$RIG_START_LOG" --style compact \
336
+ --predicate '(process == "logger" AND eventMessage CONTAINS "apply-update") OR (subsystem == "com.apple.xpc.launchd" AND eventMessage CONTAINS "com.trillboards")' \
337
+ > "$ev/unified-log.txt" 2>&1 || true
338
+ grep -i trillboards /var/log/install.log > "$ev/install.log.trillboards" 2>/dev/null || true
339
+ }
@@ -0,0 +1,153 @@
1
+ #!/bin/bash
2
+ #
3
+ # test-field-self-update.sh — does a macOS connector that is ALREADY IN THE
4
+ # FIELD update itself?
5
+ #
6
+ # Installs a connector package from its immutable address (or one built from
7
+ # this checkout), gives it the on-device model its package shipped with, a real
8
+ # RTSP camera and a stub API, starts it under its own LaunchAgent in the gui
9
+ # domain exactly as pairing does, and waits for it to take a newer published
10
+ # release with no help: stage -> safe point -> commit -> outcome -> relaunch.
11
+ # PASS only when the installed tree, the running LaunchAgent and the
12
+ # connector's own status report all name the target version.
13
+ #
14
+ # Developer tools are hidden first and proven absent: a customer Mac has no
15
+ # Xcode, and the defect that stopped every Mac from updating through 0.2.193
16
+ # was a trust check that needed one (run 41934336173).
17
+ #
18
+ # --from auto the newest published build that carries the
19
+ # stock-Mac updater (>= FIXED_UPDATER_SINCE) and is
20
+ # older than the live root; SKIPS until one exists.
21
+ # --from <commit sha> the published code-only package of that commit.
22
+ # --from candidate:<pkg> a package built from this checkout (unsigned); its
23
+ # version must be lower than the target's.
24
+ # --manifest live the connector reads the published manifest, as the
25
+ # fleet does (default).
26
+ # --manifest served the rig answers screen.trillboards.com with a copy of
27
+ # the live manifest whose root is publishedAt-aged past
28
+ # the six-hour bake, so the proof does not wait on the
29
+ # live root's age. Every byte still comes from the
30
+ # Blob origin.
31
+ #
32
+ # Execute only on a fresh GitHub-hosted macOS runner. Never on a customer Mac.
33
+ set -u
34
+
35
+ FROM='auto'
36
+ MANIFEST_MODE='live'
37
+ UPDATE_DEADLINE_MIN=60
38
+ while [ "$#" -gt 0 ]; do
39
+ case "$1" in
40
+ --from) FROM="${2:?}"; shift 2 ;;
41
+ --manifest) MANIFEST_MODE="${2:?}"; shift 2 ;;
42
+ --deadline-min) UPDATE_DEADLINE_MIN="${2:?}"; shift 2 ;;
43
+ *) echo "unknown argument: $1" >&2; exit 2 ;;
44
+ esac
45
+ done
46
+ if [ "${GITHUB_ACTIONS:-}" != true ] || [ "${RUNNER_OS:-}" != macOS ] || [ "${RUNNER_ENVIRONMENT:-}" != github-hosted ]; then
47
+ echo 'Field self-update qualification installs a connector and edits /etc/hosts; run it only on a fresh GitHub-hosted macOS runner' >&2
48
+ exit 2
49
+ fi
50
+
51
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
52
+ PKGROOT="$(cd "$HERE/../../.." && pwd)"
53
+ # shellcheck source=deploy/macos/ci/lib.sh
54
+ . "$HERE/lib.sh"
55
+ rig_init field-self-update
56
+
57
+ # The first release whose updater verifies with tools every Mac has and
58
+ # records every failure. Builds before it cannot pass; name one explicitly with
59
+ # --from <sha> to watch that happen.
60
+ FIXED_UPDATER_SINCE='0.2.194'
61
+ RECEIPT_FROM=''; RECEIPT_TARGET=''; RECEIPT_PHASE='start'; RECEIPT_PASSED=false; RECEIPT_FAILURE=''
62
+ write_receipt() {
63
+ node -e '
64
+ const [file, ...kv] = process.argv.slice(1); const o = {};
65
+ for (let i = 0; i < kv.length; i += 2) o[kv[i]] = kv[i + 1];
66
+ o.passed = o.passed === "true"; require("fs").writeFileSync(file, JSON.stringify(o, null, 2) + "\n");
67
+ ' "$OUT/receipt.json" atUtc "$(date -u +%Y-%m-%dT%H:%M:%SZ)" githubRunId "${GITHUB_RUN_ID:-}" from "$FROM" \
68
+ fromVersion "$RECEIPT_FROM" targetVersion "$RECEIPT_TARGET" manifest "$MANIFEST_MODE" phase "$RECEIPT_PHASE" \
69
+ passed "$RECEIPT_PASSED" failure "$RECEIPT_FAILURE" >/dev/null 2>&1 || true
70
+ }
71
+ fail() { RECEIPT_FAILURE="$*"; note "FAIL in phase $RECEIPT_PHASE: $*"; collect_evidence; write_receipt; exit 1; }
72
+ trap 'rig_teardown' EXIT
73
+
74
+ for leftover in "$EDGE" "$UPD" "$EDGE_PLIST" "$CFG"; do
75
+ [ -e "$leftover" ] && { echo "This Mac already holds connector state at $leftover; the field proof needs a fresh one" >&2; exit 2; }
76
+ done
77
+ RECEIPT_PHASE='root-manifest'
78
+ fetch_live_manifest || fail 'could not read the live macOS manifest'
79
+ TARGET_VERSION="$(json_get "$OUT/live-manifest.json" connectorVersion)"
80
+ RECEIPT_TARGET="$TARGET_VERSION"
81
+ case "$FROM" in
82
+ auto)
83
+ pick="$(node -e '
84
+ const m = require(process.argv[1]); const since = process.argv[2];
85
+ const v = s => s.split(".").map(Number); const lt = (a, b) => { const x = v(a), y = v(b); return x[0] - y[0] || x[1] - y[1] || x[2] - y[2]; };
86
+ const all = [m, ...(m.releaseHistory || [])].filter(e => e.updateUrl && e.updateSha256 && e.updateSizeBytes);
87
+ const ok = all.filter(e => lt(e.connectorVersion, since) >= 0 && lt(e.connectorVersion, m.connectorVersion) < 0)
88
+ .sort((a, b) => lt(b.connectorVersion, a.connectorVersion));
89
+ if (ok[0]) process.stdout.write(ok[0].gitSha);' "$OUT/live-manifest.json" "$FIXED_UPDATER_SINCE")"
90
+ if [ -z "$pick" ]; then
91
+ note "SKIP: no published build with the stock-Mac updater (>= $FIXED_UPDATER_SINCE) is older than the root $TARGET_VERSION yet"
92
+ RECEIPT_PHASE='skipped'; RECEIPT_PASSED=true; write_receipt; exit 0
93
+ fi
94
+ FROM_KIND=published; FROM_COMMIT="$pick" ;;
95
+ candidate:*) FROM_KIND=candidate; FROM_PKG_LOCAL="${FROM#candidate:}" ;;
96
+ *)
97
+ printf '%s' "$FROM" | grep -Eq '^[0-9a-f]{40}$' || fail '--from must be auto, candidate:<pkg>, or a 40-hex commit'
98
+ FROM_KIND=published; FROM_COMMIT="$FROM" ;;
99
+ esac
100
+
101
+ RECEIPT_PHASE='download'
102
+ if [ "$FROM_KIND" = published ]; then
103
+ curl -fsS --retry 3 -o "$OUT/from.pkg" "$ORIGIN/connector/updates/$FROM_COMMIT/trillboards-connector-macos-update.pkg" \
104
+ || fail "no published code-only package for $FROM_COMMIT"
105
+ else
106
+ [ -f "$FROM_PKG_LOCAL" ] || fail "no candidate package at $FROM_PKG_LOCAL"
107
+ cp "$FROM_PKG_LOCAL" "$OUT/from.pkg"
108
+ fi
109
+ FROM_VERSION="$(pkg_version "$OUT/from.pkg")"
110
+ [ -n "$FROM_VERSION" ] || fail 'could not read the package version'
111
+ RECEIPT_FROM="$FROM_VERSION"
112
+ version_lt "$FROM_VERSION" "$TARGET_VERSION" || fail "the root $TARGET_VERSION is not newer than $FROM_VERSION; nothing to update to"
113
+
114
+ hide_developer_tools
115
+ prove_developer_tools_hidden || fail 'developer tools are still reachable; the rig would not be a customer Mac'
116
+
117
+ RECEIPT_PHASE='install'
118
+ # The model the package's own full installer bundled: the May 2026 export
119
+ # through 0.2.141, the pinned April export from 0.2.142.
120
+ if version_lt "$FROM_VERSION" '0.2.142'; then MODEL_REV="$MODEL_REV_SEPTEMBER"; MODEL_SHA="$MODEL_SHA_SEPTEMBER"; else MODEL_REV="$MODEL_REV_APPROVED"; MODEL_SHA="$MODEL_SHA_APPROVED"; fi
121
+ start_stub_api
122
+ write_paired_config
123
+ stage_bundled_model "$MODEL_REV" "$MODEL_SHA" || fail 'could not fetch the bundled model'
124
+ install_pkg "$OUT/from.pkg" install-from || fail "the $FROM_VERSION package did not install"
125
+ [ "$(installed_version)" = "$FROM_VERSION" ] || fail "installed $(installed_version), not $FROM_VERSION"
126
+ local_ai_ready || fail 'the package installed but local AI is not healthy; the rig cannot exercise an update'
127
+
128
+ RECEIPT_PHASE='camera'
129
+ start_camera || fail 'the RTSP camera never became readable'
130
+ VIEW="$OUT/live-manifest.json"
131
+ if [ "$MANIFEST_MODE" = served ]; then
132
+ RECEIPT_PHASE='manifest'
133
+ serve_aged_manifest "$OUT/live-manifest.json" || fail 'could not answer screen.trillboards.com locally'
134
+ VIEW="$OUT/manifest/served-manifest.json"
135
+ fi
136
+ # What this build will take, by the rule its own update loop applies: builds
137
+ # from 0.2.176 read releaseHistory, older ones only the root; a release is
138
+ # taken once it is six hours old.
139
+ TARGET_VERSION="$(expected_target "$VIEW" "$FROM_VERSION")"
140
+ [ -n "$TARGET_VERSION" ] || fail "the manifest offers $FROM_VERSION no mature update yet"
141
+ RECEIPT_TARGET="$TARGET_VERSION"
142
+ note "field build $FROM_VERSION ($FROM_KIND) must update itself to $TARGET_VERSION"
143
+
144
+ RECEIPT_PHASE='pair'
145
+ bootstrap_connector_agent || fail 'com.trillboards.edge did not start'
146
+
147
+ RECEIPT_PHASE='self-update'
148
+ if watch_update "$FROM_VERSION" "$TARGET_VERSION" "$UPDATE_DEADLINE_MIN"; then
149
+ RECEIPT_PHASE='complete'; RECEIPT_PASSED=true
150
+ note "PASS: $FROM_VERSION updated itself to $TARGET_VERSION under its real LaunchAgent"
151
+ collect_evidence; write_receipt; exit 0
152
+ fi
153
+ fail "$WATCH_VERDICT"