-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacceptance_dock_lifecycle.sh
More file actions
executable file
·403 lines (355 loc) · 10.2 KB
/
Copy pathacceptance_dock_lifecycle.sh
File metadata and controls
executable file
·403 lines (355 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
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
usage: acceptance_dock_lifecycle.sh [--build-dir DIR] [--log-dir DIR] [--live-wayland]
运行 dock lifecycle 验收。
默认行为:
- 运行 dock lifecycle Meson 测试目标
- 记录统一日志到 BIT_SHELL_LOG_DIR 或 ~/logs
可选 live smoke:
- 需要 WAYLAND_DISPLAY、已编译 bit_dock,以及 python3
- 若同时提供 NIRI_SOCKET 和 niri 命令,会额外校验 bit-dock layer surface 挂载与退出清理
环境变量:
- BIT_SHELL_BUILD_DIR: build 目录,默认 <repo>/build
- BIT_SHELL_LOG_DIR: 日志目录,默认 ~/logs
EOF
}
step() {
printf '\n==> %s\n' "$*"
}
require_file() {
local path="$1"
if [[ ! -e "$path" ]]; then
printf 'missing required file: %s\n' "$path" >&2
exit 1
fi
}
run_cmd() {
step "$*"
"$@"
}
resolve_log_dir() {
local preferred="$1"
local fallback="${repo_root}/build/devtools-logs"
if mkdir -p "$preferred" 2>/dev/null && [[ -w "$preferred" ]]; then
printf '%s\n' "$preferred"
return
fi
mkdir -p "$fallback"
printf '%s\n' "$fallback"
}
wait_for_grep() {
local command="$1"
local pattern="$2"
local attempts="${3:-20}"
local delay="${4:-0.2}"
local output
for ((i = 0; i < attempts; i++)); do
output="$(eval "$command" 2>/dev/null || true)"
if printf '%s' "$output" | grep -Eq "$pattern"; then
return 0
fi
sleep "$delay"
done
return 1
}
wait_for_file_grep() {
local file="$1"
local pattern="$2"
local attempts="${3:-30}"
local delay="${4:-0.2}"
for ((i = 0; i < attempts; i++)); do
if [[ -f "$file" ]] && grep -Eq "$pattern" "$file"; then
return 0
fi
sleep "$delay"
done
return 1
}
namespace_present() {
local namespace="$1"
[[ -n "${NIRI_SOCKET:-}" ]] \
&& command -v niri >/dev/null 2>&1 \
&& NIRI_SOCKET="${NIRI_SOCKET}" niri msg --json layers 2>/dev/null \
| grep -Eq "\"namespace\"[[:space:]]*:[[:space:]]*\"${namespace}\""
}
require_clean_process_name() {
local process_name="$1"
local pids
pids="$(pgrep -x "$process_name" || true)"
if [[ -n "$pids" ]]; then
printf 'live smoke requires no running %s instance; found pid(s): %s\n' "$process_name" "$pids" >&2
exit 1
fi
}
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
repo_root="$(cd "${script_dir}/../.." && pwd)"
build_dir="${BIT_SHELL_BUILD_DIR:-${repo_root}/build}"
log_dir="${BIT_SHELL_LOG_DIR:-${HOME}/logs}"
live_wayland=0
while [[ $# -gt 0 ]]; do
case "$1" in
--build-dir)
build_dir="$2"
shift 2
;;
--log-dir)
log_dir="$2"
shift 2
;;
--live-wayland)
live_wayland=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
printf 'unknown argument: %s\n' "$1" >&2
usage >&2
exit 1
;;
esac
done
log_dir="$(resolve_log_dir "$log_dir")"
log_file="${log_dir}/acceptance_dock_lifecycle_$(date +%Y-%m-%d_%H-%M-%S).log"
exec > >(tee -a "$log_file") 2>&1
step "dock lifecycle acceptance log: ${log_file}"
require_file "${repo_root}/meson.build"
require_file "${build_dir}/build.ninja"
run_cmd meson compile -C "$build_dir"
run_cmd meson test -C "$build_dir" bit_dock_widget_lifecycle
if [[ "$live_wayland" -eq 0 ]]; then
step "skip live Wayland smoke (pass --live-wayland to enable)"
exit 0
fi
require_file "${build_dir}/core/bit_dock"
if [[ -z "${WAYLAND_DISPLAY:-}" ]]; then
printf 'live smoke requires WAYLAND_DISPLAY\n' >&2
exit 1
fi
if ! command -v python3 >/dev/null 2>&1; then
printf 'live smoke requires python3\n' >&2
exit 1
fi
require_clean_process_name bit_dock
runtime_dir="${XDG_RUNTIME_DIR:-/tmp}"
socket_path="$(mktemp -u "${runtime_dir}/bit_shell_acceptance_dock.XXXXXX.sock")"
server_pid=""
dock_pid=""
server_log="${log_dir}/acceptance_dock_lifecycle_fake_ipc_$(date +%Y-%m-%d_%H-%M-%S).log"
layer_check_enabled=1
cleanup() {
if [[ -n "$dock_pid" ]] && kill -0 "$dock_pid" 2>/dev/null; then
kill "$dock_pid" 2>/dev/null || true
wait "$dock_pid" 2>/dev/null || true
fi
if [[ -n "$server_pid" ]] && kill -0 "$server_pid" 2>/dev/null; then
kill "$server_pid" 2>/dev/null || true
wait "$server_pid" 2>/dev/null || true
fi
rm -f "$socket_path"
}
trap cleanup EXIT
step "start fake IPC server on ${socket_path}"
python3 - "$socket_path" >"$server_log" 2>&1 <<'PY' &
import json
import os
import socket
import sys
import time
sock_path = sys.argv[1]
messages = [
{
"kind": "snapshot",
"state": {
"dock": {
"items": [
{
"app_key": "org.test.DockApp",
"desktop_id": "org.test.DockApp.desktop",
"name": "Dock App",
"icon_name": "folder",
"window_ids": ["w-1"],
"pinned": True,
"running": True,
"focused": True,
"pinned_index": 0,
}
]
},
"settings": {
"dock": {
"icon_size_px": 48,
"magnification_enabled": False,
"hover_range_cap_units": 3,
"spacing_px": 8,
"bottom_margin_px": 8,
"show_running_indicator": True,
"animate_opening_apps": False,
"display_mode": "icons",
"center_on_primary_output": False,
}
},
},
},
{
"kind": "event",
"topic": "dock",
"payload": {
"items": [
{
"app_key": "org.test.DockApp",
"desktop_id": "org.test.DockApp.desktop",
"name": "Fallback",
"window_ids": ["w-1"],
"pinned": True,
"running": True,
"focused": True,
"pinned_index": 0,
}
]
},
},
{
"kind": "event",
"topic": "settings",
"payload": {
"dock": {
"icon_size_px": 56,
"magnification_enabled": False,
"hover_range_cap_units": 3,
"spacing_px": 10,
"bottom_margin_px": 8,
"show_running_indicator": True,
"animate_opening_apps": False,
"display_mode": "icons",
"center_on_primary_output": False,
}
},
},
{
"kind": "event",
"topic": "dock",
"payload": {
"items": [
{
"app_key": "org.test.DockApp",
"desktop_id": "org.test.DockApp.desktop",
"name": "Dock App",
"icon_name": "edit-copy",
"window_ids": ["w-1"],
"pinned": True,
"running": True,
"focused": True,
"pinned_index": 0,
}
]
},
},
]
if os.path.exists(sock_path):
os.unlink(sock_path)
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server.bind(sock_path)
server.listen(1)
server.settimeout(5.0)
try:
conn, _ = server.accept()
conn.settimeout(0.1)
start = time.time()
while time.time() - start < 0.5:
try:
data = conn.recv(4096)
except TimeoutError:
data = b""
if not data:
time.sleep(0.05)
continue
if b"subscribe" in data:
break
for message in messages:
conn.sendall((json.dumps(message) + "\n").encode("utf-8"))
time.sleep(0.35)
time.sleep(0.35)
conn.close()
except socket.timeout:
print("fake IPC server timed out waiting for client", file=sys.stderr)
sys.exit(2)
finally:
server.close()
if os.path.exists(sock_path):
os.unlink(sock_path)
PY
server_pid="$!"
for ((i = 0; i < 30; i++)); do
if [[ -S "$socket_path" ]]; then
break
fi
sleep 0.2
done
if [[ ! -S "$socket_path" ]]; then
printf 'fake IPC server did not create socket: %s\n' "$socket_path" >&2
exit 1
fi
step "start bit_dock live smoke"
G_DEBUG=fatal-criticals BIT_SHELL_SOCKET="$socket_path" "${build_dir}/core/bit_dock" &
dock_pid="$!"
if ! wait_for_file_grep \
"$log_file" \
'\[bit_dock\] IPC connected and subscribed to dock/settings topics'; then
printf 'bit_dock did not complete IPC bootstrap, see %s\n' "$log_file" >&2
exit 1
fi
if namespace_present "bit-dock"; then
step "existing bit-dock surface detected; skip namespace-based layer checks"
layer_check_enabled=0
fi
if [[ "$layer_check_enabled" -eq 1 && -n "${NIRI_SOCKET:-}" ]] && command -v niri >/dev/null 2>&1; then
if ! wait_for_grep \
"NIRI_SOCKET='${NIRI_SOCKET}' niri msg --json layers" \
'"namespace"[[:space:]]*:[[:space:]]*"bit-dock"'; then
printf 'bit_dock layer surface was not observed in niri layers\n' >&2
exit 1
fi
step "bit_dock layer surface observed"
fi
for ((i = 0; i < 50; i++)); do
if ! kill -0 "$server_pid" 2>/dev/null; then
break
fi
sleep 0.2
done
if kill -0 "$server_pid" 2>/dev/null; then
printf 'fake IPC server did not finish within timeout, see %s\n' "$server_log" >&2
exit 1
fi
if ! wait "$server_pid"; then
printf 'fake IPC server exited with failure, see %s\n' "$server_log" >&2
exit 1
fi
server_pid=""
sleep 1
if ! kill -0 "$dock_pid" 2>/dev/null; then
printf 'bit_dock exited unexpectedly during live smoke\n' >&2
exit 1
fi
if grep -Eq "invalid unclassed pointer in cast to 'GtkImage'|GTK_IS_IMAGE \(image\) failed" "$log_file"; then
printf 'detected forbidden GtkImage lifecycle critical in %s\n' "$log_file" >&2
exit 1
fi
kill "$dock_pid"
wait "$dock_pid" || true
dock_pid=""
if [[ "$layer_check_enabled" -eq 1 && -n "${NIRI_SOCKET:-}" ]] && command -v niri >/dev/null 2>&1; then
if wait_for_grep \
"NIRI_SOCKET='${NIRI_SOCKET}' niri msg --json layers" \
'"namespace"[[:space:]]*:[[:space:]]*"bit-dock"'; then
printf 'bit_dock layer surface still present after exit\n' >&2
exit 1
fi
step "bit_dock layer surface cleaned up after exit"
fi
step "fake IPC server log: ${server_log}"