Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Cache browser OS packages so slow apt mirrors stop E2E
rcourtmand2ac07bccf52
diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.ymlindex 3d8ccfb0d5..95e511f894 100644--- a/.github/workflows/test-e2e.yml+++ b/.github/workflows/test-e2e.yml@@ -14,6 +14,8 @@ on:- '.github/workflows/test-e2e.yml'- 'scripts/playwright-apt.conf'- 'scripts/tests/test_playwright_acquisition.py'+ - 'scripts/browser_os_packages.py'+ - 'scripts/tests/test_browser_os_packages.py'- 'scripts/e2e_test_images.py'- 'scripts/tests/test_e2e_test_images.py'- 'scripts/collect_e2e_container_logs.py'@@ -34,6 +36,8 @@ on:- '.github/workflows/test-e2e.yml'- 'scripts/playwright-apt.conf'- 'scripts/tests/test_playwright_acquisition.py'+ - 'scripts/browser_os_packages.py'+ - 'scripts/tests/test_browser_os_packages.py'- 'scripts/e2e_test_images.py'- 'scripts/tests/test_e2e_test_images.py'- 'scripts/collect_e2e_container_logs.py'@@ -107,6 +111,9 @@ jobs:- name: Validate browser dependency acquisition policyrun: python3 scripts/tests/test_playwright_acquisition.py+ - name: Validate verified browser OS package reuse+ run: python3 scripts/tests/test_browser_os_packages.py+- name: Set up Node.jsuses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0with:@@ -174,6 +181,25 @@ jobs:- name: Bound browser OS dependency acquisitionrun: sudo install -m 0644 scripts/playwright-apt.conf /etc/apt/apt.conf.d/99pulse-playwright-acquire+ # The browser OS packages (about 120 MB for Chromium plus WebKit) come+ # from the runner's Azure Ubuntu mirror, which since 22 October 2026+ # serves some runners at tens of kB/s (actions/runner-images#14823 and+ # #15040). Reuse the newest saved package set. apt would accept a cached+ # file on size alone, so scripts/browser_os_packages.py admits only files+ # whose SHA256 matches the freshly fetched signed index.+ - name: Restore browser OS packages+ id: browser-os-packages+ uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0+ with:+ path: ~/.cache/pulse-browser-os-packages+ key: browser-os-packages-${{ runner.os }}-chromium-${{ hashFiles('tests/integration/package-lock.json') }}-${{ github.run_id }}-${{ github.run_attempt }}+ restore-keys: |+ browser-os-packages-${{ runner.os }}-chromium-${{ hashFiles('tests/integration/package-lock.json') }}-+ browser-os-packages-${{ runner.os }}-chromium-++ - name: Admit verified browser OS packages+ run: python3 scripts/browser_os_packages.py seed "$HOME/.cache/pulse-browser-os-packages"+- name: Install locked dependenciesrun: |npm ci --prefix tests/integration@@ -184,6 +210,17 @@ jobs:timeout-minutes: 10working-directory: tests/integrationrun: npx playwright install --with-deps chromium++ - name: Collect browser OS packages+ id: browser-os-collect+ run: python3 scripts/browser_os_packages.py collect "$HOME/.cache/pulse-browser-os-packages"++ - name: Save browser OS packages+ if: steps.browser-os-collect.outputs.changed == 'true'+ uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0+ with:+ path: ~/.cache/pulse-browser-os-packages+ key: ${{ steps.browser-os-packages.outputs.cache-primary-key }}- name: Validate offline issuer boundariesworking-directory: tests/integrationrun: >-@@ -284,6 +321,25 @@ jobs:- name: Bound browser OS dependency acquisitionrun: sudo install -m 0644 scripts/playwright-apt.conf /etc/apt/apt.conf.d/99pulse-playwright-acquire+ # The browser OS packages (about 120 MB for Chromium plus WebKit) come+ # from the runner's Azure Ubuntu mirror, which since 22 October 2026+ # serves some runners at tens of kB/s (actions/runner-images#14823 and+ # #15040). Reuse the newest saved package set. apt would accept a cached+ # file on size alone, so scripts/browser_os_packages.py admits only files+ # whose SHA256 matches the freshly fetched signed index.+ - name: Restore browser OS packages+ id: browser-os-packages+ uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0+ with:+ path: ~/.cache/pulse-browser-os-packages+ key: browser-os-packages-${{ runner.os }}-chromium-webkit-${{ hashFiles('tests/integration/package-lock.json') }}-${{ github.run_id }}-${{ github.run_attempt }}+ restore-keys: |+ browser-os-packages-${{ runner.os }}-chromium-webkit-${{ hashFiles('tests/integration/package-lock.json') }}-+ browser-os-packages-${{ runner.os }}-chromium-webkit-++ - name: Admit verified browser OS packages+ run: python3 scripts/browser_os_packages.py seed "$HOME/.cache/pulse-browser-os-packages"+- name: Install Playwright dependencies# Chromium + WebKit requested 116 MB of authenticated OS packages in# the retained setup failure. Active downloads near 90 kB/s need over@@ -296,6 +352,17 @@ jobs:npm cinpx playwright install --with-deps chromium webkit+ - name: Collect browser OS packages+ id: browser-os-collect+ run: python3 scripts/browser_os_packages.py collect "$HOME/.cache/pulse-browser-os-packages"++ - name: Save browser OS packages+ if: steps.browser-os-collect.outputs.changed == 'true'+ uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0+ with:+ path: ~/.cache/pulse-browser-os-packages+ key: ${{ steps.browser-os-packages.outputs.cache-primary-key }}+- name: Install Pulse Account frontend dependenciesworking-directory: internal/cloudcp/portal/frontendrun: npm ci@@ -493,6 +560,25 @@ jobs:- name: Bound browser OS dependency acquisitionrun: sudo install -m 0644 scripts/playwright-apt.conf /etc/apt/apt.conf.d/99pulse-playwright-acquire+ # The browser OS packages (about 120 MB for Chromium plus WebKit) come+ # from the runner's Azure Ubuntu mirror, which since 22 October 2026+ # serves some runners at tens of kB/s (actions/runner-images#14823 and+ # #15040). Reuse the newest saved package set. apt would accept a cached+ # file on size alone, so scripts/browser_os_packages.py admits only files+ # whose SHA256 matches the freshly fetched signed index.+ - name: Restore browser OS packages+ id: browser-os-packages+ uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0+ with:+ path: ~/.cache/pulse-browser-os-packages+ key: browser-os-packages-${{ runner.os }}-chromium-${{ hashFiles('tests/integration/package-lock.json') }}-${{ github.run_id }}-${{ github.run_attempt }}+ restore-keys: |+ browser-os-packages-${{ runner.os }}-chromium-${{ hashFiles('tests/integration/package-lock.json') }}-+ browser-os-packages-${{ runner.os }}-chromium-++ - name: Admit verified browser OS packages+ run: python3 scripts/browser_os_packages.py seed "$HOME/.cache/pulse-browser-os-packages"+- name: Install Playwright dependenciestimeout-minutes: 10working-directory: tests/integration@@ -500,6 +586,17 @@ jobs:npm cinpx playwright install --with-deps chromium+ - name: Collect browser OS packages+ id: browser-os-collect+ run: python3 scripts/browser_os_packages.py collect "$HOME/.cache/pulse-browser-os-packages"++ - name: Save browser OS packages+ if: steps.browser-os-collect.outputs.changed == 'true'+ uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0+ with:+ path: ~/.cache/pulse-browser-os-packages+ key: ${{ steps.browser-os-packages.outputs.cache-primary-key }}+- name: Install Pulse Account frontend dependenciesworking-directory: internal/cloudcp/portal/frontendrun: npm cidiff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.mdindex f498f928a9..d476901b62 100644--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md@@ -8117,6 +8117,31 @@ dependency floor in `dependencySecurity.test.ts` drops with it. The lockfileloses only that package entry. Installer, artifact, signing, promotion androllback boundaries are unchanged.+Browser OS packages for the E2E jobs are cached between runs (23 October+2026). Each of the `offline-org-provisioning`, `e2e`, and `agent-registration`+jobs in `.github/workflows/test-e2e.yml` installs about 120 MB of Ubuntu+packages for Chromium and WebKit from the runner's Azure mirror. From+22 October some GitHub-hosted runners received them at tens of kB/s+(actions/runner-images#14823 and #15040), so installs that had taken under a+minute ran past their 10 and 30 minute budgets before any test started. The+jobs now restore the newest saved package set with `actions/cache/restore`+(v6.1.0, pinned by SHA) and admit it through `scripts/browser_os_packages.py`:+after a bounded `apt-get update`, a cached `.deb` reaches apt's archive+directory only when the SHA256 of the private copy it installs equals a signed+index value for the package, version, and architecture named by its filename.+That check is ours, because apt reuses an archive-directory file after+checking only its size.+After a successful install, and before any journey runs, the helper rebuilds+the cache from what apt holds and the job saves it under a run-unique key only+when the verified set changed, so new Ubuntu versions refresh the cache and an+empty or unchanged set is never saved. The `scripts/playwright-apt.conf`+transport bounds and install budgets are unchanged, and these jobs hold no+secrets or write tokens, which the workflow trust contract requires for any+cache. Proof: `scripts/tests/test_browser_os_packages.py`,+`scripts/tests/test_playwright_acquisition.py`, and+`scripts/tests/test_e2e_test_images.py`, which also pins that this cache can+never carry the E2E test images.+## Release-body updater ownership (30 September 2026)Each executable `/bin/update --version` example in a published body must carrydiff --git a/scripts/browser_os_packages.py b/scripts/browser_os_packages.pynew file mode 100644index 0000000000..5ea35b54ae--- /dev/null+++ b/scripts/browser_os_packages.py@@ -0,0 +1,218 @@+#!/usr/bin/env python3+"""Reuse verified browser OS packages across disposable E2E runners.++Since 22 October 2026 some GitHub-hosted runners download Ubuntu packages from+the Azure mirror at tens of kB/s, so the 120 MB Chromium and WebKit+dependency set can exceed the install budget before any test runs+(actions/runner-images#14823 and #15040). The E2E jobs keep the last package+set in an Actions cache instead.++apt reuses a file already in its archive directory after checking only its+size (apt 2.8 ``pkgAcqArchive::QueueNext``), so a restored file is admitted+only when its SHA256 equals the value in the freshly fetched, signed package+index. Package identity comes from the archive filename apt writes, never+from the untrusted file's contents.++ seed CACHE_DIR refresh the index, then copy verified cached packages+ into apt's archive directory+ collect CACHE_DIR replace CACHE_DIR with apt's current archives and set+ the step output changed=true|false+"""+from __future__ import annotations++import argparse+import hashlib+import os+import re+import shutil+import subprocess+import sys+import tempfile+from pathlib import Path+from urllib.parse import unquote++sys.path.insert(0, str(Path(__file__).resolve().parent))+from write_github_output import append_output # noqa: E402++ARCHIVES = Path("/var/cache/apt/archives")+PACKAGE_RE = re.compile(r"^[a-z0-9][a-z0-9+.-]+$")+VERSION_RE = re.compile(r"^[0-9A-Za-z.+~:-]+$")+ARCH_RE = re.compile(r"^[a-z0-9-]+$")+QUERY_BATCH = 50++Identity = tuple[str, str, str]+++def parse_archive_name(name: str) -> Identity | None:+ """Return (package, version, architecture) for an apt archive filename.++ apt stores ``name_version_arch.deb`` with ``_`` and ``:`` percent-encoded+ inside each part, so the version's epoch appears as ``%3a``.+ """+ if not name.endswith(".deb"):+ return None+ parts = name[: -len(".deb")].split("_")+ if len(parts) != 3:+ return None+ package, version, arch = (unquote(part) for part in parts)+ if not (PACKAGE_RE.fullmatch(package) and VERSION_RE.fullmatch(version) and ARCH_RE.fullmatch(arch)):+ return None+ return package, version, arch+++def archive_files(directory: Path) -> dict[str, Path]:+ """Regular, correctly named .deb files directly inside *directory*."""+ if not directory.is_dir():+ return {}+ files = {}+ for path in directory.iterdir():+ if path.is_symlink() or not path.is_file():+ continue+ if parse_archive_name(path.name) is not None:+ files[path.name] = path+ return files+++def index_hashes(identities: list[Identity], apt_cache: str) -> dict[Identity, set[str]]:+ """Every SHA256 apt's current index lists for each requested package version.++ Queries name ``package:arch`` without a version: apt-cache then prints+ every record for that architecture, whereas ``=version`` keeps only the+ first, which would drop another repository's hash for the same version.+ The exact package, version, and architecture are matched afterwards.+ """+ wanted = set(identities)+ found: dict[Identity, set[str]] = {}+ queries = sorted({f"{package}:{arch}" for package, _, arch in identities})+ for start in range(0, len(queries), QUERY_BATCH):+ # apt-cache can exit non-zero when a package is unknown; the records+ # it does print are still used.+ output = subprocess.run(+ [apt_cache, "show", *queries[start:start + QUERY_BATCH]],+ capture_output=True, text=True, check=False,+ ).stdout+ for stanza in output.split("\n\n"):+ fields = dict(+ line.split(": ", 1) for line in stanza.splitlines()+ if ": " in line and not line.startswith(" ")+ )+ identity = (fields.get("Package", ""), fields.get("Version", ""), fields.get("Architecture", ""))+ digest = fields.get("SHA256", "")+ if identity in wanted and re.fullmatch(r"[0-9a-f]{64}", digest):+ found.setdefault(identity, set()).add(digest)+ return found+++def sha256(path: Path) -> str:+ digest = hashlib.sha256()+ with path.open("rb") as handle:+ for block in iter(lambda: handle.read(1 << 20), b""):+ digest.update(block)+ return digest.hexdigest()+++def private_copy(source: Path, directory: Path) -> tuple[Path, str]:+ """Copy *source* into a private directory, hashing exactly the bytes copied.++ The copy, not the cache file, is what reaches apt, so replacing the cache+ file after hashing cannot put unverified bytes into the archives.+ """+ copy = directory / source.name+ digest = hashlib.sha256()+ with source.open("rb") as reader, copy.open("xb") as writer:+ for block in iter(lambda: reader.read(1 << 20), b""):+ digest.update(block)+ writer.write(block)+ return copy, digest.hexdigest()+++def install_file(source: Path, archives: Path) -> None:+ destination = archives / source.name+ if os.access(archives, os.W_OK):+ shutil.copyfile(source, destination)+ destination.chmod(0o644)+ else:+ subprocess.run(["sudo", "install", "-m", "0644", str(source), str(destination)], check=True)+++def seed(cache_dir: Path, archives: Path, apt_cache: str, update: list[str] | None) -> int:+ cached = archive_files(cache_dir)+ if not cached:+ print("No cached browser OS packages to admit")+ return 0+ if update:+ subprocess.run(update, check=True)+ identities = {name: parse_archive_name(name) for name in cached}+ expected = index_hashes(list(identities.values()), apt_cache)+ admitted = rejected = unknown = 0+ with tempfile.TemporaryDirectory(prefix="pulse-browser-os-") as private:+ for name, path in sorted(cached.items()):+ want = expected.get(identities[name])+ if not want:+ unknown += 1+ continue+ copy, got = private_copy(path, Path(private))+ if got not in want:+ rejected += 1+ print(f"Rejected {name}: SHA256 does not match the signed index")+ else:+ install_file(copy, archives)+ admitted += 1+ copy.unlink()+ print(f"Admitted {admitted} cached browser OS packages; {unknown} no longer in the index; {rejected} rejected")+ return 0+++def collect(cache_dir: Path, archives: Path) -> int:+ current = archive_files(archives)+ cached = archive_files(cache_dir)+ previous = set(cached)+ # Compare content too: a same-named cached file that seed rejected must+ # be replaced, or every run would reject it and download again.+ changed = bool(current) and (+ set(current) != previous+ or any(sha256(path) != sha256(cached[name]) for name, path in current.items())+ )+ if not current:+ print("::warning::apt kept no downloaded browser OS packages; the cache is left unchanged")+ elif changed:+ # Rebuild in a fresh directory so nothing restored (a symlink, a+ # directory, a stale file) survives or redirects a write.+ fresh = cache_dir.with_name(cache_dir.name + ".new")+ if fresh.is_symlink() or fresh.is_file():+ fresh.unlink()+ elif fresh.exists():+ shutil.rmtree(fresh)+ fresh.mkdir(parents=True)+ for name, path in current.items():+ shutil.copyfile(path, fresh / name)+ if cache_dir.is_symlink() or cache_dir.is_file():+ cache_dir.unlink()+ elif cache_dir.exists():+ shutil.rmtree(cache_dir)+ fresh.rename(cache_dir)+ print(f"Collected {len(current)} browser OS packages ({len(set(current) - previous)} new)")+ else:+ print(f"The {len(current)} browser OS packages match the restored cache")+ output = os.environ.get("GITHUB_OUTPUT")+ if output:+ append_output(Path(output), "changed", "true" if changed else "false")+ return 0+++def main(argv: list[str] | None = None) -> int:+ parser = argparse.ArgumentParser(description=__doc__.split("\n", 1)[0])+ parser.add_argument("command", choices=("seed", "collect"))+ parser.add_argument("cache_dir", type=Path)+ parser.add_argument("--archives", type=Path, default=ARCHIVES)+ parser.add_argument("--apt-cache", default="apt-cache")+ parser.add_argument("--no-update", action="store_true", help="skip apt-get update (tests)")+ args = parser.parse_args(argv)+ if args.command == "seed":+ update = None if args.no_update else ["sudo", "apt-get", "update"]+ return seed(args.cache_dir, args.archives, args.apt_cache, update)+ return collect(args.cache_dir, args.archives)+++if __name__ == "__main__":+ sys.exit(main())diff --git a/scripts/tests/test_browser_os_packages.py b/scripts/tests/test_browser_os_packages.pynew file mode 100644index 0000000000..29bf211249--- /dev/null+++ b/scripts/tests/test_browser_os_packages.py@@ -0,0 +1,264 @@+#!/usr/bin/env python3+"""Cached browser OS packages reach apt only with the signed index's SHA256."""++import hashlib+import os+import stat+import sys+import tempfile+import unittest+from pathlib import Path++sys.path.insert(0, str(Path(__file__).resolve().parents[1]))+import browser_os_packages as bop # noqa: E402+++def digest(data: bytes) -> str:+ return hashlib.sha256(data).hexdigest()+++FAKE_APT_CACHE = """#!{python}+import sys+stanzas = [s for s in open({index!r}).read().split("\\n\\n") if s.strip()]+queries = sys.argv[2:]+open({queries!r}, "a").write("\\n".join(queries) + "\\n")+missing = False+for query in queries:+ name, _, version = query.partition("=")+ package, _, arch = name.partition(":")+ arch = arch or "amd64"+ hits = [s for s in stanzas+ if f"Package: {{package}}\\n" in s and f"Architecture: {{arch}}\\n" in s+ and (not version or f"Version: {{version}}\\n" in s)]+ if version:+ # Like apt 2.8, pkg=version selects only the first matching record.+ hits = hits[:1]+ missing = missing or not hits+ for hit in hits:+ print(hit + "\\n")+sys.exit(100 if missing else 0)+"""+++class Workspace:+ """Temp cache and archive directories plus a fake apt-cache index."""++ def __init__(self, root: Path):+ self.cache = root / "cache"+ self.archives = root / "archives"+ self.cache.mkdir()+ self.archives.mkdir()+ self.index = root / "index"+ self.index.write_text("")+ self.queries = root / "queries"+ self.apt_cache = root / "apt-cache"+ # Like apt-cache show: prints every stanza a pkg[:arch] query names+ # but only the first for pkg[:arch]=version (no arch means the native+ # amd64), records the queries, and exits 100 when any is unknown.+ self.apt_cache.write_text(FAKE_APT_CACHE.format(+ python=sys.executable, index=str(self.index), queries=str(self.queries)))+ self.apt_cache.chmod(self.apt_cache.stat().st_mode | stat.S_IEXEC)++ def publish(self, package: str, version: str, arch: str, data: bytes) -> None:+ with self.index.open("a") as index:+ index.write(+ f"Package: {package}\nArchitecture: {arch}\nVersion: {version}\n"+ f"Size: {len(data)}\nSHA256: {digest(data)}\nDescription: fixture\n"+ f" continued description line\n\n"+ )++ def seed(self) -> None:+ bop.main(["seed", str(self.cache), "--archives", str(self.archives),+ "--apt-cache", str(self.apt_cache), "--no-update"])++ def collect(self) -> str:+ output = self.cache.parent / "github-output"+ output.write_text("")+ os.environ["GITHUB_OUTPUT"] = str(output)+ try:+ bop.main(["collect", str(self.cache), "--archives", str(self.archives)])+ finally:+ del os.environ["GITHUB_OUTPUT"]+ text = output.read_text()+ return "true" if "\ntrue\n" in text else "false" if "\nfalse\n" in text else "missing"+++class ArchiveNameTest(unittest.TestCase):+ def test_parses_apt_filenames_including_encoded_epochs(self):+ self.assertEqual(bop.parse_archive_name("libgtk-3-0t64_3.24.41-4ubuntu1.3_amd64.deb"),+ ("libgtk-3-0t64", "3.24.41-4ubuntu1.3", "amd64"))+ self.assertEqual(bop.parse_archive_name("libavformat60_7%3a6.1.1-3ubuntu5_amd64.deb"),+ ("libavformat60", "7:6.1.1-3ubuntu5", "amd64"))+ self.assertEqual(bop.parse_archive_name("fonts-noto-color-emoji_2.047-0ubuntu0.24.04.1_all.deb"),+ ("fonts-noto-color-emoji", "2.047-0ubuntu0.24.04.1", "all"))++ def test_rejects_names_that_are_not_apt_archives(self):+ for name in ("lock", "partial", "a_b.deb", "a_b_c_d.deb", "Upper_1_amd64.deb",+ "pkg_1 2_amd64.deb", "pkg_1_amd64.deb.part", "../x_1_amd64.deb"):+ with self.subTest(name=name):+ self.assertIsNone(bop.parse_archive_name(name))+++class SeedTest(unittest.TestCase):+ def setUp(self):+ self.temp = tempfile.TemporaryDirectory()+ self.ws = Workspace(Path(self.temp.name))++ def tearDown(self):+ self.temp.cleanup()++ def test_admits_only_files_matching_the_signed_index(self):+ good = b"genuine package bytes"+ self.ws.publish("libgood", "1.0-1", "amd64", good)+ (self.ws.cache / "libgood_1.0-1_amd64.deb").write_bytes(good)+ self.ws.seed()+ admitted = self.ws.archives / "libgood_1.0-1_amd64.deb"+ self.assertEqual(admitted.read_bytes(), good)+ self.assertEqual(stat.S_IMODE(admitted.stat().st_mode), 0o644)++ def test_same_size_tampered_file_is_never_admitted(self):+ # apt itself would accept this file: it checks only the size.+ good, bad = b"genuine package bytes", b"tampered package byte"+ self.assertEqual(len(good), len(bad))+ self.ws.publish("libgood", "1.0-1", "amd64", good)+ (self.ws.cache / "libgood_1.0-1_amd64.deb").write_bytes(bad)+ self.ws.seed()+ self.assertFalse((self.ws.archives / "libgood_1.0-1_amd64.deb").exists())++ def test_versions_and_architectures_missing_from_the_index_are_skipped(self):+ self.ws.publish("libold", "2.0-1", "amd64", b"new")+ (self.ws.cache / "libold_1.0-1_amd64.deb").write_bytes(b"old")+ self.ws.publish("libforeign", "1.0-1", "arm64", b"other arch")+ (self.ws.cache / "libforeign_1.0-1_amd64.deb").write_bytes(b"other arch")+ self.ws.seed()+ self.assertEqual(list(self.ws.archives.iterdir()), [])++ def test_symlinks_and_unparsable_files_are_ignored(self):+ data = b"genuine"+ self.ws.publish("liblink", "1.0-1", "amd64", data)+ target = self.ws.cache.parent / "elsewhere.deb"+ target.write_bytes(data)+ (self.ws.cache / "liblink_1.0-1_amd64.deb").symlink_to(target)+ (self.ws.cache / "not-an-archive.deb").write_bytes(data)+ self.ws.seed()+ self.assertEqual(list(self.ws.archives.iterdir()), [])++ def test_queries_name_the_architecture_of_every_archive(self):+ # On a multiarch runner an unqualified query returns only the native+ # stanza, so a valid foreign or Architecture: all archive would be+ # downloaded again every run.+ native, foreign, common = b"amd64 build", b"i386 build", b"all build"+ self.ws.publish("libmulti", "1.0-1", "amd64", native)+ self.ws.publish("libmulti", "1.0-1", "i386", foreign)+ self.ws.publish("fonts-common", "1:2.0-1", "all", common)+ (self.ws.cache / "libmulti_1.0-1_i386.deb").write_bytes(foreign)+ (self.ws.cache / "fonts-common_1%3a2.0-1_all.deb").write_bytes(common)+ self.ws.seed()+ self.assertEqual((self.ws.archives / "libmulti_1.0-1_i386.deb").read_bytes(), foreign)+ self.assertEqual((self.ws.archives / "fonts-common_1%3a2.0-1_all.deb").read_bytes(), common)+ self.assertEqual(sorted(self.ws.queries.read_text().split()),+ ["fonts-common:all", "libmulti:i386"])++ def test_any_repository_hash_for_the_version_is_accepted(self):+ # Two configured repositories can publish one version with different+ # bytes; a file matching either signed stanza is genuine.+ first, second = b"first repository", b"second repository"+ self.ws.publish("libdual", "1.0-1", "amd64", first)+ self.ws.publish("libdual", "1.0-1", "amd64", second)+ for variant in (first, second):+ with self.subTest(variant=variant):+ (self.ws.cache / "libdual_1.0-1_amd64.deb").write_bytes(variant)+ self.ws.seed()+ self.assertEqual((self.ws.archives / "libdual_1.0-1_amd64.deb").read_bytes(), variant)++ def test_admitted_bytes_are_the_bytes_that_were_hashed(self):+ # Swapping the cache file after it is read must not change what apt+ # gets: the verified private copy is what is installed.+ good, bad = b"genuine package bytes", b"tampered package byte"+ self.ws.publish("libgood", "1.0-1", "amd64", good)+ cached = self.ws.cache / "libgood_1.0-1_amd64.deb"+ cached.write_bytes(good)+ real_install = bop.install_file++ def swap_then_install(source, archives):+ cached.write_bytes(bad)+ real_install(source, archives)++ bop.install_file = swap_then_install+ try:+ self.ws.seed()+ finally:+ bop.install_file = real_install+ self.assertEqual((self.ws.archives / "libgood_1.0-1_amd64.deb").read_bytes(), good)++ def test_empty_cache_needs_no_index_refresh(self):+ # A missing update command would fail if seed tried to run it.+ bop.seed(self.ws.cache, self.ws.archives, str(self.ws.apt_cache), ["/nonexistent/apt-get", "update"])+ self.assertEqual(list(self.ws.archives.iterdir()), [])+++class CollectTest(unittest.TestCase):+ def setUp(self):+ self.temp = tempfile.TemporaryDirectory()+ self.ws = Workspace(Path(self.temp.name))++ def tearDown(self):+ self.temp.cleanup()++ def test_first_run_saves_what_apt_downloaded(self):+ (self.ws.archives / "liba_1_amd64.deb").write_bytes(b"a")+ (self.ws.archives / "lock").write_bytes(b"")+ self.assertEqual(self.ws.collect(), "true")+ self.assertEqual(sorted(p.name for p in self.ws.cache.iterdir()), ["liba_1_amd64.deb"])++ def test_unchanged_set_is_not_saved_again(self):+ for directory in (self.ws.archives, self.ws.cache):+ (directory / "liba_1_amd64.deb").write_bytes(b"a")+ self.assertEqual(self.ws.collect(), "false")++ def test_new_and_stale_versions_refresh_the_cache(self):+ (self.ws.cache / "liba_1_amd64.deb").write_bytes(b"old")+ (self.ws.archives / "liba_2_amd64.deb").write_bytes(b"new")+ self.assertEqual(self.ws.collect(), "true")+ self.assertEqual(sorted(p.name for p in self.ws.cache.iterdir()), ["liba_2_amd64.deb"])++ def test_rejected_same_name_file_is_replaced(self):+ (self.ws.cache / "liba_1_amd64.deb").write_bytes(b"bad")+ (self.ws.archives / "liba_1_amd64.deb").write_bytes(b"gen")+ self.assertEqual(self.ws.collect(), "true")+ self.assertEqual((self.ws.cache / "liba_1_amd64.deb").read_bytes(), b"gen")++ def test_restored_symlinks_and_directories_do_not_survive_a_rebuild(self):+ outside = self.ws.cache.parent / "outside"+ outside.write_bytes(b"not apt's")+ (self.ws.cache / "liba_1_amd64.deb").symlink_to(outside)+ (self.ws.cache / "libb_1_amd64.deb").mkdir()+ (self.ws.cache / "libb_1_amd64.deb" / "inner").write_bytes(b"x")+ (self.ws.archives / "liba_1_amd64.deb").write_bytes(b"a")+ (self.ws.archives / "libb_1_amd64.deb").write_bytes(b"b")+ self.assertEqual(self.ws.collect(), "true")+ entries = sorted(self.ws.cache.iterdir())+ self.assertEqual([p.name for p in entries], ["liba_1_amd64.deb", "libb_1_amd64.deb"])+ self.assertTrue(all(p.is_file() and not p.is_symlink() for p in entries))+ self.assertEqual(outside.read_bytes(), b"not apt's")++ def test_symlinked_cache_directory_is_replaced_not_followed(self):+ elsewhere = self.ws.cache.parent / "elsewhere"+ elsewhere.mkdir()+ (elsewhere / "keep").write_bytes(b"keep")+ self.ws.cache.rmdir()+ self.ws.cache.symlink_to(elsewhere, target_is_directory=True)+ (self.ws.archives / "liba_1_amd64.deb").write_bytes(b"a")+ self.assertEqual(self.ws.collect(), "true")+ self.assertFalse(self.ws.cache.is_symlink())+ self.assertEqual([p.name for p in self.ws.cache.iterdir()], ["liba_1_amd64.deb"])+ self.assertEqual([p.name for p in elsewhere.iterdir()], ["keep"])++ def test_empty_archives_never_overwrite_the_cache(self):+ (self.ws.cache / "liba_1_amd64.deb").write_bytes(b"a")+ self.assertEqual(self.ws.collect(), "false")+ self.assertTrue((self.ws.cache / "liba_1_amd64.deb").exists())+++if __name__ == "__main__":+ unittest.main()diff --git a/scripts/tests/test_e2e_test_images.py b/scripts/tests/test_e2e_test_images.pyindex 38f9d2bd55..c8364dc620 100644--- a/scripts/tests/test_e2e_test_images.py+++ b/scripts/tests/test_e2e_test_images.py@@ -323,6 +323,17 @@ class E2EImageWorkflowTest(unittest.TestCase):for ignored in ("continue-on-error", "if:", "||"):self.assertNotIn(ignored, admission)self.assertLess(start, consumer.index("- name: Start "))+ # Images arrive only as this run's artifact. The browser OS+ # package cache is the job's only Actions cache and must never+ # become a second, cross-run image channel.+ cache_steps = re.findall(+ r"(?ms)^ uses: actions/cache/(?:restore|save)@.*?(?=^ - name:|\Z)", consumer+ )+ self.assertEqual(len(cache_steps), 2)+ for step in cache_steps:+ self.assertIn("path: ~/.cache/pulse-browser-os-packages\n", step)+ self.assertNotIn("pulse-e2e-images", step)+ self.assertNotIn("docker", step.lower())self.assertIn("timeout-minutes: 60", job_block(workflow, "e2e"))self.assertIn("shard: [1, 2, 3, 4, 5, 6, 7, 8]", job_block(workflow, "e2e"))self.assertIn("timeout-minutes: 30", job_block(workflow, "agent-registration"))@@ -354,6 +365,7 @@ class E2EImageWorkflowTest(unittest.TestCase):('python3 scripts/e2e_test_images.py load "$RUNNER_TEMP/pulse-e2e-images"', 'python3 scripts/e2e_test_images.py load "$RUNNER_TEMP/pulse-e2e-images" || true'),("PULSE_E2E_MANIFEST_SHA256: ${{ needs.test-images.outputs.manifest-sha256 }}", "PULSE_E2E_MANIFEST_SHA256: unchecked"),(" - test-images\n", ""),+ ("path: ~/.cache/pulse-browser-os-packages\n", "path: ${{ runner.temp }}/pulse-e2e-images\n"),):with self.subTest(mutation=new):with self.assertRaises(AssertionError):diff --git a/scripts/tests/test_playwright_acquisition.py b/scripts/tests/test_playwright_acquisition.pyindex ecb9b523ad..7804229cd1 100644--- a/scripts/tests/test_playwright_acquisition.py+++ b/scripts/tests/test_playwright_acquisition.py@@ -17,6 +17,10 @@ INSTALL_POLICY = ("sudo install -m 0644 scripts/playwright-apt.conf ""/etc/apt/apt.conf.d/99pulse-playwright-acquire")+# actions/cache v6.1.0 (Node 24). Restore and save are separate steps so a+# successful install is cached even when later journeys fail.+CACHE_PIN = "55cc8345863c7cc4c66a329aec7e433d2d1c52a9"+CACHE_DIR = '"$HOME/.cache/pulse-browser-os-packages"'def job_block(workflow, job):@@ -54,17 +58,59 @@ class PlaywrightAcquisitionTest(unittest.TestCase):self.assertIn("working-directory: tests/integration", install)browsers = "chromium webkit" if job == "e2e" else "chromium"self.assertIn(f"npx playwright install --with-deps {browsers}\n", install)- # Browser setup must finish successfully before real journeys.- self.assertLess(i, next(+ journey = next(n for n, step in enumerate(steps)if step.startswith("Run stable-tier E2E suite")or step.startswith("Prove authenticated default")or step.startswith("Run agent registration lifecycle")- ))+ )+ # Browser setup must finish successfully before real journeys.+ self.assertLess(i, journey)+ self.assert_package_cache(steps, policies[0], i, journey, browsers)if job == "e2e":self.assertRegex(block, r"(?m)^ timeout-minutes: 60$")self.assertNotRegex(install, r"(?m)^ timeout-minutes: 10$")+ def assert_package_cache(self, steps, policy, install, journey, browsers):+ """Slow mirrors must not gate setup, and cached files must not bypass apt's authentication."""+ def only(name):+ found = [n for n, step in enumerate(steps) if step.startswith(name + "\n")]+ self.assertEqual(len(found), 1, name)+ return found[0]++ restore = only("Restore browser OS packages")+ admit = only("Admit verified browser OS packages")+ collect = only("Collect browser OS packages")+ save = only("Save browser OS packages")+ # The bounded apt policy applies to the index refresh inside admission;+ # packages are saved only after a successful install and before any+ # journey can fail the job.+ self.assertLess(policy, admit)+ self.assertLess(restore, admit)+ self.assertLess(admit, install)+ self.assertLess(install, collect)+ self.assertLess(collect, save)+ self.assertLess(save, journey)+ slug = browsers.replace(" ", "-")+ prefix = "browser-os-packages-${{ runner.os }}-" + slug + "-"+ lock = "${{ hashFiles('tests/integration/package-lock.json') }}"+ self.assertIn(f"uses: actions/cache/restore@{CACHE_PIN} # v6.1.0\n", steps[restore])+ # A run-unique key keeps saving possible as Ubuntu publishes new+ # versions; restores take the newest entry by prefix.+ self.assertIn(f"key: {prefix}{lock}-${{{{ github.run_id }}}}-${{{{ github.run_attempt }}}}\n", steps[restore])+ self.assertIn(f" {prefix}{lock}-\n {prefix}\n", steps[restore])+ # Admission and collection go through the verifying helper; a direct+ # copy would let apt accept a same-size file without a hash check.+ self.assertIn(f"run: python3 scripts/browser_os_packages.py seed {CACHE_DIR}\n", steps[admit])+ self.assertIn("id: browser-os-collect\n", steps[collect])+ self.assertIn(f"run: python3 scripts/browser_os_packages.py collect {CACHE_DIR}\n", steps[collect])+ self.assertIn(f"uses: actions/cache/save@{CACHE_PIN} # v6.1.0\n", steps[save])+ self.assertIn("if: steps.browser-os-collect.outputs.changed == 'true'\n", steps[save])+ self.assertIn("key: ${{ steps.browser-os-packages.outputs.cache-primary-key }}\n", steps[save])+ for n in (admit, collect):+ for forbidden in ("${{", "continue-on-error", "if:", "||", " cp ", "install -m"):+ self.assertNotIn(forbidden, steps[n])+def test_all_browser_jobs_bound_setup_without_weakening_gates(self):self.assert_workflow_policy(WORKFLOW.read_text())@@ -74,11 +120,14 @@ class PlaywrightAcquisitionTest(unittest.TestCase):block = re.split(r"(?m)^ \S", workflow.split(f" {event}:\n", 1)[1], maxsplit=1)[0]self.assertIn("'scripts/playwright-apt.conf'", block)self.assertIn("'scripts/tests/test_playwright_acquisition.py'", block)+ self.assertIn("'scripts/browser_os_packages.py'", block)+ self.assertIn("'scripts/tests/test_browser_os_packages.py'", block)selection = job_block(workflow, "tier-selection")- self.assertLess(- selection.index("python3 scripts/tests/test_playwright_acquisition.py"),- selection.index("npm ci"),- )+ for test in ("test_playwright_acquisition.py", "test_browser_os_packages.py"):+ self.assertLess(+ selection.index(f"python3 scripts/tests/{test}"),+ selection.index("npm ci"),+ )def test_unbounded_and_ignored_setup_mutants_are_rejected(self):workflow = WORKFLOW.read_text()@@ -90,6 +139,11 @@ class PlaywrightAcquisitionTest(unittest.TestCase):(INSTALL_POLICY, "echo no acquisition policy"),("run: npx playwright install --with-deps chromium\n","run: npx playwright install --with-deps chromium || true\n"),+ (f"actions/cache/restore@{CACHE_PIN}", "actions/cache/restore@v6"),+ ("-${{ github.run_id }}-${{ github.run_attempt }}\n", "\n"),+ (f"run: python3 scripts/browser_os_packages.py seed {CACHE_DIR}\n",+ f"run: sudo cp {CACHE_DIR}/*.deb /var/cache/apt/archives/\n"),+ ("if: steps.browser-os-collect.outputs.changed == 'true'\n", "if: always()\n"),):with self.subTest(mutation=replacement):# subTest failures cannot be caught as an ordinary assertion,