const { test } = require('node:test'); const assert = require('node:assert/strict'); const { readFileSync } = require('node:fs'); const { join } = require('node:path'); const app = readFileSync(join(__dirname, 'app.js'), 'utf8'); test('the persisted engine is Standard by default and upgrades missing JamesDSP settings safely', () => { assert.match(app, /jamesDsp: \{ enabled: false, preset: 'flat', params: \{\} \}/); assert.match(app, /enabled: saved\.enabled === true/); assert.match(app, /preset: typeof saved\.preset === 'string' \? saved\.preset : 'flat'/); assert.match(app, /settings: normalizeJamesDspSettings\(\{ \.\.\.DEFAULT_SETTINGS, \.\.\.\(loaded\.settings \|\| \{\}\) \}\)/); assert.match(app, /data\.settings = normalizeJamesDspSettings\(\{ \.\.\.DEFAULT_SETTINGS, \.\.\.payload\.settings \}\)/); }); test('live JamesDSP shares the existing iOS gate and never stacks over EqRender copies', () => { assert.match(app, /const available = \(\) => !!AC && \(!isIOS \|\| data\.settings\.liveAudioIOS === true\)/); assert.match(app, /if \(data\.settings\?\.jamesDsp\?\.enabled\) return null/); assert.match(app, /const active = \(\) => EQ\.isIOS\(\) && WEB && !data\.settings\?\.jamesDsp\?\.enabled/); assert.match(app, /if \(rendered\(\)\) throw new Error\('This song is already playing a Standard processed copy\./); }); test('EQ creates no second context or element source and passes Standard fallback routing to the controller', () => { assert.equal((app.match(/\.createMediaElementSource\(/g) || []).length, 0); assert.match(app, /st\.ctx = AudioGraph\.context\(\)/); assert.match(app, /AudioGraph\.connect\(el, st\.filters\[0\]\)/); assert.match(app, /standardInput: st\.filters\[0\]/); assert.match(app, /dspController\.setLevelDb\(st\.levelDb\)/); assert.match(app, /if \(data\.settings\.jamesDsp\?\.enabled\) \{[\s\S]{0,450}startDsp\(\)/); });