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
4 changes: 4 additions & 0 deletions .github/workflows/ui-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ on:
- 'tests/wire_main_native_handoff_contract.test.cjs'
- 'tests/approved_native_m2_contract.test.cjs'
- 'tests/approved_device_pin_identity_contract.test.cjs'
- 'tests/approved_scalar_view_model_contract.test.cjs'
- 'scripts/build_ui_css.py'
# Only user-facing GUI/bridge files are relevant. No PR metadata API gate.
pull_request:
Expand All @@ -55,6 +56,7 @@ on:
- 'tests/ci_workflow_efficiency_test.mjs'
- 'tests/approved_native_m2_contract.test.cjs'
- 'tests/approved_device_pin_identity_contract.test.cjs'
- 'tests/approved_scalar_view_model_contract.test.cjs'
- 'scripts/build_ui_css.py'
- '.github/workflows/ui-smoke.yml'
- '.github/workflows/pages-publish.yml'
Expand Down Expand Up @@ -132,6 +134,7 @@ jobs:
- name: Check native UI contracts, workflow policy, and WIRE without Chromium
run: |
node --test tests/approved_device_pin_identity_contract.test.cjs
node --test tests/approved_scalar_view_model_contract.test.cjs
node --test tests/floating_window_workspace_contract.test.mjs
node --test tests/rc_operator_workflow_contract.test.mjs
node --test tests/workstream_coordination_contract.test.mjs tests/chat_ci_dispatch_contract.test.mjs tests/gui_workflow_contract_test.mjs tests/plugin_ui_contract_test.mjs tests/ci_workflow_efficiency_test.mjs tests/fx_drag_reorder_contract_test.mjs tests/mixer_io_operator_contract_test.mjs tests/mixer_shell_contract_test.mjs tests/approved_native_m2_contract.test.cjs
Expand Down Expand Up @@ -497,6 +500,7 @@ jobs:
node --check web/mixer-layout.js
node --test tests/workstream_coordination_contract.test.mjs tests/chat_ci_dispatch_contract.test.mjs tests/gui_workflow_contract_test.mjs tests/plugin_ui_contract_test.mjs tests/ci_workflow_efficiency_test.mjs tests/fx_drag_reorder_contract_test.mjs tests/mixer_io_operator_contract_test.mjs tests/mixer_shell_contract_test.mjs tests/approved_native_m2_contract.test.cjs
node --test tests/approved_device_pin_identity_contract.test.cjs
node --test tests/approved_scalar_view_model_contract.test.cjs
- name: Validate approved GUI checkpoint and single publisher
run: python tests/gui_baseline_lock_test.py
python tests/mixer_physical_keys_contract.py
Expand Down
134 changes: 134 additions & 0 deletions tests/approved_scalar_view_model_contract.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// SPDX-License-Identifier: AGPL-3.0-only
// MV-9: pure Channel Strip scalar policy, with ONE native bridge/PCM authority.
const test=require("node:test");
const assert=require("node:assert/strict");
const {readFileSync}=require("node:fs");
const vm=require("../web/approved-channel-strip-view-model.js");

