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
104 changes: 102 additions & 2 deletions tests/approved_native_m2_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,114 @@ test("MV-7 native SOURCE requires ACKed graph revision AND independently install
const model=read("web/approved-channel-strip-view-model.js");
const bridge=read("web/approved-native-bridge.js");
assert.match(bridge,/stripVM\.sourceQueueReadback\(/);
assert.match(bridge,/beforeRevision:current\.graph\.revision,acked:false/);
assert.match(bridge,/stripVM\.sourceQueueRequestLease\(\{/);
assert.match(stripVM.sourceQueueAckTransition.toString(),/ack\.graphRevision/,
"exact native ACK graph revision is retained in the immutable VM lease");
assert.match(bridge,/settleSourceReadback\("CHANNEL_ID",next\)/);
assert.doesNotMatch(model,/backend\.emitEvent|document\.|window\.setTimeout/,
"Channel Strip readback remains pure; bridge holds one transient source queue");
});

test("G-MV22 physical SOURCE leases reject same-epoch hardware remaps for ChannelId and M4",()=>{
const epoch="91",id="9007199254740993";
const d={sampleRate:48000,bufferFrames:256,enabledInputs:[0,1],enabledOutputs:[0,1]};
const token=protocol.nativeHardwareConfiguration(d);
const choices=[{label:"None",mode:"NONE",left:-1,right:-1},
{label:"Mono IN1",mode:"MONO",left:0,right:-1}];
const selection=stripVM.sourceQueueSelection({choice:choices[1],choices,
epoch,acceptedLabel:"None",hardwareConfiguration:token});
assert.deepEqual(selection,{kind:"QUEUE",entry:{
epoch,hardwareConfiguration:token,choice:choices[1]}});
assert.equal(stripVM.sourceQueueSelection({choice:choices[1],choices,
epoch,acceptedLabel:"None",hardwareConfiguration:""}).kind,"UNAVAILABLE");
const hardware={device:{epoch},hardwareConfiguration:token,
raw:{mixerSession:{authority:"CHANNEL_ID"},legacyM4:{routingRevision:"34"}}};
const native={admitted:true,retained:false,device:{epoch},
hardwareConfiguration:token,raw:{mixerSession:{
authority:"CHANNEL_ID",deviceEpoch:epoch}},
graph:{revision:"61",rosterRevision:"17",
channels:[{id,role:"INPUT",source:null}]}};
const queue=new Map([[id,selection.entry]]);
const pick=(authority,h=hardware,n=native,q=queue)=>
stripVM.sourceQueueHead({authority,queue:q,hardware:h,
native:n,choices,deviceReady:true});
const plan=pick("CHANNEL_ID");
assert.equal(plan.kind,"SEND");
const pending=stripVM.sourceQueueRequestLease({authority:"CHANNEL_ID",
requestId:"source-native-99",plan,hardware,native});
assert.deepEqual(pending,{requestId:"source-native-99",id,epoch,
choice:choices[1],hardwareConfiguration:token,
beforeRevision:"61",acked:false});
assert.ok(Object.isFrozen(pending)&&Object.isFrozen(pending.choice));
const acked=stripVM.sourceQueueAckTransition({authority:"CHANNEL_ID",
pending,ack:{requestId:pending.requestId,channelId:id,
graphRevision:"62",ok:true}}).pending;
const installed={...native,graph:{...native.graph,revision:"62",
channels:[{id,role:"INPUT",source:{sourceFormat:"MONO",portId:"in:0"}}]}};
assert.equal(stripVM.sourceQueueReadback({authority:"CHANNEL_ID",
pending:acked,snapshot:installed}),"CONFIRMED");
assert.equal(protocol.nativeHardwareConfiguration({...d,
enabledInputs:[1,0],enabledOutputs:[1,0]}),token,
"physical port order is a set and must not restart valid source leases");
for(const variant of [
{...d,enabledInputs:[0]},{...d,enabledOutputs:[0,1,2,3]},
{...d,sampleRate:44100},{...d,bufferFrames:512}
]){
const other=protocol.nativeHardwareConfiguration(variant);
assert.notEqual(other,token);
const changed={...hardware,hardwareConfiguration:other};
assert.equal(pick("CHANNEL_ID",changed).kind,"DROP",
"old source cannot dispatch to replaced hardware within same epoch");
assert.equal(stripVM.sourceQueueRequestLease({authority:"CHANNEL_ID",
requestId:"source-native-99",plan,hardware:changed,native}),null);
assert.equal(stripVM.sourceQueueReadback({authority:"CHANNEL_ID",
pending:acked,snapshot:{...installed,hardwareConfiguration:other}}),"STALE");
assert.equal(stripVM.sourceQueueTimeoutDecision({authority:"CHANNEL_ID",
pending:acked,requestId:acked.requestId,
snapshot:{...installed,hardwareConfiguration:other}}),"REFRESH");
}
assert.equal(pick("CHANNEL_ID",hardware,
{...native,hardwareConfiguration:"other"}).kind,"DROP");
assert.equal(pick("CHANNEL_ID",hardware,native,
new Map([[id,{epoch,choice:choices[1]}]])).kind,"DROP",
"unscoped queue entries cannot enter real fingerprinted hardware");
const m4Hardware={...hardware,raw:{
mixerSession:{authority:"NONE"},legacyM4:{routingRevision:"34"}}};
const m4Native={...native,admitted:false,raw:{mixerSession:{
authority:"NONE",deviceEpoch:epoch}}};
const m4Plan=pick("M4",m4Hardware,m4Native,
new Map([[4,selection.entry]]));
assert.equal(m4Plan.kind,"SEND","first-sound M4 retains same hardware lease");
const m4Lease=stripVM.sourceQueueRequestLease({authority:"M4",requestId:101,
plan:m4Plan,hardware:m4Hardware,native:m4Native});
assert.deepEqual(m4Lease,{requestId:101,channel:4,epoch:91,revision:34,
choice:choices[1],hardwareConfiguration:token,acked:false});
const ack=stripVM.sourceQueueAckTransition({authority:"M4",pending:m4Lease,
ack:{requestId:101,ok:true,state:{ready:true,epoch:91,revision:35,
hasAcceptedRoute:true,acceptedRoute:{channels:Array.from({length:10},
(_,i)=>i===4?{mode:"MONO",left:0,right:-1}:null)}}}}).pending;
const readback={admitted:false,retained:false,device:{epoch},
hardwareConfiguration:token,raw:{
legacyM4:{active:true,routeAccepted:true,routingRevision:"35"},
mixerSession:{authority:"M4",deviceEpoch:epoch,routeRevision:"35",
channels:Array.from({length:10},(_,i)=>({role:"INPUT",
source:i===4?{mode:"MONO",left:0,right:-1}:
{mode:"NONE",left:-1,right:-1}}))}}};
assert.equal(stripVM.sourceQueueReadback({authority:"M4",
pending:ack,snapshot:readback}),"CONFIRMED");
assert.equal(stripVM.sourceQueueReadback({authority:"M4",
pending:ack,snapshot:{...readback,hardwareConfiguration:"other"}}),"STALE");
assert.equal(stripVM.sourceQueueRequestLease({authority:"M4",requestId:"101",
plan:m4Plan,hardware:m4Hardware,native:m4Native}),null);
assert.equal(queue.size,1,"VM selection cannot mutate bridge-owned queues");
const bridge=read("web/approved-native-bridge.js");
assert.match(bridge,/hardwareConfiguration:hardware\?\.hardwareConfiguration\?\?""/);
assert.equal((bridge.match(/stripVM\.sourceQueueRequestLease\(\{/g)||[]).length,1);
assert.doesNotMatch(bridge,/activeNativeSource=\{requestId,id:plan\.key/);
assert.doesNotMatch(stripVM.sourceQueueRequestLease.toString(),
/backend|document\.|window\.|setTimeout|emitEvent|AudioContext/);
});

test("MV-6 SOURCE input queues bind exact native device epoch and verified pins",()=>{
const choices=[{label:"None",mode:"NONE",left:-1,right:-1},
{label:"Mono · IN 1",mode:"MONO",left:0,right:-1},
Expand Down Expand Up @@ -550,7 +650,7 @@ test("MV-14 one pure dispatch head preserves FIFO and exact identity across Chan
assert.match(body,/while\(queue\.size\)/);
assert.match(body,/queue\.delete\(plan\.key\)/);
assert.match(body,/if\(plan\.kind==="DROP_ALL"\)\{queue\.clear\(\);return;\}/);
assert.match(body,/beforeRevision:current\.graph\.revision,acked:false/);
assert.match(body,/stripVM\.sourceQueueRequestLease\(\{/);
assert.match(body,/setTimeout\(\(\)=>handleSourceTimeout\(authority,requestId\),8000\)/);
assert.match(bridge,/nativeUiSourcePending=null;[\s\S]*?INPUT timeout/);
assert.match(body,/backend\.emitEvent\("arMixAction",\{action:plan\.action,requestId/);
Expand Down
76 changes: 69 additions & 7 deletions web/approved-channel-strip-view-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,24 +215,40 @@
choice.right===choice.left+1;
}
function sourceQueueSelection({choice,choices,epoch,acceptedLabel,
activeSameChannel=false}={}) {
if(!decimalId(epoch)||!sourceChoiceMatches(choice,choices))
activeSameChannel=false,
hardwareConfiguration}={}) {
// G-MV22: the operator's transient pin choice belongs to the EXACT
// installed physical pin/format configuration, not merely an epoch.
// The v6 native controller is the sole owner of this canonical token.
if(!decimalId(epoch)||!sourceChoiceMatches(choice,choices)||
(hardwareConfiguration!==undefined&&
(typeof hardwareConfiguration!=="string"||!hardwareConfiguration)))
return {kind:"UNAVAILABLE"};
// The operator can cancel a queued edit by returning to installed PCM.
// But when THIS channel already has an in-flight edit, queuing the old
// accepted choice is a legitimate rollback requested after its ACK.
if(choice.label===acceptedLabel&&!activeSameChannel)
return {kind:"CANCEL"};
return {kind:"QUEUE",entry:{epoch,choice:{
label:choice.label,mode:choice.mode,left:choice.left,right:choice.right
}}};
return {kind:"QUEUE",entry:{epoch,
...(hardwareConfiguration!==undefined?{hardwareConfiguration}:{}),
choice:{label:choice.label,mode:choice.mode,
left:choice.left,right:choice.right}}};
}
function sourceDispatchPlan({authority,entry,hardware,native,
channelId,channel,choices,deviceReady=false}={}) {
const unavailable={kind:"UNAVAILABLE"};
const choice=entry?.choice,epoch=hardware?.device?.epoch;
if(!deviceReady||!decimalId(epoch)||epoch!==entry?.epoch||
!sourceChoiceMatches(choice,choices))return unavailable;
!sourceChoiceMatches(choice,choices)||
// A live normalized native readback always has a fingerprint.
// Never let an unscoped old queue entry slip into that device.
(hardware?.hardwareConfiguration!==undefined?
!hardware.hardwareConfiguration||
entry?.hardwareConfiguration!==hardware.hardwareConfiguration:
entry?.hardwareConfiguration!==undefined)||
(native?.hardwareConfiguration!==undefined&&
entry?.hardwareConfiguration!==native.hardwareConfiguration))
return unavailable;
if(authority==="CHANNEL_ID"){
const graph=native?.graph,session=hardware?.raw?.mixerSession;
if(!decimalId(channelId)||native?.admitted!==true||
Expand Down Expand Up @@ -285,6 +301,48 @@
{kind:"DROP",key};
}

// G-MV22: one pure request-lease factory for both native SOURCE paths.
// Previously the bridge duplicated ChannelId/M4 pending shape, silently
// omitting the installed physical pin/format identity from both. The
// bridge still owns queues, timers and the ONE native command dispatcher.
function sourceQueueRequestLease({authority,requestId,plan,hardware,native}={}) {
if(plan?.kind!=="SEND"||!plan.entry?.choice||
!decimalId(plan.entry.epoch))return null;
const {entry,payload,key}=plan,config=entry.hardwareConfiguration;
if(config!==undefined&&
(typeof config!=="string"||!config||
config!==hardware?.hardwareConfiguration||
(native?.hardwareConfiguration!==undefined&&
config!==native.hardwareConfiguration)))return null;
const common={requestId,choice:Object.freeze({...entry.choice}),
...(config!==undefined?{hardwareConfiguration:config}:{})};
if(authority==="CHANNEL_ID") {
if(typeof requestId!=="string"||!requestId||
plan.action!=="routingNativeSourcePatch"||
!decimalId(key)||payload?.channelId!==key||
payload.deviceEpoch!==entry.epoch||
!decimalId(native?.graph?.revision)||
!decimalId(native?.graph?.rosterRevision)||
payload.graphRevision!==native.graph.revision||
payload.rosterRevision!==native.graph.rosterRevision)
return null;
return Object.freeze({...common,id:key,epoch:entry.epoch,
beforeRevision:native.graph.revision,acked:false});
}
if(authority==="M4"){
if(!Number.isSafeInteger(requestId)||requestId<=0||
!Number.isInteger(key)||key<0||key>=10||
plan.action!=="routingSourceSwitch"||
payload?.channel!==key||!positiveCounter(entry.epoch)||
payload.deviceEpoch!==Number(entry.epoch)||
!Number.isSafeInteger(payload.revision)||payload.revision<=0)
return null;
return Object.freeze({...common,channel:key,
epoch:payload.deviceEpoch,revision:payload.revision,acked:false});
}
return null;
}

function sourceAckResult(pending,ack,authority) {
if(!pending||ack?.requestId!==pending.requestId)return "IGNORE";
if(authority==="CHANNEL_ID")
Expand Down Expand Up @@ -399,6 +457,9 @@
// Each physical graph retains its own strict format, revision, epoch and
// pin verifier. A correlated ACK alone cannot confirm accepted PCM.
function sourceQueueReadback({authority,pending,snapshot}={}) {
if(pending?.hardwareConfiguration!==undefined&&
pending.hardwareConfiguration!==snapshot?.hardwareConfiguration)
return "STALE"; // same-epoch physical replacement cannot settle old ACK
if(authority==="CHANNEL_ID")
return sourceReadbackSettlement(pending,snapshot);
if(authority==="M4")
Expand Down Expand Up @@ -605,7 +666,8 @@
return Object.freeze({outputTargets,inputChoices,externalChoices,
primaryChoices,resolvePrimarySelection,readbackBindings,externalPending,
primaryOutMutation,externalOutputPlan,sourceQueueSelection,
sourceDispatchPlan,sourceQueueHead,sourceAckResult,sourceReadbackSettlement,
sourceDispatchPlan,sourceQueueHead,sourceQueueRequestLease,
sourceAckResult,sourceReadbackSettlement,
m4SourceReadbackSettlement,sourceQueueReadback,sourceQueueAckTransition,
sourceQueueTimeoutDecision,
scalarIdentityMatches,scalarVisualSettlement,m4ScalarAckResult,
Expand Down
16 changes: 8 additions & 8 deletions web/approved-native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,15 +1016,14 @@
}
const requestId=channelIdOwner?
"source-native-"+(++nativeSourceSerial):++sourceSerial;
if(channelIdOwner){
activeNativeSource={requestId,id:plan.key,
choice:plan.entry.choice,epoch:plan.entry.epoch,
beforeRevision:current.graph.revision,acked:false};
}else{
nativeUiSourcePending={requestId,channel:plan.key,
choice:plan.entry.choice,epoch:plan.payload.deviceEpoch,
revision:plan.payload.revision,acked:false};
const lease=stripVM.sourceQueueRequestLease({
authority,requestId,plan,hardware,native:current});
if(!lease){
status("SOURCE identity changed · old input choice discarded");
continue; // no old pin intent is emitted to a replaced device
}
if(channelIdOwner)activeNativeSource=lease;
else nativeUiSourcePending=lease;
backend.emitEvent("arMixAction",{action:plan.action,requestId,
...plan.payload});
if(channelIdOwner)
Expand Down Expand Up @@ -3364,6 +3363,7 @@
}
const decision=stripVM.sourceQueueSelection({
choice,choices,epoch:hardware?.device?.epoch,acceptedLabel:t.input,
hardwareConfiguration:hardware?.hardwareConfiguration??"",
activeSameChannel:nativeOwner?activeNativeSource?.id===id:
nativeUiSourcePending?.channel===channel
});
Expand Down
Loading