-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-e2e.sh
More file actions
193 lines (161 loc) · 10.2 KB
/
test-e2e.sh
File metadata and controls
193 lines (161 loc) · 10.2 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
#!/usr/bin/env bash
#
# thread CLI End-to-End Test Script — core functionality
#
# Prerequisites:
# - thread installed: npm run build && npm link
# - notifier installed (thread push triggers notifier dispatch; notifier need not be running)
#
# Usage: bash test-e2e.sh
#
set -uo pipefail
source "$(dirname "$0")/scripts/e2e-lib.sh"
THREAD="thread"
setup_e2e
T="$TD/test-thread"
# ── Pre-flight ────────────────────────────────────────────────
section "Pre-flight"
require_bin $THREAD "run npm run build"
# ══════════════════════════════════════════════════════════════
# 1. init
# ══════════════════════════════════════════════════════════════
section "1. init"
run_cmd $THREAD init "$T"
assert_exit0
assert_file_exists "$T/events.db" "events.db"
assert_file_exists "$T/events.jsonl" "events.jsonl"
# ══════════════════════════════════════════════════════════════
# 2. init — duplicate exits 1
# ══════════════════════════════════════════════════════════════
section "2. init — duplicate"
run_cmd $THREAD init "$T"
assert_exit 1
# ══════════════════════════════════════════════════════════════
# 3. push — single event
# ══════════════════════════════════════════════════════════════
section "3. push — single event"
run_cmd $THREAD push --thread "$T" --source e2e --type message --content "hello world"
assert_exit0
# ══════════════════════════════════════════════════════════════
# 4. push — with subtype
# ══════════════════════════════════════════════════════════════
section "4. push — with subtype"
run_cmd $THREAD push --thread "$T" --source e2e --type record --subtype toolcall \
--content '{"tool":"bash","args":["echo hi"]}'
assert_exit0
# ══════════════════════════════════════════════════════════════
# 5. peek — read all events
# ══════════════════════════════════════════════════════════════
section "5. peek — read all"
run_cmd $THREAD peek --thread "$T" --last-event-id 0
assert_exit0
assert_line_count_gte 2
# ══════════════════════════════════════════════════════════════
# 6. peek --filter
# ══════════════════════════════════════════════════════════════
section "6. peek --filter"
run_cmd $THREAD peek --thread "$T" --last-event-id 0 --filter "type = 'message'"
assert_exit0
assert_line_count_eq 1
# ══════════════════════════════════════════════════════════════
# 7. subscribe
# ══════════════════════════════════════════════════════════════
section "7. subscribe"
run_cmd $THREAD subscribe --thread "$T" --consumer worker-1 --handler "true"
assert_exit0
# ══════════════════════════════════════════════════════════════
# 8. subscribe — duplicate exits 1
# ══════════════════════════════════════════════════════════════
section "8. subscribe — duplicate"
run_cmd $THREAD subscribe --thread "$T" --consumer worker-1 --handler "true"
assert_exit 1
# ══════════════════════════════════════════════════════════════
# 9. pop
# ══════════════════════════════════════════════════════════════
section "9. pop"
run_cmd $THREAD pop --thread "$T" --consumer worker-1 --last-event-id 0
assert_exit0
assert_line_count_gte 2
# ══════════════════════════════════════════════════════════════
# 10. pop — no new events returns empty
# ══════════════════════════════════════════════════════════════
section "10. pop — no new events"
MAX_ID=$(tail -1 "$OUT" | grep -o '"id":[0-9]*' | grep -o '[0-9]*')
run_cmd $THREAD pop --thread "$T" --consumer worker-1 --last-event-id "$MAX_ID"
assert_exit0
assert_empty
# ══════════════════════════════════════════════════════════════
# 11. info
# ══════════════════════════════════════════════════════════════
section "11. info"
run_cmd $THREAD info --thread "$T"
assert_exit0
assert_contains "worker-1"
# ══════════════════════════════════════════════════════════════
# 12. info --json
# ══════════════════════════════════════════════════════════════
section "12. info --json"
run_cmd $THREAD info --thread "$T" --json
assert_exit0
assert_json_field "$OUT" "event_count"
# ══════════════════════════════════════════════════════════════
# 13. unsubscribe
# ══════════════════════════════════════════════════════════════
section "13. unsubscribe"
run_cmd $THREAD unsubscribe --thread "$T" --consumer worker-1
assert_exit0
# ══════════════════════════════════════════════════════════════
# 14. push --batch (stdin NDJSON)
# ══════════════════════════════════════════════════════════════
section "14. push --batch"
printf '{"source":"e2e","type":"message","content":"batch msg 1"}\n{"source":"e2e","type":"message","content":"batch msg 2"}\n' \
| $THREAD push --thread "$T" --batch >/dev/null 2>/dev/null
EC=$?
assert_exit0
run_cmd $THREAD peek --thread "$T" --last-event-id 0 --filter "type = 'message'"
assert_line_count_gte 3
# ══════════════════════════════════════════════════════════════
# 15. multiple consumers — independent read pointers
# ══════════════════════════════════════════════════════════════
section "15. multiple consumers — independent read pointers"
T2="$TD/multi-consumer-thread"
run_cmd $THREAD init "$T2"
assert_exit0
# Push 3 events
run_cmd $THREAD push --thread "$T2" --source e2e --type message --content "event-A"
assert_exit0
run_cmd $THREAD push --thread "$T2" --source e2e --type message --content "event-B"
assert_exit0
run_cmd $THREAD push --thread "$T2" --source e2e --type message --content "event-C"
assert_exit0
# Subscribe two consumers
run_cmd $THREAD subscribe --thread "$T2" --consumer alpha --handler "true"
assert_exit0
run_cmd $THREAD subscribe --thread "$T2" --consumer beta --handler "true"
assert_exit0
# Both consumers start from 0 — should each see all 3 events
run_cmd $THREAD pop --thread "$T2" --consumer alpha --last-event-id 0
assert_exit0
assert_line_count_eq 3
ALPHA_OUT="$OUT"
run_cmd $THREAD pop --thread "$T2" --consumer beta --last-event-id 0
assert_exit0
assert_line_count_eq 3
# Extract id of 2nd event (alpha advances past first 2)
ALPHA_MAX_ID=$(head -2 "$ALPHA_OUT" | tail -1 | grep -o '"id":[0-9]*' | grep -o '[0-9]*')
# alpha advances past first 2 events; beta stays at 0
# alpha should now see only event-C (1 event)
run_cmd $THREAD pop --thread "$T2" --consumer alpha --last-event-id "$ALPHA_MAX_ID"
assert_exit0
assert_line_count_eq 1
assert_contains "event-C"
# beta still sees all 3 (hasn't advanced its pointer)
run_cmd $THREAD pop --thread "$T2" --consumer beta --last-event-id 0
assert_exit0
assert_line_count_eq 3
# Advance beta past all events
BETA_MAX_ID=$(tail -1 "$OUT" | grep -o '"id":[0-9]*' | grep -o '[0-9]*')
run_cmd $THREAD pop --thread "$T2" --consumer beta --last-event-id "$BETA_MAX_ID"
assert_exit0
assert_empty
summary_and_exit