okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1/** The host's launch-policy tables come from strata_control (policy-generated.mjs, written by python -m strata_control.app_policy; tests/terminal/test_app_policy.py checks the file is current). 2* Here: the host really uses them, and the screen's own copy of the family list (src/lib/drafting.ts) is the same list. */ 3import test from 'node:test' ; 4import assert from 'node:assert/strict' ; 5import { readFile } from 'node:fs/promises' ; 6import { SPEED_SWITCH_TABLE , DRAFTING_FAMILIES , DFLASH2_MODEL_PATTERN } from '../server/policy-generated.mjs' ; 7import { transform } from 'esbuild' ; 8import * as S from '../server/native-settings.mjs' ; 9 10test ( 'the speed switches of the settings are the generated table, with the Speed group added where the table names none' , () => { 11assert . deepEqual ( S . SPEED_SWITCHES . map (({ group, ...rest }) => rest ), SPEED_SWITCH_TABLE . map (({ group, ...rest }) => rest )); 12assert . ok ( S . SPEED_SWITCHES . every ( s => s . group === ( SPEED_SWITCH_TABLE . find ( t => t . id === s . id ). group ?? 'Speed' ))); 13assert . deepEqual ( SPEED_SWITCH_TABLE . map ( s => s . id ), [ 'faster_long_prompts' , 'faster_12gb_nvidia' , 'faster_radeon_9000' , 'picture_reader' ]); 14assert . equal ( S . SPEED_SWITCHES . find ( s => s . id === 'picture_reader' ). group , 'Image reading' ); 15}); 16 17test ( 'the drafting families and the model-name rule are the generated ones' , () => { 18assert . deepEqual ( S . DRAFTING_FAMILIES , DRAFTING_FAMILIES ); 19const re = new RegExp ( DFLASH2_MODEL_PATTERN , 'i' ); 20assert . ok ( re . test ( 'qwen3.8-flash-next-iq3_s' ) && re . test ( 'qwen3.8-flash-next-unsloth-ud-q4_k_xl' ) && ! re . test ( 'swift-1.5' )); 21assert . equal ( S . resolveDrafter ( 'auto' , 'qwen3.8-flash-next-iq3_s' , true , false ), 'dflash2' ); 22assert . equal ( S . resolveDrafter ( 'auto' , 'swift-1.5-iq3_s' , true , false ), 'mtp' ); 23}); 24 25test ( 'the screen copy of the drafting families (src/lib/drafting.ts) is the generated list' , async () => { 26const ts = await readFile ( new URL ( '../src/lib/drafting.ts' , import . meta. url ), 'utf8' ); 27const m = / export const DRAFTING_FAMILIES = ( \[ [ ^ \] ] * \] ) ; / . exec ( ts ); 28assert . ok ( m , 'DRAFTING_FAMILIES in src/lib/drafting.ts' ); 29assert . deepEqual ( JSON . parse ( m [ 1 ]. replaceAll ( "'" , '"' )), DRAFTING_FAMILIES ); 30}); 31 32/* The rules (where a switch applies, which models have a Drafting choice) are code in the host and in the screen; strata_control answers the same cases (policy-vectors.json, written by python -m strata_control.app_policy). */ 33const V = JSON . parse ( await readFile ( new URL ( './data/policy-vectors.json' , import . meta. url ), 'utf8' )); 34const { code} = await transform ( await readFile ( new URL ( '../src/lib/drafting.ts' , import . meta. url ), 'utf8' ), { loader :'ts' , format :'esm' }); 35const T = await import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 36 37test ( 'the host shows the speed switches strata_control shows, for every card, engine and model of the vectors' , () => { 38assert . ok ( V . switches . length > 100 ); 39for ( const row of V . switches ) { 40const model = V . models [ row . model ]; 41const context = { backend :row . backend , gpus :[ V . cards [ row . card ]], arch :model . arch ?? null , vision :!! model . vision }; 42const shown = S . SPEED_SWITCHES . filter ( s => S . speedSwitchApplies ( s . id , context )). map ( s => s . id ). sort (); 43assert . deepEqual ( shown , row . shows , ` ${ row . model } on ${ row . backend } with ${ row . card } ` ); 44} 45}); 46 47test ( 'the host and the screen agree with strata_control on which models and families have a Drafting choice' , () => { 48for ( const { name, supported} of V . names ) assert . equal ( S . resolveDrafter ( 'dflash2' , name , true , false ) === 'dflash2' , supported , name ); 49for ( const { family, supported} of V . families ) { 50assert . equal ( T . resolveDrafter ( 'dflash2' , family , true , false ) === 'dflash2' , supported , `screen: ${ family } ` ); 51assert . equal ( S . resolveDrafter ( 'dflash2' , family , true , false ) === 'dflash2' , supported , `host: ${ family } ` ); 52} 53});