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
133 changes: 131 additions & 2 deletions tests/approved_native_m2_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4590,7 +4590,7 @@ test("G-MV28 M4 rack settlement needs exact full installed snapshot, not an old
const source=read("web/approved-native-bridge.js");
assert.ok(source.includes("fxRackVM.m4Presentation("));
assert.ok(source.includes("fxRackVM.nativePowerSettlement("));
assert.match(source,/fxRackVM\.m4RackSettlement\(p,next\)/);
assert.match(source,/fxRackVM\.m4RackSettlement\(p,next,/);
assert.doesNotMatch(source,/const actual=p\.kind==="rack"\?/);
});

Expand Down Expand Up @@ -5931,7 +5931,7 @@ test("G-MV30 bridge has one M4 insert IPC, and never paints or opens from ack.st
source=read("web/approved-fx-rack-view-model.js");
assert.match(bridge,/fxRackVM\.m4InsertPlan\(accepted,/);
assert.match(bridge,/fxRackVM\.m4InsertAckResult\(pendingFxInsert,ack\)/);
assert.match(bridge,/fxRackVM\.m4InsertReadbackSettlement\(p,snapshot\)/);
assert.match(bridge,/fxRackVM\.m4InsertReadbackSettlement\(p,snapshot,/);
assert.match(bridge,/reconcileM4FxInsertReadback\(next\)/);
assert.equal((bridge.match(/action:"routingFxInsert"/g)||[]).length,0,
"bridge must emit one ViewModel-planned action, not a duplicated raw dispatcher");
Expand Down Expand Up @@ -6053,3 +6053,132 @@ test("G-MV31 bridge delegates deferred and manually opened FX editors to one pur
assert.doesNotMatch(read("web/approved-fx-rack-view-model.js"),
/backend\.emitEvent|document\.|window\.|setTimeout/);
});


test("G-MV33 exact M4 FX host admission and hardware-scoped transaction settlement",()=>{
const device={epoch:"31",sampleRate:48000,bufferFrames:256,
enabledInputs:[0,1],enabledOutputs:[0,1]};
const token=protocol.nativeHardwareConfiguration(device);
assert.equal(typeof token,"string");
const base={admitted:false,retained:false,device,raw:{
mixerSession:{authority:"M4",deviceEpoch:"31",routeRevision:"12",
channels:Array.from({length:10},()=>({fxRackBypassed:false}))},
legacyM4:{active:true,routeAccepted:true,nativeBusStructural:false,
routingRevision:"12",fxInstances:Array.from({length:10},(_,i)=>i===4?
[{instanceId:"fx-old",catalogId:"vendor.old",bypassed:false}]:[])}
}};
const opts={channel:4,verifiedM4:true,hardwareConfiguration:token};
const rack=fxRackVM.m4PowerPlan(base,{...opts,action:"fxOn"});
const power=fxRackVM.m4PowerPlan(base,{...opts,action:"slotPower",slot:0});
const insert=fxRackVM.m4InsertPlan(base,{...opts,slot:1,catalogId:"vendor.new"});
const editor=fxRackVM.m4EditorPlan(base,{...opts,slot:0});
assert.deepEqual([rack.kind,power.kind,insert.kind,editor.kind],
["READY","READY","READY","OPEN"]);
for(const plan of [rack,power,insert])
assert.equal(plan.pending.hardwareConfiguration,token);
assert.equal(editor.instanceId,"fx-old");
for(const badSlot of [undefined,null,"0",-1,8,NaN]){
assert.equal(fxRackVM.m4InsertPlan(base,{...opts,slot:badSlot,
catalogId:"vendor.new"}).kind,"UNAVAILABLE");
assert.equal(fxRackVM.m4EditorPlan(base,{...opts,slot:badSlot}).kind,
"UNAVAILABLE");
assert.equal(fxRackVM.m4PowerPlan(base,{...opts,slot:badSlot,
action:"slotPower"}).kind,"UNAVAILABLE");
}
for(const delta of [
{verifiedM4:false},{offline:true},{hardwareConfiguration:null},
{hardwareConfiguration:""},{channel:10}
]){
const input={...opts,...delta};
assert.equal(fxRackVM.m4PowerPlan(base,{...input,action:"fxOn"}).kind,
"UNAVAILABLE");
assert.equal(fxRackVM.m4InsertPlan(base,{...input,slot:1,
catalogId:"vendor.new"}).kind,"UNAVAILABLE");
assert.equal(fxRackVM.m4EditorPlan(base,{...input,slot:0}).kind,
"UNAVAILABLE");
}
for(const change of [
s=>{s.admitted=true;},s=>{s.retained=true;},
s=>{s.raw.mixerSession.authority="CHANNEL_ID";},
s=>{s.raw.mixerSession.routeRevision="13";},
s=>{s.raw.legacyM4.active=false;},
s=>{s.raw.legacyM4.routeAccepted=false;},
s=>{s.raw.legacyM4.nativeBusStructural=true;},
s=>{s.raw.legacyM4.routingRevision="9007199254740993";},
s=>{s.device.epoch="32";}
]){
const changed=clone(base);change(changed);
assert.equal(fxRackVM.m4PowerPlan(changed,{...opts,action:"fxOn"}).kind,"UNAVAILABLE");
assert.equal(fxRackVM.m4InsertPlan(changed,{...opts,slot:1,
catalogId:"vendor.new"}).kind,"UNAVAILABLE");
assert.equal(fxRackVM.m4EditorPlan(changed,{...opts,slot:0}).kind,"UNAVAILABLE");
}
const remapped=clone(base);remapped.device.enabledInputs=[2,3];
const newer=protocol.nativeHardwareConfiguration(remapped.device);
assert.notEqual(newer,token);
remapped.raw.mixerSession.channels[4].fxRackBypassed=true;
remapped.raw.legacyM4.fxInstances[4][0].bypassed=true;
assert.equal(fxRackVM.m4RackSettlement(
{...rack.pending,acked:true},remapped,newer),"STALE");
assert.equal(fxRackVM.m4SlotPowerSettlement(
{...power.pending,acked:true},remapped,newer),"STALE");
const installed=clone(remapped);
installed.raw.legacyM4.routingRevision="13";
installed.raw.mixerSession.routeRevision="13";
installed.raw.legacyM4.fxInstances[4][1]={
instanceId:"fx-new",catalogId:"vendor.new",bypassed:false};
assert.equal(fxRackVM.m4InsertReadbackSettlement(
{...insert.pending,acked:true},installed,newer).kind,"STALE");
assert.equal(fxRackVM.m4RackSettlement(
{...rack.pending,acked:true},base,token),"WAIT");
const acceptedRack=clone(base);
acceptedRack.raw.mixerSession.channels[4].fxRackBypassed=true;
assert.equal(fxRackVM.m4RackSettlement(
{...rack.pending,acked:true},acceptedRack,token),"CONFIRMED");
const acceptedPower=clone(base);
acceptedPower.raw.legacyM4.fxInstances[4][0].bypassed=true;
assert.equal(fxRackVM.m4SlotPowerSettlement(
{...power.pending,acked:true},acceptedPower,token),"CONFIRMED");
const acceptedInsert=clone(base);
acceptedInsert.raw.legacyM4.routingRevision="13";
acceptedInsert.raw.mixerSession.routeRevision="13";
acceptedInsert.raw.legacyM4.fxInstances[4][1]={
instanceId:"fx-new",catalogId:"vendor.new",bypassed:false};
assert.equal(fxRackVM.m4InsertReadbackSettlement(
{...insert.pending,acked:true},acceptedInsert,token).kind,"CONFIRMED");
assert.equal(fxRackVM.m4InsertReadbackSettlement(
{...insert.pending,acked:false},acceptedInsert,token).kind,"WAIT");
assert.equal(fxRackVM.m4InsertReadbackSettlement(
{...insert.pending,acked:true},acceptedInsert,null).kind,"STALE");
});
test("G-MV33 late duplicate negative ACK cannot discard verified FX lease",()=>{
const rack={requestId:"rack-1",channel:4,epoch:"31",revision:"12",
bypassed:true,acked:true};
const rackAck={requestId:"rack-1",channel:4,deviceEpoch:31,
routingRevision:12,bypassed:true,ok:false};
assert.equal(fxRackVM.m4RackAckResult(rack,rackAck),"IGNORE");
assert.equal(fxRackVM.m4RackAckResult({...rack,acked:false},rackAck),"REJECTED");
const power={requestId:"power-1",channel:4,slot:0,acked:true};
const powerAck={requestId:"power-1",channel:4,slot:0,ok:false};
assert.equal(fxRackVM.m4SlotPowerAckResult(power,powerAck),"IGNORE");
assert.equal(fxRackVM.m4SlotPowerAckResult({...power,acked:false},powerAck),
"REJECTED");
const insert={authority:"M4",requestId:"insert-1",channel:4,slot:1,acked:true};
const insertAck={requestId:"insert-1",channel:4,slot:1,ok:false,
state:{fxInstances:[{instanceId:"fake"}]}};
assert.equal(fxRackVM.m4InsertAckResult(insert,insertAck),"IGNORE");
assert.equal(fxRackVM.m4InsertAckResult({...insert,acked:false},insertAck),
"REJECTED");
const source=read("web/approved-fx-rack-view-model.js");
const bridge=read("web/approved-native-bridge.js");
assert.equal((source.match(/function m4FxHost\(/g)||[]).length,1);
assert.equal((source.match(/const host=m4FxHost\(snapshot,/g)||[]).length,3);
for(const name of ["m4PowerPlan","m4InsertPlan","m4EditorPlan"])
assert.match(source,new RegExp("function "+name+"\\(snapshot,"));
assert.match(bridge,/hardwareConfiguration:protocol\.nativeHardwareConfiguration\(current\?\.device\)/);
assert.match(bridge,/hardwareConfiguration:protocol\.nativeHardwareConfiguration\(accepted\?\.device\)/);
assert.match(bridge,/fxRackVM\.m4RackSettlement\(p,next,/);
assert.match(bridge,/fxRackVM\.m4SlotPowerSettlement\(p,next,/);
assert.match(bridge,/fxRackVM\.m4InsertReadbackSettlement\(p,snapshot,/);
assert.doesNotMatch(source,/backend\.emitEvent|document\.|window\.|setTimeout/);
});
4 changes: 2 additions & 2 deletions tests/rc_operator_workflow_contract.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ test('FX picker closes and opens an actual editor only after accepted native or
assert.match(fxVM,/function m4InsertAckResult\(pending,ack\)/);
assert.match(fxVM,/ack\.channel===pending\.channel&&/);
assert.match(fxVM,/ack\.slot===pending\.slot/);
assert.match(fxVM,/function m4InsertReadbackSettlement\(pending,snapshot\)/);
assert.match(bridge,/fxRackVM\.m4InsertReadbackSettlement\(p,snapshot\)/);
assert.match(fxVM,/function m4InsertReadbackSettlement\(pending,snapshot,/);
assert.match(bridge,/fxRackVM\.m4InsertReadbackSettlement\(p,snapshot,/);
assert.match(bridge,/openRoutedFxEditor\(decision\.channel,decision\.slot,decision\.instanceId,/);
const m4AckHandler=bridge.split('backend.addEventListener("arMixRoutingFxInsertAck",ack=>{')[1]
?.split('backend.addEventListener("arMixCatalog",catalog=>{')[0];
Expand Down
116 changes: 64 additions & 52 deletions web/approved-fx-rack-view-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@
const n=Number(x);
return Number.isSafeInteger(n)&&n>0? n:null;
}
function m4PowerPlan(snapshot,{action,channel,slot=null,
verifiedM4=false,offline=false,pending=false}={}) {
const unavailable={kind:"UNAVAILABLE"};
const s=snapshot?.raw?.mixerSession,m=snapshot?.raw?.legacyM4,
epoch=safeM4Token(snapshot?.device?.epoch),
// G-MV33: ONE immutable-readback physical M4 FX admission core.
// The bridge provides the existing protocol's canonical hardware fingerprint;
// no second device model, FX host, WebView controller or IPC dispatcher.
function m4FxHost(snapshot,{channel,slot=null,verifiedM4=false,
offline=false,pending=false,hardwareConfiguration}={}) {
const s=snapshot?.raw?.mixerSession,m=snapshot?.raw?.legacyM4;
const epoch=safeM4Token(snapshot?.device?.epoch),
revision=safeM4Token(m?.routingRevision);
if(pending||offline||verifiedM4!==true||
snapshot?.admitted!==false||snapshot?.retained===true||
Expand All @@ -125,21 +127,42 @@
s.routeRevision!==m.routingRevision||
!Array.isArray(s.channels)||s.channels.length!==10||
!Number.isInteger(channel)||channel<0||channel>=10||
!s.channels[channel])return unavailable;
const lease={channel,epoch:s.deviceEpoch,
revision:s.routeRevision,acked:false};
if(action==="fxOn") {
!s.channels[channel]||
(slot!==null&&(!Number.isInteger(slot)||slot<0||slot>=8))||
(hardwareConfiguration!==undefined&&
(typeof hardwareConfiguration!=="string"||!hardwareConfiguration)))
return null;
return {s,m,epoch,revision,hardwareConfiguration:
hardwareConfiguration===undefined?null:hardwareConfiguration};
}
function m4FxHardwareLease(host){
return host.hardwareConfiguration===null?{}:
{hardwareConfiguration:host.hardwareConfiguration};
}
function m4FxHardwareMatches(pending,hardwareConfiguration){
return !Object.prototype.hasOwnProperty.call(pending,"hardwareConfiguration")||
(typeof hardwareConfiguration==="string"&&
pending.hardwareConfiguration===hardwareConfiguration);
}
function m4PowerPlan(snapshot,{action,channel,slot=null,
verifiedM4=false,offline=false,pending=false,hardwareConfiguration}={}) {
const unavailable={kind:"UNAVAILABLE"};
const host=m4FxHost(snapshot,{channel,slot,verifiedM4,offline,pending,
hardwareConfiguration});
if(!host)return unavailable;
const {s,m,epoch,revision}=host;
const lease={channel,epoch:s.deviceEpoch,revision:s.routeRevision,
acked:false,...m4FxHardwareLease(host)};
if(action==="fxOn"){
const row=s.channels[channel];
if(typeof row.fxRackBypassed!=="boolean"||slot!==null)
return unavailable;
const bypassed=!row.fxRackBypassed;
return {kind:"READY",action:"routingFxRackBypass",key:channel,
timeoutMs:8000,
pending:{...lease,bypassed},
timeoutMs:8000,pending:{...lease,bypassed},
payload:{channel,deviceEpoch:epoch,revision,value:bypassed}};
}
if(action!=="slotPower"||!Number.isInteger(slot)||
slot<0||slot>=8)return unavailable;
if(action!=="slotPower"||!Number.isInteger(slot))return unavailable;
const instances=m.fxInstances?.[channel],live=instances?.[slot];
if(!Array.isArray(instances)||
typeof live?.instanceId!=="string"||!live.instanceId||
Expand All @@ -153,13 +176,14 @@
deviceEpoch:epoch,revision,value:bypass}};
}
function m4RackAckResult(pending,ack) {
if(!pending||!ack||ack.requestId!==pending.requestId)return "IGNORE";
if(!pending||!ack||ack.requestId!==pending.requestId||
pending.acked===true)return "IGNORE";
return ack.ok===true&&ack.channel===pending.channel&&
String(ack.deviceEpoch)===pending.epoch&&
String(ack.routingRevision)===pending.revision&&
ack.bypassed===pending.bypassed?"ACKED":"REJECTED";
}
function m4RackSettlement(pending,snapshot) {
function m4RackSettlement(pending,snapshot,hardwareConfiguration) {
if(!pending)return "NONE";
const s=snapshot?.raw?.mixerSession,m=snapshot?.raw?.legacyM4;
if(snapshot?.admitted!==false||snapshot?.retained===true||
Expand All @@ -169,6 +193,7 @@
s.deviceEpoch!==pending.epoch||
s.routeRevision!==pending.revision||
m.routingRevision!==pending.revision||
!m4FxHardwareMatches(pending,hardwareConfiguration)||
!Number.isInteger(pending.channel)||
pending.channel<0||pending.channel>=10||
!Array.isArray(s.channels)||s.channels.length!==10)
Expand Down Expand Up @@ -202,39 +227,32 @@
// independent, validated Console-v6 PCM readback. Editors open only when
// the accepted M4 snapshot proves the exact new catalog/instance/route.
function m4InsertPlan(snapshot,{channel,slot,catalogId,
verifiedM4=false,offline=false,pending=false}={}) {
verifiedM4=false,offline=false,pending=false,hardwareConfiguration}={}) {
const unavailable={kind:"UNAVAILABLE"};
const s=snapshot?.raw?.mixerSession,m=snapshot?.raw?.legacyM4;
const epoch=safeM4Token(snapshot?.device?.epoch),
revision=safeM4Token(m?.routingRevision);
if(offline||pending||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||
typeof catalogId!=="string"||!catalogId)return unavailable;
const host=m4FxHost(snapshot,{channel,slot,verifiedM4,offline,pending,
hardwareConfiguration});
if(!host||!Number.isInteger(slot)||
typeof catalogId!=="string"||!catalogId)
return unavailable;
const {m,epoch,revision}=host;
const instances=m.fxInstances?.[channel];
if(!Array.isArray(instances)||instances[slot]!=null||
(slot>0&&instances[slot-1]==null))return unavailable;
return {kind:"READY",action:"routingFxInsert",
payload:{id:catalogId,channel,slot,deviceEpoch:epoch,revision},
pending:{authority:"M4",id:catalogId,channel,slot,
epoch:snapshot.device.epoch,revision:m.routingRevision,acked:false}};
epoch:snapshot.device.epoch,revision:m.routingRevision,acked:false,
...m4FxHardwareLease(host)}};
}
function m4InsertAckResult(pending,ack){
if(!pending||pending.authority!=="M4"||
!ack||ack.requestId!==pending.requestId)return "IGNORE";
!ack||ack.requestId!==pending.requestId||
pending.acked===true)return "IGNORE";
return ack.ok===true&&ack.channel===pending.channel&&
ack.slot===pending.slot?"ACKED":"REJECTED";
// Deliberately ignore ack.state, including FX inventory and revision.
}
function m4InsertReadbackSettlement(pending,snapshot){
function m4InsertReadbackSettlement(pending,snapshot,hardwareConfiguration){
if(!pending||pending.authority!=="M4")return {kind:"NONE"};
const s=snapshot?.raw?.mixerSession,m=snapshot?.raw?.legacyM4,
revision=safeM4Token(m?.routingRevision),
Expand All @@ -246,6 +264,7 @@
s.deviceEpoch!==pending.epoch||
s.routeRevision!==m.routingRevision||
previous===null||revision===null||revision<previous||
!m4FxHardwareMatches(pending,hardwareConfiguration)||
!Number.isInteger(pending.channel)||pending.channel<0||pending.channel>=10||
!Number.isInteger(pending.slot)||pending.slot<0||pending.slot>=8)
return {kind:"STALE"};
Expand Down Expand Up @@ -315,21 +334,12 @@
// 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;
offline=false,hardwareConfiguration}={}) {
const unavailable={kind:"UNAVAILABLE"};
const host=m4FxHost(snapshot,{channel,slot,verifiedM4,offline,
hardwareConfiguration});
if(!host||!Number.isInteger(slot))return unavailable;
const {m,epoch,revision}=host;
const slots=m.fxInstances?.[channel];
if(!Array.isArray(slots))return unavailable;
const effect=slots[slot];
Expand Down Expand Up @@ -484,20 +494,22 @@
// M4 compatibility FX slot ACK is NOT readback. Keep the per-slot lease
// locked until independent accepted M4 snapshot proves its exact token.
function m4SlotPowerAckResult(pending,ack){
if(!pending||!ack||pending.requestId!==ack.requestId)return "IGNORE";
if(!pending||!ack||pending.requestId!==ack.requestId||
pending.acked===true)return "IGNORE";
if(ack.channel!==pending.channel||ack.slot!==pending.slot||
ack.ok!==true)return "REJECTED";
return "ACKED";
}
function m4SlotPowerSettlement(pending,snapshot){
function m4SlotPowerSettlement(pending,snapshot,hardwareConfiguration){
if(!pending)return "NONE";
const session=snapshot?.raw?.mixerSession,m=snapshot?.raw?.legacyM4;
if(snapshot?.retained===true||snapshot?.admitted===true||
session?.authority!=="M4"||
snapshot?.device?.epoch!==pending.epoch||
session.deviceEpoch!==pending.epoch||
session.routeRevision!==pending.revision||
m?.routingRevision!==pending.revision)return "STALE";
m?.routingRevision!==pending.revision||
!m4FxHardwareMatches(pending,hardwareConfiguration))return "STALE";
const slots=m.fxInstances?.[pending.channel];
const actual=Array.isArray(slots)?slots[pending.slot]:null;
if(actual?.instanceId!==pending.token)return "STALE";
Expand Down
Loading
Loading