okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-ds-out ac306afb2 into f-own-intaff3a132f

main
5.7 KiB101 linesraw
1"""build-feed --carry-dsv41 (owner 11-11, "Keep frozen"): the last feed's DeepSeek engine packages go into the new feed as they were, with each
2package URL made absolute to the release that holds the archive, so Strata 0.2.13 and earlier keep their DeepSeek engine; this Strata never
3reads the member.  No network: the reader path an older Control takes is the entry schema (feed._engine_package, unchanged since 0.2.7) and
4the reference resolver (transfer.resolve_ref), both run on the carried entry here."""
5from __future__ import annotations
6
7import io
8import json
9import sys
10import tempfile
11import unittest
12from contextlib import redirect_stderr, redirect_stdout
13from pathlib import Path
14
15ROOT = Path(__file__).resolve().parents[2]
16sys.path.insert(0, str(ROOT))
17sys.path.insert(0, str(ROOT / "packaging"))
18
19import feed_tool  # noqa: E402
20from strata_control import feed as feedmod, transfer  # noqa: E402
21
22BASE = "https://github.com/Niko1221/Strata/releases/download/v0.2.13.1/"
23FEED_URL = "https://github.com/Niko1221/Strata/releases/latest/download/strata-feed.json"
24
25
26def entry(url):
27    return {"version": "0.1.59", "platform": "linux-x86_64", "backend": "cuda", "variant": "cuda13", "archs": ["sm_86", "sm_89", "sm_120", "compute_120"],
28            "min_driver": {"nvidia": "580.65"}, "min_runtime": None, "build_id": "b", "format": "tar.gz", "url": url, "size": 1000,
29            "sha256": "a" * 64, "manifest_sha256": "b" * 64, "installed_bytes": 2000, "notes": ""}
30
31
32def previous(folder: Path, packages) -> Path:
33    p = folder / "strata-feed.json"
34    p.write_text(json.dumps({"schema_version": 1, "feed": "strata-updates", "sequence": 122, "engine": {"packages": []},
35                             "dsv41": {"packages": packages}}), encoding="utf-8")
36    return p
37
38
39class Carry(unittest.TestCase):
40    def test_relative_urls_become_absolute_and_the_rest_is_kept(self):
41        with tempfile.TemporaryDirectory() as d:
42            flat = entry("strata-dsv41-0.1.59-linux-x86_64-cuda-cuda13.tar.gz")
43            local = entry("dsv41/strata-dsv41-0.1.59-linux-x86_64-cuda-cuda13.tar.gz")
44            absolute = entry("https://example.org/x/strata-dsv41-0.1.59-macos-arm64-metal-folder.tar.gz")
45            member = feed_tool.carried_dsv41(previous(Path(d), [flat, local, absolute]), BASE)
46        urls = [p["url"] for p in member["packages"]]
47        self.assertEqual(urls, [BASE + "strata-dsv41-0.1.59-linux-x86_64-cuda-cuda13.tar.gz"] * 2 + [absolute["url"]])
48        for got, was in zip(member["packages"], (flat, local, absolute)):
49            self.assertEqual({k: v for k, v in got.items() if k != "url"}, {k: v for k, v in was.items() if k != "url"})
50
51    def test_the_placeholder_or_a_bad_base_stops_the_build(self):
52        with tempfile.TemporaryDirectory() as d:
53            prev = previous(Path(d), [entry("a.tar.gz")])
54            for base in (feed_tool.DSV41_BASE_EXAMPLE, "http://example.org/r/", "https://example.org/r", "", None):
55                with self.assertRaises(SystemExit, msg=repr(base)):
56                    feed_tool.carried_dsv41(prev, base)
57            empty = Path(d) / "empty.json"
58            empty.write_text(json.dumps({"schema_version": 1}), encoding="utf-8")
59            with self.assertRaises(SystemExit):
60                feed_tool.carried_dsv41(empty, BASE)
61
62    def test_build_feed_needs_a_choice(self):
63        with tempfile.TemporaryDirectory() as d:
64            feed_tool.keygen(Path(d) / "keys")
65            args = ["build-feed", "--out", str(Path(d) / "rel"), "--key", str(Path(d) / "keys" / "feed-key.json"), "--sequence", "123"]
66            for extra in ([], ["--no-dsv41-carry", "--carry-dsv41", str(previous(Path(d), [entry("a.tar.gz")]))]):
67                with self.assertRaises(SystemExit), redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()):
68                    feed_tool.main(args + extra)
69            with redirect_stdout(io.StringIO()):
70                feed_tool.main(args + ["--carry-dsv41", str(previous(Path(d), [entry("a.tar.gz")])), "--carry-dsv41-base", BASE])
71            doc = json.loads((Path(d) / "rel" / feedmod.FEED_NAME).read_text(encoding="utf-8"))
72            self.assertEqual(doc["dsv41"]["packages"][0]["url"], BASE + "a.tar.gz")
73            with redirect_stdout(io.StringIO()):
74                feed_tool.main(args[:2] + [str(Path(d) / "rel2")] + args[3:] + ["--no-dsv41-carry"])
75            self.assertNotIn("dsv41", json.loads((Path(d) / "rel2" / feedmod.FEED_NAME).read_text(encoding="utf-8")))
76
77
78class OlderControlReadsIt(unittest.TestCase):
79    """What a 0.2.13 Control does with the member: each package through the engine entry schema, then its URL through resolve_ref
80    against the feed's own address (an absolute https URL is taken as it is: no fetch here)."""
81
82    def test_the_carried_entry_is_a_valid_package_with_an_absolute_https_url(self):
83        with tempfile.TemporaryDirectory() as d:
84            member = feed_tool.carried_dsv41(previous(Path(d), [entry("strata-dsv41-0.1.59-linux-x86_64-cuda-cuda13.tar.gz")]), BASE)
85        item = member["packages"][0]
86        skipped: list = []
87        pkg = feedmod._engine_package(item, skipped)
88        self.assertIsNotNone(pkg, skipped)
89        self.assertEqual(skipped, [])
90        base = transfer.base_of(FEED_URL)
91        self.assertEqual(transfer.resolve_ref(base, pkg.url), BASE + "strata-dsv41-0.1.59-linux-x86_64-cuda-cuda13.tar.gz")
92        # the relative form would have pointed at the NEW release, which does not hold the archive
93        self.assertTrue(transfer.resolve_ref(base, "strata-dsv41-0.1.59-linux-x86_64-cuda-cuda13.tar.gz").startswith(
94            "https://github.com/Niko1221/Strata/releases/latest/download/"))
95
96    def test_this_control_ignores_the_member(self):
97        self.assertFalse(hasattr(feedmod.Feed, "dsv41"))
98
99
100if __name__ == "__main__":
101    unittest.main()