Files
coreci-chat/scripts/install.test.sh
T
CIAgent 86f7dcc10b feat(P4): Wave D relay agent — Go binary, install script, WebSocket, SSH whitelist hook
REQ-010: modular install script (detect_os/install_binary/write_systemd_unit/register_target)
REQ-011: outbound WebSocket from relay agent to SaaS
REQ-012: register with tenant + target metadata
REQ-013: heartbeat + exponential backoff reconnect (max 5 → alert)
REQ-026 partial: SSH whitelist file + CheckCommand hook (G-004 contract lock,
  G-007 shadow exec.Cmd test, G-008 scope statement)
G-009: unsupported-OS abort with actionable error

---ci---
phase: 4
milestone: v0.1
status: execute
---/ci---
2026-08-25 02:03:04 +00:00

132 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# CoreCI Chat install.sh tests — exercises detect_os logic (G-009).
#
# Sources install.sh (which skips main() when sourced) and runs detect_os
# against synthetic /etc/os-release files. Covers:
# - Ubuntu 24.04 (supported) → detect_os returns 0
# - Ubuntu 22.04 (wrong version) → detect_os returns 1
# - Debian 12 (supported) → detect_os returns 0
# - Debian 11 (wrong version) → detect_os returns 1
# - Fedora 40 (wrong family) → detect_os returns 1 [G-009 non-Debian]
# - Alpine 3.20 (wrong family) → detect_os returns 1 [G-009 non-Debian]
# - missing /etc/os-release → detect_os returns 1
#
# Run: bash scripts/install.test.sh
set -uo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
INSTALL_SH="${HERE}/install.sh"
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
# Source install.sh so detect_os + version_ge are defined. main() is skipped
# because BASH_SOURCE[0] != $0 when sourced. We disable set -e for the test
# harness so a non-zero return from detect_os (the expected behavior for the
# unsupported cases) doesn't abort the script.
# shellcheck source=install.sh
set +e
source "$INSTALL_SH"
set -e
pass=0
fail=0
ok_test() { pass=$((pass+1)); printf ' \033[32mpass\033[0m %s\n' "$1"; }
fail_test() { fail=$((fail+1)); printf ' \033[31mfail\033[0m %s\n' "$1"; }
# write_os_release <id> <version_id> [pretty_name]
write_os_release() {
local f="$TMPDIR/os-release-$1-$2"
{
echo "ID=$1"
echo "VERSION_ID=$2"
echo "PRETTY_NAME=${3:-$1 $2}"
} >"$f"
echo "$f"
}
# run_detect <id> <version_id> <expect: 0|1>
run_detect() {
local id="$1" ver="$2" expect="$3"
local f
f="$(write_os_release "$id" "$ver")"
set +e
OS_RELEASE_PATH="$f" detect_os >/dev/null 2>&1
local got=$?
set -e
if [[ "$got" == "$expect" ]]; then
ok_test "detect_os $id $ver → exit $got (expect $expect)"
else
fail_test "detect_os $id $ver → exit $got (expect $expect)"
fi
}
echo "TAP: install.sh detect_os matrix (G-009)"
# Supported cases (REQ-010 happy path: Ubuntu 24.04, Debian 12+).
run_detect ubuntu 24.04 0
run_detect ubuntu 24.10 0
run_detect debian 12 0
run_detect debian 12.5 0
run_detect debian 13 0
# Wrong-version Debian-family (G-009 second unsupported case).
run_detect ubuntu 22.04 1
run_detect ubuntu 20.04 1
run_detect debian 11 1
run_detect debian 10 1
# Wrong-family (G-009 first unsupported case — non-Debian).
run_detect fedora 40 1
run_detect alpine 3.20 1
run_detect centos 9 1
run_detect arch rolling 1
# Missing /etc/os-release.
if OS_RELEASE_PATH="$TMPDIR/does-not-exist" detect_os >/dev/null 2>&1; then
fail_test "missing /etc/os-release → detect_os should fail"
else
ok_test "missing /etc/os-release → detect_os fails"
fi
# version_ge unit checks.
echo
echo "TAP: version_ge"
vg() {
set +e
version_ge "$1" "$2"
local r=$?
set -e
if [[ "$r" -eq 0 ]]; then
ok_test "version_ge $1 $2 → true (expect $3)"
else
fail_test "version_ge $1 $2 → false (expect $3)"
fi
}
vl() {
set +e
version_ge "$1" "$2"
local r=$?
set -e
if [[ "$r" -eq 0 ]]; then
fail_test "version_ge $1 $2 → true (expect $3=false)"
else
ok_test "version_ge $1 $2 → false (expect $3=false)"
fi
}
vg 24.04 24.04 true
vg 24.10 24.04 true
vg 25.04 24.04 true
vl 22.04 24.04 false
vl 20.04 24.04 false
vg 12 12 true
vg 12.5 12 true
vg 13 12 true
vl 11 12 false
vl 10 12 false
echo
echo "TAP: $pass passed, $fail failed"
if [[ "$fail" -gt 0 ]]; then
exit 1
fi
exit 0