Release: cut over Echoion 2.0 components
Modular container CI / release-build (push) Has been cancelled
Modular container CI / release-build (push) Has been cancelled
This commit is contained in:
169 files changed
+3069
-32261
No files matched your search
+239
@@ -0,0 +1,239 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Offline tests for signed channel-separated component feed publication."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SCRIPT = ROOT / "scripts" / "publish-component-feeds.py"
|
||||
|
||||
|
||||
class ComponentFeedTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.temporary = tempfile.TemporaryDirectory(
|
||||
prefix="echoion-component-feed-test."
|
||||
)
|
||||
self.root = Path(self.temporary.name)
|
||||
self.artifacts = self.root / "artifacts"
|
||||
self.feeds = self.root / "feed"
|
||||
self.artifacts.mkdir()
|
||||
self.key = self.root / "feed-key.pem"
|
||||
subprocess.run(
|
||||
[
|
||||
"openssl",
|
||||
"genpkey",
|
||||
"-algorithm",
|
||||
"ED25519",
|
||||
"-out",
|
||||
str(self.key),
|
||||
],
|
||||
check=True,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
self.key.chmod(0o600)
|
||||
components = {
|
||||
"EchoionApi": {
|
||||
"repository": "Void/EchoionApi",
|
||||
"packageId": "echoion-api",
|
||||
"kind": "sdk",
|
||||
"activation": "restart-required",
|
||||
"dependencies": {},
|
||||
},
|
||||
"EchoionPluginExample": {
|
||||
"repository": "Void/EchoionPluginExample",
|
||||
"packageId": "echoion-plugin-example",
|
||||
"pluginId": "example",
|
||||
"kind": "plugin",
|
||||
"activation": "reloadable",
|
||||
"dependencies": {"EchoionApi": ">=2.0.0 <3.0.0"},
|
||||
},
|
||||
}
|
||||
self.registry = {"schemaVersion": 1, "components": components}
|
||||
locked = {}
|
||||
for index, component_id in enumerate(components, start=1):
|
||||
locked[component_id] = {
|
||||
"repository": components[component_id]["repository"],
|
||||
"revision": f"{index:040x}",
|
||||
"componentVersion": "2.0.0",
|
||||
"abiHash": f"sha256:{index:064x}",
|
||||
"sourceTreeHash": f"git-sha1:{index + 10:040x}",
|
||||
"artifactIdentity": (
|
||||
f"{components[component_id]['packageId']}-"
|
||||
"2.0.0-linux-x86_64"
|
||||
),
|
||||
}
|
||||
self.lock = {
|
||||
"schemaVersion": 2,
|
||||
"productVersion": "2.0.0",
|
||||
"components": locked,
|
||||
}
|
||||
self.registry_path = self.root / "components.json"
|
||||
self.lock_path = self.root / "components.lock.json"
|
||||
self.registry_path.write_text(json.dumps(self.registry))
|
||||
self.lock_path.write_text(json.dumps(self.lock))
|
||||
|
||||
def tearDown(self) -> None:
|
||||
self.temporary.cleanup()
|
||||
|
||||
def write_packages(self, channel: str, sequence: int) -> None:
|
||||
for component_id, definition in self.registry["components"].items():
|
||||
version = "2.0.0"
|
||||
if channel != "stable":
|
||||
version += f"-{channel}.{sequence}"
|
||||
stem = (
|
||||
f"{definition['packageId']}-{version}-linux-x86_64"
|
||||
)
|
||||
archive = self.artifacts / f"{stem}.tar.zst"
|
||||
archive.write_bytes(f"{component_id}:{channel}:{sequence}".encode())
|
||||
locked = self.lock["components"][component_id]
|
||||
manifest = {
|
||||
"schemaVersion": 1,
|
||||
"componentId": component_id,
|
||||
"packageId": definition["packageId"],
|
||||
"kind": definition["kind"],
|
||||
"productVersion": "2.0.0",
|
||||
"componentVersion": version,
|
||||
"sourceSha": locked["revision"],
|
||||
"sourceTreeHash": locked["sourceTreeHash"],
|
||||
"abiHash": locked["abiHash"],
|
||||
"artifactIdentity": stem,
|
||||
"activation": definition["activation"],
|
||||
"dependencies": definition["dependencies"],
|
||||
"platform": "linux",
|
||||
"architecture": "x86_64",
|
||||
"toolchainContract": "linux-x86_64-glibc-2.35-cxx26",
|
||||
}
|
||||
(self.artifacts / f"{stem}.manifest.json").write_text(
|
||||
json.dumps(manifest)
|
||||
)
|
||||
|
||||
def publish(
|
||||
self, channel: str, sequence: int, *, expect_success: bool = True
|
||||
) -> subprocess.CompletedProcess[str]:
|
||||
result = subprocess.run(
|
||||
[
|
||||
str(SCRIPT),
|
||||
"--registry",
|
||||
str(self.registry_path),
|
||||
"--lock",
|
||||
str(self.lock_path),
|
||||
"--artifacts",
|
||||
str(self.artifacts),
|
||||
"--feed-root",
|
||||
str(self.feeds),
|
||||
"--base-url",
|
||||
"https://updates.example.test/echoion",
|
||||
"--artifact-base-url",
|
||||
"https://updates.example.test/releases/v2.0.0",
|
||||
"--channel",
|
||||
channel,
|
||||
"--sequence",
|
||||
str(sequence),
|
||||
"--generated-at",
|
||||
"2026-07-28T12:00:00Z",
|
||||
"--key-id",
|
||||
"test-key",
|
||||
"--private-key",
|
||||
str(self.key),
|
||||
],
|
||||
check=False,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
if expect_success and result.returncode != 0:
|
||||
self.fail(result.stderr)
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def payload(path: Path) -> dict[str, object]:
|
||||
envelope = json.loads(path.read_text())
|
||||
encoded = envelope["payload"]
|
||||
decoded = base64.urlsafe_b64decode(encoded + "=" * (-len(encoded) % 4))
|
||||
return json.loads(decoded)
|
||||
|
||||
def test_stable_layout_and_catalog(self) -> None:
|
||||
self.write_packages("stable", 100)
|
||||
self.publish("stable", 100)
|
||||
catalog = self.payload(self.feeds / "feeds/stable/catalog.json")
|
||||
self.assertEqual(len(catalog["components"]), 2)
|
||||
self.assertTrue(
|
||||
(self.feeds / "feeds/stable/echoion-api/2.0.0.json").is_file()
|
||||
)
|
||||
self.assertTrue(
|
||||
(
|
||||
self.feeds
|
||||
/ "feeds/stable/plugins/example/2.0.0.json"
|
||||
).is_file()
|
||||
)
|
||||
state = json.loads(
|
||||
(
|
||||
self.feeds
|
||||
/ "state/components/EchoionPluginExample.json"
|
||||
).read_text()
|
||||
)
|
||||
self.assertEqual(state["semVer"], "2.0.0")
|
||||
self.assertEqual(state["sequence"], 100)
|
||||
release = self.payload(
|
||||
self.feeds / "feeds/stable/echoion-api/2.0.0.json"
|
||||
)
|
||||
self.assertEqual(release["artifactIdentity"], "echoion-api-2.0.0-linux-x86_64")
|
||||
self.assertEqual(release["platform"], "linux")
|
||||
self.assertEqual(release["architecture"], "x86_64")
|
||||
self.assertEqual(
|
||||
release["toolchainContract"],
|
||||
"linux-x86_64-glibc-2.35-cxx26",
|
||||
)
|
||||
|
||||
def test_rejects_replay_and_immutable_artifact_change(self) -> None:
|
||||
self.write_packages("stable", 100)
|
||||
self.publish("stable", 100)
|
||||
replay = self.publish("stable", 100, expect_success=False)
|
||||
self.assertNotEqual(replay.returncode, 0)
|
||||
for archive in self.artifacts.glob("*.tar.zst"):
|
||||
archive.write_bytes(archive.read_bytes() + b"changed")
|
||||
conflict = self.publish("stable", 101, expect_success=False)
|
||||
self.assertNotEqual(conflict.returncode, 0)
|
||||
self.assertIn("unchanged source SHA", conflict.stderr)
|
||||
|
||||
def test_beta_does_not_advance_stable_state(self) -> None:
|
||||
self.write_packages("stable", 100)
|
||||
self.publish("stable", 100)
|
||||
for path in self.artifacts.iterdir():
|
||||
path.unlink()
|
||||
self.write_packages("beta", 200)
|
||||
self.publish("beta", 200)
|
||||
state = json.loads(
|
||||
(
|
||||
self.feeds / "state/components/EchoionApi.json"
|
||||
).read_text()
|
||||
)
|
||||
self.assertEqual(state["semVer"], "2.0.0")
|
||||
self.assertEqual(state["sequence"], 100)
|
||||
self.assertEqual(state["channels"]["beta"]["version"], "2.0.0-beta.200")
|
||||
beta_release = self.payload(
|
||||
self.feeds
|
||||
/ "feeds/beta/echoion-api/2.0.0-beta.200.json"
|
||||
)
|
||||
self.assertEqual(
|
||||
beta_release["artifactIdentity"],
|
||||
"echoion-api-2.0.0-beta.200-linux-x86_64",
|
||||
)
|
||||
self.assertTrue(
|
||||
(
|
||||
self.feeds
|
||||
/ "feeds/beta/echoion-api/2.0.0-beta.200.json"
|
||||
).is_file()
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user