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
34 changes: 34 additions & 0 deletions tests/approved_device_pin_identity_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,40 @@ test("MV-18 physical device swap cancels output and FX leases even at unchanged
"UI cleanup cannot send native commands, reset FX, or reopen devices");
});

test("MV-19 invalid read-model and malformed device identity cannot mutate hardware UI",()=>{
const bridge=readFileSync("web/approved-native-bridge.js","utf8");
const readbackStart=bridge.indexOf(" function onNativeReadback(next,confirmed) {");
const readbackEnd=bridge.indexOf(" if (connected) {\n controller = protocol.createController",readbackStart);
assert.ok(readbackStart>0&&readbackEnd>readbackStart);
const source=bridge.slice(readbackStart,readbackEnd);
const at=token=>{
const pos=source.indexOf(token);
assert.ok(pos>=0,"MV-19 lost ordered admission step: "+token);
return pos;
};
const selector=at("protocol.selectNativeReadModel(next,m4Verified(next))");
const invalid=at('if(readModel.kind==="INVALID")');
const lease=at("deviceVM.nativeLifecycleLease(next,readModel.kind)");
const noLease=at("if(!lease)");
const fence=at("lastNativeLifecycleLease=lease");
const setup=at("deviceVM.setupReadback(deviceState,next)");
const hardware=at("updateHardwarePanel(next)");
const paint=at("paintExternalReadback(next)");
const wirePaint=at("scope?.syncNativeWireGains?.([])");
assert.ok(selector<invalid&&invalid<lease&&lease<noLease&&
noLease<fence&&fence<wirePaint&&wirePaint<setup&&setup<hardware&&hardware<paint,
"invalid/stale candidates must not change Device Setup, hardware or selector UI");
assert.doesNotMatch(source.slice(0,fence),
/updateHardwarePanel\(next\)|deviceVM\.setupReadback\(deviceState,next\)|syncNativeWireGains\?\.\(\[\]\)/,
"no hardware mutation or drag reset before candidate admission");
const verified=bridge.slice(bridge.indexOf(" const m4Verified="),
bridge.indexOf(" // Live gestures choose the installed PCM authority."));
assert.match(verified,/m4Verified=\(snapshot=hardware\)/);
assert.match(verified,/snapshot\?\.raw\?\.legacyM4/);
assert.doesNotMatch(verified,/const m=legacy\(\)/,
"read-model M4 evidence must not use the prior hardware cache");
});

