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
4 changes: 4 additions & 0 deletions .github/workflows/ui-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ on:
- 'tests/wire_graph_canonical_model.test.cjs'
- 'tests/wire_main_native_handoff_contract.test.cjs'
- 'tests/approved_native_m2_contract.test.cjs'
- 'tests/approved_device_pin_identity_contract.test.cjs'
- 'scripts/build_ui_css.py'
# Only user-facing GUI/bridge files are relevant. No PR metadata API gate.
pull_request:
Expand All @@ -53,6 +54,7 @@ on:
- 'tests/wire_main_native_handoff_contract.test.cjs'
- 'tests/ci_workflow_efficiency_test.mjs'
- 'tests/approved_native_m2_contract.test.cjs'
- 'tests/approved_device_pin_identity_contract.test.cjs'
- 'scripts/build_ui_css.py'
- '.github/workflows/ui-smoke.yml'
- '.github/workflows/pages-publish.yml'
Expand Down Expand Up @@ -129,6 +131,7 @@ jobs:
python tests/css_v28_restore.py
- name: Check native UI contracts, workflow policy, and WIRE without Chromium
run: |
node --test tests/approved_device_pin_identity_contract.test.cjs
node --test tests/floating_window_workspace_contract.test.mjs
node --test tests/rc_operator_workflow_contract.test.mjs
node --test tests/workstream_coordination_contract.test.mjs tests/chat_ci_dispatch_contract.test.mjs tests/gui_workflow_contract_test.mjs tests/plugin_ui_contract_test.mjs tests/ci_workflow_efficiency_test.mjs tests/fx_drag_reorder_contract_test.mjs tests/mixer_io_operator_contract_test.mjs tests/mixer_shell_contract_test.mjs tests/approved_native_m2_contract.test.cjs
Expand Down Expand Up @@ -493,6 +496,7 @@ jobs:
node --check web/mixer-io.js
node --check web/mixer-layout.js
node --test tests/workstream_coordination_contract.test.mjs tests/chat_ci_dispatch_contract.test.mjs tests/gui_workflow_contract_test.mjs tests/plugin_ui_contract_test.mjs tests/ci_workflow_efficiency_test.mjs tests/fx_drag_reorder_contract_test.mjs tests/mixer_io_operator_contract_test.mjs tests/mixer_shell_contract_test.mjs tests/approved_native_m2_contract.test.cjs
node --test tests/approved_device_pin_identity_contract.test.cjs
- name: Validate approved GUI checkpoint and single publisher
run: python tests/gui_baseline_lock_test.py
python tests/mixer_physical_keys_contract.py
Expand Down
170 changes: 170 additions & 0 deletions tests/approved_device_pin_identity_contract.test.cjs
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/);
});
55 changes: 48 additions & 7 deletions web/approved-device-view-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
"use strict";
const INTERNAL_BUS = "Internal BUS (read-only)";
const NONE = {label:"None",left:-1,right:-1};
// MV-8: JUCE device pin masks are SETS of physical port ordinals.
// Keep one pure contract for draft admission, ACK verification and
// independently installed device readback. Never compare array order,
// coerce floating ports, invent unavailable pins or mask a driver remap.
function validPinMask(pins,reportedNames) {
const upper=Array.isArray(reportedNames)?
Math.min(64,reportedNames.length):64;
return Array.isArray(pins) && pins.length<=upper &&
pins.every(p=>Number.isInteger(p)&&p>=0&&p<upper) &&
new Set(pins).size===pins.length;
}
function samePinMask(a,b) {
return validPinMask(a)&&validPinMask(b)&&a.length===b.length&&
a.every(pin=>b.includes(pin));
}
// The native contract validates endpoints before reaching this selector.
// Additional guards keep a lost/partial snapshot from advertising phantom pins.
function activeInputPins(snapshot) {
Expand Down Expand Up @@ -122,19 +137,27 @@
const noInput=type?.separate===true&&draft?.capture==="";
const inputValid=noInput||Boolean(type?.inputs?.includes(draft?.capture));
const outputValid=Boolean(outputOptions.includes(draft?.playback));
const selectedInputPins=Array.isArray(draft?.inputPins)?
draft.inputPins:Array.isArray(active.enabledInputs)?active.enabledInputs:[];
const selectedOutputPins=Array.isArray(draft?.outputPins)?
draft.outputPins:Array.isArray(active.enabledOutputs)?active.enabledOutputs:[];
const validSelection=!same ||
(validPinMask(selectedInputPins,active.inputNames)&&
validPinMask(selectedOutputPins,active.outputNames)&&
selectedOutputPins.length>=2&&
(!noInput||selectedInputPins.length===0));
const canApply=Boolean(type && draft?.backend && inputValid&&outputValid&&
(type.separate===true||draft.capture===draft.playback)&&
(!same||selectedOutputPins.length>=2));
validSelection);
const selectedPins=(key,enabled)=>Array.isArray(draft?.[key])?
draft[key]:Array.isArray(enabled)?enabled:[];
return {type,same,backendOptions:types.map(t=>t.name),
inputOptions,outputOptions,rateOptions:["0",...rates.map(String)],
bufferOptions:["0",...buffers.map(String)],
inputPins:selectedPins("inputPins",active.enabledInputs),
outputPins:selectedPins("outputPins",active.enabledOutputs),
canApply,canAssignMain:same&&draft?.outputPins?.length===2,
canApply,canAssignMain:same&&validSelection&&
selectedOutputPins.length===2,
canReusePins:same&&state.remapGeneration===active.deviceGeneration,
asio4allHint:draft?.backend==="ASIO"&&/asio4all/i.test(draft?.capture||""),
activeText:state.message||(active.open?
Expand Down Expand Up @@ -223,7 +246,12 @@
...(assignMain?{assignSelectedPlaybackPinsToMain:true}:{})}};
const pending={requestId,expected:{backend:draft.backend,
captureDevice:draft.capture,playbackDevice:draft.playback,
generation,rate,buffer},baselineEpoch:
generation,rate,buffer,
// An existing endpoint has an explicitly requested pin mask.
// A NEW endpoint's empty masks request JUCE driver defaults, not NONE.
requestedPins:same?{
inputs:request.config.enabledInputs.slice(),
outputs:request.config.enabledOutputs.slice()}:null},baselineEpoch:
Comment on lines +252 to +254

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Verify retained-pin confirmation against the active masks

