okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
d8124515a
main
1"""#5080: the web page's About card said "MTP drafts up to 5 tokens" for an engine that ran the DFlash2 drafter (or none): the row named the MTP 2whatever /metrics said. The row now says that only when the engine's ``drafting`` is the MTP, or not reported (an older engine, which had only the MTP).""" 3 4import json 5import re 6import shutil 7import subprocess 8import tempfile 9import unittest 10from pathlib import Path 11 12APP = Path (__file__ ).resolve ().parent / "web" / "app.js" 13 14 15def speculation_expression ()-> str : 16line = next (ln for ln in APP .read_text (encoding = "utf-8" ).splitlines ()if ln .strip ().startswith ('["Speculation",' )) 17return re .match (r'\s*\["Speculation",\s*(.*)\],\s*$' ,line ).group (1 ) 18 19 20class SpeculationRow (unittest .TestCase ): 21def test_the_row_reads_the_engines_drafter (self ): 22self .assertRegex (speculation_expression (),r'eng\.drafting == null \|\| eng\.drafting === "mtp"' ) 23 24@ unittest . skipUnless ( shutil . which ( "node" ), "node is not on PATH" ) 25def test_what_the_row_says_for_each_drafter (self ): 26cases = {"dflash2" : {"spec" :6 ,"mtp_max" :6 ,"lookup" :3 ,"drafting" :"dflash2" }, 27"off" : {"spec" :4 ,"lookup" :3 ,"drafting" :"off" }, 28"mtp" : {"spec" :4 ,"lookup" :0 ,"drafting" :"mtp" }, 29"old" : {"spec" :4 ,"lookup" :3 }, 30"none" : {"spec" :0 ,"drafting" :"mtp" }} 31script = "const out = {};\n" + "" .join ( 32f"{{ const eng = { json . dumps ( eng ) } ; out[ { json . dumps ( k ) } ] = { speculation_expression () } ; }}\n" for k ,eng in cases .items ())+ \ 33"console.log(JSON.stringify(out));\n" 34with tempfile .TemporaryDirectory ()as d : 35path = Path (d )/ "row.js" 36path .write_text (script ,encoding = "utf-8" ) 37got = json .loads (subprocess .run ([shutil .which ("node" ),str (path )],capture_output = True ,text = True ,check = True ,timeout = 60 ).stdout ) 38self .assertIsNone (got ["dflash2" ],"a DFlash2 engine is not said to draft with the MTP" ) 39self .assertIsNone (got ["off" ]) 40self .assertEqual (got ["mtp" ],"MTP drafts up to 3 tokens" ) 41self .assertEqual (got ["old" ],"MTP drafts up to 3 tokens, prompt lookup on" ) 42self .assertIsNone (got ["none" ]) 43 44 45if __name__ == "__main__" : 46unittest .main ()