-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathruntime-demo.sh
More file actions
executable file
·86 lines (66 loc) · 2.1 KB
/
runtime-demo.sh
File metadata and controls
executable file
·86 lines (66 loc) · 2.1 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
#!/usr/bin/env bash
set -u -o pipefail
LAST_OUTPUT=""
FAILURES=0
run_cmd() {
local cmd="$1"
local output
local status
printf '$ %s\n' "$cmd"
output=$(eval "$cmd" 2>&1)
status=$?
if [ -n "$output" ]; then
printf '%s\n' "$output"
fi
printf '[exit %s]\n\n' "$status"
LAST_OUTPUT="$output"
if [ "$status" -ne 0 ]; then
FAILURES=$((FAILURES + 1))
fi
return "$status"
}
extract_object_id() {
local line
while IFS= read -r line; do
case "$line" in
objectId:\ *)
printf '%s' "${line#objectId: }"
return 0
;;
esac
done <<< "$LAST_OUTPUT"
return 1
}
run_cmd "pnpm run --silent agent-cdp -- start"
run_cmd "pnpm run --silent agent-cdp -- status"
run_cmd "pnpm run --silent agent-cdp -- runtime eval --expr '1 + 2'"
run_cmd "pnpm run --silent agent-cdp -- runtime eval --await --expr 'Promise.resolve(42)'"
case "$LAST_OUTPUT" in
*"number: 42"*)
;;
*"Promise"*)
printf 'Async runtime eval returned a promise instead of the resolved value\n\n'
FAILURES=$((FAILURES + 1))
;;
*)
printf 'Async runtime eval did not return the expected resolved value\n\n'
FAILURES=$((FAILURES + 1))
;;
esac
run_cmd "pnpm run --silent agent-cdp -- runtime eval --json --expr '({ title: \"runtime demo\", count: 3, nested: { ready: true }, list: [1, 2, 3] })'"
run_cmd "pnpm run --silent agent-cdp -- runtime eval --expr 'globalThis.__agentCdpRuntimeDemo = { title: \"runtime demo\", count: 3, nested: { ready: true }, list: [1, 2, 3] }; globalThis.__agentCdpRuntimeDemo'"
OBJECT_ID=""
if OBJECT_ID=$(extract_object_id); then
run_cmd "pnpm run --silent agent-cdp -- runtime props --id \"$OBJECT_ID\" --own"
run_cmd "pnpm run --silent agent-cdp -- runtime release --id \"$OBJECT_ID\""
else
printf 'No runtime object id found in eval output\n\n'
FAILURES=$((FAILURES + 1))
fi
run_cmd "pnpm run --silent agent-cdp -- runtime release-group"
run_cmd "pnpm run --silent agent-cdp -- stop"
if [ "$FAILURES" -ne 0 ]; then
printf 'Runtime demo finished with %s failure(s).\n' "$FAILURES"
exit 1
fi
printf 'Runtime demo finished successfully.\n'