import test from 'node:test'; import assert from 'node:assert/strict'; import {build} from 'esbuild'; const bundle=await build({stdin:{contents:"export * from './src/core/roverScene/sceneDocument'; export * from './src/core/roverScene/sceneMigration';",resolveDir:process.cwd()},bundle:true,write:false,platform:'node',format:'esm'}); const {defaultScene,loadStoredScene,parseScene}=await import('data:text/javascript;base64,'+Buffer.from(bundle.outputFiles[0].contents).toString('base64')); // Historical settings released by the first editor, independent of migration code. function savedFirstEditor(){ const d=defaultScene();delete d.environmentVersion; d.postFx={...d.postFx, lighting:{exposure:1.1,skyBoxIntensity:1,ambientIntensity:.22}, envAtlas:{...d.postFx.envAtlas,reflectionIntensity:1,brightness:1.2}, rendering:{...d.postFx.rendering,backgroundColor:'#202227',fog:'none',toneMapping:4}, grid:{...d.postFx.grid,colorMain:'#747982',colorX:'#93969c',colorZ:'#93969c',alphaMain:.25,alphaX:.35,alphaZ:.35,fadeStart:2,fadeEnd:5,step:.5,diameter:12}, chromaticAberration:{...d.postFx.chromaticAberration,enabled:false},vignette:{...d.postFx.vignette,enabled:false},grading:{...d.postFx.grading,enabled:false},bloom:{...d.postFx.bloom,enabled:false}, directionalLight:{...d.postFx.directionalLight,intensity:1.8,azimuth:135,elevation:45},shadowCatcher:{...d.postFx.shadowCatcher,size:4,lightIntensity:.5,shadowIntensity:.25} }; return d; } test('previous saved neutral preset migrates to NodeDC while retaining material work',()=>{ const raw=savedFirstEditor();raw.materials['rover/body'].name='Мой корпус';raw.materials['rover/body'].roughness=.73;raw.materials['rover/body'].textures.diffuse={name:'my.png',data:'data:image/png;base64,YWJj'}; raw.assignments['rover/box']='rover/body';raw.cameraZoomStrength=.1; const original=structuredClone(raw),r=loadStoredScene(raw); assert.equal(r.restoredEnvironment,true);assert.equal(r.updated,true); assert.deepEqual(r.document.postFx,defaultScene().postFx); assert.deepEqual(r.document.materials,raw.materials);assert.deepEqual(r.document.assignments,raw.assignments);assert.equal(r.document.cameraZoomStrength,.1); assert.deepEqual(raw,original,'backup must retain the exact input'); assert.equal(loadStoredScene(r.document).updated,false,'migration runs once'); }); test('a single custom environment edit prevents a destructive reset',()=>{ const raw=savedFirstEditor();raw.postFx.lighting.exposure=1.3; const r=loadStoredScene(raw);assert.equal(r.restoredEnvironment,false);assert.deepEqual(r.document.postFx,raw.postFx); }); test('a deliberate new gray scene and explicit JSON imports retain their appearance',()=>{ const raw=savedFirstEditor();raw.environmentVersion=2; assert.equal(loadStoredScene(raw).restoredEnvironment,false); delete raw.environmentVersion; const imported=parseScene(raw);assert.equal(imported.environmentVersion,2);assert.deepEqual(imported.postFx,raw.postFx); assert.equal(loadStoredScene(imported).restoredEnvironment,false); }); test('already restored legacy NodeDC scene is only versioned, not altered',()=>{ const raw=defaultScene();delete raw.environmentVersion;const r=loadStoredScene(raw); assert.equal(r.updated,true);assert.equal(r.restoredEnvironment,false);assert.deepEqual(r.document.postFx,raw.postFx); });