Repository navigation
Expand file tree
/
Copy pathassistant.sh
More file actions
executable file
·83 lines (79 loc) · 4.03 KB
/
Copy pathassistant.sh
File metadata and controls
executable file
·83 lines (79 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
# The platform's assistant, asked in typed text: `mobium assistant`.
#
# docs/checks/assistant.sh <android-serial | iphone-udid | simulator-udid>
#
# Gemini or Google Assistant on Android, opened with the assist key; Siri on
# a real iPhone. It checks:
#
# - a request that opens an app reaches it: "Open Calculator" on Android,
# "Open MobiumApp" on an iPhone, with --app naming it, answers reached;
# - the same request naming another app answers not reached — the app in
# front once the panel closes is never taken for the assistant's doing;
# - a request that acts for the owner ("Text …") is refused without --app,
# before anything is asked;
# - a simulator is refused: its Siri answers nothing (CHALLENGES 351).
#
# Each request goes to the account the assistant is signed in to, and Gemini
# keeps it in that account's activity: a phone only with ALLOW_PHONE=1. It
# never asks anything that reads the owner's data.
set -e
DEV="$1"
if [ -z "$DEV" ]; then echo "usage: $0 <serial|udid>" >&2; exit 2; fi
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
. "$ROOT/docs/checks/lib.sh"
check_lock "$DEV"
fail() { echo "FAIL: $*" >&2; exit 1; }
row() { printf ' %-10s %-60s ok\n' "$1" "$2"; }
json() { python3 -c "import json,sys; d=json.load(sys.stdin); print($1)"; }
export MOBIUM_SESSION="${MOBIUM_SESSION:-asstcheck}"
M="$ROOT/bin/mobium --device $DEV"
case "$DEV" in
????????-????????????????) KIND=phone ;;
*-*-*-*-*) KIND=simulator ;;
emulator-*) KIND=emulator ;;
*) KIND=android-phone ;;
esac
echo "--- $DEV ($KIND)"
if [ "$KIND" = simulator ]; then
out=$($M assistant "What time is it" 2>&1) && fail "a simulator's Siri was asked: $out"
echo "$out" | grep -q "answers nothing" || fail "the refusal did not say why: $out"
row "refused" "a simulator, whose Siri answers nothing"
echo PASS; exit 0
fi
case "$KIND" in
phone | android-phone) [ -n "$ALLOW_PHONE" ] || { echo "$DEV is a phone: each request goes to its owner's assistant account. ALLOW_PHONE=1 to go ahead" >&2; exit 2; } ;;
esac
out=$($M assistant "Text Mom that I am late" 2>&1) && fail "a request to text was sent without --app: $out"
echo "$out" | grep -q "on the device owner's behalf" || fail "the refusal did not say why: $out"
row "refused" "a request to text, with no app named"
if [ "$KIND" = phone ]; then
REQ="Open MobiumApp"; APP=dev.mobium.mobiumapp; START=com.apple.Preferences
else
REQ="Open Calculator"; APP=com.google.android.calculator; START=dev.mobium.mobiumapp
fi
# The request needs its app on the device. Google's Calculator is on phones
# but on no emulator image; without it the check refuses rather than fails
# for a cause that is not the assistant's. The list is read on its own, so a
# device that cannot list its apps fails as that (CHALLENGES 269).
apps=$($M apps 2>&1) || fail "listing the apps: $apps"
if ! echo "$apps" | grep -q "$APP"; then
echo "$(basename "$0") asks the assistant to open $APP, which $DEV does not have — install it first" >&2
exit 2
fi
$M terminate $APP >/dev/null 2>&1 || true
$M launch $START >/dev/null
at_exit "$M terminate $APP >/dev/null 2>&1 || true"
# The call's own error, not set -e: captured, a refusal ended the check with
# exit 5 and not a word, on an emulator with no Calculator.
got=$($M assistant "$REQ" --app $APP --json 2>&1) || fail "asking \"$REQ\": $got"
[ "$(echo "$got" | json 'd["typed"]')" = True ] || fail "the answer does not say the request was typed"
[ "$(echo "$got" | json 'd["reached"]')" = True ] || fail "\"$REQ\" did not reach $APP: $(echo "$got" | json 'd["front"]') in front"
[ "$($M current)" = "$APP" ] || fail "$APP is not in front after the assistant said so"
row "reached" "\"$REQ\" brought $APP forward ($(echo "$got" | json 'd["assistant"]'))"
$M terminate $APP >/dev/null 2>&1 || true
$M launch $START >/dev/null
got=$($M assistant "$REQ" --app $START --json 2>&1) || fail "asking \"$REQ\" again: $got"
[ "$(echo "$got" | json 'd["reached"]')" = False ] || fail "\"$REQ\" was reported as reaching $START"
row "control" "the same request, naming the app it left, is not reached"
echo PASS