ReviewOS

also looking at this

craft-native/craft

feat(ios): the speech pair closes the last deferral — ratchet 28 -> 26

#101
Merged glennmichael123 wants to merge feat/ios-speech-pair into main
10 files +1287 -573
packages/ios/fixtures/zig-slice/build-and-run.shmodified+60-2
Changes to packages/ios/fixtures/zig-slice/build-and-run.sh
@@ -65,6 +65,7 @@ swiftc -target "$TRIPLE" -sdk "$SDK" \
6565 -framework UIKit -framework WebKit -framework Foundation -framework Security \
6666 -framework Vision -framework LocalAuthentication -framework PDFKit \
6767 -framework WatchConnectivity -framework CoreBluetooth -framework AVFoundation -framework HealthKit \
68 -framework Speech \
6869 -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker "$OUT/sim.entitlements" \
6970 -o "$APP/CraftSlice"
7071
@@ -99,6 +100,21 @@ xcrun simctl install "$UDID" "$APP"
99100# permission change.
100101xcrun simctl privacy "$UDID" grant microphone "$BUNDLE_ID" 2>/dev/null || true
101102
103# And speech recognition, which needs the raw TCC identifier.
104#
105# `simctl privacy` documents nine services and none of them is speech, but the
106# service argument is not validated against that list — it is passed through,
107# so the kTCCService* name Apple uses internally is accepted where the friendly
108# name is not. Verified rather than assumed: with only `microphone` granted,
109# startListening reached SFSpeechRecognizer and stopped dead at a
110# "would like to access Speech Recognition" alert that no script can answer,
111# and the fixture timed out with no event at all. With this line, the same
112# build emits craftSpeechStart.
113#
114# If a future Xcode starts validating the argument this fails silently and the
115# i=68 assertion below fails loudly, which is the right way round.
116xcrun simctl privacy "$UDID" grant kTCCServiceSpeechRecognition "$BUNDLE_ID" 2>/dev/null || true
117
102118LOG="$OUT/console.log"
103119xcrun simctl launch --console-pty "$UDID" "$BUNDLE_ID" > "$LOG" 2>&1 &
104120LAUNCH_PID=$!
@@ -110,7 +126,8 @@ for _ in $(seq 1 60); do
110126 && grep -q 'i=32' "$LOG" 2>/dev/null && grep -q 'i=22' "$LOG" 2>/dev/null \
111127 && grep -q 'i=34' "$LOG" 2>/dev/null && grep -q 'i=38' "$LOG" 2>/dev/null \
112128 && grep -q 'i=46' "$LOG" 2>/dev/null && grep -q 'i=44' "$LOG" 2>/dev/null \
113 && grep -q 'i=24' "$LOG" 2>/dev/null && grep -q 'i=20' "$LOG" 2>/dev/null; then sleep 1; break; fi
129 && grep -q 'i=24' "$LOG" 2>/dev/null && grep -q 'i=20' "$LOG" 2>/dev/null \
130 && grep -q 'i=72' "$LOG" 2>/dev/null; then sleep 1; break; fi
114131 sleep 1
115132done
116133kill "$LAUNCH_PID" 2>/dev/null || true
@@ -318,12 +335,53 @@ C52="$(count 52)"
318335[ "$C52" -ge 1 ] || { echo "FAIL: sendToWatch did not refuse through the error path"; exit 1; }
319336echo "ok: watch refusal delivered through the async error path (i=52 seen ${C52}x)"
320337
338# The speech pair. Neither action replies, so every assertion here is on the
339# event channel: the ids below are marker dispatches the page posts from inside
340# a `craftSpeech*` listener, and reaching one means the event arrived with a
341# detail the page could index into.
342C68="$(count 68)"; C74="$(count 74)"
343if [ "$C74" -ge 1 ]; then
344 # Not a pass, but the most useful thing to print before failing: the page
345 # only posts i=74 when the detail carried one of Swift's four messages, so
346 # the refusal names its own cause and the module clearly ran.
347 echo "note: startListening refused rather than started (i=74 seen ${C74}x)"
348fi
349# The strongest assertion this pair has. craftSpeechStart is emitted on the far
350# side of the whole chain: the plist guard, requestAuthorization:'s block on an
351# arbitrary queue, the hop to the main queue, the audio session, a live
352# SFSpeechRecognizer, a non-zero input format, the recognition task, the tap
353# installed on the audio I/O thread, and AVAudioEngine actually starting. Any
354# link short of the last one emits craftSpeechError instead.
355[ "$C68" -ge 1 ] || {
356 echo "FAIL: startListening never started the engine"
357 echo " If i=74 is absent too, the authorization block never fired —"
358 echo " check that the kTCCServiceSpeechRecognition grant above still"
359 echo " takes, because an unanswerable system alert looks exactly"
360 echo " like this."
361 exit 1
362}
363echo "ok: the audio engine started and craftSpeechStart reached the page (i=68 seen ${C68}x)"
364
365C72="$(count 72)"
366# The load-bearing one, and it holds whichever way the start went. Swift's
367# stopSpeechRecognition() has no early return, so a stop that stops nothing
368# still emits craftSpeechEnd — which is what a page's listening indicator
369# binds to. This is also the only assertion that proves the teardown ran
370# without taking the process down: the tap handoff, the bounded drain and the
371# release all happen on the way to this event.
372[ "$C72" -ge 1 ] || { echo "FAIL: stopListening did not emit craftSpeechEnd"; exit 1; }
373echo "ok: stopListening emitted craftSpeechEnd through the teardown (i=72 seen ${C72}x)"
374
321375C54="$(count 54)"
322376# The exact trap this action was held back for: ios_async's pooled block would
323377# have replied the STRING "denied", and "denied" is truthy — so a page's
324378# `if (await openSettings())` would take the success branch on failure. The
325379# page asserts `typeof payload === 'boolean'`, which only the module's own
326# block can satisfy. Posted last, because it navigates to Settings.
380# block can satisfy. Posted last, because it navigates to Settings — and
381# "last" means from inside the craftSpeechEnd listener, so this assertion
382# depends on the speech pair above. That is why the speech block sits ahead of
383# it: a broken teardown would otherwise surface here, blaming openSettings for
384# an event that never arrived.
327385[ "$C54" -ge 1 ] || { echo "FAIL: openSettings did not reply with a boolean"; exit 1; }
328386echo "ok: openSettings replied a real boolean, not \"granted\"/\"denied\" (i=54 seen ${C54}x)"
329387