93d33ecb0c
SLICE-08 (devops-engineer): .env.example updated with Proxmox deployment vars (documented, sourced from ~/coreci/.env.secrets per D-026), PRAXIS_CLIENT_DIST for StaticFiles, PRAXIS_SCENARIO. config.json secrets.scopes already extended in SPECIFY (proxmox + voice scopes). SLICE-09 (devops-engineer): 10 bats test files (G-106 fix: 10 not 9) covering all proxmox scripts — 121 tests, 114 pass + 7 skipped (e2e). Mocked curl/pct/ssh; no live cluster needed for unit tests. SLICE-10 (devops-engineer): e2e-deploy.sh — sources secrets from both coreci + praxis .env.secrets, runs full deploy, verifies /health + client HTML serving. REQ-DEPLOY-15 covered. All 6 grill binding decisions addressed: G-101 MUST: GITEA_TOKEN baked into snippet (stage-snippet.sh) G-102 MUST: PRAXIS_DB_PATH env read (db/store.py + db/migrate.py) G-103 FIX: all 16 env vars in injection list (install-service.sh) G-104 FIX: health-check timeout 600s (health-check.sh) G-105 FIX: Dockerfile copy ordering (pyproject before source) G-106 FIX: bats test count = 10 REQ-DEPLOY-12, 14, 15 covered. All 20 REQ-IDs now implemented. ---ci--- project: praxis phase: 1 milestone: v0.2 status: execute slice: 08-10 wave: 4 ---/ci---
100 lines
3.9 KiB
Bash
100 lines
3.9 KiB
Bash
# Shared helpers for the praxis proxmox bats test suite.
|
|
#
|
|
# Sourced (via `load`) by the per-script .bats files to build a consistent
|
|
# sandbox: a temp STUB_DIR, a CALL_LOG, a sandbox ROOT with a mocked
|
|
# api.sh + recording stubs for the provision siblings. Each .bats file
|
|
# may further specialize the sandbox in its own setup().
|
|
#
|
|
# Usage from a .bats file:
|
|
# setup() {
|
|
# load setup_helper
|
|
# praxis_sandbox_init # sets STUB_DIR, LOG, ROOT, mocks
|
|
# PROXMOX_API_URL="https://proxmox.test:8006/api2/json"
|
|
# ...
|
|
# }
|
|
# teardown() { praxis_sandbox_teardown; }
|
|
#
|
|
# Helpers exported (functions):
|
|
# praxis_sandbox_init — create the sandbox + default mocks
|
|
# praxis_sandbox_teardown — rm -rf the sandbox
|
|
# praxis_log_stub <name> <exit-var>
|
|
# — write a recording stub at ROOT/<name>.sh
|
|
# that logs "<name>:<args>" to $CALL_LOG and
|
|
# exits ${<exit-var>:-0}
|
|
# praxis_mock_api_default — install the default mocked api.sh
|
|
# (pve_env no-op, pve_nextid → STUB_NEXTID,
|
|
# pve_get → STUB_PVE_GET, pve_curl no-op,
|
|
# pve_poll no-op). Tests may override
|
|
# individual funcs after calling this.
|
|
|
|
# praxis_sandbox_init — create the sandbox. Idempotent-ish: callers usually
|
|
# invoke once in setup(). Sets these globals for the test:
|
|
# STUB_DIR — temp dir root (cleaned in teardown)
|
|
# CALL_LOG — shared call log path (tests grep this)
|
|
# ROOT — sandbox root dir (real SCRIPT_DIR stand-in; siblings live here)
|
|
praxis_sandbox_init() {
|
|
STUB_DIR="$(mktemp -d)"
|
|
export STUB_DIR
|
|
CALL_LOG="${STUB_DIR}/calls.log"
|
|
: > "$CALL_LOG" 2>/dev/null || true
|
|
export CALL_LOG
|
|
ROOT="${STUB_DIR}/root"
|
|
mkdir -p "$ROOT"
|
|
export ROOT
|
|
# Default mocked api.sh — tests can overwrite ${ROOT}/api.sh after this.
|
|
praxis_mock_api_default
|
|
}
|
|
|
|
praxis_sandbox_teardown() {
|
|
[ -n "${STUB_DIR:-}" ] && rm -rf "$STUB_DIR"
|
|
}
|
|
|
|
# praxis_log_stub <name> <exit-var> — write a recording stub at
|
|
# ${ROOT}/<name>.sh that logs "<name>:<args>" to $CALL_LOG and exits
|
|
# with ${<exit-var>:-0}. The stub is chmod +x.
|
|
praxis_log_stub() {
|
|
_name="$1"; _exit_var="$2"
|
|
printf '#!/bin/sh\necho "%s:$*" >> "%s"\nexit ${%s:-0}\n' \
|
|
"$_name" "$CALL_LOG" "$_exit_var" > "${ROOT}/${_name}.sh"
|
|
chmod +x "${ROOT}/${_name}.sh"
|
|
}
|
|
|
|
# praxis_mock_api_default — install the default mocked api.sh.
|
|
# pve_env no-op; pve_nextid returns ${STUB_NEXTID:-200}; pve_get returns
|
|
# ${STUB_PVE_GET:-}; pve_curl no-op; pve_poll no-op. Override by writing
|
|
# your own ${ROOT}/api.sh after calling this (or by redefining funcs in
|
|
# your own setup).
|
|
praxis_mock_api_default() {
|
|
cat > "${ROOT}/api.sh" <<'ASTUB'
|
|
pve_env() { :; }
|
|
pve_nextid() { printf '%s\n' "${STUB_NEXTID:-200}"; }
|
|
pve_get() { printf '%s\n' "${STUB_PVE_GET:-}"; }
|
|
pve_curl() { :; }
|
|
pve_poll() { :; }
|
|
pve_tls_insecure() { printf '%s\n' "${STUB_TLS_INSECURE:-}"; }
|
|
pve_auth_header() { printf 'PVEAPIToken=%s' "${PROXMOX_API_TOKEN:-}"; }
|
|
pve_lxc_env_args() {
|
|
first=1
|
|
for pair in "$@"; do
|
|
[ "$first" -eq 0 ] && printf '\n'
|
|
printf '%s' "lxc.environment=${pair}"
|
|
first=0
|
|
done
|
|
}
|
|
ASTUB
|
|
chmod +x "${ROOT}/api.sh"
|
|
}
|
|
|
|
# praxis_common_env — export the common Proxmox env vars used by every
|
|
# test (all mocked; no live endpoint). Tests may override per-scenario.
|
|
praxis_common_env() {
|
|
export PROXMOX_API_URL="https://proxmox.test:8006/api2/json"
|
|
export PROXMOX_API_TOKEN="root@pam!test=secret"
|
|
export PROXMOX_NODE="testnode"
|
|
export PROXMOX_STORAGE="local"
|
|
export PROXMOX_TEMPLATE_VOLID="local:vztmpl/debian-12-template.tar.zst"
|
|
export GITEA_TOKEN="gitea-test-token"
|
|
export PRAXIS_VERSION="v0.2"
|
|
export PRAXIS_PORT="8789"
|
|
export PROXMOX_LXC_VMID="200"
|
|
} |