Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
Reuse a retained legacy model library through a guarded native data root, without moving weights (#3362)
Niko12213f81245864cf
diff --git a/apps/host/server/store.mjs b/apps/host/server/store.mjsindex 3c4b19ab0..88ab43525 100644--- a/apps/host/server/store.mjs+++ b/apps/host/server/store.mjs@@ -88,10 +88,21 @@ export let MODELS_DIR = MODELS_PICK.directory;/** Native setup writes weights to data_dir/models. Keep its data root one level up. */export function nativeDataDirectory(input) {- if(!input||process.env.STRATA_MODELS_DIR||!existsSync(DEFAULT_MODELS_DIRECTORY))return input;+ if(!input||!existsSync(input))return input;if(MODELS_DIR_NOTICE)return input;- const root=realpathSync(DEFAULT_MODELS_DIRECTORY);- if(resolve(input)!==resolve(DEFAULT_MODELS_DIRECTORY)&&realpathSync(input)!==root)return input;+ const root=realpathSync(input),legacy=realpathSync(join(HOME,'models'));+ // Retained legacy libraries are model folders too, not native data roots.+ // A named data root satisfies the installer's guard; its alias leaves weights in place.+ if(root===legacy){+ const data=join(HOME,'Strata-data'),nativeModels=join(data,'models');+ mkdirSync(data,{recursive:true});+ // Unlike a fresh default, a retained library must not fall back to an empty folder if linking fails.+ if(!existsSync(nativeModels))symlinkSync(process.platform==='win32'?root:relative(data,root),nativeModels,process.platform==='win32'?'junction':'dir');+ const a=statSync(nativeModels),b=statSync(root);+ if(realpathSync(nativeModels)!==root&&!(a.ino&&a.ino===b.ino&&a.dev===b.dev))throw new Error('The model folder conflicts with another library. Choose a different folder.');+ return data;+ }+ if(process.env.STRATA_MODELS_DIR||!existsSync(DEFAULT_MODELS_DIRECTORY)||root!==realpathSync(DEFAULT_MODELS_DIRECTORY))return input;const data=dirname(root);// `models` and `Models` are one folder on Windows and macOS; where they are not (Linux) a link makes them one, and where no link can be made (exFAT, a share) models go in `models`.alignModels(data,root);diff --git a/apps/host/tests/model-directory-default.test.mjs b/apps/host/tests/model-directory-default.test.mjsindex 85254db9e..9daae9e4a 100644--- a/apps/host/tests/model-directory-default.test.mjs+++ b/apps/host/tests/model-directory-default.test.mjs@@ -20,9 +20,94 @@ test('Linux respects localized XDG Documents and rejects shell expressions',()=>});test('new hosts create the default; custom folders and legacy weights remain in place',t=>{const root=realpathSync(mkdtempSync(join(tmpdir(),'strata-documents-')));t.after(()=>rmSync(root,{recursive:true,force:true}));- function boot(name,state,weights=false){const home=join(root,name),documents=join(root,name+'-documents');mkdirSync(join(home,'data'),{recursive:true});mkdirSync(join(home,'models'),{recursive:true});if(state)writeFileSync(join(home,'data','state.json'),JSON.stringify(state));if(weights){mkdirSync(join(home,'models','native','qwen'),{recursive:true});writeFileSync(join(home,'models','native','qwen','model.gguf'),'GGUFfixture');}const env={...process.env,STRATA_HOME:home,STRATA_DOCUMENTS_DIR:documents,STRATA_TEST_NATIVE:'1'};delete env.STRATA_MODELS_DIR;const result=spawnSync(process.execPath,['--input-type=module','-e',"const store=await import('./server/store.mjs');if(process.env.STRATA_TEST_NATIVE==='1'&&store.MODELS_DIR.endsWith('/Strata/Models')){const {statSync}=await import('node:fs');const {join}=await import('node:path');const native=store.nativeDataDirectory(store.MODELS_DIR);const a=statSync(join(native,'models')),b=statSync(store.MODELS_DIR);if(a.ino!==b.ino||a.dev!==b.dev)throw new Error('Native weights miss requested model folder');}console.log(store.MODELS_DIR);"],{cwd:fileURLToPath(new URL('..',import.meta.url)),env,encoding:'utf8'});assert.equal(result.status,0,result.stderr);return {path:result.stdout.trim(),home,documents};}+ function boot(name,state,weights=false){const home=join(root,name),documents=join(root,name+'-documents');mkdirSync(join(home,'data'),{recursive:true});mkdirSync(join(home,'models'),{recursive:true});if(state)writeFileSync(join(home,'data','state.json'),JSON.stringify(state));if(weights){mkdirSync(join(home,'models','native','qwen'),{recursive:true});writeFileSync(join(home,'models','native','qwen','model.gguf'),'GGUFfixture');}const env={...process.env,STRATA_HOME:home,STRATA_DOCUMENTS_DIR:documents,STRATA_TEST_NATIVE:'1',STRATA_TEST_DEFAULT:join(documents,'Strata','Models')};delete env.STRATA_MODELS_DIR;const result=spawnSync(process.execPath,['--input-type=module','-e',"const store=await import('./server/store.mjs');if(process.env.STRATA_TEST_NATIVE==='1'&&store.MODELS_DIR===process.env.STRATA_TEST_DEFAULT){const {statSync}=await import('node:fs');const {join}=await import('node:path');const native=store.nativeDataDirectory(store.MODELS_DIR);const a=statSync(join(native,'models')),b=statSync(store.MODELS_DIR);if(a.ino!==b.ino||a.dev!==b.dev)throw new Error('Native weights miss requested model folder');}console.log(store.MODELS_DIR);"],{cwd:fileURLToPath(new URL('..',import.meta.url)),env,encoding:'utf8',windowsHide:true});assert.equal(result.status,0,result.stderr);return {path:result.stdout.trim(),home,documents};}const fresh=boot('fresh');assert.equal(fresh.path,join(fresh.documents,'Strata','Models'));- const target=join(root,'redirected-target');mkdirSync(target);symlinkSync(target,join(root,'redirected-documents'));assert.equal(boot('redirected').path,join(target,'Strata','Models'));+ const target=join(root,'redirected-target');mkdirSync(target);symlinkSync(target,join(root,'redirected-documents'),process.platform==='win32'?'junction':'dir');assert.equal(boot('redirected').path,join(target,'Strata','Models'));const custom=join(root,'custom');mkdirSync(custom);assert.equal(boot('custom-host',{modelsDir:custom}).path,custom);const legacy=boot('legacy',{},true);assert.equal(legacy.path,join(legacy.home,'models'));});+++test('legacy model libraries resolve to a guarded native data root without moving weights',t=>{+ const root=realpathSync(mkdtempSync(join(tmpdir(),'strata-legacy-models-')));t.after(()=>rmSync(root,{recursive:true,force:true}));+ for(const choice of ['detected','saved','environment']){+ const home=join(root,choice),models=join(home,'models');mkdirSync(join(home,'data'),{recursive:true});mkdirSync(models);+ mkdirSync(join(models,'IQ3_XXS'));writeFileSync(join(models,'IQ3_XXS','model.gguf'),Buffer.from([71,71,85,70,0,255,128,1]));+ mkdirSync(join(root,'documents','Strata','Models'),{recursive:true});+ if(choice==='saved')writeFileSync(join(home,'data','state.json'),JSON.stringify({modelsDir:models}));+ const env={...process.env,STRATA_HOME:home,STRATA_DOCUMENTS_DIR:join(root,'documents')};delete env.STRATA_MODELS_DIR;+ if(choice==='environment')env.STRATA_MODELS_DIR=models;+ const result=spawnSync(process.execPath,['--input-type=module','-e',`+ import assert from 'node:assert/strict';import {join,basename} from 'node:path';+ import {readFileSync,realpathSync,readdirSync,statSync} from 'node:fs';+ const store=await import('./server/store.mjs');const models=realpathSync(join(store.HOME,'models'));+ assert.equal(store.MODELS_DIR,models);+ const data=store.nativeDataDirectory(models);+ assert.match(basename(data),/^strata/i,'a new native data root must satisfy the installer guard');+ assert.equal(realpathSync(join(data,'models')),models,'native setup must write to the existing library');+ const weight=join(models,'IQ3_XXS','model.gguf'),nativeWeight=join(data,'models','IQ3_XXS','model.gguf');+ assert.deepEqual(readFileSync(nativeWeight),Buffer.from([71,71,85,70,0,255,128,1]),'native setup sees the original weight bytes');+ assert.equal(statSync(nativeWeight).ino,statSync(weight).ino,'the alias reuses the original file');+ assert.equal(store.nativeDataDirectory(models),data,'resolution is idempotent');+ assert.deepEqual(readFileSync(weight),Buffer.from([71,71,85,70,0,255,128,1]));+ assert.deepEqual(readdirSync(models),['IQ3_XXS'],'weights stay in the original library');+ `],{cwd:fileURLToPath(new URL('..',import.meta.url)),env,encoding:'utf8',windowsHide:true});+ assert.equal(result.status,0,result.stderr);+ }+});+++test('native data roots leave explicit custom libraries and new installer folders unchanged',t=>{+ const root=realpathSync(mkdtempSync(join(tmpdir(),'strata-custom-models-')));t.after(()=>rmSync(root,{recursive:true,force:true}));+ const custom=join(root,'chosen-library');mkdirSync(custom);writeFileSync(join(custom,'keep.gguf'),'GGUFfixture');+ for(const choice of ['saved','environment']){+ const home=join(root,choice);mkdirSync(join(home,'data'),{recursive:true});+ if(choice==='saved')writeFileSync(join(home,'data','state.json'),JSON.stringify({modelsDir:custom}));+ const env={...process.env,STRATA_HOME:home,STRATA_DOCUMENTS_DIR:join(root,'documents'),STRATA_TEST_CUSTOM:custom};delete env.STRATA_MODELS_DIR;+ if(choice==='environment')env.STRATA_MODELS_DIR=custom;+ const result=spawnSync(process.execPath,['--input-type=module','-e',`+ import assert from 'node:assert/strict';import {join} from 'node:path';import {existsSync,readFileSync} from 'node:fs';+ const store=await import('./server/store.mjs'),custom=process.env.STRATA_TEST_CUSTOM;+ assert.equal(store.MODELS_DIR,custom);assert.equal(store.nativeDataDirectory(custom),custom);+ const requested=join(store.HOME,'Strata-new');assert.equal(store.nativeDataDirectory(requested),requested);+ assert.equal(existsSync(requested),false);assert.equal(existsSync(join(store.HOME,'Strata-data')),false);+ assert.equal(readFileSync(join(custom,'keep.gguf'),'utf8'),'GGUFfixture');+ `],{cwd:fileURLToPath(new URL('..',import.meta.url)),env,encoding:'utf8',windowsHide:true});+ assert.equal(result.status,0,result.stderr);+ }+});++test('legacy native aliases never overwrite a conflicting library',t=>{+ const root=realpathSync(mkdtempSync(join(tmpdir(),'strata-conflicting-models-')));t.after(()=>rmSync(root,{recursive:true,force:true}));+ for(const kind of ['directory','link']){+ const home=join(root,kind),original=join(home,'models'),other=join(home,'other-library'),alias=join(home,'Strata-data','models');mkdirSync(original,{recursive:true});mkdirSync(other);mkdirSync(join(home,'Strata-data'));+ if(kind==='link')symlinkSync(other,alias,process.platform==='win32'?'junction':'dir');else mkdirSync(alias);+ writeFileSync(join(original,'original.gguf'),'GGUForiginal');writeFileSync(join(other,'other.gguf'),'GGUFother');+ if(kind==='directory')writeFileSync(join(alias,'other.gguf'),'GGUFconflict');+ const env={...process.env,STRATA_HOME:home,STRATA_DOCUMENTS_DIR:join(home,'documents')};delete env.STRATA_MODELS_DIR;+ const result=spawnSync(process.execPath,['--input-type=module','-e',`+ import assert from 'node:assert/strict';import {join} from 'node:path';import {readFileSync,realpathSync} from 'node:fs';+ const store=await import('./server/store.mjs');+ assert.throws(()=>store.nativeDataDirectory(store.MODELS_DIR),/conflicts with another library/);+ assert.equal(realpathSync(store.MODELS_DIR),realpathSync(join(store.HOME,'models')));+ assert.equal(readFileSync(join(store.MODELS_DIR,'original.gguf'),'utf8'),'GGUForiginal');+ assert.equal(readFileSync(join(store.HOME,'other-library','other.gguf'),'utf8'),'GGUFother');+ assert.equal(readFileSync(join(store.HOME,'Strata-data','models','other.gguf'),'utf8'),${JSON.stringify(kind==='link'?'GGUFother':'GGUFconflict')});+ `],{cwd:fileURLToPath(new URL('..',import.meta.url)),env,encoding:'utf8',windowsHide:true});+ assert.equal(result.status,0,result.stderr);+ }+});++test('an unavailable Documents default retains the upstream fallback without creating a legacy alias',t=>{+ const root=realpathSync(mkdtempSync(join(tmpdir(),'strata-fallback-models-')));t.after(()=>rmSync(root,{recursive:true,force:true}));+ const home=join(root,'home'),documents=join(root,'blocked-documents');mkdirSync(home);writeFileSync(documents,'not a directory');+ const env={...process.env,STRATA_HOME:home,STRATA_DOCUMENTS_DIR:documents};delete env.STRATA_MODELS_DIR;+ const result=spawnSync(process.execPath,['--input-type=module','-e',`+ import assert from 'node:assert/strict';import {join} from 'node:path';import {existsSync} from 'node:fs';+ const store=await import('./server/store.mjs');+ assert.match(store.MODELS_DIR_NOTICE,/Strata could not use/);+ assert.equal(store.nativeDataDirectory(store.MODELS_DIR),store.MODELS_DIR);+ assert.equal(existsSync(join(store.HOME,'Strata-data')),false);+ `],{cwd:fileURLToPath(new URL('..',import.meta.url)),env,encoding:'utf8',windowsHide:true});+ assert.equal(result.status,0,result.stderr);+});