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
72 changes: 71 additions & 1 deletion tests/approved_native_m2_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,67 @@ function acceptedFixture(){
tap:"POST",gainLinear:1,enabled:true,signalKind:"AUDIO"}];
return s;
}
test("M5 native FX snapshot rejects malformed/duplicate lease tokens without losing accepted state",()=>{
const good=acceptedFixture(),input=good.graph.channels[0].id;
good.graph.channels[0].inserts=[{
id:"native-lease-A",catalogId:"vendor.fx.catalog",name:"Vendor FX",bypassed:false
}];
const sent=[],statuses=[],controller=protocol.createController({
emit:(event,payload)=>sent.push({event,payload}),
onStatus:x=>statuses.push(x)
});
assert.equal(controller.onSnapshot(good),true);
const accepted=controller.state().current;
assert.ok(accepted.admitted);
const mutations=[
row=>{row.graph.channels[0].inserts=[null];},
row=>{row.graph.channels[0].inserts=[{}];},
row=>{row.graph.channels[0].inserts=[{id:"",catalogId:"vendor.fx.catalog"}];},
row=>{row.graph.channels[0].inserts=[{id:"native-lease-A",catalogId:""}];},
row=>{row.graph.channels[0].inserts=[{id:"native-lease-A",catalogId:"vendor.fx.catalog",bypassed:"false"}];},
row=>{row.graph.channels[0].inserts.push({...row.graph.channels[0].inserts[0]});},
row=>{row.graph.channels[1].inserts.push({...row.graph.channels[0].inserts[0]});},
row=>{row.graph.channels[0].inserts=Array.from({length:9},(_,i)=>({
id:"lease-"+i,catalogId:"vendor.fx.catalog"}));}
];
for(const mutate of mutations){
const bad=clone(good);
mutate(bad);
assert.equal(protocol.normalizeSnapshot(bad),null,
"malformed instance lease must not be accepted as native PCM graph");
assert.equal(controller.onSnapshot(bad),false);
assert.equal(controller.state().current,accepted,
"rejected FX snapshot must preserve the latest accepted physical graph");
assert.equal(controller.state().lastError,"INVALID_NATIVE_SNAPSHOT");
assert.equal(controller.state().pending,null);
assert.equal(sent.length,0,"no bogus native intent or subscription");
}
assert.equal(statuses.at(-1).lastError,"INVALID_NATIVE_SNAPSHOT");
assert.equal(protocol.readbackProvesIntent(null,{
operation:"REMOVE_INSERT",targetChannelId:input,payload:{slot:0}
}),false,"invalid snapshot may never prove ACK");

// Malformed unsolicited readback during an edit is not a reason to commit or
// lose the valid pending request; a subsequent real ACK+snapshot may recover.
const edit=controller.intent("SET_FADER",input,{valueDb:-12});
assert.equal(edit.ok,true);
const bad=clone(good);bad.graph.channels[0].inserts=[null];
assert.equal(controller.onSnapshot(bad),false);
assert.equal(controller.state().pending?.requestId,edit.requestId);
assert.equal(controller.state().current,accepted);
assert.equal(controller.onAck({
requestId:edit.requestId,status:"ACCEPTED",
deviceEpoch:good.device.epoch,
graphRevision:good.graph.revision,
rosterRevision:good.graph.rosterRevision,errorCode:"NONE"
}),true);
const after=clone(good);
after.graph.channels[0].controls.faderDb=-12;
assert.equal(controller.onSnapshot(after),true);
assert.equal(controller.state().lastError,"ACCEPTED_READBACK");
assert.equal(controller.state().pending,null);
assert.equal(controller.state().current.graph.channels[0].controls.faderDb,-12);
});
test("M5 rejected FX intents update observable native status without emitting or repainting PCM",()=>{
const s=acceptedFixture();
const ch=s.graph.channels[0];
Expand Down Expand Up @@ -1605,8 +1666,17 @@ test("native FX remove/reorder/transfer requires exact token, ACK and ordered re
c.onAck({requestId:request.requestId,status:'ACCEPTED',errorCode:'NONE',deviceEpoch:t.base.device.epoch,graphRevision:'6',rosterRevision:'8'});
const wrong=clone(t.base);wrong.graph.revision='6';wrong.graph.rosterRevision='8';
wrong.graph.channels[1].inserts.push(clone(wrong.graph.channels[0].inserts[0]));
assert.equal(c.onSnapshot(wrong),false,'name/token copy cannot masquerade as MOVE');
assert.equal(c.onSnapshot(wrong),false,'duplicate live token is invalid native schema');
assert.equal(c.state().lastError,'INVALID_NATIVE_SNAPSHOT');
assert.equal(c.state().pending?.requestId,request.requestId,
'invalid transport snapshot must not consume the accepted native ACK');
const wrongEffect=clone(t.base);
wrongEffect.graph.revision='6';wrongEffect.graph.rosterRevision='8';
wrongEffect.graph.channels[0].inserts.reverse();
assert.equal(c.onSnapshot(wrongEffect),false,
'valid but wrong FX order cannot masquerade as MOVE');
assert.equal(c.state().lastError,'ACK_READBACK_EFFECT_MISMATCH');
assert.equal(c.state().pending,null);
});

test("native vendor editor retention follows current PCM ownership, not inactive M4 slots",()=>{
Expand Down
6 changes: 5 additions & 1 deletion tests/m4_operator_routing.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ test('uint64 identities remain exact strings; malformed ids and stale capability
'NATIVE_WIRE_OPERATION_UNAVAILABLE');
});
test('sidechain is NEVER an audible WIRE edge and cannot claim a missing VST3 bus',()=>{
// Public installed schema uses exact live lease token 'id' plus the
// independent catalog identity. The old instanceId-only fixture was not
// a valid native M2 snapshot and masked malformed-insert admission.
const s=base();s.graph.channels[0].inserts.push({
instanceId:'native-vst-1',name:'Compressor',bypassed:false});
id:'native-vst-1',catalogId:'vendor.compressor',
name:'Compressor',bypassed:false});
let p=planM4OperatorIntent(accepted(s),{kind:'SIDECHAIN',
sourceId:ids.kick,destinationId:ids.v,pluginInstanceId:'native-vst-1'});
assert.equal(p.error,'VST3_AUX_DETECTOR_BUS_NOT_NEGOTIATED');
Expand Down
20 changes: 20 additions & 0 deletions web/approved-native-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@
Number.isFinite(ch.controls.pan) && isBool(ch.controls.mute) &&
isBool(ch.controls.solo) && Array.isArray(ch.inserts) &&
Array.isArray(ch.sends));
// Native insert instance tokens are live FX lease identities, not a
// browser slot ordinal or catalog name. A malformed slot/duplicate token
// must never enter the accepted renderer: MOVE/REMOVE and vendor editors
// dereference these entries after native ACK.
const validInsert = fx => fields(fx,["id","catalogId"]) &&
typeof fx.id === "string" && fx.id.length > 0 &&
typeof fx.catalogId === "string" && fx.catalogId.length > 0 &&
(fx.name === undefined || typeof fx.name === "string") &&
(fx.bypassed === undefined || isBool(fx.bypassed));
if (hasAcceptedGraph) {
const tokens=[];
for (const ch of g.channels) {
if (ch.inserts.length > 8 || !ch.inserts.every(validInsert)) return null;
for (const fx of ch.inserts) tokens.push(fx.id);
}
if (!unique(tokens)) return null;
}
const retained = g.bindingState === "NEEDS_REMAP";
if (retained && (!hasAcceptedGraph || caps.callbackOwnsChannelIds ||
caps.supportedOps.length !== 0 || d.outputArmed ||
Expand All @@ -111,6 +128,9 @@
// control/route actually reached the accepted native graph. No invented UI
// updates and no optimistic fader/edge commits.
function readbackProvesIntent(next, pending) {
// Also exposed as a pure test/helper API. A rejected/unadmitted native
// snapshot cannot be used to prove an FX or WIRE command.
if (!next?.admitted || !pending || !object(pending.payload)) return false;
const {operation,targetChannelId,payload} = pending;
const ch = next.graph.channels.find(c=>c.id===targetChannelId);
if (!ch) return false;
Expand Down
Loading