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
55 changes: 55 additions & 0 deletions tests/approved_native_m2_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,3 +1780,58 @@ test("M5 logical-only editor proves the exact ACK revision and full FX/WIRE effe
assert.match(bridge,/beforeInsertCatalogs:/);
assert.match(bridge,/beforeEdges:/);
});


test("M5 native presentation policy is pure and preserves editable ChannelId identity rules",()=>{
const n=protocol.validPresentationName,c=protocol.validPresentationColor,
i=protocol.validPresentationIcon;
for(const valid of ["Vocal","Channel 07","Mic 🎙","Guitar","X".repeat(30)])
assert.equal(n(valid),true);
for(const invalid of [""," X","X ","X".repeat(31),"line\nbreak","name\twith tab",null,123])
assert.equal(n(invalid),false);
for(const valid of ["#abcdef","#AABBCC","#012345"])
assert.equal(c(valid),true);
for(const invalid of ["abc","#fff","#abcdefghijkl","#xyzxyz",undefined,23])
assert.equal(c(invalid),false);
for(const valid of ["🎙","♫","♬","⊞","◎"])
assert.equal(i(valid),true);
for(const invalid of ["🐙","A",null,0,"🎙♫"])
assert.equal(i(invalid),false);
const bridge=read("web/approved-native-bridge.js");
assert.match(bridge,/const legalName=protocol\.validPresentationName/);
assert.match(bridge,/const legalColor=protocol\.validPresentationColor/);
assert.match(bridge,/const legalIcon=protocol\.validPresentationIcon/);
assert.match(bridge,/const operatorMessage=protocol\.operatorMessage/);
assert.doesNotMatch(bridge,/const operatorMessage = message =>/);
});

