chore(test): run the container test bodies from files instead of inline bash

No code in code for the container tests (operator denial d8b0c6c8; operator choice 13bec2bf: swarm funnel; fits Quality req 018 clean.embedded-code). The five host scripts no longer embed an in-container script as bash -lc; each runs a file with bash -l: test-unit.sh and test-integration.sh call scripts/test/container/unittest.sh with tests/unit or tests/integration, test-e2e.sh calls container/e2e.sh, test-env-virtual.sh calls container/env-virtual.sh, test-env-nix.sh calls container/env-nix.sh with IMAGE and PKGMGR_DISTRO as arguments. Commands, order, strict-mode lines, env vars, volumes and workdir are unchanged.

| 🌿 Branch | 📊 Diff stat | 🎯 Fix | 💥 Break | 💸 Tokens | ⏱️ Velocity | 🛡️ Security | 🏆 Score | Gate |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| chore/test-scripts-no-inline | 9 files +116/-127 | 90 % | 4 % | – | – | 100 % | 86 | ✅ 90/5, tokens and velocity <= 100, security 100 % |

Evidence: shellcheck -x clean on all 9 files, no bash -lc block left under scripts/, MEDUSA 100 % critical 0 (2 SC1091 scanner artefacts accepted). Break 4 %: unproven until PR CI runs the containers. Operator review a493a79a (re-card of f877c5dd).
Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-30 19:44:34 +00:00
1 parent 2c70837d00
commit 9a9ac39ad4
9 files changed
+116 -127

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -euo pipefail
if [ -f /etc/os-release ]; then
# shellcheck source=/dev/null
. /etc/os-release
fi
echo "Running tests inside distro: ${ID:-unknown}"
if [ -f "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ]; then
# shellcheck source=/dev/null
. "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
fi
if [ -f "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
# shellcheck source=/dev/null
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
fi
PATH="/nix/var/nix/profiles/default/bin:$HOME/.nix-profile/bin:$PATH"
command -v nix >/dev/null || {
echo "ERROR: nix not found."
exit 1
}
if command -v git >/dev/null 2>&1; then
git config --global --add safe.directory /opt/src/pkgmgr || true
git config --global --add safe.directory /opt/src/pkgmgr/.git || true
git config --global --add safe.directory "*" || true
fi
nix develop .#default --no-write-lock-file -c \
python3 -m unittest discover \
-s /opt/src/pkgmgr/tests/e2e \
-p "$TEST_PATTERN"
+46
View File
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
set -euo pipefail
# Param: $1 IMAGE, the image name shown in the missing-nix error.
# Param: $2 PKGMGR_DISTRO, the distro shown in the missing-nix error.
IMAGE="$1"
PKGMGR_DISTRO="$2"
if command -v git >/dev/null 2>&1; then
git config --global --add safe.directory /opt/src/pkgmgr || true
git config --global --add safe.directory /opt/src/pkgmgr/.git || true
git config --global --add safe.directory "*" || true
fi
echo ">>> preflight: nix must exist in image"
if ! command -v nix >/dev/null 2>&1; then
echo "NO_NIX"
echo "ERROR: nix not found in image ${IMAGE} (PKGMGR_DISTRO=${PKGMGR_DISTRO})"
echo "HINT: Ensure Nix is installed during image build for this distro."
exit 1
fi
echo ">>> nix version"
nix --version
if [[ -f /opt/src/pkgmgr/scripts/nix/lib/retry_403.sh ]]; then
# shellcheck source=SCRIPTDIR/../../nix/lib/retry_403.sh
source /opt/src/pkgmgr/scripts/nix/lib/retry_403.sh
elif [[ -f ./scripts/nix/lib/retry_403.sh ]]; then
# shellcheck source=SCRIPTDIR/../../nix/lib/retry_403.sh
source ./scripts/nix/lib/retry_403.sh
else
echo "ERROR: retry helper not found: scripts/nix/lib/retry_403.sh"
exit 1
fi
echo ">>> nix flake show"
run_with_github_403_retry nix flake show . --no-write-lock-file >/dev/null
echo ">>> nix build .#default"
run_with_github_403_retry nix build .#default --no-link --no-write-lock-file
echo ">>> nix run .#pkgmgr -- --help"
run_with_github_403_retry nix run .#pkgmgr -- --help --no-write-lock-file
echo ">>> OK: Nix flake-only test succeeded."
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail
echo "[test-env-virtual] Installing pkgmgr (distro package)..."
make install
echo "[test-env-virtual] Setting up Python venv..."
make setup-venv
echo "[test-env-virtual] Activating venv..."
# shellcheck source=/dev/null
. "$HOME/.venvs/pkgmgr/bin/activate"
echo "[test-env-virtual] Using pkgmgr from:"
command -v pkgmgr
pkgmgr --help
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e
# Param: $1 the test folder to discover, tests/unit or tests/integration.
suite="$1"
git config --global --add safe.directory /opt/src/pkgmgr || true
nix develop .#default --no-write-lock-file -c \
python3 -m unittest discover \
-s "$suite" \
-t /opt/src/pkgmgr \
-p "$TEST_PATTERN"
+1 -45
View File
@@ -14,48 +14,4 @@ docker run --rm \
-e NIX_CONFIG="${NIX_CONFIG}" \ -e NIX_CONFIG="${NIX_CONFIG}" \
--workdir /opt/src/pkgmgr \ --workdir /opt/src/pkgmgr \
"pkgmgr-${PKGMGR_DISTRO}" \ "pkgmgr-${PKGMGR_DISTRO}" \
bash -lc ' bash -l scripts/test/container/e2e.sh
set -euo pipefail
# Load distro info
if [ -f /etc/os-release ]; then
. /etc/os-release
fi
echo "Running tests inside distro: ${ID:-unknown}"
# Load Nix environment if available
if [ -f "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ]; then
. "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
fi
if [ -f "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
fi
PATH="/nix/var/nix/profiles/default/bin:$HOME/.nix-profile/bin:$PATH"
command -v nix >/dev/null || {
echo "ERROR: nix not found."
exit 1
}
# Mark the mounted repository as safe to avoid Git ownership errors.
# Newer Git (e.g. on Ubuntu) complains about the gitdir (/opt/src/pkgmgr/.git),
# older versions about the worktree (/opt/src/pkgmgr). Nix turns "." into the
# flake input "git+file:///opt/src/pkgmgr", which then uses Git under the hood.
if command -v git >/dev/null 2>&1; then
# Worktree path
git config --global --add safe.directory /opt/src/pkgmgr || true
# Gitdir path shown in the "dubious ownership" error
git config --global --add safe.directory /opt/src/pkgmgr/.git || true
# Ephemeral CI containers: allow all paths as a last resort
git config --global --add safe.directory "*" || true
fi
# Run the E2E tests inside the Nix development shell
nix develop .#default --no-write-lock-file -c \
python3 -m unittest discover \
-s /opt/src/pkgmgr/tests/e2e \
-p "$TEST_PATTERN"
'
+1 -45
View File
@@ -16,48 +16,4 @@ docker run --rm \
-e REINSTALL_PKGMGR=1 \ -e REINSTALL_PKGMGR=1 \
-e NIX_CONFIG="${NIX_CONFIG}" \ -e NIX_CONFIG="${NIX_CONFIG}" \
"${IMAGE}" \ "${IMAGE}" \
bash -lc ' bash -l scripts/test/container/env-nix.sh "${IMAGE}" "${PKGMGR_DISTRO}"
set -euo pipefail
if command -v git >/dev/null 2>&1; then
git config --global --add safe.directory /opt/src/pkgmgr || true
git config --global --add safe.directory /opt/src/pkgmgr/.git || true
git config --global --add safe.directory "*" || true
fi
echo ">>> preflight: nix must exist in image"
if ! command -v nix >/dev/null 2>&1; then
echo "NO_NIX"
echo "ERROR: nix not found in image '"${IMAGE}"' (PKGMGR_DISTRO='"${PKGMGR_DISTRO}"')"
echo "HINT: Ensure Nix is installed during image build for this distro."
exit 1
fi
echo ">>> nix version"
nix --version
# ------------------------------------------------------------
# Retry helper for GitHub API rate-limit (HTTP 403)
# ------------------------------------------------------------
if [[ -f /opt/src/pkgmgr/scripts/nix/lib/retry_403.sh ]]; then
# shellcheck source=./scripts/nix/lib/retry_403.sh
source /opt/src/pkgmgr/scripts/nix/lib/retry_403.sh
elif [[ -f ./scripts/nix/lib/retry_403.sh ]]; then
# shellcheck source=./scripts/nix/lib/retry_403.sh
source ./scripts/nix/lib/retry_403.sh
else
echo "ERROR: retry helper not found: scripts/nix/lib/retry_403.sh"
exit 1
fi
echo ">>> nix flake show"
run_with_github_403_retry nix flake show . --no-write-lock-file >/dev/null
echo ">>> nix build .#default"
run_with_github_403_retry nix build .#default --no-link --no-write-lock-file
echo ">>> nix run .#pkgmgr -- --help"
run_with_github_403_retry nix run .#pkgmgr -- --help --no-write-lock-file
echo ">>> OK: Nix flake-only test succeeded."
'
+1 -19
View File
@@ -12,31 +12,13 @@ echo "[test-env-virtual] Inspect image metadata:"
docker image inspect "${IMAGE}" | sed -n '1,40p' docker image inspect "${IMAGE}" | sed -n '1,40p'
echo echo
# ------------------------------------------------------------
# Run VENV-based pkgmgr test inside container
# ------------------------------------------------------------
if OUTPUT=$(docker run --rm \ if OUTPUT=$(docker run --rm \
-e REINSTALL_PKGMGR=1 \ -e REINSTALL_PKGMGR=1 \
-v "$(pwd):/opt/src/pkgmgr" \ -v "$(pwd):/opt/src/pkgmgr" \
-w /opt/src/pkgmgr \ -w /opt/src/pkgmgr \
-e NIX_CONFIG="${NIX_CONFIG}" \ -e NIX_CONFIG="${NIX_CONFIG}" \
"${IMAGE}" \ "${IMAGE}" \
bash -lc ' bash -l scripts/test/container/env-virtual.sh 2>&1); then
set -euo pipefail
echo "[test-env-virtual] Installing pkgmgr (distro package)..."
make install
echo "[test-env-virtual] Setting up Python venv..."
make setup-venv
echo "[test-env-virtual] Activating venv..."
. "$HOME/.venvs/pkgmgr/bin/activate"
echo "[test-env-virtual] Using pkgmgr from:"
command -v pkgmgr
pkgmgr --help
' 2>&1); then
echo "$OUTPUT" echo "$OUTPUT"
echo echo
+1 -9
View File
@@ -14,12 +14,4 @@ docker run --rm \
-e TEST_PATTERN="${TEST_PATTERN}" \ -e TEST_PATTERN="${TEST_PATTERN}" \
-e NIX_CONFIG="${NIX_CONFIG}" \ -e NIX_CONFIG="${NIX_CONFIG}" \
"pkgmgr-${PKGMGR_DISTRO}" \ "pkgmgr-${PKGMGR_DISTRO}" \
bash -lc ' bash -l scripts/test/container/unittest.sh tests/integration
set -e;
git config --global --add safe.directory /opt/src/pkgmgr || true;
nix develop .#default --no-write-lock-file -c \
python3 -m unittest discover \
-s tests/integration \
-t /opt/src/pkgmgr \
-p "$TEST_PATTERN";
'
+1 -9
View File
@@ -14,12 +14,4 @@ docker run --rm \
-e TEST_PATTERN="${TEST_PATTERN}" \ -e TEST_PATTERN="${TEST_PATTERN}" \
-e NIX_CONFIG="${NIX_CONFIG}" \ -e NIX_CONFIG="${NIX_CONFIG}" \
"pkgmgr-${PKGMGR_DISTRO}" \ "pkgmgr-${PKGMGR_DISTRO}" \
bash -lc ' bash -l scripts/test/container/unittest.sh tests/unit
set -e;
git config --global --add safe.directory /opt/src/pkgmgr || true;
nix develop .#default --no-write-lock-file -c \
python3 -m unittest discover \
-s tests/unit \
-t /opt/src/pkgmgr \
-p "$TEST_PATTERN";
'