Skip to content
Merged
56 changes: 56 additions & 0 deletions tests/approved_scalar_view_model_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,62 @@ const ack=(p,extra={})=>({
parameter:p.parameter,ok:true,...extra
});

test("G-MV26 MAIN scalar gate uses current PCM authority, never stale M4 status",()=>{
const main=(authority="CHANNEL_ID")=>{
const s=m4Snapshot({authority});
s.admitted=authority==="CHANNEL_ID";
s.retained=false;
s.raw.legacyM4.active=true;
s.raw.legacyM4.routeAccepted=true;
s.raw.mixerSession.deviceEpoch=s.device.epoch;
return s;
};
const gate=(s,options={})=>vm.masterScalarAuthority(s,{
m4Verified:true,graphConnected:true,...options
});
const channel=main();
assert.equal(gate(channel),"CHANNEL_ID");
assert.equal(gate({...channel,admitted:false}),"UNAVAILABLE",
"old M4 routeAccepted cannot authorize MAIN after ChannelId loses PCM");
assert.equal(gate(channel,{graphConnected:false}),"UNAVAILABLE",
"ChannelId MAIN command waits for accepted GUI projection");
const retained=main();
retained.retained=true;
assert.equal(gate(retained),"UNAVAILABLE");
const replacement=main("M4");
assert.equal(gate(replacement),"M4",
"a verified current M4 producer retains native physical MAIN control");
assert.equal(gate(replacement,{m4Verified:false}),"UNAVAILABLE");
assert.equal(gate({...replacement,admitted:true}),"UNAVAILABLE");
const oldM4=main("NONE");
assert.equal(gate(oldM4),"UNAVAILABLE",
"unadmitted first sound must not inherit retired MAIN controls");
const stale=main("M4");
stale.raw.mixerSession.routeRevision="24";
assert.equal(gate(stale),"UNAVAILABLE");
const lost=main("M4");
lost.raw.legacyM4.routeAccepted=false;
assert.equal(gate(lost),"UNAVAILABLE");
const changed=main();
changed.raw.mixerSession.deviceEpoch="999";
assert.equal(gate(changed),"UNAVAILABLE");
const incomplete=main();
delete incomplete.raw.mixerSession.main;
assert.equal(gate(incomplete),"UNAVAILABLE");
const overflow=main();
overflow.device.epoch="18446744073709551610";
overflow.raw.mixerSession.deviceEpoch=overflow.device.epoch;
assert.equal(gate(overflow),"UNAVAILABLE",
"numeric M4 host tokens must not silently round uint64 device epochs");
assert.equal(gate(null),"UNAVAILABLE");
const bridge=readFileSync("web/approved-native-bridge.js","utf8");
assert.match(bridge,/stripVM\.masterScalarAuthority\(/);
assert.match(bridge,/nativeMasterAuthority\(\)===?"UNAVAILABLE"/);
assert.doesNotMatch(bridge,/m4Verified\(\)\s*\|\|\s*nativeMasterReady\(\)/);
assert.doesNotMatch(vm.masterScalarAuthority.toString(),
/document\.|window\.|backend|setTimeout|AudioContext|emitEvent/);
});

test("MV-9 exact native edit identity never rounds uint64 channel/device values",()=>{
assert.equal(vm.scalarIdentityMatches(edit,identity),true);
assert.equal(vm.scalarIdentityMatches(edit,{...identity,channelId:bigNext}),false);
Expand Down
56 changes: 54 additions & 2 deletions tests/live_fader_held_drag.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function nativeChannelIdFixture(){
};
return s;
}
function harness({m4=false}={}){
function harness({m4=false,rejectMaster=false}={}){
const sent=[],listeners=new Map(),timers=[],visual=[],meters=[];
const m4Tracks=m4?Array.from({length:10},(_,i)=>({
id:1000+i,name:"CH"+(i+1),kind:"audio",format:"mono",level:-6,
Expand Down Expand Up @@ -80,7 +80,8 @@ function harness({m4=false}={}){
};
const window={
__JUCE__:{backend},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,
ArSonApprovedChannelStripViewModel:stripVM,ArSonApprovedFxRackViewModel:fxRackVM,ArSonApprovedWireViewModel:wireVM,
ArSonApprovedChannelStripViewModel:rejectMaster?
Object.freeze({...stripVM,masterScalarAuthority:()=>"UNAVAILABLE"}):stripVM,ArSonApprovedFxRackViewModel:fxRackVM,ArSonApprovedWireViewModel:wireVM,
__ARMIX_NATIVE_SCOPE__:scope,addEventListener(){},
setTimeout(fn,delay=0){timers.push({fn,at:now+Math.max(0,Number(delay)||0)});return timers.length;}
};
Expand All @@ -98,6 +99,57 @@ function harness({m4=false}={}){
}
};
}
test("G-MV26 refused MAIN MUTE and fader reset never fall through to ChannelId",()=>{
const h=harness({rejectMaster:true}),s=nativeChannelIdFixture();
s.device.epoch="77";s.mixerSession.deviceEpoch="77";
h.listeners.get("arMixConsoleSnapshot")(s);
assert.equal(h.window.__ARMIX_APPROVED_NATIVE_GUI__.acceptedGraphConnected,true);
const master=h.scope.master;
const commands=()=>h.sent.filter(e=>e.name==="arMixConsoleIntent" ||
(e.name==="arMixAction"&&e.payload?.action==="routingM4Control"));
const before=commands().length;
assert.equal(h.window.__ARMIX_NATIVE_M2__.consumeAction(master,"mute",{}),true);
assert.equal(h.window.__ARMIX_NATIVE_M2__.consumeDoubleClick({
target:{classList:{contains:cls=>cls==="fader"}}
},master),true);
assert.equal(commands().length,before,
"refused MAIN can neither emit host scalar nor bypass via generic v6 intent");
});

test("G-MV26 offline .smix MAIN MUTE and unity reset keep logical native ACK path",()=>{
const makeOffline=()=>{
const h=harness(),s=clone(fixture),live=nativeChannelIdFixture();
s.productionCallbackLive=false;
s.mixerSession={authority:"NONE",deviceEpoch:s.device.epoch};
const graph=clone(live.graph);
graph.revision="12";graph.rosterRevision="12";
graph.capabilities.callbackOwnsChannelIds=false;
graph.capabilities.supportedOps=["SET_FADER","SET_MUTE"];
s.logicalMixer={schema:"arsonmix.native.logical-mixer.v1",
authority:"LOGICAL_ONLY",workspaceToken:"offline-main-gmv26",
readOnly:false,revision:"12",physicalOutputAdmitted:false,
outputArmed:false,graph};
h.listeners.get("arMixConsoleSnapshot")(s);
return {h,graph};
};
for(const operation of ["SET_MUTE","SET_FADER"]){
const {h,graph}=makeOffline(),master=h.scope.master;
if(operation==="SET_MUTE")
assert.equal(h.window.__ARMIX_NATIVE_M2__.consumeAction(master,"mute",{}),true);
else
assert.equal(h.window.__ARMIX_NATIVE_M2__.consumeDoubleClick({
target:{classList:{contains:x=>x==="fader"}}
},master),true);
const emitted=h.sent.filter(e=>e.name==="arMixLogicalIntent");
assert.equal(emitted.length,1,operation+" must edit offline .smix via logical authority");
assert.equal(emitted[0].payload.operation,operation);
assert.equal(emitted[0].payload.channelId,graph.mainChannelId);
assert.equal(h.sent.some(e=>e.name==="arMixConsoleIntent" ||
e.payload?.action==="routingM4Control"),false,
"logical MAIN edit must never trigger physical PCM or output");
}
});

test("held ChannelId drag publishes first gain and coalesces latest BEFORE release",()=>{
const h=harness(),s=nativeChannelIdFixture();
h.listeners.get("arMixConsoleSnapshot")(s);
Expand Down
29 changes: 28 additions & 1 deletion web/approved-channel-strip-view-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,33 @@
"SETTLE":"REFRESH";
}

// G-MV26: one native-authority gate for physical MAIN gain and mute.
// The host still accepts MAIN via its existing routingM4Control scalar
// transport, but stale legacy M4 telemetry is NEVER enough to authorize
// a new command after ChannelId takeover or loss of PCM admission.
// Keep this pure: no GUI, ACK state, output arming, or graph mutation.
function masterScalarAuthority(snapshot,{m4Verified=false,
graphConnected=false}={}) {
const epoch=snapshot?.device?.epoch,
session=snapshot?.raw?.mixerSession,
legacy=snapshot?.raw?.legacyM4;
// MAIN host IPC uses safe integer M4 epoch/revision tokens, unlike
// the separate uint64 ChannelId controller. Require real readback.
if(!positiveCounter(epoch)||!positiveCounter(legacy?.routingRevision)||
session?.deviceEpoch!==epoch||snapshot?.retained===true||
!Number.isFinite(session?.main?.db)||
typeof session?.main?.mute!=="boolean")return "UNAVAILABLE";
if(session.authority==="CHANNEL_ID")
return snapshot?.admitted===true && graphConnected===true?
"CHANNEL_ID":"UNAVAILABLE";
if(session.authority==="M4")
return snapshot?.admitted===false && m4Verified===true &&
legacy.active===true && legacy.routeAccepted===true &&
session.routeRevision===legacy.routingRevision?
"M4":"UNAVAILABLE";
return "UNAVAILABLE";
}

// MV-9: pure Channel Strip scalar gesture/readback policy. The only
// pending Maps, native events, timers and audio transport stay in the
// approved bridge. Treat exact decimal-string ChannelIds as opaque data.
Expand Down Expand Up @@ -717,7 +744,7 @@
sourceAckResult,sourceReadbackSettlement,
m4SourceReadbackSettlement,sourceQueueReadback,sourceQueueAckTransition,
sourceQueueTimeoutDecision,
scalarIdentityMatches,scalarVisualSettlement,m4ScalarAckResult,
masterScalarAuthority,scalarIdentityMatches,scalarVisualSettlement,m4ScalarAckResult,
m4ScalarReadbackSettlement,scalarDispatchLease,
scalarGestureFlushPlan,scalarDispatchPlan,
identityReadback,identityEditPlan,
Expand Down
49 changes: 34 additions & 15 deletions web/approved-native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,11 @@
// One native SessionSnapshot, not an independently reconstructed M4 model.
const mixerSession=()=>hardware?.raw?.mixerSession;
const m4ControlIsOwner=()=>mixerSession()?.authority==="M4";
const nativeMasterReady=()=>mixerSession()?.authority==="CHANNEL_ID" &&
safeNativeCounter(hardware?.device?.epoch)!==null &&
safeNativeCounter(legacy()?.routingRevision)!==null &&
Number.isFinite(mixerSession()?.main?.db) &&
typeof mixerSession()?.main?.mute==="boolean";
// The pure Strip VM admits MAIN only for the CURRENT, installed PCM
// producer. Old M4 status is never permission to control a retired owner.
const nativeMasterAuthority=()=>stripVM.masterScalarAuthority(
controller?.state()?.current,{m4Verified:m4Verified(),
graphConnected:flags.acceptedGraphConnected});
// The shipped /preview/ IN dropdown is the sole normal hardware source
// selector. Build options exclusively from JUCE-reported active pins, never
// the public browser demo's hardcoded "Input 1 / CABLE / Realtek" strings.
Expand Down Expand Up @@ -1544,7 +1544,7 @@
};
function liveScalarReady(parameter,t) {
if(t?.kind==="master")return logicalView?parameter==="masterGain":
parameter==="masterGain"&&(m4Verified()||nativeMasterReady());
parameter==="masterGain"&&nativeMasterAuthority()!=="UNAVAILABLE";
if(m4ControlIsOwner())return m4Verified()&&m4Index(t)>=0;
return channelIdScalarReady(parameter,t);
}
Expand Down Expand Up @@ -1665,8 +1665,9 @@
}
}
function sendM4Control(parameter,t,value) {
if((t?.kind!=="master"&&!m4ControlIsOwner()) ||
!(m4Verified()||(t?.kind==="master"&&nativeMasterReady())) ||
if((t?.kind==="master"?
nativeMasterAuthority()==="UNAVAILABLE":
!m4ControlIsOwner()||!m4Verified()) ||
(typeof value!=="boolean"&&!Number.isFinite(value)))
return false;
const channel=t?.kind==="master"?-1:m4Index(t);
Expand Down Expand Up @@ -3666,10 +3667,18 @@
return true;
}
if (action==="mute"||action==="solo") {
if((m4Verified()||nativeMasterReady()) &&
t.kind==="master" && action==="mute"){
if(!sendM4Control("masterMute",t,!t.mute))
status("Native MAIN mute rejected");
// MAIN has one host scalar gateway. A refused native MAIN lease
// must never fall through to generic ChannelId SET_MUTE/SOLO.
if(t.kind==="master"){
// Offline .smix remains an editable durable logical mixer:
// its native logical-intent owner is distinct from physical PCM.
if(logicalView){
intent(action==="mute"?"SET_MUTE":"SET_SOLO",t,
{value:!t[action],enabled:!t[action]});
}else if(action==="mute" && nativeMasterAuthority()!=="UNAVAILABLE"){
if(!sendM4Control("masterMute",t,!t.mute))
status("Native MAIN mute rejected");
}else status("MAIN mute unavailable · verified PCM required");
return true;
}
if(m4ControlIsOwner()&&m4Verified()&&m4Index(t)>=0){
Expand Down Expand Up @@ -3930,9 +3939,19 @@
status("SOF unity reset unavailable · select one admitted SEND");
return true;
}
if((m4ControlIsOwner()&&m4Verified()) ||
(t?.kind==="master"&&(m4Verified()||nativeMasterReady())))
sendM4Control(t?.kind==="master"?"masterGain":"faderDb",t,0);
// MAIN reset must not become an unrelated ChannelId SET_FADER
// when its native physical host scalar lease is not admitted.
if(t?.kind==="master"){
// An offline MAIN unity reset edits the logical .smix document,
// never the unavailable physical host/ChannelId PCM authority.
if(logicalView)intent("SET_FADER",t,{valueDb:0});
else if(nativeMasterAuthority()!=="UNAVAILABLE")
sendM4Control("masterGain",t,0);
else status("MAIN reset unavailable · verified PCM required");
return true;
}
if(m4ControlIsOwner()&&m4Verified())
sendM4Control("faderDb",t,0);
else intent("SET_FADER",t,{valueDb:0});
}
else if(event.target.closest?.(".gain-dial")){
Expand Down
Loading