test("M5 native operator status renders useful actions without exposing internal QA state",()=>{
const f=protocol.operatorMessage;
const pairs=[
["HARDWARE_FAT_PENDING","Mixer ready"],
["NATIVE PCM GRAPH pending","Mixer ready"],
["FAT PENDING; output muted","Output muted"],
["FAT FAILED; output enabled","Output enabled"],
["DEVICE_DISCONNECTED","Audio device unavailable · Open Audio I/O"],
["Native routing rejected","Routing not changed · Check the connection and try again"],
["NATIVE: STALE_NATIVE_WIRE_GRAPH","Routing not changed · Check the connection and try again"],
["Native routing failed","Routing not changed · Check the connection and try again"],
["Native VST3 plugin rejected","Effect change failed · Previous settings kept"],
["WIRE applying, waiting for graph revision","Updating channel routing…"],
["Native VST3 plugin loading","Applying effect…"],
["native FX rejected","Effect change failed · Previous settings kept"],
["INVALID_NATIVE_SNAPSHOT","Change not applied · Previous mixer settings kept"],
["ACK_READBACK_EFFECT_MISMATCH","Change not applied · Previous mixer settings kept"],
["PENDING_NATIVE_ACK","Applying mixer changes…"],
["Mixer input accepted","Mixer input accepted"],
["",""],
[" User visible message ","User visible message"]
];
for(const [raw,expected] of pairs)
assert.equal(f(raw),expected,`status ${JSON.stringify(raw)} should stay operator-safe`);
// No network, DOM, snapshot or runtime can be accessed by this pure helper.
const state=acceptedFixture(),before=clone(state);
f("Native routing rejected");f("PENDING_NATIVE_ACK");
assert.deepEqual(state,before);
assert.ok(protocol.normalizeSnapshot(state).admitted);
});
12 changes: 4 additions & 8 deletions tests/native_caption_wire_geometry_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ assert.match(chrome, /const auto advance = juce::GlyphArrangement::getStringWidt
assert.match(chrome, /2026 SonKuPik/);
assert.doesNotMatch(chrome, /NATIVE SESSION/);
assert.ok(bridge.includes('classList?.add?.("armix-native-desktop")'));
assert.match(bridge, /const operatorMessage = message =>/);
const operatorCopy=require('../web/approved-native-contract.js').operatorMessage;
assert.match(bridge, /const operatorMessage=protocol\.operatorMessage/);
assert.match(bridge, /const NEEDS_REMAP="Audio connection lost"/);
assert.match(bridge, /MutationObserver\(sanitize\)/);
assert.match(bridge, /const nodes=\[transport,info,warning\]\.filter\(Boolean\)/);
assert.match(bridge, /const operatorTransport=operatorMessage\(transport\)/);
assert.match(bridge, /return "Mixer ready"/);
assert.equal(operatorCopy('HARDWARE FAT PENDING'),'Mixer ready');
assert.doesNotMatch(bridge, /FAT PENDING/);
assert.doesNotMatch(bridge, /HARDWARE FAT PENDING/);
assert.match(bridge, /"OUTPUT ENABLED"/);
Expand Down Expand Up @@ -77,12 +78,7 @@ console.log('Native titlebar + supplied SVG + WIRE geometry contract PASS');
const vm = require('node:vm');
// User-visible status copy must never expose internal admission/QA or revision
// codes even if the preview or native error path emits one later.
const messageStart=bridge.indexOf('const operatorMessage = message => {');
const messageEnd=bridge.indexOf('\n const status = message => {',messageStart);
assert.ok(messageStart>0&&messageEnd>messageStart,'operator copy adapter missing');
const operatorCopy=vm.runInNewContext(
bridge.slice(messageStart,messageEnd).replace('const operatorMessage','var operatorMessage')+
'\noperatorMessage;',{}, {filename:'native-operator-copy.js'});
assert.equal(typeof operatorCopy,'function','native presentation helper must be exported');
for(const raw of [
'NATIVE PCM · HARDWARE FAT PENDING',
'NATIVE PCM GRAPH ACCEPTED · FAT PENDING · device 3 · graph 3 · roster 94',
Expand Down
49 changes: 6 additions & 43 deletions web/approved-native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
const channelPresentation=new Map();
let appearanceRevision="0",appearanceWritable=false;
let pendingIdentity=null,identityRequestSerial=0;
const legalName=name=>typeof name==="string"&&name.length>0&&name.length<=30&&
name===name.trim()&&!/[\x00-\x1f\x7f]/.test(name);
const legalColor=color=>typeof color==="string"&&/^#[0-9a-fA-F]{6}$/.test(color);
const legalIcon=icon=>typeof icon==="string"&&
["♩","♫","♬","🎙","🎸","🎹","🥁","🎧","▥","◉","◎","⊞"].includes(icon);
// Pure policy shared with Node tests; native controls still own the edit.
const legalName=protocol.validPresentationName;
const legalColor=protocol.validPresentationColor;
const legalIcon=protocol.validPresentationIcon;
const displayNameFor=ch=>channelPresentation.get(ch.id)?.name||ch.name;
// Legacy WebView aliases are an import queue ONLY, never rendered or written
// as authoritative state. Each imported row must receive a native ACK plus
Expand Down Expand Up @@ -263,44 +262,8 @@
Math.random().toString(36).slice(2,10);
// Human-facing presentation is isolated from native diagnostic state.
// Internal identifiers remain in engine logs, never footer, dialog or toast.
const operatorMessage = message => {
const raw=String(message??"").trim();
if(!raw)return "";
// A product never advertises unfinished internal QA/FAT certification to
// operators. This is a display-only adapter, not an audio-state override.
if(/\b(?:HARDWARE\s+)?FAT\s+(?:PENDING|PASSED|FAILED)\b|\b(?:NATIVE\s+)?PCM\s+(?:GRAPH|HARDWARE|FAT)\b|\b(?:PENDING_ACCEPTED_SNAPSHOT|HARDWARE_FAT_PENDING)\b/i.test(raw)){
if(/\b(?:output muted|monitor off)\b/i.test(raw))return "Output muted";
if(/\b(?:monitor on|output enabled|output active)\b/i.test(raw))return "Output enabled";
return "Mixer ready";
}
const internalCode=/\b[A-Z][A-Z0-9]{2,}(?:_[A-Z0-9]+)+\b/.test(raw);
if(internalCode ||
/\b(FAT|PCM|ACK|readback|admission|admitted|graph|roster|epoch|revision|M[0-9]|JUCE|callback|worker|fixture|reference|mockup|simulated|demo|legacy|native|authoritative)\b/i.test(raw)){
if(/\b(device|driver|audio interface)\b|DEVICE_/i.test(raw) &&
/\b(disconnect|unavailable|not ready|not open|not found|failed)\b|_(FAILED|ERROR|DISCONNECTED|UNAVAILABLE)/i.test(raw))
return "Audio device unavailable · Open Audio I/O";
if(/\b(WIRE|route|routing)\b/i.test(raw)){
if(/\b(reject|fail|error|timed out|not applied|unavailable)\b/i.test(raw))
return "Routing not changed · Check the connection and try again";
if(/\b(pending|await|verif|applying|completing)\w*/i.test(raw))
return "Updating channel routing…";
return "Channel routing updated";
}
if(/\b(VST3|plugin|effect|FX)\b/i.test(raw)){
if(/\b(reject|fail|error|timed out)\b/i.test(raw))
return "Effect change failed · Previous settings kept";
if(/\b(pending|await|verif|loading|applying)\w*/i.test(raw))
return "Applying effect…";
return "Effect settings updated";
}
if(/\b(error|failed|rejected|timed out|invalid|unavailable|not applied)\b|_(FAILED|ERROR|REJECTED|STALE|INVALID|TIMEOUT|MISSING)(?:\b|_)/i.test(raw))
return "Change not applied · Previous mixer settings kept";
if(/\b(pending|awaiting|verifying|saving|processing|applying|loading|deleting)\b|_PENDING\b|PENDING_/i.test(raw))
return "Applying mixer changes…";
return "Mixer settings updated";
}
return raw;
};
// Exact human-facing status policy, independently testable without WebView.
const operatorMessage=protocol.operatorMessage;
const status = message => {
lastNativeError = message; // raw engine state remains inspectable internally
const text = operatorMessage(message);
Expand Down
50 changes: 49 additions & 1 deletion web/approved-native-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,54 @@
const fields = (item, names) => object(item) && names.every(key => Object.prototype.hasOwnProperty.call(item, key));
const isBool = x => typeof x === "boolean";
const unique = values => new Set(values).size === values.length;
// Pure native UI presentation policy: no DOM, physical status rewrite,
// optimistically accepted graph or alternative mixer renderer.
const validPresentationName=name=>typeof name==="string"&&name.length>0&&name.length<=30&&
name===name.trim()&&!/[\x00-\x1f\x7f]/.test(name);
const validPresentationColor=color=>typeof color==="string"&&/^#[0-9a-fA-F]{6}$/.test(color);
const validPresentationIcon=icon=>typeof icon==="string"&&
["♩","♫","♬","🎙","🎸","🎹","🥁","🎧","▥","◉","◎","⊞"].includes(icon);

const operatorMessage = message => {
const raw=String(message??"").trim();
if(!raw)return "";
// A product never advertises unfinished internal QA/FAT certification to
// operators. This is a display-only adapter, not an audio-state override.
if(/\b(?:HARDWARE\s+)?FAT\s+(?:PENDING|PASSED|FAILED)\b|\b(?:NATIVE\s+)?PCM\s+(?:GRAPH|HARDWARE|FAT)\b|\b(?:PENDING_ACCEPTED_SNAPSHOT|HARDWARE_FAT_PENDING)\b/i.test(raw)){
if(/\b(?:output muted|monitor off)\b/i.test(raw))return "Output muted";
if(/\b(?:monitor on|output enabled|output active)\b/i.test(raw))return "Output enabled";
return "Mixer ready";
}
const failure=/\b(reject(?:ed|ion)?|fail(?:ed|ure)?|error|timed out|not applied|unavailable|invalid)\b|(?:^|[^A-Z0-9])(FAILED|ERROR|REJECTED|STALE|INVALID|TIMEOUT|MISSING|UNSUPPORTED|UNKNOWN|MISMATCH|CONFLICTING)(?:\b|_)/i.test(raw);
const internalCode=/\b[A-Z][A-Z0-9]{2,}(?:_[A-Z0-9]+)+\b/.test(raw);
if(internalCode ||
/\b(FAT|PCM|ACK|readback|admission|admitted|graph|roster|epoch|revision|M[0-9]|JUCE|callback|worker|fixture|reference|mockup|simulated|demo|legacy|native|authoritative)\b/i.test(raw)){
if(/\b(device|driver|audio interface)\b|DEVICE_/i.test(raw) &&
/\b(disconnect|unavailable|not ready|not open|not found|failed)\b|_(FAILED|ERROR|DISCONNECTED|UNAVAILABLE)/i.test(raw))
return "Audio device unavailable · Open Audio I/O";
if(/\b(WIRE|route|routing)\b|(?:^|_)(?:WIRE|ROUTING)(?:_|$)/i.test(raw)){
if(failure)
return "Routing not changed · Check the connection and try again";
if(/\b(pending|await|verif|applying|completing)\w*/i.test(raw))
return "Updating channel routing…";
return "Channel routing updated";
}
if(/\b(VST3|plugin|effect|FX)\b|(?:^|_)(?:VST3|PLUGIN|FX)(?:_|$)/i.test(raw)){
if(failure)
return "Effect change failed · Previous settings kept";
if(/\b(pending|await|verif|loading|applying)\w*/i.test(raw))
return "Applying effect…";
return "Effect settings updated";
}
if(failure)
return "Change not applied · Previous mixer settings kept";
if(/\b(pending|awaiting|verifying|saving|processing|applying|loading|deleting)\b|_PENDING\b|PENDING_/i.test(raw))
return "Applying mixer changes…";
return "Mixer settings updated";
}
return raw;
};

function normalizeSnapshot(raw) {
if (!fields(raw, ["schemaVersion","productionCallbackLive","device","graph","telemetry"]) ||
raw.schemaVersion !== 6 || !isBool(raw.productionCallbackLive)) return null;
Expand Down Expand Up @@ -538,5 +586,5 @@
}
return Object.freeze({subscribe,onSnapshot,onAck,intent,state,expire});
}
return Object.freeze({decimal,cmp,normalizeSnapshot,readbackProvesIntent,logicalReadbackProves,diagnoseFirstSound,createController});
return Object.freeze({decimal,cmp,normalizeSnapshot,readbackProvesIntent,logicalReadbackProves,diagnoseFirstSound,createController,validPresentationName,validPresentationColor,validPresentationIcon,operatorMessage});
});
Loading