Skip to content

The headless browser for AI agents and web scraping

ci: recover incomplete V8 native-library caches

SGavrl3aba28e3d1ca
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c602ee81..d91fb23e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -156,6 +156,14 @@ jobs:
# release workflows do not consume this cache.
save-if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
+ - name: Repair incomplete V8 cache
+ run: |
+ # rust-cache removes gn_out but can retain V8's build-script metadata.
+ if [[ ! -f target/release/gn_out/obj/librusty_v8.a || ! -s target/release/gn_out/obj/librusty_v8.a ]]; then
+ rm -f -- target/release/gn_out/obj/librusty_v8.sum
+ cargo clean --release -p v8
+ fi
+
- name: Build render release
run: cargo build --release -p obscura-cli --bins --features render
@@ -272,6 +280,14 @@ jobs:
shared-key: obscura-ci-dependencies
save-if: false
+ - name: Repair incomplete V8 cache
+ run: |
+ # This checkout is the trusted base, so keep the repair self-contained.
+ if [[ ! -f target/release/gn_out/obj/librusty_v8.a || ! -s target/release/gn_out/obj/librusty_v8.a ]]; then
+ rm -f -- target/release/gn_out/obj/librusty_v8.sum
+ cargo clean --release -p v8
+ fi
+
- name: Build base revision
shell: bash
env:
diff --git a/scripts/ci/test_repair_v8_cache.py b/scripts/ci/test_repair_v8_cache.py
new file mode 100644
index 00000000..19b627ed
--- /dev/null
+++ b/scripts/ci/test_repair_v8_cache.py
@@ -0,0 +1,71 @@
+import os
+from pathlib import Path
+import subprocess
+import tempfile
+import textwrap
+import unittest
+
+
+class RepairV8CacheTests(unittest.TestCase):
+ def repair_steps(self):
+ workflow = (Path(__file__).resolve().parents[2] / ".github/workflows/ci.yml").read_text()
+ restores = workflow.split("- name: Restore Rust dependency cache")[1:]
+ self.assertEqual(len(restores), 2)
+ scripts = []
+ for consumer in restores:
+ before_build = consumer.split("- name: Build", 1)[0]
+ marker = "- name: Repair incomplete V8 cache\n run: |\n"
+ self.assertIn(marker, before_build)
+ scripts.append(textwrap.dedent(before_build.split(marker, 1)[1]).strip())
+ return scripts
+
+ def test_both_cache_consumers_repair_before_building(self):
+ self.assertEqual(len(self.repair_steps()), 2)
+
+ def check_archive(self, kind, should_clean, clean_exit=0):
+ with tempfile.TemporaryDirectory() as directory:
+ root = Path(directory)
+ archive = root / "target/release/gn_out/obj/librusty_v8.a"
+ archive.parent.mkdir(parents=True)
+ if kind == "valid":
+ archive.write_bytes(b"archive fixture")
+ elif kind == "empty":
+ archive.touch()
+ elif kind == "directory":
+ archive.mkdir()
+ cargo = root / "cargo"
+ cargo.write_text('#!/bin/sh\nprintf "%s\\n" "$@" > "$CACHE_CALLS"\nexit "$CACHE_EXIT"\n')
+ cargo.chmod(0o755)
+ calls = root / "calls"
+ environment = {**os.environ, "PATH": str(root) + os.pathsep + os.environ["PATH"], "CACHE_CALLS": str(calls), "CACHE_EXIT": str(clean_exit)}
+ for script in self.repair_steps():
+ with self.subTest(kind=kind, script=script):
+ calls.unlink(missing_ok=True)
+ checksum = archive.with_suffix(".sum")
+ checksum.write_text("cached URL")
+ run = subprocess.run(["bash", "-euc", script], cwd=root, env=environment, capture_output=True, text=True)
+ self.assertEqual(run.returncode, clean_exit if should_clean else 0, run.stderr)
+ self.assertEqual(checksum.exists(), not should_clean)
+ if should_clean:
+ self.assertEqual(calls.read_text().splitlines(), ["clean", "--release", "-p", "v8"])
+ else:
+ self.assertFalse(calls.exists())
+
+ def test_missing_archive_invalidates_only_v8(self):
+ self.check_archive("missing", True)
+
+ def test_empty_archive_invalidates_only_v8(self):
+ self.check_archive("empty", True)
+
+ def test_directory_is_not_an_archive(self):
+ self.check_archive("directory", True)
+
+ def test_valid_archive_preserves_warm_cache(self):
+ self.check_archive("valid", False)
+
+ def test_clean_failure_is_not_hidden(self):
+ self.check_archive("missing", True, clean_exit=7)
+
+
+if __name__ == "__main__":
+ unittest.main()