52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
import importlib.util
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
PACK_ROOT = Path(__file__).resolve().parents[1]
|
|
INSTALL_PATH = PACK_ROOT / "scripts" / "install.py"
|
|
spec = importlib.util.spec_from_file_location("gewu_install", INSTALL_PATH)
|
|
assert spec and spec.loader
|
|
gewu_install = importlib.util.module_from_spec(spec)
|
|
sys.modules[spec.name] = gewu_install
|
|
spec.loader.exec_module(gewu_install)
|
|
|
|
|
|
def test_install_receipt_contains_service_run_pins(tmp_path: Path) -> None:
|
|
workspace = tmp_path / "project"
|
|
state = gewu_install.install(workspace, PACK_ROOT, "dedicated")
|
|
manifest = json.loads((PACK_ROOT / "manifest.json").read_text(encoding="utf-8"))
|
|
|
|
assert state["run_pins"] == {
|
|
"pack_id": manifest["pack_id"],
|
|
"pack_version": manifest["pack_version"],
|
|
"pack_snapshot_digest": manifest["snapshot"]["digest"],
|
|
"module_pins": [
|
|
{
|
|
"module_id": module["module_id"],
|
|
"implementation_version": module["implementation_version"],
|
|
"sha256": module["sha256"],
|
|
}
|
|
for module in manifest["modules"]
|
|
],
|
|
}
|
|
assert gewu_install._validated_state(state) == state
|
|
|
|
installed_state = json.loads(
|
|
(workspace / gewu_install.STATE_PATH).read_text(encoding="utf-8")
|
|
)
|
|
assert installed_state["run_pins"] == state["run_pins"]
|
|
gewu_install.uninstall(workspace)
|
|
|
|
|
|
def test_uninstall_accepts_legacy_install_receipt(tmp_path: Path) -> None:
|
|
workspace = tmp_path / "project"
|
|
state = gewu_install.install(workspace, PACK_ROOT, "dedicated")
|
|
state.pop("run_pins")
|
|
(workspace / gewu_install.STATE_PATH).write_text(
|
|
json.dumps(state), encoding="utf-8"
|
|
)
|
|
|
|
gewu_install.uninstall(workspace)
|