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
108 changes: 102 additions & 6 deletions tests/approved_native_m2_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,63 @@ const clone=x=>JSON.parse(JSON.stringify(x));

// GUI-4: SOURCE ONLY and physical PRIMARY OUT must not consume a parallel SEND.


test("MV-7 native SOURCE requires ACKed graph revision AND independently installed input pins",()=>{
const id="9007199254740993",epoch="18446744073709551610";
const beforeRevision="9223372036854775807",afterRevision="9223372036854775808";
const p={requestId:"source-native-99",id,epoch,beforeRevision,
choice:{label:"Mic A",mode:"STEREO",left:2,right:3},acked:false};
const snapshot={admitted:true,retained:false,device:{epoch},
graph:{revision:beforeRevision,channels:[{id,role:"INPUT",
source:{portId:"in:2",portIdRight:"in:3",sourceFormat:"STEREO"}}]}};
const before=JSON.stringify(snapshot);
const settle=(request,readback=snapshot)=>stripVM.sourceReadbackSettlement(request,readback);
assert.equal(settle(null),"NONE");
assert.equal(settle(p),"PENDING_ACK");
assert.equal(settle({...p,acked:true,ackRevision:afterRevision}),"PENDING",
"even matching pins at old revision are not accepted readback");
const installed=clone(snapshot);installed.graph.revision=afterRevision;
assert.equal(settle({...p,acked:true,ackRevision:afterRevision},installed),
"CONFIRMED");
assert.equal(JSON.stringify(snapshot),before,"VM cannot mutate accepted PCM");
const acked={...p,acked:true,ackRevision:afterRevision};
const other=clone(installed);other.graph.channels[0].source.portIdRight="in:4";
assert.equal(settle(acked,other),"PENDING",
"stereo right pin must independently match native source readback");
const wrongFormat=clone(installed);
wrongFormat.graph.channels[0].source.sourceFormat="MONO";
assert.equal(settle(acked,wrongFormat),"PENDING");
const noRoute=clone(installed);delete noRoute.graph.channels[0].source;
assert.equal(settle(acked,noRoute),"PENDING");
const reconnect=clone(installed);reconnect.device.epoch="18446744073709551611";
assert.equal(settle(acked,reconnect),"STALE");
assert.equal(settle(acked,{...installed,retained:true,admitted:false}),"STALE");
assert.equal(settle(acked,{...installed,raw:{mixerSession:{
authority:"M4",deviceEpoch:epoch}}}),"STALE");
assert.equal(settle(acked,{...installed,raw:{mixerSession:{
authority:"CHANNEL_ID",deviceEpoch:"18446744073709551611"}}}),"STALE");
assert.equal(settle({...acked,ackRevision:beforeRevision},installed),"PENDING",
"ACK publisher revision cannot equal original accepted source graph");
const missing=clone(installed);missing.graph.channels=[];
assert.equal(settle(acked,missing),"STALE");
const mono={...acked,choice:{label:"Mono",mode:"MONO",left:2,right:-1}};
const monoread=clone(installed);delete monoread.graph.channels[0].source.portIdRight;
monoread.graph.channels[0].source.sourceFormat="MONO";
assert.equal(settle(mono,monoread),"CONFIRMED");
const none={...acked,choice:{label:"None",mode:"NONE",left:-1,right:-1}};
assert.equal(settle(none,noRoute),"CONFIRMED");
assert.equal(settle(none,installed),"PENDING",
"SOURCE NONE must not remove a physical input from UI before installed PCM");
const model=read("web/approved-channel-strip-view-model.js");
const bridge=read("web/approved-native-bridge.js");
assert.match(bridge,/stripVM\.sourceReadbackSettlement\(/);
assert.match(bridge,/beforeRevision:current\.graph\.revision,acked:false/);
assert.match(bridge,/ackRevision:ack\.graphRevision/);
assert.match(bridge,/settleNativeSourceReadback\(next\)/);
assert.doesNotMatch(model,/backend\.emitEvent|document\.|window\.setTimeout/,
"Channel Strip readback remains pure; bridge holds one transient source queue");
});

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 @@ -124,12 +181,26 @@ test("MV-6 M4 SOURCE dispatch reuses fresh revision but never migrates stale dev
assert.equal(stripVM.sourceAckResult(pending,{...ack,state:{...ack.state,
acceptedRoute:{channels:Array.from({length:10},(_,i)=>i===4?
{mode:"MONO",left:2,right:-1}:null)}}},"M4"),"REJECTED");
assert.equal(stripVM.sourceAckResult({requestId:"source-native-1"},
{requestId:"source-native-1",ok:true},"CHANNEL_ID"),"ACKED");
assert.equal(stripVM.sourceAckResult({requestId:"source-native-1"},
{requestId:"source-native-2",ok:true},"CHANNEL_ID"),"IGNORE");
assert.equal(stripVM.sourceAckResult({requestId:"source-native-1"},
{requestId:"source-native-1",ok:false},"CHANNEL_ID"),"REJECTED");
const nativePending={requestId:"source-native-1",
id:"9007199254740993",epoch:"18446744073709551610",
beforeRevision:"9223372036854775807"};
const nativeAck={requestId:"source-native-1",
channelId:"9007199254740993",graphRevision:"9223372036854775808",
ok:true};
assert.equal(stripVM.sourceAckResult(nativePending,nativeAck,"CHANNEL_ID"),
"ACKED");
assert.equal(stripVM.sourceAckResult(nativePending,
{...nativeAck,requestId:"source-native-2"},"CHANNEL_ID"),"IGNORE");
assert.equal(stripVM.sourceAckResult(nativePending,
{...nativeAck,ok:false},"CHANNEL_ID"),"REJECTED");
assert.equal(stripVM.sourceAckResult(nativePending,
{...nativeAck,channelId:"9007199254740994"},"CHANNEL_ID"),"REJECTED");
assert.equal(stripVM.sourceAckResult(nativePending,
{...nativeAck,graphRevision:nativePending.beforeRevision},"CHANNEL_ID"),
"REJECTED");
assert.equal(stripVM.sourceAckResult(nativePending,
{...nativeAck,graphRevision:"18446744073709551616"},"CHANNEL_ID"),
"REJECTED");
const bridge=read("web/approved-native-bridge.js");
assert.match(bridge,/stripVM\.sourceQueueSelection\(/);
assert.equal((bridge.match(/stripVM\.sourceDispatchPlan\(/g)||[]).length,2,
Expand Down Expand Up @@ -2248,6 +2319,31 @@ test("P0 native hardware IN remains selectable after ChannelId ownership, failed
assert.equal(sourceCommands()[1].payload.left,1);
assert.equal(sourceCommands()[1].payload.graphRevision,base.graph.revision);
assert.notEqual(sourceCommands()[1].payload.requestId,id);
// MV-7: a later positive ACK must NOT drain a third channel edit until the
// exact new source pins and native graph revision are observed separately.
assert.equal(choose(scope.tracks[0],"Mono · Mic A [IN 1]"),true);
const secondCommand=sourceCommands()[1];
listeners.get("arMixNativeSourceAck")({
requestId:secondCommand.payload.requestId,channelId:second.id,
graphRevision:"6",ok:true
});
assert.equal(sourceCommands().length,2,"ACK is not installed PCM readback");
listeners.get("arMixConsoleSnapshot")(base);
while(microtasks.length)microtasks.shift()();
assert.equal(sourceCommands().length,2,
"unchanged pre-ACK PCM must hold next queued SOURCE");
const installed=clone(base);
installed.graph.revision="6";
installed.graph.channels.find(ch=>ch.id===second.id).source={
sourceFormat:"MONO",portId:"in:1"
};
installed.mixerSession.routeRevision="6";
listeners.get("arMixConsoleSnapshot")(installed);
while(microtasks.length)microtasks.shift()();
assert.equal(sourceCommands().length,3,
"installed source readback unlocks only one next queued edit");
assert.equal(sourceCommands()[2].payload.channelId,first.id);
assert.equal(sourceCommands()[2].payload.graphRevision,"6");
});
test("M3/V60 Windows bundle dispatches exactly one fader release through native ACK and fences FX reorder",()=>{
const builder=read("scripts/build_approved_native_gui.py");
Expand Down
44 changes: 42 additions & 2 deletions web/approved-channel-strip-view-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@
function sourceAckResult(pending,ack,authority) {
if(!pending||ack?.requestId!==pending.requestId)return "IGNORE";
if(authority==="CHANNEL_ID")
return ack?.ok===true?"ACKED":"REJECTED";
return ack?.ok===true && ack?.channelId===pending.id &&
decimalId(pending.beforeRevision) && decimalId(ack.graphRevision) &&
BigInt(ack.graphRevision)>BigInt(pending.beforeRevision)?
"ACKED":"REJECTED";
if(authority!=="M4")return "REJECTED";
const next=ack?.state||{},row=next.acceptedRoute?.channels?.[pending.channel];
return ack?.ok===true&&next.ready===true&&
Expand All @@ -275,8 +278,45 @@
"ACKED":"REJECTED";
}


// MV-7: ACK is only a correlated native acceptance, never proof of PCM.
// Compare the installed ChannelId SOURCE row, physical pins and exact
// revision without converting 64-bit graph identities through Number.
// The bridge remains the sole holder of the active transient request.
function sourceReadbackSettlement(pending,next) {
if(!pending)return "NONE";
if(!decimalId(pending.id)||!decimalId(pending.epoch)||
next?.device?.epoch!==pending.epoch||
next?.retained===true||next?.admitted!==true||
(next?.raw && (next.raw.mixerSession?.authority!=="CHANNEL_ID"||
next.raw.mixerSession.deviceEpoch!==pending.epoch)))return "STALE";
const rows=next?.graph?.channels;
if(!Array.isArray(rows))return "PENDING";
const channel=rows.find(row=>row?.id===pending.id);
if(!channel||channel.role!=="INPUT")return "STALE";
if(pending.acked!==true)return "PENDING_ACK";
if(!decimalId(pending.beforeRevision)||
!decimalId(pending.ackRevision)||
!decimalId(next.graph.revision)||
BigInt(pending.ackRevision)<=BigInt(pending.beforeRevision)||
BigInt(next.graph.revision)<BigInt(pending.ackRevision))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Require the ACK's exact graph revision before confirming SOURCE

If another native edit advances the graph before the ACKed revision is observed, this comparison accepts the later snapshot as proof of the SOURCE request. For example, an ACK for revision 6 followed only by revision 7 with matching pins returns CONFIRMED, causing settleNativeSourceReadback to report verified PCM and release the next queued edit without observing revision 6. The existing controller in web/approved-native-contract.js instead treats readback beyond the ACK revision as conflicting. Require exact revision equality and handle a superseding revision as a conflict/refresh rather than successful settlement; AGENTS.md explicitly requires a matching ACK and same-revision native snapshot.

AGENTS.md reference: AGENTS.md:L178-L178

Useful? React with 👍 / 👎.

return "PENDING";
const choice=pending.choice;
if(!choice||!["NONE","MONO","STEREO"].includes(choice.mode))
return "PENDING";
const source=channel.source;
if(choice.mode==="NONE")return !source?"CONFIRMED":"PENDING";
if(!source||source.bindingState==="NEEDS_REMAP"||
source.portId!=="in:"+choice.left)return "PENDING";
if(choice.mode==="MONO")
return source.sourceFormat==="MONO" &&
source.portIdRight===undefined?"CONFIRMED":"PENDING";
return source.sourceFormat==="STEREO" &&
source.portIdRight==="in:"+choice.right?"CONFIRMED":"PENDING";
}

return Object.freeze({outputTargets,inputChoices,externalChoices,
primaryChoices,resolvePrimarySelection,readbackBindings,externalPending,
primaryOutMutation,externalOutputPlan,sourceQueueSelection,
sourceDispatchPlan,sourceAckResult});
sourceDispatchPlan,sourceAckResult,sourceReadbackSettlement});
});
31 changes: 26 additions & 5 deletions web/approved-native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -1049,18 +1049,31 @@
return;
}
const requestId="source-native-"+(++nativeSourceSerial);
activeNativeSource={requestId,id,choice:entry.choice,epoch:entry.epoch};
activeNativeSource={requestId,id,choice:entry.choice,epoch:entry.epoch,
beforeRevision:current.graph.revision,acked:false};
backend.emitEvent("arMixAction",{
action:plan.action,requestId,...plan.payload
});
status("Input "+entry.choice.label+" · native PCM readback pending");
window.setTimeout(()=>{
if(activeNativeSource?.requestId!==requestId)return;
activeNativeSource=null;
nativeToast("Source ACK timed out · previous PCM preserved");
status("SOURCE timeout · refreshing accepted PCM and input choices");
controller?.subscribe();
},8000);
}
// Only independently installed ChannelId PCM readback may confirm SOURCE.
// Do not release the one active native transaction after ACK alone.
function settleNativeSourceReadback(next) {
const verdict=stripVM.sourceReadbackSettlement(activeNativeSource,next);
if(verdict!=="CONFIRMED"&&verdict!=="STALE")return;
const settled=activeNativeSource;
activeNativeSource=null;
if(verdict==="CONFIRMED")
status("Input "+settled.choice.label+" · native PCM readback verified");
else status("SOURCE changed or disconnected · accepted input refreshed");
if(pendingNativeSources.size)window.queueMicrotask(dispatchNativeSource);
}
let pendingBusCreate=null,pendingTrackDelete=null,stripRequestSerial=0;
function requestNativeTrackDelete(track){
if(logicalView)return logicalIntent("DELETE_CHANNEL",nativeIdFor(track),{}).ok;
Expand Down Expand Up @@ -2668,6 +2681,7 @@
status("NATIVE READBACK INVALID · existing GUI controls unchanged");
return;
}
settleNativeSourceReadback(next);
if(readModel.kind==="LOGICAL_ONLY") {
const staged=readModel.view;
let revealCreatedId=null,wireImpact=null;
Expand Down Expand Up @@ -2979,10 +2993,17 @@
backend.addEventListener("arMixNativeSourceAck",ack=>{
const verdict=stripVM.sourceAckResult(activeNativeSource,ack,"CHANNEL_ID");
if(verdict==="IGNORE")return;
activeNativeSource=null;
if(verdict!=="ACKED")
if(verdict==="ACKED"){
// ACK contains the publisher revision, but is not yet installed PCM.
activeNativeSource={...activeNativeSource,acked:true,
ackRevision:ack.graphRevision};
status("Native input ACKed · verifying accepted PCM source");
// An independently accepted snapshot can race ahead of the ACK.
settleNativeSourceReadback(controller?.state()?.current);
}else{
activeNativeSource=null;
nativeToast("Native input rejected · "+(ack?.error||"stale PCM"));
else status("Native input accepted · checking subsequent PCM readback");
}
controller?.subscribe();
});
backend.addEventListener("arMixNativeBusAck",ack=>{
Expand Down
Loading