diff --git a/integration/M4_OPERATOR_ROUTING_HANDOFF.md b/integration/M4_OPERATOR_ROUTING_HANDOFF.md new file mode 100644 index 000000000..33a6d887a --- /dev/null +++ b/integration/M4_OPERATOR_ROUTING_HANDOFF.md @@ -0,0 +1,36 @@ +# M4 integration: operator routing admission, native DSP handoff + +**One product:** existing approved `/preview/`, existing M2 native v8 protocol, ONE JUCE callback. Do not create GUI/PCM/graph alternatives. + +## What is executable now (integration control plane) + +`integration/console-v6/m4-operator-routing.mjs` consumes the **already normalized/accepted** `web/approved-native-contract.js` snapshot, never Pages mock data. `planM4OperatorIntent(accepted, gesture)` can emit the existing native `APPLY_WIRE_TRANSACTION` for: +- `ROUTE_ONLY`: replace the source's exclusive primary OUT with a Group or MAIN, after cycle and parallel dry-path checks; +- `SEND_POST`: add a unity-gain POST send, including a wet-only-verified FX return, after duplicate and double-dry checks. + +These are *candidate intents*, not applied changes. GUI/controller is still responsible for the same device epoch, graph revision, roster revision, request ID, native ACK and **later independently accepted readback**. In particular, do not paint a cable after the intent returns `ok:true`. No new source of truth is introduced. + +This is not yet wired to the approved visual renderer: GUI owner must add minimal one/two-click gestures **only after** the owner accepts the intent API; retain all approved pixels and controls. Current M3 #402 remains the authoritative native adapter. + +## Explicit fail-closed boundaries + +- `SEND_PRE`: ENGINE #266's v8 WIRE decoder currently permits only `POST_FADER`, although older native DSP accepts PRE. Requires decoder + exact tap readback proof. +- `SET_SEND_GAIN`: existing `readbackProvesIntent` checks WIRE presence, not the exact accepted gain. Requires native gain authority and ACK/readback proof. +- `GROUP_SELECTED` and `NEW_FX_RETURN`: engine core has graph support, but public M2 controller must add exact structural accepted-readback tests before these are operator actions. +- `SIDECHAIN`: must use a separate detector-only VST3 AUX input bus, never an audible WIRE connection. `src/VstBusLayout.h` currently disables all auxiliary input buses; there is no verified detector-only edge or native readback. No sidechain intent may be emitted before the ENGINE owner supplies real bus layout negotiation, detector buffer processing, precise latency handling and accepted ACK/readback. +- `PDC`: unknown latency fails closed; nonzero latency requires native graph compensation. Low-latency live-monitor mode must not silently acquire high buffered latency. + +## ENGINE owner (#266) handoff + +1. One prepared graph with explicit primary OUT, separate parallel audible send and *detector-only* sidechain edge; no feedback across either dependency graph. +2. VST3 main stereo + optional auxiliary sidechain bus negotiation; no allocations/locks/plugin discovery within audio callback; genuine plugin/input bus ownership, enable/disable and readback. +3. Graph-aware alignment across mixed dry/wet, send taps and detector path, plus explicit tradeoff of LIVE_LOW_LATENCY vs STUDIO_COMPENSATED mode. +4. Native capability flags and exact accepted snapshot effects: PRE/POST, gain/tap, bus creation, plugin sidechain assignment, PDC and revisioned ACK. Until readback proves a new op, do not advertise it in `supportedOps`. + +## GUI owner handoff + +Reuse `/preview/`. Map operator shortcuts (Group Selected, New FX Send, Route Only, External Sidechain selector) to accepted native intents *after* their capabilities are installed. No changed layout, fake meter, alternate GUI or JS PCM. + +## Acceptance and release + +The M4 pure routing contract tests run in existing cheap `scripts/check_console_puzzle.mjs` before heavy Windows CI. They are source/control correctness only, not hardware FAT or real sidechain DSP. M3 #402/#266, Windows exact-head CTest, screenshot parity and physical #15 remain separate blockers. Never mark M4 complete or product LIVE based solely on these tests. diff --git a/integration/console-v6/m4-operator-routing.mjs b/integration/console-v6/m4-operator-routing.mjs new file mode 100644 index 000000000..31c17db9e --- /dev/null +++ b/integration/console-v6/m4-operator-routing.mjs @@ -0,0 +1,220 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// M4 operator intent ADMISSION for the ONE approved /preview/ + JUCE product. +// CONTROL PLANE ONLY: no audio buffers, second graph authority, plugin bus +// allocation, optimistic mutation, callback, or extra renderer. +// Accepts a previously normalized native v8/schemaVersion=6 readback and +// returns a controller.intent() request only when the existing native ABI +// can prove the requested result after ACK + matching accepted snapshot. +const MAX64=(1n<<64n)-1n; +export const M4_OPERATOR_ABI=Object.freeze({schemaVersion:6, + nativeWireOperation:'APPLY_WIRE_TRANSACTION',supportedWireTap:'POST_FADER'}); + +const fail=(error,detail)=>({ok:false,error,detail}); +const id=value=>{ + if(typeof value!=='string'||!/^[1-9][0-9]*$/.test(value))return false; + try{return BigInt(value)<=MAX64;}catch{return false;} +}; +const object=value=>value!==null&&typeof value==='object'&&!Array.isArray(value); +const safeGain=value=>typeof value==='number'&&Number.isFinite(value)&&value>=0&&value<=4; +function admittedView(accepted){ + // A Pages demo or raw JSON is NOT a native-accepted graph. The caller must + // pass normalizeSnapshot() output from the existing M2 controller. + if(!accepted||accepted.admitted!==true||!object(accepted.device)|| + !object(accepted.graph)||!object(accepted.graph.capabilities)|| + accepted.graph.capabilities.callbackOwnsChannelIds!==true || + !id(accepted.device.epoch)||!id(accepted.graph.revision)|| + !id(accepted.graph.rosterRevision)|| + !Array.isArray(accepted.graph.channels)|| + !Array.isArray(accepted.graph.edges)) + return fail('NATIVE_CHANNELID_NOT_ADMITTED'); + if(!Array.isArray(accepted.graph.capabilities.supportedOps)|| + !accepted.graph.capabilities.supportedOps.includes(M4_OPERATOR_ABI.nativeWireOperation)) + return fail('NATIVE_WIRE_OPERATION_UNAVAILABLE'); + const channels=new Map(); + let main=null; + for(const ch of accepted.graph.channels){ + if(!object(ch)||!id(ch.id)||channels.has(ch.id)|| + !['INPUT','GROUP','FX_RETURN','MAIN','MONITOR'].includes(ch.role)) + return fail('INVALID_ACCEPTED_CHANNELS'); + channels.set(ch.id,ch); + if(ch.role==='MAIN'){ + if(main!==null)return fail('MULTIPLE_NATIVE_MASTERS'); + main=ch.id; + } + } + if(!main||accepted.graph.mainChannelId!==main) + return fail('MISSING_NATIVE_MASTER'); + const edges=[],edgeIds=new Set(),arcs=new Map([...channels.keys()].map(x=>[x,[]])); + for(const e of accepted.graph.edges){ + if(!object(e)||!id(e.edgeId)||edgeIds.has(e.edgeId)|| + !id(e.from)||!id(e.to)||!channels.has(e.from)||!channels.has(e.to)|| + e.from===e.to||e.from===main||e.signalKind!=='AUDIO'|| + e.enabled!==true||typeof e.primaryOutput!=='boolean'|| + !safeGain(e.gainLinear)) + return fail('INVALID_NATIVE_AUDIO_EDGE'); + edgeIds.add(e.edgeId);edges.push(e);arcs.get(e.from).push(e.to); + } + const path=(start,target,graph=arcs)=>{ + const visited=new Set(),stack=[start]; + while(stack.length){ + const cur=stack.pop(); + if(cur===target)return true; + if(visited.has(cur))continue; + visited.add(cur); + for(const to of graph.get(cur)||[])stack.push(to); + } + return false; + }; + // Do not use a rejected/feedback graph as a source of proposed changes. + for(const [src,targets] of arcs.entries()) + if(targets.some(to=>path(to,src)))return fail('ACCEPTED_GRAPH_CYCLE'); + return {ok:true,channels,main,edges,arcs,path,accepted}; +} +function sendsToMain(view,source,candidate){ + const next=new Map([...view.channels.keys()].map(x=>[x,[]])); + for(const e of candidate){ + // FX return explicitly verified as 100% wet does not count as + // second *dry* path. Unverified returns are conservatively counted. + const dest=view.channels.get(e.to); + if(dest?.role==='FX_RETURN'&&dest.wetOnly===true)continue; + next.get(e.from).push(e.to); + } + const count=(node,seen)=>{ + if(node===view.main)return 1; + if(seen.has(node))return 2; + const scope=new Set(seen);scope.add(node); + let n=0; + for(const to of next.get(node)||[]){ + n+=count(to,scope);if(n>1)return 2; + } + return n; + }; + return count(source,new Set()); +} +function planWire(view,request){ + const {kind,sourceId,destinationId}=request; + if(!id(sourceId)||!view.channels.has(sourceId)|| + !id(destinationId)||!view.channels.has(destinationId)) + return fail('UNKNOWN_NATIVE_CHANNELID'); + if(sourceId===destinationId)return fail('SELF_ROUTE_FORBIDDEN'); + const source=view.channels.get(sourceId),destination=view.channels.get(destinationId); + if(['MAIN','MONITOR'].includes(source.role))return fail('OUTPUT_BUS_CANNOT_SOURCE_SEND'); + // A dependency cycle is the strongest/most specific routing fault. + // Report it before the more general INPUT destination role rejection. + if(view.path(destinationId,sourceId))return fail('ROUTING_FEEDBACK_CYCLE'); + if(destination.role==='INPUT')return fail('INPUT_NOT_A_ROUTING_DESTINATION'); + const same=view.edges.filter(e=>e.from===sourceId&&e.to===destinationId); + const currentPrimary=view.edges.filter(e=>e.from===sourceId&&e.primaryOutput); + if(currentPrimary.length>1)return fail('MULTIPLE_ACCEPTED_PRIMARY_OUTPUTS'); + if(kind==='ROUTE_ONLY'){ + if(destination.role!=='GROUP'&&destination.role!=='MAIN') + return fail('EXCLUSIVE_ROUTE_REQUIRES_GROUP_OR_MAIN'); + if(currentPrimary.length===1&¤tPrimary[0].to===destinationId) + return fail('PRIMARY_ALREADY_AT_DESTINATION'); + if(same.length)return fail('DUPLICATE_NATIVE_ROUTE'); + const simulated=view.edges.filter(e=> + !(e.from===sourceId&&e.primaryOutput)); + simulated.push({from:sourceId,to:destinationId,primaryOutput:true}); + if(sendsToMain(view,sourceId,simulated)>1) + return fail('EXCLUSIVE_ROUTE_RETAINS_PARALLEL_DRY_PATH', + 'Native Route Only changes the primary OUT; existing parallel sends remain.'); + return {ok:true,intent:{operation:M4_OPERATOR_ABI.nativeWireOperation, + targetChannelId:sourceId,payload:{changes:[{ + op:'ROUTE_ONLY',from:sourceId,to:destinationId, + tap:'POST_FADER',gainLinear:1 + }]}},fence:fence(view)}; + } + if(kind!=='SEND_POST')return fail('UNKNOWN_ROUTING_GESTURE'); + if(destination.role==='MAIN') + return fail('MAIN_REQUIRES_PRIMARY_OUT','Use Route Only to MAIN.'); + if(same.length)return fail('DUPLICATE_NATIVE_ROUTE'); + if(destination.role==='FX_RETURN'&&destination.wetOnly!==true) + return fail('FX_RETURN_WET_ONLY_NOT_VERIFIED', + 'Return must be proven 100% wet by native accepted readback.'); + // Non-unity gain is intentionally blocked: current v8 wire + // readbackProvesIntent only confirms existence, NOT accepted send gain. + if(request.gainDb!==undefined&&request.gainDb!==0) + return fail('SEND_GAIN_ACK_READBACK_NOT_AVAILABLE'); + const simulated=[...view.edges,{from:sourceId,to:destinationId,primaryOutput:false}]; + if(destination.role!=='FX_RETURN'&&sendsToMain(view,sourceId,simulated)>1) + return fail('DOUBLE_DRY_TO_MAIN', + 'Choose Route Only for subgroup instead of mixing direct MAIN twice.'); + return {ok:true,intent:{operation:M4_OPERATOR_ABI.nativeWireOperation, + targetChannelId:sourceId,payload:{changes:[{ + op:'CONNECT',from:sourceId,to:destinationId, + tap:'POST_FADER',gainLinear:1 + }]}},fence:fence(view)}; +} +const fence=view=>Object.freeze({ + deviceEpoch:view.accepted.device.epoch, + graphRevision:view.accepted.graph.revision, + rosterRevision:view.accepted.graph.rosterRevision +}); +function sidechainGate(view,request){ + if(!id(request.sourceId)||!id(request.destinationId)|| + !view.channels.has(request.sourceId)||!view.channels.has(request.destinationId)) + return fail('UNKNOWN_NATIVE_CHANNELID'); + if(request.sourceId===request.destinationId|| + view.path(request.destinationId,request.sourceId)) + return fail('SIDECHAIN_DEPENDENCY_CYCLE'); + const dest=view.channels.get(request.destinationId); + if(dest.role==='MAIN'||dest.role==='MONITOR') + return fail('SIDECHAIN_TARGET_NOT_AN_INSERT_CHANNEL'); + if(typeof request.pluginInstanceId!=='string'|| + !request.pluginInstanceId.trim()|| + !Array.isArray(dest.inserts)|| + !dest.inserts.some(fx=>fx.instanceId===request.pluginInstanceId|| + fx.id===request.pluginInstanceId)) + return fail('VST3_INSERT_LEASE_NOT_VERIFIED'); + const aux=request.nativeAuxInput; + if(!object(aux)||aux.pluginInstanceId!==request.pluginInstanceId|| + !Number.isInteger(aux.busIndex)||aux.busIndex<1|| + ![1,2].includes(aux.channels)||aux.enabled!==true|| + aux.detectorOnly!==true) + return fail('VST3_AUX_DETECTOR_BUS_NOT_NEGOTIATED'); + const caps=view.accepted.graph.capabilities; + if(!caps.supportedOps.includes('CONNECT_PLUGIN_SIDECHAIN')|| + caps.nativeSidechainBusReady!==true) + return fail('NATIVE_SIDECHAIN_CAPABILITY_UNAVAILABLE'); + const pdc=assessM4Pdc({latencySamples:aux.latencySamples, + compensated:aux.compensated,monitorMode:request.monitorMode}); + if(!pdc.ok)return pdc; + // Even if future metadata appears, existing M2 controller does not + // prove a detector-only route in readbackProvesIntent(). Never emit an + // unprovable accepted sidechain or covert audible send. + return fail('SIDECHAIN_ACK_READBACK_UNIMPLEMENTED', + 'Require native detector-only edge + plugin-bus readback and exact ACK proof.'); +} +export function assessM4Pdc({latencySamples,compensated,monitorMode}={}){ + if(!Number.isSafeInteger(latencySamples)||latencySamples<0) + return fail('PLUGIN_LATENCY_UNVERIFIED'); + if(monitorMode!==undefined&&!['LIVE_LOW_LATENCY','STUDIO_COMPENSATED'].includes(monitorMode)) + return fail('UNKNOWN_MONITOR_LATENCY_MODE'); + if(latencySamples>0&&compensated!==true) + return fail('NATIVE_GRAPH_PDC_UNAVAILABLE'); + if(latencySamples>0&&monitorMode==='LIVE_LOW_LATENCY') + return fail('LIVE_MONITOR_LATENCY_POLICY_CONFLICT'); + return {ok:true,latencySamples}; +} +/** + * Produces a candidate native controller.intent operation ONLY. + * No message is sent by this function; GUI/Integrator must dispatch with + * existing M2 controller and wait for ACK + same-revision native readback. + */ +export function planM4OperatorIntent(accepted,request){ + const view=admittedView(accepted); + if(!view.ok)return view; + if(!object(request)||typeof request.kind!=='string') + return fail('INVALID_OPERATOR_REQUEST'); + switch(request.kind){ + case 'ROUTE_ONLY': + case 'SEND_POST':return planWire(view,request); + case 'SEND_PRE':return fail('NATIVE_PRE_FADER_WIRE_NOT_ADMITTED', + 'ENGINE #266 WIRE decoder currently accepts POST_FADER only.'); + case 'SET_SEND_GAIN':return fail('SEND_GAIN_ACK_READBACK_NOT_AVAILABLE'); + case 'GROUP_SELECTED':return fail('GROUP_CREATE_ACK_READBACK_UNIMPLEMENTED'); + case 'NEW_FX_RETURN':return fail('FX_RETURN_CREATE_ACK_READBACK_UNIMPLEMENTED'); + case 'SIDECHAIN':return sidechainGate(view,request); + default:return fail('UNKNOWN_OPERATOR_GESTURE'); + } +} diff --git a/scripts/check_console_puzzle.mjs b/scripts/check_console_puzzle.mjs index 03db0e082..f8a4627ad 100644 --- a/scripts/check_console_puzzle.mjs +++ b/scripts/check_console_puzzle.mjs @@ -14,7 +14,7 @@ export const PATHS=Object.freeze({ engine:'src/LiveAudioEngine.h', nativeG0:'src/ApprovedConsoleNativeTransportV6.h', nativeV8:'src/ConsoleLiveBridgeV6.h', - projection:'src/ApprovedNativeV8Projection.h', + projection:'integration/ApprovedNativeV8Projection.h', renderOwner:'engine/core/NativeRenderAuthority.h', gui:'web/approved-native-bridge.js', protocol:'web/approved-native-contract.js', @@ -112,7 +112,8 @@ export function inspectMilestoneA(s) { async function cli() { const release=process.argv.includes('--release'); execFileSync(process.execPath,['--test','tests/console_v6_puzzle_seam_test.mjs', - 'tests/milestone_a_native_contract_test.mjs'],{stdio:'inherit'}); + 'tests/milestone_a_native_contract_test.mjs', + 'tests/m4_operator_routing.test.mjs'],{stdio:'inherit'}); const report=inspectMilestoneA(collectSources()); const selected=release?[...report.baseline,...report.integration]:report.baseline; for(const x of selected) diff --git a/tests/m4_operator_routing.test.mjs b/tests/m4_operator_routing.test.mjs new file mode 100644 index 000000000..e6fc7d5e0 --- /dev/null +++ b/tests/m4_operator_routing.test.mjs @@ -0,0 +1,263 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// M4 acceptance: one approved native graph, no fake PCM/sidechain/PDC. +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {readFileSync} from 'node:fs'; +import {createRequire} from 'node:module'; +import {planM4OperatorIntent,assessM4Pdc,M4_OPERATOR_ABI} from + '../integration/console-v6/m4-operator-routing.mjs'; +const require=createRequire(import.meta.url); +const {normalizeSnapshot,createController}=require('../web/approved-native-contract.js'); +const clone=x=>structuredClone(x); +const g0=JSON.parse(readFileSync('integration/console-v6/fixtures.json','utf8')).g0; +const ids={v:'9007199254740993',kick:'9007199254740994', + group:'100',wet:'101',main:'18446744073709551615'}; +function base(){ + const s=clone(g0); + s.graph.revision='3';s.graph.rosterRevision='2'; + s.graph.mainChannelId=ids.main; + s.graph.capabilities.callbackOwnsChannelIds=true; + s.graph.capabilities.supportedOps=['APPLY_WIRE_TRANSACTION']; + s.graph.capabilities.groups=true;s.graph.capabilities.fxReturns=true; + const channel=(id,role,out,extra={})=>({ + id,role,name:role+' '+id,processingFormat:'STEREO', + ...(out?{primaryOutId:out}:{}), + controls:{faderDb:0,pan:0,mute:false,solo:false}, + inserts:[],sends:[],...extra + }); + s.graph.channels=[ + channel(ids.v,'INPUT',ids.main), + channel(ids.kick,'INPUT',ids.main), + channel(ids.group,'GROUP',ids.main), + channel(ids.wet,'FX_RETURN',ids.main,{wetOnly:true}), + channel(ids.main,'MAIN') + ]; + s.graph.destinations=s.graph.channels.slice(2).map(x=>({id:x.id})); + const edge=(edgeId,from,to,primaryOutput=true)=>({ + edgeId,from,to,primaryOutput,tap:'POST_FADER',gainLinear:1, + enabled:true,signalKind:'AUDIO' + }); + s.graph.edges=[ + edge('1',ids.v,ids.main),edge('2',ids.kick,ids.main), + edge('3',ids.group,ids.main),edge('4',ids.wet,ids.main) + ]; + return s; +} +const accepted=(raw=base())=>{ + const a=normalizeSnapshot(raw); + assert.ok(a?.admitted,'fixture must pass real public M2 native contract'); + return a; +}; +test('G0/no callback and raw browser graphs never create native intents',()=>{ + assert.equal(planM4OperatorIntent(normalizeSnapshot(g0), + {kind:'ROUTE_ONLY',sourceId:ids.v,destinationId:ids.group}).error, + 'NATIVE_CHANNELID_NOT_ADMITTED'); + assert.equal(planM4OperatorIntent(base(), + {kind:'ROUTE_ONLY',sourceId:ids.v,destinationId:ids.group}).ok,false); +}); +test('one operator Route Only emits exact native wire operation and revision fence',()=>{ + const snapshot=accepted(),before=clone(snapshot.raw); + const planned=planM4OperatorIntent(snapshot,{ + kind:'ROUTE_ONLY',sourceId:ids.v,destinationId:ids.group}); + assert.equal(planned.ok,true); + assert.deepEqual(planned.intent,{ + operation:'APPLY_WIRE_TRANSACTION',targetChannelId:ids.v, + payload:{changes:[{op:'ROUTE_ONLY',from:ids.v,to:ids.group, + tap:'POST_FADER',gainLinear:1}]} + }); + assert.deepEqual(planned.fence,{deviceEpoch:'69',graphRevision:'3',rosterRevision:'2'}); + assert.deepEqual(snapshot.raw,before,'planner must never write accepted graph'); + assert.equal(M4_OPERATOR_ABI.schemaVersion,6); +}); +test('keep-main post send to verified wet FX Return is allowed, no dry path removal',()=>{ + const snapshot=accepted(); + const p=planM4OperatorIntent(snapshot,{kind:'SEND_POST', + sourceId:ids.v,destinationId:ids.wet,gainDb:0}); + assert.equal(p.ok,true); + assert.equal(p.intent.payload.changes[0].op,'CONNECT'); + assert.equal(p.intent.payload.changes[0].tap,'POST_FADER'); + assert.equal(snapshot.graph.channels[0].primaryOutId,ids.main, + 'dry MAIN remains untouched; wet send must be truly wet-only'); +}); +test('subgroup parallel send is blocked before double-dry, route only is advised',()=>{ + const p=planM4OperatorIntent(accepted(),{kind:'SEND_POST', + sourceId:ids.v,destinationId:ids.group}); + assert.equal(p.ok,false);assert.equal(p.error,'DOUBLE_DRY_TO_MAIN'); +}); +test('route only preserves parallel wet send but replaces primary, never both dry',()=>{ + const s=base();s.graph.edges.push({edgeId:'5',from:ids.v,to:ids.wet, + tap:'POST_FADER',gainLinear:.5,primaryOutput:false,enabled:true,signalKind:'AUDIO'}); + assert.equal(planM4OperatorIntent(accepted(s),{kind:'ROUTE_ONLY', + sourceId:ids.v,destinationId:ids.group}).ok,true); +}); +test('route only refuses existing parallel dry path to MAIN',()=>{ + const s=base();s.graph.edges.push({edgeId:'6',from:ids.v,to:ids.group, + tap:'POST_FADER',gainLinear:.5,primaryOutput:false,enabled:true,signalKind:'AUDIO'}); + const p=planM4OperatorIntent(accepted(s),{kind:'ROUTE_ONLY', + sourceId:ids.v,destinationId:ids.main}); + assert.equal(p.ok,false); + assert.equal(p.error,'PRIMARY_ALREADY_AT_DESTINATION'); + // Now route to a second group while parallel dry path remains. + s.graph.channels.push({id:'102',role:'GROUP',name:'BUS 2', + processingFormat:'STEREO',primaryOutId:ids.main, + controls:{faderDb:0,pan:0,mute:false,solo:false},inserts:[],sends:[]}); + s.graph.destinations.push({id:'102'}); + s.graph.edges.push({edgeId:'7',from:'102',to:ids.main, + tap:'POST_FADER',gainLinear:1,primaryOutput:true,enabled:true,signalKind:'AUDIO'}); + const q=planM4OperatorIntent(accepted(s),{kind:'ROUTE_ONLY', + sourceId:ids.v,destinationId:'102'}); + assert.equal(q.error,'EXCLUSIVE_ROUTE_RETAINS_PARALLEL_DRY_PATH'); +}); +test('accepted feedback path and self-send cannot be planned',()=>{ + const s=base(); + // Making group -> vocal also creates a cycle only if vocal -> group. First + // change source to group, then target vocal which is already upstream. + s.graph.edges[0]={...s.graph.edges[0],to:ids.group}; + s.graph.channels[0].primaryOutId=ids.group; + assert.equal(planM4OperatorIntent(accepted(s),{kind:'SEND_POST', + sourceId:ids.group,destinationId:ids.v}).error,'ROUTING_FEEDBACK_CYCLE'); + assert.equal(planM4OperatorIntent(accepted(),{kind:'SEND_POST', + sourceId:ids.v,destinationId:ids.v}).error,'SELF_ROUTE_FORBIDDEN'); +}); +test('duplicate path and prohibited output-to-input routing are rejected',()=>{ + const s=base(); + s.graph.edges.push({edgeId:'8',from:ids.v,to:ids.wet, + tap:'POST_FADER',gainLinear:1,primaryOutput:false,enabled:true,signalKind:'AUDIO'}); + assert.equal(planM4OperatorIntent(accepted(s),{kind:'SEND_POST', + sourceId:ids.v,destinationId:ids.wet}).error,'DUPLICATE_NATIVE_ROUTE'); + assert.equal(planM4OperatorIntent(accepted(),{kind:'SEND_POST', + sourceId:ids.main,destinationId:ids.group}).error,'OUTPUT_BUS_CANNOT_SOURCE_SEND'); + assert.equal(planM4OperatorIntent(accepted(),{kind:'SEND_POST', + sourceId:ids.group,destinationId:ids.kick}).error, + 'INPUT_NOT_A_ROUTING_DESTINATION'); +}); +test('nonverified FX wet-only routing refuses double-dry risk',()=>{ + const s=base();delete s.graph.channels[3].wetOnly; + assert.equal(planM4OperatorIntent(accepted(s),{kind:'SEND_POST', + sourceId:ids.v,destinationId:ids.wet}).error,'FX_RETURN_WET_ONLY_NOT_VERIFIED'); +}); +test('send level/ PRE send/ structural bus creation never fake accepted effects',()=>{ + const current=accepted(); + const requests=[ + ['SEND_PRE','NATIVE_PRE_FADER_WIRE_NOT_ADMITTED'], + ['SET_SEND_GAIN','SEND_GAIN_ACK_READBACK_NOT_AVAILABLE'], + ['GROUP_SELECTED','GROUP_CREATE_ACK_READBACK_UNIMPLEMENTED'], + ['NEW_FX_RETURN','FX_RETURN_CREATE_ACK_READBACK_UNIMPLEMENTED']]; + for(const [kind,error] of requests){ + const p=planM4OperatorIntent(current,{kind,sourceId:ids.v, + destinationId:ids.group}); + assert.equal(p.ok,false);assert.equal(p.error,error);assert.equal(p.intent,undefined); + } + assert.equal(planM4OperatorIntent(current,{kind:'SEND_POST', + sourceId:ids.v,destinationId:ids.wet,gainDb:-18}).error, + 'SEND_GAIN_ACK_READBACK_NOT_AVAILABLE'); +}); +test('uint64 identities remain exact strings; malformed ids and stale capability fail',()=>{ + const current=accepted(); + for(const bad of ['01','18446744073709551616',1,9007199254740993,'0']){ + assert.equal(planM4OperatorIntent(current,{kind:'ROUTE_ONLY', + sourceId:bad,destinationId:ids.group}).ok,false); + } + const s=base();s.graph.capabilities.supportedOps=[]; + assert.equal(planM4OperatorIntent(accepted(s),{kind:'ROUTE_ONLY', + sourceId:ids.v,destinationId:ids.group}).error, + 'NATIVE_WIRE_OPERATION_UNAVAILABLE'); +}); +test('sidechain is NEVER an audible WIRE edge and cannot claim a missing VST3 bus',()=>{ + const s=base();s.graph.channels[0].inserts.push({ + instanceId:'native-vst-1',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'); + assert.equal(p.intent,undefined); + s.graph.capabilities.supportedOps.push('CONNECT_PLUGIN_SIDECHAIN'); + s.graph.capabilities.nativeSidechainBusReady=true; + p=planM4OperatorIntent(accepted(s),{kind:'SIDECHAIN', + sourceId:ids.kick,destinationId:ids.v,pluginInstanceId:'native-vst-1', + nativeAuxInput:{pluginInstanceId:'native-vst-1',busIndex:1, + channels:2,enabled:true,detectorOnly:true,latencySamples:0,compensated:true}}); + assert.equal(p.error,'SIDECHAIN_ACK_READBACK_UNIMPLEMENTED'); + assert.equal(p.intent,undefined,'unproven detector-only route is never dispatched'); +}); +test('sidechain feedback dependency fails independently of audible double-dry',()=>{ + const s=base();s.graph.edges[0]={...s.graph.edges[0],to:ids.group}; + s.graph.channels[0].primaryOutId=ids.group; + const p=planM4OperatorIntent(accepted(s),{kind:'SIDECHAIN', + sourceId:ids.group,destinationId:ids.v,pluginInstanceId:'x'}); + assert.equal(p.error,'SIDECHAIN_DEPENDENCY_CYCLE'); +}); +test('PDC policy blocks unknown and unaligned latency, preserves live monitor',()=>{ + assert.equal(assessM4Pdc({}).error,'PLUGIN_LATENCY_UNVERIFIED'); + assert.equal(assessM4Pdc({latencySamples:-1}).ok,false); + assert.equal(assessM4Pdc({latencySamples:128,compensated:false}).error, + 'NATIVE_GRAPH_PDC_UNAVAILABLE'); + assert.equal(assessM4Pdc({latencySamples:128,compensated:true, + monitorMode:'LIVE_LOW_LATENCY'}).error, + 'LIVE_MONITOR_LATENCY_POLICY_CONFLICT'); + assert.deepEqual(assessM4Pdc({latencySamples:128,compensated:true, + monitorMode:'STUDIO_COMPENSATED'}),{ok:true,latencySamples:128}); +}); +test('no version of plan can update browser acceptance without ACK + readback',()=>{ + const current=accepted(),before=JSON.stringify(current.raw); + const p=planM4OperatorIntent(current,{kind:'ROUTE_ONLY', + sourceId:ids.v,destinationId:ids.group}); + assert.equal(p.ok,true); + assert.equal(Object.hasOwn(p,'acceptedGraph'),false); + assert.equal(Object.hasOwn(p,'productionCallbackLive'),false); + assert.equal(JSON.stringify(current.raw),before); +}); + +test('Route Only ACK never approves new GROUP cable with old MAIN double-dry',()=>{ + const raw=base(),snapshot=accepted(raw); + const plan=planM4OperatorIntent(snapshot,{kind:'ROUTE_ONLY', + sourceId:ids.v,destinationId:ids.group}); + assert.ok(plan.ok); + const controller=createController({emit:()=>{}}); + assert.equal(controller.onSnapshot(raw),true); + const req=controller.intent(plan.intent.operation,plan.intent.targetChannelId, + plan.intent.payload); + assert.equal(req.ok,true); + controller.onAck({requestId:req.requestId,status:'ACCEPTED',errorCode:'NONE', + deviceEpoch:'69',graphRevision:'4',rosterRevision:'2'}); + const lied=clone(raw);lied.graph.revision='4'; + lied.graph.channels[0].primaryOutId=ids.group; + lied.graph.edges.push({edgeId:'9',from:ids.v,to:ids.group, + primaryOutput:true,tap:'POST_FADER',gainLinear:1,enabled:true,signalKind:'AUDIO'}); + assert.equal(controller.onSnapshot(lied),false,'old MAIN still audible; reject'); + assert.equal(controller.state().lastError,'ACK_READBACK_EFFECT_MISMATCH'); + assert.equal(controller.state().current.graph.revision,'3'); + + const validController=createController({emit:()=>{}}); + validController.onSnapshot(raw); + const good=validController.intent(plan.intent.operation,plan.intent.targetChannelId, + plan.intent.payload); + validController.onAck({requestId:good.requestId,status:'ACCEPTED',errorCode:'NONE', + deviceEpoch:'69',graphRevision:'4',rosterRevision:'2'}); + const actual=clone(raw);actual.graph.revision='4'; + actual.graph.channels[0].primaryOutId=ids.group; + actual.graph.edges[0].to=ids.group; + assert.equal(validController.onSnapshot(actual),true); + assert.equal(validController.state().current.graph.channels[0].primaryOutId,ids.group); +}); + +test('POST send ACK requires actual accepted gain and tap, not cable existence',()=>{ + const raw=base(),snapshot=accepted(raw); + const plan=planM4OperatorIntent(snapshot,{kind:'SEND_POST', + sourceId:ids.v,destinationId:ids.wet,gainDb:0}); + assert.ok(plan.ok); + const check=(gain,tap)=>{ + const c=createController({emit:()=>{}}); + c.onSnapshot(raw); + const req=c.intent(plan.intent.operation,plan.intent.targetChannelId, + plan.intent.payload); + c.onAck({requestId:req.requestId,status:'ACCEPTED',errorCode:'NONE', + deviceEpoch:'69',graphRevision:'4',rosterRevision:'2'}); + const next=clone(raw);next.graph.revision='4'; + next.graph.edges.push({edgeId:'90',from:ids.v,to:ids.wet, + primaryOutput:false,tap,gainLinear:gain,enabled:true,signalKind:'AUDIO'}); + return {pass:c.onSnapshot(next),error:c.state().lastError}; + }; + assert.equal(check(0.5,'POST_FADER').pass,false); + assert.equal(check(1,'PRE_FADER').pass,false); + assert.equal(check(1,'POST_FADER').pass,true); +}); diff --git a/tests/milestone_a_native_contract_test.mjs b/tests/milestone_a_native_contract_test.mjs index 259eb911b..1f4be99b8 100644 --- a/tests/milestone_a_native_contract_test.mjs +++ b/tests/milestone_a_native_contract_test.mjs @@ -3,7 +3,7 @@ // These cannot replace real JUCE PCM/Windows screenshot/physical hardware FAT. import test from 'node:test'; import assert from 'node:assert/strict'; -import {collectSources,inspectMilestoneA} from '../scripts/check_console_puzzle.mjs'; +import {collectSources,inspectMilestoneA,PATHS} from '../scripts/check_console_puzzle.mjs'; const sources=collectSources(); const inspect=s=>inspectMilestoneA(s); @@ -64,3 +64,16 @@ test('accepted native callback still requires a proper event dispatcher and phys assert.ok(g0.integration.every(x=>typeof x.pass==='boolean'&&x.release)); assert.ok(g0.baseline.every(x=>x.release===false)); }); + +test('release preflight reads M3C INTEGRATOR-owned V8 projection rather than abandoned ENGINE path',()=>{ + assert.equal(collectSources().projection,sources.projection); + assert.equal(PATHS.projection,'integration/ApprovedNativeV8Projection.h'); + assert.notEqual(PATHS.projection,'src/ApprovedNativeV8Projection.h'); + // This is a source-path regression check, never a permanent G0 assertion: + // a future fully admitted product must also pass this test. + if (sources.projection) { + assert.match(sources.projection,/mainChannelId/); + assert.match(sources.projection,/processingFormat/); + } + assert.ok(inspect(sources).integration.every(x=>typeof x.pass==='boolean')); +}); diff --git a/web/approved-native-contract.js b/web/approved-native-contract.js index 6837e91b2..964a93d13 100644 --- a/web/approved-native-contract.js +++ b/web/approved-native-contract.js @@ -127,9 +127,39 @@ if (edit.op==="REMOVE") return decimal(edit.edgeId)!==null && !edges.some(e=>e.edgeId===edit.edgeId); - if (edit.op==="CONNECT" || edit.op==="ROUTE_ONLY") - return decimal(edit.to)!==null && - edges.some(e=>e.from===edit.from&&e.to===edit.to); + if (edit.op==="CONNECT" || edit.op==="ROUTE_ONLY") { + if (decimal(edit.to)===null) return false; + // A cable painted at the requested destination is not proof that + // the actual native tap/gain was accepted. Verify readback whenever + // the request names those fields; older v6 CONNECT still works. + const matching=edges.filter(e=>e.from===edit.from&&e.to===edit.to); + const effect=matching.some(e=>{ + if (edit.tap!==undefined && + e.tap!==edit.tap && + !(edit.tap==="POST_FADER"&&e.tap==="POST") && + !(edit.tap==="PRE_FADER"&&e.tap==="PRE")) + return false; + if (edit.gainLinear!==undefined && + (!Number.isFinite(edit.gainLinear) || + !Number.isFinite(e.gainLinear) || + Math.abs(edit.gainLinear-e.gainLinear)>0.0001)) + return false; + return edit.op!=="ROUTE_ONLY" || e.primaryOutput===true; + }); + if (!effect) return false; + if (edit.op==="ROUTE_ONLY") { + // Route Only must REMOVE the previous primary dry path. An ACK + // with both new BUS and original MAIN remains double-dry even + // when the graph revision advanced. + if (ch.primaryOutId!==edit.to) return false; + if (edges.some(e=>e.from===edit.from&&e.primaryOutput===true&&e.to!==edit.to)) + return false; + if (edit.to!==next.graph.mainChannelId && + edges.some(e=>e.from===edit.from&&e.to===next.graph.mainChannelId)) + return false; + } + return true; + } if (edit.op==="RETARGET") return decimal(edit.edgeId)!==null && decimal(edit.to)!==null && edges.some(e=>e.edgeId===edit.edgeId&&e.from===edit.from&&e.to===edit.to);