test("MV-12 approved bridge invalidates transient UI leases, not durable JUCE state",()=>{
const source=readFileSync("web/approved-native-bridge.js","utf8");
const start=source.indexOf(" function expireTransientNativeUi(reason) {");
Expand Down
43 changes: 41 additions & 2 deletions tests/approved_native_m2_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2526,7 +2526,28 @@ test("MV-18 real M4 FX slot lease survives no old device ACK on same-epoch drive
id==="preview"?{disabled:false}:
id==="armixNativeToast"?toast:null,
querySelector:()=>null,addEventListener(){}};
const win={__JUCE__:{backend},ArSonApprovedNativeContract:protocol,
// MV-19 defense-in-depth: force one controller callback with a rejected
// read-model candidate. Such a callback must not paint untrusted hardware
// even if a future controller inadvertently forwards it.
const guardedProtocol={...protocol,
createController(options){
const native=protocol.createController(options);
return {...native,onSnapshot(raw){
if(raw?.device?.captureDevice==="Quarantined ASIO"){
const normalized=protocol.normalizeSnapshot(raw);
assert.ok(normalized,"rejected read-model candidate must be schema-valid");
options.onAccepted(normalized);
return true;
}
return native.onSnapshot(raw);
}};
},
selectNativeReadModel(next,verified){
if(next?.device?.captureDevice==="Quarantined ASIO")
return {kind:"INVALID"};
return protocol.selectNativeReadModel(next,verified);
}};
const win={__JUCE__:{backend},ArSonApprovedNativeContract:guardedProtocol,
ArSonApprovedDeviceViewModel:deviceVM,
ArSonApprovedChannelStripViewModel:stripVM,
ArSonApprovedFxRackViewModel:fxRackVM,
Expand Down Expand Up @@ -2578,7 +2599,25 @@ test("MV-18 real M4 FX slot lease survives no old device ACK on same-epoch drive
assert.equal(bypasses().length,1,"same slot is gated by its unresolved native lease");
const oldTimer=timers.filter(t=>t.ms===5000).at(-1);
assert.ok(oldTimer);
// A different driver using the SAME epoch must expire the old M4 slot lease.
// MV-19: rejected candidate has a different physical identity, but neither
// the active output label nor this legitimate pending M4 FX edit may change.
const acceptedOutput=scope.master.output;
const acceptedChoices=win.__ARMIX_NATIVE_M2__.inputChoices(tracks[4])
.map(x=>x.label).join("|");
const quarantined=clone(installed);
quarantined.device.captureDevice="Quarantined ASIO";
quarantined.device.playbackDevice="Quarantined ASIO";
quarantined.device.inputEndpoints[0].label="Untrusted IN";
publish(quarantined);
assert.equal(scope.master.output,acceptedOutput,
"invalid candidate cannot repaint master hardware output");
assert.equal(win.__ARMIX_NATIVE_M2__.inputChoices(tracks[4])
.map(x=>x.label).join("|"),acceptedChoices,
"invalid candidate cannot install untrusted physical pin choices");
assert.equal(click(),true);
assert.equal(bypasses().length,1,
"invalid candidate cannot release the pending physical FX lease");
// A different VALID driver using the SAME epoch must expire the old slot lease.
const changed=clone(installed);
changed.device.captureDevice="Vendor B ASIO";
changed.device.playbackDevice="Vendor B ASIO";
Expand Down
32 changes: 18 additions & 14 deletions web/approved-native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -1506,8 +1506,11 @@
}
let pendingNativeControl=new Map(),lastNativeControlSent=new Map();
const m4Meters=new Map();
const m4Verified=()=>{
const m=legacy(),d=hardware?.device;
// MV-19: read-model admission must use the candidate native snapshot.
// The installed hardware cache is updated only AFTER this candidate is
// validated, so old accepted M4 evidence cannot admit a new device.
const m4Verified=(snapshot=hardware)=>{
const m=snapshot?.raw?.legacyM4,d=snapshot?.device;
return m4TrackIds.length===10 &&
new Set(m4TrackIds).size===10 &&
m?.active===true && m.routeAccepted===true &&
Expand Down Expand Up @@ -2683,16 +2686,11 @@
"Mixer authority changed · old control gestures discarded");
}
function onNativeReadback(next,confirmed) {
scope?.syncNativeWireGains?.([]); // flush accepted paint after pointer release
// This callback is invoked only by the existing schema-v6 reconciler.
// A correlated Apply ACK waits for a subsequent installed PCM snapshot.
const previousSetup=deviceState;
deviceState=deviceVM.setupReadback(deviceState,next);
if(deviceState!==previousSetup && !deviceState.pending)finishDeviceApplyUi();
updateHardwarePanel(next);
// One schema-v6 read-model selector decides native PCM, retained,
// M4 and offline document authority. Do not revalidate it in the DOM.
const readModel=protocol.selectNativeReadModel(next,m4Verified());
// No Device Setup, hardware panel or strip state may mutate until the
// candidate read-model AND native device identity are admitted below.
// Evaluate M4 against next itself, not previously painted hardware.
const readModel=protocol.selectNativeReadModel(next,m4Verified(next));
const session=next?.raw?.mixerSession;
const offline=next?.raw?.logicalMixer;
if(readModel.kind==="INVALID"){
Expand All @@ -2711,9 +2709,15 @@
confirmed=null;
}
lastNativeLifecycleLease=lease;
// Paint only after the lifecycle fence has expired old device-scoped
// output leases. This releases aria-busy immediately on the same
// authoritative snapshot, even if a new driver reuses its old epoch.
// MV-19: commit all hardware-scoped UI only after the common identity
// fence. Invalid/inconsistent candidates must leave the last accepted
// Device Setup transaction, selectors and physical output untouched.
scope?.syncNativeWireGains?.([]); // flush accepted paint after pointer release
const previousSetup=deviceState;
deviceState=deviceVM.setupReadback(deviceState,next);
if(deviceState!==previousSetup && !deviceState.pending)finishDeviceApplyUi();
updateHardwarePanel(next);
// The MV-18 external-output repaint must stay after the same fence.
paintExternalReadback(next);
appearanceFromNative(next);
settleSourceReadback("CHANNEL_ID",next);
Expand Down
Loading