|
| 1 | +"""Contract tests: every bundled preset must ship inside the wheel's core_pack. |
| 2 | +
|
| 3 | +``specify preset add <id>`` resolves a bundled preset via |
| 4 | +``specify_cli._assets._locate_bundled_preset``, which checks the wheel's |
| 5 | +``specify_cli/core_pack/presets/<id>/`` directory first. Any preset marked |
| 6 | +``bundled: true`` in ``presets/catalog.json`` must therefore be force-included |
| 7 | +at build time; otherwise the released wheel advertises a bundled preset it does |
| 8 | +not actually ship, and ``specify preset add <id>`` falls through and reports the |
| 9 | +preset as missing. |
| 10 | +""" |
| 11 | + |
| 12 | +from __future__ import annotations |
| 13 | + |
| 14 | +import json |
| 15 | +import tomllib |
| 16 | +from pathlib import Path |
| 17 | + |
| 18 | +REPO_ROOT = Path(__file__).parents[2] |
| 19 | + |
| 20 | + |
| 21 | +def _force_include() -> dict[str, str]: |
| 22 | + with (REPO_ROOT / "pyproject.toml").open("rb") as pyproject_file: |
| 23 | + pyproject = tomllib.load(pyproject_file) |
| 24 | + return pyproject["tool"]["hatch"]["build"]["targets"]["wheel"]["force-include"] |
| 25 | + |
| 26 | + |
| 27 | +def _bundled_preset_ids() -> list[str]: |
| 28 | + catalog = json.loads((REPO_ROOT / "presets" / "catalog.json").read_text()) |
| 29 | + return sorted( |
| 30 | + preset_id |
| 31 | + for preset_id, entry in catalog["presets"].items() |
| 32 | + if entry.get("bundled") |
| 33 | + ) |
| 34 | + |
| 35 | + |
| 36 | +def test_every_bundled_preset_is_force_included(): |
| 37 | + force_include = _force_include() |
| 38 | + bundled = _bundled_preset_ids() |
| 39 | + |
| 40 | + assert bundled, "expected at least one bundled preset in presets/catalog.json" |
| 41 | + for preset_id in bundled: |
| 42 | + assert force_include.get(f"presets/{preset_id}") == ( |
| 43 | + f"specify_cli/core_pack/presets/{preset_id}" |
| 44 | + ), f"bundled preset '{preset_id}' is missing from the wheel force-include list" |
| 45 | + |
| 46 | + |
| 47 | +def test_constitution_sync_is_bundled_and_shipped(): |
| 48 | + # Explicit regression guard: constitution-sync was advertised as bundled |
| 49 | + # before it was added to the wheel force-include list. |
| 50 | + assert "constitution-sync" in _bundled_preset_ids() |
| 51 | + assert _force_include()["presets/constitution-sync"] == ( |
| 52 | + "specify_cli/core_pack/presets/constitution-sync" |
| 53 | + ) |
0 commit comments