-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathupdate-lifecycle-test.sh
More file actions
executable file
·382 lines (309 loc) · 12.8 KB
/
update-lifecycle-test.sh
File metadata and controls
executable file
·382 lines (309 loc) · 12.8 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#!/bin/bash
# Update mechanism verification — comprehensive test suite for the self-update
# lifecycle: concurrency safety, panic recovery, build timeouts, failure
# handling, npm retry logic, heartbeat, output capture, and source invariants.
#
# Usage:
# ./scripts/update-lifecycle-test.sh # Run all update tests
#
# Prerequisites:
# - Go installed
#
# Output:
# /tmp/update-lifecycle-report.json — JSON test results
# /tmp/update-lifecycle-summary.md — human-readable summary
#
# Exit code:
# 0 — all tests pass
# 1 — one or more tests failed
set -euo pipefail
cd "$(dirname "$0")/.."
# ============================================================================
# Colors
# ============================================================================
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m'
REPORT_JSON="/tmp/update-lifecycle-report.json"
REPORT_MD="/tmp/update-lifecycle-summary.md"
TMPDIR_UL=$(mktemp -d)
trap 'rm -rf "$TMPDIR_UL"' EXIT
if ! command -v go &>/dev/null; then
echo -e "${RED}ERROR: Go is not installed${NC}"
exit 1
fi
echo -e "${BOLD}═══════════════════════════════════════════════════${NC}"
echo -e "${BOLD} Update Lifecycle Verification${NC}"
echo -e "${BOLD}═══════════════════════════════════════════════════${NC}"
echo ""
TOTAL=0
PASSED=0
FAILED=0
# ============================================================================
# Phase 1: Update checker unit tests
# ============================================================================
echo -e "${BOLD}Phase 1: Update checker tests${NC}"
TEST_OUTPUT="$TMPDIR_UL/update-tests.txt"
TEST_EXIT=0
go test ./pkg/agent/... -run "TestTriggerNow|TestIsUpdating|TestStatus" -v -timeout 30s > "$TEST_OUTPUT" 2>&1 || TEST_EXIT=$?
GO_PASSED=$(grep -c "^--- PASS:" "$TEST_OUTPUT" 2>/dev/null) || GO_PASSED=0
GO_FAILED_COUNT=$(grep -c "^--- FAIL:" "$TEST_OUTPUT" 2>/dev/null) || GO_FAILED_COUNT=0
TOTAL=$((TOTAL + 1))
if [ "$TEST_EXIT" -eq 0 ]; then
echo -e " ${GREEN}✓${NC} Update checker tests passed (${GO_PASSED} tests)"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌${NC} Update checker tests failed (${GO_FAILED_COUNT} failures)"
grep "^--- FAIL:" "$TEST_OUTPUT" 2>/dev/null | while IFS= read -r line; do
echo -e " ${DIM}${line}${NC}"
done
FAILED=$((FAILED + 1))
fi
echo ""
# ============================================================================
# Phase 2: Concurrent rejection stress test
# ============================================================================
echo -e "${BOLD}Phase 2: Concurrent rejection stress test${NC}"
STRESS_OUTPUT="$TMPDIR_UL/stress-tests.txt"
STRESS_EXIT=0
go test ./pkg/agent/... -run "TestTriggerNowConcurrentStress" -v -timeout 30s -count=3 > "$STRESS_OUTPUT" 2>&1 || STRESS_EXIT=$?
TOTAL=$((TOTAL + 1))
if [ "$STRESS_EXIT" -eq 0 ]; then
echo -e " ${GREEN}✓${NC} Concurrent rejection stress test passed (3 runs)"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌${NC} Concurrent rejection stress test failed"
grep "FAIL\|Error" "$STRESS_OUTPUT" 2>/dev/null | head -5 | while IFS= read -r line; do
echo -e " ${DIM}${line}${NC}"
done
FAILED=$((FAILED + 1))
fi
echo ""
# ============================================================================
# Phase 3: Panic recovery test
# ============================================================================
echo -e "${BOLD}Phase 3: Panic recovery test${NC}"
PANIC_OUTPUT="$TMPDIR_UL/panic-tests.txt"
PANIC_EXIT=0
go test ./pkg/agent/... -run "TestTriggerNowRecoversPanic|TestTriggerNowReleasesOnCompletion" -v -timeout 30s > "$PANIC_OUTPUT" 2>&1 || PANIC_EXIT=$?
TOTAL=$((TOTAL + 1))
if [ "$PANIC_EXIT" -eq 0 ]; then
echo -e " ${GREEN}✓${NC} Panic recovery and flag release tests passed"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌${NC} Panic recovery tests failed"
grep "FAIL\|Error" "$PANIC_OUTPUT" 2>/dev/null | head -5 | while IFS= read -r line; do
echo -e " ${DIM}${line}${NC}"
done
FAILED=$((FAILED + 1))
fi
echo ""
# ============================================================================
# Phase 4: 5-iteration developer update reliability loop
# ============================================================================
echo -e "${BOLD}Phase 4: Developer update reliability loop (5 iterations)${NC}"
LOOP_OUTPUT="$TMPDIR_UL/loop-tests.txt"
LOOP_EXIT=0
go test ./pkg/agent/... -run "TestDeveloperUpdateLoop_5x" -v -timeout 120s > "$LOOP_OUTPUT" 2>&1 || LOOP_EXIT=$?
TOTAL=$((TOTAL + 1))
if [ "$LOOP_EXIT" -eq 0 ]; then
echo -e " ${GREEN}✓${NC} 5-iteration reliability loop passed"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌${NC} 5-iteration reliability loop failed"
grep "FAIL\|Error" "$LOOP_OUTPUT" 2>/dev/null | head -5 | while IFS= read -r line; do
echo -e " ${DIM}${line}${NC}"
done
FAILED=$((FAILED + 1))
fi
echo ""
# ============================================================================
# Phase 5: Build timeout handling
# ============================================================================
echo -e "${BOLD}Phase 5: Build timeout handling${NC}"
TIMEOUT_OUTPUT="$TMPDIR_UL/timeout-tests.txt"
TIMEOUT_EXIT=0
go test ./pkg/agent/... -run "TestDeveloperUpdate_BuildTimeout" -v -timeout 30s > "$TIMEOUT_OUTPUT" 2>&1 || TIMEOUT_EXIT=$?
TOTAL=$((TOTAL + 1))
if [ "$TIMEOUT_EXIT" -eq 0 ]; then
echo -e " ${GREEN}✓${NC} Build timeout handling passed"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌${NC} Build timeout handling failed"
grep "FAIL\|Error" "$TIMEOUT_OUTPUT" 2>/dev/null | head -5 | while IFS= read -r line; do
echo -e " ${DIM}${line}${NC}"
done
FAILED=$((FAILED + 1))
fi
echo ""
# ============================================================================
# Phase 6: Build failure with output capture
# ============================================================================
echo -e "${BOLD}Phase 6: Build failure with output capture${NC}"
BUILDFAIL_OUTPUT="$TMPDIR_UL/buildfail-tests.txt"
BUILDFAIL_EXIT=0
go test ./pkg/agent/... -run "TestDeveloperUpdate_BuildFailure" -v -timeout 30s > "$BUILDFAIL_OUTPUT" 2>&1 || BUILDFAIL_EXIT=$?
TOTAL=$((TOTAL + 1))
if [ "$BUILDFAIL_EXIT" -eq 0 ]; then
echo -e " ${GREEN}✓${NC} Build failure output capture passed"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌${NC} Build failure output capture failed"
grep "FAIL\|Error" "$BUILDFAIL_OUTPUT" 2>/dev/null | head -5 | while IFS= read -r line; do
echo -e " ${DIM}${line}${NC}"
done
FAILED=$((FAILED + 1))
fi
echo ""
# ============================================================================
# Phase 7: npm install retry logic
# ============================================================================
echo -e "${BOLD}Phase 7: npm install retry logic${NC}"
RETRY_OUTPUT="$TMPDIR_UL/retry-tests.txt"
RETRY_EXIT=0
go test ./pkg/agent/... -run "TestDeveloperUpdate_NpmInstallRetry" -v -timeout 30s > "$RETRY_OUTPUT" 2>&1 || RETRY_EXIT=$?
TOTAL=$((TOTAL + 1))
if [ "$RETRY_EXIT" -eq 0 ]; then
echo -e " ${GREEN}✓${NC} npm install retry logic passed"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌${NC} npm install retry logic failed"
grep "FAIL\|Error" "$RETRY_OUTPUT" 2>/dev/null | head -5 | while IFS= read -r line; do
echo -e " ${DIM}${line}${NC}"
done
FAILED=$((FAILED + 1))
fi
echo ""
# ============================================================================
# Phase 8: Heartbeat during long builds
# ============================================================================
echo -e "${BOLD}Phase 8: Heartbeat during long builds${NC}"
HEARTBEAT_OUTPUT="$TMPDIR_UL/heartbeat-tests.txt"
HEARTBEAT_EXIT=0
go test ./pkg/agent/... -run "TestDeveloperUpdate_HeartbeatDuringBuild" -v -timeout 120s > "$HEARTBEAT_OUTPUT" 2>&1 || HEARTBEAT_EXIT=$?
TOTAL=$((TOTAL + 1))
if [ "$HEARTBEAT_EXIT" -eq 0 ]; then
echo -e " ${GREEN}✓${NC} Heartbeat during long builds passed"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌${NC} Heartbeat during long builds failed"
grep "FAIL\|Error" "$HEARTBEAT_OUTPUT" 2>/dev/null | head -5 | while IFS= read -r line; do
echo -e " ${DIM}${line}${NC}"
done
FAILED=$((FAILED + 1))
fi
echo ""
# ============================================================================
# Phase 9: Output capture utilities
# ============================================================================
echo -e "${BOLD}Phase 9: Output capture and utility tests${NC}"
UTIL_OUTPUT="$TMPDIR_UL/util-tests.txt"
UTIL_EXIT=0
go test ./pkg/agent/... -run "TestRunBuildCmd_OutputCapture|TestTailLines|TestBuildErrorDetail|TestMockPathResolution" -v -timeout 30s > "$UTIL_OUTPUT" 2>&1 || UTIL_EXIT=$?
TOTAL=$((TOTAL + 1))
if [ "$UTIL_EXIT" -eq 0 ]; then
echo -e " ${GREEN}✓${NC} Output capture and utility tests passed"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌${NC} Output capture and utility tests failed"
grep "FAIL\|Error" "$UTIL_OUTPUT" 2>/dev/null | head -5 | while IFS= read -r line; do
echo -e " ${DIM}${line}${NC}"
done
FAILED=$((FAILED + 1))
fi
echo ""
# ============================================================================
# Phase 10: Verify update checker source patterns
# ============================================================================
echo -e "${BOLD}Phase 4: Update mechanism source verification${NC}"
CHECKER_FILE="pkg/agent/update_checker.go"
TOTAL=$((TOTAL + 1))
if grep -q "atomic" "$CHECKER_FILE" 2>/dev/null; then
echo -e " ${GREEN}✓${NC} Atomic concurrency control present"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌${NC} Missing atomic concurrency control"
FAILED=$((FAILED + 1))
fi
TOTAL=$((TOTAL + 1))
if grep -q "defer" "$CHECKER_FILE" 2>/dev/null; then
echo -e " ${GREEN}✓${NC} Defer-based cleanup present"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌${NC} Missing defer-based cleanup"
FAILED=$((FAILED + 1))
fi
TOTAL=$((TOTAL + 1))
if grep -q "channel\|Channel" "$CHECKER_FILE" 2>/dev/null; then
echo -e " ${GREEN}✓${NC} Update channel support present"
PASSED=$((PASSED + 1))
else
echo -e " ${RED}❌${NC} Missing update channel support"
FAILED=$((FAILED + 1))
fi
echo ""
# ============================================================================
# Generate reports
# ============================================================================
cat > "$REPORT_JSON" << EOF
{
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"summary": {
"total": ${TOTAL},
"passed": ${PASSED},
"failed": ${FAILED}
},
"phases": {
"unitTests": { "exit_code": ${TEST_EXIT}, "passed": ${GO_PASSED} },
"stressTest": { "exit_code": ${STRESS_EXIT} },
"panicRecovery": { "exit_code": ${PANIC_EXIT} },
"reliabilityLoop": { "exit_code": ${LOOP_EXIT} },
"buildTimeout": { "exit_code": ${TIMEOUT_EXIT} },
"buildFailure": { "exit_code": ${BUILDFAIL_EXIT} },
"npmRetry": { "exit_code": ${RETRY_EXIT} },
"heartbeat": { "exit_code": ${HEARTBEAT_EXIT} },
"utilities": { "exit_code": ${UTIL_EXIT} }
}
}
EOF
cat > "$REPORT_MD" << EOF
# Update Lifecycle Verification
**Date:** $(date -u +%Y-%m-%dT%H:%M:%SZ)
## Summary
| Metric | Count |
|----------|-------|
| Total | ${TOTAL} |
| Passed | ${PASSED} |
| Failed | ${FAILED} |
## Phases
- **Phase 1:** Update checker unit tests — $([ "$TEST_EXIT" -eq 0 ] && echo "PASS" || echo "FAIL")
- **Phase 2:** Concurrent rejection stress — $([ "$STRESS_EXIT" -eq 0 ] && echo "PASS" || echo "FAIL")
- **Phase 3:** Panic recovery — $([ "$PANIC_EXIT" -eq 0 ] && echo "PASS" || echo "FAIL")
- **Phase 4:** 5x reliability loop — $([ "$LOOP_EXIT" -eq 0 ] && echo "PASS" || echo "FAIL")
- **Phase 5:** Build timeout — $([ "$TIMEOUT_EXIT" -eq 0 ] && echo "PASS" || echo "FAIL")
- **Phase 6:** Build failure capture — $([ "$BUILDFAIL_EXIT" -eq 0 ] && echo "PASS" || echo "FAIL")
- **Phase 7:** npm retry — $([ "$RETRY_EXIT" -eq 0 ] && echo "PASS" || echo "FAIL")
- **Phase 8:** Heartbeat — $([ "$HEARTBEAT_EXIT" -eq 0 ] && echo "PASS" || echo "FAIL")
- **Phase 9:** Utilities — $([ "$UTIL_EXIT" -eq 0 ] && echo "PASS" || echo "FAIL")
- **Phase 10:** Source pattern verification
EOF
# ============================================================================
# Summary
# ============================================================================
if [ "$PASSED" -eq 0 ] && [ "$FAILED" -eq 0 ]; then
echo -e "${RED}${BOLD}No tests were executed${NC}"
elif [ "$FAILED" -eq 0 ]; then
echo -e "${GREEN}${BOLD}All ${PASSED} update lifecycle checks passed${NC}"
else
echo -e "${RED}${BOLD}${FAILED}/${TOTAL} update lifecycle checks failed${NC}"
fi
echo ""
echo "Reports:"
echo " JSON: $REPORT_JSON"
echo " Summary: $REPORT_MD"
[ "$PASSED" -eq 0 ] && [ "$FAILED" -eq 0 ] && exit 1
[ "$FAILED" -gt 0 ] && exit 1
exit 0