Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-pkg-server

Source of release 0.6.0

0.6.0 / tests / run_registry.py

#!/usr/bin/env python3
"""Build the loopback registry and run proxy/invite tests in every compiler mode."""
import argparse
import os
from pathlib import Path
import subprocess

ROOT = Path(__file__).resolve().parents[1]
MODES = {f"native{i}": ["--native", "--opt", str(i)] for i in range(4)}
MODES.update({"c": ["--backend=c"], "c-release": ["--backend=c", "--release"]})
# a release of 72 MiB through luc is slow to repeat: once per backend
PUBLISH_MODES = ("native3", "c-release")


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--mode", choices=[*MODES, "all"], default="all")
    parser.add_argument("--base", type=Path, default=ROOT / "build/toolchain/luce-base")
    args = parser.parse_args()
    if not args.base.is_file():
        raise SystemExit("Need luce-base at build/toolchain/luce-base (tools/bootstrap_registry.py)")
    environment = dict(os.environ, LUCE_BASE=str(args.base.resolve()))
    environment.setdefault("LUCE_STD", str(ROOT.parent / "luce-base/src/std"))
    environment.setdefault("LUCE_CACHE", str(ROOT / "build/cache"))
    def run(command, timeout=180):
        subprocess.run([str(a) for a in command], cwd=ROOT, env=environment, check=True, timeout=timeout)
    for mode, flags in MODES.items():
        if args.mode not in (mode, "all"): continue
        if mode == "c":
            # Two intentionally concurrent Argon2 registrations can exceed the
            # ordinary per-request guard in the unoptimized generated-C build on
            # hosted runners. This is a correctness matrix, not a latency SLA.
            environment["LUCE_TEST_HTTP_TIMEOUT"] = "60"
        else:
            environment.pop("LUCE_TEST_HTTP_TIMEOUT", None)
        output = ROOT / "build" / mode
        output.mkdir(parents=True, exist_ok=True)
        print(f"MODE {mode}", flush=True)
        run([args.base.resolve(), "build", ROOT / "src/registry.lucb", *flags, "-o", output / "registry"])
        run([args.base.resolve(), "build", ROOT / "src/admin.lucb", *flags, "-o", output / "admin"])
        run([args.base.resolve(), "build", ROOT / "tests/http_auth.lucb", *flags, "-o", output / "http-auth"])
        run([args.base.resolve(), "build", ROOT / "tests/rate_limit.lucb", *flags, "-o", output / "rate-limit"])
        run([args.base.resolve(), "build", ROOT / "tests/account_fixture.lucb", *flags, "-o", output / "account-fixture"])
        run([args.base.resolve(), "build", ROOT / "tests/legacy_fixture.lucb", *flags, "-o", output / "legacy-fixture"])
        # Unoptimized generated C executes the complete native ML-DSA/Argon2
        # integration matrix substantially more slowly than the native backend.
        # Hosted x86-64 Linux has exceeded seven minutes after completing Git,
        # release and both native-client transfers. Keep every assertion and only
        # widen this per-process wall-clock guard within the 75-minute job bound.
        timeout = 600 if mode == "c" else 240
        run([output / "http-auth"])
        run([output / "rate-limit"])
        run([os.environ.get("PYTHON", "python3"), str(ROOT / "tests/check_accounts.py"), output / "registry", output / "account-fixture"], timeout=timeout)
        run([os.environ.get("PYTHON", "python3"), str(ROOT / "tests/admin.py"), output / "admin", output / "registry"], timeout=timeout)
        run([os.environ.get("PYTHON", "python3"), str(ROOT / "tests/deployment.py"), output / "admin"], timeout=timeout)
        run([os.environ.get("PYTHON", "python3"), str(ROOT / "tests/storage.py"), output / "registry", output / "admin", output / "account-fixture"], timeout=timeout)
        run([os.environ.get("PYTHON", "python3"), str(ROOT / "tests/remove.py"), output / "registry", output / "admin", output / "account-fixture"], timeout=timeout)
        run([os.environ.get("PYTHON", "python3"), str(ROOT / "tests/rebuild.py"), output / "registry", output / "admin", output / "account-fixture"], timeout=timeout)
        run([os.environ.get("PYTHON", "python3"), str(ROOT / "tests/migration.py"), output / "registry", output / "admin", output / "legacy-fixture"], timeout=timeout)
        if mode in PUBLISH_MODES:
            # luc, checked out beside this repository, publishing to this registry
            luc = ROOT.parent / "luce-luc"
            run([args.base.resolve(), "build", luc / "src/main.lucb", "--native", "-o", output / "luc"])
            run([os.environ.get("PYTHON", "python3"), str(ROOT / "tests/publish.py"), output / "registry", output / "account-fixture", output / "luc"], timeout=timeout * 2)
        print(f"PASS {mode}", flush=True)
    print("PASS all selected compiler modes", flush=True)


if __name__ == "__main__":
    main()