When an operator edits pin checkboxes after a NEEDS_REMAP response and then chooses to reuse the existing mapping, canReusePins still permits that action, but requestedPins captures the edited draft. In src/Main.cpp:2488–2503, the confirmRetainedPinMapping branch deliberately ignores draft pin changes and confirms the currently installed mapping. Consequently, a successful native confirmation now becomes RECOVERY_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 👍 / 👎.

typeof baselineEpoch==="string"&&/^(0|[1-9]\d*)$/.test(baselineEpoch)?
baselineEpoch:null,ack:null};
return {request,state:{phase:"APPLYING",pending,message:"",
Expand All @@ -246,6 +274,19 @@
active.enabledOutputs.length>=2&&
Number.isFinite(active.rate)&&active.rate>0&&
Number.isInteger(active.buffer)&&active.buffer>0;
// A driver can open yet return a *different* physical mask from what the
// operator requested. Do not close the dialog or show a false success.
// Native may already have changed hardware, so do NOT claim rollback.
const requested=state.pending.expected.requestedPins;
if(accepted && requested &&
(!samePinMask(requested.inputs,active.enabledInputs)||
!samePinMask(requested.outputs,active.enabledOutputs)))
return {phase:"RECOVERY_REQUIRED",pending:null,remapGeneration:null,
message:"Applied device pins differ from selection · Refresh Audio I/O and verify routes"};
if(accepted && (!validPinMask(active.enabledInputs)||
!validPinMask(active.enabledOutputs)))
return {phase:"RECOVERY_REQUIRED",pending:null,remapGeneration:null,
message:"Device pin readback invalid · Refresh Audio I/O and verify routes"};
if(accepted)return {...state,phase:"VERIFYING",
pending:{...state.pending,ack:{
active:{backend:active.backend,captureDevice:active.captureDevice,
Expand Down Expand Up @@ -285,14 +326,14 @@
if(BigInt(epoch)<BigInt(expected.deviceGeneration))return state;
if(snapshot?.raw?.schemaVersion!==6||!Array.isArray(d?.enabledInputs)||
!Array.isArray(d.enabledOutputs))return state;
const equalPins=(a,b)=>Array.isArray(a)&&Array.isArray(b)&&
a.length===b.length&&a.every((n,i)=>n===b[i]);
// Endpoint lists are physical sets, not ordered callback-channel arrays.
// Require exact installed pins while tolerating a harmless reorder.
const same=d.backend===expected.backend&&
d.captureDevice===expected.captureDevice&&
d.playbackDevice===expected.playbackDevice&&
d.sampleRate===expected.rate&&d.bufferFrames===expected.buffer&&
equalPins(d.enabledInputs,expected.enabledInputs)&&
equalPins(d.enabledOutputs,expected.enabledOutputs);
samePinMask(d.enabledInputs,expected.enabledInputs)&&
samePinMask(d.enabledOutputs,expected.enabledOutputs);
if(!same)return state; // The driver or graph may still be publishing.
// Physical device Apply is a distinct transaction from ChannelId PCM
// admission. Legacy M4/G0 can have a verified open driver without an
Expand Down
Loading