Linux ARM64 reads its own signed feed file (strata-feed-linux-aarch64.json): a Control up to 0.1.52 refuses a feed with a platform it does not know, so the aarch64 entries stay out of strata-feed.json
This commit is contained in:
1 parent
87a755bf1e
commit
39c5534ed3
6 files changed
+208
-8
No files matched your search
@@ -181,6 +181,8 @@ was made (a second `sign-and-notarize.sh` run) makes a new archive: sign and add
|
||||
`build-feed` leaves a pack in the wrong format out of the manifest and says so. Pack Control for every platform you want the one-line install to cover (`install.sh` knows `linux-x86_64`, `linux-aarch64` and `macos-arm64`, `install.ps1` `windows-x86_64`);
|
||||
a platform with no line gets "this release has no Terminal for <platform>". Upload `install.sh` and `install.ps1` from `packaging/` unchanged: their built-in address is the release folder.
|
||||
|
||||
**Linux ARM64 (DGX Spark) has its own feed file.** A Control up to 0.1.52 refuses a feed that names a platform it does not know (`the feed's control entry names an unknown platform`), so the `linux-aarch64` entries are not in `strata-feed.json`, which every released client reads. They are in `strata-feed-linux-aarch64.json` (+ `.sig`, same format, same key, its own `sequence`, aarch64 entries only), uploaded to the same release. A Linux ARM64 Terminal reads that file by default, from a folder or a release address (`strata_control.feed.feed_name()`); a source that names its own `.json` file is used as given. Until every client skips unknown platforms, each release must publish both files, and the aarch64 file's sequence must never go down.
|
||||
|
||||
The feed is hosted as the files of a GitHub release of `Niko1221/Strata`. The built-in address is
|
||||
`https://github.com/Niko1221/Strata/releases/latest/download` (`strata_cli/update_cmd.py` `DEFAULT_FEED` adds `/strata-feed.json`; `install.sh`
|
||||
and `install.ps1` use the folder). GitHub assets are flat, so build the packages with `--url-prefix ""` and upload every file of the release folder
|
||||
|
||||
@@ -106,6 +106,9 @@ def main(argv=None) -> int:
|
||||
shutil.rmtree(copy.parent, ignore_errors=True)
|
||||
ft.build_feed(out, key=key, sequence=a.sequence, channel=a.channel, engine_dir=out / "engine" if a.engine else None,
|
||||
control_dir=out / "control" if a.terminal else None, dsv41_dir=out / "dsv41" if a.dsv41 else None)
|
||||
if any("linux-aarch64" in p.name for p in (out / "control").glob("*.entry.json")): # the Linux ARM64 Terminal reads its own feed file (same bytes here)
|
||||
for suffix in ("", ".sig"):
|
||||
shutil.copy2(out / ("strata-feed.json" + suffix), out / ("strata-feed-linux-aarch64.json" + suffix))
|
||||
base = a.url.rstrip("/")
|
||||
for name in ("install.sh", "install.ps1"):
|
||||
text = (ROOT / "packaging" / name).read_text(encoding="utf-8").replace(RELEASE_FEED, base)
|
||||
|
||||
@@ -24,9 +24,16 @@ from pathlib import Path
|
||||
#: one-line installers use). Only a feed signed with a key in update_keys.json (or STRATA_UPDATE_TRUSTED_KEYS) is accepted.
|
||||
DEFAULT_FEED = "https://github.com/Niko1221/Strata/releases/latest/download/strata-feed.json"
|
||||
ENV_FEED = "STRATA_UPDATE_FEED"
|
||||
|
||||
ENV_APP_VERSION = "STRATA_APP_VERSION"
|
||||
|
||||
|
||||
def default_feed() -> str:
|
||||
"""DEFAULT_FEED for this machine: a Linux ARM64 machine (the DGX Spark) reads strata-feed-linux-aarch64.json from the same release."""
|
||||
from strata_control import feed as feedmod
|
||||
return DEFAULT_FEED.rsplit("/", 1)[0] + "/" + feedmod.feed_name()
|
||||
|
||||
|
||||
def _common(p: argparse.ArgumentParser) -> None:
|
||||
p.add_argument("--feed", default=None, help=f"where the signed update feed is (URL or folder). Default: ${ENV_FEED}, the feed used last, or the project's")
|
||||
p.add_argument("--components-dir", default=None, help="the component folder (default: the per-user one, or STRATA_COMPONENTS_DIR)")
|
||||
@@ -94,7 +101,9 @@ def _feed_source(a, root: Path) -> str:
|
||||
if os.environ.get(ENV_FEED):
|
||||
return os.environ[ENV_FEED]
|
||||
remembered = (updater.State(root).data.get("feed") or {}).get("source")
|
||||
return remembered if _may_be_remembered(remembered) else DEFAULT_FEED
|
||||
if remembered == DEFAULT_FEED: # the common feed remembered from before: a Linux ARM64 machine reads its own file
|
||||
return default_feed()
|
||||
return remembered if _may_be_remembered(remembered) else default_feed()
|
||||
|
||||
|
||||
def _may_be_remembered(source) -> bool:
|
||||
|
||||
+19
-3
@@ -27,10 +27,13 @@ import re
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from strata_control import signing, transfer
|
||||
from strata_control.targets import BACKEND_MATRIX
|
||||
from strata_control.targets import BACKEND_MATRIX, host_platform
|
||||
|
||||
SCHEMA_VERSION = 1
|
||||
FEED_NAME = "strata-feed.json"
|
||||
#: The Linux ARM64 (DGX Spark) Terminal reads this file instead. A Control older than 0.1.53 refuses a feed that names a platform it does not know, so
|
||||
#: the linux-aarch64 entries cannot sit in strata-feed.json: that file stays as every released client can read it. Same format, same key.
|
||||
AARCH64_FEED_NAME = "strata-feed-linux-aarch64.json"
|
||||
SIGNATURE_SUFFIX = ".sig"
|
||||
FORMATS = ("tar.gz", "tar.xz", "zip")
|
||||
PLATFORMS = ("windows-x86_64", "linux-x86_64", "linux-aarch64", "macos-arm64", "macos-x86_64")
|
||||
@@ -339,6 +342,17 @@ def verify_and_parse(payload: bytes, signature_bytes: bytes, *, source: str, tru
|
||||
return feed
|
||||
|
||||
|
||||
def feed_name(platform: str | None = None) -> str:
|
||||
"""The feed file this machine reads from a folder or a release address: ``strata-feed-linux-aarch64.json`` on a Linux ARM64 machine, else
|
||||
``strata-feed.json``. A source that names its file (``.../x.json``) is used as given, whatever the machine."""
|
||||
if platform is None:
|
||||
try:
|
||||
platform = host_platform()
|
||||
except Exception: # noqa: BLE001 - an unknown OS reads the common feed
|
||||
platform = None
|
||||
return AARCH64_FEED_NAME if platform == "linux-aarch64" else FEED_NAME
|
||||
|
||||
|
||||
def fetch(source: str, trusted: dict[str, bytes], **guards) -> Feed:
|
||||
"""Read the feed and its signature from `source` (an https URL, a loopback http URL, a file URL or a folder/file path)."""
|
||||
if not trusted:
|
||||
@@ -348,9 +362,11 @@ def fetch(source: str, trusted: dict[str, bytes], **guards) -> Feed:
|
||||
if transfer.kind_of(source) == "path":
|
||||
path = transfer._local_path(source)
|
||||
if path.is_dir():
|
||||
location = str(path / FEED_NAME)
|
||||
location = str(path / feed_name())
|
||||
if not (path / feed_name()).is_file() and (path / FEED_NAME).is_file():
|
||||
location = str(path / FEED_NAME) # a local folder made for the common feed (a test feed, an offline copy)
|
||||
elif transfer.kind_of(source) in ("http", "https") and not source.rsplit("/", 1)[-1].endswith(".json"):
|
||||
location = source.rstrip("/") + "/" + FEED_NAME
|
||||
location = source.rstrip("/") + "/" + feed_name()
|
||||
try:
|
||||
payload = transfer.read_small(location)
|
||||
signature = transfer.read_small(location + SIGNATURE_SUFFIX)
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
"""The Linux ARM64 (DGX Spark) Terminal reads strata-feed-linux-aarch64.json; every other machine reads strata-feed.json, as before.
|
||||
|
||||
Why: a Control older than 0.1.53 refuses a feed that names a platform it does not know, so the linux-aarch64 entries cannot be in the common
|
||||
feed. Same format, same signing key; only the file name differs.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from unittest import mock
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(ROOT / "packaging"))
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
import feed_tool # noqa: E402
|
||||
from strata_cli import update_cmd # noqa: E402
|
||||
from strata_control import feed as feedmod # noqa: E402
|
||||
from strata_control import updater # noqa: E402
|
||||
|
||||
COMMON = "strata-feed.json"
|
||||
ARM = "strata-feed-linux-aarch64.json"
|
||||
RELEASE = "https://github.com/Niko1221/Strata/releases/latest/download"
|
||||
|
||||
|
||||
def host(platform):
|
||||
return mock.patch("strata_control.feed.host_platform", return_value=platform)
|
||||
|
||||
|
||||
class FeedFileName(unittest.TestCase):
|
||||
def test_names(self):
|
||||
self.assertEqual(feedmod.feed_name("linux-aarch64"), ARM)
|
||||
for plat in ("windows-x86_64", "linux-x86_64", "macos-arm64", "macos-x86_64"):
|
||||
self.assertEqual(feedmod.feed_name(plat), COMMON)
|
||||
|
||||
def test_the_machine_decides(self):
|
||||
with host("linux-aarch64"):
|
||||
self.assertEqual(feedmod.feed_name(), ARM)
|
||||
with host("linux-x86_64"):
|
||||
self.assertEqual(feedmod.feed_name(), COMMON)
|
||||
|
||||
def test_an_unknown_os_reads_the_common_feed(self):
|
||||
with mock.patch("strata_control.feed.host_platform", side_effect=RuntimeError("no")):
|
||||
self.assertEqual(feedmod.feed_name(), COMMON)
|
||||
|
||||
def test_the_common_name_and_default_are_unchanged(self):
|
||||
self.assertEqual(feedmod.FEED_NAME, COMMON)
|
||||
self.assertEqual(update_cmd.DEFAULT_FEED, RELEASE + "/" + COMMON)
|
||||
|
||||
|
||||
class DefaultSource(unittest.TestCase):
|
||||
def source(self, remembered=None, feed=None, env=None):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
if remembered:
|
||||
state = updater.State(root)
|
||||
state.data["feed"] = {"source": remembered}
|
||||
state.save()
|
||||
with mock.patch.dict("os.environ", {}, clear=False):
|
||||
import os
|
||||
os.environ.pop(update_cmd.ENV_FEED, None)
|
||||
if env:
|
||||
os.environ[update_cmd.ENV_FEED] = env
|
||||
return update_cmd._feed_source(SimpleNamespace(feed=feed), root)
|
||||
|
||||
def test_arm64_linux_defaults_to_its_own_file(self):
|
||||
with host("linux-aarch64"):
|
||||
self.assertEqual(update_cmd.default_feed(), RELEASE + "/" + ARM)
|
||||
self.assertEqual(self.source(), RELEASE + "/" + ARM)
|
||||
|
||||
def test_the_common_feed_remembered_from_before_does_not_stick_on_arm64(self):
|
||||
with host("linux-aarch64"):
|
||||
self.assertEqual(self.source(remembered=update_cmd.DEFAULT_FEED), RELEASE + "/" + ARM)
|
||||
|
||||
def test_other_machines_are_unchanged(self):
|
||||
for plat in ("windows-x86_64", "linux-x86_64", "macos-arm64"):
|
||||
with host(plat):
|
||||
self.assertEqual(self.source(), update_cmd.DEFAULT_FEED)
|
||||
self.assertEqual(self.source(remembered=update_cmd.DEFAULT_FEED), update_cmd.DEFAULT_FEED)
|
||||
|
||||
def test_an_explicit_feed_wins_on_arm64(self):
|
||||
with host("linux-aarch64"):
|
||||
self.assertEqual(self.source(feed="https://mirror.example/f.json"), "https://mirror.example/f.json")
|
||||
self.assertEqual(self.source(env="/tmp/feed"), "/tmp/feed")
|
||||
self.assertEqual(self.source(feed="http://127.0.0.1:9", env="/tmp/feed"), "http://127.0.0.1:9")
|
||||
|
||||
def test_a_remembered_mirror_is_kept_on_arm64(self):
|
||||
with host("linux-aarch64"):
|
||||
self.assertEqual(self.source(remembered="https://mirror.example/f.json"), "https://mirror.example/f.json")
|
||||
|
||||
|
||||
class ReadsTheRightFile(unittest.TestCase):
|
||||
"""feed.fetch against a folder and against a release address: which file is asked for."""
|
||||
|
||||
def setUp(self):
|
||||
self._tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self._tmp.cleanup)
|
||||
self.dir = Path(self._tmp.name)
|
||||
feed_tool.keygen(self.dir / "keys")
|
||||
self.key = feed_tool._load_key(self.dir / "keys" / "feed-key.json")
|
||||
self.trusted = {self.key["key_id"]: __import__("base64").b64decode(self.key["public"])}
|
||||
|
||||
def write(self, folder, name, sequence):
|
||||
tmp = folder / "_tmp"
|
||||
feed_tool.build_feed(tmp, key=self.key, sequence=sequence)
|
||||
for suffix in ("", ".sig"):
|
||||
shutil.copy2(tmp / ("strata-feed.json" + suffix), folder / (name + suffix))
|
||||
shutil.rmtree(tmp)
|
||||
|
||||
def test_a_folder_with_both_files(self):
|
||||
folder = self.dir / "both"
|
||||
folder.mkdir()
|
||||
self.write(folder, COMMON, 115)
|
||||
self.write(folder, ARM, 116)
|
||||
with host("linux-aarch64"):
|
||||
self.assertEqual(feedmod.fetch(str(folder), self.trusted).sequence, 116)
|
||||
for plat in ("windows-x86_64", "linux-x86_64", "macos-arm64"):
|
||||
with host(plat):
|
||||
self.assertEqual(feedmod.fetch(str(folder), self.trusted).sequence, 115)
|
||||
|
||||
def test_a_folder_made_for_the_common_feed_still_works_on_arm64(self):
|
||||
folder = self.dir / "common"
|
||||
folder.mkdir()
|
||||
self.write(folder, COMMON, 7)
|
||||
with host("linux-aarch64"):
|
||||
self.assertEqual(feedmod.fetch(str(folder), self.trusted).sequence, 7)
|
||||
|
||||
def test_a_named_file_is_used_as_given(self):
|
||||
folder = self.dir / "named"
|
||||
folder.mkdir()
|
||||
self.write(folder, COMMON, 115)
|
||||
self.write(folder, ARM, 116)
|
||||
with host("linux-aarch64"):
|
||||
self.assertEqual(feedmod.fetch(str(folder / COMMON), self.trusted).sequence, 115)
|
||||
with host("linux-x86_64"):
|
||||
self.assertEqual(feedmod.fetch(str(folder / ARM), self.trusted).sequence, 116)
|
||||
|
||||
def test_a_release_address_asks_for_the_machines_file(self):
|
||||
asked = []
|
||||
|
||||
def read_small(location, **kw):
|
||||
asked.append(location)
|
||||
raise feedmod.transfer.TransferError("stop here")
|
||||
|
||||
with mock.patch("strata_control.feed.transfer.read_small", side_effect=read_small):
|
||||
for plat, want in (("linux-aarch64", ARM), ("linux-x86_64", COMMON), ("windows-x86_64", COMMON), ("macos-arm64", COMMON)):
|
||||
asked.clear()
|
||||
with host(plat), self.assertRaises(feedmod.FeedError):
|
||||
feedmod.fetch(RELEASE, self.trusted)
|
||||
self.assertEqual(asked[0], RELEASE + "/" + want, plat)
|
||||
asked.clear()
|
||||
with host("linux-aarch64"), self.assertRaises(feedmod.FeedError):
|
||||
feedmod.fetch(RELEASE + "/" + COMMON, self.trusted)
|
||||
self.assertEqual(asked[0], RELEASE + "/" + COMMON)
|
||||
|
||||
|
||||
class CommonFeedStaysReadableByOldClients(unittest.TestCase):
|
||||
def test_the_published_parser_set_is_the_reason(self):
|
||||
"""The platforms a 0.1.52 Control accepts are the four below; a feed with a fifth is refused whole, which is why linux-aarch64 has its own file."""
|
||||
self.assertEqual(sorted(set(feedmod.PLATFORMS) - {"linux-aarch64"}),
|
||||
["linux-x86_64", "macos-arm64", "macos-x86_64", "windows-x86_64"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -25,17 +25,17 @@ class FeedMemoryTest(unittest.TestCase):
|
||||
return update_cmd._feed_source(SimpleNamespace(feed=args.get("feed")), Path(tmp))
|
||||
|
||||
def test_a_loopback_test_feed_is_forgotten(self):
|
||||
self.assertEqual(self.source("http://127.0.0.1:18831"), update_cmd.DEFAULT_FEED)
|
||||
self.assertEqual(self.source("http://127.0.0.1:18831"), update_cmd.default_feed())
|
||||
|
||||
def test_a_local_folder_is_forgotten(self):
|
||||
self.assertEqual(self.source(r"C:\rel\FEED-interim"), update_cmd.DEFAULT_FEED)
|
||||
self.assertEqual(self.source("/tmp/feed"), update_cmd.DEFAULT_FEED)
|
||||
self.assertEqual(self.source(r"C:\rel\FEED-interim"), update_cmd.default_feed())
|
||||
self.assertEqual(self.source("/tmp/feed"), update_cmd.default_feed())
|
||||
|
||||
def test_an_https_mirror_is_kept(self):
|
||||
self.assertEqual(self.source("https://mirror.example.com/strata-feed.json"), "https://mirror.example.com/strata-feed.json")
|
||||
|
||||
def test_nothing_remembered_is_the_project_feed(self):
|
||||
self.assertEqual(self.source(None), update_cmd.DEFAULT_FEED)
|
||||
self.assertEqual(self.source(None), update_cmd.default_feed())
|
||||
|
||||
def test_a_named_feed_still_wins(self):
|
||||
self.assertEqual(self.source("https://a.example/f.json", feed="http://127.0.0.1:1"), "http://127.0.0.1:1")
|
||||
|
||||
Reference in new issue
Block a user