Improve machine manager engineering workbench

This commit is contained in:
2026-09-21 12:54:56 +08:00
parent a2c6dd1c01
commit a7233bc8e4
18 changed files with 388 additions and 57 deletions

View File

@@ -0,0 +1,12 @@
import assert from 'node:assert/strict';
import { machineDraftHistory } from '../web/react/src/machine-manager-history.ts';
const draft = { parts: [], cOriginMm:[0,0,0], tiltOffsetMm:[0,0,0], physicalZero:{x:0,y:0,z:0,a:0,b:0,c:0} };
let state = { current:draft, past:[], future:[] };
const edit = (n) => ({ type:'edit', change:(d) => ({...d, cOriginMm:[n,0,0]}) });
state = machineDraftHistory(state, edit(1)); state = machineDraftHistory(state,edit(1)); assert.equal(state.past.length,1);
state = machineDraftHistory(state,{type:'undo'}); assert.equal(state.current.cOriginMm[0],0);
state = machineDraftHistory(state,{type:'redo'}); assert.equal(state.current.cOriginMm[0],1);
state = machineDraftHistory(state,{type:'undo'}); state = machineDraftHistory(state,edit(2)); assert.equal(state.future.length,0);
for(let i=3;i<45;i++) state=machineDraftHistory(state,edit(i)); assert.equal(state.past.length,30);
const current=state.current; state=machineDraftHistory(state,{type:'clear'}); assert.equal(state.current,current); assert.equal(state.past.length,0);
console.log(JSON.stringify({report_id:'GLB-MGR-E14-HISTORY',status:'verified',checks:['undo/redo','duplicate edits ignored','new edit discards redo','30-entry bound','clear preserves draft']}));