collabSupport/tests/atlasAzmWs.test.js
jmcqueen 5e54ea6f57 Add /atlasdiag live AZM diagnostic with source alerts and monitor auto-off.
Ports Atlas /check as /atlasdiag: Hub resolve, UI tunnel, WebSocket report
for sources/zones/accessories, low source dB warnings, and auto-disable of
the monitor speaker when left on after troubleshooting.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-29 17:59:17 -04:00

94 lines
2.8 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {
formatCheckMarkdown,
formatUptime,
getSourceLevelDb,
isLowSourceLevel,
} from '../integrations/atlas/azmWs.js';
test('formatUptime: hours vs days', () => {
assert.equal(formatUptime(12), '12.0 hours');
assert.equal(formatUptime(48), '2.0 days');
assert.equal(formatUptime(null), 'Unknown');
});
test('isLowSourceLevel: -80 to -70 dB band', () => {
assert.equal(isLowSourceLevel(-65), false);
assert.equal(isLowSourceLevel(-70), true);
assert.equal(isLowSourceLevel(-75), true);
assert.equal(isLowSourceLevel(-80), true);
assert.equal(isLowSourceLevel(-85), false);
assert.equal(isLowSourceLevel(null), false);
});
test('getSourceLevelDb: prefers meter avg over gain setpoint', () => {
assert.equal(getSourceLevelDb({ volume: { avg: -72.1 }, db: '-20' }), -72.1);
assert.equal(getSourceLevelDb({ db: '-74.5' }), -74.5);
assert.equal(getSourceLevelDb({}), null);
});
test('formatCheckMarkdown: shows monitor auto-disable success', () => {
const md = formatCheckMarkdown({
projectName: 'Test Store',
deviceName: 'US002547AMP',
uptimeHours: 12,
sources: [],
zones: [],
accessories: [],
monitorSpeaker: { status: 'Off', inputChannel: '<none>' },
}, {
storeNumber: '2547',
monitorDisable: {
attempted: true,
ok: true,
previousChannel: 'Sales Floor',
},
});
assert.match(md, /Monitor speaker — Off \(auto-disabled; was listening to \*\*Sales Floor\*\*\)/);
});
test('formatCheckMarkdown: shows monitor auto-disable failure', () => {
const md = formatCheckMarkdown({
projectName: 'Test Store',
deviceName: 'US002547AMP',
uptimeHours: 12,
sources: [],
zones: [],
accessories: [],
monitorSpeaker: { status: 'On', gain: '-18', inputChannel: 'Sales Floor' },
}, {
monitorDisable: {
attempted: true,
ok: false,
error: 'Monitor still On',
},
});
assert.match(md, /Monitor speaker — On/);
assert.match(md, /auto-disable failed: Monitor still On/);
});
test('formatCheckMarkdown: flags low source levels', () => {
const md = formatCheckMarkdown({
projectName: 'Test Store',
deviceName: 'US002547AMP',
model: 'AZM-8',
uptimeHours: 30,
sources: [
{ name: 'BGM', muted: false, db: '-20', volume: null },
{ name: 'Mic', muted: false, db: '-74', volume: { low: -76, avg: -74.2, high: -72 } },
],
zones: [],
accessories: [],
monitorSpeaker: { status: 'Not present' },
}, { storeNumber: '2547', deviceStatus: 'online' });
assert.match(md, /⚠️ 1 source\(s\) with low input level/);
assert.match(md, /⚠️ .*Mic.*low level: -74\.2 dB/);
assert.doesNotMatch(md, /⚠️ .*BGM/);
assert.match(md, /\*\*Sources\*\*/);
assert.match(md, /\*\*Zones\*\*/);
});