test(utils): cover scheduledMessages + lotusDenoiseUtils; fix AudioWorklet detect

- scheduledMessages.test.ts (9): pins the MSC4140 request shape (PUT to the room
  send endpoint with the org.matrix.msc4140.delay query, POST cancel/restart to
  /delayed_events with the unstable prefix), the delay-floor math (Math.max(1000,
  round(sendAt-now)) — "now"/past targets still yield a valid >=1000ms delay),
  rounding, and url-encoding.
- lotusDenoiseUtils.test.ts (9): model-catalog data integrity + isMLDenoiseSupported
  feature detection across AudioContext/webkit/getUserMedia.
- Bug found + fixed: isMLDenoiseSupported used `!!AudioWorkletNode`, a bare global
  reference that throws ReferenceError (not returns false) on a browser with
  AudioContext but no AudioWorkletNode binding. Switched to `typeof` so the
  detection helper reports unsupported instead of throwing. Regression test proven
  to fail on the old code.

Suite now 545 tests (4th real bug caught by the prevention work).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-30 19:01:25 -04:00
co-authored by Claude Opus 4.8
parent 1daa8aa9b1
commit 353bb59393
4 changed files with 235 additions and 2 deletions
+5 -1
View File
@@ -61,7 +61,11 @@ export const isMLDenoiseSupported = (): boolean => {
// 2. AudioWorklet (Real-time processing in a background thread)
// 3. getUserMedia (Microphone access)
const hasAudioContext = !!(window.AudioContext || (window as any).webkitAudioContext);
const hasAudioWorklet = hasAudioContext && !!AudioWorkletNode;
// Use `typeof` rather than `!!AudioWorkletNode`: on a browser that has
// AudioContext but no AudioWorkletNode binding (older Safari/Edge), a bare
// reference throws ReferenceError, making this feature-detection helper throw
// instead of returning false.
const hasAudioWorklet = hasAudioContext && typeof AudioWorkletNode !== 'undefined';
const hasGetUserMedia = !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia);
return hasAudioWorklet && hasGetUserMedia;