okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0fdfa40b4
main
1import test from 'node:test' ; 2import assert from 'node:assert/strict' ; 3import { resolve } from 'node:path' ; 4import { createRequire } from 'node:module' ; 5import { build } from 'esbuild' ; 6 7/* The family menu rows for the update feed's models: a model this engine cannot use is a note with its reason, not a choice; one that is allowed shows the reason beside its name. */ 8const root = resolve ( import . meta. dirname , '..' ); 9const virtual = { './ui' :"export const Icon=()=>null;" , './FloatingMenu' :"export const FloatingMenu=()=>null;" }; 10const stubs = { name :'stubs' , setup ( b ){ b . onResolve ({ filter :/ ^\.\/ ( ui | FloatingMenu ) $ / }, a => ({ path :a . path , namespace :'stub' })); b . onLoad ({ filter :/ . */ , namespace :'stub' }, a => ({ contents :virtual [ a . path ], loader :'js' }));}}; 11const out = await build ({ entryPoints :[ resolve ( root , 'src/components/FamilySwitch.tsx' )], bundle :true , write :false , platform :'node' , format :'cjs' , jsx :'automatic' , plugins :[ stubs ], external :[ 'react' , 'react-dom' , 'react/jsx-runtime' ], loader :{ '.json' :'json' }}); 12const require = createRequire ( resolve ( root , 'package.json' )); 13const mod = { exports :{}}; new Function ( 'module' , 'exports' , 'require' , out . outputFiles [ 0 ]. text )( mod , mod . exports , require ); 14const { renderToStaticMarkup} = require ( 'react-dom/server' ); 15const React = require ( 'react' ); 16const { FamilyMenuList} = mod . exports ; 17const fam = ( family , title , extra = {}) => ({ family, title, about :'' , experimental :false , images :true , sizes :[{ id :family + '-x' }], ...extra }); 18test ( 'a model the engine cannot use is a note with its reason; an allowed one shows the reason beside its name' ,() => { 19const reason = 'needs a newer Strata engine: update Strata to use it' ; 20const shown = [ fam ( 'qwen3.8' , 'Qwen3.8-Flash-Next' ), fam ( 'qwen4-test' , 'Qwen4 Test' ,{ feed :true , available :false , unavailable_reason :reason })]; 21const missing = [ fam ( 'later-one' , 'Later One' ,{ sizes :[], feed :true , available :false , unavailable_reason :"this Strata version doesn't know this model yet: update Strata to use it" })]; 22const html = renderToStaticMarkup ( React . createElement ( FamilyMenuList ,{ shown, missing, current :shown [ 0 ], onPick (){}})); 23assert . equal (( html . match ( / role="menuitemradio" / g ) || []). length , 2 ); 24assert . equal (( html . match ( / role="note" / g ) || []). length , 1 ); 25assert ( html . includes ( 'Qwen4 Test</strong><small>' + reason + '</small>' )); 26assert ( html . includes ( 'Later One</strong><small>this Strata version doesn't know this model yet: update Strata to use it</small>' )); 27const plain = renderToStaticMarkup ( React . createElement ( FamilyMenuList ,{ shown :[ shown [ 0 ]], missing :[], current :shown [ 0 ], onPick (){}})); 28assert ( ! plain . includes ( '<small>' )); assert ( ! plain . includes ( 'role="note"' )); 29});