Repository-wide mechanical cleanup so `ruff check src tests` has a chance of passing; no behavioural changes. - Add `from __future__ import annotations` where PEP 604 unions are used. This has to come first: pyproject declares requires-python >= 3.9, where `X | None` is not evaluable at runtime unless annotations are stringified. - Replace typing.List/Dict/Tuple/Set with the builtin generics and Optional[X] with X | None, then drop the imports that became unused. The four actions/*/__init__.py files needed this by hand because ruff leaves unused imports in __init__.py alone (possible re-exports). - Strip shebangs from 72 importable modules. None of them are executable or invoked directly; the entry points are console_scripts and runpy. - Flatten nested `with` blocks, collapse needless-bool returns, and apply the remaining mechanical ruff fixes (PIE810, FLY002, PERF102, FURB192, RUF059, I001). - Pass check=False explicitly to the four subprocess.run() calls that inspect returncode themselves. That is the existing default. Two rewrites are visible to mocks, so their tests move with them: subprocess.run(stdout=PIPE, stderr=PIPE) became capture_output=True, and open(path, "r", ...) lost the redundant mode. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
92 lines
2.4 KiB
Python
92 lines
2.4 KiB
Python
"""
|
||
E2E test to inspect the Nix environment and build the pkgmgr flake
|
||
in *every* distro container.
|
||
|
||
Commands executed inside the container (for all distros):
|
||
|
||
nix --version
|
||
nix show-config | grep sandbox
|
||
id
|
||
nix build .#pkgmgr -L
|
||
|
||
No docker is called from here – the outer test harness
|
||
(scripts/test/test-e2e.sh) is responsible for starting the container.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import os
|
||
import subprocess
|
||
import unittest
|
||
|
||
# Resolve project root (the repo where flake.nix lives, e.g. /src)
|
||
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||
|
||
|
||
def _run_cmd(cmd: list[str]) -> subprocess.CompletedProcess:
|
||
"""
|
||
Run a command in a subprocess, capture stdout/stderr and print them.
|
||
|
||
Does NOT raise by itself – the caller checks returncode.
|
||
"""
|
||
print("\n[TEST] Running command:", " ".join(cmd))
|
||
proc = subprocess.run(
|
||
cmd,
|
||
text=True,
|
||
capture_output=True,
|
||
check=False,
|
||
)
|
||
print("[STDOUT]\n", proc.stdout)
|
||
print("[STDERR]\n", proc.stderr)
|
||
print("[RETURN CODE]", proc.returncode)
|
||
return proc
|
||
|
||
|
||
class TestNixBuildPkgmgrAllDistros(unittest.TestCase):
|
||
"""
|
||
E2E test that runs the same Nix diagnostics + flake build
|
||
in all distro containers.
|
||
"""
|
||
|
||
def test_nix_env_and_build_pkgmgr(self) -> None:
|
||
# Ensure we are in the project root (where flake.nix resides)
|
||
original_cwd = os.getcwd()
|
||
try:
|
||
os.chdir(PROJECT_ROOT)
|
||
|
||
# --- Nix version ---
|
||
_run_cmd(["nix", "--version"])
|
||
|
||
# --- Nix sandbox setting ---
|
||
_run_cmd(["sh", "-c", "nix show-config | grep sandbox || true"])
|
||
|
||
# --- Current user ---
|
||
_run_cmd(["id"])
|
||
|
||
# --- nix build .#pkgmgr -L ---
|
||
proc = _run_cmd(
|
||
[
|
||
"nix",
|
||
"--option",
|
||
"sandbox",
|
||
"false",
|
||
"build",
|
||
".#pkgmgr",
|
||
"-L",
|
||
]
|
||
)
|
||
|
||
if proc.returncode != 0:
|
||
raise AssertionError(
|
||
"nix build .#pkgmgr -L failed inside the test container.\n"
|
||
f"Exit code: {proc.returncode}\n"
|
||
"See STDOUT/STDERR above for Nix diagnostics."
|
||
)
|
||
|
||
finally:
|
||
os.chdir(original_cwd)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|