const bigId="9007199254740993";
const bigNext="9007199254740994";
const bigEpoch="18446744073709551610";
const identity={epoch:bigEpoch,authority:"CHANNEL_ID",channelId:bigId};
const edit={...identity,parameter:"faderDb",value:-8.5};
const m4Epoch="14",m4Revision="23";
function m4Snapshot({
epoch=m4Epoch,revision=m4Revision,authority="M4",
fader=-7.5,pan=.25,mute=false,solo=false,master=-3.0
}={}) {
return {device:{epoch},raw:{
legacyM4:{routingRevision:revision},
mixerSession:{authority,routeRevision:revision,
channels:Array.from({length:10},(_,i)=>({
controls:{faderDb:i===2?fader:0,pan:i===2?pan:0,
mute:i===2?mute:false,solo:i===2?solo:false}
})),main:{db:master,mute:false}}}};
}
const m4Pending=(parameter,value,channel=2)=>({
requestId:"m4-45",channel,parameter,value,
epoch:m4Epoch,revision:m4Revision,acked:false
});
const ack=(p,extra={})=>({
requestId:p.requestId,deviceEpoch:Number(p.epoch),
routingRevision:Number(p.revision),channel:p.channel,
parameter:p.parameter,ok:true,...extra
});

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);
assert.equal(vm.scalarIdentityMatches(edit,{...identity,epoch:"18446744073709551611"}),false);
assert.equal(vm.scalarIdentityMatches(edit,{...identity,authority:"M4"}),false);
assert.equal(vm.scalarIdentityMatches(edit,{...identity,channelId:Number(bigId)}),false);
assert.equal(vm.scalarIdentityMatches(null,identity),false);
assert.equal(vm.scalarIdentityMatches(edit,null),false);
});

test("MV-9 last fader cap remains display-only until separately accepted readback",()=>{
assert.equal(vm.scalarVisualSettlement(null,-8.5,identity),"NONE");
assert.equal(vm.scalarVisualSettlement(edit,-12.5,identity),"WAIT");
assert.equal(vm.scalarVisualSettlement(edit,-8.41,identity),"CONFIRMED");
assert.equal(vm.scalarVisualSettlement(edit,-8.62,identity),"WAIT");
assert.equal(vm.scalarVisualSettlement(edit,NaN,identity),"WAIT");
assert.equal(vm.scalarVisualSettlement(edit,Infinity,identity),"WAIT");
assert.equal(vm.scalarVisualSettlement({...edit,value:NaN},0,identity),"STALE");
assert.equal(vm.scalarVisualSettlement(edit,-8.5,{...identity,channelId:bigNext}),"STALE",
"old channel's target cannot override the next channel's fader");
assert.equal(vm.scalarVisualSettlement(edit,-8.5,{...identity,epoch:"18446744073709551612"}),"STALE",
"device reconnect must drop last gesture display");
});

test("MV-9 M4 ACK must correlate exact request/channel, epoch, revision, parameter",()=>{
const p=m4Pending("faderDb",-7.5);
assert.equal(vm.m4ScalarAckResult(null,ack(p)),"IGNORE");
assert.equal(vm.m4ScalarAckResult(p,{...ack(p),requestId:"m4-44"}),"IGNORE");
assert.equal(vm.m4ScalarAckResult(p,ack(p)),"ACKED");
for(const patch of [
{ok:false},{channel:3},{parameter:"pan"},{deviceEpoch:15},
{routingRevision:24},{routingRevision:null}
])assert.equal(vm.m4ScalarAckResult(p,ack(p,patch)),"REJECTED",
"stale or wrong ACK is not installed native scalar proof");
});

test("MV-9 M4 fader ACK alone is not accepted fader readback",()=>{
const p=m4Pending("faderDb",-7.5),unchanged=m4Snapshot({fader:0});
assert.equal(vm.m4ScalarReadbackSettlement(p,unchanged),"WAIT");
assert.equal(vm.m4ScalarReadbackSettlement({...p,acked:true},unchanged),"WAIT");
const readback=m4Snapshot();
assert.equal(vm.m4ScalarReadbackSettlement(p,readback),"WAIT");
assert.equal(vm.m4ScalarReadbackSettlement({...p,acked:true},readback),"CONFIRMED");
assert.equal(vm.m4ScalarReadbackSettlement({...p,acked:true},
m4Snapshot({fader:-7.63})),"WAIT");
});

