mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 11:46:35 +00:00
Replace the previous OR-based assertion in scripts/tests/environment (which trivially passed because the Nexus log always grows from health probes) with a richer set of helpers split across two files under utils/ for SRP/SPOT. scripts/tests/environment/utils/cache.sh (new): * expected_system_proxy_for_runtime maps DEV_RUNTIME_IMAGE to the Nexus proxy that handles its system package manager (apt-debian, apt-ubuntu, yum-fedora, yum-rocky; empty for Manjaro/Arch where pacman is not cached). * nexus_repo_requests counts only /repository/<name>/... entries in the Nexus request log, optionally scoped to one proxy. Filters out health probes, admin REST calls, and Web-UI traffic. * registry_cache_flows counts every cache-flow status (HIT, MISS, REVALIDATED, UPDATING, STALE) so cold deploys also count. * assert_caches_used fails with a per-cache breakdown when any of three independent conditions is violated: total Nexus repo traffic = 0, the runtime's expected system proxy has 0 cached requests, or the deploy itself produced 0 registry-cache flows. * probe_caches actively fetches a known upstream resource through each cache (apt-debian/dists/bookworm/Release for the package cache, /ca.crt for the registry cache). * probe_did_inner_build drives a throwaway docker build whose apt-get update runs against deb.debian.org. The build container is placed on the compose network and pinned via --add-host to the frontend IP, exactly like the runtime override that roles/sys-svc-compose/files/compose.py injects for app builds. After the build the test snapshots ``docker logs infinito-package-cache-frontend`` and asserts the frontend recorded new requests, proving DiD apt traffic flows through nginx -> Nexus apt-debian and not directly to upstream. DOCKER_BUILDKIT=0 because BuildKit refuses --network=<compose-net>. scripts/tests/environment/utils/common.sh (renamed from lib.sh): keeps the bootstrap, constants, inventory inspect, and assert_http_status; cache helpers moved out so the file is single-concern. scripts/tests/environment/07_deploy_minimal.sh sources both files; order is snapshot, deploy, probe_caches, probe_did_inner_build, snapshot, assert_caches_used. Active probes contribute traffic that the AND assertion verifies, so the assertion is robust on deploys that do not naturally trigger inner-build apt traffic. .github/workflows/test-environment.yml: propagate DEV_RUNTIME_IMAGE into the inner ``docker run`` so per-distro probe target and proxy expectation resolve correctly inside the orchestrator. .gitignore + .dockerignore: also ignore .claude/settings.local.json, which compose mounts as /dev/null and which the classic docker builder would otherwise try (and fail) to read into the build context. Verified end-to-end with five iterations of ``make act-workflow ACT_WORKFLOW=.github/workflows/test-environment.yml ACT_JOB=test-environment ACT_MATRIX='dev_runtime_image:debian:bookworm'``. The final iteration reports +81 apt-debian, +235 registry-cache flows, +13 frontend log lines from the DiD probe, and "[OK] both cache stacks observed activity" plus "[OK] DiD inner-build flowed through cache frontend".
82 lines
2.5 KiB
Bash
Executable File
82 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Shared bootstrap, constants, and generic helpers for the environment
|
|
# test suite. Sourcing this file loads the repository env modules and
|
|
# configures git's safe.directory for the mounted workflow checkout.
|
|
# Cache-specific helpers live in cache.sh.
|
|
set -euo pipefail
|
|
|
|
DASHBOARD_APP="web-app-dashboard"
|
|
MATOMO_APP="web-app-matomo"
|
|
DASHBOARD_URL="https://dashboard.infinito.example"
|
|
MATOMO_URL="https://matomo.infinito.example"
|
|
|
|
# These constants are part of the sourced interface consumed by sibling scripts.
|
|
: "${DASHBOARD_APP}" "${MATOMO_APP}" "${DASHBOARD_URL}" "${MATOMO_URL}"
|
|
|
|
UTILS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$(cd "${UTILS_DIR}/../../../.." && pwd)"
|
|
|
|
ensure_git_safe_directory() {
|
|
local git_probe=""
|
|
|
|
if ! command -v git >/dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
|
|
if git -C "${REPO_ROOT}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
|
|
git_probe="$(git -C "${REPO_ROOT}" rev-parse --is-inside-work-tree 2>&1 || true)"
|
|
if [[ "${git_probe}" != *"detected dubious ownership"* ]]; then
|
|
return 0
|
|
fi
|
|
|
|
if ! git config --global --get-all safe.directory 2>/dev/null | grep -Fx "${REPO_ROOT}" >/dev/null 2>&1; then
|
|
echo "Configuring Git safe.directory for the mounted workflow checkout."
|
|
git config --global --add safe.directory "${REPO_ROOT}"
|
|
fi
|
|
}
|
|
|
|
load_repo_env() {
|
|
local previous_pwd
|
|
previous_pwd="$(pwd)"
|
|
cd "${REPO_ROOT}"
|
|
unset INFINITO_ENV_LOADED
|
|
unset INFINITO_ENV_PYTHON_LOADED
|
|
unset INFINITO_ENV_RUNTIME_LOADED
|
|
unset INFINITO_ENV_DEFAULTS_LOADED
|
|
unset INFINITO_ENV_INVENTORY_LOADED
|
|
unset INFINITO_ENV_GITHUB_LOADED
|
|
unset PYTHON
|
|
unset PIP
|
|
# shellcheck source=scripts/meta/env/all.sh
|
|
source scripts/meta/env/all.sh
|
|
cd "${previous_pwd}"
|
|
}
|
|
|
|
load_repo_env
|
|
ensure_git_safe_directory
|
|
|
|
# Print the generated inventory and host_vars for debugging and verification.
|
|
inspect() {
|
|
echo "Printing the generated inventory to verify which roles were deployed."
|
|
make exec CMD="cat ${INVENTORY_FILE}"
|
|
echo "Printing host_vars to verify per-host configuration."
|
|
make exec CMD="cat ${HOST_VARS_FILE}"
|
|
}
|
|
|
|
# Check that a URL responds with the expected HTTP status code.
|
|
# Usage: assert_http_status <expected_code> <url>
|
|
assert_http_status() {
|
|
local expected="${1}"
|
|
local url="${2}"
|
|
local actual
|
|
actual="$(curl -sS -o /dev/null -w '%{http_code}' "${url}" || true)"
|
|
if [ "${actual}" != "${expected}" ]; then
|
|
echo "[FAIL] ${url} returned HTTP ${actual}, expected ${expected}" >&2
|
|
exit 1
|
|
fi
|
|
echo "[OK] ${url} returned HTTP ${actual}"
|
|
}
|