2025-12-05 20:20:33 +01:00
|
|
|
import runpy
|
|
|
|
|
import sys
|
Refactor pkgmgr installers, introduce capability-based execution, and replace manifest layer
References:
- Current ChatGPT conversation: https://chatgpt.com/share/6935d6d7-0ae4-800f-988a-44a50c17ba48
- Extended discussion: https://chatgpt.com/share/6935d734-fd84-800f-9755-290902b8cee8
Summary:
This commit performs a major cleanup and modernization of the installation pipeline:
1. Introduced a new capability-detection subsystem:
- Capabilities (python-runtime, make-install, nix-flake) are detected per installer/layer.
- Installers run only when they add new capabilities.
- Prevents duplicated work such as Python installers running when Nix already provides the runtime.
2. Removed deprecated pkgmgr.yml manifest installer:
- Dependency resolution is now delegated entirely to real package managers (Nix, pip, make, distro build tools).
- Simplifies layering and avoids unnecessary recursion.
3. Reworked OS-specific installers:
- Arch PKGBUILD now uses 'makepkg --syncdeps --cleanbuild --install --noconfirm'.
- Debian installer now builds proper .deb packages via dpkg-buildpackage + installs them.
- RPM installer now builds packages using rpmbuild and installs them via rpm.
4. Switched from remote GitHub flakes to local-flake execution:
- Wrapper now executes: nix run /usr/lib/package-manager#pkgmgr
- Avoids lock-file write attempts and improves reliability in CI.
5. Added bash -i based integration test:
- Correctly sources ~/.bashrc and evaluates alias + venv activation.
- ‘pkgmgr --help’ is now printed for debugging without failing tests.
6. Updated unit tests across all installers:
- Removed references to manifest installer.
- Adjusted expectations for new behaviors (makepkg, dpkg-buildpackage, rpmbuild).
- Added capability subsystem tests.
7. Improved flake.nix packaging logic:
- The entire project source tree is copied into the runtime closure.
- pkgmgr wrapper now executes runpy inside the packaged directory.
Together, these changes create a predictable, layered, capability-driven installer pipeline with consistent behavior across Arch, Debian, RPM, Nix, and Python layers.
2025-12-07 20:36:39 +01:00
|
|
|
import os
|
2025-12-05 20:20:33 +01:00
|
|
|
import unittest
|
2025-12-06 17:47:46 +01:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def nix_profile_list_debug(label: str) -> None:
|
|
|
|
|
"""
|
|
|
|
|
Print `nix profile list` for debugging inside the test container.
|
|
|
|
|
Never fails the test.
|
|
|
|
|
"""
|
|
|
|
|
print(f"\n--- NIX PROFILE LIST ({label}) ---")
|
|
|
|
|
proc = subprocess.run(
|
|
|
|
|
["nix", "profile", "list"],
|
|
|
|
|
capture_output=True,
|
|
|
|
|
text=True,
|
|
|
|
|
check=False,
|
|
|
|
|
)
|
|
|
|
|
stdout = proc.stdout.strip()
|
|
|
|
|
stderr = proc.stderr.strip()
|
|
|
|
|
|
|
|
|
|
if stdout:
|
|
|
|
|
print(stdout)
|
|
|
|
|
if stderr:
|
|
|
|
|
print("stderr:", stderr)
|
|
|
|
|
print("--- END ---\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remove_pkgmgr_from_nix_profile() -> None:
|
|
|
|
|
"""
|
|
|
|
|
Best-effort cleanup before running the integration test.
|
2025-12-05 20:20:33 +01:00
|
|
|
|
2025-12-06 17:47:46 +01:00
|
|
|
We *do not* try to parse profile indices here, because modern `nix profile list`
|
|
|
|
|
prints a descriptive format without an index column inside the container.
|
2025-12-05 20:20:33 +01:00
|
|
|
|
2025-12-06 17:47:46 +01:00
|
|
|
Instead, we directly try to remove possible names:
|
2025-12-09 17:54:41 +01:00
|
|
|
- 'pkgmgr' (the actual name shown in `nix profile list`)
|
2025-12-06 17:47:46 +01:00
|
|
|
- 'package-manager' (the name mentioned in Nix's own error hints)
|
|
|
|
|
"""
|
|
|
|
|
for spec in ("pkgmgr", "package-manager"):
|
|
|
|
|
subprocess.run(
|
|
|
|
|
["nix", "profile", "remove", spec],
|
|
|
|
|
check=False, # never fail on cleanup
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
Refactor pkgmgr installers, introduce capability-based execution, and replace manifest layer
References:
- Current ChatGPT conversation: https://chatgpt.com/share/6935d6d7-0ae4-800f-988a-44a50c17ba48
- Extended discussion: https://chatgpt.com/share/6935d734-fd84-800f-9755-290902b8cee8
Summary:
This commit performs a major cleanup and modernization of the installation pipeline:
1. Introduced a new capability-detection subsystem:
- Capabilities (python-runtime, make-install, nix-flake) are detected per installer/layer.
- Installers run only when they add new capabilities.
- Prevents duplicated work such as Python installers running when Nix already provides the runtime.
2. Removed deprecated pkgmgr.yml manifest installer:
- Dependency resolution is now delegated entirely to real package managers (Nix, pip, make, distro build tools).
- Simplifies layering and avoids unnecessary recursion.
3. Reworked OS-specific installers:
- Arch PKGBUILD now uses 'makepkg --syncdeps --cleanbuild --install --noconfirm'.
- Debian installer now builds proper .deb packages via dpkg-buildpackage + installs them.
- RPM installer now builds packages using rpmbuild and installs them via rpm.
4. Switched from remote GitHub flakes to local-flake execution:
- Wrapper now executes: nix run /usr/lib/package-manager#pkgmgr
- Avoids lock-file write attempts and improves reliability in CI.
5. Added bash -i based integration test:
- Correctly sources ~/.bashrc and evaluates alias + venv activation.
- ‘pkgmgr --help’ is now printed for debugging without failing tests.
6. Updated unit tests across all installers:
- Removed references to manifest installer.
- Adjusted expectations for new behaviors (makepkg, dpkg-buildpackage, rpmbuild).
- Added capability subsystem tests.
7. Improved flake.nix packaging logic:
- The entire project source tree is copied into the runtime closure.
- pkgmgr wrapper now executes runpy inside the packaged directory.
Together, these changes create a predictable, layered, capability-driven installer pipeline with consistent behavior across Arch, Debian, RPM, Nix, and Python layers.
2025-12-07 20:36:39 +01:00
|
|
|
def pkgmgr_help_debug() -> None:
|
|
|
|
|
"""
|
|
|
|
|
Run `pkgmgr --help` after installation *inside an interactive bash shell*,
|
|
|
|
|
print its output and return code, but never fail the test.
|
|
|
|
|
|
|
|
|
|
Reason:
|
|
|
|
|
- The installer adds venv/alias setup into shell rc files (~/.bashrc, ~/.zshrc)
|
|
|
|
|
- Those changes are only applied in a new interactive shell session.
|
|
|
|
|
"""
|
|
|
|
|
print("\n--- PKGMGR HELP (after installation, via bash -i) ---")
|
|
|
|
|
|
|
|
|
|
# Simulate a fresh interactive bash, so ~/.bashrc gets sourced
|
|
|
|
|
proc = subprocess.run(
|
|
|
|
|
["bash", "-i", "-c", "pkgmgr --help"],
|
|
|
|
|
capture_output=True,
|
|
|
|
|
text=True,
|
|
|
|
|
check=False,
|
|
|
|
|
env=os.environ.copy(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
stdout = proc.stdout.strip()
|
|
|
|
|
stderr = proc.stderr.strip()
|
|
|
|
|
|
|
|
|
|
if stdout:
|
|
|
|
|
print(stdout)
|
|
|
|
|
if stderr:
|
|
|
|
|
print("stderr:", stderr)
|
|
|
|
|
|
|
|
|
|
print(f"returncode: {proc.returncode}")
|
|
|
|
|
print("--- END ---\n")
|
|
|
|
|
|
2025-12-09 17:54:41 +01:00
|
|
|
# Important: this is **debug-only**. Do NOT fail the test here.
|
|
|
|
|
# If you ever want to hard-assert on this, you can add an explicit
|
|
|
|
|
# assertion in the test method instead of here.
|
Refactor pkgmgr installers, introduce capability-based execution, and replace manifest layer
References:
- Current ChatGPT conversation: https://chatgpt.com/share/6935d6d7-0ae4-800f-988a-44a50c17ba48
- Extended discussion: https://chatgpt.com/share/6935d734-fd84-800f-9755-290902b8cee8
Summary:
This commit performs a major cleanup and modernization of the installation pipeline:
1. Introduced a new capability-detection subsystem:
- Capabilities (python-runtime, make-install, nix-flake) are detected per installer/layer.
- Installers run only when they add new capabilities.
- Prevents duplicated work such as Python installers running when Nix already provides the runtime.
2. Removed deprecated pkgmgr.yml manifest installer:
- Dependency resolution is now delegated entirely to real package managers (Nix, pip, make, distro build tools).
- Simplifies layering and avoids unnecessary recursion.
3. Reworked OS-specific installers:
- Arch PKGBUILD now uses 'makepkg --syncdeps --cleanbuild --install --noconfirm'.
- Debian installer now builds proper .deb packages via dpkg-buildpackage + installs them.
- RPM installer now builds packages using rpmbuild and installs them via rpm.
4. Switched from remote GitHub flakes to local-flake execution:
- Wrapper now executes: nix run /usr/lib/package-manager#pkgmgr
- Avoids lock-file write attempts and improves reliability in CI.
5. Added bash -i based integration test:
- Correctly sources ~/.bashrc and evaluates alias + venv activation.
- ‘pkgmgr --help’ is now printed for debugging without failing tests.
6. Updated unit tests across all installers:
- Removed references to manifest installer.
- Adjusted expectations for new behaviors (makepkg, dpkg-buildpackage, rpmbuild).
- Added capability subsystem tests.
7. Improved flake.nix packaging logic:
- The entire project source tree is copied into the runtime closure.
- pkgmgr wrapper now executes runpy inside the packaged directory.
Together, these changes create a predictable, layered, capability-driven installer pipeline with consistent behavior across Arch, Debian, RPM, Nix, and Python layers.
2025-12-07 20:36:39 +01:00
|
|
|
|
|
|
|
|
|
2025-12-06 17:47:46 +01:00
|
|
|
class TestIntegrationInstalPKGMGRShallow(unittest.TestCase):
|
|
|
|
|
def test_install_pkgmgr_self_install(self) -> None:
|
2025-12-09 17:54:41 +01:00
|
|
|
"""
|
|
|
|
|
End-to-end test that runs "python main.py install pkgmgr ..." inside
|
|
|
|
|
the test container.
|
|
|
|
|
|
|
|
|
|
We isolate HOME into /tmp/pkgmgr-self-install so that:
|
|
|
|
|
- ~/.config/pkgmgr points to an isolated test config area
|
|
|
|
|
- ~/Repositories is owned by the current user inside the container
|
|
|
|
|
(avoiding Nix's 'repository path is not owned by current user' error)
|
|
|
|
|
"""
|
|
|
|
|
# Use a dedicated HOME for this test to avoid permission/ownership issues
|
|
|
|
|
temp_home = "/tmp/pkgmgr-self-install"
|
|
|
|
|
os.makedirs(temp_home, exist_ok=True)
|
2025-12-05 20:20:33 +01:00
|
|
|
|
|
|
|
|
original_argv = sys.argv
|
2025-12-09 17:54:41 +01:00
|
|
|
original_environ = os.environ.copy()
|
|
|
|
|
|
2025-12-05 20:20:33 +01:00
|
|
|
try:
|
2025-12-09 17:54:41 +01:00
|
|
|
# Isolate HOME so that ~ expands to /tmp/pkgmgr-self-install
|
|
|
|
|
os.environ["HOME"] = temp_home
|
|
|
|
|
|
|
|
|
|
# Optional: ensure XDG_* also use the temp HOME for extra isolation
|
|
|
|
|
os.environ.setdefault("XDG_CONFIG_HOME", os.path.join(temp_home, ".config"))
|
|
|
|
|
os.environ.setdefault("XDG_CACHE_HOME", os.path.join(temp_home, ".cache"))
|
|
|
|
|
os.environ.setdefault("XDG_DATA_HOME", os.path.join(temp_home, ".local", "share"))
|
|
|
|
|
|
|
|
|
|
# Debug before cleanup
|
|
|
|
|
nix_profile_list_debug("BEFORE CLEANUP")
|
|
|
|
|
|
|
|
|
|
# Cleanup: aggressively try to drop any pkgmgr/profile entries
|
|
|
|
|
remove_pkgmgr_from_nix_profile()
|
|
|
|
|
|
|
|
|
|
# Debug after cleanup
|
|
|
|
|
nix_profile_list_debug("AFTER CLEANUP")
|
|
|
|
|
|
2025-12-05 20:20:33 +01:00
|
|
|
sys.argv = [
|
2025-12-06 17:47:46 +01:00
|
|
|
"python",
|
2025-12-05 20:20:33 +01:00
|
|
|
"install",
|
|
|
|
|
"pkgmgr",
|
|
|
|
|
"--clone-mode",
|
|
|
|
|
"shallow",
|
|
|
|
|
"--no-verification",
|
|
|
|
|
]
|
2025-12-09 17:54:41 +01:00
|
|
|
|
|
|
|
|
# Run installation via main.py
|
2025-12-05 20:20:33 +01:00
|
|
|
runpy.run_module("main", run_name="__main__")
|
Refactor pkgmgr installers, introduce capability-based execution, and replace manifest layer
References:
- Current ChatGPT conversation: https://chatgpt.com/share/6935d6d7-0ae4-800f-988a-44a50c17ba48
- Extended discussion: https://chatgpt.com/share/6935d734-fd84-800f-9755-290902b8cee8
Summary:
This commit performs a major cleanup and modernization of the installation pipeline:
1. Introduced a new capability-detection subsystem:
- Capabilities (python-runtime, make-install, nix-flake) are detected per installer/layer.
- Installers run only when they add new capabilities.
- Prevents duplicated work such as Python installers running when Nix already provides the runtime.
2. Removed deprecated pkgmgr.yml manifest installer:
- Dependency resolution is now delegated entirely to real package managers (Nix, pip, make, distro build tools).
- Simplifies layering and avoids unnecessary recursion.
3. Reworked OS-specific installers:
- Arch PKGBUILD now uses 'makepkg --syncdeps --cleanbuild --install --noconfirm'.
- Debian installer now builds proper .deb packages via dpkg-buildpackage + installs them.
- RPM installer now builds packages using rpmbuild and installs them via rpm.
4. Switched from remote GitHub flakes to local-flake execution:
- Wrapper now executes: nix run /usr/lib/package-manager#pkgmgr
- Avoids lock-file write attempts and improves reliability in CI.
5. Added bash -i based integration test:
- Correctly sources ~/.bashrc and evaluates alias + venv activation.
- ‘pkgmgr --help’ is now printed for debugging without failing tests.
6. Updated unit tests across all installers:
- Removed references to manifest installer.
- Adjusted expectations for new behaviors (makepkg, dpkg-buildpackage, rpmbuild).
- Added capability subsystem tests.
7. Improved flake.nix packaging logic:
- The entire project source tree is copied into the runtime closure.
- pkgmgr wrapper now executes runpy inside the packaged directory.
Together, these changes create a predictable, layered, capability-driven installer pipeline with consistent behavior across Arch, Debian, RPM, Nix, and Python layers.
2025-12-07 20:36:39 +01:00
|
|
|
|
2025-12-09 17:54:41 +01:00
|
|
|
# After successful installation: run `pkgmgr --help` for debug
|
Refactor pkgmgr installers, introduce capability-based execution, and replace manifest layer
References:
- Current ChatGPT conversation: https://chatgpt.com/share/6935d6d7-0ae4-800f-988a-44a50c17ba48
- Extended discussion: https://chatgpt.com/share/6935d734-fd84-800f-9755-290902b8cee8
Summary:
This commit performs a major cleanup and modernization of the installation pipeline:
1. Introduced a new capability-detection subsystem:
- Capabilities (python-runtime, make-install, nix-flake) are detected per installer/layer.
- Installers run only when they add new capabilities.
- Prevents duplicated work such as Python installers running when Nix already provides the runtime.
2. Removed deprecated pkgmgr.yml manifest installer:
- Dependency resolution is now delegated entirely to real package managers (Nix, pip, make, distro build tools).
- Simplifies layering and avoids unnecessary recursion.
3. Reworked OS-specific installers:
- Arch PKGBUILD now uses 'makepkg --syncdeps --cleanbuild --install --noconfirm'.
- Debian installer now builds proper .deb packages via dpkg-buildpackage + installs them.
- RPM installer now builds packages using rpmbuild and installs them via rpm.
4. Switched from remote GitHub flakes to local-flake execution:
- Wrapper now executes: nix run /usr/lib/package-manager#pkgmgr
- Avoids lock-file write attempts and improves reliability in CI.
5. Added bash -i based integration test:
- Correctly sources ~/.bashrc and evaluates alias + venv activation.
- ‘pkgmgr --help’ is now printed for debugging without failing tests.
6. Updated unit tests across all installers:
- Removed references to manifest installer.
- Adjusted expectations for new behaviors (makepkg, dpkg-buildpackage, rpmbuild).
- Added capability subsystem tests.
7. Improved flake.nix packaging logic:
- The entire project source tree is copied into the runtime closure.
- pkgmgr wrapper now executes runpy inside the packaged directory.
Together, these changes create a predictable, layered, capability-driven installer pipeline with consistent behavior across Arch, Debian, RPM, Nix, and Python layers.
2025-12-07 20:36:39 +01:00
|
|
|
pkgmgr_help_debug()
|
2025-12-09 17:54:41 +01:00
|
|
|
|
2025-12-05 20:20:33 +01:00
|
|
|
finally:
|
|
|
|
|
sys.argv = original_argv
|
2025-12-09 17:54:41 +01:00
|
|
|
# Restore full environment
|
|
|
|
|
os.environ.clear()
|
|
|
|
|
os.environ.update(original_environ)
|
2025-12-05 20:20:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|