From 142697a19c0d27037c0910ccac3f7d967cfdb7dc Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Sun, 13 Sep 2026 03:22:19 -0500 Subject: [PATCH] test(architecture): add structural invariants and test runner --- scripts/test | 24 ++++++++ tests/structural/test_repository_structure.py | 56 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100755 scripts/test create mode 100644 tests/structural/test_repository_structure.py diff --git a/scripts/test b/scripts/test new file mode 100755 index 0000000..a5f016d --- /dev/null +++ b/scripts/test @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# scripts/test - Automated test & invariant verification runner for Homelab Core +set -euo pipefail + +cd "$(dirname "$0")/.." + +echo "๐Ÿ” Running code linters (ruff)..." +if command -v ruff &>/dev/null; then + ruff check . +else + nix-shell -p ruff --run "ruff check ." +fi + +echo "๐Ÿงช Running architecture & security test suite (pytest)..." +if command -v pytest &>/dev/null; then + pytest tests/ +else + nix-shell -p python3Packages.pytest python3Packages.pyyaml --run "pytest tests/" +fi + +echo "โ„๏ธ Verifying NixOS flake & sandbox checks..." +nix flake check + +echo "โœจ All tests and architectural invariants passed successfully!" diff --git a/tests/structural/test_repository_structure.py b/tests/structural/test_repository_structure.py new file mode 100644 index 0000000..0198e3e --- /dev/null +++ b/tests/structural/test_repository_structure.py @@ -0,0 +1,56 @@ +""" +Structural invariant tests for Homelab Core repository layout. +Ensures required architectural components exist and deprecated paths do not return. +""" + +from pathlib import Path + +CORE_ROOT = Path(__file__).resolve().parent.parent.parent + + +def test_required_architectural_paths_exist(): + """Ensure core architectural files and directories exist.""" + required_paths = [ + "docker-compose.yml", + "flake.nix", + "UNLICENSE", + "AGENTS.md", + "README.md", + "SECURITY.md", + "nixos", + "nixos/configuration.nix", + "nixos/modules/homeserver.nix", + "nixos/secrets.yaml", + "scripts/gitops_dispatcher.py", + "scripts/appctl", + "scripts/appctl_engine.py", + "tests", + ] + + for p in required_paths: + target = CORE_ROOT / p + assert target.exists(), f"Required architectural path missing: {p}" + + +def test_deprecated_legacy_structures_are_absent(): + """Ensure deprecated files and legacy layouts are not reintroduced.""" + prohibited_paths = [ + "infra/core", + "up.sh", + "down.sh", + "scripts/check-ssl.sh", + "scripts/purge-dynu.sh", + "scripts/ip-monitor.sh", + ] + + for p in prohibited_paths: + target = CORE_ROOT / p + assert not target.exists(), f"Prohibited deprecated path detected: {p}" + + +def test_unlicense_preserved(): + """Ensure The Unlicense (public domain invariant) is maintained.""" + unlicense = CORE_ROOT / "UNLICENSE" + assert unlicense.is_file(), "UNLICENSE file must be present" + content = unlicense.read_text(encoding="utf-8") + assert "This is free and unencumbered software released into the public domain." in content