Add independent component release architecture
Modular container CI / release-build (push) Failing after 12s
Modular container CI / release-build (push) Failing after 12s
This commit is contained in:
18 files changed
+2110
-216
No files matched your search
+284
@@ -0,0 +1,284 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Offline tests for product-independent component release transactions."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
PACKAGE = ROOT / "scripts" / "package-component.py"
|
||||
PUBLISH = ROOT / "scripts" / "publish-component-release.py"
|
||||
VERIFY = ROOT / "scripts" / "verify-locked-component-feeds.py"
|
||||
|
||||
|
||||
class IndependentComponentReleaseTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.temporary = tempfile.TemporaryDirectory(
|
||||
prefix="echoion-independent-component."
|
||||
)
|
||||
self.root = Path(self.temporary.name)
|
||||
self.registry = self.root / "components.json"
|
||||
self.output = self.root / "dist"
|
||||
self.feed = self.root / "feed"
|
||||
self.key = self.root / "key.pem"
|
||||
self.public_key = self.root / "public.pem"
|
||||
self.registry.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"components": {
|
||||
"EchoionApi": {
|
||||
"repository": "Void/EchoionApi",
|
||||
"packageId": "echoion-api",
|
||||
"kind": "sdk",
|
||||
"activation": "restart-required",
|
||||
"dependencies": {},
|
||||
},
|
||||
"EchoionWeb": {
|
||||
"repository": "Void/EchoionWeb",
|
||||
"packageId": "echoion-web",
|
||||
"kind": "runtime-module",
|
||||
"activation": "restart-required",
|
||||
"dependencies": {
|
||||
"EchoionApi": ">=2.0.0 <3.0.0"
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
"openssl",
|
||||
"genpkey",
|
||||
"-algorithm",
|
||||
"ED25519",
|
||||
"-out",
|
||||
str(self.key),
|
||||
],
|
||||
check=True,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
self.key.chmod(0o600)
|
||||
subprocess.run(
|
||||
[
|
||||
"openssl",
|
||||
"pkey",
|
||||
"-in",
|
||||
str(self.key),
|
||||
"-pubout",
|
||||
"-out",
|
||||
str(self.public_key),
|
||||
],
|
||||
check=True,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
def tearDown(self) -> None:
|
||||
self.temporary.cleanup()
|
||||
|
||||
def package(self, component: str, package_id: str, version: str) -> tuple[Path, Path]:
|
||||
package_root = self.root / f"stage-{component}"
|
||||
package_root.mkdir()
|
||||
(package_root / "payload.txt").write_text(component)
|
||||
environment = os.environ.copy()
|
||||
environment["SOURCE_DATE_EPOCH"] = "100"
|
||||
result = subprocess.run(
|
||||
[
|
||||
str(PACKAGE),
|
||||
"--registry",
|
||||
str(self.registry),
|
||||
"--component",
|
||||
component,
|
||||
"--package-root",
|
||||
str(package_root),
|
||||
"--output",
|
||||
str(self.output),
|
||||
"--component-version",
|
||||
version,
|
||||
"--source-sha",
|
||||
("1" if component == "EchoionApi" else "2") * 40,
|
||||
"--source-tree-hash",
|
||||
"git-sha1:" + ("3" if component == "EchoionApi" else "4") * 40,
|
||||
"--abi-hash",
|
||||
"sha256:" + ("5" if component == "EchoionApi" else "6") * 64,
|
||||
],
|
||||
check=False,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
env=environment,
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
stem = f"{package_id}-{version}-linux-x86_64"
|
||||
return (
|
||||
self.output / f"{stem}.manifest.json",
|
||||
self.output / f"{stem}.tar.zst",
|
||||
)
|
||||
|
||||
def publish(
|
||||
self,
|
||||
component: str,
|
||||
manifest: Path,
|
||||
archive: Path,
|
||||
sequence: int,
|
||||
) -> subprocess.CompletedProcess[str]:
|
||||
return subprocess.run(
|
||||
[
|
||||
str(PUBLISH),
|
||||
"--registry",
|
||||
str(self.registry),
|
||||
"--component",
|
||||
component,
|
||||
"--manifest",
|
||||
str(manifest),
|
||||
"--archive",
|
||||
str(archive),
|
||||
"--feed-root",
|
||||
str(self.feed),
|
||||
"--base-url",
|
||||
"https://updates.example.test/echoion",
|
||||
"--artifact-base-url",
|
||||
"https://downloads.example.test/components",
|
||||
"--channel",
|
||||
"stable",
|
||||
"--sequence",
|
||||
str(sequence),
|
||||
"--generated-at",
|
||||
"2026-07-29T12:00:00Z",
|
||||
"--key-id",
|
||||
"test-key",
|
||||
"--private-key",
|
||||
str(self.key),
|
||||
],
|
||||
check=False,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def payload(path: Path) -> dict[str, object]:
|
||||
envelope = json.loads(path.read_text())
|
||||
encoded = envelope["payload"]
|
||||
raw = base64.urlsafe_b64decode(encoded + "=" * (-len(encoded) % 4))
|
||||
return json.loads(raw)
|
||||
|
||||
def test_single_component_publication_merges_catalog(self) -> None:
|
||||
api_manifest, api_archive = self.package(
|
||||
"EchoionApi", "echoion-api", "2.1.0"
|
||||
)
|
||||
api_result = self.publish(
|
||||
"EchoionApi", api_manifest, api_archive, 100
|
||||
)
|
||||
self.assertEqual(api_result.returncode, 0, api_result.stderr)
|
||||
web_manifest, web_archive = self.package(
|
||||
"EchoionWeb", "echoion-web", "2.0.1"
|
||||
)
|
||||
web_result = self.publish(
|
||||
"EchoionWeb", web_manifest, web_archive, 101
|
||||
)
|
||||
self.assertEqual(web_result.returncode, 0, web_result.stderr)
|
||||
|
||||
catalog = self.payload(self.feed / "feeds/stable/catalog.json")
|
||||
self.assertEqual(
|
||||
[item["componentId"] for item in catalog["components"]],
|
||||
["EchoionApi", "EchoionWeb"],
|
||||
)
|
||||
api = self.payload(
|
||||
self.feed / "feeds/stable/echoion-api/2.1.0.json"
|
||||
)
|
||||
self.assertNotIn("productVersion", api)
|
||||
for private_field in (
|
||||
"repository",
|
||||
"repositoryUrl",
|
||||
"cloneUrl",
|
||||
"giteaReleaseUrl",
|
||||
):
|
||||
self.assertNotIn(private_field, api)
|
||||
self.assertEqual(api["productCompatibility"], ">=2.0.0 <3.0.0")
|
||||
self.assertEqual(
|
||||
api["artifact"]["url"],
|
||||
"https://downloads.example.test/components/"
|
||||
"EchoionApi/2.1.0/echoion-api-2.1.0-linux-x86_64.tar.zst",
|
||||
)
|
||||
|
||||
def test_rejects_replay_without_mutating_lock(self) -> None:
|
||||
manifest, archive = self.package(
|
||||
"EchoionApi", "echoion-api", "2.0.1"
|
||||
)
|
||||
first = self.publish("EchoionApi", manifest, archive, 200)
|
||||
self.assertEqual(first.returncode, 0, first.stderr)
|
||||
replay = self.publish("EchoionApi", manifest, archive, 200)
|
||||
self.assertNotEqual(replay.returncode, 0)
|
||||
self.assertIn("sequence is not monotonic", replay.stderr)
|
||||
|
||||
def test_product_lock_verifies_against_independent_feeds(self) -> None:
|
||||
manifests: dict[str, Path] = {}
|
||||
for sequence, component, package_id, version in (
|
||||
(300, "EchoionApi", "echoion-api", "2.1.0"),
|
||||
(301, "EchoionWeb", "echoion-web", "2.0.1"),
|
||||
):
|
||||
manifest, archive = self.package(
|
||||
component, package_id, version
|
||||
)
|
||||
result = self.publish(component, manifest, archive, sequence)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
manifests[component] = manifest
|
||||
|
||||
locked: dict[str, object] = {}
|
||||
for component, manifest_path in manifests.items():
|
||||
manifest = json.loads(manifest_path.read_text())
|
||||
locked[component] = {
|
||||
"componentVersion": manifest["componentVersion"],
|
||||
"revision": manifest["sourceSha"],
|
||||
"sourceTreeHash": manifest["sourceTreeHash"],
|
||||
"abiHash": manifest["abiHash"],
|
||||
"artifactIdentity": manifest["artifactIdentity"],
|
||||
}
|
||||
lock = self.root / "components.lock.json"
|
||||
lock.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"schemaVersion": 2,
|
||||
"productVersion": "2.0.0",
|
||||
"components": locked,
|
||||
}
|
||||
)
|
||||
)
|
||||
result = subprocess.run(
|
||||
[
|
||||
str(VERIFY),
|
||||
"--registry",
|
||||
str(self.registry),
|
||||
"--lock",
|
||||
str(lock),
|
||||
"--feed-root",
|
||||
str(self.feed),
|
||||
"--channel",
|
||||
"stable",
|
||||
"--key-id",
|
||||
"test-key",
|
||||
"--public-key",
|
||||
str(self.public_key),
|
||||
],
|
||||
check=False,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertIn("verified 2 locked components", result.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Tests for independent component version derivation."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SCRIPT = ROOT / "scripts" / "prepare-component-release.py"
|
||||
|
||||
|
||||
class PrepareComponentReleaseTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.temporary = tempfile.TemporaryDirectory(
|
||||
prefix="echoion-prepare-component."
|
||||
)
|
||||
self.root = Path(self.temporary.name)
|
||||
self.repo = self.root / "repo"
|
||||
self.feed = self.root / "feed"
|
||||
self.repo.mkdir()
|
||||
subprocess.run(
|
||||
["git", "init", "-b", "main"],
|
||||
cwd=self.repo,
|
||||
check=True,
|
||||
stdout=subprocess.DEVNULL,
|
||||
)
|
||||
subprocess.run(
|
||||
["git", "config", "user.email", "test@example.invalid"],
|
||||
cwd=self.repo,
|
||||
check=True,
|
||||
)
|
||||
subprocess.run(
|
||||
["git", "config", "user.name", "Test"],
|
||||
cwd=self.repo,
|
||||
check=True,
|
||||
)
|
||||
(self.repo / "abi").mkdir()
|
||||
self.contract = self.repo / "abi/module.json"
|
||||
self.contract.write_text(
|
||||
json.dumps({"schemaVersion": 1, "functions": ["create"]})
|
||||
)
|
||||
self.commit("initial")
|
||||
self.initial_sha = self.git("rev-parse", "HEAD")
|
||||
self.registry = self.root / "components.json"
|
||||
self.registry.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"components": {
|
||||
"EchoionExample": {
|
||||
"repository": "Void/EchoionExample",
|
||||
"packageId": "echoion-example",
|
||||
"kind": "runtime-module",
|
||||
"activation": "restart-required",
|
||||
"dependencies": {},
|
||||
"abiContract": "abi/module.json",
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
self.configuration = self.root / "component.release.json"
|
||||
self.configuration.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"componentId": "EchoionExample",
|
||||
"productCompatibility": ">=2.0.0 <3.0.0",
|
||||
"cmakeOptions": {},
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def tearDown(self) -> None:
|
||||
self.temporary.cleanup()
|
||||
|
||||
def git(self, *arguments: str) -> str:
|
||||
return subprocess.check_output(
|
||||
["git", *arguments], cwd=self.repo, text=True
|
||||
).strip()
|
||||
|
||||
def commit(self, message: str) -> None:
|
||||
subprocess.run(["git", "add", "."], cwd=self.repo, check=True)
|
||||
subprocess.run(
|
||||
["git", "commit", "-m", message],
|
||||
cwd=self.repo,
|
||||
check=True,
|
||||
stdout=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
def state(self, version: str) -> None:
|
||||
path = self.feed / "state/components/EchoionExample.json"
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"schemaVersion": 2,
|
||||
"componentId": "EchoionExample",
|
||||
"lastSourceSha": self.initial_sha,
|
||||
"semVer": version,
|
||||
"channels": {},
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def run_prepare(
|
||||
self, version: str
|
||||
) -> subprocess.CompletedProcess[str]:
|
||||
return subprocess.run(
|
||||
[
|
||||
str(SCRIPT),
|
||||
"--registry",
|
||||
str(self.registry),
|
||||
"--configuration",
|
||||
str(self.configuration),
|
||||
"--repository",
|
||||
str(self.repo),
|
||||
"--feed-root",
|
||||
str(self.feed),
|
||||
"--channel",
|
||||
"stable",
|
||||
"--requested-version",
|
||||
version,
|
||||
],
|
||||
check=False,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
def test_initial_component_starts_at_2_0_0(self) -> None:
|
||||
result = self.run_prepare("2.0.0")
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(json.loads(result.stdout)["change"], "initial")
|
||||
|
||||
def test_append_only_contract_change_requires_minor(self) -> None:
|
||||
self.state("2.0.0")
|
||||
self.contract.write_text(
|
||||
json.dumps(
|
||||
{"schemaVersion": 1, "functions": ["create", "destroy"]}
|
||||
)
|
||||
)
|
||||
self.commit("append")
|
||||
rejected = self.run_prepare("2.0.1")
|
||||
self.assertNotEqual(rejected.returncode, 0)
|
||||
accepted = self.run_prepare("2.1.0")
|
||||
self.assertEqual(accepted.returncode, 0, accepted.stderr)
|
||||
self.assertEqual(json.loads(accepted.stdout)["change"], "minor")
|
||||
|
||||
def test_reordered_contract_requires_major(self) -> None:
|
||||
self.state("2.2.0")
|
||||
self.contract.write_text(
|
||||
json.dumps({"schemaVersion": 1, "functions": ["destroy", "create"]})
|
||||
)
|
||||
self.commit("breaking")
|
||||
accepted = self.run_prepare("3.0.0")
|
||||
self.assertEqual(accepted.returncode, 0, accepted.stderr)
|
||||
self.assertEqual(json.loads(accepted.stdout)["change"], "major")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user