Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 143 additions & 4 deletions tests/approved_native_m2_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -999,11 +999,15 @@ test("Native FX GUI routes through ChannelId PCM with no operator MONITOR ritual
const activeProjection=read("integration/ApprovedNativeV8Projection.h");
assert.match(activeProjection,/insert->setProperty\("catalogId",catalog\)/);
assert.match(activeProjection,/ch->setProperty\("fxRackBypassed",rackBypassed\)/);
assert.match(bridge,/controller\.intent\("LOAD_INSERT",nativeId,/);
assert.match(bridge,/if\(accepted\?\.admitted && nativeCh\)/);
assert.match(bridge,/fxRackVM\.nativeInsertPlan\(accepted,/);
assert.match(bridge,/controller\.intent\("LOAD_INSERT",plan\.channelId,plan\.payload\)/);
assert.match(bridge,/accepted\?\.admitted \|\| mixerSession\(\)\?\.authority==="CHANNEL_ID"/);
assert.match(lab,/nativeAccepted_\.fxOwners->externalChannel\(\)==target/);
assert.match(bridge,/pendingFxInsert=\{authority:"CHANNEL_ID"/);
assert.match(bridge,/inserted\?\.catalogId===p\.id/);
const fxVM=read("web/approved-fx-rack-view-model.js");
assert.match(bridge,/fxRackVM\.nativeInsertSettlement\(pendingFxInsert,next,confirmed\)/);
assert.match(fxVM,/fx\.catalogId!==pending\.id/);
assert.match(fxVM,/confirmed\.requestId!==pending\.requestId/);
assert.match(translate,/if\(op=="LOAD_INSERT"\)/);
assert.match(snapshot,/available\.add\(juce::String\("LOAD_INSERT"\)\)/);
assert.match(main,/engine_\.installNativeVst3\(/);
Expand Down Expand Up @@ -2833,7 +2837,8 @@ test("Guitar FX picker binding is real, visible and matches native installed reg
assert.ok(bridge.includes("const presentFxCatalog=()=>scope?.setNativeCatalog?.("));
assert.ok(guiBuilder.includes("setNativeCatalog(rows)"));
assert.ok(guiBuilder.includes("renderPluginCatalog();renderFastPicker();"));
assert.ok(bridge.includes('controller.intent("LOAD_INSERT",nativeId,'));
assert.ok(bridge.includes('fxRackVM.nativeInsertPlan(accepted,'));
assert.ok(bridge.includes('controller.intent("LOAD_INSERT",plan.channelId,plan.payload)'));
assert.ok(bridge.includes('pendingFxInsert={authority:"CHANNEL_ID"'));
});

Expand Down Expand Up @@ -3488,3 +3493,137 @@ test("MV-7 bridge delegates WIRE decisions, preserves only one native controller
assert.doesNotMatch(read("web/approved-wire-view-model.js"),
/backend\.emitEvent|window\.setTimeout|document\.querySelector/);
});

test("MV-8 FX native insert preflight keeps exact ChannelId, slot and installed roster",()=>{
const id="9007199254740993",id2="9007199254740995";
const snapshot={admitted:true,retained:false,device:{epoch:"73"},graph:{
revision:"55",capabilities:{supportedOps:["LOAD_INSERT","MOVE_INSERT","REMOVE_INSERT"]},
channels:[{id,role:"INPUT",inserts:[{id:"fx-1",catalogId:"eq"}]},
{id:id2,role:"GROUP",inserts:[]}]}};
const before=JSON.stringify(snapshot);
const ask={channelId:id,slot:1,catalogId:"vendor.vst3"};
assert.deepEqual(fxRackVM.nativeInsertPlan(snapshot,ask),{
kind:"READY",channelId:id,payload:{catalogId:"vendor.vst3",slot:1}});
const unavailable=(snap=snapshot,params=ask)=>
assert.equal(fxRackVM.nativeInsertPlan(snap,params).kind,"UNAVAILABLE");
unavailable(snapshot,{...ask,pending:true});
unavailable(snapshot,{...ask,slot:0});unavailable(snapshot,{...ask,slot:2});
unavailable(snapshot,{...ask,slot:8});unavailable(snapshot,{...ask,slot:1.5});
unavailable(snapshot,{...ask,channelId:Number(id)});
unavailable(snapshot,{...ask,channelId:"18446744073709551616"});
unavailable(snapshot,{...ask,catalogId:""});
unavailable({...snapshot,admitted:false});unavailable({...snapshot,retained:true});
unavailable({...snapshot,graph:{...snapshot.graph,capabilities:{supportedOps:[]}}});
unavailable({...snapshot,graph:{...snapshot.graph,channels:[
snapshot.graph.channels[0],{...snapshot.graph.channels[0]}]}});
unavailable({...snapshot,graph:{...snapshot.graph,channels:[
snapshot.graph.channels[0],
{id:id2,role:"GROUP",inserts:[{id:"fx-1",catalogId:"eq"}]}]}});
assert.equal(JSON.stringify(snapshot),before);
});
test("MV-8 FX move/remove preflight preserves exact instance and destination",()=>{
const a="9007199254740993",b="9007199254740995";
const base={admitted:true,retained:false,graph:{capabilities:{
supportedOps:["MOVE_INSERT","REMOVE_INSERT"]},
channels:[{id:a,role:"INPUT",inserts:[{id:"lease-a"},{id:"lease-b"}]},
{id:b,role:"GROUP",inserts:[]}]}};
const request={channelId:a,slot:0,instanceId:"lease-a",
move:true,destinationId:b,position:0};
assert.deepEqual(fxRackVM.nativeEditPlan(base,request),{
kind:"READY",operation:"MOVE_INSERT",channelId:a,
payload:{slot:0,instanceId:"lease-a",toChannelId:b,toSlot:0}});
assert.deepEqual(fxRackVM.nativeEditPlan(base,{channelId:a,slot:1,
instanceId:"lease-b"}),{kind:"READY",operation:"REMOVE_INSERT",
channelId:a,payload:{slot:1,instanceId:"lease-b"}});
assert.equal(fxRackVM.nativeEditPlan(base,{...request,destinationId:a,
position:0}).kind,"NO_CHANGE");
const bad=(s=base,args=request)=>assert.equal(
fxRackVM.nativeEditPlan(s,args).kind,"UNAVAILABLE");
bad(base,{...request,slot:1});
bad(base,{...request,instanceId:"vendor.vst3"});
bad(base,{...request,destinationId:"0"});
bad(base,{...request,destinationId:null}); // lost mapping never deletes FX
bad(base,{...request,destinationId:Number(b)});
bad(base,{...request,move:false}); // stray target cannot become REMOVE
bad(base,{...request,move:"yes"});
bad(base,{...request,position:1});
bad(base,{...request,position:-1});
bad({...base,retained:true});
bad({...base,graph:{...base.graph,channels:[
base.graph.channels[0],{...base.graph.channels[1],
inserts:[{id:"lease-a"}]}]}});
bad({...base,graph:{...base.graph,capabilities:{supportedOps:[]}}});
});
test("MV-8 FX inserted editor requires correlated controller proof and unique lease",()=>{
const ch="9007199254740993",cat="vendor.vst3";
const pending={authority:"CHANNEL_ID",requestId:"r-7",channelId:ch,
id:cat,slot:0,epoch:"73"};
const snapshot={admitted:true,retained:false,device:{epoch:"73"},graph:{
channels:[{id:ch,role:"INPUT",inserts:[
{id:"live-instance-a",catalogId:cat,name:"Vendor VST3"}]}]}};
const ack={requestId:"r-7",operation:"LOAD_INSERT",targetChannelId:ch,
payload:{catalogId:cat,slot:0}};
assert.deepEqual(fxRackVM.nativeInsertSettlement(pending,snapshot,ack),{
kind:"CONFIRMED",channelId:ch,slot:0,catalogId:cat,
instanceId:"live-instance-a",name:"Vendor VST3"});
assert.equal(fxRackVM.nativeInsertSettlement(pending,snapshot,null).kind,"WAIT");
assert.equal(fxRackVM.nativeInsertSettlement(pending,snapshot,
{...ack,requestId:"r-8"}).kind,"WAIT");
assert.equal(fxRackVM.nativeInsertSettlement(pending,snapshot,
{...ack,targetChannelId:"71"}).kind,"WAIT");
assert.equal(fxRackVM.nativeInsertSettlement(pending,snapshot,
{...ack,payload:{catalogId:"different",slot:0}}).kind,"WAIT");
assert.equal(fxRackVM.nativeInsertSettlement(pending,
{...snapshot,device:{epoch:"74"}},ack).kind,"STALE");
assert.equal(fxRackVM.nativeInsertSettlement(pending,
{...snapshot,admitted:false},ack).kind,"WAIT");
assert.equal(fxRackVM.nativeInsertSettlement(pending,
{...snapshot,graph:{channels:[...snapshot.graph.channels,
{id:"91",role:"GROUP",inserts:[
{id:"live-instance-a",catalogId:cat}]}]}},ack).kind,"WAIT");
assert.equal(fxRackVM.nativeInsertSettlement(pending,
{...snapshot,graph:{channels:[{id:ch,role:"INPUT",inserts:[
{id:"live-instance-b",catalogId:"different"}]}]}},ack).kind,"WAIT");
assert.deepEqual(fxRackVM.nativeInsertSettlement(null,snapshot,ack),{kind:"NONE"});
});
test("MV-8 FX native bypass plan and ACK are independent of global and insert states",()=>{
const channelId="9007199254740993";
const snapshot={admitted:true,retained:false,device:{epoch:"73"},graph:{
revision:"22",channels:[{id:channelId,role:"INPUT",fxRackBypassed:false,
inserts:[{id:"lease-1",bypassed:true},{id:"lease-2",bypassed:false}]}]}};
const rack=fxRackVM.nativePowerPlan(snapshot,{channelId,action:"fxOn"});
assert.equal(rack.kind,"READY");
assert.equal(rack.pending.bypassed,true);
assert.equal(rack.action,"routingNativeFxRackBypass");
assert.equal(rack.payload.revision,"22");
const slot=fxRackVM.nativePowerPlan(snapshot,{channelId,action:"slotPower",slot:0});
assert.equal(slot.kind,"READY");
assert.equal(slot.pending.insertId,"lease-1");
assert.equal(slot.pending.bypassed,false);
assert.equal(slot.payload.value,false);
assert.equal(fxRackVM.nativePowerPlan(snapshot,{channelId,action:"slotPower",slot:2}).kind,"UNAVAILABLE");
assert.equal(fxRackVM.nativePowerPlan(snapshot,{channelId,action:"slotPower",slot:0,
pending:true}).kind,"UNAVAILABLE");
const p={...slot.pending,requestId:"fx-17"};
assert.equal(fxRackVM.nativePowerAckResult(p,{requestId:"other",ok:true}),"IGNORE");
assert.equal(fxRackVM.nativePowerAckResult(p,{requestId:"fx-17",ok:true,
channelId,bypassed:false,insertId:"lease-1"}),"ACKED");
assert.equal(fxRackVM.nativePowerAckResult(p,{requestId:"fx-17",ok:true,
channelId,bypassed:false,insertId:"replaced"}),"REJECTED");
assert.equal(fxRackVM.nativePowerAckResult(p,{requestId:"fx-17",ok:false,
channelId,bypassed:false}),"REJECTED");
assert.equal(fxRackVM.nativePowerAckResult(null,{}),"IGNORE");
});
test("MV-8 FX bridge delegates preflight and settlement to existing pure FX VM",()=>{
const bridge=read("web/approved-native-bridge.js");
assert.match(bridge,/fxRackVM\.nativeInsertPlan\(/);
assert.match(bridge,/fxRackVM\.nativeInsertSettlement\(/);
assert.match(bridge,/fxRackVM\.nativeEditPlan\(/);
assert.match(bridge,/move:!!target/);
assert.match(bridge,/fxRackVM\.nativePowerPlan\(/);
assert.match(bridge,/fxRackVM\.nativePowerAckResult\(/);
assert.match(bridge,/controller\.intent\(plan\.channelId,|controller\.intent\("LOAD_INSERT",plan\.channelId/);
assert.match(bridge,/controller\.intent\(decision\.operation,decision\.channelId/);
assert.doesNotMatch(read("web/approved-fx-rack-view-model.js"),
/backend\.emitEvent|document\.querySelector|setTimeout\(/);
});
11 changes: 9 additions & 2 deletions tests/rc_operator_workflow_contract.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,15 @@ test('FX picker closes and opens an actual editor only after accepted native or
assert.match(bridge,/effect\.id!==instanceId\|\|effect\.catalogId!==catalogId/);
assert.match(bridge,/justInsertedLogicalFx/);
assert.match(bridge,/scope\?\.closeNativePicker\?\.\(\);\s*openVerifiedInsertedFx\(p\.channelId,p\.slot,p\.catalogId,inserted\.id\)/);
assert.match(bridge,/openVerifiedInsertedFx\(p\.channelId,p\.slot,p\.id,inserted\.id\)/);
assert.match(bridge,/confirmed\.requestId===pendingFxInsert\.requestId/);
// Native editor requires verified accepted lease, not catalog key or ACK.
const fxVM=read('web/approved-fx-rack-view-model.js');
assert.match(bridge,/fxRackVM\.nativeInsertSettlement\(pendingFxInsert,next,confirmed\)/);
assert.match(bridge,/if\(fxInsert\.kind==="CONFIRMED"\)/);
assert.match(bridge,/openVerifiedInsertedFx\(fxInsert\.channelId,fxInsert\.slot,/);
assert.match(bridge,/fxInsert\.catalogId,fxInsert\.instanceId\)/);
assert.match(fxVM,/confirmed\.requestId!==pending\.requestId/);
assert.match(fxVM,/fx\.catalogId!==pending\.id/);
assert.match(bridge,/pendingFxInsert=null;\s*scope\?\.closeNativePicker\?\.\(\)/);
assert.match(bridge,/ack\.channel===p\.channel && ack\.slot===p\.slot/);
assert.match(bridge,/paintM4FxInstances\(state\);\s*scope\?\.closeNativePicker\?\.\(\);\s*openRoutedFxEditor\(p\.channel,p\.slot,actual\.instanceId,epoch,revision\)/);
assert.match(bridge,/consumeAction\?\.\(track,"openPlugin"/);
Expand Down
121 changes: 120 additions & 1 deletion web/approved-fx-rack-view-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,125 @@
session.channels?.[pending.channel]?.fxRackBypassed===pending.bypassed?
"CONFIRMED":"WAIT";
}

// MV-8: do not invent JS-owned FX identities or interpret a catalog key
// as an instance lease. These plans may only target admitted native PCM.
const VALID_ROLES=new Set(["INPUT","GROUP","FX_RETURN","MAIN"]);
function channelId(value) {
if(typeof value!=="string"||!/^[1-9][0-9]*$/.test(value))return false;
try{return BigInt(value)<=18446744073709551615n;}catch{return false;}
}
function rosterUnique(graph) {
if(!Array.isArray(graph?.channels))return false;
const seen=new Set();
for(const ch of graph.channels) {
if(!Array.isArray(ch?.inserts))return false;
for(const fx of ch.inserts) {
if(typeof fx?.id!=="string"||!fx.id||seen.has(fx.id))return false;
seen.add(fx.id);
}
}
return true;
}
function nativeInsertPlan(snapshot,{channelId:id,slot,catalogId,pending=false}={}) {
const graph=snapshot?.graph;
if(pending||snapshot?.admitted!==true||snapshot?.retained===true||
!channelId(id)||typeof catalogId!=="string"||!catalogId||
!Number.isInteger(slot)||slot<0||slot>=8||
!graph?.capabilities?.supportedOps?.includes("LOAD_INSERT")||
!rosterUnique(graph))return {kind:"UNAVAILABLE"};
const matches=graph.channels.filter(ch=>ch.id===id);
if(matches.length!==1||!VALID_ROLES.has(matches[0].role)||
matches[0].inserts.length!==slot)return {kind:"UNAVAILABLE"};
return {kind:"READY",channelId:id,payload:{catalogId,slot}};
}
function nativeEditPlan(snapshot,{channelId:id,slot,instanceId,
move=false,destinationId=null,position=null}={}) {
const graph=snapshot?.graph;
// A MOVE with a lost destination must NEVER become a REMOVE.
if(typeof move!=="boolean"||
(!move&&(destinationId!==null||position!==null)))
return {kind:"UNAVAILABLE"};
const operation=move?"MOVE_INSERT":"REMOVE_INSERT";
if(snapshot?.admitted!==true||snapshot?.retained===true||
!channelId(id)||!Number.isInteger(slot)||slot<0||slot>=8||
typeof instanceId!=="string"||!instanceId||
!graph?.capabilities?.supportedOps?.includes(operation)||
!rosterUnique(graph))return {kind:"UNAVAILABLE"};
const sources=graph.channels.filter(ch=>ch.id===id);
if(sources.length!==1||!VALID_ROLES.has(sources[0].role)||
sources[0].inserts[slot]?.id!==instanceId)
return {kind:"UNAVAILABLE"};
const payload={slot,instanceId};
if(move){
if(!channelId(destinationId)||!Number.isInteger(position))return {kind:"UNAVAILABLE"};
const targets=graph.channels.filter(ch=>ch.id===destinationId);
if(targets.length!==1||!VALID_ROLES.has(targets[0].role))
return {kind:"UNAVAILABLE"};
const same=destinationId===id,max=targets[0].inserts.length-(same?1:0);
if(position<0||position>max||(!same&&max>=8))
return {kind:"UNAVAILABLE"};
if(same&&slot===position)return {kind:"NO_CHANGE"};
payload.toChannelId=destinationId;
payload.toSlot=position;
}
return {kind:"READY",operation,channelId:id,payload};
}
// createController is the ONLY source of matched ACK + independent
// readback. We additionally check exact editor lease before navigation.
function nativeInsertSettlement(pending,snapshot,confirmed){
if(!pending||pending.authority!=="CHANNEL_ID")return {kind:"NONE"};
if(snapshot?.device?.epoch!==pending.epoch)return {kind:"STALE"};
if(!confirmed||confirmed.operation!=="LOAD_INSERT"||
confirmed.requestId!==pending.requestId)return {kind:"WAIT"};
if(snapshot?.admitted!==true||snapshot.retained===true||
confirmed.targetChannelId!==pending.channelId||
confirmed.payload?.catalogId!==pending.id||
confirmed.payload?.slot!==pending.slot||
!channelId(pending.channelId)||!rosterUnique(snapshot.graph))
return {kind:"WAIT"};
const ch=snapshot.graph.channels.filter(c=>c.id===pending.channelId);
const fx=ch.length===1?ch[0].inserts[pending.slot]:null;
if(!fx||fx.catalogId!==pending.id||
typeof fx.id!=="string"||!fx.id)return {kind:"WAIT"};
return {kind:"CONFIRMED",channelId:pending.channelId,
slot:pending.slot,catalogId:fx.catalogId,instanceId:fx.id,name:fx.name};
}
function nativePowerPlan(snapshot,{channelId:id,action,slot,pending=false}={}){
const graph=snapshot?.graph;
if(pending||snapshot?.admitted!==true||snapshot?.retained===true||
!channelId(id)||!Array.isArray(graph?.channels)||!rosterUnique(graph))
return {kind:"UNAVAILABLE"};
const matches=graph.channels.filter(ch=>ch.id===id);
if(matches.length!==1)return {kind:"UNAVAILABLE"};
const ch=matches[0],rack=action==="fxOn";
if(!rack&&action!=="slotPower")return {kind:"UNAVAILABLE"};
const insert=rack?null:ch.inserts?.[slot];
if(rack?typeof ch.fxRackBypassed!=="boolean":
!Number.isInteger(slot)||slot<0||slot>=8||
typeof insert?.id!=="string"||!insert.id||
typeof insert.bypassed!=="boolean")return {kind:"UNAVAILABLE"};
const bypassed=rack?!ch.fxRackBypassed:!insert.bypassed;
return {kind:"READY",action:rack?"routingNativeFxRackBypass":
"routingNativeFxInsertBypass",
pending:{channelId:id,kind:rack?"rack":"insert",
insertId:insert?.id,bypassed,epoch:snapshot.device?.epoch,acked:false},
payload:{channelId:id,deviceEpoch:snapshot.device?.epoch,
revision:graph.revision,value:bypassed,
...(rack?{}:{slot,insertId:insert.id})}};
}
function nativePowerAckResult(pending,ack){
if(!pending||!ack||ack.requestId!==pending.requestId)return "IGNORE";
if(ack.ok!==true||ack.channelId!==pending.channelId||
ack.bypassed!==pending.bypassed||
(ack.insertId!==undefined&&
pending.kind==="insert"&&ack.insertId!==pending.insertId))
return "REJECTED";
return "ACKED";
}

return Object.freeze({powerReadback,mountedRackMatches,
m4Presentation,nativePowerSettlement,m4RackSettlement});
m4Presentation,nativePowerSettlement,m4RackSettlement,
nativeInsertPlan,nativeEditPlan,nativeInsertSettlement,
nativePowerPlan,nativePowerAckResult});
});
Loading
Loading