okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0fdfa40b4
main
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 ): 21m = {"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 }]}]} 23m .update (kw ) 24return m 25 26 27class FeedModelsOnTheModelScreen (Base ): 28def setUp (self ): 29super ().setUp () 30self .key = signing .generate_key () 31keys = os .path .join (self .home .tmp .name ,"keys.json" ) 32with open (keys ,"w" ,encoding = "utf-8" )as f : 33json .dump ({"keys" : [signing .public_part (self .key )]},f ) 34p = mock .patch .dict (os .environ , {"STRATA_UPDATE_TRUSTED_KEYS" :keys }) 35p .start () 36self .addCleanup (p .stop ) 37 38def keep_feed (self ,models ): 39doc = {"schema_version" :1 ,"feed" :"strata-updates" ,"channel" :"stable" ,"sequence" :3 ,"generated_at" :"2026-11-06T00:00:00Z" ,"expires_at" :None } 40if models is not None : 41doc ["models" ]= {"packages" :models } 42raw = (json .dumps (doc ,sort_keys = True )+ "\n" ).encode () 43sig = json .dumps (signing .sign_bytes (self .key ,raw )).encode () 44feed_models .remember (_with_signature (raw ,sig ,self .key )) 45 46def test_a_model_this_strata_does_not_know_is_named_with_the_reason (self ): 47self .keep_feed ([entry ()]) 48 49async def case (app ,pilot ,ctx ): 50await press (pilot ,"enter" ) 51t = " " .join (text_of (app ).split ()) 52self .assertIn ("Which model?" ,t ) 53self .assertIn ("Later One: " + feed_models .UNAVAILABLE_UNKNOWN ,t ) 54self .assertNotIn ("qwen5new" ,t )# the family name is for the log, not for people 55self .run_app (case ,ctx = make_ctx ()) 56 57def test_a_feed_without_models_changes_nothing (self ): 58self .keep_feed (None ) 59 60async def case (app ,pilot ,ctx ): 61await press (pilot ,"enter" ) 62t = text_of (app ) 63self .assertNotIn ("update Strata to use it" ,t ) 64self .assertIn ("Which model?" ,t ) 65self .run_app (case ,ctx = make_ctx ()) 66 67 68def _with_signature (raw :bytes ,sig :bytes ,key :dict ): 69import dataclasses 70feed = feedmod .verify_and_parse (raw ,sig ,source = "x" ,trusted = {key ["key_id" ]:base64 .b64decode (key ["public" ])}) 71return dataclasses .replace (feed ,signature = sig ) 72 73 74if __name__ == "__main__" : 75unittest .main ()