opencode-pilot 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin/index.js +1 -1
- package/test/unit/paths.test.js +0 -15
- package/service/io.opencode.pilot.plist +0 -29
- package/test/run_tests.bash +0 -34
- package/test/test_actions.bash +0 -248
- package/test/test_cli.bash +0 -157
- package/test/test_helper.bash +0 -140
- package/test/test_plist.bash +0 -124
- package/test/test_poll_service.bash +0 -179
- package/test/test_poller.bash +0 -120
- package/test/test_readiness.bash +0 -313
- package/test/test_repo_config.bash +0 -192
- package/test/test_service.bash +0 -295
package/test/test_service.bash
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
# Tests for service/server.js - Standalone polling server
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
set -euo pipefail
|
|
7
|
-
|
|
8
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
9
|
-
source "$SCRIPT_DIR/test_helper.bash"
|
|
10
|
-
|
|
11
|
-
SERVICE_DIR="$(dirname "$SCRIPT_DIR")/service"
|
|
12
|
-
|
|
13
|
-
echo "Testing service/server.js module..."
|
|
14
|
-
echo ""
|
|
15
|
-
|
|
16
|
-
# =============================================================================
|
|
17
|
-
# File Structure Tests
|
|
18
|
-
# =============================================================================
|
|
19
|
-
|
|
20
|
-
test_service_file_exists() {
|
|
21
|
-
assert_file_exists "$SERVICE_DIR/server.js"
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
test_service_js_syntax() {
|
|
25
|
-
if ! command -v node &>/dev/null; then
|
|
26
|
-
echo "SKIP: node not available"
|
|
27
|
-
return 0
|
|
28
|
-
fi
|
|
29
|
-
node --check "$SERVICE_DIR/server.js" 2>&1 || {
|
|
30
|
-
echo "server.js has syntax errors"
|
|
31
|
-
return 1
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
# =============================================================================
|
|
36
|
-
# Export Tests
|
|
37
|
-
# =============================================================================
|
|
38
|
-
|
|
39
|
-
test_service_exports_start_service() {
|
|
40
|
-
grep -q "export.*function startService\|export.*startService" "$SERVICE_DIR/server.js" || {
|
|
41
|
-
echo "startService export not found in server.js"
|
|
42
|
-
return 1
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
test_service_exports_stop_service() {
|
|
47
|
-
grep -q "export.*function stopService\|export.*stopService" "$SERVICE_DIR/server.js" || {
|
|
48
|
-
echo "stopService export not found in server.js"
|
|
49
|
-
return 1
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
# =============================================================================
|
|
54
|
-
# Implementation Tests
|
|
55
|
-
# =============================================================================
|
|
56
|
-
|
|
57
|
-
test_service_has_http_server() {
|
|
58
|
-
grep -q "createServer\|http" "$SERVICE_DIR/server.js" || {
|
|
59
|
-
echo "HTTP server not found in server.js"
|
|
60
|
-
return 1
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
test_service_has_health_endpoint() {
|
|
65
|
-
grep -q "/health" "$SERVICE_DIR/server.js" || {
|
|
66
|
-
echo "/health endpoint not found in server.js"
|
|
67
|
-
return 1
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
test_service_logs_with_prefix() {
|
|
72
|
-
grep -q "\[opencode-pilot\]" "$SERVICE_DIR/server.js" || {
|
|
73
|
-
echo "Logging prefix [opencode-pilot] not found in server.js"
|
|
74
|
-
return 1
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
test_service_imports_poll_service() {
|
|
79
|
-
grep -q "poll-service" "$SERVICE_DIR/server.js" || {
|
|
80
|
-
echo "poll-service import not found in server.js"
|
|
81
|
-
return 1
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
# =============================================================================
|
|
86
|
-
# Functional Tests (requires Node.js)
|
|
87
|
-
# =============================================================================
|
|
88
|
-
|
|
89
|
-
test_service_starts_and_stops() {
|
|
90
|
-
if ! command -v node &>/dev/null; then
|
|
91
|
-
echo "SKIP: node not available"
|
|
92
|
-
return 0
|
|
93
|
-
fi
|
|
94
|
-
|
|
95
|
-
local result
|
|
96
|
-
result=$(node --experimental-vm-modules -e "
|
|
97
|
-
import { startService, stopService } from './service/server.js';
|
|
98
|
-
|
|
99
|
-
// Use random port to avoid conflicts
|
|
100
|
-
const config = {
|
|
101
|
-
httpPort: 0,
|
|
102
|
-
enablePolling: false
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const service = await startService(config);
|
|
106
|
-
|
|
107
|
-
if (!service.httpServer) {
|
|
108
|
-
console.log('FAIL: HTTP server not started');
|
|
109
|
-
process.exit(1);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
await stopService(service);
|
|
113
|
-
console.log('PASS');
|
|
114
|
-
" 2>&1) || {
|
|
115
|
-
echo "Functional test failed: $result"
|
|
116
|
-
return 1
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if ! echo "$result" | grep -q "PASS"; then
|
|
120
|
-
echo "$result"
|
|
121
|
-
return 1
|
|
122
|
-
fi
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
test_service_health_endpoint_returns_200() {
|
|
126
|
-
if ! command -v node &>/dev/null; then
|
|
127
|
-
echo "SKIP: node not available"
|
|
128
|
-
return 0
|
|
129
|
-
fi
|
|
130
|
-
|
|
131
|
-
local result
|
|
132
|
-
result=$(node --experimental-vm-modules -e "
|
|
133
|
-
import { startService, stopService } from './service/server.js';
|
|
134
|
-
|
|
135
|
-
const config = {
|
|
136
|
-
httpPort: 0,
|
|
137
|
-
enablePolling: false
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const service = await startService(config);
|
|
141
|
-
const port = service.httpServer.address().port;
|
|
142
|
-
|
|
143
|
-
const res = await fetch('http://localhost:' + port + '/health');
|
|
144
|
-
|
|
145
|
-
if (res.status !== 200) {
|
|
146
|
-
console.log('FAIL: Health check returned ' + res.status);
|
|
147
|
-
process.exit(1);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
await stopService(service);
|
|
151
|
-
console.log('PASS');
|
|
152
|
-
" 2>&1) || {
|
|
153
|
-
echo "Functional test failed: $result"
|
|
154
|
-
return 1
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if ! echo "$result" | grep -q "PASS"; then
|
|
158
|
-
echo "$result"
|
|
159
|
-
return 1
|
|
160
|
-
fi
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
test_service_returns_404_for_unknown_route() {
|
|
164
|
-
if ! command -v node &>/dev/null; then
|
|
165
|
-
echo "SKIP: node not available"
|
|
166
|
-
return 0
|
|
167
|
-
fi
|
|
168
|
-
|
|
169
|
-
local result
|
|
170
|
-
result=$(node --experimental-vm-modules -e "
|
|
171
|
-
import { startService, stopService } from './service/server.js';
|
|
172
|
-
|
|
173
|
-
const config = {
|
|
174
|
-
httpPort: 0,
|
|
175
|
-
enablePolling: false
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
const service = await startService(config);
|
|
179
|
-
const port = service.httpServer.address().port;
|
|
180
|
-
|
|
181
|
-
const res = await fetch('http://localhost:' + port + '/nonexistent');
|
|
182
|
-
|
|
183
|
-
if (res.status !== 404) {
|
|
184
|
-
console.log('FAIL: Expected 404, got ' + res.status);
|
|
185
|
-
process.exit(1);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
await stopService(service);
|
|
189
|
-
console.log('PASS');
|
|
190
|
-
" 2>&1) || {
|
|
191
|
-
echo "Functional test failed: $result"
|
|
192
|
-
return 1
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if ! echo "$result" | grep -q "PASS"; then
|
|
196
|
-
echo "$result"
|
|
197
|
-
return 1
|
|
198
|
-
fi
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
test_service_handles_cors_preflight() {
|
|
202
|
-
if ! command -v node &>/dev/null; then
|
|
203
|
-
echo "SKIP: node not available"
|
|
204
|
-
return 0
|
|
205
|
-
fi
|
|
206
|
-
|
|
207
|
-
local result
|
|
208
|
-
result=$(node --experimental-vm-modules -e "
|
|
209
|
-
import { startService, stopService } from './service/server.js';
|
|
210
|
-
|
|
211
|
-
const config = {
|
|
212
|
-
httpPort: 0,
|
|
213
|
-
enablePolling: false
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const service = await startService(config);
|
|
217
|
-
const port = service.httpServer.address().port;
|
|
218
|
-
|
|
219
|
-
// Send OPTIONS preflight request
|
|
220
|
-
const res = await fetch('http://localhost:' + port + '/health', {
|
|
221
|
-
method: 'OPTIONS'
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
if (res.status !== 204) {
|
|
225
|
-
console.log('FAIL: Expected 204 for OPTIONS, got ' + res.status);
|
|
226
|
-
process.exit(1);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const allowOrigin = res.headers.get('access-control-allow-origin');
|
|
230
|
-
if (allowOrigin !== '*') {
|
|
231
|
-
console.log('FAIL: Expected Access-Control-Allow-Origin: *, got ' + allowOrigin);
|
|
232
|
-
process.exit(1);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
await stopService(service);
|
|
236
|
-
console.log('PASS');
|
|
237
|
-
" 2>&1) || {
|
|
238
|
-
echo "Functional test failed: $result"
|
|
239
|
-
return 1
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if ! echo "$result" | grep -q "PASS"; then
|
|
243
|
-
echo "$result"
|
|
244
|
-
return 1
|
|
245
|
-
fi
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
# =============================================================================
|
|
249
|
-
# Run Tests
|
|
250
|
-
# =============================================================================
|
|
251
|
-
|
|
252
|
-
echo "File Structure Tests:"
|
|
253
|
-
|
|
254
|
-
for test_func in \
|
|
255
|
-
test_service_file_exists \
|
|
256
|
-
test_service_js_syntax
|
|
257
|
-
do
|
|
258
|
-
run_test "${test_func#test_}" "$test_func"
|
|
259
|
-
done
|
|
260
|
-
|
|
261
|
-
echo ""
|
|
262
|
-
echo "Export Tests:"
|
|
263
|
-
|
|
264
|
-
for test_func in \
|
|
265
|
-
test_service_exports_start_service \
|
|
266
|
-
test_service_exports_stop_service
|
|
267
|
-
do
|
|
268
|
-
run_test "${test_func#test_}" "$test_func"
|
|
269
|
-
done
|
|
270
|
-
|
|
271
|
-
echo ""
|
|
272
|
-
echo "Implementation Tests:"
|
|
273
|
-
|
|
274
|
-
for test_func in \
|
|
275
|
-
test_service_has_http_server \
|
|
276
|
-
test_service_has_health_endpoint \
|
|
277
|
-
test_service_logs_with_prefix \
|
|
278
|
-
test_service_imports_poll_service
|
|
279
|
-
do
|
|
280
|
-
run_test "${test_func#test_}" "$test_func"
|
|
281
|
-
done
|
|
282
|
-
|
|
283
|
-
echo ""
|
|
284
|
-
echo "Functional Tests:"
|
|
285
|
-
|
|
286
|
-
for test_func in \
|
|
287
|
-
test_service_starts_and_stops \
|
|
288
|
-
test_service_health_endpoint_returns_200 \
|
|
289
|
-
test_service_returns_404_for_unknown_route \
|
|
290
|
-
test_service_handles_cors_preflight
|
|
291
|
-
do
|
|
292
|
-
run_test "${test_func#test_}" "$test_func"
|
|
293
|
-
done
|
|
294
|
-
|
|
295
|
-
print_summary
|