Files
nixos-core/tests/structural/test_repository_structure.py
kiskaadee ce969f4678 feat(nixos): add homelab.workloadGrants option, grants.json projection, and instance.example.nix
- Define homelab.workloadGrants attrsOf submodule in nixos/modules/homeserver.nix with devices, groups, and readOnlyPaths

- Add Nix assertions rejecting privileged groups (0, root, wheel, docker) and relative/traversal paths

- Generate /etc/homelab/grants.json (root:homelab-operators 0640) and wire HOMELAB_GRANTS_FILE into homelab-appctl and homelab-gitops

- Add tracked nixos/instance.example.nix and prioritize /etc/nixos/homelab-instance.nix over nixos/instance.nix

- Add structural and security invariant tests for workloadGrants and instance.example.nix
2026-11-21 03:54:02 -05:00

71 lines
2.1 KiB
Python

"""
Structural invariant tests for Homelab Core repository layout.
Ensures required architectural components exist and deprecated paths do not return.
"""
import os
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/instance.example.nix",
"nixos/modules/homeserver.nix",
"nixos/secrets.yaml",
"scripts/gitops_dispatcher.py",
"scripts/appctl",
"scripts/appctl_engine.py",
"config/homepage",
".githooks/pre-commit",
"tests",
]
for p in required_paths:
target = CORE_ROOT / p
assert target.exists(), f"Required architectural path missing: {p}"
pre_commit = CORE_ROOT / ".githooks" / "pre-commit"
assert pre_commit.is_file(), ".githooks/pre-commit must be a regular file"
assert os.access(pre_commit, os.X_OK), (
".githooks/pre-commit must be marked executable"
)
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",
"docs/legacy",
]
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
)