Every ISO bundles the cn profile; the first-screen pick decides. --region cn only preselects China and names the artifact. The region value is cn, the cn timezone is preselected when China is chosen, and the profile packages and ArchLinuxCN keyring reach the target only for China.
119 lines
5.6 KiB
Python
119 lines
5.6 KiB
Python
"""Local-source installs pin the packages the ISO built from the checkouts."""
|
|
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import types
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(ROOT / "configs/airootfs/usr/share/omarchy-iso"))
|
|
sys.modules.setdefault(
|
|
"orchestrator.archinstall_adapter",
|
|
types.ModuleType("orchestrator.archinstall_adapter"),
|
|
)
|
|
from orchestrator import phases_impl # noqa: E402
|
|
|
|
LINE = "IgnorePkg = omarchy-dev omarchy-settings-dev rime-ice-installer"
|
|
CONF = "[options]\nHoldPkg = pacman glibc\n\n[core]\nInclude = /etc/pacman.d/mirrorlist\n"
|
|
|
|
|
|
class PinLocalPackagesTest(unittest.TestCase):
|
|
def run_pin(self, root: Path, *, pinned: bool, defer: bool = False):
|
|
(root / "etc").mkdir()
|
|
(root / "etc/pacman.conf").write_text(CONF)
|
|
pinned_file = root / "pinned-packages"
|
|
if pinned:
|
|
pinned_file.write_text("omarchy-dev\nomarchy-settings-dev\nrime-ice-installer\n")
|
|
ctx = types.SimpleNamespace(target=root, username="test", defer_provisioning=defer)
|
|
with mock.patch.object(phases_impl, "PINNED_PACKAGES", pinned_file), \
|
|
mock.patch.object(phases_impl.subprocess, "run") as run:
|
|
phases_impl.pin_local_packages(ctx)
|
|
phases_impl.pin_local_packages(ctx)
|
|
return run
|
|
|
|
def test_pins_once_and_installs_refresh_hook(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
run = self.run_pin(root, pinned=True)
|
|
self.assertEqual((root / "etc/pacman.conf").read_text(), CONF.replace("[options]\n", f"[options]\n{LINE}\n"))
|
|
hook = root / "home/test/.config/omarchy/hooks/pre-refresh-pacman.d/pin-local-packages"
|
|
self.assertIn(f'line="{LINE}"', hook.read_text())
|
|
self.assertTrue(hook.stat().st_mode & 0o111)
|
|
guard = (root / "etc/pacman.d/hooks/00-omarchy-pin-local-builds.hook").read_text()
|
|
for package in ("omarchy-dev", "omarchy-settings-dev", "rime-ice-installer"):
|
|
self.assertIn(f"Target = {package}\n", guard)
|
|
self.assertIn("AbortOnFail", guard)
|
|
skel = root / "etc/skel/.config/omarchy/hooks/pre-refresh-pacman.d/pin-local-packages"
|
|
self.assertEqual(skel.read_text(), hook.read_text())
|
|
run.assert_called_with(
|
|
["arch-chroot", str(root), "chown", "-R", "test:test", "/home/test/.config/omarchy/hooks"],
|
|
check=True,
|
|
)
|
|
|
|
def test_hook_restores_the_pin_after_a_refresh(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
self.run_pin(root, pinned=True)
|
|
hook = root / "home/test/.config/omarchy/hooks/pre-refresh-pacman.d/pin-local-packages"
|
|
conf = root / "pacman.conf"
|
|
conf.write_text(CONF)
|
|
script = hook.read_text().replace("/etc/pacman.conf", str(conf)).replace("sudo ", "")
|
|
for _ in range(2):
|
|
subprocess.run(["bash", "-c", script], check=True)
|
|
self.assertEqual(conf.read_text(), CONF.replace("[options]\n", f"[options]\n{LINE}\n"))
|
|
|
|
def test_deferred_install_stages_the_hook_for_the_first_owner(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
run = self.run_pin(root, pinned=True, defer=True)
|
|
self.assertIn(LINE, (root / "etc/pacman.conf").read_text())
|
|
self.assertTrue((root / "etc/pacman.d/hooks/00-omarchy-pin-local-builds.hook").exists())
|
|
self.assertTrue((root / "etc/skel/.config/omarchy/hooks/pre-refresh-pacman.d/pin-local-packages").exists())
|
|
self.assertFalse((root / "home").exists())
|
|
run.assert_not_called()
|
|
|
|
def test_published_builds_stay_unpinned(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
self.run_pin(root, pinned=False)
|
|
self.assertEqual((root / "etc/pacman.conf").read_text(), CONF)
|
|
self.assertFalse((root / "etc/pacman.d").exists())
|
|
|
|
|
|
class RuntimePackagesTest(unittest.TestCase):
|
|
def runtime_packages(self, pinned: str | None) -> list[str]:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
pinned_file = root / "pinned-packages"
|
|
if pinned is not None:
|
|
pinned_file.write_text(pinned)
|
|
base = root / "omarchy-base.packages"
|
|
base.write_text("# base\nfcitx5\ngit\n")
|
|
real_path = phases_impl.Path
|
|
|
|
def path(arg, *rest):
|
|
if arg == "/usr/share/omarchy-iso/omarchy-base.packages":
|
|
return base
|
|
return real_path(arg, *rest)
|
|
|
|
with mock.patch.object(phases_impl, "PINNED_PACKAGES", pinned_file), \
|
|
mock.patch.object(phases_impl, "Path", side_effect=path), \
|
|
mock.patch.object(phases_impl, "_early_packages", return_value=["git"]), \
|
|
mock.patch.object(phases_impl, "_package_targets", return_value={
|
|
"runtime": "omarchy-dev", "settings": "omarchy-settings-dev", "nvim": "omarchy-nvim"}):
|
|
return phases_impl._runtime_package_list(types.SimpleNamespace(omarchy_install={"region": "global"}))
|
|
|
|
def test_local_builds_install_on_every_region(self):
|
|
packages = self.runtime_packages("omarchy-dev\nomarchy-settings-dev\nrime-ice-installer\n")
|
|
self.assertEqual(packages, ["omarchy-dev", "fcitx5", "rime-ice-installer"])
|
|
|
|
def test_published_builds_add_nothing(self):
|
|
self.assertEqual(self.runtime_packages(None), ["omarchy-dev", "fcitx5"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|