test("MV-9 native M4 scalar is invalidated by route/epoch and authority changes",()=>{
const p={...m4Pending("faderDb",-7.5),acked:true};
assert.equal(vm.m4ScalarReadbackSettlement(p,m4Snapshot({epoch:"15"})),"STALE");
assert.equal(vm.m4ScalarReadbackSettlement(p,m4Snapshot({revision:"24"})),"STALE");
assert.equal(vm.m4ScalarReadbackSettlement(p,m4Snapshot({authority:"CHANNEL_ID"})),"STALE");
assert.equal(vm.m4ScalarReadbackSettlement(p,null),"STALE");
assert.equal(vm.m4ScalarReadbackSettlement(null,m4Snapshot()),"NONE");
});

test("MV-9 M4 PAN conversion preserves percent target and existing tolerance",()=>{
const pan={...m4Pending("pan",25),acked:true};
assert.equal(vm.m4ScalarReadbackSettlement(pan,m4Snapshot({pan:.25})),"CONFIRMED");
assert.equal(vm.m4ScalarReadbackSettlement(pan,m4Snapshot({pan:.257})),"CONFIRMED");
assert.equal(vm.m4ScalarReadbackSettlement(pan,m4Snapshot({pan:.26})),"WAIT");
assert.equal(vm.m4ScalarReadbackSettlement(pan,m4Snapshot({pan:NaN})),"WAIT");
assert.equal(vm.m4ScalarReadbackSettlement({...pan,value:NaN},m4Snapshot()),"WAIT");
assert.equal(vm.m4ScalarReadbackSettlement({...pan,channel:9},m4Snapshot()),"WAIT",
"an unrelated channel cannot satisfy this M4 PAN edit");
});

test("MV-9 M4 MUTE/SOLO boolean state cannot be confirmed by truthy coercion",()=>{
const mute={...m4Pending("mute",true),acked:true};
const solo={...m4Pending("solo",false),acked:true};
assert.equal(vm.m4ScalarReadbackSettlement(mute,m4Snapshot({mute:true})),"CONFIRMED");
assert.equal(vm.m4ScalarReadbackSettlement(mute,m4Snapshot({mute:false})),"WAIT");
assert.equal(vm.m4ScalarReadbackSettlement(solo,m4Snapshot({solo:false})),"CONFIRMED");
assert.equal(vm.m4ScalarReadbackSettlement(solo,m4Snapshot({solo:true})),"WAIT");
});

test("MV-9 M4 MAIN gain uses existing legacy routing epoch not ChannelId revision",()=>{
const main={...m4Pending("masterGain",-3,-1),acked:true};
assert.equal(vm.m4ScalarReadbackSettlement(main,m4Snapshot()),"CONFIRMED");
assert.equal(vm.m4ScalarReadbackSettlement(main,m4Snapshot({master:2})),"WAIT");
const changed=m4Snapshot();changed.raw.legacyM4.routingRevision="24";
assert.equal(vm.m4ScalarReadbackSettlement(main,changed),"STALE");
const other=m4Snapshot({authority:"CHANNEL_ID"});
assert.equal(vm.m4ScalarReadbackSettlement(main,other),"CONFIRMED",
"existing native MAIN host scalar is not M4 channel ordinal");
});

