forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent-logic-harness.sh
More file actions
executable file
·351 lines (313 loc) · 10.3 KB
/
Copy pathagent-logic-harness.sh
File metadata and controls
executable file
·351 lines (313 loc) · 10.3 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/usr/bin/env bash
# Focused, self-driving harness for desktop agent / realtime voice control-plane changes.
#
# Usage:
# cd desktop/macos && ./scripts/agent-logic-harness.sh
# ./scripts/agent-logic-harness.sh --swift-only
# ./scripts/agent-logic-harness.sh --node-only
# ./scripts/agent-logic-harness.sh --cross-surface-smoke
# ./scripts/agent-logic-harness.sh --skip-install
# ./scripts/agent-logic-harness.sh --verbose
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
DESKTOP_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
REPO_ROOT="$(cd "$DESKTOP_DIR/../.." && pwd)"
RUN_SWIFT=1
RUN_NODE=1
RUN_GAUNTLET=0
RUN_CROSS_SURFACE_SMOKE=0
SKIP_INSTALL=0
VERBOSE=0
INTERNAL_FAILURE_PROBE=0
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)"
RUN_DIR="$DESKTOP_DIR/.harness/agent-logic/$RUN_ID"
usage() {
cat <<'USAGE'
Focused harness for Omi desktop agent / voice logic.
Runs:
1. Swift focused tests:
AgentPillLifecycleTests, PushToTalkStateMachineTests, RealtimeHubSpawnAgentTests
2. Agent runtime focused tests:
codemagic-pi-mono-extension-ci, runtime-adapter, pi-mono-adapter
3. pi-mono-extension package tests:
npm ci if needed, then node --experimental-strip-types --test index.test.ts
--cross-surface-smoke runs only the compact deterministic contract suite:
cross-surface Swift projections, the matching agent-runtime protocol and
provider tests, and Rust retrieval-policy tests. It does not launch the app,
audio capture, or a live provider.
Options:
--swift-only Run only Swift focused tests
--node-only Run only Node/package focused tests
--cross-surface-smoke Run the compact cross-surface contract smoke suite only
--skip-install Do not run npm ci for pi-mono-extension if deps are missing
--with-gauntlet After unit tests, run agent-continuity-gauntlet.sh (requires live app)
--verbose Stream command output instead of saving it quietly
--help Show this help
USAGE
}
while [[ $# -gt 0 ]]; do
case "$1" in
--swift-only)
RUN_SWIFT=1
RUN_NODE=0
;;
--node-only)
RUN_SWIFT=0
RUN_NODE=1
;;
--cross-surface-smoke)
RUN_SWIFT=0
RUN_NODE=0
RUN_CROSS_SURFACE_SMOKE=1
;;
--skip-install)
SKIP_INSTALL=1
;;
--with-gauntlet)
RUN_GAUNTLET=1
;;
--verbose)
VERBOSE=1
;;
--internal-failure-probe)
INTERNAL_FAILURE_PROBE=1
RUN_SWIFT=0
RUN_NODE=0
;;
--help|-h)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage >&2
exit 2
;;
esac
shift
done
if [[ "$INTERNAL_FAILURE_PROBE" -eq 0 && "$RUN_SWIFT" -eq 0 && "$RUN_NODE" -eq 0 && "$RUN_CROSS_SURFACE_SMOKE" -eq 0 ]]; then
echo "Nothing selected." >&2
exit 2
fi
declare -a STEP_NAMES=()
declare -a STEP_SECONDS=()
declare -a STEP_LOGS=()
now_seconds() {
python3 - <<'PY'
import time
print(f"{time.monotonic():.6f}")
PY
}
elapsed_seconds() {
local start="$1"
python3 - "$start" <<'PY'
import sys, time
start = float(sys.argv[1])
print(f"{time.monotonic() - start:.2f}")
PY
}
run_step() {
local name="$1"
shift
echo
echo "=== $name ==="
local start
local log_path="$RUN_DIR/$(printf '%02d' "$((${#STEP_NAMES[@]} + 1))")-$(echo "$name" | tr '[:upper:] ' '[:lower:]-' | tr -cd 'a-z0-9._-').log"
start="$(now_seconds)"
local status=0
if [[ "$VERBOSE" -eq 1 ]]; then
if "$@" 2>&1 | tee "$log_path"; then
status=0
else
status="${PIPESTATUS[0]}"
[[ "$status" -eq 0 ]] && status=1
fi
else
if "$@" >"$log_path" 2>&1; then
status=0
else
status=$?
fi
fi
if [[ "$status" -ne 0 ]]; then
echo "--- $name failed; log: $log_path" >&2
cat "$log_path" >&2
exit "$status"
fi
local elapsed
elapsed="$(elapsed_seconds "$start")"
STEP_NAMES+=("$name")
STEP_SECONDS+=("$elapsed")
STEP_LOGS+=("$log_path")
echo "--- $name passed in ${elapsed}s (log: $log_path)"
}
run_failure_propagation_self_check() {
echo
echo "=== harness failure propagation self-check ==="
local start
local elapsed
local log_path="$RUN_DIR/$(printf '%02d' "$((${#STEP_NAMES[@]} + 1))")-harness-failure-propagation-self-check.log"
start="$(now_seconds)"
set +e
"$0" --internal-failure-probe >"$log_path" 2>&1
local status=$?
set -e
elapsed="$(elapsed_seconds "$start")"
if [[ "$status" -ne 7 ]]; then
echo "--- harness failure propagation self-check failed; expected exit 7, got $status; log: $log_path" >&2
cat "$log_path" >&2
exit 1
fi
STEP_NAMES+=("harness failure propagation self-check")
STEP_SECONDS+=("$elapsed")
STEP_LOGS+=("$log_path")
echo "--- harness failure propagation self-check passed in ${elapsed}s (log: $log_path)"
}
run_swift_focus() {
(
cd "$DESKTOP_DIR"
xcrun swift test --package-path Desktop \
--filter 'PTTAudioCaptureRaceTests|MainChatRecoveredDraftTests|VoiceTypeOpeningDecoderTests|OfflinePTTQuestionRecoveryTests|VoiceTypeTargetSafetyTests|VoiceTypeSessionTests|DictationPolisherTests|PushToTalkSpeechGateTests|NotchVoiceMorphMarkTests|ShortcutSettingsTests|AgentPillLifecycleTests|PushToTalkStateMachineTests|PushToTalkButtonTriggerTests|RealtimeScreenEvidenceTests|VoiceTurnReducerTests|VoiceTurnReducerFuzzTests|VoiceTurnCoordinatorTests|VoiceTurnOutputOwnershipTests|VoiceTurnUIProjectionCopyTests|LegacyVoiceJournalImporterTests|RealtimeHubBargeInContinuityTests|RealtimeHubReconnectContractTests|RealtimeHubSessionInputLifecycleTests|RealtimeHubSpawnAgentTests|RealtimeProviderToolResultPolicyTests|AgentContinuityGauntletTests|KernelTurnRecordedProjectionTests|ChatTimelineContinuityTests|FloatingControlBarStateTests|RuntimeOwnerIdentityTests|TaskThreadProjectionTests|AgentRuntimeBridgeLifecycleTests|AgentRuntimeContractFixtureTests|PiMonoWiringTests|HubSystemInstructionTests|RealtimeScreenEvidenceHonestFailureTests|ConversationEvidenceTests|RealtimeTurnEvidenceTests|ChatAttachmentEvidenceTests'
)
}
run_cross_surface_swift_smoke() {
(
cd "$DESKTOP_DIR"
xcrun swift test --package-path Desktop \
--filter 'CrossSurfaceContractSmokeTests|AgentRuntimeStatusStoreTests|AgentRuntimeBridgeLifecycleTests|AgentRuntimeContractFixtureTests|RealtimeHubSpawnAgentTests|PiMonoWiringTests|DesktopAutomationBridgeRouteTests/testUnauthenticatedHealthReportsBackendAndRuntimeProtocolIdentity'
)
}
run_agent_runtime_focus() {
(
cd "$DESKTOP_DIR"
scripts/test-tool-surfaces.sh
)
}
ensure_agent_runtime_deps() {
if [[ -d "$DESKTOP_DIR/agent/node_modules" ]]; then
return
fi
if [[ "$SKIP_INSTALL" -eq 1 ]]; then
echo "agent/node_modules missing and --skip-install was set" >&2
return 1
fi
(
cd "$DESKTOP_DIR/agent"
npm ci --no-fund --no-audit
)
}
run_cross_surface_agent_smoke() {
ensure_agent_runtime_deps
(
cd "$DESKTOP_DIR/agent"
npm run build
node node_modules/vitest/vitest.mjs run \
tests/cross-surface-contract-smoke.test.ts \
tests/runtime-stdio-contract.test.ts \
tests/protocol-v2.test.ts \
tests/conversation-journal.test.ts \
tests/conversation-evidence.test.ts \
tests/conversation-operations.test.ts \
tests/evidence-tools.test.ts \
tests/control-tools.test.ts \
tests/runtime-adapter.test.ts \
tests/pi-mono-adapter.test.ts \
tests/context-snapshot.test.ts \
tests/agent-runtime-contract-fixtures.test.ts \
tests/runtime-adapter-contract-conformance.test.ts \
tests/relay-tool-result.test.ts \
tests/spawn-receipt-fixtures.test.ts
)
}
ensure_pi_mono_extension_deps() {
if [[ -d "$DESKTOP_DIR/pi-mono-extension/node_modules" ]]; then
return
fi
if [[ "$SKIP_INSTALL" -eq 1 ]]; then
echo "pi-mono-extension/node_modules missing and --skip-install was set" >&2
return 1
fi
(
cd "$DESKTOP_DIR/pi-mono-extension"
npm ci --no-fund --no-audit
)
}
node_supports_strip_types() {
"$1" --experimental-strip-types -e '0' >/dev/null 2>&1
}
select_node22() {
local node_bin
local -a candidates=(
"$DESKTOP_DIR/Desktop/Sources/Resources/node"
"/opt/homebrew/opt/node@22/bin/node"
"/usr/local/opt/node@22/bin/node"
)
if command -v brew >/dev/null 2>&1; then
node_bin="$(brew --prefix node@22 2>/dev/null || true)"
if [[ -n "$node_bin" ]]; then
candidates+=("$node_bin/bin/node")
fi
fi
node_bin="$(command -v node 2>/dev/null || true)"
[[ -n "$node_bin" ]] && candidates+=("$node_bin")
for node_bin in "${candidates[@]}"; do
if [[ -x "$node_bin" ]] && node_supports_strip_types "$node_bin"; then
printf '%s\n' "$node_bin"
return
fi
done
echo "ERROR: Node.js 22.6+ with --experimental-strip-types is required for desktop agent package tests." >&2
echo "Install Node 22 or run desktop/macos/scripts/prepare-agent-runtime.sh first." >&2
return 1
}
run_pi_mono_extension_exact() {
ensure_pi_mono_extension_deps
(
cd "$DESKTOP_DIR/pi-mono-extension"
local node22
node22="$(select_node22)"
PATH="$(dirname "$node22"):$PATH" npx --yes tsx --test index.test.ts
)
}
run_continuity_gauntlet() {
(
cd "$DESKTOP_DIR"
./scripts/agent-continuity-gauntlet.sh
)
}
total_start="$(now_seconds)"
echo "Omi desktop agent logic harness"
echo "repo: $REPO_ROOT"
echo "desktop: $DESKTOP_DIR"
echo "git: $(git -C "$REPO_ROOT" rev-parse --short HEAD 2>/dev/null || echo unknown)"
mkdir -p "$RUN_DIR"
echo "logs: $RUN_DIR"
if [[ "$INTERNAL_FAILURE_PROBE" -eq 1 ]]; then
run_step "failure propagation probe" bash -c 'exit 7'
exit 99
fi
run_failure_propagation_self_check
if [[ "$RUN_SWIFT" -eq 1 ]]; then
run_step "swift focused lifecycle/state tests" run_swift_focus
fi
if [[ "$RUN_NODE" -eq 1 ]]; then
run_step "agent runtime focused tests" run_agent_runtime_focus
run_step "pi-mono-extension exact package tests" run_pi_mono_extension_exact
fi
if [[ "$RUN_CROSS_SURFACE_SMOKE" -eq 1 ]]; then
run_step "cross-surface Swift contract smoke" run_cross_surface_swift_smoke
run_step "cross-surface agent contract smoke" run_cross_surface_agent_smoke
fi
if [[ "$RUN_GAUNTLET" -eq 1 ]]; then
run_step "agent continuity gauntlet (INV-6)" run_continuity_gauntlet
fi
total_elapsed="$(elapsed_seconds "$total_start")"
echo
echo "=== Timing Summary ==="
for i in "${!STEP_NAMES[@]}"; do
printf '%7ss %s (%s)\n' "${STEP_SECONDS[$i]}" "${STEP_NAMES[$i]}" "${STEP_LOGS[$i]}"
done
printf '%7ss TOTAL\n' "$total_elapsed"
echo
echo "Harness passed."