test_image_grammars.py
python
sha256:b4b999434d042d74edc7032f1f2cfd20fda5b3580fe85966351db5b8eef0abb3
feat(intel): every grammar on the hub, and every intel job …
Opus 5.5
minor
⚠ breaking
1 day ago
| 1 | """muse#251 — the MuseHub image parses every language Muse does. |
| 2 | |
| 3 | The background intel jobs parse stored objects in-process with Muse's library; without the grammar packages every |
| 4 | non-Python file is file-level only on the hub (languages, api-surface, codemap, call-graph jobs, blob outlines). |
| 5 | |
| 6 | IMG_01: grammar-requirements.txt pins exactly the grammars of Muse's ``[all]`` extra, at versions Muse accepts, |
| 7 | each with an amd64 and an arm64 wheel hash (the build uses ``--require-hashes``). |
| 8 | IMG_02: the Dockerfile installs that file with ``--require-hashes --no-deps``. |
| 9 | IMG_03: in this image every grammar loads and every non-optional language is operational. |
| 10 | """ |
| 11 | from __future__ import annotations |
| 12 | |
| 13 | import pathlib |
| 14 | import re |
| 15 | import tomllib |
| 16 | |
| 17 | import pytest |
| 18 | from packaging.requirements import Requirement |
| 19 | |
| 20 | ROOT = pathlib.Path(__file__).resolve().parents[1] |
| 21 | GRAMMARS = ROOT / "grammar-requirements.txt" |
| 22 | |
| 23 | |
| 24 | def _muse_pyproject() -> dict: |
| 25 | import muse |
| 26 | |
| 27 | path = pathlib.Path(muse.__file__).resolve().parents[1] / "pyproject.toml" |
| 28 | if not path.exists(): |
| 29 | pytest.skip(f"muse source tree not mounted ({path})") |
| 30 | return tomllib.loads(path.read_text()) |
| 31 | |
| 32 | |
| 33 | def _expand(extras: dict[str, list[str]], name: str) -> list[Requirement]: |
| 34 | out: list[Requirement] = [] |
| 35 | for spec in extras[name]: |
| 36 | req = Requirement(spec) |
| 37 | if req.name == "muse": |
| 38 | for extra in req.extras: |
| 39 | out += _expand(extras, extra) |
| 40 | else: |
| 41 | out.append(req) |
| 42 | return out |
| 43 | |
| 44 | |
| 45 | def _pinned() -> dict[str, tuple[str, list[str]]]: |
| 46 | """``{package: (version, [sha256, …])}`` from grammar-requirements.txt (continuation lines joined).""" |
| 47 | text = re.sub(r"\\\n\s*", " ", GRAMMARS.read_text()) |
| 48 | out: dict[str, tuple[str, list[str]]] = {} |
| 49 | for line in text.splitlines(): |
| 50 | line = line.split("#", 1)[0].strip() |
| 51 | if not line: |
| 52 | continue |
| 53 | m = re.match(r"([A-Za-z0-9_.-]+)==([^\s]+)", line) |
| 54 | assert m, f"not an exact pin: {line!r}" |
| 55 | out[m.group(1).lower()] = (m.group(2), re.findall(r"--hash=sha256:([0-9a-f]{64})", line)) |
| 56 | return out |
| 57 | |
| 58 | |
| 59 | def test_IMG_01_grammar_requirements_match_muse_all() -> None: |
| 60 | extras = _muse_pyproject()["project"]["optional-dependencies"] |
| 61 | wanted = {r.name.lower(): r for r in _expand(extras, "all")} |
| 62 | pinned = _pinned() |
| 63 | assert set(pinned) == set(wanted), f"missing {sorted(set(wanted) - set(pinned))}, extra {sorted(set(pinned) - set(wanted))}" |
| 64 | for name, (version, hashes) in pinned.items(): |
| 65 | assert wanted[name].specifier.contains(version, prereleases=True), f"{name}=={version} not allowed by muse ({wanted[name]})" |
| 66 | assert len(set(hashes)) >= 2, f"{name}: needs an amd64 and an arm64 wheel hash" |
| 67 | |
| 68 | |
| 69 | def test_IMG_02_dockerfile_installs_the_hashed_grammars() -> None: |
| 70 | dockerfile = (ROOT / "Dockerfile").read_text() |
| 71 | assert "grammar-requirements.txt" in dockerfile |
| 72 | install = next(l for l in dockerfile.splitlines() if "grammar-requirements.txt" in l and "pip install" in l) |
| 73 | assert "--require-hashes" in install and "--no-deps" in install |
| 74 | |
| 75 | |
| 76 | def test_IMG_03_every_grammar_loads_in_this_image() -> None: |
| 77 | from muse.plugins.code._diagnostics import diagnose_languages |
| 78 | |
| 79 | broken = {name: d["parser"] for name, d in diagnose_languages().items() |
| 80 | if d["profile"] != "opt_in" and d["parser"]["state"] not in ("operational", "not_required")} |
| 81 | assert not broken, f"grammars missing from the image: {sorted(broken)}" |
File History
1 commit
sha256:b4b999434d042d74edc7032f1f2cfd20fda5b3580fe85966351db5b8eef0abb3
feat(intel): every grammar on the hub, and every intel job …
Opus 5.5
minor
⚠
1 day ago