mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 20:07:04 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
61 lines
2.8 KiB
Bash
Executable File
61 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Edge-conflict checks, site startup and Caddy reload.
|
|
#
|
|
# Sourced by setup_kcd2_dice_solver.sh; split out to keep kcd2_serve.sh
|
|
# under the 250-line cap. Sourced rather than run, so it inherits the
|
|
# caller's strict mode and the variables above the source line.
|
|
|
|
# This container shares the host network namespace with the public edge, so a
|
|
# misconfiguration here does not fail locally — it quietly steals a share of
|
|
# :80 or :443 from every other site on the box. Gate on it rather than trust
|
|
# the config to stay correct.
|
|
assert_no_edge_conflict() {
|
|
local pid listeners
|
|
pid="$(docker inspect -f '{{.State.Pid}}' "$DICE_CONTAINER" 2>/dev/null || echo "")"
|
|
[[ -n $pid && $pid != "0" ]] || die "Could not read the ${DICE_CONTAINER} PID."
|
|
|
|
listeners="$(sudo -n ss -ltnp 2>/dev/null | grep "pid=${pid}," || true)"
|
|
|
|
# Demand positive evidence FIRST. Asserting only the absence of :80/:443
|
|
# fails open: if `ss` returns nothing — a stale PID after a restart, or
|
|
# sudo -n unavailable — every "is it bad?" test misses and the guard happily
|
|
# reports success without having looked at anything.
|
|
if ! grep -qE '(^|[[:space:]])127\.0\.0\.1:'"${DICE_PORT}"'([[:space:]]|$)' <<<"$listeners"; then
|
|
docker stop "$DICE_CONTAINER" >/dev/null 2>&1 || true
|
|
die "Could not confirm ${DICE_CONTAINER} listens on 127.0.0.1:${DICE_PORT}. Container stopped."
|
|
fi
|
|
if grep -qE ':(80|443)\b' <<<"$listeners"; then
|
|
docker stop "$DICE_CONTAINER" >/dev/null 2>&1 || true
|
|
die "${DICE_CONTAINER} bound :80/:443 — it would contend with ${CADDY_CONTAINER}. Container stopped."
|
|
fi
|
|
# Must be on loopback, not 0.0.0.0/*: host networking would otherwise expose
|
|
# the unfronted static server to the whole LAN.
|
|
if grep -qE '(\*|0\.0\.0\.0):'"${DICE_PORT}"'\b' <<<"$listeners"; then
|
|
docker stop "$DICE_CONTAINER" >/dev/null 2>&1 || true
|
|
die "${DICE_CONTAINER} bound ${DICE_PORT} on all interfaces, not loopback. Container stopped."
|
|
fi
|
|
log_ok "${DICE_CONTAINER} listens on loopback:${DICE_PORT} only — no contention, not LAN-exposed."
|
|
}
|
|
|
|
start_site() {
|
|
log_info "Starting the ${DICE_CONTAINER} container…"
|
|
docker compose -f "$DICE_COMPOSE" up -d
|
|
if wait_for_site; then
|
|
log_ok "Solver answering on http://127.0.0.1:${DICE_PORT}/."
|
|
else
|
|
docker stop "$DICE_CONTAINER" >/dev/null 2>&1 || true
|
|
die "Solver did not become reachable on 127.0.0.1:${DICE_PORT} (container stopped)."
|
|
fi
|
|
assert_no_edge_conflict
|
|
}
|
|
|
|
# --- Phase 6: reload the edge -----------------------------------------------
|
|
reload_caddy() {
|
|
if docker exec "$CADDY_CONTAINER" caddy validate --config /etc/caddy/Caddyfile >/dev/null 2>&1; then
|
|
docker exec "$CADDY_CONTAINER" caddy reload --config /etc/caddy/Caddyfile
|
|
log_ok "Reloaded ${CADDY_CONTAINER}."
|
|
else
|
|
die "Caddy config invalid — aborting reload. Check ${SITES_DIR}/*.caddy."
|
|
fi
|
|
}
|