From e32324ad147cbd5e37ceed2b61458e73856902b9 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 18 Nov 2026 10:40:31 +0700 Subject: [PATCH 1/3] refactor(gui): FX Rack M4 metadata and ACK/readback settlement use one pure VM --- tests/approved_native_m2_contract.test.cjs | 48 ++++++++++++++++++++++ web/approved-fx-rack-view-model.js | 48 +++++++++++++++++++++- web/approved-native-bridge.js | 46 +++++++++------------ 3 files changed, 114 insertions(+), 28 deletions(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 4b07b28c6..56ee42459 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -2822,3 +2822,51 @@ test("MV-2 merged #767 retains one selector; #768 unique duplex/one-pin guards a {inventory,draft:reset,requestId:"gui1-fallback"}); assert.deepEqual(recovered.request.config.enabledOutputs,[0,1]); }); + +test("GUI-2 native FX catalog projection keeps exact M4 processor identity",()=>{ + const rows=Array(8).fill(null); + rows[1]={instanceId:"18446744073709551615",catalogId:"eq.a",bypassed:true}; + rows[3]={instanceId:"9007199254740993",catalogId:"unknown",bypassed:false}; + const before=JSON.stringify(rows); + const result=fxRackVM.m4Presentation(rows,new Map([["eq.a",{name:"EQ One"}]]),true); + assert.equal(result.fxOn,false);assert.equal(result.slots.length,8); + assert.deepEqual(result.slots[1].instance,{id:"18446744073709551615",name:"EQ One"}); + assert.deepEqual(result.slots[3].instance,{id:"9007199254740993",name:"VST3 Loaded"}); + assert.equal(result.slots[0].instance,null); + assert.equal(fxRackVM.m4Presentation(rows,new Map(),null).fxOn,null); + assert.equal(JSON.stringify(rows),before,"M4 metadata never edits native FX"); + const forged=rows.slice();forged[1]={catalogId:"eq.a",bypassed:false}; + assert.equal(fxRackVM.m4Presentation(forged,new Map(),false),null); +}); +test("GUI-2 native FX pending settlement requires ACK, exact lease and epoch",()=>{ + const epoch="18446744073709551612"; + const ch={id:"9007199254740993",fxRackBypassed:false, + inserts:[{id:"18446744073709551615",bypassed:true}]}; + const next={device:{epoch},graph:{channels:[ch]}}; + const p={requestId:"fx42",channelId:ch.id,kind:"insert", + insertId:"18446744073709551615",bypassed:true,epoch,acked:false}; + assert.equal(fxRackVM.nativePowerSettlement(p,next),"WAIT"); + assert.equal(fxRackVM.nativePowerSettlement({...p,acked:true},next),"CONFIRMED"); + assert.equal(fxRackVM.nativePowerSettlement({...p,acked:true}, + {...next,device:{epoch:"18446744073709551613"}}),"STALE"); + assert.equal(fxRackVM.nativePowerSettlement({...p,acked:true}, + {...next,graph:{channels:[{...ch,inserts:[{id:"new",bypassed:true}]}]}}),"WAIT"); + assert.equal(fxRackVM.nativePowerSettlement({...p,acked:true,kind:"rack",bypassed:false},next),"CONFIRMED"); + assert.equal(fxRackVM.nativePowerSettlement(null,next),"NONE"); +}); +test("GUI-2 M4 rack pending selector rejects revisions and unaccepted authority",()=>{ + const s={authority:"M4",deviceEpoch:"17",routeRevision:"8", + channels:[{fxRackBypassed:true}]}; + const p={channel:0,epoch:"17",revision:"8",bypassed:true,acked:false}; + assert.equal(fxRackVM.m4RackSettlement(p,s),"WAIT"); + assert.equal(fxRackVM.m4RackSettlement({...p,acked:true},s),"CONFIRMED"); + assert.equal(fxRackVM.m4RackSettlement({...p,acked:true},{...s,routeRevision:"9"}),"STALE"); + assert.equal(fxRackVM.m4RackSettlement({...p,acked:true},{...s,authority:"CHANNEL_ID"}),"STALE"); + assert.equal(fxRackVM.m4RackSettlement({...p,acked:true}, + {...s,channels:[{fxRackBypassed:false}]}),"WAIT"); + const source=read("web/approved-native-bridge.js"); + assert.match(source,/fxRackVM\\.m4Presentation\\(/); + assert.match(source,/fxRackVM\\.nativePowerSettlement\\(/); + assert.match(source,/fxRackVM\\.m4RackSettlement\\(/); + assert.doesNotMatch(source,/const actual=p\\.kind==="rack"\\?/); +}); diff --git a/web/approved-fx-rack-view-model.js b/web/approved-fx-rack-view-model.js index 0b73ef511..d03b19e99 100644 --- a/web/approved-fx-rack-view-model.js +++ b/web/approved-fx-rack-view-model.js @@ -64,5 +64,51 @@ }); } - return Object.freeze({powerReadback,mountedRackMatches}); + + // M4 inventory and catalog names are UI metadata, never an installed + // ChannelId processor graph or permission to resurrect a retired instance. + function m4Presentation(instances,catalog,acceptedRack) { + if(!Array.isArray(instances))return null; + const slots=[]; + for(let index=0;index<8;index++){ + const live=instances[index]; + if(live!=null && + (typeof live.instanceId!=="string"||!live.instanceId|| + typeof live.catalogId!=="string"||!live.catalogId|| + typeof live.bypassed!=="boolean"))return null; + const name=live?(catalog?.get?.(live.catalogId)?.name||"VST3 Loaded"):"None"; + slots.push({index,name,bypassed:live?.bypassed===true, + instance:live?{id:live.instanceId,name}:null}); + } + return {fxOn:typeof acceptedRack==="boolean"?!acceptedRack:null,slots}; + } + // ACK alone is not installed PCM proof. Correlate channel, insert lease, + // physical device epoch and subsequent accepted readback. + function nativePowerSettlement(pending,snapshot) { + if(!pending)return "NONE"; + if(pending.epoch!==undefined && + snapshot?.device?.epoch!==pending.epoch)return "STALE"; + if(pending.acked!==true)return "WAIT"; + const channels=snapshot?.graph?.channels; + if(!Array.isArray(channels))return "WAIT"; + const channel=channels.find(ch=>ch.id===pending.channelId); + if(!channel)return "WAIT"; + const value=pending.kind==="rack"?channel.fxRackBypassed: + pending.kind==="insert"? + channel.inserts?.find(i=>i.id===pending.insertId)?.bypassed: + undefined; + return typeof value==="boolean"&&value===pending.bypassed? + "CONFIRMED":"WAIT"; + } + function m4RackSettlement(pending,session) { + if(!pending)return "NONE"; + if(session?.authority!=="M4"|| + session.deviceEpoch!==pending.epoch|| + session.routeRevision!==pending.revision)return "STALE"; + return pending.acked===true&& + session.channels?.[pending.channel]?.fxRackBypassed===pending.bypassed? + "CONFIRMED":"WAIT"; + } + return Object.freeze({powerReadback,mountedRackMatches, + m4Presentation,nativePowerSettlement,m4RackSettlement}); }); diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 371e6dfd2..ef5b7b61b 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -1403,12 +1403,9 @@ function reconcileM4RackReadback(next){ const session=next?.raw?.mixerSession; for(const [lane,p] of pendingM4RackPowers){ - if(session?.authority!=="M4"|| - session.deviceEpoch!==p.epoch||session.routeRevision!==p.revision){ - pendingM4RackPowers.delete(lane);continue; - } - const actual=session.channels?.[lane]?.fxRackBypassed; - if(p.acked && actual===p.bypassed)pendingM4RackPowers.delete(lane); + const decision=fxRackVM.m4RackSettlement(p,session); + if(decision==="STALE"||decision==="CONFIRMED") + pendingM4RackPowers.delete(lane); } } // Global A/B is a SINGLE native atomic override. Individual racks and @@ -1477,7 +1474,7 @@ const bypassed=rack?!ch.fxRackBypassed:!insert.bypassed; const requestId="native-rack-"+(++nativeFxPowerSerial); pendingNativeFxPower={requestId,channelId,kind:rack?"rack":"insert", - insertId:insert?.id,bypassed,acked:false}; + insertId:insert?.id,bypassed,epoch:current.device.epoch,acked:false}; backend.emitEvent("arMixAction",{action:rack? "routingNativeFxRackBypass":"routingNativeFxInsertBypass", requestId,channelId,deviceEpoch:current.device.epoch, @@ -1623,23 +1620,22 @@ if(!Array.isArray(m?.fxInstances)||!scope?.tracks)return; for(let lane=0;lane<10;lane++){ const t=scope.tracks.find(x=>x.id===m4TrackIds[lane]); - const rows=m.fxInstances[lane]; - if(!t||!Array.isArray(rows))continue; - let change=false; const acceptedRack=mixerSession()?.authority==="M4"? mixerSession()?.channels?.[lane]?.fxRackBypassed:undefined; - if(typeof acceptedRack==="boolean" && t.fxOn===acceptedRack){ - t.fxOn=!acceptedRack;change=true; + const projection=fxRackVM.m4Presentation(m.fxInstances[lane], + nativeCatalog,acceptedRack); + if(!t||!projection)continue; + let change=false; + if(projection.fxOn!==null&&t.fxOn!==projection.fxOn){ + t.fxOn=projection.fxOn;change=true; } - for(let slot=0;slot<8;slot++){ - const live=rows[slot],entry=nativeCatalog.get(live?.catalogId); - const name=live?(entry?.name||"VST3 Loaded"):"None"; - if(t.fx[slot]!==name || t.slotBypass[slot]!==Boolean(live?.bypassed) || - (t.fxInsertIds?.[slot]?.id||null)!==(live?.instanceId||null)){ - t.fx[slot]=name; - t.slotBypass[slot]=Boolean(live?.bypassed); + for(const slot of projection.slots){ + const index=slot.index; + if(t.fx[index]!==slot.name||t.slotBypass[index]!==slot.bypassed|| + (t.fxInsertIds?.[index]?.id||null)!==(slot.instance?.id||null)){ + t.fx[index]=slot.name;t.slotBypass[index]=slot.bypassed; if(!Array.isArray(t.fxInsertIds))t.fxInsertIds=Array(8).fill(null); - t.fxInsertIds[slot]=live?{id:live.instanceId,name}:null; + t.fxInsertIds[index]=slot.instance; change=true; } } @@ -2901,13 +2897,9 @@ status("VST3 loaded · "+inserted.name+" · native PCM readback verified"); } } - if(pendingNativeFxPower?.acked){ - const p=pendingNativeFxPower; - const ch=next.graph.channels.find(x=>x.id===p.channelId); - const actual=p.kind==="rack"?ch?.fxRackBypassed: - ch?.inserts?.find(x=>x.id===p.insertId)?.bypassed; - if(actual===p.bypassed)pendingNativeFxPower=null; - } + const fxSettlement=fxRackVM.nativePowerSettlement(pendingNativeFxPower,next); + if(fxSettlement==="CONFIRMED"||fxSettlement==="STALE") + pendingNativeFxPower=null; if(startupWire)window.queueMicrotask(flushStartupWire); status("Mixer settings updated"); } From 85e2b6c6b53c085967598d02d2ce2c3c77713b1a Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 18 Nov 2026 10:41:01 +0700 Subject: [PATCH 2/3] test(gui): correct literal regex escaping in FX settlement ownership contracts --- tests/approved_native_m2_contract.test.cjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 56ee42459..ec57de38e 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -2865,8 +2865,8 @@ test("GUI-2 M4 rack pending selector rejects revisions and unaccepted authority" assert.equal(fxRackVM.m4RackSettlement({...p,acked:true}, {...s,channels:[{fxRackBypassed:false}]}),"WAIT"); const source=read("web/approved-native-bridge.js"); - assert.match(source,/fxRackVM\\.m4Presentation\\(/); - assert.match(source,/fxRackVM\\.nativePowerSettlement\\(/); - assert.match(source,/fxRackVM\\.m4RackSettlement\\(/); - assert.doesNotMatch(source,/const actual=p\\.kind==="rack"\\?/); + assert.match(source,/fxRackVM\.m4Presentation\(); + assert.match(source,/fxRackVM\.nativePowerSettlement\(); + assert.match(source,/fxRackVM\.m4RackSettlement\(); + assert.doesNotMatch(source,/const actual=p\.kind==="rack"\?/); }); From 81266ed338fbfdeadfc6a2d4ddb90ad4f813c81f Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 18 Nov 2026 10:42:48 +0700 Subject: [PATCH 3/3] test(gui): assert extracted FX method calls without malformed regular expressions --- tests/approved_native_m2_contract.test.cjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index ec57de38e..84cd2d6ef 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -2865,8 +2865,8 @@ test("GUI-2 M4 rack pending selector rejects revisions and unaccepted authority" assert.equal(fxRackVM.m4RackSettlement({...p,acked:true}, {...s,channels:[{fxRackBypassed:false}]}),"WAIT"); const source=read("web/approved-native-bridge.js"); - assert.match(source,/fxRackVM\.m4Presentation\(); - assert.match(source,/fxRackVM\.nativePowerSettlement\(); - assert.match(source,/fxRackVM\.m4RackSettlement\(); + assert.ok(source.includes("fxRackVM.m4Presentation(")); + assert.ok(source.includes("fxRackVM.nativePowerSettlement(")); + assert.ok(source.includes("fxRackVM.m4RackSettlement(")); assert.doesNotMatch(source,/const actual=p\.kind==="rack"\?/); });