*fix(nix): resolve nix profile conflicts without numeric indices and fix update pkgmgr system test*
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 / linter-shell (push) Has been cancelled
Mark stable commit / linter-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
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 / linter-shell (push) Has been cancelled
Mark stable commit / linter-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
* Switch conflict handling from index-based removal to token-based removal (*nix profile remove <name>*) for newer nix versions * Add robust parsing of *nix profile list --json* with normalization and heuristics for output/name matching * Detect at runtime whether numeric profile indices are supported and fall back automatically when they are not * Ensure *pkgmgr* / *package-manager* flake outputs are correctly identified and cleaned up during reinstall * Fix failing E2E test *test_update_pkgmgr_shallow_pkgmgr_with_system* by reliably removing conflicting profile entries before reinstall https://chatgpt.com/share/693efae5-b8bc-800f-94e3-28c93b74ed7b
This commit is contained in:
63
tests/integration/test_nix_profile_list_json.py
Normal file
63
tests/integration/test_nix_profile_list_json.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class FakeRunResult:
|
||||
"""
|
||||
Mimics your runner returning a structured result object.
|
||||
"""
|
||||
returncode: int
|
||||
stdout: str
|
||||
stderr: str = ""
|
||||
|
||||
|
||||
class FakeRunner:
|
||||
"""
|
||||
Minimal runner stub: returns exactly what we configure.
|
||||
"""
|
||||
def __init__(self, result):
|
||||
self._result = result
|
||||
|
||||
def run(self, ctx, cmd: str, allow_failure: bool = False):
|
||||
return self._result
|
||||
|
||||
|
||||
class TestE2ENixProfileListJsonParsing(unittest.TestCase):
|
||||
"""
|
||||
This test verifies that NixProfileInspector can parse `nix profile list --json`
|
||||
regardless of whether the CommandRunner returns:
|
||||
- raw stdout string, OR
|
||||
- a RunResult-like object with a `.stdout` attribute.
|
||||
"""
|
||||
|
||||
def test_list_json_accepts_raw_string(self) -> None:
|
||||
from pkgmgr.actions.install.installers.nix.profile import NixProfileInspector
|
||||
|
||||
payload = {"elements": {"pkgmgr-1": {"attrPath": "packages.x86_64-linux.pkgmgr"}}}
|
||||
raw = json.dumps(payload)
|
||||
|
||||
runner = FakeRunner(raw)
|
||||
inspector = NixProfileInspector()
|
||||
|
||||
data = inspector.list_json(ctx=None, runner=runner)
|
||||
self.assertEqual(data["elements"]["pkgmgr-1"]["attrPath"], "packages.x86_64-linux.pkgmgr")
|
||||
|
||||
def test_list_json_accepts_runresult_object(self) -> None:
|
||||
from pkgmgr.actions.install.installers.nix.profile import NixProfileInspector
|
||||
|
||||
payload = {"elements": {"pkgmgr-1": {"attrPath": "packages.x86_64-linux.pkgmgr"}}}
|
||||
raw = json.dumps(payload)
|
||||
|
||||
runner = FakeRunner(FakeRunResult(returncode=0, stdout=raw))
|
||||
inspector = NixProfileInspector()
|
||||
|
||||
data = inspector.list_json(ctx=None, runner=runner)
|
||||
self.assertEqual(data["elements"]["pkgmgr-1"]["attrPath"], "packages.x86_64-linux.pkgmgr")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user