diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index f8e200ad0..e5b46730f 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -564,7 +564,9 @@ test("P0 DAW approved Windows GUI directly binds every IN to current JUCE ports, assert.match(producer,/firstSound->setProperty\("channels",juce::var\(verifiedChannels\)\)/); assert.match(producer,/publishAuthoritativeMixerSession/); assert.match(nativeMain,/publishAuthoritativeMixerSession\(accepted\)/); - assert.match(bridge,/session\.authority==="CHANNEL_ID"/); + assert.match(bridge,/const nativeAdmitted=readModel\.kind==="CHANNEL_ID"/); + assert.match(read("web/approved-native-contract.js"), + /session\.authority==="CHANNEL_ID"&&next\.admitted===true/); assert.match(bridge,/m4ControlIsOwner\(\)/); assert.match(producer,/list->size\(\)==10/); assert.match(nativeMain,/engine_\.switchDryRoutingLabSource\(channel,/); @@ -1117,7 +1119,9 @@ test("P0 native WIRE MAIN disconnect requires exact accepted EdgeId or verified test("P0 native-only WIRE cables reflect actual M4 MAIN readback, not demo ghosts",()=>{ const bridge=read("web/approved-native-bridge.js"); const bundle=read("scripts/build_approved_native_gui.py"); - assert.match(bridge,/if\(session\.authority==="M4" && m4Verified\(\)\)/); + assert.match(bridge,/if\(readModel\.kind==="M4"\)/); + assert.match(read("web/approved-native-contract.js"), + /session\.authority==="M4"&&verifiedM4===true/); assert.match(bridge,/scope\?\.syncVerifiedM4Wires\?\.\(session\.channels\.map\(ch=>ch\.source\),m4TrackIds\)/); assert.match(bundle,/syncVerifiedM4Wires\(rows,ids\)/); assert.match(bundle,/typeof r\.main!=='boolean'/); diff --git a/tests/milestone_a_single_authority.test.cjs b/tests/milestone_a_single_authority.test.cjs index 08bb77170..829055582 100644 --- a/tests/milestone_a_single_authority.test.cjs +++ b/tests/milestone_a_single_authority.test.cjs @@ -10,8 +10,12 @@ test("only installed callback determines GUI channel control authority",()=>{ assert.match(host,/publishAuthoritativeMixerSession\(accepted\)/); assert.match(producer,/const auto authority=hasChannelId\?"CHANNEL_ID":validM4\?"M4":"NONE"/); assert.match(producer,/row->setProperty\("id","m4:"/); - assert.match(adapter,/if\(session\.authority==="M4" && m4Verified\(\)\)/); - assert.match(adapter,/const nativeAdmitted=session\.authority==="CHANNEL_ID"/); + const source=read("web/approved-native-contract.js"); + assert.match(adapter,/const readModel=protocol\.selectNativeReadModel\(next,m4Verified\(\)\)/); + assert.match(adapter,/if\(readModel\.kind==="M4"\)/); + assert.match(adapter,/const nativeAdmitted=readModel\.kind==="CHANNEL_ID"/); + assert.match(source,/session\.authority==="M4"&&verifiedM4===true/); + assert.match(source,/session\.authority==="CHANNEL_ID"&&next\.admitted===true/); assert.match(adapter,/m4ControlIsOwner\(\)&&m4Verified\(\)&&m4Index\(t\)>=0/); assert.doesNotMatch(adapter,/rackSavedBypass/); assert.match(adapter,/const ctl=session\.channels\.map\(row=>row\.controls\)/); @@ -53,3 +57,141 @@ test("native ChannelId source preserves post-fader physical MAIN and VST3",()=>{ assert.match(engine,/insertDryRoutingLabFx/); assert.match(engine,/applyGuardedDryTopology/); }); + + +const protocol=require("../web/approved-native-contract.js"); +const fixture=JSON.parse(read("integration/console-v6/fixtures.json")).g0; +const copy=value=>JSON.parse(JSON.stringify(value)); + +// These tests use the very same schema-v6 normalizeSnapshot as native +// transport; no alternate JS mixer session or browser-only LIVE model. +function installedReadModelFixture() { + const raw=copy(fixture),input="9007199254740993", + main="18446744073709551615"; + raw.device.epoch="18446744073709551610"; + raw.device.outputArmed=true; + raw.productionCallbackLive=true; + raw.graph.revision="5";raw.graph.rosterRevision="7"; + raw.graph.mainChannelId=main; + raw.graph.capabilities.callbackOwnsChannelIds=true; + raw.graph.capabilities.supportedOps=["SET_FADER","APPLY_WIRE_TRANSACTION"]; + raw.graph.channels=[ + {id:input,role:"INPUT",name:"Vocal",processingFormat:"MONO", + primaryOutId:main,controls:{faderDb:-6,pan:0,mute:false,solo:false}, + inserts:[],sends:[]}, + {id:main,role:"MAIN",name:"MAIN",processingFormat:"STEREO", + controls:{faderDb:0,pan:0,mute:false,solo:false},inserts:[],sends:[]} + ]; + raw.graph.destinations=[{id:main,role:"MAIN"}]; + raw.graph.edges=[{edgeId:"9223372036854775808",from:input,to:main, + tap:"POST_FADER",gainLinear:1,enabled:true,signalKind:"AUDIO", + primaryOutput:true}]; + raw.mixerSession={authority:"CHANNEL_ID",deviceEpoch:raw.device.epoch}; + return raw; +} +function offlineReadModelFixture() { + const raw=copy(fixture); + raw.mixerSession={authority:"NONE",deviceEpoch:raw.device.epoch}; + raw.logicalMixer={ + schema:"arsonmix.native.logical-mixer.v1",authority:"LOGICAL_ONLY", + workspaceToken:"offline-smix-v1",readOnly:false,revision:"12", + physicalOutputAdmitted:false,outputArmed:false, + graph:{revision:"12",rosterRevision:"12", + capabilities:{callbackOwnsChannelIds:false,supportedOps:["SET_FADER"]}, + channels:[{id:"9007199254740993",role:"INPUT",name:"Vocal", + processingFormat:"MONO",inserts:[],sends:[], + controls:{faderDb:-6,pan:0,mute:false,solo:false}}], + edges:[]} + }; + return raw; +} +test("MV-3 native read-model prioritizes installed ChannelId without physical LIVE fabrication",()=>{ + const raw=installedReadModelFixture(),saved=JSON.stringify(raw); + const normalized=protocol.normalizeSnapshot(raw); + assert.ok(normalized?.admitted); + const view=protocol.selectNativeReadModel(normalized,false); + assert.equal(view.kind,"CHANNEL_ID"); + assert.strictEqual(view.view,normalized, + "selector must reuse the exact accepted readback, not clone a new graph"); + assert.equal(view.view.graph.channels[0].id,"9007199254740993"); + assert.equal(view.view.graph.edges[0].edgeId,"9223372036854775808"); + assert.equal(view.view.productLive,true); + assert.equal(JSON.stringify(raw),saved,"read-model cannot mutate installed graph"); + assert.equal(protocol.selectNativeReadModel({...normalized, + graph:{...normalized.graph}},false).kind,"INVALID", + "independent UI copy is not the normalized native graph"); + const g0=copy(fixture); + g0.mixerSession={authority:"CHANNEL_ID",deviceEpoch:g0.device.epoch}; + const unadmitted=protocol.normalizeSnapshot(g0); + assert.equal(unadmitted.admitted,false); + assert.equal(protocol.selectNativeReadModel(unadmitted,false).kind,"UNADMITTED", + "naming CHANNEL_ID cannot turn an uninstalled graph into PCM"); + g0.mixerSession.deviceEpoch="18446744073709551615"; + assert.equal(protocol.selectNativeReadModel(protocol.normalizeSnapshot(g0),false).kind,"STALE", + "mismatched producer epoch cannot grant native device status"); +}); +test("MV-3 offline .smix read-model is nonphysical and cannot outrank installed/M4",()=>{ + const raw=offlineReadModelFixture(),original=JSON.stringify(raw); + const normalized=protocol.normalizeSnapshot(raw); + assert.ok(normalized && !normalized.admitted && !normalized.retained); + const eligible=protocol.selectNativeReadModel(normalized,false); + assert.equal(eligible.kind,"LOGICAL_ONLY"); + assert.equal(eligible.view.logical,true); + assert.equal(eligible.view.admitted,false); + assert.equal(eligible.view.productLive,false); + assert.equal(eligible.view.retained,false); + assert.equal(eligible.view.telemetry && Object.keys(eligible.view.telemetry).length,0); + assert.strictEqual(eligible.view.graph,raw.logicalMixer.graph, + "offline presenter must reuse exact native .smix readback, not construct a second session"); + assert.equal(eligible.view.identity,"logical:offline-smix-v1:12"); + assert.equal(JSON.stringify(raw),original,"selector never modifies native or offline source"); + const readonly=copy(raw);readonly.logicalMixer.readOnly=true; + assert.equal(protocol.selectNativeReadModel(protocol.normalizeSnapshot(readonly),false).view.readOnly,true); + for(const mutate of [ + x=>{x.logicalMixer.physicalOutputAdmitted=true;}, + x=>{x.logicalMixer.outputArmed=true;}, + x=>{x.logicalMixer.graph.capabilities.callbackOwnsChannelIds=true;}, + x=>{x.logicalMixer.graph.rosterRevision="11";}, + x=>{x.logicalMixer.revision="11";}, + x=>{x.logicalMixer.workspaceToken="";}, + x=>{x.logicalMixer.graph.edges=null;} + ]) { + const bad=copy(raw);mutate(bad); + assert.notEqual(protocol.selectNativeReadModel(protocol.normalizeSnapshot(bad),false).kind, + "LOGICAL_ONLY","invalid offline status must never be projected"); + } + const m4=copy(raw);m4.mixerSession.authority="M4"; + assert.equal(protocol.selectNativeReadModel(protocol.normalizeSnapshot(m4),true).kind,"M4"); + assert.notEqual(protocol.selectNativeReadModel(protocol.normalizeSnapshot(m4),false).kind,"LOGICAL_ONLY"); + assert.notEqual(protocol.selectNativeReadModel(normalized,true).kind,"LOGICAL_ONLY", + "a verified legacy physical renderer takes precedence over saved logical edit"); +}); +test("MV-3 retained device-loss readback wins over stale logical state, never rearms",()=>{ + const raw=installedReadModelFixture(); + raw.graph.bindingState="NEEDS_REMAP"; + raw.graph.capabilities.callbackOwnsChannelIds=false; + raw.graph.capabilities.supportedOps=[]; + raw.productionCallbackLive=false; + raw.device.outputArmed=false; + raw.mixerSession.bindingState="NEEDS_REMAP"; + raw.logicalMixer=offlineReadModelFixture().logicalMixer; + const next=protocol.normalizeSnapshot(raw); + assert.ok(next && next.retained && !next.admitted, + "retained graph is normalized by original schema-v6 decoder"); + const view=protocol.selectNativeReadModel(next,false); + assert.equal(view.kind,"NEEDS_REMAP"); + assert.strictEqual(view.view,next); + assert.equal(view.view.device.outputArmed,false); + assert.equal(view.view.productLive,false); + assert.equal(view.view.graph.channels.length,2); + assert.equal(view.view.graph.edges[0].edgeId,"9223372036854775808", + "source/edge intent survives device remap without phantom PCM"); + const bridge=read("web/approved-native-bridge.js"); + assert.match(bridge,/const readModel=protocol\.selectNativeReadModel\(next,m4Verified\(\)\)/); + assert.match(bridge,/if\(readModel\.kind==="LOGICAL_ONLY"\)/); + assert.match(bridge,/const nativeAdmitted=readModel\.kind==="CHANNEL_ID"/); + assert.doesNotMatch(bridge,/const logicalAvailable=/, + "legacy duplicate offline authority policy must be deleted from bridge"); + assert.doesNotMatch(bridge,/const nativeAdmitted=session\.authority===/, + "native callback admission belongs to schema-v6 read-model, not DOM"); +}); diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 153ecd934..720f89e1b 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -2662,28 +2662,17 @@ if(deviceState!==previousSetup && !deviceState.pending)finishDeviceApplyUi(); updateHardwarePanel(next); paintExternalReadback(next); - // The installed native SessionSnapshot selects exactly one UI authority. + // 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()); const session=next?.raw?.mixerSession; const offline=next?.raw?.logicalMixer; - // Retained PCM owns vendor state even if the saved descriptors look - // identical. Only native can authorize the unbound logical editor. - const logicalAvailable=!next.admitted&&!next.retained&&!m4Verified()&& - session?.authority!=="M4"&&session?.authority!=="CHANNEL_ID"&& - offline?.schema==="arsonmix.native.logical-mixer.v1" && - offline.authority==="LOGICAL_ONLY"&& - typeof offline.workspaceToken==="string"&&offline.workspaceToken.length>0&& - offline.physicalOutputAdmitted===false&&offline.outputArmed===false&& - offline.graph?.capabilities?.callbackOwnsChannelIds===false&& - protocol.decimal(offline.revision)!==null&&offline.revision!=="0"&& - offline.revision===offline.graph?.revision&& - offline.revision===offline.graph?.rosterRevision&& - Array.isArray(offline.graph?.channels)&&Array.isArray(offline.graph?.edges); - if(logicalAvailable) { - const staged={...next,graph:offline.graph, - workspaceToken:offline.workspaceToken, - identity:"logical:"+offline.workspaceToken+":"+offline.revision,logical:true, - readOnly:offline.readOnly===true, - admitted:false,retained:false,productLive:false,telemetry:{}}; + if(readModel.kind==="INVALID"){ + status("NATIVE READBACK INVALID · existing GUI controls unchanged"); + return; + } + if(readModel.kind==="LOGICAL_ONLY") { + const staged=readModel.view; let revealCreatedId=null,wireImpact=null; if(pendingLogical && pendingLogical.workspaceToken!==offline.workspaceToken) pendingLogical=null; @@ -2757,7 +2746,7 @@ pendingLogical=null; status("Audio connection changed · refresh mixer before editing"); } - if(!session || session.deviceEpoch!==next.device.epoch) { + if(readModel.kind==="STALE") { flags.acceptedGraphConnected=false; flags.productionCallbackLive=false; lastPaintedSignature=""; @@ -2771,7 +2760,7 @@ // data can update controls; independent meters and FX racks keep moving. reconcileM4ControlReadback(next); reconcileM4RackReadback(next); - if(session.authority==="M4" && m4Verified()) { + if(readModel.kind==="M4") { paintM4Fallback(next); if(scope?.syncVerifiedM4Wires?.(session.channels.map(ch=>ch.source),m4TrackIds)) document.documentElement.dataset.armixNativeRoster="accepted"; @@ -2782,8 +2771,7 @@ if(!nativeUiSourcePending && pendingSourceQueue.size) window.queueMicrotask(()=>dispatchQueuedSource()); const caps=next?.graph?.capabilities; - const nativeAdmitted=session.authority==="CHANNEL_ID" && - next.admitted && caps?.callbackOwnsChannelIds===true; + const nativeAdmitted=readModel.kind==="CHANNEL_ID"; if(pendingBusCreate && pendingBusCreate.epoch!==next.device.epoch) pendingBusCreate=null; syncAddTrack(next); diff --git a/web/approved-native-contract.js b/web/approved-native-contract.js index 9c7f53636..815107025 100644 --- a/web/approved-native-contract.js +++ b/web/approved-native-contract.js @@ -174,6 +174,53 @@ productLive:admitted && raw.productionCallbackLive, identity: d.epoch + ":" + g.revision + ":" + g.rosterRevision }; } + // MV-3: select exactly one existing native read authority for /preview/. + // The reconciler already validated schema-v6, epoch and accepted PCM. + // This is a projection of THAT immutable control-thread readback, never + // an alternative session, acceptance controller or JS-owned graph. + function selectNativeReadModel(next,verifiedM4=false) { + const invalid=Object.freeze({kind:"INVALID",view:null}); + if(!next || next.raw?.schemaVersion!==6 || + next.device!==next.raw.device || next.graph!==next.raw.graph || + !next.device || !next.graph || typeof next.admitted!=="boolean" || + typeof next.retained!=="boolean")return invalid; + const session=next.raw.mixerSession,offline=next.raw.logicalMixer; + // The physical installed producer (including NEEDS_REMAP) takes + // priority over a saved logical .smix, even if stale metadata is present. + // Do NOT use outputArmed, GUI labels, or an ACK to invent PCM admission. + const offlineEligible=!next.admitted&&!next.retained&&verifiedM4!==true&& + session?.authority!=="M4"&&session?.authority!=="CHANNEL_ID"&& + offline?.schema==="arsonmix.native.logical-mixer.v1"&& + offline.authority==="LOGICAL_ONLY"&& + typeof offline.workspaceToken==="string"&&offline.workspaceToken.length>0&& + offline.physicalOutputAdmitted===false&&offline.outputArmed===false&& + offline.graph?.capabilities?.callbackOwnsChannelIds===false&& + decimal(offline.revision)!==null&&offline.revision!=="0"&& + offline.revision===offline.graph?.revision&& + offline.revision===offline.graph?.rosterRevision&& + Array.isArray(offline.graph?.channels)&&Array.isArray(offline.graph?.edges); + if(offlineEligible) { + // A logical view is a read-only DISPLAY projection of the same native + // envelope, not a second accepted mixer or physical output authority. + const view={...next,graph:offline.graph, + workspaceToken:offline.workspaceToken, + identity:"logical:"+offline.workspaceToken+":"+offline.revision, + logical:true,readOnly:offline.readOnly===true, + admitted:false,retained:false,productLive:false,telemetry:{}}; + return Object.freeze({kind:"LOGICAL_ONLY",view}); + } + if(!session || session.deviceEpoch!==next.device.epoch) + return Object.freeze({kind:"STALE",view:null}); + if(session.authority==="CHANNEL_ID"&&next.admitted===true&& + next.graph.capabilities?.callbackOwnsChannelIds===true) + return Object.freeze({kind:"CHANNEL_ID",view:next}); + if(next.retained===true&&session.authority==="CHANNEL_ID") + return Object.freeze({kind:"NEEDS_REMAP",view:next}); + if(session.authority==="M4"&&verifiedM4===true&&!next.admitted&&!next.retained) + return Object.freeze({kind:"M4",view:next}); + return Object.freeze({kind:"UNADMITTED",view:null}); + } + // Read-only physical OUTPUTS projection from the authoritative JUCE snapshot. // No guessed ports, UI-owned routing, monitor activation or audible claims. function physicalOutputOverview(snapshot) { @@ -705,5 +752,5 @@ } return Object.freeze({subscribe,onSnapshot,onAck,intent,state,expire}); } - return Object.freeze({decimal,cmp,normalizeSnapshot,readbackProvesIntent,logicalReadbackProves,diagnoseFirstSound,createController,validPresentationName,validPresentationColor,validPresentationIcon,operatorMessage,physicalOutputOverview}); + return Object.freeze({decimal,cmp,normalizeSnapshot,selectNativeReadModel,readbackProvesIntent,logicalReadbackProves,diagnoseFirstSound,createController,validPresentationName,validPresentationColor,validPresentationIcon,operatorMessage,physicalOutputOverview}); });