okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e39a52e33
main
1import test from 'node:test' ; 2import assert from 'node:assert/strict' ; 3import { readFile } from 'node:fs/promises' ; 4import { nativeUnloadPlan } from '../server/storage-check.mjs' ; 5 6const loaded = [{ id :'a' , model :'gyro-gyro-s' }, { id :'b' , model :'iq3_s' }]; 7 8test ( 'O01: checking the same folder unloads nothing' , () => { 9assert . deepEqual ( nativeUnloadPlan ({ changed :false , unload :true , instances :loaded }), { refuse :null , ids :[] }); 10assert . deepEqual ( nativeUnloadPlan ({ changed :false , unload :undefined , instances :loaded }), { refuse :null , ids :[] }); 11}); 12 13test ( 'O01: changing the folder unloads the loaded models only when the person agreed' , () => { 14assert . match ( nativeUnloadPlan ({ changed :true , unload :false , instances :loaded }). refuse , / Unload native models / ); 15assert . deepEqual ( nativeUnloadPlan ({ changed :true , unload :true , instances :loaded }), { refuse :null , ids :[ 'a' , 'b' ] }); 16assert . deepEqual ( nativeUnloadPlan ({ changed :true , unload :false , instances :[] }), { refuse :null , ids :[] }); 17assert . deepEqual ( nativeUnloadPlan ({ changed :true , unload :true , instances :undefined }), { refuse :null , ids :[] }); 18}); 19 20test ( 'O01: the route uses that plan and the screen asks for an unload only when the folder differs' , async () => { 21const route = await readFile ( new URL ( '../server/index.mjs' , import . meta. url ), 'utf8' ); 22assert . match ( route , / nativeUnloadPlan\(\{changed,unload:body\.unload,instances:native\.state\(\)\.instances\}\) / ); 23assert . doesNotMatch ( route , / for\(const instance of native\.state\(\)\.instances\)await native\.unload\(instance\.id\);\}\s * \n\s * storageChanging = true / ); 24const screen = await readFile ( new URL ( '../src/components/SettingsStorage.tsx' , import . meta. url ), 'utf8' ); 25assert . match ( screen , / changeModelDirectory\(path, path\.trim\(\) !== currentDirectory\) / ); 26}); 27 28test ( 'F02: Settings -> Storage has ONE Downloaded models list and one total, with the shared files as a line of their own' , async () => { 29const screen = await readFile ( new URL ( '../src/components/SettingsStorage.tsx' , import . meta. url ), 'utf8' ); 30assert . equal (( screen . match ( / <Field wide label=\{tr\("Downloaded models"\)\} / g ) ?? []). length , 1 , 'no second section that contradicts the first' ); 31assert . match ( screen , / totalGb / ); 32assert . match ( screen , / Shared files / ); 33assert . match ( screen , / No downloaded models / ); 34}); 35 36test ( 'item 8: "Strata" in Settings is the app\'s version; Strata Control\'s 0.1.45 is only a fallback; the update check gets the app version too' , async () => { 37const { appVersionToShow} = await import ( '../server/app-version.mjs' ); 38assert . equal ( appVersionToShow ( '0.2.0-beta' , '0.1.45' ), '0.2.0-beta' ); 39assert . equal ( appVersionToShow ( 'dev' , '0.1.45' ), '0.1.45' , 'a source checkout has no app version: the next best number' ); 40assert . equal ( appVersionToShow ( undefined , null ), null ); 41assert . equal ( appVersionToShow ( 'dev' , null ), 'dev' ); 42const { build} = await import ( 'esbuild' ); 43const out = await build ({ stdin :{ contents :"export * from './src/lib/app-version';" , resolveDir :process . cwd () }, bundle :true , write :false , platform :'node' , format :'esm' }); 44const { appVersionLabel} = await import ( `data:text/javascript;base64, ${ Buffer . from ( out . outputFiles [ 0 ]. text ). toString ( 'base64' )} ` ); 45assert . equal ( appVersionLabel ( '0.2.0-beta' , '0.1.45' ), '0.2.0-beta' ); 46assert . equal ( appVersionLabel ( 'dev' , '0.1.45' ), '0.1.45' ); 47assert . equal ( appVersionLabel ( undefined , undefined ), undefined ); 48const route = await readFile ( new URL ( '../server/index.mjs' , import . meta. url ), 'utf8' ); 49assert . match ( route , / appVersion:appVersionToShow\(setupState\(\)\.app\.version,native\.state\(\)\.version\) / ); 50const updates = await readFile ( new URL ( '../src/components/SettingsUpdates.tsx' , import . meta. url ), 'utf8' ); 51assert . doesNotMatch ( updates , / native\?\.version \?\? appVersion / , 'the Strata row no longer prefers Control\'s version' ); 52assert . match ( updates , / AboutVersions / ); 53}); 54 55test ( 'Cargo.toml, tauri.conf.json and the desktop package agree on the app version the host reports' , async () => { 56const root = new URL ( '../../desktop/' , import . meta. url ); 57const cargo = / ^version\s * =\s * " ([ ^ " ] + ) " / m . exec ( await readFile ( new URL ( 'src-tauri/Cargo.toml' , root ), 'utf8' ))[ 1 ]; 58const pkg = JSON . parse ( await readFile ( new URL ( 'package.json' , root ), 'utf8' )). version ; 59assert . equal ( cargo , pkg ); 60assert . equal ( cargo , '0.2.15' ); 61});