**test(e2e): split update-all HTTPS integration test into pkgmgr and nix runs**
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled

Refactored the E2E update-all test to execute real CLI commands instead of invoking *main.py*.
The test is now split into two independent cases: one running *pkgmgr update* directly and one running the same command via *nix run .#pkgmgr*.
This improves realism, diagnostics, and parity with actual user workflows inside the container.

https://chatgpt.com/share/693c52cb-cc10-800f-994b-5b2940dcf948
This commit is contained in:
Kevin Veen-Birkenbach
2025-12-12 18:37:07 +01:00
parent f2caa68e3d
commit c8bf1c91ad

View File

@@ -7,11 +7,13 @@ This test is intended to be run inside the Docker container where:
- the config/config.yaml is present, - the config/config.yaml is present,
- and it is safe to perform real git operations. - and it is safe to perform real git operations.
It passes if the command completes without raising an exception. It passes if BOTH commands complete successfully (in separate tests):
1) pkgmgr update --all --clone-mode https --no-verification
2) nix run .#pkgmgr -- update --all --clone-mode https --no-verification
""" """
import runpy import os
import sys import subprocess
import unittest import unittest
from test_install_pkgmgr_shallow import ( from test_install_pkgmgr_shallow import (
@@ -22,55 +24,35 @@ from test_install_pkgmgr_shallow import (
class TestIntegrationUpdateAllHttps(unittest.TestCase): class TestIntegrationUpdateAllHttps(unittest.TestCase):
def _run_pkgmgr_update_all_https(self) -> None: def _run_cmd(self, cmd: list[str], label: str) -> None:
""" """
Helper that runs the CLI command via main.py and provides Run a real CLI command and raise a helpful assertion on failure.
extra diagnostics if the command exits with a non-zero code.
""" """
cmd_repr = "pkgmgr update --all --clone-mode https --no-verification" cmd_repr = " ".join(cmd)
original_argv = sys.argv env = os.environ.copy()
try: try:
sys.argv = [ print(f"\n[TEST] Running ({label}): {cmd_repr}")
"pkgmgr", subprocess.run(
"update", cmd,
"--all", check=True,
"--clone-mode", cwd=os.getcwd(),
"https", env=env,
"--no-verification", text=True,
] )
except subprocess.CalledProcessError as exc:
print(f"\n[TEST] Command failed ({label})")
print(f"[TEST] Command : {cmd_repr}")
print(f"[TEST] Exit code: {exc.returncode}")
try: nix_profile_list_debug(f"ON FAILURE ({label})")
# Execute main.py as if it was called from CLI.
# This will run the full update pipeline inside the container.
runpy.run_module("main", run_name="__main__")
except SystemExit as exc:
# Convert SystemExit into a more helpful assertion with debug output.
exit_code = exc.code if isinstance(exc.code, int) else str(exc.code)
print("\n[TEST] pkgmgr update --all failed with SystemExit") raise AssertionError(
print(f"[TEST] Command : {cmd_repr}") f"({label}) {cmd_repr!r} failed with exit code {exc.returncode}. "
print(f"[TEST] Exit code: {exit_code}") "Scroll up to see the full pkgmgr/nix output inside the container."
) from exc
# Additional Nix profile debug on failure (useful if any update def _common_setup(self) -> None:
# step interacts with Nix-based tooling).
nix_profile_list_debug("ON FAILURE (AFTER SystemExit)")
raise AssertionError(
f"{cmd_repr!r} failed with exit code {exit_code}. "
"Scroll up to see the full pkgmgr/make output inside the container."
) from exc
finally:
sys.argv = original_argv
def test_update_all_repositories_https(self) -> None:
"""
Run: pkgmgr update --all --clone-mode https --no-verification
This will perform real git update operations inside the container.
The test succeeds if no exception is raised and `pkgmgr --help`
works in a fresh interactive bash session afterwards.
"""
# Debug before cleanup # Debug before cleanup
nix_profile_list_debug("BEFORE CLEANUP") nix_profile_list_debug("BEFORE CLEANUP")
@@ -81,11 +63,28 @@ class TestIntegrationUpdateAllHttps(unittest.TestCase):
# Debug after cleanup # Debug after cleanup
nix_profile_list_debug("AFTER CLEANUP") nix_profile_list_debug("AFTER CLEANUP")
# Run the actual update with extended diagnostics def test_update_all_repositories_https_pkgmgr(self) -> None:
self._run_pkgmgr_update_all_https() """
Run: pkgmgr update --all --clone-mode https --no-verification
"""
self._common_setup()
# After successful update: show `pkgmgr --help` args = ["update", "--all", "--clone-mode", "https", "--no-verification"]
# via interactive bash (same helper as in the other integration tests). self._run_cmd(["pkgmgr", *args], label="pkgmgr")
# After successful update: show `pkgmgr --help` via interactive bash
pkgmgr_help_debug()
def test_update_all_repositories_https_nix_pkgmgr(self) -> None:
"""
Run: nix run .#pkgmgr -- update --all --clone-mode https --no-verification
"""
self._common_setup()
args = ["update", "--all", "--clone-mode", "https", "--no-verification"]
self._run_cmd(["nix", "run", ".#pkgmgr", "--", *args], label="nix run .#pkgmgr")
# After successful update: show `pkgmgr --help` via interactive bash
pkgmgr_help_debug() pkgmgr_help_debug()