mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-24 19:16:18 +01:00
Compare commits
5 Commits
417fbed3e3
...
92aa2f971d
| Author | SHA1 | Date | |
|---|---|---|---|
| 92aa2f971d | |||
| e4ca3717a5 | |||
| 4c7a8c832e | |||
| 213e16836d | |||
| 2a76d05f9d |
6
.github/workflows/pre-commit.yml
vendored
6
.github/workflows/pre-commit.yml
vendored
@ -196,9 +196,9 @@ jobs:
|
||||
- name: Install prettier and shfmt (pinned)
|
||||
if: matrix.group == 'pylint'
|
||||
env:
|
||||
PRETTIER_VERSION: 3.9.5
|
||||
SHFMT_VERSION: v3.13.1
|
||||
SHFMT_SHA256: fb096c5d1ac6beabbdbaa2874d025badb03ee07929f0c9ff67563ce8c75398b1
|
||||
PRETTIER_VERSION: 3.9.10
|
||||
SHFMT_VERSION: v3.14.1
|
||||
SHFMT_SHA256: 76e77641faa025814b77f153b29796b8e6fa2fca03e0c76a691608b86c7ea7bf
|
||||
run: |
|
||||
set -euo pipefail
|
||||
npm install --global --no-fund --no-audit "prettier@${PRETTIER_VERSION}"
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
{
|
||||
"title": "Static-site Caddies serve AgentReady-compliant prerendered sites, with a narrow redeploy + verify",
|
||||
"objective": "Both loopback static-site Caddies (personal website, kcd2 dice solver) render one shared site-block body that serves the prerendered dist/ with real 404s and the ai-catalog Link header, gain a sudo-free `serve` redeploy, and redeploy_agent_ready_sites.sh redeploys and verifies the three public static sites with the AgentReady checker.",
|
||||
"acceptance_criteria": [
|
||||
"e2e_agent_ready_caddy.sh website and dice: every assert passes and agent_ready url mode exits 0 against the rendered Caddyfile",
|
||||
"Unknown paths return 404 with the site's 404 page, not the SPA shell with 200",
|
||||
"`serve` refuses a missing dist/ before docker runs and recreates only that site's container",
|
||||
"redeploy_agent_ready_sites.sh --verify-only prints one PASS/FAIL/UNDETERMINED line per site and exits 0 only when all pass"
|
||||
],
|
||||
"out_of_scope": [
|
||||
"Site content and build (personal-website, kcd2-dice-solver, signal-bot repos)",
|
||||
"The shared edge Caddy, sudo/pacman steps and full setup rebuilds"
|
||||
],
|
||||
"verifier": "linux_configuration/features/lib/tests/test_static_site_serve.sh, test_redeploy_agent_ready_sites.sh, e2e_agent_ready_caddy.sh website|dice, shellcheck, pre-commit"
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
{
|
||||
"intent": "redeploy_agent_ready_sites.sh --verify-only stops flaking FAIL on all three sites: the checks run concurrently, each with the checker's own 45 s network budget, and the whole script still ends inside 60 s.",
|
||||
"scope": [
|
||||
"linux_configuration/features/redeploy_agent_ready_sites.sh",
|
||||
"linux_configuration/features/lib/tests/test_redeploy_agent_ready_sites.sh",
|
||||
"Non-goal: changing the AgentReady checker in ~/src/utils; no live container restarts"
|
||||
],
|
||||
"changes": [
|
||||
"The three url checks run in parallel (in_parallel helper: per-job output files, exit status collected via wait, verdicts printed in fixed site order)",
|
||||
"Each check passes --budget to the checker: min(45, RUN_DEADLINE(55) - elapsed - 5 s grace); the outer timeout is budget + 5 s and only a hang backstop. Below 3 s left, every site reports UNDETERMINED (no time left) and nothing starts",
|
||||
"The three redeploy steps also run in parallel and the systemctl restart is now under the 20 s timeout too, so a full run fits 60 s worst case (20 s redeploy + <=35 s checks)",
|
||||
"--help prints only the header block instead of every comment in the file"
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "bash linux_configuration/features/lib/tests/test_redeploy_agent_ready_sites.sh",
|
||||
"result": "pass",
|
||||
"evidence": "RED before the change: 18 passed, 6 failed (concurrency barriers, --budget 45, deadline budget, no-time-left). GREEN after: 25 passed, 0 failed"
|
||||
},
|
||||
{
|
||||
"command": "bash linux_configuration/features/redeploy_agent_ready_sites.sh --verify-only (3 consecutive live runs)",
|
||||
"result": "pass",
|
||||
"evidence": "3/3 runs: PASS kuhy.duckdns.org, dice.kuhy.duckdns.org, popes.kuhy.duckdns.org, rc=0, 0.68-0.89 s wall each"
|
||||
},
|
||||
{
|
||||
"command": "shellcheck -x + shfmt -d on both files",
|
||||
"result": "pass",
|
||||
"evidence": "no findings, no diff"
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"Parallel docker recreates of the two static sites contend for the docker daemon; they use separate compose dirs, and the 20 s per-step timeout still applies",
|
||||
"AGENT_READY_RUN_DEADLINE env override exists for the tests; setting it high in production could exceed 60 s"
|
||||
],
|
||||
"rollback": [
|
||||
"git revert this commit",
|
||||
"Re-run bash linux_configuration/features/redeploy_agent_ready_sites.sh --verify-only and confirm three verdict lines"
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
{
|
||||
"intent": "The personal website and kcd2 dice solver static Caddies serve their prerendered dist/ so both sites pass the AgentReady v2.0 checker (real 404s, discovery files, ai-catalog Link header), and a narrow sudo-free redeploy + verify exists for the three public static sites.",
|
||||
"scope": [
|
||||
"linux_configuration/features/lib/static_site_caddy.sh (new shared site-block body), website_build.sh, kcd2_serve.sh, kcd2_expose.sh",
|
||||
"linux_configuration/features/setup_personal_website.sh and setup_kcd2_dice_solver.sh (new `serve` subcommand), redeploy_agent_ready_sites.sh (new)",
|
||||
"linux_configuration/features/lib/tests: test_static_site_serve.sh, test_redeploy_agent_ready_sites.sh, e2e_agent_ready_caddy.sh",
|
||||
"Non-goal: no edge Caddy, sudo, pacman or rebuild changes; site content lives in each site's own repo"
|
||||
],
|
||||
"changes": [
|
||||
"static_site_caddy.sh: one Caddy site-block body for both static sites (prerendered paths, real 404 via handle_errors, ai-catalog Link header) plus a dist/ presence guard; website_build.sh and kcd2_serve.sh render it instead of two drifting SPA catch-alls",
|
||||
"kcd2_serve.sh readiness wait requires HTTP 200 with a body, so the non-empty 404 page no longer counts as ready",
|
||||
"setup_* `serve`: re-render the inner compose + Caddyfile and recreate only that site's container",
|
||||
"redeploy_agent_ready_sites.sh: serve both sites, restart the popes-site user unit, then run agent_ready url against each public URL (--verify-only skips the redeploy)"
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "bash linux_configuration/features/lib/tests/test_static_site_serve.sh && bash linux_configuration/features/lib/tests/test_redeploy_agent_ready_sites.sh",
|
||||
"result": "pass",
|
||||
"evidence": "static-site serve: 26 passed, 0 failed; redeploy agent-ready sites: 15 passed, 0 failed"
|
||||
},
|
||||
{
|
||||
"command": "bash linux_configuration/features/lib/tests/e2e_agent_ready_caddy.sh website && bash linux_configuration/features/lib/tests/e2e_agent_ready_caddy.sh dice",
|
||||
"result": "pass",
|
||||
"evidence": "e2e agent-ready website: 16 passed, 0 failed; e2e agent-ready dice: 16 passed, 0 failed (real caddy:2.8 container serving a copy of each dist/)"
|
||||
},
|
||||
{
|
||||
"command": "bash linux_configuration/features/redeploy_agent_ready_sites.sh --verify-only",
|
||||
"result": "pass",
|
||||
"evidence": "PASS kuhy.duckdns.org, dice.kuhy.duckdns.org, popes.kuhy.duckdns.org (rc=0); an earlier run hit the 10 s per-site CHECK_TIMEOUT on all three while the checker alone took 2-22 s"
|
||||
},
|
||||
{
|
||||
"command": "shellcheck -x on all 10 changed/new scripts; pre-commit run on the staged files",
|
||||
"result": "pass",
|
||||
"evidence": "shellcheck clean; pre-commit hooks pass"
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"CHECK_TIMEOUT=10 in redeploy_agent_ready_sites.sh is tight: live checks took up to 22 s, which reports FAIL (timed out) on a healthy site",
|
||||
"A `serve` with no dist/ is refused before docker runs; a stale dist/ is still served as-is"
|
||||
],
|
||||
"rollback": [
|
||||
"git revert the commit, then run setup_personal_website.sh / setup_kcd2_dice_solver.sh to re-render the old Caddyfiles",
|
||||
"curl both sites and check the landing page returns 200"
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
{
|
||||
"intent": "CI's pinned formatter versions match the newest stable releases and the versions the local hooks run, so local and CI never disagree on formatting.",
|
||||
"scope": [
|
||||
".github/workflows/pre-commit.yml (SHFMT_VERSION, SHFMT_SHA256, PRETTIER_VERSION)",
|
||||
"linux_configuration/.githooks/lib/common.sh (PINNED_TOOL_VERSIONS)",
|
||||
"Non-goal: the dead nested linux_configuration/.github/workflows/shell-check.yml (GitHub never runs it); the shared dep_freshness gate"
|
||||
],
|
||||
"changes": [
|
||||
"shfmt v3.13.1 -> v3.14.1 (newest stable, GitHub releases/latest), SHA256 76e77641... taken from a real download and matching the release asset digest",
|
||||
"prettier 3.9.5 -> 3.9.10 (npm dist-tag latest); local nvm-global prettier upgraded to 3.9.10 to match",
|
||||
"shellcheck stays v0.11.0: already the newest stable release and what pacman ships locally"
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "curl shfmt_v3.14.1_linux_amd64 && sha256sum && shfmt --version",
|
||||
"result": "pass",
|
||||
"evidence": "76e77641faa025814b77f153b29796b8e6fa2fca03e0c76a691608b86c7ea7bf, v3.14.1"
|
||||
},
|
||||
{
|
||||
"command": "source linux_configuration/.githooks/lib/common.sh; check_pinned_tool_versions",
|
||||
"result": "pass",
|
||||
"evidence": "no drift warning, rc=0 (local shfmt 3.14.1, prettier 3.9.10, shellcheck 0.11.0)"
|
||||
},
|
||||
{
|
||||
"command": "pre-commit run prettier --hook-stage pre-push --all-files (prettier 3.9.10)",
|
||||
"result": "pass",
|
||||
"evidence": "Passed: the patch bump reformats nothing in the repo"
|
||||
},
|
||||
{
|
||||
"command": "scripts/check_dependency_freshness.sh .github/workflows/pre-commit.yml",
|
||||
"result": "pass",
|
||||
"evidence": "rc=0; note its workflow parser only reads flutter/node/python-version, so it does not see these env pins"
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"A wrong SHA would only fail in CI's pylint group; mitigated by hashing a real download",
|
||||
"Other developer machines still on shfmt 3.13.1 or prettier 3.9.5 now get the common.sh drift warning"
|
||||
],
|
||||
"rollback": [
|
||||
"git revert this commit",
|
||||
"Check that the pre-commit workflow's 'Install prettier and shfmt (pinned)' step goes green"
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
{
|
||||
"intent": "hypothesis pin in meta/requirements.txt is the newest stable release again, so the dependency-freshness CI job goes green.",
|
||||
"scope": [
|
||||
"meta/requirements.txt (hypothesis only)",
|
||||
"Non-goal: typescript 6.0.3 allowlist entry (unchanged, predicate still blocking)"
|
||||
],
|
||||
"changes": [
|
||||
"hypothesis 6.170.5 -> 6.170.6 (released after the previous bump landed)"
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "scripts/check_dependency_freshness.sh --all --strict",
|
||||
"result": "pass",
|
||||
"evidence": "CI run for e4ca3717 reported exactly one finding: pypi:hypothesis 6.170.5 -> 6.170.6"
|
||||
}
|
||||
],
|
||||
"risks": ["patch release of a test-only dependency"],
|
||||
"rollback": ["git revert this commit"]
|
||||
}
|
||||
27
docs/superpowers/evidence/pypi-pins-bump-2026-10-22.json
Normal file
27
docs/superpowers/evidence/pypi-pins-bump-2026-10-22.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"intent": "Python pins in meta/requirements*.txt are the newest stable releases again, so the dependency-freshness gate and Pre-commit checks go green in CI.",
|
||||
"scope": [
|
||||
"meta/requirements.txt, meta/requirements-test.txt (anthropic, coverage, hypothesis, ruff, types-python-dateutil, websockets)",
|
||||
"Non-goal: typescript 6.0.3 allowlist entry (unchanged, predicate still blocking)"
|
||||
],
|
||||
"changes": [
|
||||
"anthropic 1.15.0 -> 2.1.0, coverage 7.16.2 -> 7.17.0, hypothesis 6.170.2 -> 6.170.5",
|
||||
"ruff 0.17.1 -> 0.17.2, types-python-dateutil 2.9.0.20260807 -> 2.9.0.20261021, websockets 17.2 -> 17.3"
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "scripts/check_dependency_freshness.sh --all --strict",
|
||||
"result": "pass",
|
||||
"evidence": "see commit run; CI run 39843132891 listed exactly these 8 findings before the bump"
|
||||
},
|
||||
{
|
||||
"command": "PYTHONPATH=<anthropic 2.1.0 target> pytest python_pkg/code_tutor/tests/test_claude_backend.py python_pkg/code_tutor/tests/test_llm_fallback.py",
|
||||
"result": "pass",
|
||||
"evidence": "16 passed with anthropic 2.1.0 (only importer: python_pkg/code_tutor)"
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"anthropic is a major bump; only code_tutor uses anthropic.Anthropic/APIError/messages.create/stream, covered by the 16 tests above"
|
||||
],
|
||||
"rollback": ["git revert this commit"]
|
||||
}
|
||||
@ -109,8 +109,8 @@ Run this yourself, then retry:
|
||||
# nobody intended.
|
||||
readonly PINNED_TOOL_VERSIONS=(
|
||||
"shellcheck:0.11.0:.github/workflows/pre-commit.yml (SHELLCHECK_VERSION)"
|
||||
"prettier:3.9.5:.github/workflows/pre-commit.yml (PRETTIER_VERSION)"
|
||||
"shfmt:3.13.1:.github/workflows/pre-commit.yml (SHFMT_VERSION)"
|
||||
"prettier:3.9.10:.github/workflows/pre-commit.yml (PRETTIER_VERSION)"
|
||||
"shfmt:3.14.1:.github/workflows/pre-commit.yml (SHFMT_VERSION)"
|
||||
"zsh:5.9:.github/workflows/pre-commit.yml (zsh comes from apt; major.minor only)"
|
||||
)
|
||||
|
||||
@ -123,13 +123,13 @@ _tool_version() {
|
||||
local cmd="$1" raw=""
|
||||
|
||||
case "$cmd" in
|
||||
shellcheck) raw="$(shellcheck --version 2>/dev/null | awk '/^version:/ { print $2 }')" ;;
|
||||
prettier) raw="$(prettier --version 2>/dev/null)" ;;
|
||||
shfmt) raw="$(shfmt --version 2>/dev/null)" ;;
|
||||
# zsh patch releases are not selectable via apt, so compare major.minor
|
||||
# only -- 5.9.2 locally and 5.9 in CI are not a meaningful divergence.
|
||||
zsh) raw="$(zsh --version 2>/dev/null | awk '{ print $2 }' | cut -d. -f1,2)" ;;
|
||||
*) return 1 ;;
|
||||
shellcheck) raw="$(shellcheck --version 2>/dev/null | awk '/^version:/ { print $2 }')" ;;
|
||||
prettier) raw="$(prettier --version 2>/dev/null)" ;;
|
||||
shfmt) raw="$(shfmt --version 2>/dev/null)" ;;
|
||||
# zsh patch releases are not selectable via apt, so compare major.minor
|
||||
# only -- 5.9.2 locally and 5.9 in CI are not a meaningful divergence.
|
||||
zsh) raw="$(zsh --version 2>/dev/null | awk '{ print $2 }' | cut -d. -f1,2)" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
|
||||
printf '%s' "${raw#v}"
|
||||
|
||||
@ -10,16 +10,18 @@
|
||||
# :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)"
|
||||
local listeners
|
||||
# netstat run INSIDE the container: it shares the host's network namespace
|
||||
# but has its own pid namespace, so the only sockets it can attribute to a
|
||||
# process ("<pid>/caddy") are the container's own. That is the same
|
||||
# per-container listener table `sudo ss -ltnp | grep pid=` gave, without sudo.
|
||||
listeners="$(docker exec "$DICE_CONTAINER" netstat -ltnp 2>/dev/null |
|
||||
grep -E '[[:space:]][0-9]+/[^[:space:]]+[[:space:]]*$' || 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.
|
||||
# fails open: if netstat returns nothing — a container that already exited,
|
||||
# or an image without busybox — 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."
|
||||
@ -30,7 +32,7 @@ assert_no_edge_conflict() {
|
||||
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
|
||||
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
|
||||
@ -39,7 +41,9 @@ assert_no_edge_conflict() {
|
||||
|
||||
start_site() {
|
||||
log_info "Starting the ${DICE_CONTAINER} container…"
|
||||
docker compose -f "$DICE_COMPOSE" up -d
|
||||
# --force-recreate: the Caddyfile is a bind mount compose does not track,
|
||||
# and the inner caddy runs with `admin off`, so only a recreate loads it.
|
||||
docker compose -f "$DICE_COMPOSE" up -d --force-recreate
|
||||
if wait_for_site; then
|
||||
log_ok "Solver answering on http://127.0.0.1:${DICE_PORT}/."
|
||||
else
|
||||
|
||||
@ -5,6 +5,9 @@
|
||||
# Sourced rather than run, so it inherits the caller's strict mode and
|
||||
# the helper functions and variables defined above the source line.
|
||||
|
||||
# shellcheck source=static_site_caddy.sh
|
||||
source "${BASH_SOURCE[0]%/*}/static_site_caddy.sh"
|
||||
|
||||
# --- Phase 3: the static-serve stack ----------------------------------------
|
||||
write_serve_stack() {
|
||||
ensure_dir "$DICE_DATA_DIR"
|
||||
@ -63,11 +66,7 @@ EOF
|
||||
|
||||
:${DICE_PORT} {
|
||||
bind 127.0.0.1
|
||||
root * /srv
|
||||
# Single-page bundle: unknown paths should serve the app, not 404.
|
||||
try_files {path} /index.html
|
||||
file_server
|
||||
encode gzip
|
||||
$(static_site_caddy_body)
|
||||
}
|
||||
EOF
|
||||
log_ok "Wrote ${DICE_COMPOSE} and ${DICE_INNER_CADDY}."
|
||||
@ -89,12 +88,14 @@ EOF
|
||||
# non-empty body. A bare "curl http://127.0.0.1:PORT/" sends Host: 127.0.0.1
|
||||
# and returns an empty 200 against a host-matcher misconfiguration — it passes
|
||||
# while every real request serves a blank page. Ask the question the edge asks.
|
||||
# The status matters as much as the body: the handle_errors 404 page has a body
|
||||
# too, so a non-empty 404 (an empty or stale /srv) must not count as ready.
|
||||
wait_for_site() {
|
||||
local _ size
|
||||
local _ code size
|
||||
for _ in $(seq 1 30); do
|
||||
size="$(curl -s -o /dev/null -w '%{size_download}' \
|
||||
-H "Host: ${DICE_DOMAIN}" "http://127.0.0.1:${DICE_PORT}/" 2>/dev/null || echo 0)"
|
||||
if [[ ${size:-0} -gt 0 ]]; then
|
||||
read -r code size < <(curl -s -o /dev/null -w '%{http_code} %{size_download}\n' \
|
||||
-H "Host: ${DICE_DOMAIN}" "http://127.0.0.1:${DICE_PORT}/" 2>/dev/null || echo "000 0")
|
||||
if [[ $code == "200" && ${size:-0} -gt 0 ]]; then
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
|
||||
66
linux_configuration/features/lib/static_site_caddy.sh
Executable file
66
linux_configuration/features/lib/static_site_caddy.sh
Executable file
@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
# Shared site-block body for the loopback static-site Caddies.
|
||||
#
|
||||
# Sourced by website_build.sh and kcd2_serve.sh, which each wrap this in their
|
||||
# own global options and site address. One copy, because both serve a
|
||||
# prerendered dist/ that must pass AgentReady (~/src/utils/agent_ready) and the
|
||||
# two blocks drifting apart is how one of them grew an SPA catch-all.
|
||||
#
|
||||
# Check end to end with tests/e2e_agent_ready_caddy.sh website|dice.
|
||||
|
||||
# `serve` guard: refuse before docker sees the bind-mount source. A missing
|
||||
# dist/ is not an error to compose -- docker creates it as an empty root-owned
|
||||
# directory inside the repo and the site 404s while "running".
|
||||
static_site_require_dist() {
|
||||
[[ -f "$1/index.html" ]] || die "No build at $1 — run setup first."
|
||||
}
|
||||
|
||||
# Prints the directives that go inside the ":<port> { ... }" block.
|
||||
static_site_caddy_body() {
|
||||
cat <<'EOF'
|
||||
root * /srv
|
||||
encode gzip
|
||||
# AgentReady FIND-04: advertise the AI catalog in an HTTP header as well
|
||||
# as in the page head.
|
||||
header Link "</.well-known/ai-catalog.json>; rel=\"ai-catalog\"; type=\"application/ai-catalog+json\""
|
||||
# Exact types the agent spec asks for. Go's defaults are text/xml and
|
||||
# application/json, and a .md would otherwise be guessed per platform.
|
||||
# The "file" matcher limits each to files that exist, so a missing
|
||||
# /x.md 404s as the HTML 404 page rather than as markdown.
|
||||
@md {
|
||||
path *.md
|
||||
file
|
||||
}
|
||||
header @md Content-Type "text/markdown; charset=utf-8"
|
||||
@txt {
|
||||
path /robots.txt /llms.txt
|
||||
file
|
||||
}
|
||||
header @txt Content-Type "text/plain; charset=utf-8"
|
||||
@sitemap {
|
||||
path /sitemap.xml
|
||||
file
|
||||
}
|
||||
header @sitemap Content-Type "application/xml"
|
||||
@catalog {
|
||||
path /.well-known/ai-catalog.json
|
||||
file
|
||||
}
|
||||
header @catalog Content-Type "application/ai-catalog+json"
|
||||
# {path}/index.html is the load-bearing middle term: every route is
|
||||
# prerendered to dist/<route>/index.html (blog posts, /how-it-works/),
|
||||
# and try_files does NOT resolve a directory to its index on its own.
|
||||
# Without it those pages 404 instead of serving their own HTML.
|
||||
#
|
||||
# There is deliberately no /index.html catch-all after it: that SPA
|
||||
# fallback answered every unknown path, robots.txt typo or probe with
|
||||
# "200 text/html", which agents read as a soft 404.
|
||||
try_files {path} {path}/index.html
|
||||
file_server
|
||||
# The prerendered 404 page, keeping the 404 status.
|
||||
handle_errors 404 {
|
||||
rewrite * /404.html
|
||||
file_server
|
||||
}
|
||||
EOF
|
||||
}
|
||||
156
linux_configuration/features/lib/tests/e2e_agent_ready_caddy.sh
Executable file
156
linux_configuration/features/lib/tests/e2e_agent_ready_caddy.sh
Executable file
@ -0,0 +1,156 @@
|
||||
#!/usr/bin/env bash
|
||||
# End-to-end AgentReady check of the inner Caddyfile a static-site lib renders.
|
||||
#
|
||||
# linux_configuration/features/lib/tests/e2e_agent_ready_caddy.sh website|dice
|
||||
#
|
||||
# Deliberately NOT named test_*.sh: run_all.sh runs those inside the namespace
|
||||
# jail, which has no docker. This one runs on the host and needs docker plus
|
||||
# ~/src/utils/agent_ready.
|
||||
#
|
||||
# It renders the inner Caddyfile with the real lib function into a temp dir,
|
||||
# serves a COPY of the site's built dist/ (dotfiles included, as the live bind
|
||||
# mount does) from a throwaway caddy:2.8 container -- the image production pins
|
||||
# -- on a spare loopback port, then runs the checker in url mode plus exact
|
||||
# asserts the checker is too lenient to make (it also accepts text/xml,
|
||||
# application/json and text/plain where the spec here demands more).
|
||||
#
|
||||
# Host mapping: robots.txt and the sitemap carry absolute PUBLIC URLs, and the
|
||||
# checker treats any other host as off-site. So the checker is pointed at
|
||||
# http://<public host> with http_proxy aimed at the container: urllib then sends
|
||||
# every request to 127.0.0.1:<port> carrying the public Host header. A canary
|
||||
# run BEFORE the container starts must exit 3 (connection refused); output from
|
||||
# it would mean the checker reached the live site and proves nothing.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=./features_harness.sh
|
||||
. "$SCRIPT_DIR/features_harness.sh"
|
||||
|
||||
readonly IMAGE="caddy:2.8"
|
||||
readonly CHECKER="${HOME}/src/utils/agent_ready/check.sh"
|
||||
CONTAINER=""
|
||||
|
||||
cleanup() {
|
||||
if [[ -n $CONTAINER ]]; then
|
||||
docker rm -f "$CONTAINER" >/dev/null 2>&1 || true
|
||||
fi
|
||||
_t_teardown
|
||||
}
|
||||
|
||||
# Stand-ins for the common.sh helpers the libs inherit from their entry script.
|
||||
log_ok() { :; }
|
||||
log_info() { :; }
|
||||
ensure_dir() { mkdir -p "$1"; }
|
||||
|
||||
# Globals each lib takes from above its entry script's source line.
|
||||
render_website() {
|
||||
WEBSITE_SRC="$TEST_TMPDIR/src"
|
||||
WEBSITE_PORT="$PORT"
|
||||
WEBSITE_DATA_DIR="$TEST_TMPDIR/serve"
|
||||
WEBSITE_COMPOSE="$WEBSITE_DATA_DIR/docker-compose.yml"
|
||||
WEBSITE_INNER_CADDY="$CADDYFILE_OUT"
|
||||
# shellcheck source=../website_build.sh
|
||||
. "$FEATURES_LIB_DIR/website_build.sh"
|
||||
write_website_stack
|
||||
}
|
||||
|
||||
render_dice() {
|
||||
DICE_DOMAIN="$HOST"
|
||||
DICE_PORT="$PORT"
|
||||
DICE_SRC="$TEST_TMPDIR/src"
|
||||
DICE_DATA_DIR="$TEST_TMPDIR/serve"
|
||||
DICE_COMPOSE="$DICE_DATA_DIR/docker-compose.yml"
|
||||
DICE_INNER_CADDY="$CADDYFILE_OUT"
|
||||
DICE_CONTAINER="kcd2-dice"
|
||||
CADDY_CONTAINER="gitea-caddy"
|
||||
# shellcheck source=../kcd2_serve.sh
|
||||
. "$FEATURES_LIB_DIR/kcd2_serve.sh"
|
||||
write_serve_stack
|
||||
}
|
||||
|
||||
run_checker() {
|
||||
HTTP_PROXY="http://127.0.0.1:${PORT}" http_proxy="http://127.0.0.1:${PORT}" \
|
||||
NO_PROXY="" no_proxy="" "$CHECKER" url "http://${HOST}" --budget 40
|
||||
}
|
||||
|
||||
# "<status> <content-type>" for one path, body kept in $TEST_TMPDIR/body.
|
||||
probe() {
|
||||
curl -s -o "$TEST_TMPDIR/body" -D "$TEST_TMPDIR/headers" -w '%{http_code} %{content_type}' \
|
||||
--max-time 5 -H "Host: ${HOST}" "http://127.0.0.1:${PORT}$1"
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
website)
|
||||
HOST="kuhy.duckdns.org" PORT=18088 SRC_DIST="${HOME}/src/personal-website/dist"
|
||||
PAGE="/blog/hello-world" PAGE_FILE="blog/hello-world/index.html" MIRROR="/blog/hello-world.md"
|
||||
;;
|
||||
dice)
|
||||
HOST="dice.kuhy.duckdns.org" PORT=18089 SRC_DIST="${HOME}/src/kcd2-dice-solver/dist"
|
||||
PAGE="/how-it-works/" PAGE_FILE="how-it-works/index.html" MIRROR="/how-it-works/index.md"
|
||||
;;
|
||||
*)
|
||||
printf 'usage: %s website|dice\n' "$0" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
_t_setup_env
|
||||
trap cleanup EXIT
|
||||
CADDYFILE_OUT="$TEST_TMPDIR/Caddyfile"
|
||||
mkdir -p "$TEST_TMPDIR/dist"
|
||||
cp -a "$SRC_DIST/." "$TEST_TMPDIR/dist"
|
||||
"render_$1"
|
||||
|
||||
printf '== rendered site block\n'
|
||||
sed -n "/^:${PORT} {/,/^}/p" "$CADDYFILE_OUT"
|
||||
|
||||
printf '== canary (no container yet): checker must exit 3\n'
|
||||
canary=0
|
||||
run_checker >/dev/null 2>&1 || canary=$?
|
||||
_t_eq 3 "$canary" "checker cannot reach the live site through the proxy mapping"
|
||||
|
||||
if docker run --rm -v "$CADDYFILE_OUT:/etc/caddy/Caddyfile:ro" "$IMAGE" \
|
||||
caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile >/dev/null 2>&1; then
|
||||
_t_pass "caddy validate"
|
||||
else
|
||||
_t_fail "caddy validate"
|
||||
fi
|
||||
|
||||
CONTAINER="agent-ready-e2e-$1-$$"
|
||||
docker run -d --name "$CONTAINER" --network host \
|
||||
-v "$TEST_TMPDIR/dist:/srv:ro" -v "$CADDYFILE_OUT:/etc/caddy/Caddyfile:ro" \
|
||||
"$IMAGE" >/dev/null
|
||||
for _ in $(seq 1 30); do
|
||||
[[ "$(probe / || true)" == 200* ]] && break
|
||||
sleep 0.2
|
||||
done
|
||||
|
||||
printf '== exact HTTP asserts\n'
|
||||
_t_has "$(probe /)" "200 text/html" "/ is 200 html"
|
||||
_t_has "$(cat "$TEST_TMPDIR/headers")" '</.well-known/ai-catalog.json>; rel="ai-catalog"' "/ sends the ai-catalog Link header"
|
||||
_t_has "$(probe "$PAGE")" "200 text/html" "$PAGE is 200 html"
|
||||
if cmp -s "$TEST_TMPDIR/body" "$TEST_TMPDIR/dist/$PAGE_FILE"; then
|
||||
_t_pass "$PAGE serves its own prerendered $PAGE_FILE, not the shell"
|
||||
else
|
||||
_t_fail "$PAGE serves its own prerendered $PAGE_FILE, not the shell"
|
||||
fi
|
||||
_t_eq "200 text/plain; charset=utf-8" "$(probe /robots.txt)" "/robots.txt type"
|
||||
_t_eq "200 text/plain; charset=utf-8" "$(probe /llms.txt)" "/llms.txt type"
|
||||
_t_eq "200 application/xml" "$(probe /sitemap.xml)" "/sitemap.xml type"
|
||||
_t_eq "200 application/ai-catalog+json" "$(probe /.well-known/ai-catalog.json)" "ai-catalog type"
|
||||
_t_eq "200 text/markdown; charset=utf-8" "$(probe /index.md)" "/index.md type"
|
||||
_t_eq "200 text/markdown; charset=utf-8" "$(probe "$MIRROR")" "$MIRROR type"
|
||||
_t_has "$(probe /agentready-e2e-nope)" "404 text/html" "unknown path is a 404 html page"
|
||||
if cmp -s "$TEST_TMPDIR/body" "$TEST_TMPDIR/dist/404.html"; then
|
||||
_t_pass "404 body is dist/404.html"
|
||||
else
|
||||
_t_fail "404 body is dist/404.html"
|
||||
fi
|
||||
_t_has "$(probe /nope.md)" "404 text/html" "missing .md is a 404 html page, not markdown"
|
||||
|
||||
printf '== AgentReady url mode (http://%s via 127.0.0.1:%s)\n' "$HOST" "$PORT"
|
||||
status=0
|
||||
run_checker || status=$?
|
||||
_t_eq 0 "$status" "agent_ready url mode exit"
|
||||
|
||||
_t_report "e2e agent-ready $1"
|
||||
125
linux_configuration/features/lib/tests/test_redeploy_agent_ready_sites.sh
Executable file
125
linux_configuration/features/lib/tests/test_redeploy_agent_ready_sites.sh
Executable file
@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tests for features/redeploy_agent_ready_sites.sh.
|
||||
#
|
||||
# The wrapper is copied next to stub setup_*.sh scripts (it resolves its
|
||||
# siblings from its own path), HOME points at a temp dir holding a stub
|
||||
# checker, and systemctl is stubbed on PATH. Nothing live is restarted or
|
||||
# fetched; the real --verify-only run against the public sites is manual.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=./features_harness.sh
|
||||
. "$SCRIPT_DIR/features_harness.sh"
|
||||
|
||||
_t_setup_env
|
||||
trap _t_teardown EXIT
|
||||
|
||||
readonly WRAP_DIR="$TEST_TMPDIR/features"
|
||||
readonly WRAPPER="$WRAP_DIR/redeploy_agent_ready_sites.sh"
|
||||
mkdir -p "$WRAP_DIR" "$TEST_TMPDIR/src/utils/agent_ready"
|
||||
cp "$FEATURES_LIB_DIR/../redeploy_agent_ready_sites.sh" "$WRAPPER"
|
||||
|
||||
# Barrier: `barrier.sh <group> <member>` marks <member> as started and waits
|
||||
# up to 3 s for all three members of <group>. A sequential caller can never
|
||||
# have all three running at once, so it logs SERIAL instead: a deterministic
|
||||
# concurrency check with no timing threshold to flake on.
|
||||
cat >"$TEST_TMPDIR/barrier.sh" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
mkdir -p "$TEST_TMPDIR/barrier/$1"
|
||||
: >"$TEST_TMPDIR/barrier/$1/$2"
|
||||
for _ in $(seq 30); do
|
||||
n="$(find "$TEST_TMPDIR/barrier/$1" -type f | wc -l)"
|
||||
[[ $n -ge 3 ]] && exit 0
|
||||
sleep 0.1
|
||||
done
|
||||
printf 'SERIAL %s %s\n' "$1" "$2" >>"$TEST_TMPDIR/calls.log"
|
||||
EOF
|
||||
chmod +x "$TEST_TMPDIR/barrier.sh"
|
||||
|
||||
# A sibling setup script that records its argv, joins the redeploy barrier,
|
||||
# sleeps $FAKE_SLEEP and exits $FAKE_RC_<name>.
|
||||
cat >"$WRAP_DIR/setup_personal_website.sh" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
name="$(basename "$0" .sh)"
|
||||
printf '%s %s\n' "$name" "$*" >>"$TEST_TMPDIR/calls.log"
|
||||
"$TEST_TMPDIR/barrier.sh" redeploy "$name"
|
||||
sleep "${FAKE_SLEEP:-0}"
|
||||
rc_var="FAKE_RC_${name}"
|
||||
exit "${!rc_var:-0}"
|
||||
EOF
|
||||
cp "$WRAP_DIR/setup_personal_website.sh" "$WRAP_DIR/setup_kcd2_dice_solver.sh"
|
||||
cat >"$TEST_TMPDIR/bin/systemctl" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
printf 'systemctl %s\n' "$*" >>"$TEST_TMPDIR/calls.log"
|
||||
"$TEST_TMPDIR/barrier.sh" redeploy systemctl
|
||||
EOF
|
||||
chmod +x "$TEST_TMPDIR/bin/systemctl"
|
||||
|
||||
# Checker stub: PASS for kuhy (finishing last), FAIL lines for dice,
|
||||
# unreachable for popes. Every call joins the check barrier first.
|
||||
cat >"$TEST_TMPDIR/src/utils/agent_ready/check.sh" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
printf 'check %s\n' "$*" >>"$TEST_TMPDIR/calls.log"
|
||||
host="${2#*//}"
|
||||
"$TEST_TMPDIR/barrier.sh" check "${host%%.*}"
|
||||
case "$2" in
|
||||
*//kuhy.*)
|
||||
sleep 0.5
|
||||
exit "${FAKE_KUHY_RC:-0}"
|
||||
;;
|
||||
*//dice.*)
|
||||
printf 'PASS AR-READ-03 ok\nFAIL AR-READ-02 soft 404\nFAIL AR-FIND-04 no Link\nFAIL AR-READ-02 again\n'
|
||||
exit 1
|
||||
;;
|
||||
*) exit 3 ;;
|
||||
esac
|
||||
EOF
|
||||
chmod +x "$TEST_TMPDIR/src/utils/agent_ready/check.sh"
|
||||
|
||||
run_wrapper() {
|
||||
: >"$TEST_TMPDIR/calls.log"
|
||||
rm -rf "$TEST_TMPDIR/barrier"
|
||||
local rc=0
|
||||
HOME="$TEST_TMPDIR" bash "$WRAPPER" "$@" >"$TEST_TMPDIR/out" 2>&1 || rc=$?
|
||||
echo "$rc"
|
||||
}
|
||||
|
||||
printf '== --verify-only restarts nothing\n'
|
||||
_t_eq 1 "$(run_wrapper --verify-only)" "a failing site makes the run exit 1"
|
||||
_t_eq 0 "$(grep -cE '^(setup_|systemctl)' "$TEST_TMPDIR/calls.log" || true)" "no serve and no restart"
|
||||
_t_eq 3 "$(grep -c '^check url https://' "$TEST_TMPDIR/calls.log")" "all three sites checked"
|
||||
out="$(cat "$TEST_TMPDIR/out")"
|
||||
_t_has "$out" "PASS https://kuhy.duckdns.org" "kuhy verdict"
|
||||
_t_has "$out" "FAIL https://dice.kuhy.duckdns.org (AR-FIND-04,AR-READ-02)" "dice verdict lists unique failing ids"
|
||||
_t_has "$out" "UNDETERMINED https://popes.kuhy.duckdns.org" "popes verdict on checker exit 3"
|
||||
_t_eq 3 "$(wc -l <"$TEST_TMPDIR/out")" "one line per site"
|
||||
_t_eq 0 "$(grep -c '^SERIAL check' "$TEST_TMPDIR/calls.log" || true)" "the three checks run concurrently"
|
||||
_t_eq "kuhy dice popes" "$(grep -oE '//[a-z]+' "$TEST_TMPDIR/out" | tr -d / | paste -sd' ')" \
|
||||
"verdicts print in site order even when kuhy finishes last"
|
||||
_t_eq 3 "$(grep -cE '^check url https://[^ ]+ --budget 45$' "$TEST_TMPDIR/calls.log")" \
|
||||
"each check gets the checker's full 45 s network budget"
|
||||
|
||||
printf '== full run\n'
|
||||
_t_eq 1 "$(FAKE_RC_setup_kcd2_dice_solver=1 run_wrapper)" "full run exits 1"
|
||||
_t_called "setup_personal_website serve" "website serve ran"
|
||||
_t_called "setup_kcd2_dice_solver serve" "dice serve ran"
|
||||
_t_called "systemctl --user restart signal-bot-popes-site.service" "popes unit restarted"
|
||||
_t_has "$(cat "$TEST_TMPDIR/out")" "kcd2-dice FAILED (exit 1)" "a failed serve is reported"
|
||||
_t_eq 3 "$(grep -c '^check url' "$TEST_TMPDIR/calls.log")" "a failed serve does not skip the checks"
|
||||
_t_eq 0 "$(grep -c '^SERIAL redeploy' "$TEST_TMPDIR/calls.log" || true)" "the three redeploy steps run concurrently"
|
||||
|
||||
printf '== the check budget shrinks to fit the run deadline\n'
|
||||
_t_eq 1 "$(FAKE_SLEEP=2 AGENT_READY_RUN_DEADLINE=12 run_wrapper)" "slow redeploy still checks (dice fails)"
|
||||
_t_eq 3 "$(grep -cE '^check url https://[^ ]+ --budget [1-5]$' "$TEST_TMPDIR/calls.log")" \
|
||||
"checks get only what is left of the deadline"
|
||||
_t_eq 1 "$(FAKE_SLEEP=2 AGENT_READY_RUN_DEADLINE=8 run_wrapper)" "no time left fails the run"
|
||||
_t_eq 0 "$(grep -c '^check url' "$TEST_TMPDIR/calls.log" || true)" "no checker starts once the deadline is spent"
|
||||
_t_eq 3 "$(grep -c '^UNDETERMINED .*no time left' "$TEST_TMPDIR/out")" "each site reports no time left"
|
||||
|
||||
printf '== exit codes\n'
|
||||
_t_eq 2 "$(run_wrapper --bogus)" "unknown argument exits 2"
|
||||
help_text="$(bash "$WRAPPER" --help)"
|
||||
_t_has "$help_text" "--verify-only" "help documents --verify-only"
|
||||
_t_eq 0 "$(grep -c 'in_parallel' <<<"$help_text" || true)" "help stops at the header block"
|
||||
|
||||
_t_report "redeploy agent-ready sites"
|
||||
122
linux_configuration/features/lib/tests/test_static_site_serve.sh
Executable file
122
linux_configuration/features/lib/tests/test_static_site_serve.sh
Executable file
@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tests for the `serve` subcommand of setup_personal_website.sh and
|
||||
# setup_kcd2_dice_solver.sh: re-render the inner compose + Caddyfile and
|
||||
# recreate only that site's container, with no sudo, pacman, rebuild or edge
|
||||
# reload.
|
||||
#
|
||||
# Hermetic by necessity, not by taste. Every path in the entry scripts is a
|
||||
# readonly constant under $HOME and the website's container_name is fixed, so a
|
||||
# real `docker compose up --force-recreate` from a throwaway dir would recreate
|
||||
# the LIVE personal-website container. Instead the real entry scripts run with
|
||||
# HOME pointed at a temp dir and docker/curl stubbed on PATH. The rendered
|
||||
# Caddyfile itself is served by real caddy in e2e_agent_ready_caddy.sh.
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=./features_harness.sh
|
||||
. "$SCRIPT_DIR/features_harness.sh"
|
||||
FEATURES_DIR="$(cd "$FEATURES_LIB_DIR/.." && pwd)"
|
||||
readonly FEATURES_DIR
|
||||
|
||||
_t_setup_env
|
||||
trap _t_teardown EXIT
|
||||
|
||||
# docker records every call; `docker exec <c> netstat` answers $FAKE_LISTENERS,
|
||||
# the sudo-free listener table the dice edge-conflict guard reads.
|
||||
cat >"$TEST_TMPDIR/bin/docker" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
printf 'docker %s\n' "$*" >>"$TEST_TMPDIR/calls.log"
|
||||
if [[ $1 == exec && $* == *netstat* ]]; then
|
||||
printf '%s\n' "${FAKE_LISTENERS:-}"
|
||||
fi
|
||||
EOF
|
||||
# curl expands only the -w variables the readiness loops ask for, plus the \n
|
||||
# escape as real curl does.
|
||||
cat >"$TEST_TMPDIR/bin/curl" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
printf 'curl %s\n' "$*" >>"$TEST_TMPDIR/calls.log"
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 == -w ]]; then
|
||||
fmt="${2//'%{http_code}'/${FAKE_CODE:-200}}"
|
||||
printf '%b' "${fmt//'%{size_download}'/1234}"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
EOF
|
||||
chmod +x "$TEST_TMPDIR/bin/docker" "$TEST_TMPDIR/bin/curl"
|
||||
# Anything serve must never reach. `sleep` only to keep the 404 case fast.
|
||||
for cmd in sudo pacman pnpm systemctl sleep; do
|
||||
_t_stub "$cmd"
|
||||
done
|
||||
|
||||
readonly OK_LISTENERS="tcp 0 0 127.0.0.1:8089 0.0.0.0:* LISTEN 1/caddy"
|
||||
readonly WEB_SERVE="$TEST_TMPDIR/services/personal-website-serve"
|
||||
readonly DICE_SERVE="$TEST_TMPDIR/services/kcd2-dice-serve"
|
||||
|
||||
make_dist() {
|
||||
mkdir -p "$TEST_TMPDIR/src/$1/dist"
|
||||
printf '<!doctype html>\n' >"$TEST_TMPDIR/src/$1/dist/index.html"
|
||||
}
|
||||
|
||||
# run_serve <script> -> exit status; output in $TEST_TMPDIR/out.
|
||||
run_serve() {
|
||||
: >"$TEST_TMPDIR/calls.log"
|
||||
local rc=0
|
||||
HOME="$TEST_TMPDIR" bash "$FEATURES_DIR/$1" serve >"$TEST_TMPDIR/out" 2>&1 || rc=$?
|
||||
echo "$rc"
|
||||
}
|
||||
|
||||
assert_nothing_heavy() {
|
||||
local hits
|
||||
hits="$(grep -E '^(sudo|pacman|pnpm|systemctl) |caddy reload' "$TEST_TMPDIR/calls.log" || true)"
|
||||
_t_eq "" "$hits" "$1: no sudo, pacman, pnpm, systemctl or edge reload"
|
||||
}
|
||||
|
||||
printf '== usage advertises serve\n'
|
||||
for script in setup_personal_website.sh setup_kcd2_dice_solver.sh; do
|
||||
_t_has "$(bash "$FEATURES_DIR/$script" help)" "$script serve" "$script help lists serve"
|
||||
done
|
||||
|
||||
printf '== serve refuses without a build, before touching docker\n'
|
||||
for script in setup_personal_website.sh setup_kcd2_dice_solver.sh; do
|
||||
_t_eq 1 "$(run_serve "$script")" "$script serve with no dist/ exits 1"
|
||||
_t_eq 0 "$(grep -c '^docker' "$TEST_TMPDIR/calls.log" || true)" "$script: no docker call without a build"
|
||||
done
|
||||
|
||||
make_dist personal-website
|
||||
make_dist kcd2-dice-solver
|
||||
|
||||
printf '== website serve\n'
|
||||
_t_eq 0 "$(run_serve setup_personal_website.sh)" "website serve exits 0"
|
||||
_t_file_has "$WEB_SERVE/docker-compose.yml" "container_name: personal-website" "website compose rendered"
|
||||
_t_file_has "$WEB_SERVE/Caddyfile" 'rel=\\"ai-catalog\\"' "website Caddyfile carries the Link header"
|
||||
_t_called "docker compose -f $WEB_SERVE/docker-compose.yml up -d --force-recreate" \
|
||||
"website container force-recreated"
|
||||
assert_nothing_heavy "website serve"
|
||||
|
||||
printf '== dice serve\n'
|
||||
export FAKE_LISTENERS="$OK_LISTENERS"
|
||||
_t_eq 0 "$(run_serve setup_kcd2_dice_solver.sh)" "dice serve exits 0"
|
||||
_t_file_has "$DICE_SERVE/docker-compose.yml" "container_name: kcd2-dice" "dice compose rendered"
|
||||
_t_file_has "$DICE_SERVE/Caddyfile" "handle_errors 404" "dice Caddyfile carries the 404 handler"
|
||||
_t_called "docker compose -f $DICE_SERVE/docker-compose.yml up -d --force-recreate" \
|
||||
"dice container force-recreated"
|
||||
_t_called "docker exec kcd2-dice netstat -ltnp" "dice edge guard ran without sudo"
|
||||
assert_nothing_heavy "dice serve"
|
||||
|
||||
printf '== dice serve fails closed\n'
|
||||
FAKE_LISTENERS="$OK_LISTENERS"$'\n'"tcp 0 0 :::80 :::* LISTEN 1/caddy"
|
||||
_t_eq 1 "$(run_serve setup_kcd2_dice_solver.sh)" "a :80 listener fails serve"
|
||||
_t_called "docker stop kcd2-dice" "the contending container is stopped"
|
||||
_t_has "$(cat "$TEST_TMPDIR/out")" "bound :80/:443" " ...for the :80 reason"
|
||||
FAKE_LISTENERS="$OK_LISTENERS"$'\n'"tcp 0 0 :::8089 :::* LISTEN 1/caddy"
|
||||
_t_eq 1 "$(run_serve setup_kcd2_dice_solver.sh)" "an all-interfaces :8089 listener fails serve"
|
||||
_t_has "$(cat "$TEST_TMPDIR/out")" "on all interfaces" " ...for the all-interfaces reason"
|
||||
FAKE_LISTENERS=""
|
||||
_t_eq 1 "$(run_serve setup_kcd2_dice_solver.sh)" "no attributable listener fails serve"
|
||||
_t_has "$(cat "$TEST_TMPDIR/out")" "Could not confirm" " ...for the missing-evidence reason"
|
||||
FAKE_LISTENERS="$OK_LISTENERS"
|
||||
_t_eq 1 "$(FAKE_CODE=404 run_serve setup_kcd2_dice_solver.sh)" "a 404 with a body is not ready"
|
||||
_t_has "$(cat "$TEST_TMPDIR/out")" "did not become reachable" " ...for the readiness reason"
|
||||
|
||||
_t_report "static-site serve"
|
||||
@ -5,6 +5,9 @@
|
||||
# Sourced rather than run, so it inherits the caller's strict mode and
|
||||
# the helper functions and variables defined above the source line.
|
||||
|
||||
# shellcheck source=static_site_caddy.sh
|
||||
source "${BASH_SOURCE[0]%/*}/static_site_caddy.sh"
|
||||
|
||||
# --- Phase 5: build the website --------------------------------------------
|
||||
build_website() {
|
||||
log_info "Installing website dependencies and building…"
|
||||
@ -48,17 +51,7 @@ EOF
|
||||
}
|
||||
|
||||
:${WEBSITE_PORT} {
|
||||
root * /srv
|
||||
# {path}/index.html is the load-bearing middle term: the website
|
||||
# prerenders each blog post to dist/blog/<slug>/index.html, and
|
||||
# try_files does NOT resolve a directory to its index on its own.
|
||||
# Without it every post silently falls through to the SPA shell and
|
||||
# is served as the landing page -- right content once React boots,
|
||||
# wrong <title> and no link preview, which looks like nothing is
|
||||
# wrong until you check the tab.
|
||||
try_files {path} {path}/index.html /index.html
|
||||
file_server
|
||||
encode gzip
|
||||
$(static_site_caddy_body)
|
||||
}
|
||||
EOF
|
||||
log_ok "Wrote ${WEBSITE_COMPOSE} and ${WEBSITE_INNER_CADDY}."
|
||||
|
||||
167
linux_configuration/features/redeploy_agent_ready_sites.sh
Executable file
167
linux_configuration/features/redeploy_agent_ready_sites.sh
Executable file
@ -0,0 +1,167 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# redeploy_agent_ready_sites.sh — narrow redeploy + AgentReady check of the
|
||||
# three public static sites.
|
||||
#
|
||||
# Redeploy (skipped with --verify-only), the three steps run concurrently:
|
||||
# - setup_personal_website.sh serve recreate the kuhy.duckdns.org container
|
||||
# - setup_kcd2_dice_solver.sh serve recreate the dice.kuhy.duckdns.org one
|
||||
# - systemctl --user restart signal-bot-popes-site.service
|
||||
# None of these uses sudo, pacman, a rebuild or the shared edge: build first in
|
||||
# each site's own repo, then run this to make the new dist/ + Caddyfile live.
|
||||
#
|
||||
# Verify: ~/src/utils/agent_ready/check.sh url against each public URL, all
|
||||
# three at once, one verdict line per site in a fixed order (PASS, FAIL with
|
||||
# the failing check ids, or UNDETERMINED when the checker could not reach the
|
||||
# site or ran out of time).
|
||||
#
|
||||
# Usage:
|
||||
# redeploy_agent_ready_sites.sh Redeploy, then verify.
|
||||
# redeploy_agent_ready_sites.sh --verify-only Verify only; restarts nothing.
|
||||
# redeploy_agent_ready_sites.sh --help Show this help.
|
||||
#
|
||||
# Exit status: 0 when every step and every site passes, 1 otherwise, 2 on a
|
||||
# usage error.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||
readonly SCRIPT_DIR
|
||||
readonly CHECKER="${HOME}/src/utils/agent_ready/check.sh"
|
||||
readonly POPES_UNIT="signal-bot-popes-site.service"
|
||||
readonly SITES=(
|
||||
"https://kuhy.duckdns.org"
|
||||
"https://dice.kuhy.duckdns.org"
|
||||
"https://popes.kuhy.duckdns.org"
|
||||
)
|
||||
# Timing. A live check takes anywhere from under a second to ~22 s (measured),
|
||||
# so each one gets the checker's own 45 s network budget, which it enforces
|
||||
# itself and answers with exit 3 when spent. The whole run must end inside
|
||||
# 60 s, so that budget is cut to whatever is left before RUN_DEADLINE once the
|
||||
# redeploy is done. GRACE covers Python start-up and the post-network scoring
|
||||
# and is also the margin of the outer `timeout`, a backstop for a hung process.
|
||||
readonly RUN_DEADLINE="${AGENT_READY_RUN_DEADLINE:-55}"
|
||||
readonly CHECK_BUDGET_MAX=45
|
||||
readonly CHECK_BUDGET_MIN=3
|
||||
readonly GRACE=5
|
||||
readonly SERVE_TIMEOUT=20
|
||||
|
||||
FAILED=0
|
||||
CHECK_BUDGET=0
|
||||
WORK_DIR=""
|
||||
|
||||
usage() {
|
||||
# The header block only: it ends at the first non-comment line.
|
||||
sed -nE '2,/^[^#]/{/^#( |$)/s/^# ?//p}' "$0"
|
||||
exit "${1:-0}"
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
[[ -z $WORK_DIR ]] || rm -rf "$WORK_DIR"
|
||||
}
|
||||
|
||||
# in_parallel <fn> <arg>...: run `<fn> <arg>` for every arg at once, then print
|
||||
# each one's output in argument order. Runs in the background cannot set
|
||||
# FAILED themselves, so their exit status is collected here.
|
||||
in_parallel() {
|
||||
local fn="$1" arg i=0 pids=()
|
||||
shift
|
||||
for arg in "$@"; do
|
||||
"$fn" "$arg" >"${WORK_DIR}/${i}.out" 2>&1 &
|
||||
pids+=("$!")
|
||||
i=$((i + 1))
|
||||
done
|
||||
for i in "${!pids[@]}"; do
|
||||
wait "${pids[$i]}" || FAILED=1
|
||||
cat "${WORK_DIR}/${i}.out"
|
||||
done
|
||||
}
|
||||
|
||||
# run_step <label> <cmd...>: output is shown only when the step fails, so a
|
||||
# clean run stays at one line per step.
|
||||
run_step() {
|
||||
local label="$1" out rc=0
|
||||
shift
|
||||
out="$("$@" 2>&1)" || rc=$?
|
||||
if [[ $rc -eq 0 ]]; then
|
||||
printf 'redeploy %-28s ok\n' "$label"
|
||||
else
|
||||
printf 'redeploy %-28s FAILED (exit %d)\n' "$label" "$rc"
|
||||
tail -n 15 <<<"$out" | sed 's/^/ /'
|
||||
fi
|
||||
return "$rc"
|
||||
}
|
||||
|
||||
redeploy_step() {
|
||||
case "$1" in
|
||||
personal-website)
|
||||
run_step "$1" timeout "$SERVE_TIMEOUT" bash "${SCRIPT_DIR}/setup_personal_website.sh" serve
|
||||
;;
|
||||
kcd2-dice)
|
||||
run_step "$1" timeout "$SERVE_TIMEOUT" bash "${SCRIPT_DIR}/setup_kcd2_dice_solver.sh" serve
|
||||
;;
|
||||
*) run_step "$1" timeout "$SERVE_TIMEOUT" systemctl --user restart "$1" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# check_site <url>: one verdict line; non-zero on anything but a pass.
|
||||
check_site() {
|
||||
local url="$1" out rc=0 ids
|
||||
out="$(timeout "$((CHECK_BUDGET + GRACE))" "$CHECKER" url "$url" --budget "$CHECK_BUDGET" 2>&1)" || rc=$?
|
||||
case "$rc" in
|
||||
0)
|
||||
printf 'PASS %s\n' "$url"
|
||||
return 0
|
||||
;;
|
||||
3) printf 'UNDETERMINED %s (checker could not reach it within %ss)\n' "$url" "$CHECK_BUDGET" ;;
|
||||
124) printf 'FAIL %s (checker hung past %ss)\n' "$url" "$((CHECK_BUDGET + GRACE))" ;;
|
||||
*)
|
||||
ids="$(grep -oE '^FAIL AR-[A-Z]+-[0-9]+' <<<"$out" | cut -d' ' -f2 | sort -u | paste -sd, || true)"
|
||||
printf 'FAIL %s (%s)\n' "$url" "${ids:-exit ${rc}}"
|
||||
;;
|
||||
esac
|
||||
return 1
|
||||
}
|
||||
|
||||
verify() {
|
||||
local url
|
||||
CHECK_BUDGET=$((RUN_DEADLINE - SECONDS - GRACE))
|
||||
if [[ $CHECK_BUDGET -gt $CHECK_BUDGET_MAX ]]; then
|
||||
CHECK_BUDGET=$CHECK_BUDGET_MAX
|
||||
fi
|
||||
if [[ $CHECK_BUDGET -lt $CHECK_BUDGET_MIN ]]; then
|
||||
for url in "${SITES[@]}"; do
|
||||
printf 'UNDETERMINED %s (no time left before the %ss deadline)\n' "$url" "$RUN_DEADLINE"
|
||||
done
|
||||
FAILED=1
|
||||
return 0
|
||||
fi
|
||||
in_parallel check_site "${SITES[@]}"
|
||||
}
|
||||
|
||||
main() {
|
||||
local verify_only=0
|
||||
case "${1:-}" in
|
||||
"") ;;
|
||||
--verify-only) verify_only=1 ;;
|
||||
-h | --help) usage ;;
|
||||
*)
|
||||
printf 'Unknown argument: %s\n' "$1" >&2
|
||||
usage 2
|
||||
;;
|
||||
esac
|
||||
[[ -x $CHECKER ]] || {
|
||||
printf 'AgentReady checker missing: %s\n' "$CHECKER" >&2
|
||||
exit 1
|
||||
}
|
||||
WORK_DIR="$(mktemp -d)"
|
||||
trap cleanup EXIT
|
||||
|
||||
if [[ $verify_only -eq 0 ]]; then
|
||||
in_parallel redeploy_step personal-website kcd2-dice "$POPES_UNIT"
|
||||
fi
|
||||
verify
|
||||
return "$FAILED"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@ -25,6 +25,9 @@
|
||||
#
|
||||
# Usage:
|
||||
# setup_kcd2_dice_solver.sh [setup] Build + deploy (default).
|
||||
# setup_kcd2_dice_solver.sh serve Re-render the inner compose + Caddyfile
|
||||
# and recreate only the kcd2-dice container
|
||||
# (no sudo, pacman, rebuild or edge change).
|
||||
# setup_kcd2_dice_solver.sh status Self-diagnose the deployment.
|
||||
# setup_kcd2_dice_solver.sh help Show this help.
|
||||
#
|
||||
@ -115,12 +118,24 @@ source "$SCRIPT_DIR/lib/kcd2_expose.sh"
|
||||
# shellcheck source=lib/kcd2_autorebuild.sh
|
||||
source "$SCRIPT_DIR/lib/kcd2_autorebuild.sh"
|
||||
|
||||
# serve: the narrow redeploy. The inner caddy runs with `admin off`, so a
|
||||
# Caddyfile change only loads on recreate; start_site forces one and keeps the
|
||||
# edge-conflict guard.
|
||||
serve_cmd() {
|
||||
static_site_require_dist "${DICE_SRC}/dist"
|
||||
write_serve_stack
|
||||
start_site
|
||||
}
|
||||
|
||||
main() {
|
||||
local cmd="${1:-setup}"
|
||||
case "$cmd" in
|
||||
setup)
|
||||
setup_cmd
|
||||
;;
|
||||
serve)
|
||||
serve_cmd
|
||||
;;
|
||||
status)
|
||||
status_cmd
|
||||
;;
|
||||
|
||||
@ -25,6 +25,9 @@
|
||||
#
|
||||
# Usage:
|
||||
# setup_personal_website.sh [setup] Build + deploy (default).
|
||||
# setup_personal_website.sh serve Re-render the inner compose + Caddyfile
|
||||
# and recreate only the website container
|
||||
# (no sudo, pacman, rebuild or edge change).
|
||||
# setup_personal_website.sh status Self-diagnose the deployment.
|
||||
# setup_personal_website.sh help Show this help.
|
||||
#
|
||||
@ -174,12 +177,23 @@ source "$SCRIPT_DIR/lib/website_build.sh"
|
||||
# shellcheck source=lib/website_admin.sh
|
||||
source "$SCRIPT_DIR/lib/website_admin.sh"
|
||||
|
||||
# serve: the narrow redeploy. The inner caddy runs with `admin off`, so a
|
||||
# Caddyfile change only loads on recreate; start_website forces one.
|
||||
serve_cmd() {
|
||||
static_site_require_dist "${WEBSITE_SRC}/dist"
|
||||
write_website_stack
|
||||
start_website
|
||||
}
|
||||
|
||||
main() {
|
||||
local cmd="${1:-setup}"
|
||||
case "$cmd" in
|
||||
setup)
|
||||
setup_cmd
|
||||
;;
|
||||
serve)
|
||||
serve_cmd
|
||||
;;
|
||||
status)
|
||||
status_cmd
|
||||
;;
|
||||
|
||||
@ -21,9 +21,9 @@
|
||||
# suite itself fails loudly here on a missing import.
|
||||
# ==============================================================================
|
||||
|
||||
anthropic==1.15.0
|
||||
anthropic==2.1.0
|
||||
beautifulsoup4==4.15.0
|
||||
coverage==7.16.2
|
||||
coverage==7.17.0
|
||||
defusedxml==0.7.1
|
||||
genanki==0.13.1
|
||||
markdownify==1.2.3
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
add-trailing-comma==4.0.0
|
||||
aiohttp==3.14.5
|
||||
anthropic==1.15.0
|
||||
anthropic==2.1.0
|
||||
autoflake==2.4.0
|
||||
autopep8==2.3.2
|
||||
bandit==1.9.4
|
||||
@ -15,7 +15,7 @@ berserk==0.14.0
|
||||
black==26.10.1
|
||||
bottle==0.13.4
|
||||
codespell==2.4.3
|
||||
coverage==7.16.2
|
||||
coverage==7.17.0
|
||||
cryptography==50.0.2
|
||||
darglint==1.8.1
|
||||
dead==2.1.0
|
||||
@ -39,7 +39,7 @@ gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.11.0#subdirectory=gate
|
||||
genanki==0.13.1
|
||||
geopandas==1.2.0
|
||||
howlongtobeatpy==1.0.24
|
||||
hypothesis==6.170.2
|
||||
hypothesis==6.170.6
|
||||
importlib-metadata==9.0.1
|
||||
interrogate==1.7.0
|
||||
# isort is deliberately not pinned: nothing here imports it (ruff's isort
|
||||
@ -77,16 +77,16 @@ radon==6.0.1
|
||||
reorder-python-imports==3.19.0
|
||||
requests==2.34.2
|
||||
rich==15.0.0
|
||||
ruff==0.17.1
|
||||
ruff==0.17.2
|
||||
# safety is deliberately not pinned: its only reference in this repo is a
|
||||
# commented-out pre-commit hook, and safety 3.8.1 declares `typer<0.26`,
|
||||
# which would hold the typer this repo actually imports below latest.
|
||||
secretstorage==3.5.0
|
||||
selenium==4.51.0
|
||||
typer==0.27.3
|
||||
types-python-dateutil==2.9.0.20260807
|
||||
types-python-dateutil==2.9.0.20261021
|
||||
types-PyYAML==6.0.12.20260906
|
||||
types-requests==2.33.0.20261006
|
||||
types-setuptools==84.0.0.20261006
|
||||
typing_extensions==4.16.0 # Self annotation on py310 target (session_autopsy store lock)
|
||||
websockets==17.2
|
||||
websockets==17.3
|
||||
|
||||
Loading…
Reference in New Issue
Block a user