1c837766cd
Add backend-driven assembly and simulation experiences, MAKE branding, mobile rendering budgets and desktop-only CAD/PCB routes. Improve logo loading progress, document image recovery and URDF request handling; include dev packaging and regression coverage.
75 lines
5.3 KiB
JavaScript
75 lines
5.3 KiB
JavaScript
// Validate freshly prepared upload assets with the supplied latest Sandbox schema
|
|
// and the community assembly schema. This does not imply browser simulation tests.
|
|
import {readFile,writeFile,readdir,mkdtemp,rm} from 'node:fs/promises';
|
|
import {join,resolve,dirname} from 'node:path';
|
|
import {tmpdir} from 'node:os';
|
|
import {createRequire} from 'node:module';
|
|
import {createHash} from 'node:crypto';
|
|
import assert from 'node:assert/strict';
|
|
import {build} from 'esbuild';
|
|
import {validatePackage as validateAssembly,validateEmbeddedGlb} from '../js/experience-packages.js';
|
|
|
|
const repo=new URL('..',import.meta.url).pathname;
|
|
const root=resolve(process.argv[2]??'/Users/jerry/Downloads/三个机器人-当前上传');
|
|
const source='/Users/jerry/Downloads/vibemakersandbox/app/src/platform';
|
|
const temp=await mkdtemp(join(tmpdir(),'make-upload-validators-'));
|
|
const readJSON=async path=>JSON.parse(await readFile(path,'utf8'));
|
|
const hash=b=>createHash('sha256').update(b).digest('hex');
|
|
const arrayBuffer=b=>b.buffer.slice(b.byteOffset,b.byteOffset+b.byteLength);
|
|
try{
|
|
const compiled=await build({stdin:{contents:`
|
|
export {validatePackage as validateRobot,validateWorld} from ${JSON.stringify(source+'/loader/SchemaValidator.js')};
|
|
export {JointMotionReference} from ${JSON.stringify(source+'/policy/JointMotionReference.js')};
|
|
export {validateBodyGlb} from ${JSON.stringify(source+'/render/BodyVisuals.js')};
|
|
export {resolveWorldId} from ${JSON.stringify(source+'/worlds/arena.js')};
|
|
`,resolveDir:repo},bundle:true,platform:'node',format:'cjs',write:false,
|
|
nodePaths:[join(repo,'sandbox/node_modules'),join(repo,'node_modules')],define:{'import.meta.env.BASE_URL':'"/"'},logLevel:'silent'});
|
|
const bundled=join(temp,'validators.cjs');await writeFile(bundled,compiled.outputFiles[0].contents);
|
|
const {validateRobot,validateWorld,JointMotionReference,validateBodyGlb,resolveWorldId}=createRequire(import.meta.url)(bundled);
|
|
const results=[];
|
|
for(const name of ['01-小鸭子-Microduck','02-双足机器人-Microban','03-双足机器人-RP1']){
|
|
const folder=join(root,name),motion=join(folder,'04-机器人运动演示'),result={folder:name,motion:[]};
|
|
const entries=name.startsWith('01')?['robot.json','variants/rollers.json']:['robot.json'];
|
|
for(const entry of entries){
|
|
const file=join(motion,entry),config=validateRobot(await readJSON(file));
|
|
const ref=[];
|
|
for(const skill of config.skills.filter(s=>s.reference)){
|
|
const spec=await readJSON(resolve(dirname(file),skill.reference));
|
|
const data=await readFile(resolve(dirname(file),spec.data));
|
|
const reader=new JointMotionReference(spec,arrayBuffer(data),config.joints.groups[skill.owns],config.sim.timestep*config.sim.decimation);
|
|
ref.push({skill:skill.id,frames:reader.frames});
|
|
}
|
|
for(const visual of config.render.body_visuals??[])validateBodyGlb(arrayBuffer(await readFile(resolve(dirname(file),visual.path))));
|
|
validateWorld(await readJSON(join(motion,'worlds',resolveWorldId(config),'world.json')));
|
|
result.motion.push({entry,id:config.id,skills:config.skills.map(s=>s.id),bodyVisuals:config.render.body_visuals?.length??0,references:ref});
|
|
}
|
|
if(!name.startsWith('03')){
|
|
const stepsFolder=join(folder,'03-拼装步骤'),files=(await readdir(stepsFolder)).filter(f=>f.endsWith('.json'));
|
|
assert.equal(files.length,1,'Only one current assembly file should be offered');
|
|
const data=await readFile(join(stepsFolder,files[0]));
|
|
const config=validateAssembly(JSON.parse(data),'assembly','https://assets.example/manifest.json');
|
|
for(const record of config.files.values()){
|
|
const bytes=await readFile(join(folder,'02-零件模型',record.path));
|
|
assert.equal(bytes.length,record.bytes);assert.equal(hash(bytes),record.sha256,record.path);
|
|
validateEmbeddedGlb(arrayBuffer(bytes));
|
|
}
|
|
for(const filename of await readdir(join(folder,'01-整机模型'))){
|
|
if(filename.endsWith('.glb'))validateEmbeddedGlb(arrayBuffer(await readFile(join(folder,'01-整机模型',filename))));
|
|
}
|
|
result.assembly={file:files[0],steps:config.steps.length,instances:config.parts.length,referencedFiles:config.files.size,sha256:hash(data)};
|
|
if(name.startsWith('01')){
|
|
const latest=await readFile('/Users/jerry/Downloads/小鸭子-双腿及躯干-当前上传/小鸭子-双腿及躯干-149步装配.json');
|
|
assert.equal(hash(data),hash(latest),'Duck must match the current 149-step delivery byte for byte');
|
|
assert.equal(config.steps.length,149);assert.equal(config.parts.length,201);
|
|
assert.ok(config.tools.some(t=>t.file==='内六角扳手.glb'));
|
|
assert.ok(!config.steps.some(s=>['trunk-3-36','trunk-3-37'].includes(s.id)));
|
|
result.assembly.skipped=['3-36','3-37'];result.assembly.collisionCertified=false;
|
|
}
|
|
}else result.assembly=null;
|
|
results.push(result);console.log(JSON.stringify(result));
|
|
}
|
|
const report={checkedAt:new Date().toISOString(),browserPlaybackTested:false,
|
|
scope:'Latest source schemas, world schemas, GLB files/material bytes, assembly references/SHA256, motion reference values/joint order/control clock',results};
|
|
await writeFile(join(root,'最新Schema与装配校验.json'),JSON.stringify(report,null,2)+'\n');
|
|
}finally{await rm(temp,{recursive:true,force:true});}
|