forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscenario-13-task-thread-e2e.sh
More file actions
executable file
·172 lines (157 loc) · 6.44 KB
/
Copy pathscenario-13-task-thread-e2e.sh
File metadata and controls
executable file
·172 lines (157 loc) · 6.44 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
# Deterministic named-bundle proof for the task-backed thread slice of scenario 13.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
# shellcheck source=automation-token-path.sh
source "$ROOT/scripts/automation-token-path.sh"
APP_NAME="${OMI_APP_NAME:?Set OMI_APP_NAME to the running named bundle (omi-*)}"
case "$APP_NAME" in
omi-*) ;;
*) echo "scenario-13: refusing non-test app name '$APP_NAME'" >&2; exit 1 ;;
esac
BUNDLE_ID="com.omi.${APP_NAME}"
CAPTURE_ROOT="${OMI_AUTOMATION_CAPTURE_ROOT:-${TMPDIR:-/tmp}/omi-harness}"
EVIDENCE_DIR="${OMI_SCENARIO_EVIDENCE_DIR:-$CAPTURE_ROOT/scenario-13-task-thread}"
mkdir -p "$EVIDENCE_DIR"
ctl() {
"$ROOT/scripts/omi-ctl" "$@"
}
set_ui_presentation() {
local token="$1"
local mode="$2"
local activate="$3"
local body
body="$(jq -nc \
--arg mode "$mode" \
--argjson activate "$activate" \
'{name:"set_automation_ui_presentation",params:{mode:$mode,activate:$activate}}')"
curl -fsS \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-X POST "http://127.0.0.1:${OMI_AUTOMATION_PORT:-47777}/action" \
-d "$body" >/dev/null
}
run_external_capture() (
local token="$1"
shift
# AX/screencapture is the only lane allowed to reveal and activate the window.
# The EXIT trap is this shell function's finally path, including command failure.
trap 'set_ui_presentation "$token" quiet false >/dev/null 2>&1 || true' EXIT
if ! set_ui_presentation "$token" interactive true; then
return 1
fi
"$@"
)
run_agent_swift_capture() {
local bundle_id="$1"
local output="$2"
agent-swift connect --bundle-id "$bundle_id" >/dev/null 2>&1 \
&& agent-swift screenshot "$output" >/dev/null 2>&1
}
bridge_token() {
local token_file
token_file="$(omi_automation_token_file "${OMI_AUTOMATION_PORT:-47777}")"
local token="${OMI_AUTOMATION_TOKEN:-}"
[ -n "$token" ] || token="$(tr -d '\r\n' < "$token_file")"
printf '%s' "$token"
}
capture_window() {
local output="$1"
local token
token="$(bridge_token)"
local body
body="$(jq -nc --arg path "$output" '{path:$path,target:"task_thread"}')"
for _ in 1 2 3; do
if curl -fsS \
-H "Authorization: Bearer $token" \
-X POST "http://127.0.0.1:${OMI_AUTOMATION_PORT:-47777}/visual/export" \
-d "$body" >/dev/null 2>&1 \
&& [ "$(stat -f %z "$output" 2>/dev/null || echo 0)" -gt 20000 ]; then
return
fi
sleep 0.5
done
if command -v agent-swift >/dev/null 2>&1; then
if run_external_capture "$token" run_agent_swift_capture "$BUNDLE_ID" "$output"; then
return
fi
fi
run_external_capture "$token" screencapture -x "$output"
}
SCENARIO_TOKEN="$(bridge_token)"
set_ui_presentation "$SCENARIO_TOKEN" quiet false
ctl state >"$EVIDENCE_DIR/app-state.json"
# Exercise the production app→kernel continuity RPCs against a persistent
# SQLite kernel before rendering the deterministic UI layer. The probe migrates
# a legacy task session, writes cited v1/v2, exports/imports a checkpoint across
# a real close/reopen, replays v2 idempotently, and evaluates external send via
# the control-tool boundary.
(cd "$ROOT/agent" && npm run build >/dev/null)
kernel_proof="$(cd "$ROOT/agent" && node scripts/scenario-13-kernel.mjs "$EVIDENCE_DIR/kernel.sqlite")"
printf '%s\n' "$kernel_proof" >"$EVIDENCE_DIR/kernel-continuity.json"
jq -e '
.ok == true and
.migratedTaskMappings == 1 and
.copiedTurns == 1 and
.conversationTurnsAfterRestart == 1 and
.queuedDeliveriesAfterRestart >= 2 and
.firstVersion == 1 and
.secondVersion == 2 and
.replayVersion == 2 and
(.versions | map(.version) == [1, 2]) and
(.versions | all(.cited == true)) and
.externalSendDecision == "dispatch_required"
' <<<"$kernel_proof" >/dev/null
first="$(ctl action task_thread_scenario_13 task=first settleMs=250)"
printf '%s\n' "$first" >"$EVIDENCE_DIR/first-task.json"
first_workstream="$(jq -er '.result.detail.workstream_id' <<<"$first")"
first_session="$(jq -er '.result.detail.kernel_session_id' <<<"$first")"
jq -e '
.ok == true and
.result.detail.active_task_id == "scenario-13-task-draft" and
.result.detail.kernel_surface == "workstream" and
.result.detail.runtime_bridge == "live_app_kernel" and
.result.detail.artifact_versions == "v2,v1" and
.result.detail.cited_v2 == "true" and
.result.detail.external_send_decision == "dispatch_required"
' <<<"$first" >/dev/null
capture_window "$EVIDENCE_DIR/first-task.png"
second="$(ctl action task_thread_scenario_13 task=second resume=true settleMs=250)"
printf '%s\n' "$second" >"$EVIDENCE_DIR/second-task.json"
second_workstream="$(jq -er '.result.detail.workstream_id' <<<"$second")"
jq -e '.result.detail.active_task_id == "scenario-13-task-review"' <<<"$second" >/dev/null
test "$first_workstream" = "$second_workstream"
test "$(jq -er '.result.detail.kernel_session_id' <<<"$second")" = "$first_session"
capture_window "$EVIDENCE_DIR/second-task.png"
send_decision="$(jq -r '.result.detail.external_send_decision' <<<"$first")"
test "$send_decision" = "dispatch_required"
printf '%s\n' "$send_decision" >"$EVIDENCE_DIR/external-send-without-grant.txt"
# Restart only the explicitly named test bundle and prove the same workstream is
# reprojected while the selected Task remains merely UI scope.
osascript -e "tell application id \"$BUNDLE_ID\" to quit" >/dev/null 2>&1 || true
for _ in $(seq 1 40); do
if ! pgrep -f "/Applications/${APP_NAME}.app/Contents/MacOS/" >/dev/null; then break; fi
sleep 0.25
done
open -g -b "$BUNDLE_ID" --args \
"--automation-port=${OMI_AUTOMATION_PORT:-47777}" \
"--automation-capture-root=$CAPTURE_ROOT" \
"--automation-ui=quiet"
for _ in $(seq 1 80); do
if ctl health >/dev/null 2>&1; then break; fi
sleep 0.25
done
ctl state >"$EVIDENCE_DIR/app-state-after-restart.json"
resumed="$(ctl action task_thread_scenario_13 task=second resume=true settleMs=1000)"
printf '%s\n' "$resumed" >"$EVIDENCE_DIR/resumed-task.json"
resumed_workstream="$(jq -er '.result.detail.workstream_id' <<<"$resumed")"
test "$resumed_workstream" = "$first_workstream"
test "$(jq -er '.result.detail.kernel_session_id' <<<"$resumed")" = "$first_session"
jq -e '
.result.detail.active_task_id == "scenario-13-task-review" and
.result.detail.runtime_bridge == "live_app_kernel" and
.result.detail.artifact_versions == "v2,v1" and
.result.detail.cited_v2 == "true"
' <<<"$resumed" >/dev/null
capture_window "$EVIDENCE_DIR/resumed-task.png"
printf 'scenario-13 task thread passed: workstream=%s evidence=%s\n' "$first_workstream" "$EVIDENCE_DIR"