Repository navigation
refactor(mv8): Device Setup selected-pin identity through ACK and readback #785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
masarray
merged 2 commits into
main
from
refactor/mv8-device-apply-pin-identity-20261118
Nov 18, 2026
+222
−7
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-only | ||
| // MV-8: Device Setup pin identity is an operator request, never PCM authority. | ||
| const test=require("node:test"); | ||
| const assert=require("node:assert/strict"); | ||
| const {readFileSync}=require("node:fs"); | ||
| const vm=require("../web/approved-device-view-model.js"); | ||
|
|
||
| function fixture(){ | ||
| const active={ | ||
| backend:"ASIO",captureDevice:"Studio ASIO",playbackDevice:"Studio ASIO", | ||
| deviceGeneration:40,open:true,authorized:true,rate:48000,buffer:256, | ||
| inputNames:["Mic 1","Mic 2","Mic 3","Mic 4"], | ||
| outputNames:["Main L","Main R","Phones L","Phones R"], | ||
| enabledInputs:[0,1],enabledOutputs:[0,1],mainOutputs:[0,1] | ||
| }; | ||
| const inventory={active,types:[{ | ||
| name:"ASIO",separate:false,inputs:["Studio ASIO","Other ASIO"], | ||
| outputs:["Studio ASIO","Other ASIO"] | ||
| },{ | ||
| name:"Windows Audio",separate:true,inputs:["Microphone"], | ||
| outputs:["Speakers"] | ||
| }]}; | ||
| const draft={backend:"ASIO",capture:"Studio ASIO",playback:"Studio ASIO", | ||
| inputPins:[0,2],outputPins:[2,3],rate:48000,buffer:256}; | ||
| const begin=(requestId="pin-1",d=draft,inv=inventory)=> | ||
| vm.setupBegin(vm.setupInitial(),{inventory:inv,draft:d, | ||
| requestId,baselineEpoch:"40"}); | ||
| const ack=(requestId="pin-1",overrides={})=>({ | ||
| requestId,ok:true,state:"ACCEPTED_MUTED", | ||
| active:{...active,deviceGeneration:41,enabledInputs:[2,0], | ||
| enabledOutputs:[3,2]},mixerBound:true,outputMuted:true, | ||
| ...overrides | ||
| }); | ||
| const readback={ | ||
| raw:{schemaVersion:6},admitted:false,retained:false,productLive:false, | ||
| device:{epoch:"41",backend:active.backend, | ||
| captureDevice:active.captureDevice,playbackDevice:active.playbackDevice, | ||
| sampleRate:48000,bufferFrames:256,enabledInputs:[0,2], | ||
| enabledOutputs:[2,3],outputArmed:false} | ||
| }; | ||
| return {active,inventory,draft,begin,ack,readback}; | ||
| } | ||
|
|
||
| test("MV-8 same-device Apply remembers explicit physical pin sets, not callback order",()=>{ | ||
| const f=fixture(),original=JSON.stringify(f.inventory); | ||
| const begun=f.begin(); | ||
| assert.ok(begun); | ||
| assert.deepEqual(begun.request.config.enabledInputs,[0,2]); | ||
| assert.deepEqual(begun.request.config.enabledOutputs,[2,3]); | ||
| assert.deepEqual(begun.state.pending.expected.requestedPins,{ | ||
| inputs:[0,2],outputs:[2,3]}); | ||
| const v=vm.setupAck(begun.state,f.ack()); | ||
| assert.equal(v.phase,"VERIFYING", | ||
| "same physical sets in different order are still exactly installed pins"); | ||
| assert.equal(v.pending.ack.active.deviceGeneration,41); | ||
| assert.equal(vm.setupReadback(v,{...f.readback,device:{ | ||
| ...f.readback.device,enabledInputs:[2,0],enabledOutputs:[3,2] | ||
| }}).phase,"ACCEPTED"); | ||
| assert.equal(vm.setupReadback(v,f.readback).phase,"ACCEPTED"); | ||
| assert.equal(JSON.stringify(f.inventory),original, | ||
| "DeviceVM cannot edit authoritative JUCE inventory"); | ||
| }); | ||
|
|
||
| test("MV-8 native accepted ACK with changed output pins never claims selected hardware",()=>{ | ||
| const f=fixture(),begun=f.begin("pin-2"); | ||
| const acceptedDifferent=f.ack("pin-2",{active:{ | ||
| ...f.active,deviceGeneration:41, | ||
| enabledInputs:[0,2],enabledOutputs:[0,1] | ||
| }}); | ||
| const verdict=vm.setupAck(begun.state,acceptedDifferent); | ||
| assert.equal(verdict.phase,"RECOVERY_REQUIRED"); | ||
| assert.equal(verdict.pending,null); | ||
| assert.match(verdict.message,/pins differ/i); | ||
| assert.doesNotMatch(verdict.message,/Previous device restored|Output live/); | ||
| assert.equal(vm.setupReadback(verdict,f.readback),verdict); | ||
| assert.equal(vm.setupAck(verdict,f.ack("pin-2")),verdict, | ||
| "late correct ACK cannot resurrect a finished mismatched request"); | ||
| }); | ||
|
|
||
| test("MV-8 altered capture mask and missing pins are rejected without claiming rollback",()=>{ | ||
| const f=fixture(),begun=f.begin("pin-3"); | ||
| const mismatchedInput=vm.setupAck(begun.state,f.ack("pin-3",{ | ||
| active:{...f.active,deviceGeneration:41, | ||
| enabledInputs:[1,2],enabledOutputs:[2,3]} | ||
| })); | ||
| assert.equal(mismatchedInput.phase,"RECOVERY_REQUIRED"); | ||
| for(const output of [[2,2],[3,65],[2],[3,2,3],["2",3]]){ | ||
| const state=vm.setupAck(begun.state,f.ack("pin-3",{ | ||
| active:{...f.active,deviceGeneration:41, | ||
| enabledInputs:[0,2],enabledOutputs:output} | ||
| })); | ||
| assert.notEqual(state.phase,"VERIFYING", | ||
| "bad hardware evidence must never pass into VERIFYING"); | ||
| assert.notEqual(state.phase,"ACCEPTED"); | ||
| } | ||
| }); | ||
|
|
||
| test("MV-8 stale, duplicate, out-of-range and fractional draft masks cannot apply",()=>{ | ||
| const f=fixture(); | ||
| for(const [inputPins,outputPins] of [ | ||
| [[0,0],[2,3]],[[0,2],[2,2]],[[0,2],[2,4]], | ||
| [[0,2],[2,64]],[[1.5],[2,3]],[[0,2],[2]], | ||
| [["0",2],[2,3]],[[0,2],[2,3,3]],[[0,-1],[2,3]] | ||
| ]){ | ||
| const d={...f.draft,inputPins,outputPins}; | ||
| const view=vm.setupPresentation(f.inventory,d); | ||
| assert.equal(view.canApply,false,JSON.stringify(d)); | ||
| assert.equal(view.canAssignMain,false); | ||
| assert.equal(f.begin("bad-"+String(outputPins),d),null); | ||
| } | ||
| assert.equal(vm.setupPresentation(f.inventory,f.draft).canApply,true); | ||
| assert.equal(vm.setupPresentation(f.inventory,f.draft).canAssignMain,true); | ||
| }); | ||
|
|
||
| test("MV-8 readback mismatch remains pending after accepted ACK, then bounded timeout",()=>{ | ||
| const f=fixture(); | ||
| const pending=vm.setupAck(f.begin("pin-4").state,f.ack("pin-4")); | ||
| assert.equal(pending.phase,"VERIFYING"); | ||
| assert.equal(vm.setupReadback(pending,{...f.readback,device:{ | ||
| ...f.readback.device,enabledOutputs:[0,1] | ||
| }}),pending,"different driver output pins cannot settle this Apply"); | ||
| assert.equal(vm.setupReadback(pending,{...f.readback,device:{ | ||
| ...f.readback.device,enabledInputs:[1,2] | ||
| }}),pending,"different physical capture pins cannot settle this Apply"); | ||
| const old={...f.readback,device:{...f.readback.device,epoch:"39"}}; | ||
| assert.equal(vm.setupReadback(pending,old).phase,"STALE"); | ||
| const timeout=vm.setupTimeout(pending,"pin-4"); | ||
| assert.equal(timeout.phase,"TIMEOUT"); | ||
| assert.equal(vm.setupReadback(timeout,f.readback),timeout); | ||
| }); | ||
|
|
||
| test("MV-8 NEW device has driver-selected pins, never an old device mask",()=>{ | ||
| const f=fixture(),next={...f.draft, | ||
| backend:"Windows Audio",capture:"",playback:"Speakers", | ||
| inputPins:null,outputPins:null,rate:0,buffer:0}; | ||
| assert.equal(vm.setupPresentation(f.inventory,next).canApply,true); | ||
| const begun=f.begin("new-io",next); | ||
| assert.ok(begun); | ||
| assert.deepEqual(begun.request.config.enabledInputs,[]); | ||
| assert.deepEqual(begun.request.config.enabledOutputs,[]); | ||
| assert.equal(begun.state.pending.expected.requestedPins,null); | ||
| const ack=f.ack("new-io",{state:"ACCEPTED_MUTED",active:{ | ||
| ...f.active,deviceGeneration:41,backend:"Windows Audio", | ||
| captureDevice:"",playbackDevice:"Speakers",enabledInputs:[], | ||
| enabledOutputs:[0,1],rate:48000,buffer:256 | ||
| }}); | ||
| const verifying=vm.setupAck(begun.state,ack); | ||
| assert.equal(verifying.phase,"VERIFYING"); | ||
| const readback={...f.readback,device:{ | ||
| ...f.readback.device,backend:"Windows Audio",captureDevice:"", | ||
| playbackDevice:"Speakers",enabledInputs:[],enabledOutputs:[1,0] | ||
| }}; | ||
| assert.equal(vm.setupReadback(verifying,readback).phase,"ACCEPTED"); | ||
| }); | ||
|
|
||
| test("MV-8 DeviceVM remains pure; exactly one unchanged native Apply transport",()=>{ | ||
| const source=readFileSync("web/approved-device-view-model.js","utf8"); | ||
| const bridge=readFileSync("web/approved-native-bridge.js","utf8"); | ||
| const region=bridge.slice(bridge.indexOf(" // Compact DAW-style device preferences"), | ||
| bridge.indexOf(" function installFirstSoundMenu()")); | ||
| assert.match(source,/function validPinMask\(/); | ||
| assert.match(source,/function samePinMask\(/); | ||
| assert.match(source,/requestedPins:same\?/); | ||
| assert.match(source,/samePinMask\(requested.inputs,active.enabledInputs\)/); | ||
| assert.match(source,/samePinMask\(d.enabledOutputs,expected.enabledOutputs\)/); | ||
| assert.match(region,/deviceVM\.setupAck\(deviceState,ack\)/); | ||
| assert.match(bridge,/deviceVM\.setupReadback\(deviceState,next\)/); | ||
| assert.equal((region.match(/backend\.emitEvent\("arMixAction",begun\.request\)/g)||[]).length,1); | ||
| assert.doesNotMatch(source,/document\.|window\.|AudioWorklet|new AudioContext|localStorage/); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an operator edits pin checkboxes after a NEEDS_REMAP response and then chooses to reuse the existing mapping,
canReusePinsstill permits that action, butrequestedPinscaptures the edited draft. Insrc/Main.cpp:2488–2503, theconfirmRetainedPinMappingbranch deliberately ignores draft pin changes and confirms the currently installed mapping. Consequently, a successful native confirmation now becomesRECOVERY_REQUIRED, clears the remap opportunity, and incorrectly reports that hardware pins differ. Capture the active masks for retained-mapping confirmation, while retaining draft-mask verification for ordinary Apply. This preserves the existing native confirmation behavior required by the MVVM boundary.AGENTS.md reference: AGENTS.md:L39-L39
Useful? React with 👍 / 👎.