test("MV-9 bridge uses exactly one real scalar transport and pure decisions",()=>{
const model=readFileSync("web/approved-channel-strip-view-model.js","utf8");
const bridge=readFileSync("web/approved-native-bridge.js","utf8");
assert.match(bridge,/stripVM\.scalarIdentityMatches\(edit,nativeEditIdentity\(edit\.t\)\)/);
assert.match(bridge,/stripVM\.scalarVisualSettlement\(pending,actualDb,/);
assert.match(bridge,/stripVM\.m4ScalarReadbackSettlement\(p,next\)/);
assert.match(bridge,/stripVM\.m4ScalarAckResult\(p,ack\)/);
assert.match(bridge,/if\(!Number\.isFinite\(value\)\|\|!liveScalarReady\(parameter,t\)\)return false;/);
assert.equal((bridge.match(/backend\.addEventListener\("arMixM4ControlAck"/g)||[]).length,1);
assert.equal((bridge.match(/action:"routingM4Control"/g)||[]).length,1);
assert.doesNotMatch(model,/document\.|window\.|backend\.emitEvent|localStorage|AudioContext/);
});
54 changes: 53 additions & 1 deletion web/approved-channel-strip-view-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,60 @@
source.portIdRight==="in:"+choice.right?"CONFIRMED":"PENDING";
}

// 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.
function scalarIdentityMatches(edit,identity) {
return !!edit && !!identity &&
edit.epoch===identity.epoch &&
edit.authority===identity.authority &&
edit.channelId===identity.channelId;
}
// Last pointer target is DISPLAY-ONLY until independently installed
// fader PCM readback matches it; never rewrite a native track model.
function scalarVisualSettlement(pending,acceptedDb,identity) {
if(!pending)return "NONE";
if(!scalarIdentityMatches(pending,identity) ||
!Number.isFinite(pending.value))return "STALE";
return Number.isFinite(acceptedDb) &&
Math.abs(acceptedDb-pending.value)<=.11?"CONFIRMED":"WAIT";
}
function m4ScalarAckResult(pending,ack) {
if(!pending || ack?.requestId!==pending.requestId)return "IGNORE";
return ack.ok===true &&
String(ack.deviceEpoch)===pending.epoch &&
String(ack.routingRevision)===pending.revision &&
ack.channel===pending.channel &&
ack.parameter===pending.parameter?"ACKED":"REJECTED";
}
// One M4 scalar can be confirmed by only its corresponding accepted
// producer readback; an ACK never installs fader, PAN, MUTE, or MAIN gain.
// The full routing revision must still belong to the original M4 request.
function m4ScalarReadbackSettlement(pending,snapshot) {
if(!pending)return "NONE";
const session=snapshot?.raw?.mixerSession;
const revision=pending.channel===-1?
snapshot?.raw?.legacyM4?.routingRevision:session?.routeRevision;
if(snapshot?.device?.epoch!==pending.epoch ||
revision!==pending.revision ||
(pending.channel!==-1&&session?.authority!=="M4"))
return "STALE";
const row=pending.channel===-1?null:session?.channels?.[pending.channel];
const value=pending.channel===-1?
(pending.parameter==="masterGain"?session?.main?.db:session?.main?.mute):
pending.parameter==="faderDb"?row?.controls?.faderDb:
pending.parameter==="pan"?row?.controls?.pan*100:
row?.controls?.[pending.parameter];
const matches=typeof pending.value==="boolean"?value===pending.value:
Number.isFinite(pending.value)&&Number.isFinite(value)&&
Math.abs(value-pending.value)<=(pending.parameter==="pan"?.8:.11);
return pending.acked===true&&matches?"CONFIRMED":"WAIT";
}

return Object.freeze({outputTargets,inputChoices,externalChoices,
primaryChoices,resolvePrimarySelection,readbackBindings,externalPending,
primaryOutMutation,externalOutputPlan,sourceQueueSelection,
sourceDispatchPlan,sourceAckResult,sourceReadbackSettlement});
sourceDispatchPlan,sourceAckResult,sourceReadbackSettlement,
scalarIdentityMatches,scalarVisualSettlement,m4ScalarAckResult,
m4ScalarReadbackSettlement});
});
45 changes: 12 additions & 33 deletions web/approved-native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -1502,10 +1502,7 @@
channelId:logicalView?nativeIdFor(t):t?.kind==="master"?null:nativeIdFor(t)
});
function sameNativeEditIdentity(edit) {
const now=nativeEditIdentity(edit.t);
return edit.epoch===now.epoch &&
edit.authority===now.authority &&
edit.channelId===now.channelId;
return stripVM.scalarIdentityMatches(edit,nativeEditIdentity(edit.t));
}
// Only the last gesture target owns the visual fader cap until the
// producer independently reads that SAME target back. Earlier ACKs and
Expand All @@ -1516,13 +1513,12 @@
const key=controlKey(t?.kind==="master"?"masterGain":"faderDb",t);
const pending=liveFaderVisualTargets.get(key);
if(!pending)return null;
if(!sameNativeEditIdentity(pending)){
const result=stripVM.scalarVisualSettlement(pending,actualDb,
nativeEditIdentity(t));
if(result==="STALE"||result==="CONFIRMED"){
liveFaderVisualTargets.delete(key);return null;
}
if(Math.abs(actualDb-pending.value)<=.11){
liveFaderVisualTargets.delete(key);return null;
}
return pending.value;
return result==="WAIT"?pending.value:null;
}
// null means an admitted ChannelId intent is already awaiting its ACK /
// producer readback. Keep ONLY the newest dB target, never drop release.
Expand Down Expand Up @@ -1551,7 +1547,7 @@
}
}
function streamFaderControl(parameter,t,value,final){
if(!liveScalarReady(parameter,t))return false;
if(!Number.isFinite(value)||!liveScalarReady(parameter,t))return false;
const key=controlKey(parameter,t),now=performance.now();
const edit={parameter,t,value,...nativeEditIdentity(t)};
pendingNativeControl.set(key,edit); // coalesce: last writer always wins
Expand Down Expand Up @@ -1645,26 +1641,12 @@
const m4ControlKey=(parameter,channel)=>parameter+":"+channel;
function reconcileM4ControlReadback(next) {
let awaiting=false;
const session=next?.raw?.mixerSession;
for(const [key,p] of pendingM4Controls) {
const revision=p.channel===-1?
next?.raw?.legacyM4?.routingRevision:session?.routeRevision;
if(next.device.epoch!==p.epoch || revision!==p.revision ||
(p.channel!==-1 && session?.authority!=="M4")) {
const result=stripVM.m4ScalarReadbackSettlement(p,next);
if(result==="STALE"){
pendingM4Controls.delete(key);
status("STALE M4 control · device/route changed; restoring readback");
continue;
}
const row=p.channel===-1?null:session?.channels?.[p.channel];
const value=p.channel===-1?
(p.parameter==="masterGain"?session?.main?.db:session?.main?.mute):
p.parameter==="faderDb"?row?.controls?.faderDb:
p.parameter==="pan"?row?.controls?.pan*100:
row?.controls?.[p.parameter];
const matches=typeof p.value==="boolean"?value===p.value:
Number.isFinite(value)&&Math.abs(value-p.value)<=
(p.parameter==="pan"?.8:.11);
if(p.acked && matches)pendingM4Controls.delete(key);
}else if(result==="CONFIRMED")pendingM4Controls.delete(key);
else awaiting=true;
}
return awaiting;
Expand Down Expand Up @@ -3070,17 +3052,14 @@
const item=[...pendingM4Controls].find(([,p])=>p.requestId===ack?.requestId);
if(!item)return; // late, unrelated and superseded ACKs cannot commit
const [key,p]=item;
const accepted=ack.ok===true &&
String(ack.deviceEpoch)===p.epoch &&
String(ack.routingRevision)===p.revision &&
ack.channel===p.channel && ack.parameter===p.parameter;
if(!accepted) {
const verdict=stripVM.m4ScalarAckResult(p,ack);
if(verdict==="REJECTED") {
pendingM4Controls.delete(key);
if(p.parameter==="masterGain")liveFaderVisualTargets.delete("masterGain:main");
else if(p.parameter==="faderDb")
liveFaderVisualTargets.delete("faderDb:"+m4TrackIds[p.channel]);
status("NATIVE M4 REJECTED · "+(ack?.error||"stale control token"));
} else p.acked=true;
} else if(verdict==="ACKED")p.acked=true;
controller.subscribe(); // request later independent producer readback
});
backend.addEventListener("arMixChannelPatchAck",ack=>{
Expand Down
Loading