okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0b3299a01
main
1import test from 'node:test' ; 2import assert from 'node:assert/strict' ; 3import { readFile } from 'node:fs/promises' ; 4import { transform } from 'esbuild' ; 5const { code} = await transform ( await readFile ( new URL ( '../src/lib/onboarding-download.ts' , import . meta. url ), 'utf8' ),{ loader :'ts' , format :'esm' }); 6const { downloadCounter, onboardingError, modelFolderLabel} = await import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 7test ( 'download remaining reflects the current shard rather than the whole model' ,() => { 8assert . deepEqual ( downloadCounter ( 66.4 ,{ file :'shard-1' , total_gb :22.1 , done_gb :8.4 , percent :38 }, true ),{ value :13.700000000000001 , label :'GB left in this file' , key :'shard-1' }); 9assert . ok ( downloadCounter ( 66.4 ,{ file :'shard-1' , total_gb :22.1 , done_gb :15.9 }, true ). value < 6.3 ); 10assert . equal ( downloadCounter ( 66.4 ,{ file :'shard-2' , total_gb :22.1 , done_gb :0 }, true ). key , 'shard-2' ); 11assert . equal ( downloadCounter ( 66.4 ,{ remaining_gb :0 }, true ). value , 0 ); 12}); 13test ( 'unknown download totals never invent a countdown' ,() => { 14assert . equal ( downloadCounter ( 66.4 ,{ percent :50 }, true ). value , undefined ); 15assert . equal ( downloadCounter ( 66.4 , undefined , true ). value , undefined ); 16assert . equal ( downloadCounter ( 66.4 , undefined , false ). value , 66.4 ); 17assert . equal ( downloadCounter ( 66.4 ,{ total_gb :10 , percent :150 }, true ). value , 0 ); 18}); 19test ( 'storage errors expose needed/free space without paths or command flags' ,() => { 20for ( const location of [ '/Users/name/Documents/Private' , 'D:\\private\\weights' ]){ 21const result = onboardingError ( `Not enough free disk space for Q2_0: about 75 GB needed at ${ location } , 18 GB free; choose data_dir (e.g. D:\\Strata-data)` ); 22assert . equal ( result . storage , true ); assert . equal ( result . message , 'This model needs about 75 GB. You have 18 GB free.' ); 23assert . equal ( JSON . stringify ( result ). includes ( location ), false ); assert . equal ( JSON . stringify ( result ). includes ( 'data_dir' ), false ); 24} 25assert . equal ( onboardingError ( 'ENOSPC: write failed at /secret' ). message , 'There isn’t enough free space to download this model.' ); 26assert . equal ( onboardingError ( 'Network unavailable' ). message , 'Network unavailable' ); 27}); 28test ( 'default folder labels are readable across platform separators' ,() => { 29assert . equal ( modelFolderLabel ( 'C:\\Users\\Me\\Documents\\Strata\\Models' ), 'Documents / Strata / Models' ); 30assert . equal ( modelFolderLabel ( '/home/me/Documents/Strata/Models' ), 'Documents / Strata / Models' ); 31assert . equal ( modelFolderLabel ( '/mnt/external/models' ), '/mnt/external/models' ); 32});