Files
Echoion/scripts/tests/test_package_components.py
T
faumaray 8ac39621fd
Modular container CI / release-build (push) Has been cancelled
Harden signed feeds and RelWithDebInfo releases
2026-08-01 18:02:55 +03:00

105 lines
3.5 KiB
Python
Executable File

#!/usr/bin/env python3
"""Offline tests for deterministic independent component packages."""
from __future__ import annotations
import json
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
SCRIPT = ROOT / "scripts" / "package-components.py"
class PackageComponentsTests(unittest.TestCase):
def test_packages_every_locked_component(self) -> None:
with tempfile.TemporaryDirectory(
prefix="echoion-package-components."
) as directory:
root = Path(directory)
staging = root / "staging"
output = root / "dist"
(staging / "echoion-api/include").mkdir(parents=True)
(staging / "echoion-api/include/api.hpp").write_text("api")
registry = {
"schemaVersion": 1,
"components": {
"EchoionApi": {
"repository": "Void/EchoionApi",
"kind": "sdk",
"packageId": "echoion-api",
"activation": "restart-required",
"dependencies": {},
}
},
}
lock = {
"schemaVersion": 2,
"productVersion": "2.0.0",
"components": {
"EchoionApi": {
"repository": "Void/EchoionApi",
"revision": "1" * 40,
"componentVersion": "2.0.0",
"abiHash": "sha256:" + "2" * 64,
"sourceTreeHash": "git-sha1:" + "3" * 40,
"artifactIdentity": (
"echoion-api-2.0.0-linux-x86_64"
),
}
},
}
registry_path = root / "components.json"
lock_path = root / "components.lock.json"
registry_path.write_text(json.dumps(registry))
lock_path.write_text(json.dumps(lock))
environment = os.environ.copy()
environment["SOURCE_DATE_EPOCH"] = "100"
result = subprocess.run(
[
str(SCRIPT),
"--registry",
str(registry_path),
"--lock",
str(lock_path),
"--staging-root",
str(staging),
"--output",
str(output),
"--channel",
"stable",
"--sequence",
"100",
"--product-version",
"2.0.0",
"--build-type",
"RelWithDebInfo",
],
check=False,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=environment,
)
self.assertEqual(result.returncode, 0, result.stderr)
manifest_path = (
output
/ "echoion-api-2.0.0-linux-x86_64.manifest.json"
)
manifest = json.loads(manifest_path.read_text())
self.assertEqual(manifest["componentId"], "EchoionApi")
self.assertEqual(manifest["buildType"], "RelWithDebInfo")
self.assertTrue(
(
output / "echoion-api-2.0.0-linux-x86_64.tar.zst"
).is_file()
)
if __name__ == "__main__":
unittest.main()