okami.mom/strata

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

Niko1221Merge f-q4-feedmodels (d4b72bc90): the signed feed's optional models member (strata_control/feed.py, feed_models.py), setup tables and prescan, tools/strata_mcp.py catalog, packaging/feed_tool.py --models/model-files/verify-feed, the app family menu (Qwen4 prep)0fdfa40b4

main
3.1 KiB75 linesraw
1"""The model screen of `strata launch` with models from the signed feed: a model this Strata does not know is named under the list with the plain reason, and a feed
2without models changes nothing on the screen. No engine is needed: the list comes from the cached feed in the test's own components folder (a throwaway key)."""
3
4from __future__ import annotations
5
6import base64
7import json
8import os
9import unittest
10from unittest import mock
11
12from strata_control import feed as feedmod
13from strata_control import feed_models, signing
14from tests.terminal.launch_support import text_of
15from tests.terminal.test_launch_tui import Base, make_ctx, press
16
17REV = "0123456789abcdef0123456789abcdef01234567"
18
19
20def entry(**kw):
21    m = {"id": "later-one", "title": "Later One", "by": "Someone", "licence": "Apache 2.0", "licence_url": "https://example.org/l", "family": "qwen5new",
22         "repo": "test/Later-GGUF", "revision": REV, "quants": [{"name": "Q4", "ram_gb": 24, "files": [{"name": "later-Q4.gguf", "size": 10, "sha256": "a" * 64}]}]}
23    m.update(kw)
24    return m
25
26
27class FeedModelsOnTheModelScreen(Base):
28    def setUp(self):
29        super().setUp()
30        self.key = signing.generate_key()
31        keys = os.path.join(self.home.tmp.name, "keys.json")
32        with open(keys, "w", encoding="utf-8") as f:
33            json.dump({"keys": [signing.public_part(self.key)]}, f)
34        p = mock.patch.dict(os.environ, {"STRATA_UPDATE_TRUSTED_KEYS": keys})
35        p.start()
36        self.addCleanup(p.stop)
37
38    def keep_feed(self, models):
39        doc = {"schema_version": 1, "feed": "strata-updates", "channel": "stable", "sequence": 3, "generated_at": "2026-11-06T00:00:00Z", "expires_at": None}
40        if models is not None:
41            doc["models"] = {"packages": models}
42        raw = (json.dumps(doc, sort_keys=True) + "\n").encode()
43        sig = json.dumps(signing.sign_bytes(self.key, raw)).encode()
44        feed_models.remember(_with_signature(raw, sig, self.key))
45
46    def test_a_model_this_strata_does_not_know_is_named_with_the_reason(self):
47        self.keep_feed([entry()])
48
49        async def case(app, pilot, ctx):
50            await press(pilot, "enter")
51            t = " ".join(text_of(app).split())
52            self.assertIn("Which model?", t)
53            self.assertIn("Later One: " + feed_models.UNAVAILABLE_UNKNOWN, t)
54            self.assertNotIn("qwen5new", t)                                  # the family name is for the log, not for people
55        self.run_app(case, ctx=make_ctx())
56
57    def test_a_feed_without_models_changes_nothing(self):
58        self.keep_feed(None)
59
60        async def case(app, pilot, ctx):
61            await press(pilot, "enter")
62            t = text_of(app)
63            self.assertNotIn("update Strata to use it", t)
64            self.assertIn("Which model?", t)
65        self.run_app(case, ctx=make_ctx())
66
67
68def _with_signature(raw: bytes, sig: bytes, key: dict):
69    import dataclasses
70    feed = feedmod.verify_and_parse(raw, sig, source="x", trusted={key["key_id"]: base64.b64decode(key["public"])})
71    return dataclasses.replace(feed, signature=sig)
72
73
74if __name__ == "__main__":
75    unittest.main()