nas-burnin/scripts/run-tests.sh
Brandon Walter cd92a4d3c8
Some checks are pending
Security scan / pip-audit (push) Waiting to run
Security scan / bandit (push) Waiting to run
Security scan / gitleaks (push) Waiting to run
Security scan / mypy (push) Waiting to run
chore: dev-experience + mypy noise cleanup
- scripts/run-tests.sh — one-shot wrapper for the tar+docker-cp dance
  that was being done by hand every test run. Optional pattern arg
  for a single module. Cleans tests/ out of the container after.

- scripts/security-scan.sh — mount the deploy app/ at /opt/app/app
  (not /src) so internal `from . import X` resolves through the
  `app` package and stops producing spurious "Module 'src' has no
  attribute X" errors that masked real findings.

- app/truenas.py — explicit `raise RuntimeError("unreachable")` after
  the retry loop. Functionally a no-op (loop always returns or
  re-raises), but makes the post-loop control flow obvious to
  readers and silences the mypy missing-return false positive.

mypy stays informational. Down to 14 real findings after these
fixes — promoting to gating still needs settings_store + retention
typing work, which is its own pass.
2026-05-03 21:11:23 -07:00

44 lines
1.6 KiB
Bash
Executable file

#!/usr/bin/env bash
# Run the test suite against the deployed container on maple.
#
# Tests aren't shipped in the prod image (Dockerfile only COPYs app/),
# so this tars them, copies them in, and runs unittest discover. Cleans
# up after itself so the running container doesn't accrue test files.
#
# Usage:
# scripts/run-tests.sh # run full suite
# scripts/run-tests.sh test_lifecycle # run a specific module
#
# Requires: ssh access to maple (configured in ~/.ssh/config).
set -euo pipefail
REMOTE_HOST="${REMOTE_HOST:-maple}"
CONTAINER="${CONTAINER:-truenas-burnin}"
REMOTE_TMP="/tmp/tnb-tests-$$.tgz"
CONTAINER_TMP="/tmp/tnb-tests.tgz"
PATTERN="${1:-}"
# Resolve repo root so this works whether invoked from the root or scripts/
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
echo "→ Packing tests/ from $REPO_ROOT"
cd "$REPO_ROOT"
tar cz tests | ssh "$REMOTE_HOST" "cat > $REMOTE_TMP"
echo "→ Copying into container $CONTAINER"
ssh "$REMOTE_HOST" "docker cp $REMOTE_TMP $CONTAINER:$CONTAINER_TMP && rm -f $REMOTE_TMP"
if [ -n "$PATTERN" ]; then
echo "→ Running tests matching: $PATTERN"
RUN_CMD="cd /opt/app && tar xzf $CONTAINER_TMP && python -m unittest tests.$PATTERN -v"
else
echo "→ Running full suite"
RUN_CMD="cd /opt/app && tar xzf $CONTAINER_TMP && python -m unittest discover -s tests"
fi
# Always try to clean tests/ out of the container after the run, even on failure.
CLEANUP="rm -rf /opt/app/tests $CONTAINER_TMP"
ssh "$REMOTE_HOST" "docker exec $CONTAINER sh -c '$RUN_CMD; rc=\$?; $CLEANUP; exit \$rc'"