From 647964f2c3f6a9c7a90f8a62ede3307a613b270b Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 18 Nov 2026 10:19:07 +0700 Subject: [PATCH 1/3] refactor(gui3): establish pure WIRE EdgeId gain and tap presentation model --- web/approved-wire-view-model.js | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 web/approved-wire-view-model.js diff --git a/web/approved-wire-view-model.js b/web/approved-wire-view-model.js new file mode 100644 index 000000000..69c317fdf --- /dev/null +++ b/web/approved-wire-view-model.js @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// GUI-3: WIRE/BUS/MAIN presentation for one accepted ChannelId/EdgeId graph. +// Pure selectors, no DOM, DSP, native dispatcher or second routing authority. +(function(root,factory){ + const api=factory(); + if(typeof module==="object"&&module.exports)module.exports=api; + if(root)root.ArSonApprovedWireViewModel=api; +})(typeof globalThis==="object"?globalThis:undefined,function(){ + "use strict"; + // Only independently editable sends; never turn PRIMARY OUT into SEND. + // Exact uint64 decimal identities remain strings, never JS Numbers. + function parallelEdge(edges,source,edgeId){ + if(typeof source!=="string"||!source||typeof edgeId!=="string"|| + !edgeId||!Array.isArray(edges))return null; + const matches=edges.filter(e=>e?.enabled===true&& + e.edgeId===edgeId&&e.from===source&&e.primaryOutput===false); + return matches.length===1?matches[0]:null; + } + function gainDraft(levelDb,source,identity){ + const db=Number(levelDb); + if(!Number.isFinite(db)||db< -60||db>6|| + typeof source!=="string"||!source|| + typeof identity!=="string"||!identity)return null; + // UI floor is -infinity: actual zero PCM, not 0.001 linear gain. + return {source,gain:db<=-60?0:Math.pow(10,db/20),identity}; + } + function readbackGains(edges,uiByEdge,pendingByEdge){ + if(!Array.isArray(edges))return []; + return edges.filter(e=>e?.enabled===true&&e.primaryOutput===false) + .map(e=>({id:uiByEdge?.get?.(e.edgeId), + pending:pendingByEdge?.has?.(e.edgeId)===true, + levelDb:Math.round(Math.max(-60,Math.min(6, + e.gainLinear>0?20*Math.log10(e.gainLinear):-60))*10)/10})); + } + function flushDecision(current,edgeId,draft){ + if(!current||!draft||current.identity!==draft.identity)return "STALE"; + const edge=parallelEdge(current.graph?.edges,draft.source,edgeId); + if(!edge)return "UNROUTED"; + return Math.abs(edge.gainLinear-draft.gain)<.00001?"UNCHANGED":"SEND"; + } + // Inspector legacy modes translate to the existing native EdgeId tap. + function tapFromGesture(mode){ + return mode==="split"?"PRE_FADER":mode==="send"?"POST_FADER":null; + } + return Object.freeze({parallelEdge,gainDraft,readbackGains, + flushDecision,tapFromGesture}); +}); From 087e1a039e5f6bc52dcfacf0473414cf76653c7c Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 18 Nov 2026 10:19:34 +0700 Subject: [PATCH 2/3] refactor(gui3): make approved WIRE bridge a pure-model gesture/readback adapter --- web/approved-native-bridge.js | 42 ++++++++++++----------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 371e6dfd2..464a02a98 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -7,11 +7,12 @@ const deviceVM = window.ArSonApprovedDeviceViewModel; const stripVM = window.ArSonApprovedChannelStripViewModel; const fxRackVM = window.ArSonApprovedFxRackViewModel; + const wireVM = window.ArSonApprovedWireViewModel; // The public GUI owns one lexical model. Native-only bundle exports a narrow // reference to that SAME model; never reconstruct a parallel DOM/DSP. const scope = window.__ARMIX_NATIVE_SCOPE__ || null; const connected = Boolean(backend?.emitEvent && backend?.addEventListener && - protocol && deviceVM && stripVM && fxRackVM); + protocol && deviceVM && stripVM && fxRackVM && wireVM); // Public browser preview keeps its header; the native JUCE caption replaces it. if (backend?.emitEvent && backend?.addEventListener) document.documentElement?.classList?.add?.("armix-native-desktop"); @@ -368,22 +369,14 @@ if(state?.pending||!current?.admitted)return; for(const [edgeId,edit] of pendingWireGains){ pendingWireGains.delete(edgeId); - if(current.identity!==edit.identity){ - // A changed device/graph invalidates a deferred edit, but must not - // strand its LCD while waiting for a nonexistent ACK. + const decision=wireVM.flushDecision(current,edgeId,edit); + if(decision==="STALE"||decision==="UNROUTED"){ scope?.rollbackNativeWireInspector?.(nativeWireGainReadback(current)); - continue; // never replay into a new graph/device + continue; // changed graph or retargeted EdgeId never replays } - const edge=current.graph.edges.find(e=>e.enabled&&e.edgeId===edgeId&&e.from===edit.source); - if(!edge||edge.primaryOutput!==false){ - scope?.rollbackNativeWireInspector?.(nativeWireGainReadback(current)); - continue; - } - if(Math.abs(edge.gainLinear-edit.gain)<.00001){ - // The accepted PCM gain already equals the requested scalar. Do not - // emit a redundant native intent, but DO settle the pending display. + if(decision==="UNCHANGED"){ scope?.syncNativeWireGains?.(nativeWireGainReadback(current)); - continue; + continue; // do not emit a redundant accepted PCM scalar } const result=controller.intent("SET_WIRE_GAIN",edit.source,{edgeId,gainLinear:edit.gain}); if(result.ok)window.setTimeout(()=>controller?.expire(result.requestId),8000); @@ -400,18 +393,15 @@ if(!flags.acceptedGraphConnected||!current?.admitted||current.retained|| !source||!edgeId||!current.graph.capabilities.supportedOps.includes(operation)) return null; - const matches=current.graph.edges.filter(e=>e.enabled&& - e.edgeId===edgeId&&e.from===source&&e.primaryOutput===false); - return matches.length===1?matches[0]:null; + return wireVM.parallelEdge(current.graph.edges,source,edgeId); } function requestWireGain(op){ - const db=Number(op.levelDb); - if(!Number.isFinite(db)||db< -60||db>6|| - !admittedParallelWire(op.sourceId,op.edgeId,"SET_WIRE_GAIN"))return false; + if(!admittedParallelWire(op.sourceId,op.edgeId,"SET_WIRE_GAIN"))return false; const current=controller.state().current; const edgeId=wireByUiId.get(op.edgeId),source=nativeByUiId.get(op.sourceId); - // A physical SEND fader floor is -infinity (zero PCM), NOT -60 dB linear. - pendingWireGains.set(edgeId,{source,gain:db<=-60?0:Math.pow(10,db/20),identity:current.identity}); + const draft=wireVM.gainDraft(op.levelDb,source,current.identity); + if(!draft)return false; + pendingWireGains.set(edgeId,draft); queueWireGainFlush();return true; } function nativeOutputTargets(t,channels=activeView()?.graph?.channels||[]){ @@ -638,10 +628,7 @@ // One authoritative EdgeId gain projection for normal readback AND failure // rollback. No duplicate DSP math or synthetic accepted control state. function nativeWireGainReadback(next){ - return (next?.graph?.edges||[]).filter(e=>e.enabled&&e.primaryOutput===false) - .map(e=>({id:uiByWireId.get(e.edgeId),pending:pendingWireGains.has(e.edgeId), - levelDb:Math.round(Math.max(-60,Math.min(6, - e.gainLinear>0?20*Math.log10(e.gainLinear):-60))*10)/10})); + return wireVM.readbackGains(next?.graph?.edges,uiByWireId,pendingWireGains); } // Paint ONLY an independently accepted ChannelId input scalar. Comparing // the actual DOM as well as the model also repairs a rejected/expired gain @@ -3740,8 +3727,7 @@ if(Array.isArray(ops)&&ops.length===1&&ops[0].type==="MODE"){ const op=ops[0]; const source=nativeByUiId.get(op.sourceId),edgeId=wireByUiId.get(op.edgeId); - const tap=op.mode==="split"?"PRE_FADER": - op.mode==="send"?"POST_FADER":null; + const tap=wireVM.tapFromGesture(op.mode); requestNativeTap(source,edgeId,tap); return true; } From 10e4d659777ddbde37ccca66ecc681c313742899 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 18 Nov 2026 10:20:51 +0700 Subject: [PATCH 3/3] test(gui3): wire VM native assembly, real DOM mock parity and source/EdgeId contracts --- scripts/build_approved_native_gui.py | 3 + tests/approved_native_cold_start_smoke.py | 1 + tests/approved_native_gui_bundle_test.py | 6 ++ tests/approved_native_m2_contract.test.cjs | 70 ++++++++++++++++++++-- tests/live_fader_held_drag.test.cjs | 3 +- 5 files changed, 77 insertions(+), 6 deletions(-) diff --git a/scripts/build_approved_native_gui.py b/scripts/build_approved_native_gui.py index d1d9e19e2..f38406916 100644 --- a/scripts/build_approved_native_gui.py +++ b/scripts/build_approved_native_gui.py @@ -25,6 +25,7 @@ '\n' '\n' '\n' + '\n' '\n' '\n' '\n') @@ -368,6 +369,8 @@ def stage(out: Path) -> dict: out / "assets" / "approved-channel-strip-view-model.js") shutil.copy2(ROOT / "web" / "approved-fx-rack-view-model.js", out / "assets" / "approved-fx-rack-view-model.js") + shutil.copy2(ROOT / "web" / "approved-wire-view-model.js", + out / "assets" / "approved-wire-view-model.js") native = native_html(approved.decode("utf-8")).encode("utf-8") (out / "index.html").write_bytes(native) files = [out / "index.html", *sorted(p for p in (out / "assets").rglob("*") if p.is_file())] diff --git a/tests/approved_native_cold_start_smoke.py b/tests/approved_native_cold_start_smoke.py index ba2cf12c3..f286b60be 100644 --- a/tests/approved_native_cold_start_smoke.py +++ b/tests/approved_native_cold_start_smoke.py @@ -77,6 +77,7 @@ def main(): assert page.evaluate("""()=>Boolean( window.ArSonApprovedChannelStripViewModel && window.ArSonApprovedFxRackViewModel && + window.ArSonApprovedWireViewModel?.readbackGains && window.__ARMIX_NATIVE_M2__?.inputChoices && window.__ARMIX_NATIVE_M2__?.outputChoices)"""), ( 'native assembled GUI missing GUI-1 Channel Strip ViewModel') diff --git a/tests/approved_native_gui_bundle_test.py b/tests/approved_native_gui_bundle_test.py index 1604a9468..90cd5b11f 100644 --- a/tests/approved_native_gui_bundle_test.py +++ b/tests/approved_native_gui_bundle_test.py @@ -69,7 +69,13 @@ def test_native_is_exact_assembled_public_pages_plus_nonvisual_native_seam(self) self.assertLess(native.index('assets/approved-channel-strip-view-model.js'), native.index('assets/approved-fx-rack-view-model.js')) self.assertLess(native.index('assets/approved-fx-rack-view-model.js'), + native.index('assets/approved-wire-view-model.js')) + self.assertLess(native.index('assets/approved-wire-view-model.js'), native.index('assets/approved-native-bridge.js')) + self.assertNotIn('assets/approved-wire-view-model.js', approved) + self.assertEqual( + (out / 'assets/approved-wire-view-model.js').read_bytes(), + (ROOT / 'web/approved-wire-view-model.js').read_bytes()) self.assertNotIn('assets/approved-channel-strip-view-model.js', approved) self.assertNotIn('assets/approved-fx-rack-view-model.js', approved) self.assertEqual( diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 4b07b28c6..290e74c9e 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -7,6 +7,7 @@ const protocol=require("../web/approved-native-contract.js"); const deviceVM=require("../web/approved-device-view-model.js"); const stripVM=require("../web/approved-channel-strip-view-model.js"); const fxRackVM=require("../web/approved-fx-rack-view-model.js"); +const wireVM=require("../web/approved-wire-view-model.js"); const read=p=>readFileSync(p,"utf8"); const fixtures=JSON.parse(read("integration/console-v6/fixtures.json")); const clone=x=>JSON.parse(JSON.stringify(x)); @@ -94,6 +95,63 @@ function acceptedFixture(){ tap:"POST",gainLinear:1,enabled:true,signalKind:"AUDIO"}]; return s; } +// GUI-3 WIRE/BUS/MAIN projection is immutable and uses exact native ids. +test("GUI-3 WIRE selects unique exact EdgeId and never writes PRIMARY OUT",()=>{ + const source="9007199254740993",target="18446744073709551615"; + const send="9223372036854775809",route="9223372036854775811"; + const edges=[ + {edgeId:send,from:source,to:target,enabled:true, + primaryOutput:false,gainLinear:0.5}, + {edgeId:route,from:source,to:target,enabled:true, + primaryOutput:true,gainLinear:1} + ]; + assert.equal(wireVM.parallelEdge(edges,source,send),edges[0]); + assert.equal(wireVM.parallelEdge(edges,source,route),null); + assert.equal(wireVM.parallelEdge(edges,"9007199254740994",send),null); + assert.equal(wireVM.parallelEdge([...edges,edges[0]],source,send),null, + "duplicated EdgeId cannot choose an arbitrary send"); + assert.equal(wireVM.parallelEdge(edges,source,Number(send)),null, + "uint64 identity must not round through JS Number"); +}); +test("GUI-3 WIRE projection preserves infinity floor, pending, tap and BUS/MAIN readback",()=>{ + const edges=[ + {edgeId:"e-a",enabled:true,primaryOutput:false,gainLinear:0.5011872336272722}, + {edgeId:"e-b",enabled:true,primaryOutput:false,gainLinear:0}, + {edgeId:"primary",enabled:true,primaryOutput:true,gainLinear:1} + ]; + const observed=wireVM.readbackGains(edges,new Map([["e-a",72],["e-b",73]]), + new Map([["e-b",{requestId:"pending"}]])); + assert.deepEqual(observed,[{id:72,pending:false,levelDb:-6}, + {id:73,pending:true,levelDb:-60}]); + assert.equal(wireVM.gainDraft(-60,"ch","graph").gain,0); + assert.ok(Math.abs(wireVM.gainDraft(-12,"ch","graph").gain- + Math.pow(10,-12/20))<1e-12); + assert.equal(wireVM.gainDraft(6.01,"ch","graph"),null); + assert.equal(wireVM.gainDraft(-60.1,"ch","graph"),null); + assert.equal(wireVM.tapFromGesture("split"),"PRE_FADER"); + assert.equal(wireVM.tapFromGesture("send"),"POST_FADER"); + assert.equal(wireVM.tapFromGesture("routeOnly"),null); +}); +test("GUI-3 queued WIRE gesture never crosses changed native graph or moved EdgeId",()=>{ + const source="9007199254740993",id="9223372036854775809"; + const draft=wireVM.gainDraft(-6,source,"graph:13"); + const edge={edgeId:id,from:source,enabled:true,primaryOutput:false,gainLinear:1}; + const current={identity:"graph:13",graph:{edges:[edge]}}; + assert.equal(wireVM.flushDecision(current,id,draft),"SEND"); + assert.equal(wireVM.flushDecision({...current,identity:"graph:14"},id,draft),"STALE"); + assert.equal(wireVM.flushDecision({...current,graph:{edges:[{...edge,from:"other"}]}}, + id,draft),"UNROUTED"); + assert.equal(wireVM.flushDecision({...current,graph:{edges:[{...edge,primaryOutput:true}]}}, + id,draft),"UNROUTED"); + assert.equal(wireVM.flushDecision({...current,graph:{edges:[{...edge,gainLinear:draft.gain}]}}, + id,draft),"UNCHANGED"); + const bridge=read("web/approved-native-bridge.js"); + assert.match(bridge,/wireVM\.gainDraft\(op\.levelDb,source,current\.identity\)/); + assert.match(bridge,/wireVM\.flushDecision\(current,edgeId,edit\)/); + assert.match(bridge,/wireVM\.readbackGains\(next\?\.graph\?\.edges,uiByWireId,pendingWireGains\)/); + assert.match(bridge,/wireVM\.tapFromGesture\(op\.mode\)/); + assert.doesNotMatch(bridge,/db<=-60\?0:Math\.pow\(10,db\/20\)/); +}); test("WIRE inspector controls PRIMARY BUS and PARALLEL MAIN by actual EdgeId, with native readback only",()=>{ const vm=require("node:vm"),{execFileSync}=require("node:child_process"); const publicHtml=read("site/preview-v2/index.html"); @@ -112,7 +170,9 @@ test("WIRE inspector controls PRIMARY BUS and PARALLEL MAIN by actual EdgeId, wi const bridge=read("web/approved-native-bridge.js"); const builder=read("scripts/build_approved_native_gui.py"); assert.match(bridge,/function admittedParallelWire\(uiSourceId,uiEdgeId,operation\)/); - assert.match(bridge,/e\.edgeId===edgeId&&e\.from===source&&e\.primaryOutput===false/); + assert.match(bridge,/wireVM\.parallelEdge\(current\.graph\.edges,source,edgeId\)/); + assert.match(read("web/approved-wire-view-model.js"), + /e\.edgeId===edgeId&&e\.from===source&&e\.primaryOutput===false/); assert.match(builder,/getElementById\('wireWsGainText'\)/); assert.match(builder,/!row\.pending/); const renderStart=html.indexOf("function renderWireWsInspector(){"); @@ -1314,7 +1374,7 @@ test("M3 native-only Pages scope performs real bridge projection, fader intent a querySelector:()=>null,addEventListener(){} }; const window={ - __JUCE__:{backend:native},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,ArSonApprovedChannelStripViewModel:stripVM,ArSonApprovedFxRackViewModel:fxRackVM, + __JUCE__:{backend:native},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,ArSonApprovedChannelStripViewModel:stripVM,ArSonApprovedFxRackViewModel:fxRackVM,ArSonApprovedWireViewModel:wireVM, __ARMIX_NATIVE_SCOPE__:scope,addEventListener(){},queueMicrotask(fn){microtasks.push(fn);},setTimeout(fn,ms){timers.push({fn,ms});return timers.length;} }; vm.runInNewContext(read("web/approved-native-bridge.js"),{ @@ -1538,7 +1598,7 @@ test("P0 native FX rack and per-slot readback update mounted strip without repla querySelector:selector=>selector.startsWith('.strip[data-id=')?strip:null, addEventListener(){} }; - const win={__JUCE__:{backend:native},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,ArSonApprovedChannelStripViewModel:stripVM,ArSonApprovedFxRackViewModel:fxRackVM, + const win={__JUCE__:{backend:native},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,ArSonApprovedChannelStripViewModel:stripVM,ArSonApprovedFxRackViewModel:fxRackVM,ArSonApprovedWireViewModel:wireVM, __ARMIX_NATIVE_SCOPE__:scope,addEventListener(){}, setTimeout(){return 0},clearTimeout(){},queueMicrotask(fn){fn();}}; vm.runInNewContext(read("web/approved-native-bridge.js"), @@ -1716,7 +1776,7 @@ test("P0 FIRST SOUND G0 offers verified input and leaves automatic MAIN to nativ addEventListener(){} }; win={ - __JUCE__:{backend},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,ArSonApprovedChannelStripViewModel:stripVM,ArSonApprovedFxRackViewModel:fxRackVM, + __JUCE__:{backend},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,ArSonApprovedChannelStripViewModel:stripVM,ArSonApprovedFxRackViewModel:fxRackVM,ArSonApprovedWireViewModel:wireVM, __ARMIX_NATIVE_SCOPE__:scope,addEventListener(){}, setTimeout(){return 0},clearTimeout(){},queueMicrotask(fn){fn();} }; @@ -1803,7 +1863,7 @@ test("P0 native hardware IN remains selectable after ChannelId ownership, failed id==="preview"?{disabled:true}:null, querySelector:()=>null,addEventListener(){} }; - const win={__JUCE__:{backend},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,ArSonApprovedChannelStripViewModel:stripVM,ArSonApprovedFxRackViewModel:fxRackVM, + const win={__JUCE__:{backend},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,ArSonApprovedChannelStripViewModel:stripVM,ArSonApprovedFxRackViewModel:fxRackVM,ArSonApprovedWireViewModel:wireVM, __ARMIX_NATIVE_SCOPE__:scope,addEventListener(){}, setTimeout(){return 0},clearTimeout(){}, queueMicrotask(fn){microtasks.push(fn);}}; diff --git a/tests/live_fader_held_drag.test.cjs b/tests/live_fader_held_drag.test.cjs index 4158147f1..03116ed98 100644 --- a/tests/live_fader_held_drag.test.cjs +++ b/tests/live_fader_held_drag.test.cjs @@ -9,6 +9,7 @@ const protocol=require("../web/approved-native-contract.js"); const deviceVM=require("../web/approved-device-view-model.js"); const stripVM=require("../web/approved-channel-strip-view-model.js"); const fxRackVM=require("../web/approved-fx-rack-view-model.js"); +const wireVM=require("../web/approved-wire-view-model.js"); const read=p=>readFileSync(p,"utf8"); const clone=x=>JSON.parse(JSON.stringify(x)); const fixture=JSON.parse(read("integration/console-v6/fixtures.json")).g0; @@ -79,7 +80,7 @@ function harness({m4=false}={}){ }; const window={ __JUCE__:{backend},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM, - ArSonApprovedChannelStripViewModel:stripVM,ArSonApprovedFxRackViewModel:fxRackVM, + ArSonApprovedChannelStripViewModel:stripVM,ArSonApprovedFxRackViewModel:fxRackVM,ArSonApprovedWireViewModel:wireVM, __ARMIX_NATIVE_SCOPE__:scope,addEventListener(){}, setTimeout(fn,delay=0){timers.push({fn,at:now+Math.max(0,Number(delay)||0)});return timers.length;} };