diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index d11272cec..f15acb71b 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -2181,7 +2181,9 @@ test("P0 MAIN WIRE unplug uses UI-to-native EdgeId and no fake graph",()=>{ test("P0 real slot VST3 power and native editor use verified instance tokens",()=>{ const bridge=read("web/approved-native-bridge.js"); const main=read("src/Main.cpp"); - assert.match(bridge,/function verifiedFxFor\(t,slot\)/); + assert.match(bridge,/fxRackVM\.m4EditorPlan\(current,/); + assert.match(read("web/approved-fx-rack-view-model.js"),/function m4EditorPlan\(snapshot,/); + assert.doesNotMatch(bridge,/function verifiedFxFor\(/); assert.match(bridge,/function requestM4FxPower\(t,action,button=null\)/); assert.match(bridge,/if\(action==="slotPower"\)/); assert.match(bridge,/if\(action==="fxOn"\)/); @@ -3611,8 +3613,13 @@ test("native FX remove/reorder/transfer requires exact token, ACK and ordered re test("ImmerSIB opens the exact native ChannelId HWND, survives VST3 editor, no success-only toast",()=>{ const bridge=read("web/approved-native-bridge.js"),host=read("src/Main.cpp"); - assert.match(bridge,/insert\.catalogId==='armix\.builtin\.imersip\.v1' && current\.admitted/); - assert.match(bridge,/backend\.emitEvent\("arMixAction",\{action:"routingFxEditor",channelId:id,slot,/); + const editorVM=read("web/approved-fx-rack-view-model.js"); + assert.match(bridge,/fxRackVM\.editorNavigationPlan\(current,/); + assert.match(editorVM,/view\.raw\?\.mixerSession\?\.authority==="CHANNEL_ID"/); + assert.match(bridge,/else \{\s*\/\/ Both vendor VST3 and ImmerSIB retain their exact real/); + assert.match(bridge,/backend\.emitEvent\("arMixAction",\{action:"routingFxEditor",\s*channelId:editor\.channelId,slot:editor\.slot,/); + assert.match(bridge,/else if\(editor\.authority==="LOGICAL"\)/); + assert.match(bridge,/action:"logicalVendorFxEditor"/); assert.doesNotMatch(bridge,/else status\("Native VST3 editor opened"\)/); assert.match(host,/shownWindow=dedicatedImmerSIB\?immersibEditorWindow_:editorWindow_/); assert.match(host,/shownOwner=dedicatedImmerSIB\?immersibEditorOwner_:routedEditorOwner_/); @@ -5934,3 +5941,115 @@ test("G-MV30 bridge has one M4 insert IPC, and never paints or opens from ack.st assert.doesNotMatch(ack,/ack\?\.state|paintM4FxInstances\(|openRoutedFxEditor\(/); assert.doesNotMatch(source,/document\.|window\.|backend\.emitEvent|setTimeout/); }); + +// G-MV31: automatic native/logical FX editor navigation must never cross a +// session generation between confirmed readback and the queued microtask. +test("G-MV31 ChannelId FX editor action is bound to physical graph, roster, device and instance",()=>{ + const raw=gmv20AcceptedGraph(); + raw.mixerSession={authority:"CHANNEL_ID",deviceEpoch:raw.device.epoch, + routeRevision:raw.graph.revision,rosterRevision:raw.graph.rosterRevision}; + raw.graph.channels[0].inserts=[{id:"instance-native-22", + catalogId:"vendor.fx-22",name:"Delay",bypassed:false}]; + const snap=protocol.normalizeSnapshot(raw); + assert.ok(snap?.admitted,"must start from genuinely normalized native snapshot"); + const id=snap.graph.channels[0].id, + hw=protocol.nativeHardwareConfiguration(snap.device); + const open=fxRackVM.editorNavigationPlan(snap,{ + channelId:id,slot:0,hardwareConfiguration:hw}); + assert.equal(open.kind,"OPEN"); + assert.equal(open.lease.authority,"CHANNEL_ID"); + assert.equal(open.lease.channelId,id); + assert.equal(open.lease.instanceId,"instance-native-22"); + assert.equal(fxRackVM.editorNavigationLeaseMatches(snap,open.lease, + {hardwareConfiguration:hw}),true); + for(const edit of [ + s=>{s.device.epoch="9999";s.raw.mixerSession.deviceEpoch="9999";}, + s=>{s.graph.revision="998";}, + s=>{s.graph.rosterRevision="997";}, + s=>{s.graph.channels[0].inserts[0].id="instance-replacement";}, + s=>{s.graph.channels[0].inserts[0].catalogId="another.vendor";}, + s=>{s.raw.mixerSession.authority="M4";}, + s=>{s.retained=true;s.admitted=false;}, + s=>{s.graph.channels[0].inserts=[];}, + s=>{s.graph.channels.push({...s.graph.channels[0]});}, + ]){ + const next=clone(snap);edit(next); + assert.equal(fxRackVM.editorNavigationLeaseMatches(next,open.lease, + {hardwareConfiguration:hw}),false); + } + assert.equal(fxRackVM.editorNavigationLeaseMatches(snap,open.lease, + {hardwareConfiguration:hw+":new-buffer"}),false, + "same-epoch device configuration replacement must revoke HWND navigation"); + assert.equal(fxRackVM.editorNavigationPlan(snap,{ + channelId:id,slot:1,hardwareConfiguration:hw}).kind,"PICKER"); + assert.equal(fxRackVM.editorNavigationPlan(snap,{ + channelId:id,slot:0,hardwareConfiguration:null}).kind,"UNAVAILABLE"); + assert.equal(fxRackVM.editorNavigationPlan(snap,{ + channelId:"9007199254740993",slot:0,hardwareConfiguration:hw}).kind,"UNAVAILABLE"); +}); +test("G-MV31 .smix editor navigation is scoped to exact workspace, graph, and FX lease",()=>{ + const ch={id:"9007199254740993",role:"INPUT", + inserts:[{id:"logical-instance",catalogId:"catalog.test"}]}; + const base={logical:true,admitted:false,retained:false,workspaceToken:"work-a", + device:{epoch:"0"}, + graph:{revision:"5",rosterRevision:"5",channels:[ch]}}; + const params={channelId:ch.id,slot:0}; + const open=fxRackVM.editorNavigationPlan(base,params); + assert.equal(open.kind,"OPEN"); + assert.equal(open.lease.authority,"LOGICAL"); + assert.equal(open.lease.workspaceToken,"work-a"); + assert.equal(open.lease.deviceEpoch,null); + assert.equal(fxRackVM.editorNavigationLeaseMatches(base,open.lease),true); + const changed=clone(base); + changed.workspaceToken="work-b"; + assert.equal(fxRackVM.editorNavigationLeaseMatches(changed,open.lease),false); + changed.workspaceToken="work-a";changed.graph.revision="6"; + assert.equal(fxRackVM.editorNavigationLeaseMatches(changed,open.lease),false); + const physical=clone(base);physical.logical=false;physical.admitted=true; + assert.equal(fxRackVM.editorNavigationLeaseMatches(physical,open.lease),false); + const offline=clone(base);offline.retained=true; + assert.equal(fxRackVM.editorNavigationPlan(offline,params).kind,"UNAVAILABLE"); + const empty=clone(base);empty.graph.channels[0].inserts=[]; + assert.equal(fxRackVM.editorNavigationPlan(empty,params).kind,"PICKER"); +}); +test("G-MV31 manual M4 editor must read one admitted FX slot from current host",()=>{ + const snap={admitted:false,retained:false,device:{epoch:"55"},raw:{ + mixerSession:{authority:"M4",deviceEpoch:"55",routeRevision:"12", + channels:Array.from({length:10},()=>({role:"INPUT"}))}, + legacyM4:{active:true,routeAccepted:true,nativeBusStructural:false, + routingRevision:"12",fxInstances:Array.from({length:10},()=>[])} + }}; + snap.raw.legacyM4.fxInstances[4][0]={ + instanceId:"verified-m4-fx",catalogId:"vendor.m4",bypassed:false}; + const args={channel:4,slot:0,verifiedM4:true}; + assert.deepEqual(fxRackVM.m4EditorPlan(snap,args),{kind:"OPEN", + channel:4,slot:0,instanceId:"verified-m4-fx",deviceEpoch:55,revision:12}); + assert.equal(fxRackVM.m4EditorPlan(snap,{...args,slot:1}).kind,"PICKER"); + for(const delta of [ + {verifiedM4:false},{offline:true},{channel:-1},{slot:8} + ])assert.equal(fxRackVM.m4EditorPlan(snap,{...args,...delta}).kind,"UNAVAILABLE"); + for(const change of [ + s=>{s.raw.mixerSession.authority="CHANNEL_ID";}, + s=>{s.raw.legacyM4.routingRevision="13";}, + s=>{s.device.epoch="56";}, + s=>{s.raw.legacyM4.routeAccepted=false;}, + s=>{s.raw.legacyM4.nativeBusStructural=true;}, + s=>{s.raw.legacyM4.fxInstances[4][0].instanceId="";} + ]){ + const v=clone(snap);change(v); + assert.equal(fxRackVM.m4EditorPlan(v,args).kind,"UNAVAILABLE"); + } +}); +test("G-MV31 bridge delegates deferred and manually opened FX editors to one pure plan",()=>{ + const bridge=read("web/approved-native-bridge.js"); + assert.match(bridge,/fxRackVM\.editorNavigationPlan\(verified,/); + assert.match(bridge,/fxRackVM\.editorNavigationPlan\(current,/); + assert.match(bridge,/fxRackVM\.editorNavigationLeaseMatches\(current,lease,/); + assert.match(bridge,/track&&nativeIdFor\(track\)===channelId/); + assert.match(bridge,/fxRackVM\.m4EditorPlan\(current,/); + assert.doesNotMatch(bridge,/function verifiedFxFor\(/); + assert.match(bridge,/scope\?\.closeNativePicker\?\.\(\)/); + assert.match(bridge,/openVerifiedInsertedFx\(p\.channelId,p\.slot,p\.catalogId,inserted\.id\)/); + assert.doesNotMatch(read("web/approved-fx-rack-view-model.js"), + /backend\.emitEvent|document\.|window\.|setTimeout/); +}); diff --git a/tests/rc_operator_workflow_contract.test.mjs b/tests/rc_operator_workflow_contract.test.mjs index bc46d6113..cc00588d0 100644 --- a/tests/rc_operator_workflow_contract.test.mjs +++ b/tests/rc_operator_workflow_contract.test.mjs @@ -52,7 +52,10 @@ test('built-in FX preset store works with verified offline logical workspace',() }); test('FX picker closes and opens an actual editor only after accepted native or logical readback',()=>{ assert.match(bridge,/function openVerifiedInsertedFx\(channelId,slot,catalogId,instanceId\)/); - assert.match(bridge,/effect\.id!==instanceId\|\|effect\.catalogId!==catalogId/); + assert.match(bridge,/plan\.lease\.instanceId!==instanceId/); + assert.match(bridge,/plan\.lease\.catalogId!==catalogId/); + assert.match(bridge,/fxRackVM\.editorNavigationLeaseMatches\(current,lease,/); + assert.match(bridge,/fxRackVM\.m4EditorPlan\(current,/); assert.match(bridge,/justInsertedLogicalFx/); assert.match(bridge,/scope\?\.closeNativePicker\?\.\(\);\s*openVerifiedInsertedFx\(p\.channelId,p\.slot,p\.catalogId,inserted\.id\)/); // Native editor requires verified accepted lease, not catalog key or ACK. diff --git a/web/approved-fx-rack-view-model.js b/web/approved-fx-rack-view-model.js index b3b325735..405ecc438 100644 --- a/web/approved-fx-rack-view-model.js +++ b/web/approved-fx-rack-view-model.js @@ -261,6 +261,86 @@ revision}; } + + // G-MV31: one exact, immutable navigation policy for the verified /preview/ + // FX editor. No HWND, IPC, DOM or duplicated editor state lives in this VM. + // Capture the accepted graph and device generation before a deferred click; + // the same generation must still own the instance when it is consumed. + function editorNavigationPlan(view,{channelId:id,slot, + hardwareConfiguration}={}) { + const unavailable={kind:"UNAVAILABLE"},graph=view?.graph; + if(!channelId(id)||!Number.isInteger(slot)||slot<0||slot>=8|| + !rosterUnique(graph)||!Array.isArray(graph?.channels)|| + !channelId(graph.revision)||!channelId(graph.rosterRevision)|| + new Set(graph.channels.map(ch=>ch.id)).size!==graph.channels.length) + return unavailable; + const offline=view?.logical===true&&view?.admitted===false&& + view?.retained===false&& + typeof view.workspaceToken==="string"&&view.workspaceToken.length>0; + const physical=view?.logical!==true&&view?.admitted===true&& + view?.retained===false&& + view.graph.capabilities?.callbackOwnsChannelIds===true&& + view.raw?.mixerSession?.authority==="CHANNEL_ID"&& + view.raw.mixerSession.deviceEpoch===view.device?.epoch&& + channelId(view.device.epoch)&& + typeof hardwareConfiguration==="string"&&hardwareConfiguration.length>0; + if(!offline&&!physical)return unavailable; + const rows=graph.channels.filter(ch=>ch.id===id); + if(rows.length!==1||!VALID_ROLES.has(rows[0].role)|| + !Array.isArray(rows[0].inserts))return unavailable; + const effect=rows[0].inserts[slot]; + if(effect==null)return {kind:"PICKER"}; + if(typeof effect.id!=="string"||!effect.id|| + typeof effect.catalogId!=="string"||!effect.catalogId) + return unavailable; + const lease=Object.freeze({ + authority:offline?"LOGICAL":"CHANNEL_ID", + channelId:id,slot,instanceId:effect.id,catalogId:effect.catalogId, + graphRevision:graph.revision,rosterRevision:graph.rosterRevision, + workspaceToken:offline?view.workspaceToken:null, + deviceEpoch:physical?view.device.epoch:null, + hardwareConfiguration:physical?hardwareConfiguration:null + }); + return {kind:"OPEN",lease}; + } + function editorNavigationLeaseMatches(view,lease,{hardwareConfiguration}={}) { + if(!lease||typeof lease!=="object")return false; + const now=editorNavigationPlan(view,{ + channelId:lease.channelId,slot:lease.slot,hardwareConfiguration}); + if(now.kind!=="OPEN")return false; + return Object.keys(now.lease).every(key=>now.lease[key]===lease[key])&& + Object.keys(lease).length===Object.keys(now.lease).length; + } + + // M4 uses host ordinals, never ChannelIds. An old accepted FX inventory + // cannot be permission to open an editor after device/route owner changes. + function m4EditorPlan(snapshot,{channel,slot,verifiedM4=false, + offline=false}={}) { + const unavailable={kind:"UNAVAILABLE"},s=snapshot?.raw?.mixerSession, + m=snapshot?.raw?.legacyM4, + epoch=safeM4Token(snapshot?.device?.epoch), + revision=safeM4Token(m?.routingRevision); + if(offline||verifiedM4!==true||snapshot?.admitted!==false|| + snapshot?.retained===true||s?.authority!=="M4"|| + m?.active!==true||m.routeAccepted!==true|| + m.nativeBusStructural===true||epoch===null||revision===null|| + s.deviceEpoch!==snapshot.device.epoch|| + s.routeRevision!==m.routingRevision|| + !Array.isArray(s.channels)||s.channels.length!==10|| + !Number.isInteger(channel)||channel<0||channel>=10|| + !s.channels[channel]|| + !Number.isInteger(slot)||slot<0||slot>=8)return unavailable; + const slots=m.fxInstances?.[channel]; + if(!Array.isArray(slots))return unavailable; + const effect=slots[slot]; + if(effect==null)return {kind:"PICKER"}; + if(typeof effect.instanceId!=="string"||!effect.instanceId|| + typeof effect.catalogId!=="string"||!effect.catalogId) + return unavailable; + return {kind:"OPEN",channel,slot,instanceId:effect.instanceId, + deviceEpoch:epoch,revision}; + } + function nativeInsertPlan(snapshot,{channelId:id,slot,catalogId,pending=false}={}) { const graph=snapshot?.graph; if(pending||snapshot?.admitted!==true||snapshot?.retained===true|| @@ -429,6 +509,7 @@ m4Presentation,nativePowerSettlement,m4PowerPlan,m4RackAckResult, m4RackSettlement, m4InsertPlan,m4InsertAckResult,m4InsertReadbackSettlement, + editorNavigationPlan,editorNavigationLeaseMatches,m4EditorPlan, nativeInsertPlan,nativeEditPlan,nativeInsertSettlement, nativePowerPlan,nativePowerAckResult, globalPowerContext,globalPowerPlan,globalPowerAckResult, diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 63a84540f..7240e01ed 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -1336,15 +1336,21 @@ // never infer an instance from a catalog name. Reuse the installed editor // action for both native DSP and vendor VST3s, after exact graph readback. function openVerifiedInsertedFx(channelId,slot,catalogId,instanceId) { + const verified=activeView(); + const plan=fxRackVM.editorNavigationPlan(verified,{channelId,slot, + hardwareConfiguration:protocol.nativeHardwareConfiguration(verified?.device)}); + if(plan.kind!=="OPEN"||plan.lease.instanceId!==instanceId|| + plan.lease.catalogId!==catalogId)return; + const lease=plan.lease; // exact workspace, ChannelId, roster and device window.queueMicrotask(()=>{ - const view=activeView(); - const effect=view?.graph?.channels?.find(ch=>ch.id===channelId) - ?.inserts?.[slot]; - if(!effect||effect.id!==instanceId||effect.catalogId!==catalogId)return; + const current=activeView(); + if(!fxRackVM.editorNavigationLeaseMatches(current,lease,{ + hardwareConfiguration:protocol.nativeHardwareConfiguration(current?.device)})) + return; // a replaced session must never inherit the old editor click const local=uiByNativeId.get(channelId); const track=[...(scope?.tracks||[]),scope?.master] .find(item=>item?.id===local); - if(track) + if(track&&nativeIdFor(track)===channelId) window.__ARMIX_NATIVE_M2__?.consumeAction?.(track,"openPlugin", {dataset:{slot:String(slot)}}); }); @@ -1382,13 +1388,6 @@ const pendingSlotPowers=new Map(); // ACK/readback, never demo FX flags // The rack header restores exact prior per-insert state, including // deliberately bypassed plugins; it never blindly turns ALL FX on. - function verifiedFxFor(t,slot){ - const lane=m4Index(t),live=legacy()?.fxInstances?.[lane]?.[slot]; - return lane>=0 && Number.isInteger(slot) && slot>=0&&slot<8 && - live && typeof live.instanceId==="string" && - live.instanceId && typeof live.catalogId==="string"? - {lane,slot,live}:null; - } function editNativeFx(t,slot,target,position,token){ const current=controller?.state()?.current,id=nativeIdFor(t); const decision=fxRackVM.nativeEditPlan(current,{ @@ -3591,54 +3590,53 @@ editNativeFx(t,slot,null,0,token);return true; } if(action==="openPlugin"){ + const slot=Number(btn?.dataset.slot),current=activeView(); if(logicalView||mixerSession()?.authority==="CHANNEL_ID") { - const current=activeView(),id=nativeIdFor(t),slot=Number(btn?.dataset.slot); - if(!Number.isInteger(slot)||slot<0||slot>=8)return true; - const insert=current?.graph?.channels.find(ch=>ch.id===id)?.inserts?.[slot]; - if(!insert?.id) { + const id=nativeIdFor(t); + const plan=fxRackVM.editorNavigationPlan(current,{channelId:id,slot, + hardwareConfiguration:protocol.nativeHardwareConfiguration(current?.device)}); + if(plan.kind==="PICKER"){ discoverFxOnFirstPickerOpen(); scope?.openFastPicker?.(t,slot,btn); - } else if(current.admitted||current.logical) { - if(insert.catalogId==='armix.builtin.channel-eq.v1') { + }else if(plan.kind==="OPEN"){ + const editor=plan.lease; + if(editor.catalogId==='armix.builtin.channel-eq.v1') { window.ArSonMixNativeEq?.open(t,slot); - } else if(insert.catalogId==='armix.builtin.channel-compressor.v1') { + } else if(editor.catalogId==='armix.builtin.channel-compressor.v1') { window.ArSonMixNativeCompressor?.open(t,slot); - } else if(insert.catalogId==='armix.builtin.arson-harmony.v1') { + } else if(editor.catalogId==='armix.builtin.arson-harmony.v1') { window.ArSonMixNativeHarmony?.open(t,slot); - } else if(insert.catalogId==='armix.builtin.vocal-throw.v1') { + } else if(editor.catalogId==='armix.builtin.vocal-throw.v1') { window.ArSonMixNativeVocalThrow?.open(t,slot); - } else if(insert.catalogId==='armix.builtin.8d-sonku.v1') { + } else if(editor.catalogId==='armix.builtin.8d-sonku.v1') { if(window.ArSonMixNativeSonKu?.open) window.ArSonMixNativeSonKu.open(t,slot); else nativeToast("8D-SonKu editor unavailable · refresh the approved GUI bundle"); - } else if(insert.catalogId==='armix.builtin.imersip.v1' && current.admitted) { - // ImmerSIB is a real JUCE AudioProcessorEditor, not a - // WebView2 SonKu overlay, preset-change action or demo FX. - // Route the exact accepted ChannelId/lease into the dedicated - // native HWND, which remains open when a VST3 editor is opened. - backend.emitEvent("arMixAction",{action:"routingFxEditor",channelId:id,slot, - instanceId:insert.id,deviceEpoch:current.device.epoch, - revision:current.graph.revision}); - } else if(current.logical) { - backend.emitEvent("arMixAction",{action:"logicalVendorFxEditor",channelId:id, - slot,instanceId:insert.id,workspaceToken:current.workspaceToken, - graphRevision:current.graph.revision,deviceEpoch:"0"}); - } else backend.emitEvent("arMixAction",{action:"routingFxEditor",channelId:id,slot, - instanceId:insert.id,deviceEpoch:current.device.epoch,revision:current.graph.revision}); - } else nativeToast("This FX is held with the disconnected audio session"); + } else if(editor.authority==="LOGICAL") { + backend.emitEvent("arMixAction",{action:"logicalVendorFxEditor", + channelId:editor.channelId,slot:editor.slot,instanceId:editor.instanceId, + workspaceToken:editor.workspaceToken, + graphRevision:editor.graphRevision,deviceEpoch:"0"}); + } else { + // Both vendor VST3 and ImmerSIB retain their exact real + // JUCE HWND path; no parallel WebView editor authority. + backend.emitEvent("arMixAction",{action:"routingFxEditor", + channelId:editor.channelId,slot:editor.slot, + instanceId:editor.instanceId,deviceEpoch:editor.deviceEpoch, + revision:editor.graphRevision}); + } + }else nativeToast("This FX is held with the disconnected audio session"); return true; } - const slot=Number(btn?.dataset.slot),instance=verifiedFxFor(t,slot); - if(instance){ - const ep=safeNativeCounter(hardware?.device?.epoch), - rev=safeNativeCounter(legacy()?.routingRevision); - if(ep!==null&&rev!==null) - openRoutedFxEditor(instance.lane,slot,instance.live.instanceId,ep,rev); - else nativeToast("VST3 editor · refresh native device and FX instance"); - }else { + const plan=fxRackVM.m4EditorPlan(current,{ + channel:m4Index(t),slot,verifiedM4:m4Verified(),offline:!!logicalView}); + if(plan.kind==="OPEN") + openRoutedFxEditor(plan.channel,plan.slot,plan.instanceId, + plan.deviceEpoch,plan.revision); + else if(plan.kind==="PICKER"){ discoverFxOnFirstPickerOpen(); scope?.openFastPicker?.(t,slot,btn); - } + }else nativeToast("VST3 editor · refresh native device and FX instance"); return true; } if(action==="slotPower"){