From 04cb49c95e4c3631bb8cb7ac78937d88690e69f3 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 20 Nov 2026 09:31:25 +0700 Subject: [PATCH 1/3] refactor(gui G-MV37): single accepted M/ST format policy for .smix, ChannelId and M4 --- tests/approved_native_m2_contract.test.cjs | 97 +++++++++++++++++++++- web/approved-channel-strip-view-model.js | 55 +++++++++++- web/approved-native-bridge.js | 51 +++++------- 3 files changed, 169 insertions(+), 34 deletions(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 7471f7d41..8a040c03d 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -1924,8 +1924,8 @@ test("M/ST after BUS/WIRE uses native ChannelId intent and accepted PCM processi const fn=bridge.slice(bridge.indexOf("function requestProcessingFormat(t)"), bridge.indexOf("function previewNativePan(t,el,event)")); assert.match(fn,/session\(\)\?\.authority|mixerSession\(\)\?\.authority/); - assert.match(fn,/controller.intent\("SET_PROCESSING_FORMAT",channelId,/); - assert.ok(fn.includes('dispatchM4ChannelPatch(t,"SET_PROCESSING_FORMAT"')); + assert.match(fn,/controller\\.intent\\(plan\\.operation,plan\\.channelId,plan\\.payload\\)/); + assert.ok(fn.includes('dispatchM4ChannelPatch(t,plan.operation,plan.target,plan.channel)')); assert.ok(fn.indexOf('authority==="CHANNEL_ID"')< fn.indexOf('dispatchM4ChannelPatch(t,"SET_PROCESSING_FORMAT"')); }); @@ -2159,7 +2159,7 @@ test("P0 typed mono-stereo, PAN detent, fader geometry & FX failure diagnostics" assert.match(bridge,/const width=event\.type==="change"\?18:latched\?22:14/); assert.match(bridge,/readout\.textContent=value===0\?"C"/); assert.match(bridge,/function requestProcessingFormat\(t\)/); - assert.ok(bridge.includes('dispatchM4ChannelPatch(t,"SET_PROCESSING_FORMAT"')); + assert.ok(bridge.includes('dispatchM4ChannelPatch(t,plan.operation,plan.target,plan.channel)')); assert.ok(read("web/approved-channel-strip-view-model.js").includes('operation==="SET_PROCESSING_FORMAT"')); assert.match(bridge,/if\(action==="format"&&t\?\.kind==="audio"\)/); assert.match(main,/operation=="SET_PROCESSING_FORMAT"/); @@ -6398,3 +6398,94 @@ test("G-MV35 native MOVE/REMOVE FX demands installed ChannelId hardware owner",( assert.match(bridge,/fxRackVM\.nativeEditPlan\(current,/); assert.doesNotMatch(pure,/backend\.emitEvent|document\.|window\.|setTimeout/); }); + +test("G-MV37 one physical ChannelId M/ST policy validates exact accepted input",()=>{ + const id="9007199254740993",hw="asio|48000|256|0,1|0,1"; + const graph={revision:"45",rosterRevision:"8", + capabilities:{callbackOwnsChannelIds:true, + supportedOps:["SET_PROCESSING_FORMAT"]}, + channels:[{id,role:"INPUT",processingFormat:"MONO"}]}; + const native={admitted:true,retained:false,logical:false, + device:{epoch:"17"},raw:{mixerSession:{ + authority:"CHANNEL_ID",deviceEpoch:"17"}},graph}; + const get=(snapshot=native,args={})=>stripVM.processingFormatPlan(snapshot,{ + authority:"CHANNEL_ID",channelId:id,hardwareConfiguration:hw,...args}); + assert.deepEqual(get(),{kind:"READY",authority:"CHANNEL_ID", + operation:"SET_PROCESSING_FORMAT",channelId:id, + payload:{format:"STEREO"},target:"STEREO"}); + const stereo=clone(native);stereo.graph.channels[0].processingFormat="STEREO"; + assert.equal(get(stereo).target,"MONO"); + for(const h of ["",null,0]) + assert.equal(get(native,{hardwareConfiguration:h}).kind,"UNAVAILABLE"); + for(const mutation of [ + s=>{s.admitted=false;},s=>{s.retained=true;},s=>{s.logical=true;}, + s=>{s.raw.mixerSession.authority="M4";}, + s=>{s.raw.mixerSession.deviceEpoch="18";}, + s=>{s.device.epoch="0";},s=>{s.graph.revision="0";}, + s=>{s.graph.rosterRevision="0";}, + s=>{s.graph.capabilities.callbackOwnsChannelIds=false;}, + s=>{s.graph.capabilities.supportedOps=[];}, + s=>{s.graph.channels[0].role="GROUP";}, + s=>{s.graph.channels[0].processingFormat="UNKNOWN";}, + s=>{s.graph.channels.push({...s.graph.channels[0]});} + ]){const snapshot=clone(native);mutation(snapshot); + assert.equal(get(snapshot).kind,"UNAVAILABLE");} + assert.equal(get(native,{pending:true}).kind,"UNAVAILABLE"); +}); +test("G-MV37 .smix M/ST stays offline and workspace-scoped",()=>{ + const id="9007199254740993"; + const saved={logical:true,admitted:false,retained:false,readOnly:false, + workspaceToken:"workspace-A",graph:{ + capabilities:{supportedOps:["SET_PROCESSING_FORMAT"]}, + channels:[{id,role:"INPUT",processingFormat:"STEREO"}]}}; + const get=(snapshot=saved,args={})=>stripVM.processingFormatPlan(snapshot,{ + authority:"LOGICAL",channelId:id,...args}); + assert.deepEqual(get(),{kind:"READY",authority:"LOGICAL", + operation:"SET_PROCESSING_FORMAT",channelId:id, + payload:{format:"MONO"},target:"MONO"}); + for(const mutation of [ + s=>{s.logical=false;},s=>{s.admitted=true;},s=>{s.retained=true;}, + s=>{s.readOnly=true;},s=>{s.workspaceToken="";}, + s=>{s.graph.capabilities.supportedOps=[];}, + s=>{s.graph.channels[0].processingFormat=null;}, + s=>{s.graph.channels.push({...s.graph.channels[0]});} + ]){const snapshot=clone(saved);mutation(snapshot); + assert.equal(get(snapshot).kind,"UNAVAILABLE");} + assert.equal(get(saved,{pending:true}).kind,"UNAVAILABLE"); +}); +test("G-MV37 M4 M/ST reuses exact existing routed channel patch",()=>{ + const sessionChannels=Array.from({length:10},(_,i)=>({ + role:"INPUT",ordinal:i,source:{main:false,channelFormat:"MONO"}, + primaryOut:"NONE"})); + const legacyChannels=sessionChannels.map(()=>({main:false,channelFormat:"MONO"})); + const snapshot={admitted:false,retained:false,device:{epoch:"21"},raw:{ + mixerSession:{authority:"M4",deviceEpoch:"21",routeRevision:"12", + channels:sessionChannels}, + legacyM4:{active:true,routeAccepted:true,nativeBusStructural:false, + routingRevision:"12",channels:legacyChannels}}}; + const opts={authority:"M4",channel:4,verifiedM4:true,deviceReady:true, + hardwareConfiguration:"physical-lease"}; + const plan=stripVM.processingFormatPlan(snapshot,opts); + assert.equal(plan.kind,"READY"); + assert.equal(plan.operation,"SET_PROCESSING_FORMAT"); + assert.equal(plan.action,"routingChannelPatch"); + assert.equal(plan.target,"STEREO"); + assert.equal(plan.payload.channel,4); + for(const change of [ + {verifiedM4:false},{deviceReady:false},{pending:true}, + {sourcePending:true},{hardwareConfiguration:null}, + {hardwareConfiguration:""},{channel:10} + ])assert.equal(stripVM.processingFormatPlan(snapshot,{...opts,...change}).kind, + "UNAVAILABLE"); + const wrong=clone(snapshot); + wrong.raw.mixerSession.channels[4].source.channelFormat="STEREO"; + assert.equal(stripVM.processingFormatPlan(wrong,opts).kind,"UNAVAILABLE"); + const bridge=read("web/approved-native-bridge.js"); + const section=bridge.slice(bridge.indexOf("function requestProcessingFormat(t)"), + bridge.indexOf("function previewNativePan(t,el,event)")); + assert.match(section,/stripVM\.processingFormatPlan\(snapshot,/); + assert.match(section,/logicalIntent\(plan\.operation,plan\.channelId,plan\.payload\)/); + assert.match(section,/controller\.intent\(plan\.operation,plan\.channelId,plan\.payload\)/); + assert.match(section,/dispatchM4ChannelPatch\(t,plan\.operation,plan\.target,plan\.channel\)/); + assert.doesNotMatch(section,/const target=.*processingFormat|channelFormat===/); +}); diff --git a/web/approved-channel-strip-view-model.js b/web/approved-channel-strip-view-model.js index b3a00a901..b78e84ea3 100644 --- a/web/approved-channel-strip-view-model.js +++ b/web/approved-channel-strip-view-model.js @@ -1009,7 +1009,60 @@ return plan.kind==="READY"?{kind:"SEND",plan}:{kind:"DEFER"}; } - return Object.freeze({outputTargets,inputChoices,externalChoices, + // G-MV37: the only M/ST decision across saved, ChannelId and M4. + // UI proposes a change, never mutates accepted PCM before native readback. + function processingFormatPlan(snapshot,{authority,channelId,channel, + hardwareConfiguration,verifiedM4=false,deviceReady=false, + pending=false,sourcePending=false}={}) { + const bad={kind:"UNAVAILABLE"},graph=snapshot?.graph; + if(pending||snapshot?.retained===true)return bad; + if(authority==="LOGICAL"){ + if(snapshot?.logical!==true||snapshot?.admitted!==false|| + snapshot?.readOnly===true|| + typeof snapshot.workspaceToken!=="string"||!snapshot.workspaceToken|| + !decimalId(channelId)||!Array.isArray(graph?.channels)|| + !graph.capabilities?.supportedOps?.includes("SET_PROCESSING_FORMAT")) + return bad; + const rows=graph.channels.filter(ch=>ch?.id===channelId); + if(rows.length!==1||rows[0].role!=="INPUT"|| + !["MONO","STEREO"].includes(rows[0].processingFormat))return bad; + const target=rows[0].processingFormat==="MONO"?"STEREO":"MONO"; + return {kind:"READY",authority,operation:"SET_PROCESSING_FORMAT", + channelId,payload:{format:target},target}; + } + if(typeof hardwareConfiguration!=="string"||!hardwareConfiguration) + return bad; + if(authority==="CHANNEL_ID"){ + const session=snapshot?.raw?.mixerSession; + if(snapshot?.admitted!==true||snapshot?.logical===true|| + session?.authority!=="CHANNEL_ID"|| + session.deviceEpoch!==snapshot.device?.epoch|| + !decimalId(snapshot.device?.epoch)|| + !decimalId(graph?.revision)||!decimalId(graph?.rosterRevision)|| + graph.capabilities?.callbackOwnsChannelIds!==true|| + !graph.capabilities?.supportedOps?.includes("SET_PROCESSING_FORMAT")|| + !decimalId(channelId)||!Array.isArray(graph?.channels))return bad; + const rows=graph.channels.filter(ch=>ch?.id===channelId); + if(rows.length!==1||rows[0].role!=="INPUT"|| + !["MONO","STEREO"].includes(rows[0].processingFormat))return bad; + const target=rows[0].processingFormat==="MONO"?"STEREO":"MONO"; + return {kind:"READY",authority,operation:"SET_PROCESSING_FORMAT", + channelId,payload:{format:target},target}; + } + if(authority==="M4"){ + const current=snapshot?.raw?.legacyM4?.channels?.[channel]?.channelFormat; + if(!["MONO","STEREO"].includes(current))return bad; + const target=current==="MONO"?"STEREO":"MONO"; + const plan=m4ChannelPatchPlan(snapshot,{ + operation:"SET_PROCESSING_FORMAT",channel,target, + verifiedM4,deviceReady,pending,sourcePending}); + if(plan.kind!=="READY")return bad; + return {kind:"READY",authority,operation:"SET_PROCESSING_FORMAT", + channel,target,action:plan.action,payload:plan.payload}; + } + return bad; + } + return Object.freeze({processingFormatPlan,outputTargets,inputChoices,externalChoices, primaryChoices,resolvePrimarySelection,readbackBindings,externalPending, primaryOutMutation,externalOutputPlan,rosterMutationPlan, rosterAckResult,rosterReadbackSettlement,m4ChannelPatchPlan, diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 109d16152..d91e66f2e 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -901,40 +901,31 @@ } function requestProcessingFormat(t){ - if(logicalView){ - const id=nativeIdFor(t),source=logicalView.graph.channels.find(ch=>ch.id===id); - if(source?.role!=="INPUT")return false; - const format=source.processingFormat==="MONO"?"STEREO":"MONO"; - return logicalIntent("SET_PROCESSING_FORMAT",id,{format}).ok; + const snapshot=activeView(),authority=logicalView?"LOGICAL": + mixerSession()?.authority; + const plan=stripVM.processingFormatPlan(snapshot,{ + authority,channelId:nativeIdFor(t),channel:m4Index(t), + hardwareConfiguration:logicalView?undefined: + protocol.nativeHardwareConfiguration(snapshot?.device), + verifiedM4:m4Verified(),deviceReady:deviceReady(), + pending:!!pendingOutputPatch||!!pendingLogical, + sourcePending:!!nativeUiSourcePending + }); + if(plan.kind!=="READY"){ + status("M/ST unavailable · refresh accepted native input/format"); + return false; } - // Once the native ChannelId callback owns PCM, the old M4 routing - // revision is no longer authoritative. Send M/ST through the SAME - // admitted epoch/revision/roster transaction as WIRE and SOURCE. - if(mixerSession()?.authority==="CHANNEL_ID"){ - const current=controller?.state()?.current; - const channelId=nativeIdFor(t); - const source=current?.graph?.channels?.find(ch=>ch.id===channelId); - if(!current?.admitted || !channelId || source?.role!=="INPUT" || - !current.graph.capabilities.supportedOps.includes("SET_PROCESSING_FORMAT")){ - status("M/ST unavailable · native processing format not admitted"); - return false; - } - const target=source.processingFormat==="MONO"?"STEREO":"MONO"; - const request=controller.intent("SET_PROCESSING_FORMAT",channelId, - {format:target}); - if(!request.ok){ - status("M/ST rejected · "+request.error); - return false; - } + if(authority==="LOGICAL") + return logicalIntent(plan.operation,plan.channelId,plan.payload).ok; + if(authority==="CHANNEL_ID"){ + // Existing controller alone correlates ACK + accepted PCM readback. + const request=controller.intent(plan.operation,plan.channelId,plan.payload); + if(!request.ok){status("M/ST rejected · "+request.error);return false;} window.setTimeout(()=>controller?.expire(request.requestId),8000); - status(t.name+" M/ST → "+target+" · verifying native PCM readback"); + status(t.name+" M/ST → "+plan.target+" · verifying native PCM readback"); return true; } - const channel=m4Index(t); - const accepted=controller?.state()?.current?.raw?.legacyM4?.channels?.[channel]; - const target=accepted?.channelFormat==="MONO"?"STEREO": - accepted?.channelFormat==="STEREO"?"MONO":null; - if(!dispatchM4ChannelPatch(t,"SET_PROCESSING_FORMAT",target,channel)){ + if(!dispatchM4ChannelPatch(t,plan.operation,plan.target,plan.channel)){ status("M/ST unavailable · wait for accepted hardware route"); return false; } From 03319a4d651b6dbe8e53ceb54b525356839673bf Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 20 Nov 2026 09:33:01 +0700 Subject: [PATCH 2/3] test(gui G-MV37): assert exact controller dispatch rather than escaped regex --- tests/approved_native_m2_contract.test.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 8a040c03d..3dc3da0c4 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -1924,7 +1924,7 @@ test("M/ST after BUS/WIRE uses native ChannelId intent and accepted PCM processi const fn=bridge.slice(bridge.indexOf("function requestProcessingFormat(t)"), bridge.indexOf("function previewNativePan(t,el,event)")); assert.match(fn,/session\(\)\?\.authority|mixerSession\(\)\?\.authority/); - assert.match(fn,/controller\\.intent\\(plan\\.operation,plan\\.channelId,plan\\.payload\\)/); + assert.ok(fn.includes('controller.intent(plan.operation,plan.channelId,plan.payload)')); assert.ok(fn.includes('dispatchM4ChannelPatch(t,plan.operation,plan.target,plan.channel)')); assert.ok(fn.indexOf('authority==="CHANNEL_ID"')< fn.indexOf('dispatchM4ChannelPatch(t,"SET_PROCESSING_FORMAT"')); From 624baf5dbf47b25239dffcf864cf7a56cdf78b9a Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 20 Nov 2026 09:34:13 +0700 Subject: [PATCH 3/3] test(gui G-MV37): verify native authority precedes actual M4 adapter after extraction --- tests/approved_native_m2_contract.test.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 3dc3da0c4..0b9ee5e82 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -1927,7 +1927,7 @@ test("M/ST after BUS/WIRE uses native ChannelId intent and accepted PCM processi assert.ok(fn.includes('controller.intent(plan.operation,plan.channelId,plan.payload)')); assert.ok(fn.includes('dispatchM4ChannelPatch(t,plan.operation,plan.target,plan.channel)')); assert.ok(fn.indexOf('authority==="CHANNEL_ID"')< - fn.indexOf('dispatchM4ChannelPatch(t,"SET_PROCESSING_FORMAT"')); + fn.indexOf('dispatchM4ChannelPatch(t,plan.operation,plan.target,plan.channel)')); }); test("P0 first Add FX discovers real local VST3 lazily without an audio-thread scan",()=>{ const bridge=read("web/approved-native-bridge.js");