Repository navigation
Expand file tree
/
Copy pathverify.sh
More file actions
executable file
·608 lines (532 loc) · 25.6 KB
/
Copy pathverify.sh
File metadata and controls
executable file
·608 lines (532 loc) · 25.6 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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
#!/bin/bash
# verify.sh — assert the cross-layer invariants on an installed agent.
#
# WHY THIS EXISTS
#
# Every defect that reached a live site during the managed-hosting rollout was a
# disagreement BETWEEN layers, not a fault within one:
#
# unit User= vs unit HOME the agent ran with a home it cannot read
# recorded option vs manifest file capture read a set the site had moved on from
# manifest vs harvest components a hardcoded list drifted from the declaration
# owned set vs permission.edit declared editable, actually denied
# function vs the lib its caller sources
# a guard silently skipped, leaving database
# credentials group-writable
#
# Each component was internally correct and individually tested. Nothing owned
# the seam, so nothing failed until someone looked — and the looking is what
# does not scale. An operator with two sites inspects a rendered systemd unit
# before starting services. An operator with two thousand does not.
#
# So the seams get an owner. This asserts them, exits non-zero on disagreement,
# and is cheap enough to run on a schedule.
#
# WHAT IT DELIBERATELY DOES NOT DO
#
# It never repairs. A check that fixes what it finds cannot be trusted to report
# honestly, and the failure it hides is exactly the one worth seeing: silent
# convergence is how "it works on my box" survives. `./upgrade.sh` is the
# repair; this is the measurement.
#
# Usage:
# ./verify.sh [--site-path PATH] [--quiet] [--json]
#
# Exit: 0 all invariants hold, 1 at least one disagreement, 2 cannot check.
set -u
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/lib/common.sh"
source "$SCRIPT_DIR/lib/source-policy.sh"
source "$SCRIPT_DIR/lib/agents-md-guidance.sh"
source "$SCRIPT_DIR/lib/systems-capabilities.sh"
source "$SCRIPT_DIR/lib/codebox-database.sh"
source "$SCRIPT_DIR/lib/composer-provision.sh"
QUIET=false
JSON=false
SITE_PATH="${SITE_PATH:-}"
while [ $# -gt 0 ]; do
case "$1" in
--runtime|--runtime=*) error "--runtime was removed with OpenCode (#751). Pi is the only runtime." ;;
--site-path) SITE_PATH="$2"; shift 2 ;;
--quiet) QUIET=true; shift ;;
--json) JSON=true; QUIET=true; shift ;;
--help|-h)
sed -n '2,30p' "$0" | sed 's/^# \{0,1\}//'
exit 0 ;;
*) shift ;;
esac
done
PASSED=0
FAILED=0
SKIPPED=0
FINDINGS=""
_say() { [ "$QUIET" = true ] || printf '%s\n' "$1"; }
pass() {
PASSED=$((PASSED + 1))
_say " ok $1"
}
# A disagreement. The message must name BOTH sides — "permissions are wrong" is
# not actionable; "declared X, permission.edit allows Y" is.
fail() {
FAILED=$((FAILED + 1))
FINDINGS="${FINDINGS}${1}"$'\n'
_say " FAIL $1"
}
# Something this cannot see from here. Distinct from a pass on purpose: an
# invariant that could not be checked has not been shown to hold, and reporting
# it as fine is how a check becomes decoration.
skip() {
SKIPPED=$((SKIPPED + 1))
_say " skip $1"
}
section() { _say ""; _say "$1"; }
# ---------------------------------------------------------------------------
# Environment
# ---------------------------------------------------------------------------
if [ -z "$SITE_PATH" ]; then
for candidate in /var/www/*/; do
[ -f "${candidate}wp-config.php" ] || continue
SITE_PATH="${candidate%/}"
break
done
fi
if [ -z "$SITE_PATH" ] || [ ! -f "$SITE_PATH/wp-config.php" ]; then
echo "verify: no WordPress install found (pass --site-path)" >&2
exit 2
fi
wp_cli_transport_ensure
command -v "${WP_CLI_TRANSPORT[0]}" >/dev/null 2>&1 || { echo "verify: $(wp_cli_transport_display) not on PATH" >&2; exit 2; }
WP_ROOT_FLAG=""
[ "$(id -u)" -eq 0 ] && WP_ROOT_FLAG="--allow-root"
wp_opt() {
wp_cli option get "$1" $WP_ROOT_FLAG --path="$SITE_PATH" 2>/dev/null \
| sed -e '/^PHP Deprecated:/d' -e '/^Deprecated:/d' || true
}
SOURCE_MODE="$(wp_opt wp_coding_agents_source_mode | tr -d '[:space:]')"
[ -n "$SOURCE_MODE" ] || SOURCE_MODE="$(wp_opt wp_coding_agents_posture | tr -d '[:space:]')"
case "$SOURCE_MODE" in
managed) SOURCE_MODE=owned ;;
engineering) SOURCE_MODE=workspace ;;
esac
_say "wp-coding-agents verify"
_say " site: $SITE_PATH"
_say " source mode: ${SOURCE_MODE:-<unset>}"
# ---------------------------------------------------------------------------
# Guidance producer freshness
# ---------------------------------------------------------------------------
section "guidance producer freshness"
EXPECTED_PRODUCER="version=$(agents_md_guidance_producer_version) source=$(agents_md_guidance_producer_source)"
GUIDANCE_PLUGIN="$SITE_PATH/wp-content/mu-plugins/wp-coding-agents-agents-md.php"
COMPOSED_GUIDANCE="$SITE_PATH/AGENTS.md"
GUIDANCE_DRIFT=false
guidance_producers() {
[ -f "$1" ] || return 0
sed -n 's/.*wp-coding-agents-provenance: version=\([^ ]*\) source=\([^ ]*\).*/version=\1 source=\2/p' "$1" | sort -u
}
pass "source checkout producer: $EXPECTED_PRODUCER"
INSTALLED_PRODUCER="$(guidance_producers "$GUIDANCE_PLUGIN")"
if [ -z "$INSTALLED_PRODUCER" ]; then
GATE_STATUS=0
agents_md_guidance_composition_gate wp_cli $WP_ROOT_FLAG --path="$SITE_PATH" || GATE_STATUS=$?
case "$GATE_STATUS" in
1|2) pass "Data Machine AGENTS.md composition is disabled or unavailable; installed guidance is gated" ;;
*)
fail "installed guidance plugin has no producer provenance — source checkout is $EXPECTED_PRODUCER"
GUIDANCE_DRIFT=true
;;
esac
elif [ "$INSTALLED_PRODUCER" = "$EXPECTED_PRODUCER" ]; then
pass "installed guidance plugin matches the source checkout"
else
fail "installed guidance plugin is $INSTALLED_PRODUCER; source checkout is $EXPECTED_PRODUCER"
GUIDANCE_DRIFT=true
fi
COMPOSED_PRODUCER="$(guidance_producers "$COMPOSED_GUIDANCE")"
if [ -z "$COMPOSED_PRODUCER" ]; then
GATE_STATUS=0
agents_md_guidance_composition_gate wp_cli $WP_ROOT_FLAG --path="$SITE_PATH" || GATE_STATUS=$?
case "${GATE_STATUS:-0}" in
1|2) pass "Data Machine AGENTS.md composition is disabled or unavailable; freshness is gated" ;;
*)
fail "generated AGENTS.md has no producer provenance — installed guidance is ${INSTALLED_PRODUCER:-unknown}; Data Machine AGENTS.md composition is not explicitly disabled or unavailable"
GUIDANCE_DRIFT=true
;;
esac
elif [ "$COMPOSED_PRODUCER" = "$INSTALLED_PRODUCER" ]; then
pass "generated AGENTS.md matches the installed guidance plugin"
else
fail "generated AGENTS.md is $COMPOSED_PRODUCER; installed guidance plugin is $INSTALLED_PRODUCER"
GUIDANCE_DRIFT=true
fi
if [ -z "$COMPOSED_PRODUCER" ]; then
: # The active guidance gate above is a healthy, intentionally unverifiable state.
elif [ "$COMPOSED_PRODUCER" = "$EXPECTED_PRODUCER" ]; then
pass "runtime/service guidance is current for new sessions"
else
fail "runtime/service guidance is $COMPOSED_PRODUCER; source checkout is $EXPECTED_PRODUCER"
GUIDANCE_DRIFT=true
fi
if [ "$GUIDANCE_DRIFT" = true ]; then
_say " remedy: ./upgrade.sh --agents-md-only"
fi
# ---------------------------------------------------------------------------
# Seam 0: workspace declarations must point at native repositories and match
# the runtime permission surface that makes them editable.
# ---------------------------------------------------------------------------
section "workspace repository agreement"
if [ "$SOURCE_MODE" != "workspace" ]; then
skip "not a workspace-mode install"
else
PROFILE="$SITE_PATH/.wp-coding-agents/installation-profile"
DECLARED_WORKSPACE_REPOSITORIES=""
if [ -f "$PROFILE" ]; then
DECLARED_WORKSPACE_REPOSITORIES="$(awk -F= '$1 == "workspace_repositories" { print substr($0, index($0, "=") + 1); exit }' "$PROFILE")"
fi
if [ -z "$DECLARED_WORKSPACE_REPOSITORIES" ]; then
skip "no declared workspace repositories — cannot validate repository authority"
else
while IFS= read -r repository; do
[ -n "$repository" ] || continue
if ! git -C "$repository" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
fail "declared workspace repository $repository is not a reachable Git checkout"
continue
fi
pass "declared repository $repository is a Git checkout"
done < <(printf '%s\n' "$DECLARED_WORKSPACE_REPOSITORIES" | tr ':' '\n')
fi
fi
# ---------------------------------------------------------------------------
# Seam 1: the recorded set, the manifest, and the permissions must agree
# ---------------------------------------------------------------------------
section "owned set agreement"
if [ "$SOURCE_MODE" != "owned" ]; then
skip "not an owned-mode install — no owned set to agree about"
else
RECORDED="$(wp_opt wp_coding_agents_owned_sources | sed '/^[[:space:]]*$/d' | sort)"
[ -n "$RECORDED" ] || RECORDED="$(wp_opt wp_coding_agents_managed_sources | sed '/^[[:space:]]*$/d' | sort)"
SITE_KEY="$(basename "$SITE_PATH")"
MANIFEST="${SOURCE_POLICY_MANIFEST_ROOT:-/var/lib/wp-coding-agents}/$SITE_KEY/owned-sources"
if [ -z "$RECORDED" ]; then
fail "owned mode records no sources — the agent has no editable source at all"
else
pass "recorded owned sources: $(printf '%s' "$RECORDED" | tr '\n' ' ')"
fi
if [ ! -f "$MANIFEST" ]; then
fail "manifest missing at $MANIFEST — out-of-band capture cannot learn the editable set"
else
MANIFEST_SET="$(sed '/^[[:space:]]*$/d' "$MANIFEST" | sort)"
if [ "$MANIFEST_SET" = "$RECORDED" ]; then
pass "manifest agrees with the recorded set"
else
fail "manifest disagrees with the recorded set — capture and permissions would diverge
recorded: $(printf '%s' "$RECORDED" | tr '\n' ' ')
manifest: $(printf '%s' "$MANIFEST_SET" | tr '\n' ' ')"
fi
# The reader is a deliberately unprivileged identity that cannot reach the
# database. A manifest it cannot read is the same as no manifest.
MODE="$(file_mode "$MANIFEST")"
case "$MODE" in
*4|*5|*6|*7) pass "manifest is world-readable ($MODE) — the capture identity can read it" ;;
*) fail "manifest mode $MODE is not world-readable — the capture identity cannot read it" ;;
esac
case "$MANIFEST" in
"$SITE_PATH"/*) fail "manifest lives inside the web root — it is fetchable over HTTP" ;;
*) pass "manifest lives outside the web root" ;;
esac
fi
fi
# ---------------------------------------------------------------------------
# Seam 2: the service identity must be internally coherent
# ---------------------------------------------------------------------------
section "service identity coherence"
UNIT_DIR="${SYSTEMD_UNIT_DIR:-/etc/systemd/system}"
UNITS_CHECKED=0
NON_ROOT_SERVICE=false
for unit in "$UNIT_DIR"/roadie*.service "$UNIT_DIR"/datamachine-worker.service "$UNIT_DIR"/homeboy-daemon.service; do
[ -f "$unit" ] || continue
UNITS_CHECKED=$((UNITS_CHECKED + 1))
name="$(basename "$unit")"
if host_has_local_database && ! agent_systemd_memory_ceiling_present "$name"; then
warn "$name has no effective memory ceiling alongside a local database; run upgrade.sh"
fi
u_user="$(awk -F= '/^User=/ {print $2; exit}' "$unit")"
[ -n "$u_user" ] || continue
[ "$u_user" = "root" ] || NON_ROOT_SERVICE=true
u_home="$(getent passwd "$u_user" 2>/dev/null | cut -d: -f6)"
[ -n "$u_home" ] || u_home="/home/$u_user"
[ "$u_user" = "root" ] && u_home="/root"
env_home="$(awk -F= '/^Environment=HOME=/ {print $3; exit}' "$unit")"
if [ -z "$env_home" ]; then
skip "$name declares no HOME"
elif [ "$env_home" = "$u_home" ]; then
pass "$name: User=$u_user and HOME=$env_home agree"
else
fail "$name: User=$u_user but HOME=$env_home — the service cannot read its own home"
fi
# Any value pointing into a home that is not this user's is left over from an
# identity that no longer exists.
while IFS= read -r line; do
value="${line#Environment=*=}"
case "$value" in
/root/*|/home/*)
case "$value" in
"$u_home"/*|"$u_home") ;;
*) fail "$name: '${line%%=*}=${line#Environment=}' points outside ${u_user}'s home" ;;
esac
;;
esac
done < <(grep '^Environment=' "$unit" 2>/dev/null | grep -vE '^Environment=(PATH|HOME)=')
done
[ "$UNITS_CHECKED" -eq 0 ] && skip "no agent systemd units on this host"
# The site root's own mode is part of the sharing contract (#644): a non-root
# service identity that is a member of the webroot group can create and
# replace files at the site root only when the root directory itself is
# group-writable — which is how Data Machine's session-start composition
# atomically writes AGENTS.md there. setup's one-time recursive grant does
# not survive an external directory replacement, so measure the drift here;
# ./upgrade.sh owns the repair.
if [ "$NON_ROOT_SERVICE" != true ]; then
skip "no non-root agent service — the site-root sharing contract does not apply"
elif [ ! -d "$SITE_PATH" ]; then
skip "no site root directory at $SITE_PATH"
else
SR_MODE="$(file_mode "$SITE_PATH" 2>/dev/null || true)"
case "${SR_MODE: -2:1}" in
2|3|6|7)
pass "site root is group-writable ($SR_MODE) — the service identity can write at the root" ;;
*)
if [ -n "$SR_MODE" ]; then
fail "site root mode $SR_MODE is not group-writable — AGENTS.md composition at the root fails; repair with: sudo chmod g+w $SITE_PATH"
else
skip "cannot read the site root mode"
fi ;;
esac
fi
HOMEBOY_MANAGED_BIN="${WP_CODING_AGENTS_HOMEBOY_MANAGED_BIN:-/usr/local/lib/wp-coding-agents/bin/homeboy}"
if [ -x "$HOMEBOY_MANAGED_BIN" ]; then
HOMEBOY_BIN_DIR="$(dirname "$HOMEBOY_MANAGED_BIN")"
HOMEBOY_MODE="$(file_mode "$HOMEBOY_MANAGED_BIN" 2>/dev/null || true)"
case "$HOMEBOY_MODE" in
755) pass "managed Homeboy executable is mode 755 at $HOMEBOY_MANAGED_BIN" ;;
*) fail "managed Homeboy executable is mode ${HOMEBOY_MODE:-unknown}, expected 755 at $HOMEBOY_MANAGED_BIN" ;;
esac
while IFS= read -r unit; do
[ -f "$unit" ] || continue
if grep '^Environment=PATH=' "$unit" | grep -Fq "$HOMEBOY_BIN_DIR"; then
pass "$(basename "$unit") PATH includes managed Homeboy directory"
else
fail "$(basename "$unit") PATH does not include $HOMEBOY_BIN_DIR — service and guidance may select different Homeboy binaries"
fi
done < <(printf '%s\n' "$UNIT_DIR"/roadie*.service)
# The pin is the release this install ships (homeboy.json dependency_stack);
# upgrade converges on it. A binary on any other version was moved by hand
# and is invisible to the deploy summary that reports the pin.
HOMEBOY_PIN="$(tr -d '[:space:]' 2>/dev/null < "$SCRIPT_DIR/services/homeboy-version" || true)"
HOMEBOY_RUNNING="$("$HOMEBOY_MANAGED_BIN" --version 2>/dev/null | head -1 || true)"
HOMEBOY_RUNNING="${HOMEBOY_RUNNING#homeboy }"
HOMEBOY_RUNNING="${HOMEBOY_RUNNING%%+*}"
if [ -z "$HOMEBOY_PIN" ]; then
skip "no Homeboy pin at services/homeboy-version"
elif [ -z "$HOMEBOY_RUNNING" ]; then
skip "cannot read the managed Homeboy version"
elif [ "$HOMEBOY_RUNNING" = "$HOMEBOY_PIN" ]; then
pass "managed Homeboy is at the pinned $HOMEBOY_PIN"
else
fail "managed Homeboy is $HOMEBOY_RUNNING but this install pins $HOMEBOY_PIN — the next upgrade converges it; check: homeboy upgrade status"
fi
else
skip "no executable managed Homeboy at $HOMEBOY_MANAGED_BIN"
fi
# ---------------------------------------------------------------------------
# Seam 3: the pieces owned mode requires must actually be installed
# ---------------------------------------------------------------------------
section "owned-mode components"
if [ "$SOURCE_MODE" != "owned" ]; then
skip "not an owned-mode install"
else
for mu in wp-coding-agents-source-reconcile wp-coding-agents-runtime-guard; do
if [ -f "$SITE_PATH/wp-content/mu-plugins/$mu.php" ]; then
pass "$mu is installed"
else
fail "$mu is missing — owned mode is not fully applied"
fi
done
# A reconcile that cannot write is a reconcile that reports success and
# changes nothing.
MANIFEST_DIR="${SOURCE_POLICY_MANIFEST_ROOT:-/var/lib/wp-coding-agents}/$(basename "$SITE_PATH")"
if [ -d "$MANIFEST_DIR" ]; then
# Answering this requires becoming another user, which requires root. When
# that is impossible the invariant has not been shown to hold and must be
# reported as unchecked — not as a failure, which would cry wolf on every
# unprivileged run, and not as a pass, which is how a checker becomes
# decoration.
if [ "$(id -u)" -ne 0 ] || ! id -u www-data >/dev/null 2>&1; then
skip "cannot test manifest writability without root and a www-data account"
elif su -s /bin/bash www-data -c "test -w '$MANIFEST_DIR'" 2>/dev/null; then
pass "the web user can write the manifest directory"
else
fail "www-data cannot write $MANIFEST_DIR — the reactive reconcile updates the option and leaves capture reading a stale file"
fi
fi
fi
# ---------------------------------------------------------------------------
# Seam: a privilege grant is the most consequential file this harness writes and
# was, until now, the least examined one. Nothing here repaired or even read
# /etc/sudoers.d, so a grant that had been hand-placed, widened, or left
# group-writable looked exactly like a grant that was installed correctly.
#
# Two of these are hard invariants. The third is a census: a grant this harness
# did not install is not wrong, but nothing reinstalls it after a rebuild and
# nothing notices when it changes — which is the state most grants on the first
# host to get this were in.
# ---------------------------------------------------------------------------
section "privilege grant agreement"
GRANT_DIR="${GRANTS_SUDOERS_DIR:-/etc/sudoers.d}"
if [ ! -d "$GRANT_DIR" ]; then
skip "no $GRANT_DIR on this host"
elif [ ! -r "$GRANT_DIR" ] || [ ! -x "$GRANT_DIR" ]; then
skip "$GRANT_DIR is not readable here — re-run as root to check privilege grants"
else
GRANT_COUNT=0
GRANT_PERM_BAD=0
GRANT_INVALID=0
GRANT_UNOWNED=""
for grant_path in "$GRANT_DIR"/*; do
[ -f "$grant_path" ] || continue
grant_name="$(basename "$grant_path")"
# sudo ignores backup and dotted names, so neither should this.
case "$grant_name" in
README|*~|*.*) continue ;;
esac
GRANT_COUNT=$((GRANT_COUNT + 1))
grant_owner="$(file_owner "$grant_path" 2>/dev/null || true)"
grant_group="$(file_group "$grant_path" 2>/dev/null || true)"
grant_mode="$(file_mode "$grant_path" 2>/dev/null || true)"
if [ "$grant_owner:$grant_group:$grant_mode" != "root:root:440" ]; then
fail "grant $grant_name is $grant_owner:$grant_group $grant_mode; sudo requires root:root 440"
GRANT_PERM_BAD=$((GRANT_PERM_BAD + 1))
fi
if command -v visudo >/dev/null 2>&1 && ! visudo -cf "$grant_path" >/dev/null 2>&1; then
fail "grant $grant_name is not valid sudoers policy — sudo may refuse to run for every user on this host"
GRANT_INVALID=$((GRANT_INVALID + 1))
fi
case "$grant_name" in
wp-coding-agents-*) ;;
*) GRANT_UNOWNED="${GRANT_UNOWNED}${grant_name} " ;;
esac
done
if [ "$GRANT_COUNT" -eq 0 ]; then
skip "no privilege grants installed on this host"
else
[ "$GRANT_PERM_BAD" -eq 0 ] && pass "all $GRANT_COUNT privilege grants are root:root 440"
if ! command -v visudo >/dev/null 2>&1; then
skip "visudo is unavailable; cannot validate grant policy syntax"
elif [ "$GRANT_INVALID" -eq 0 ]; then
pass "all $GRANT_COUNT privilege grants parse as valid sudoers policy"
fi
if [ -n "$GRANT_UNOWNED" ]; then
_say " note grants this harness does not install: ${GRANT_UNOWNED% }"
_say " these do not survive a host rebuild and nothing detects changes to them"
fi
fi
fi
# ---------------------------------------------------------------------------
# Seam: a provisioned test database user is not enough — it has to actually
# work, and it has to actually be unable to reach the site database. That
# second half is the security invariant #624 exists for: pointing a test
# harness at a scoped account instead of the site's own WordPress credentials
# only holds if the scoped account really cannot read production data.
# ---------------------------------------------------------------------------
section "codebox test database"
systems_capabilities_resolve_profile
if ! systems_capabilities_enabled; then
skip "managed-vps profile is not enabled on this install — no codebox test database expected"
elif [ ! -f "$CODEBOX_DATABASE_ENV_FILE" ]; then
skip "no codebox test database env file at $CODEBOX_DATABASE_ENV_FILE"
elif ! command -v "$CODEBOX_DATABASE_MYSQL_BIN" >/dev/null 2>&1; then
skip "$CODEBOX_DATABASE_MYSQL_BIN is not on PATH — cannot verify the codebox test database user"
elif [ "$(id -u)" -ne 0 ] && [ ! -r "$CODEBOX_DATABASE_ENV_FILE" ]; then
skip "$CODEBOX_DATABASE_ENV_FILE is root-owned and unreadable here — re-run as root to verify the codebox test database user"
else
CODEBOX_DB_USER="$(codebox_database_env_value WP_CODEBOX_DB_USER "$CODEBOX_DATABASE_ENV_FILE")"
CODEBOX_DB_PASSWORD="$(codebox_database_env_value WP_CODEBOX_DB_PASSWORD "$CODEBOX_DATABASE_ENV_FILE")"
CODEBOX_DB_HOST="$(codebox_database_env_value WP_CODEBOX_DB_HOST "$CODEBOX_DATABASE_ENV_FILE")"
CODEBOX_DB_PORT="$(codebox_database_env_value WP_CODEBOX_DB_PORT "$CODEBOX_DATABASE_ENV_FILE")"
if [ -z "$CODEBOX_DB_USER" ] || [ -z "$CODEBOX_DB_PASSWORD" ]; then
fail "$CODEBOX_DATABASE_ENV_FILE exists but is missing WP_CODEBOX_DB_USER or WP_CODEBOX_DB_PASSWORD"
else
CODEBOX_VERIFY_DB="codebox_verify_$$"
if MYSQL_PWD="$CODEBOX_DB_PASSWORD" "$CODEBOX_DATABASE_MYSQL_BIN" -h "$CODEBOX_DB_HOST" -P "$CODEBOX_DB_PORT" -u "$CODEBOX_DB_USER" \
-e "CREATE DATABASE \`$CODEBOX_VERIFY_DB\`; DROP DATABASE \`$CODEBOX_VERIFY_DB\`;" >/dev/null 2>&1; then
pass "codebox database user can create and drop a $CODEBOX_DATABASE_PATTERN database"
else
fail "codebox database user cannot create a $CODEBOX_DATABASE_PATTERN database — the test harness account does not work"
fi
SITE_DB_NAME="$(wp_cli config get DB_NAME $WP_ROOT_FLAG --path="$SITE_PATH" 2>/dev/null | wp_cli_strip_php_diagnostics | tr -d '[:space:]')"
if [ -z "$SITE_DB_NAME" ]; then
skip "could not resolve the site database name — cannot verify isolation from it"
elif MYSQL_PWD="$CODEBOX_DB_PASSWORD" "$CODEBOX_DATABASE_MYSQL_BIN" -h "$CODEBOX_DB_HOST" -P "$CODEBOX_DB_PORT" -u "$CODEBOX_DB_USER" \
"$SITE_DB_NAME" -e "SHOW TABLES;" >/dev/null 2>&1; then
fail "codebox database user CAN read the site database ($SITE_DB_NAME) — the isolation this account exists for is broken"
else
pass "codebox database user cannot read the site database ($SITE_DB_NAME)"
fi
fi
fi
# ---------------------------------------------------------------------------
# Seam: Homeboy's release preflight fails on any composer stderr output, and
# the distro composer package emits a PHP 8.4 deprecation notice on every
# call. A harness-owned Composer that is merely installed is not enough — it
# has to actually run clean on this host's PHP, or every release still fails
# the exact way #624 reports.
# ---------------------------------------------------------------------------
section "harness-owned Composer"
if ! systems_capabilities_enabled; then
skip "managed-vps profile is not enabled on this install — no harness-owned Composer expected"
elif [ ! -f "$(composer_provision_phar)" ]; then
skip "no harness-owned Composer at $(composer_provision_phar)"
elif composer_provision_healthy; then
pass "$(composer_provision_phar) runs clean on this host's PHP (no deprecation/warning output)"
else
fail "$(composer_provision_phar) exists but does not run clean — composer --version emitted output on stderr"
fi
if ! systems_capabilities_enabled; then
: # already reported above
elif [ ! -f "$(composer_provision_wrapper)" ]; then
skip "no wrapper at $(composer_provision_wrapper) — the service PATH would fall back to the distro composer"
else
WRAPPER_TARGET="$(command -v "$(basename "$(composer_provision_wrapper)")" 2>/dev/null || true)"
if [ "$WRAPPER_TARGET" = "$(composer_provision_wrapper)" ]; then
pass "the wrapper at $(composer_provision_wrapper) is first on PATH"
else
fail "PATH resolves 'composer' to ${WRAPPER_TARGET:-<not found>}, not $(composer_provision_wrapper) — releases may still hit the distro package"
fi
fi
# ---------------------------------------------------------------------------
# Read-only disk co-tenancy doctor. Warnings do not fail invariants, but are
# included in JSON findings so unattended checks do not silently discard them.
section "agent state disk placement"
if [ -z "${DM_WORKSPACE_DIR:-}" ] && [ -f "$SITE_PATH/.wp-coding-agents/installation-profile" ]; then
DM_WORKSPACE_DIR="$(awk -F= '$1 == "workspace_repositories" { split(substr($0, index($0, "=") + 1), roots, ":"); print roots[1]; exit }' "$SITE_PATH/.wp-coding-agents/installation-profile")"
fi
DOCTOR_HOME="${SERVICE_HOME:-}"
if [ -z "$DOCTOR_HOME" ] && command -v systemctl >/dev/null 2>&1; then
DOCTOR_USER="$(systemctl show roadie.service -p User --value 2>/dev/null || true)"
[ -z "$DOCTOR_USER" ] || DOCTOR_HOME="$(getent passwd "$DOCTOR_USER" | cut -d: -f6)"
fi
if [ "$(uname -s)" != Darwin ] && [ -n "$DOCTOR_HOME" ]; then
STATE_WARNING="$(agent_state_doctor "$DOCTOR_HOME" "$SITE_PATH")"
if [ -n "$STATE_WARNING" ]; then
FINDINGS="${FINDINGS}WARNING: ${STATE_WARNING}"$'\n'
_say " WARN $STATE_WARNING"
fi
fi
section "result"
_say " $PASSED passed, $FAILED failed, $SKIPPED skipped"
if [ "$JSON" = true ]; then
printf '{"passed":%d,"failed":%d,"skipped":%d,"findings":' "$PASSED" "$FAILED" "$SKIPPED"
printf '%s' "$FINDINGS" | python3 -c 'import json,sys; print(json.dumps([l for l in sys.stdin.read().split("\n") if l.strip()]))'
printf '}\n'
fi
[ "$FAILED" -eq 0 ] || exit 1
exit 0