okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
74e25e165
main
1import test from 'node:test' ; 2import assert from 'node:assert/strict' ; 3import { mkdtempSync , rmSync } from 'node:fs' ; 4import { tmpdir } from 'node:os' ; 5import { join } from 'node:path' ; 6 7/** 8* The starter list (real-model-catalog.mjs) names five files by repository and file name with no hash. With the real engine on, nothing 9* may download from it. REAL is read when the module loads, and node --test runs each file in its own process, so this file sets it first. 10*/ 11const home = mkdtempSync ( join ( tmpdir (), 'strata-list-' )); 12process . env . STRATA_HOME = home ; 13process . env . STRATA_MODELS_DIR = join ( home , 'models' ); 14process . env . STRATA_REAL_ENGINE = '1' ; 15const calls = []; 16const realFetch = globalThis . fetch ; 17globalThis . fetch = ( ...args ) => { calls . push ( String ( args [ 0 ])); return Promise . reject ( new Error ( 'no network in this test' )); }; 18const models = await import ( '../server/models.mjs' ); 19const { REAL_VARIANTS } = await import ( '../server/real-model-catalog.mjs' ); 20test . after (() => { globalThis . fetch = realFetch ; rmSync ( home , { recursive :true , force :true }); }); 21 22test ( 'with the real engine on, installing from the starter list is refused before any request, for every entry' , async () => { 23assert . equal ( models . REAL , true ); 24assert . ok ( REAL_VARIANTS . length >= 1 ); 25for ( const v of REAL_VARIANTS ) { 26await assert . rejects ( models . install ( v . id ), err => err . status === 409 && err . message === 'The app downloads models from the Models screen of the native engine, not from this list.' , v . id ); 27} 28assert . deepEqual ( calls , [], 'no request was made' ); 29// nothing was left half-started 30for ( const v of REAL_VARIANTS ) assert . notEqual ( models . library (). variants . find ( row => row . id === v . id )?. state , 'downloading' ); 31});