Files
behind_glass/scripts/test-render-demand.mjs
T
horoli e358e24436 Replace project with current server release and Windows setup
Import the 2026-10-09 source release, Fastify/SQLite backend, restored source
assets, and analytics-enabled server build. Replace files from the previous
release while retaining the existing repository history.

Make builds portable across Windows and Linux, configure local startup,
normalize Windows static asset paths, and fix test fixture cleanup and file
URL handling. Exclude local environment settings, databases, dependencies,
validation output, and TypeScript build cache from version control.

Validation: npm ci, static and server builds, 106 arrival tests, and actual
local HTTP checks passed. The full suite passed 467 of 470 tests; three tests
still require QA fixtures omitted from the supplied release, documented in
README-서버실행.md.
2026-10-09 16:43:35 +09:00

63 lines
3.2 KiB
JavaScript

import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { test } from 'node:test';
import ts from 'typescript';
const source=await readFile(new URL('../src/rendering/RenderDemand.ts',import.meta.url),'utf8');
const output=ts.transpileModule(source,{compilerOptions:{target:ts.ScriptTarget.ES2022,module:ts.ModuleKind.ES2022}}).outputText;
const {RenderDemand}=await import(`data:text/javascript;base64,${Buffer.from(output).toString('base64')}`);
const state=(signature='still',continuous=false,temporal=false)=>({signature,continuous,temporal});
test('static B submits once, then zero renders across ten seconds of idle RAFs',()=>{
const demand=new RenderDemand();
assert.equal(demand.shouldRender(1/60,state()),true);
let submitted=0;
for(let i=0;i<600;i++)if(demand.shouldRender(1/60,state()))submitted++;
assert.equal(submitted,0);
});
test('input signatures and asset invalidation resume immediately and coalesce duplicate events',()=>{
const demand=new RenderDemand();demand.shouldRender(1/60,state());
assert.equal(demand.shouldRender(1/60,state('new camera')),true);
assert.equal(demand.shouldRender(1/60,state('new camera')),false);
for(const reason of ['asset','depth','resize','theme','recovery','renderer retry']){
demand.invalidate();demand.invalidate();
assert.equal(demand.shouldRender(1/60,state('new camera')),true,reason);
assert.equal(demand.shouldRender(1/60,state('new camera')),false,reason);
}
});
test('mechanical animation keeps every requested frame and stops at its exact final pose',()=>{
const demand=new RenderDemand();
for(let i=0;i<240;i++)assert.equal(demand.shouldRender(1/60,state('still',true)),true);
assert.equal(demand.shouldRender(1/60,state()),false);
assert.equal(demand.shouldRender(1/60,state('final animation position')),true);
assert.equal(demand.shouldRender(1/60,state('final animation position')),false);
});
test('A history settles for ten existing 70ms time constants and then stops',()=>{
const demand=new RenderDemand();
let submitted=0;
for(let i=0;i<600;i++)if(demand.shouldRender(1/60,state('a',false,true)))submitted++;
assert.ok(submitted>=42&&submitted<=44,`expected bounded settling, got ${submitted}`);
assert.ok(Math.exp(-submitted/60/.07)<.0001,'remaining history contribution below 1e-4');
assert.equal(demand.shouldRender(1/60,state('a',false,true)),false);
assert.equal(demand.shouldRender(1/60,state('new a view',false,true)),true);
});
test('continuous A video resets history settling and B never inherits its tail',()=>{
const demand=new RenderDemand();
for(let i=0;i<90;i++)demand.shouldRender(1/60,state('a',true,true));
let tail=0;for(let i=0;i<120;i++)if(demand.shouldRender(1/60,state('a',false,true)))tail++;
assert.ok(tail>=41&&tail<=43);
assert.equal(demand.shouldRender(1/60,state('b')),true);
assert.equal(demand.shouldRender(1/60,state('b')),false);
});
test('invalid and long frame deltas cannot discard temporal work',()=>{
for(const dt of [NaN,-1,Infinity,100]){
const demand=new RenderDemand();assert.equal(demand.shouldRender(dt,state('a',false,true)),true);
assert.equal(demand.shouldRender(1/60,state('a',false,true)),true);
}
});