Files
vibemake/tests/numbered-schedule.test.js
T

61 lines
3.4 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { numberedSchedule } from '../scripts/lib/numbered-schedule.mjs';
import { validatePackage, visibleAssemblyParts } from '../js/experience-packages.js';
import { assemblyStageKey } from '../js/assembly-groups.js';
const item=(group,number,flags={})=>({group:{number:group,path:`${group}组件`},directory:`${group}组件`,number,...flags});
const compile=ordered=>{
const schedule=numberedSchedule(ordered);
const parts=[...schedule.actions].map(([id])=>({id,file:'part.glb'}));
const steps=[...schedule.actions].flatMap(([id,action])=>[...action.joins.map(join=>({...join,installOffset:[0,.1,0]})),
{id:`step-${id}`,groupId:schedule.groups.find(group=>group.parts.includes(id)).id,parts:[id],visibleParts:action.visibleParts}]);
return validatePackage({schemaVersion:1,kind:'assembly',unit:'meter',playback:'scoped-v1',
files:[{path:'part.glb',bytes:1,sha256:'a'.repeat(64)}],parts,steps,groups:schedule.groups},'assembly','https://example.com/manifest.json');
};
test('outer #11 installs ten completed folders in numeric order then its loose parts, even on arbitrary seeks',()=>{
const ordered=Array.from({length:10},(_,i)=>item(i+1,1));
ordered.push(item(11,1,{group:{number:11,path:'#11总装',revealAll:true}}),item(11,2,{group:{number:11,path:'#11总装',revealAll:true}}));
const pkg=compile(ordered);
assert.equal(pkg.steps.length,22);
for(const n of [10,1,7,2,9,3,8,4,6,5]) {
const index=9+n,step=pkg.steps[index];
assert.equal(step.type,'join');assert.equal(step.groupId,`group-${n}`);
assert.deepEqual([...visibleAssemblyParts(pkg,index)],Array.from({length:n},(_,i)=>`p-${i+1}-1`));
assert.equal(assemblyStageKey(pkg,index),null);
}
assert.equal(assemblyStageKey(pkg,0),'group-1');
assert.equal(assemblyStageKey(pkg,20),null);
assert.equal(visibleAssemblyParts(pkg,20).size,11);
assert.equal(visibleAssemblyParts(pkg,21).size,12);
});
test('consecutive internal # steps share joins; minus restores local scope and plus starts isolation',()=>{
const ordered=[item(1,1),item(2,1),item(3,1),item(3,2,{revealAll:true}),item(3,3,{revealAll:true}),
item(3,4),item(3,5,{isolated:true}),item(3,6,{isolated:true}),item(3,7),item(3,8,{revealAll:true})];
const pkg=compile(ordered),at=id=>pkg.steps.findIndex(step=>step.id===`step-p-3-${id}`);
assert.equal(pkg.steps.filter(step=>step.type==='join').length,4);
assert.equal(visibleAssemblyParts(pkg,at(3)).size,5);
assert.deepEqual([...visibleAssemblyParts(pkg,at(4))],['p-3-1','p-3-2','p-3-3','p-3-4']);
assert.deepEqual([...visibleAssemblyParts(pkg,at(6))],['p-3-5','p-3-6']);
assert.equal(visibleAssemblyParts(pkg,at(7)).size,7);
const firstJoin=pkg.steps[3];
assert.deepEqual(firstJoin.visibleParts,['p-3-1','p-1-1']);
assert.equal(firstJoin.parts.length,1,'current cover remains still while a prior group moves');
});
test('scoped manifests reject absent scope, partial joins, future groups and wrong group members',()=>{
const source=()=>compile([item(1,1),item(1,2),item(2,1,{revealAll:true})]);
for(const mutate of [
pkg=>delete pkg.steps[0].visibleParts,
pkg=>pkg.steps[2].parts.pop(),
pkg=>pkg.steps[2].groupId='group-2',
pkg=>pkg.steps[0].visibleParts.push('p-2-1'),
]) {
const pkg=source();mutate(pkg);
const raw={...pkg,files:[{path:'part.glb',bytes:1,sha256:'a'.repeat(64)}]};
assert.throws(()=>validatePackage(raw,'assembly','https://example.com/manifest.json'));
}
});