| 1 | """Exercise the target binary's bundled Vile resources and real installed database queries.""" |
| 2 | import os |
| 3 | from pathlib import Path |
| 4 | import json |
| 5 | import subprocess |
| 6 | import tempfile |
| 7 | |
| 8 | root = Path(os.environ["VPAC_MAKEPKG_ROOT"]) |
| 9 | db = Path(os.environ["VPAC_MAKEPKG_DB"]) |
| 10 | exe = Path("vpac-target").resolve() |
| 11 | with tempfile.TemporaryDirectory() as directory: |
| 12 | work = Path(directory) |
| 13 | # Debug V builds read Scheme files from the compiler checkout. Temporarily move |
| 14 | # those build inputs so only a self-contained release executable can pass. |
| 15 | moved = [] |
| 16 | try: |
| 17 | for resource in (Path("vpac-src/src/config_objects.scm"), Path("modules/vile/scheme/goops_protocol.scm")): |
| 18 | hidden = resource.with_suffix(".scm.hidden") |
| 19 | resource.rename(hidden) |
| 20 | moved.append((hidden, resource)) |
| 21 | contents = Path("config.vile").read_text() |
| 22 | contents = contents.replace('path-root = "/"', "path-root = " + json.dumps(str(root) + "/")) |
| 23 | contents = contents.replace('path-db = "/var/lib/vpac/"', "path-db = " + json.dumps(str(db) + "/")) |
| 24 | config = work / "config.vile" |
| 25 | config.write_text(contents) |
| 26 | env = os.environ.copy() |
| 27 | env.pop("V_RESOURCE_PATH", None) |
| 28 | result = subprocess.check_output(["vinix-run", exe, "--config", config, "q", "-F", |
| 29 | "name,version,validation", "local/musl"], env=env, text=True) |
| 30 | fields = dict(line.split(None, 1) for line in result.splitlines() if len(line.split(None, 1)) == 2) |
| 31 | if fields.get("name") != "musl" or fields.get("validation") != "signature": |
| 32 | raise RuntimeError(f"target vpac did not query signed musl: {result!r}") |
| 33 | finally: |
| 34 | for hidden, resource in moved: |
| 35 | hidden.rename(resource) |
| 36 | |