aboutsummaryrefslogtreecommitdiff
path: root/tests/installer-steps
diff options
context:
space:
mode:
Diffstat (limited to 'tests/installer-steps')
-rw-r--r--tests/installer-steps/test_configure_openai_chatgpt_repo.py324
-rw-r--r--tests/installer-steps/test_install_gnome_keyring_fix.py209
2 files changed, 533 insertions, 0 deletions
diff --git a/tests/installer-steps/test_configure_openai_chatgpt_repo.py b/tests/installer-steps/test_configure_openai_chatgpt_repo.py
new file mode 100644
index 0000000..cb0e84b
--- /dev/null
+++ b/tests/installer-steps/test_configure_openai_chatgpt_repo.py
@@ -0,0 +1,324 @@
+"""Test configure_openai_chatgpt_repo — OpenAI's signed pacman repo for ChatGPT.
+
+OpenAI ships the ChatGPT (Codex) desktop app for Arch as chatgpt-bin from
+its own signed pacman repository. Its install-arch.sh pins the repository
+signing-key fingerprint, locally signs the key into the pacman keyring,
+writes /etc/pacman.d/openai-chatgpt.conf and adds an Include line to
+pacman.conf; ratio and velox were set up that way on 2026-10-11. The step
+reproduces exactly that configuration so a re-run on those machines is a
+no-op and the app rides normal pacman upgrades under OpenAI's signature.
+The AUR repackage of the same binary (chatgpt-desktop) would conflict with
+chatgpt-bin on any machine already using the repo, so it is not used.
+
+A half-configured repository is worse than none: with the Include in place
+and the key untrusted, SigLevel TrustedOnly makes every later pacman call
+fail on the invalid database. So an untrusted key (fingerprint mismatch or
+failed download) must import nothing and leave pacman.conf untouched.
+
+The pin is on the primary key's fingerprint alone. pacman-key --lsign-key
+resolves a subkey fingerprint to its primary, so a bundle whose subkey or
+second primary carries the pinned fingerprint must be rejected too.
+
+Method: sed-extract configure_openai_chatgpt_repo from the real `archsetup`,
+point it at a temp pacman.conf and repo drop-in, and replace curl, gpg,
+pacman-key and pacman with recorders driven by environment switches.
+
+ python3 -m unittest tests.installer-steps.test_configure_openai_chatgpt_repo
+"""
+
+import os
+import re
+import stat
+import subprocess
+import tempfile
+import textwrap
+import unittest
+
+REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
+ARCHSETUP = os.path.join(REPO_ROOT, "archsetup")
+
+FPR = "3BFA0E4AE8B8CC16A2D9BA684A3B4A566C4660E4"
+KEY_URL = "https://persistent.oaistatic.com/codex-app-prod/linux/repository-signing-key.gpg"
+SERVER = "https://persistent.oaistatic.com/codex-app-prod/linux/arch/$arch"
+BASE_CONF = "[core]\nInclude = /etc/pacman.d/mirrorlist\n"
+
+# Recorders. Every fake appends its argv to $MARKER; the pacman fake also
+# records whether the Include line is already in pacman.conf at call time,
+# which is how the tests see that -Sy ran after the repo was wired in.
+STUBS = r"""
+logfile=/dev/null
+action=""
+display() { :; }
+backup_system_file() { :; }
+error_warn() { echo "WARN: $1"; return 1; }
+pacman-key() {
+ echo "PACMAN_KEY: $*" >> "$MARKER"
+ case "$1" in
+ --list-keys) [ "$KEY_PRESENT" = 1 ] ;;
+ *) return 0 ;;
+ esac
+}
+curl() {
+ echo "CURL: $*" >> "$MARKER"
+ [ "$CURL_FAIL" = 1 ] && return 22
+ local out=""
+ while [ $# -gt 0 ]; do
+ case "$1" in -o) out="$2"; shift ;; esac
+ shift
+ done
+ [ -n "$out" ] && printf 'FAKE KEY\n' > "$out"
+ return 0
+}
+gpg() {
+ echo "GPG: $*" >> "$MARKER"
+ case " $* " in
+ *" --show-keys "*)
+ printf 'pub:u:4096:1:4A3B4A566C4660E4:1754362069:::u:::scSC::::::23::0:\n'
+ printf 'fpr:::::::::%s:\n' "$SERVED_FPR"
+ printf 'uid:u::::1754362069::ABC::Codex Linux Repository::::::::::0:\n'
+ if [ -n "$SERVED_SUBKEY_FPR" ]; then
+ printf 'sub:u:4096:1:0123456789ABCDEF:1754362069::::::e::::::23:\n'
+ printf 'fpr:::::::::%s:\n' "$SERVED_SUBKEY_FPR"
+ fi
+ if [ -n "$SERVED_SECOND_PUB_FPR" ]; then
+ printf 'pub:u:4096:1:FEDCBA9876543210:1754362069:::u:::scSC::::::23::0:\n'
+ printf 'fpr:::::::::%s:\n' "$SERVED_SECOND_PUB_FPR"
+ printf 'uid:u::::1754362069::DEF::Somebody Else::::::::::0:\n'
+ fi
+ ;;
+ esac
+ return 0
+}
+pacman() {
+ local n
+ n=$(grep -cxF "Include = $REPO_CONF" "$PACMAN_CONF" 2>/dev/null)
+ echo "PACMAN: $* include=$n" >> "$MARKER"
+ return 0
+}
+"""
+
+
+def paths(d):
+ return (os.path.join(d, "pacman.conf"),
+ os.path.join(d, "pacman.d", "openai-chatgpt.conf"),
+ os.path.join(d, "calls"))
+
+
+def run(d, *, key_present=False, served_fpr=FPR, served_subkey_fpr="",
+ served_second_pub_fpr="", curl_fail=False, pacman_conf_body=BASE_CONF):
+ pacman_conf, repo_conf, marker = paths(d)
+ if pacman_conf_body is not None and not os.path.exists(pacman_conf):
+ with open(pacman_conf, "w") as f:
+ f.write(pacman_conf_body)
+ script = STUBS + textwrap.dedent(f"""\
+ source <(sed -n '/^configure_openai_chatgpt_repo() {{/,/^}}/p' "{ARCHSETUP}")
+ configure_openai_chatgpt_repo "$PACMAN_CONF" "$REPO_CONF"
+ echo "RC=$?"
+ exit 0
+ """)
+ env = dict(os.environ, MARKER=marker, PACMAN_CONF=pacman_conf,
+ REPO_CONF=repo_conf, KEY_PRESENT="1" if key_present else "0",
+ SERVED_FPR=served_fpr, SERVED_SUBKEY_FPR=served_subkey_fpr,
+ SERVED_SECOND_PUB_FPR=served_second_pub_fpr,
+ CURL_FAIL="1" if curl_fail else "0")
+ return subprocess.run(["bash", "-c", script], capture_output=True,
+ text=True, timeout=10, env=env)
+
+
+def rc_of(r):
+ m = re.search(r"^RC=(\d+)$", r.stdout, re.M)
+ assert m, "no RC line in output: %r / %r" % (r.stdout, r.stderr)
+ return int(m.group(1))
+
+
+def read(path):
+ with open(path) as f:
+ return f.read()
+
+
+def calls(d):
+ marker = paths(d)[2]
+ return read(marker) if os.path.exists(marker) else ""
+
+
+class ConfigureOpenaiChatgptRepo(unittest.TestCase):
+ # ------------------------------------------------------------ normal ----
+ def test_writes_the_published_repo_definition(self):
+ with tempfile.TemporaryDirectory() as d:
+ r = run(d)
+ self.assertEqual(rc_of(r), 0)
+ _, repo_conf, _ = paths(d)
+ self.assertTrue(os.path.exists(repo_conf))
+ body = read(repo_conf)
+ self.assertIn("[openai-chatgpt]\n", body)
+ self.assertIn("SigLevel = Required DatabaseRequired TrustedOnly\n", body)
+ # $arch stays literal: pacman expands it, the shell must not.
+ self.assertIn(f"Server = {SERVER}\n", body)
+
+ def test_repo_definition_is_world_readable_not_writable(self):
+ with tempfile.TemporaryDirectory() as d:
+ run(d)
+ mode = stat.S_IMODE(os.stat(paths(d)[1]).st_mode)
+ self.assertEqual(mode, 0o644)
+
+ def test_adds_one_include_line_to_pacman_conf(self):
+ with tempfile.TemporaryDirectory() as d:
+ run(d)
+ pacman_conf, repo_conf, _ = paths(d)
+ body = read(pacman_conf)
+ self.assertTrue(body.startswith(BASE_CONF), body)
+ self.assertEqual(body.count(f"\nInclude = {repo_conf}\n"), 1)
+
+ def test_imports_and_locally_signs_the_pinned_key(self):
+ with tempfile.TemporaryDirectory() as d:
+ run(d)
+ c = calls(d)
+ self.assertIn(f" {KEY_URL}", c)
+ self.assertIn("GPG: ", c)
+ self.assertIn("--show-keys", c)
+ self.assertIn("PACMAN_KEY: --add ", c)
+ self.assertIn(f"PACMAN_KEY: --lsign-key {FPR}", c)
+
+ def test_refreshes_databases_after_the_include_is_in_place(self):
+ with tempfile.TemporaryDirectory() as d:
+ run(d)
+ self.assertIn("PACMAN: -Sy include=1", calls(d))
+
+ # ---------------------------------------------------------- boundary ----
+ def test_running_twice_leaves_one_include_and_the_same_files(self):
+ with tempfile.TemporaryDirectory() as d:
+ pacman_conf, repo_conf, _ = paths(d)
+ self.assertEqual(rc_of(run(d)), 0)
+ first_conf, first_repo = read(pacman_conf), read(repo_conf)
+ self.assertEqual(rc_of(run(d)), 0)
+ self.assertEqual(read(pacman_conf), first_conf)
+ self.assertEqual(read(repo_conf), first_repo)
+ self.assertEqual(first_conf.count("Include = " + repo_conf), 1)
+
+ def test_already_trusted_key_is_not_downloaded_or_added_again(self):
+ with tempfile.TemporaryDirectory() as d:
+ r = run(d, key_present=True)
+ self.assertEqual(rc_of(r), 0)
+ c = calls(d)
+ self.assertNotIn("CURL:", c)
+ self.assertNotIn("PACMAN_KEY: --add", c)
+ self.assertTrue(os.path.exists(paths(d)[1]))
+
+ def test_pacman_conf_without_trailing_newline_gets_its_own_line(self):
+ with tempfile.TemporaryDirectory() as d:
+ r = run(d, pacman_conf_body=BASE_CONF.rstrip("\n"))
+ self.assertEqual(rc_of(r), 0)
+ pacman_conf, repo_conf, _ = paths(d)
+ body = read(pacman_conf)
+ self.assertIn("Include = /etc/pacman.d/mirrorlist\n", body)
+ self.assertRegex(body, re.compile(rf"^Include = {re.escape(repo_conf)}$", re.M))
+
+ def test_existing_differing_repo_definition_is_kept_and_flagged(self):
+ with tempfile.TemporaryDirectory() as d:
+ pacman_conf, repo_conf, _ = paths(d)
+ os.makedirs(os.path.dirname(repo_conf))
+ custom = "[openai-chatgpt]\nSigLevel = Required\nServer = file:///srv/mirror\n"
+ with open(repo_conf, "w") as f:
+ f.write(custom)
+ r = run(d)
+ self.assertIn("WARN:", r.stdout)
+ self.assertEqual(read(repo_conf), custom)
+ # The repository is still configured, just by the user's file.
+ self.assertIn(f"\nInclude = {repo_conf}\n", read(pacman_conf))
+ self.assertEqual(rc_of(r), 0)
+
+ # ------------------------------------------------------------- error ----
+ def assert_nothing_configured(self, d, r):
+ pacman_conf, repo_conf, _ = paths(d)
+ c = calls(d)
+ self.assertIn("WARN:", r.stdout)
+ self.assertNotIn("PACMAN_KEY: --add", c)
+ self.assertNotIn("PACMAN_KEY: --lsign-key", c)
+ self.assertNotIn("PACMAN: -Sy", c)
+ self.assertFalse(os.path.exists(repo_conf))
+ self.assertEqual(read(pacman_conf), BASE_CONF)
+ self.assertNotEqual(rc_of(r), 0)
+
+ def test_fingerprint_mismatch_imports_nothing_and_touches_nothing(self):
+ with tempfile.TemporaryDirectory() as d:
+ r = run(d, served_fpr="DEADBEEF" * 5)
+ self.assert_nothing_configured(d, r)
+
+ def test_key_download_failure_imports_nothing_and_touches_nothing(self):
+ with tempfile.TemporaryDirectory() as d:
+ r = run(d, curl_fail=True)
+ self.assert_nothing_configured(d, r)
+
+ # The pin is on the PRIMARY key's fingerprint and nothing else. pacman-key
+ # --lsign-key resolves a subkey fingerprint to the primary that carries it,
+ # so a pin that a subkey or a second primary could satisfy would trust
+ # whatever key the bundle smuggled in beside the expected one.
+ def test_subkey_carrying_the_pinned_fingerprint_is_rejected(self):
+ with tempfile.TemporaryDirectory() as d:
+ r = run(d, served_fpr="DEADBEEF" * 5, served_subkey_fpr=FPR)
+ self.assert_nothing_configured(d, r)
+
+ def test_second_primary_carrying_the_pinned_fingerprint_is_rejected(self):
+ with tempfile.TemporaryDirectory() as d:
+ r = run(d, served_fpr="DEADBEEF" * 5, served_second_pub_fpr=FPR)
+ self.assert_nothing_configured(d, r)
+
+ def test_rogue_second_primary_beside_the_pinned_key_is_rejected(self):
+ with tempfile.TemporaryDirectory() as d:
+ r = run(d, served_fpr=FPR, served_second_pub_fpr="DEADBEEF" * 5)
+ self.assert_nothing_configured(d, r)
+
+ @unittest.skipUnless(os.geteuid() != 0, "root ignores file write bits")
+ def test_unwritable_pacman_conf_warns_and_reports_failure(self):
+ with tempfile.TemporaryDirectory() as d:
+ pacman_conf, _, _ = paths(d)
+ with open(pacman_conf, "w") as f:
+ f.write(BASE_CONF)
+ os.chmod(pacman_conf, 0o444)
+ try:
+ r = run(d)
+ self.assertIn("WARN:", r.stdout)
+ self.assertNotEqual(rc_of(r), 0)
+ self.assertNotIn("PACMAN: -Sy", calls(d))
+ finally:
+ os.chmod(pacman_conf, 0o644)
+
+
+class SupplementalSoftwareWiring(unittest.TestCase):
+ """chatgpt-bin is installed only once its repository is trusted."""
+
+ def run_step(self, repo_rc):
+ script = textwrap.dedent(f"""\
+ desktop_env=hyprland
+ display() {{ :; }}
+ run_task() {{ :; }}
+ mask_fwupd_passim() {{ :; }}
+ pacman_install() {{ echo "PACMAN_INSTALL: $1"; }}
+ aur_install() {{ echo "AUR_INSTALL: $1"; }}
+ configure_openai_chatgpt_repo() {{ echo "CONFIGURE_REPO"; return {repo_rc}; }}
+ source <(sed -n '/^supplemental_software() {{/,/^}}/p' "{ARCHSETUP}")
+ supplemental_software
+ """)
+ return subprocess.run(["bash", "-c", script], capture_output=True,
+ text=True, timeout=10)
+
+ def test_installs_chatgpt_bin_after_configuring_the_repo(self):
+ out = self.run_step(0).stdout
+ self.assertIn("CONFIGURE_REPO\n", out)
+ self.assertLess(out.index("CONFIGURE_REPO"),
+ out.index("PACMAN_INSTALL: chatgpt-bin"))
+
+ def test_skips_chatgpt_bin_when_the_repo_cannot_be_trusted(self):
+ out = self.run_step(1).stdout
+ self.assertNotIn("PACMAN_INSTALL: chatgpt-bin", out)
+ # The failure is local to the app; the rest of the step still runs.
+ self.assertIn("AUR_INSTALL: claude-desktop", out)
+ self.assertIn("AUR_INSTALL: freetube", out)
+
+ def test_does_not_also_pull_the_conflicting_aur_repackage(self):
+ out = self.run_step(0).stdout
+ self.assertNotIn("chatgpt-desktop", out)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/installer-steps/test_install_gnome_keyring_fix.py b/tests/installer-steps/test_install_gnome_keyring_fix.py
new file mode 100644
index 0000000..1a4115a
--- /dev/null
+++ b/tests/installer-steps/test_install_gnome_keyring_fix.py
@@ -0,0 +1,209 @@
+"""Tests for install_gnome_keyring_fix in the archsetup installer.
+
+gnome-keyring 51.1 (and 48 through 50) aborts when a Secret Service client's
+first OpenSession is dispatched before the daemon has created its per-client
+record. Every abort loses the unlocked state, so the next request pops the
+keyring password dialog; on ratio this fired three times a day once the
+ChatGPT desktop app's codex app-server started bursting keyring reads. The
+fix is upstream merge request !112 plus an alias-lifetime correction, carried
+as a patched rebuild of Arch's own package under packages/gnome-keyring in
+this repo (pkgrel 1.1). install_gnome_keyring_fix builds and installs it with
+makepkg as the user when the stock 1:51.1-1 is what is installed.
+
+Versioning is the whole contract. The rebuild sorts above stock 1:51.1-1 and
+below any future 1:51.1-2 or 51.2, so a normal pacman upgrade replaces it the
+moment Arch or upstream ships a fix, and the step must never pin or hold the
+package. When something newer than the rebuild is already installed, the fix
+is assumed upstream and the step skips with a warning so the assumption is
+visible rather than silent. When the rebuild itself is installed, the step is
+a no-op.
+
+These tests exercise the REAL function body, extracted from the `archsetup`
+script at run time. pacman, vercmp, makepkg and sudo are replaced by
+recorders driven by environment switches; the package directory is a temp
+copy of the real packages/gnome-keyring tree.
+
+Run from repo root:
+ python3 -m unittest tests.installer-steps.test_install_gnome_keyring_fix
+"""
+
+import os
+import re
+import shutil
+import subprocess
+import tempfile
+import unittest
+
+REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
+ARCHSETUP = os.path.join(REPO_ROOT, "archsetup")
+PACKAGE_DIR = os.path.join(REPO_ROOT, "packages", "gnome-keyring")
+
+STUBS = r"""
+logfile=/dev/null
+action=""
+username=tester
+display() { echo "DISPLAY: $*"; }
+pacman_install() { echo "PACMAN_INSTALL: $1" >> "$MARKER"; }
+error_warn() { echo "WARN:$1"; return 1; }
+# pacman -Q prints the installed version, or fails when INSTALLED is empty.
+pacman() {
+ echo "PACMAN: $*" >> "$MARKER"
+ case "$1" in
+ -Q) [ -n "$INSTALLED" ] && echo "gnome-keyring $INSTALLED" ;;
+ *) return 0 ;;
+ esac
+}
+# The real vercmp is used so the ordering under test is pacman's own.
+makepkg() {
+ echo "MAKEPKG: $* (pwd=$PWD)" >> "$MARKER"
+ [ "$MAKEPKG_FAILS" = 1 ] && return 2
+ return 0
+}
+# sudo -u user cmd... runs cmd in place; the recorder notes the user.
+sudo() {
+ echo "SUDO: $*" >> "$MARKER"
+ shift 2
+ "$@"
+}
+safe_rm_rf() { rm -rf "$1"; }
+# chown needs root; the tests only care that the copy was staged.
+chown() { echo "CHOWN: $*" >> "$MARKER"; }
+"""
+
+
+def run(pkg_dir, installed, makepkg_fails=False, source_dir=None):
+ marker = tempfile.NamedTemporaryFile(prefix="keyring-fix-", delete=False)
+ marker.close()
+ source_dir = source_dir or tempfile.mkdtemp(prefix="keyring-src-")
+ script = (
+ STUBS
+ + "source <(sed -n '/^install_gnome_keyring_fix() {/,/^}/p' \"%s\")\n"
+ + 'user_archsetup_dir="%s"\n'
+ + 'source_dir="%s"\n'
+ + "install_gnome_keyring_fix\n"
+ + 'echo "RC=$?"\n'
+ ) % (ARCHSETUP, pkg_dir, source_dir)
+ env = dict(os.environ, MARKER=marker.name, INSTALLED=installed,
+ MAKEPKG_FAILS="1" if makepkg_fails else "0")
+ result = subprocess.run(["bash", "-c", script], capture_output=True,
+ text=True, timeout=30, env=env)
+ with open(marker.name) as f:
+ calls = f.read().splitlines()
+ os.remove(marker.name)
+ return result, calls, source_dir
+
+
+class InstallGnomeKeyringFix(unittest.TestCase):
+ def setUp(self):
+ # A fake archsetup checkout holding a copy of the real package tree.
+ self.checkout = tempfile.mkdtemp(prefix="archsetup-checkout-")
+ self.addCleanup(shutil.rmtree, self.checkout, ignore_errors=True)
+ shutil.copytree(PACKAGE_DIR, os.path.join(self.checkout, "packages", "gnome-keyring"))
+ self.source_dir = tempfile.mkdtemp(prefix="keyring-src-")
+ self.addCleanup(shutil.rmtree, self.source_dir, ignore_errors=True)
+
+ def _run(self, installed, **kw):
+ return run(self.checkout, installed, source_dir=self.source_dir, **kw)
+
+ @staticmethod
+ def _makepkg_calls(calls):
+ return [c for c in calls if c.startswith("MAKEPKG:")]
+
+ # ---------------------------------------------------------- normal ----
+ def test_stock_51_1_gets_the_rebuild(self):
+ result, calls, _ = self._run("1:51.1-1")
+ self.assertEqual(len(self._makepkg_calls(calls)), 1, calls)
+ self.assertIn("RC=0", result.stdout)
+ self.assertNotIn("WARN:", result.stdout)
+
+ def test_builds_as_the_user_with_syncdeps_and_install(self):
+ _, calls, _ = self._run("1:51.1-1")
+ self.assertTrue(any(c.startswith("SUDO: -u tester makepkg") for c in calls), calls)
+ makepkg = self._makepkg_calls(calls)[0]
+ self.assertIn("--noconfirm", makepkg)
+ # -s (sync makedepends) and -i (install), spelled separately or combined.
+ short = "".join(t[1:] for t in makepkg.split() if re.fullmatch(r"-[a-zA-Z]+", t))
+ self.assertIn("s", short, makepkg)
+ self.assertIn("i", short, makepkg)
+
+ def test_builds_from_a_user_owned_copy_not_the_checkout(self):
+ # makepkg writes into its directory; the checkout must stay clean.
+ _, calls, _ = self._run("1:51.1-1")
+ makepkg = self._makepkg_calls(calls)[0]
+ self.assertIn("pwd=" + self.source_dir, makepkg)
+ self.assertNotIn("pwd=" + self.checkout, makepkg)
+ self.assertTrue(os.path.exists(os.path.join(self.source_dir, "gnome-keyring", "PKGBUILD")))
+
+ def test_older_stock_releases_also_get_the_rebuild(self):
+ # 50.0 carries the same bug; the rebuild is 51.1 so it is an upgrade.
+ _, calls, _ = self._run("1:50.0-1")
+ self.assertEqual(len(self._makepkg_calls(calls)), 1)
+
+ # -------------------------------------------------------- boundary ----
+ def test_rebuild_already_installed_is_a_noop(self):
+ result, calls, _ = self._run("1:51.1-1.1")
+ self.assertEqual(self._makepkg_calls(calls), [])
+ self.assertIn("RC=0", result.stdout)
+ self.assertNotIn("WARN:", result.stdout)
+
+ def test_newer_package_skips_visibly_without_counting_an_error(self):
+ for newer in ("1:51.1-2", "1:51.2-1", "1:52.0-1"):
+ with self.subTest(installed=newer):
+ result, calls, _ = self._run(newer)
+ self.assertEqual(self._makepkg_calls(calls), [], newer)
+ self.assertIn("newer than the rebuild", result.stdout,
+ "a newer package means the fix is assumed upstream; say so")
+ self.assertNotIn("WARN:", result.stdout,
+ "a deliberate skip must not count as an installer error")
+ self.assertIn("RC=0", result.stdout)
+
+ def test_rerun_after_success_does_not_rebuild(self):
+ _, calls, _ = self._run("1:51.1-1")
+ self.assertEqual(len(self._makepkg_calls(calls)), 1)
+ _, calls, _ = self._run("1:51.1-1.1")
+ self.assertEqual(self._makepkg_calls(calls), [])
+
+ def test_missing_package_installs_stock_first_then_builds(self):
+ # With no gnome-keyring present, stock is installed as the baseline
+ # and the rebuild then upgrades it; both happen in that order.
+ result, calls, _ = self._run("")
+ self.assertEqual(len(self._makepkg_calls(calls)), 1)
+ stock = [i for i, c in enumerate(calls) if c.startswith("PACMAN_INSTALL: gnome-keyring")]
+ build = [i for i, c in enumerate(calls) if c.startswith("MAKEPKG:")]
+ self.assertEqual(len(stock), 1, calls)
+ self.assertLess(stock[0], build[0], "stock install must precede the build")
+ self.assertIn("RC=0", result.stdout)
+
+ def test_rerun_with_rebuild_installed_never_touches_stock(self):
+ # pacman's --needed only skips an equal version, so a stock install
+ # ahead of the rebuild would downgrade it on every re-run. The step
+ # must not call the stock install at all once anything is installed.
+ for installed in ("1:51.1-1.1", "1:51.1-1", "1:51.2-1"):
+ with self.subTest(installed=installed):
+ _, calls, _ = self._run(installed)
+ self.assertFalse(any(c.startswith("PACMAN_INSTALL:") for c in calls), calls)
+
+ # ----------------------------------------------------------- error ----
+ def test_failed_build_warns_and_leaves_stock_in_place(self):
+ result, calls, _ = self._run("1:51.1-1", makepkg_fails=True)
+ self.assertIn("WARN:", result.stdout)
+ self.assertNotIn("RC=0", result.stdout)
+ self.assertFalse(any(c.startswith("PACMAN: -U") for c in calls),
+ "nothing may be installed by hand after a failed build")
+
+ def test_missing_recipe_warns_instead_of_building(self):
+ shutil.rmtree(os.path.join(self.checkout, "packages", "gnome-keyring"))
+ result, calls, _ = self._run("1:51.1-1")
+ self.assertEqual(self._makepkg_calls(calls), [])
+ self.assertIn("WARN:", result.stdout)
+
+ def test_never_pins_or_holds_the_package(self):
+ # No IgnorePkg edit and no pacman -D hold: the next upstream fix must
+ # replace the rebuild on a normal upgrade.
+ _, calls, _ = self._run("1:51.1-1")
+ self.assertFalse(any("IgnorePkg" in c for c in calls))
+ self.assertFalse(any(c.startswith("PACMAN: -D") for c in calls))
+
+
+if __name__ == "__main__":
+ unittest.main()