From 3a9594963664c2593418a42f62c73660f8350ff5 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Nov 2026 21:38:16 +0000 Subject: [PATCH 1/3] test(radio): Lock Radio Alhara away from the retired RadioJar mount RADIO-22 was MEDIA_ERR_SRC_NOT_SUPPORTED mapped to PLAY_ERROR on single-mode loads of the retired n03.radiojar.com mount (HTTP 404). Root cause already fixed on main by #456 via toPlaybackInput. Add media-path and reporting regressions so the override cannot regress, and so genuine unsupported-stream diagnostics stay reportable. Fixes RADIO-22 https://avoidquest.sentry.io/issues/RADIO-22 Changelog: skip Co-authored-by: Francesco Castrovilli --- .../media-element-playback-source.test.ts | 49 +++++++++++++++++++ .../src/lib/playback-action-errors.test.ts | 13 +++++ 2 files changed, 62 insertions(+) diff --git a/apps/radio/src/lib/audio/playback/media-element-playback-source.test.ts b/apps/radio/src/lib/audio/playback/media-element-playback-source.test.ts index 2c20a4642..c2f14111a 100644 --- a/apps/radio/src/lib/audio/playback/media-element-playback-source.test.ts +++ b/apps/radio/src/lib/audio/playback/media-element-playback-source.test.ts @@ -342,6 +342,55 @@ describe("MediaElementPlaybackSource native playback", () => { } ); + // RADIO-22: Chrome maps the retired RadioJar 404 to MEDIA_ERR_SRC_NOT_SUPPORTED. + // Single-mode loads through toPlaybackInput; the override must keep that mount + // off the media element so readiness never rejects with PLAY_ERROR. + test("single-mode Radio Alhara loads never attach the retired RadioJar mount", async () => { + const browser = installBrowser(); + const onError = mock(() => undefined); + const source = new MediaElementPlaybackSource(null, "native", { + onError, + }); + const retiredMount = "https://n03.radiojar.com/78cxy6wkxtzuv"; + const currentMount = "https://stream.radioalhara.net/ra"; + try { + const audio = browser.audio(); + audio.load = () => { + if (audio.src === retiredMount) { + queueMicrotask(() => { + audio.error = { + code: MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED, + } as MediaError; + audio.emit("error"); + }); + return; + } + if (audio.src === currentMount) { + queueMicrotask(() => { + audio.error = null; + audio.emit("canplay"); + }); + } + }; + const input = toPlaybackInput({ + name: "Radio Alhara", + streamUrl: retiredMount, + }); + await source.load(input); + expect(input).toMatchObject({ + format: "progressive", + src: currentMount, + }); + expect(audio.loadSources).toEqual([currentMount]); + expect(audio.src).toBe(currentMount); + expect(onError).not.toHaveBeenCalled(); + expect(source.status).not.toBe("error"); + } finally { + source.cleanup(); + browser.restore(); + } + }); + test("a failed start stays stopped when late media events arrive", async () => { const browser = installBrowser(); const onPlaying = mock(() => undefined); diff --git a/apps/radio/src/lib/playback-action-errors.test.ts b/apps/radio/src/lib/playback-action-errors.test.ts index a28c42763..0eca5e2f5 100644 --- a/apps/radio/src/lib/playback-action-errors.test.ts +++ b/apps/radio/src/lib/playback-action-errors.test.ts @@ -21,6 +21,9 @@ test("support limits preserve guidance; ordinary media failures still reach Sent "The operation is not supported.", "NotSupportedError" ); + // RADIO-22 symptom: MEDIA_ERR_SRC_NOT_SUPPORTED mapped by mediaElementError. + // Keep reporting unexpected stream failures; do not silence the diagnostic. + const unsupportedStream = new Error("Audio stream format is not supported"); try { expect(toRuntimeAudioError(support).message).toBe(support.safeMessage); capturePlaybackActionError( @@ -35,6 +38,16 @@ test("support limits preserve guidance; ordinary media failures still reach Sent ); expect(capture).toHaveBeenCalledTimes(1); expect(capture.mock.calls[0]?.[0]).toBe(failure); + const unsupportedAction = createPlaybackActionError({ + cause: unsupportedStream, + mode: "single", + }); + expect(unsupportedAction.userMessage).toBe( + "The stream could not be reached. Check the station URL and try again." + ); + capturePlaybackActionError(unsupportedAction); + expect(capture).toHaveBeenCalledTimes(2); + expect(capture.mock.calls[1]?.[0]).toBe(unsupportedStream); } finally { capture.mockRestore(); enabled.mockRestore(); From 4e85d20f5bdd5cab1d0d877c99c7d383c70a434e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Nov 2026 22:49:31 +0000 Subject: [PATCH 2/3] fix(radio): Match retired stream mounts by host and path Rewrite saved Radio Alhara RadioJar URLs even with query or hash, without overmatching lookalike hosts or paths. Distinguish unsupported-format guidance from unreachable-stream guidance. Cover single-mode AudioManager remount of a query-bearing RadioJar URL. Changelog: Radio Alhara keeps playing from older saved links, and unsupported stream formats get clearer guidance. Co-authored-by: Francesco Castrovilli --- .../lib/audio/manager/audio-manager.test.ts | 28 ++++++ .../media-element-playback-source.test.ts | 91 ++++++++++--------- .../lib/audio/playback/playback-input.test.ts | 40 ++++++-- .../src/lib/audio/playback/playback-input.ts | 33 ++++++- apps/radio/src/lib/node-playback.test.ts | 2 +- .../src/lib/playback-action-errors.test.ts | 7 ++ apps/radio/src/lib/playback-action-errors.ts | 17 +++- 7 files changed, 164 insertions(+), 54 deletions(-) diff --git a/apps/radio/src/lib/audio/manager/audio-manager.test.ts b/apps/radio/src/lib/audio/manager/audio-manager.test.ts index 1efa4f996..cc94bf808 100644 --- a/apps/radio/src/lib/audio/manager/audio-manager.test.ts +++ b/apps/radio/src/lib/audio/manager/audio-manager.test.ts @@ -139,6 +139,34 @@ afterEach(() => { }); describe("AudioManager", () => { + // RADIO-22: single-mode playSound must go through toPlaybackInput so a + // persisted RadioJar mount (including query variants) never reaches media. + test("single-mode playSound remounts a persisted Radio Alhara RadioJar URL", async () => { + const harness = createMediaPlaybackHarness(); + try { + const { manager, browser, effects } = harness; + effects.connectGraph = mock(async () => true); + const soundId = manager.createSound( + { + name: "Radio Alhara", + streamUrl: "https://n03.radiojar.com/78cxy6wkxtzuv?source=radio", + }, + "single:alhara", + "native", + "station" + ); + const starting = manager.playSound(soundId); + await flushMicrotasks(); + expect(browser.audio().loadSources).toEqual([ + "https://stream.radioalhara.net/ra", + ]); + browser.audio().emit("canplay"); + await starting; + } finally { + harness.restore(); + } + }); + test.each([ [Number.POSITIVE_INFINITY, 1], [120, 1], diff --git a/apps/radio/src/lib/audio/playback/media-element-playback-source.test.ts b/apps/radio/src/lib/audio/playback/media-element-playback-source.test.ts index c2f14111a..a47bb3ade 100644 --- a/apps/radio/src/lib/audio/playback/media-element-playback-source.test.ts +++ b/apps/radio/src/lib/audio/playback/media-element-playback-source.test.ts @@ -345,51 +345,56 @@ describe("MediaElementPlaybackSource native playback", () => { // RADIO-22: Chrome maps the retired RadioJar 404 to MEDIA_ERR_SRC_NOT_SUPPORTED. // Single-mode loads through toPlaybackInput; the override must keep that mount // off the media element so readiness never rejects with PLAY_ERROR. - test("single-mode Radio Alhara loads never attach the retired RadioJar mount", async () => { - const browser = installBrowser(); - const onError = mock(() => undefined); - const source = new MediaElementPlaybackSource(null, "native", { - onError, - }); - const retiredMount = "https://n03.radiojar.com/78cxy6wkxtzuv"; - const currentMount = "https://stream.radioalhara.net/ra"; - try { - const audio = browser.audio(); - audio.load = () => { - if (audio.src === retiredMount) { - queueMicrotask(() => { - audio.error = { - code: MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED, - } as MediaError; - audio.emit("error"); - }); - return; - } - if (audio.src === currentMount) { - queueMicrotask(() => { - audio.error = null; - audio.emit("canplay"); - }); - } - }; - const input = toPlaybackInput({ - name: "Radio Alhara", - streamUrl: retiredMount, - }); - await source.load(input); - expect(input).toMatchObject({ - format: "progressive", - src: currentMount, + test.each([ + "https://n03.radiojar.com/78cxy6wkxtzuv", + "https://n03.radiojar.com/78cxy6wkxtzuv?source=radio", + ])( + "single-mode Radio Alhara loads never attach the retired RadioJar mount (%s)", + async (retiredMount) => { + const browser = installBrowser(); + const onError = mock(() => undefined); + const source = new MediaElementPlaybackSource(null, "native", { + onError, }); - expect(audio.loadSources).toEqual([currentMount]); - expect(audio.src).toBe(currentMount); - expect(onError).not.toHaveBeenCalled(); - expect(source.status).not.toBe("error"); - } finally { - source.cleanup(); - browser.restore(); + const currentMount = "https://stream.radioalhara.net/ra"; + try { + const audio = browser.audio(); + audio.load = () => { + if (audio.src.includes("n03.radiojar.com/78cxy6wkxtzuv")) { + queueMicrotask(() => { + audio.error = { + code: MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED, + } as MediaError; + audio.emit("error"); + }); + return; + } + if (audio.src !== "") { + queueMicrotask(() => { + audio.error = null; + audio.emit("canplay"); + }); + } + }; + const input = toPlaybackInput({ + name: "Radio Alhara", + streamUrl: retiredMount, + }); + await source.load(input); + expect(input).toMatchObject({ + format: "progressive", + src: currentMount, + }); + expect(audio.loadSources).toEqual([currentMount]); + expect(audio.src).toBe(currentMount); + expect(onError).not.toHaveBeenCalled(); + expect(source.status).not.toBe("error"); + } finally { + source.cleanup(); + browser.restore(); + } } - }); + ); test("a failed start stays stopped when late media events arrive", async () => { const browser = installBrowser(); diff --git a/apps/radio/src/lib/audio/playback/playback-input.test.ts b/apps/radio/src/lib/audio/playback/playback-input.test.ts index 79774620b..1e8e1e70e 100644 --- a/apps/radio/src/lib/audio/playback/playback-input.test.ts +++ b/apps/radio/src/lib/audio/playback/playback-input.test.ts @@ -50,22 +50,46 @@ describe("toPlaybackInput", () => { }); test("upgrades persisted Radio Alhara URLs to its first-party stream", () => { + const currentMount = "https://stream.radioalhara.net/ra"; + for (const streamUrl of [ + "https://n03.radiojar.com/78cxy6wkxtzuv", + "https://n03.radiojar.com/78cxy6wkxtzuv?source=radio", + "https://N03.RadioJar.com/78cxy6wkxtzuv#legacy", + ]) { + expect( + toPlaybackInput({ + name: "Radio Alhara", + streamUrl, + }) + ).toMatchObject({ + format: "progressive", + live: true, + src: currentMount, + }); + } expect( toPlaybackInput({ - name: "Radio Alhara", - streamUrl: "https://n03.radiojar.com/78cxy6wkxtzuv", + name: "Lookalike", + streamUrl: "https://example.com/78cxy6wkxtzuv", + }) + ).toMatchObject({ src: "https://example.com/78cxy6wkxtzuv" }); + expect( + toPlaybackInput({ + name: "Embedded path", + streamUrl: + "https://evil.example/https://n03.radiojar.com/78cxy6wkxtzuv", }) ).toMatchObject({ - format: "progressive", - live: true, - src: "https://stream.radioalhara.net/ra", + src: "https://evil.example/https://n03.radiojar.com/78cxy6wkxtzuv", }); expect( toPlaybackInput({ - name: "Lookalike", - streamUrl: "https://example.com/78cxy6wkxtzuv", + name: "Path sibling", + streamUrl: "https://n03.radiojar.com/78cxy6wkxtzuv/extra", }) - ).toMatchObject({ src: "https://example.com/78cxy6wkxtzuv" }); + ).toMatchObject({ + src: "https://n03.radiojar.com/78cxy6wkxtzuv/extra", + }); }); test("upgrades persisted NTS relay URLs to Web Audio compatible sources", () => { diff --git a/apps/radio/src/lib/audio/playback/playback-input.ts b/apps/radio/src/lib/audio/playback/playback-input.ts index 8c0f48b3a..c73269578 100644 --- a/apps/radio/src/lib/audio/playback/playback-input.ts +++ b/apps/radio/src/lib/audio/playback/playback-input.ts @@ -25,13 +25,44 @@ const STREAM_URL_OVERRIDES: Readonly> = { "https://streams.radiomast.io/nts2", }; +/** Host + path identity only; query/hash and trailing slash must not bypass. */ +function streamOverrideIdentity(url: string): string | null { + try { + const parsed = new URL(url); + if (parsed.protocol !== "http:" && parsed.protocol !== "https:") { + return null; + } + const path = + parsed.pathname.length > 1 && parsed.pathname.endsWith("/") + ? parsed.pathname.slice(0, -1) + : parsed.pathname; + return `${parsed.protocol}//${parsed.hostname.toLowerCase()}${path}`; + } catch { + return null; + } +} + +const STREAM_URL_OVERRIDE_BY_IDENTITY = new Map( + Object.entries(STREAM_URL_OVERRIDES).flatMap(([from, to]) => { + const identity = streamOverrideIdentity(from); + return identity ? [[identity, to] as const] : []; + }) +); + +function resolveStreamUrlOverride(streamUrl: string): string | undefined { + return ( + STREAM_URL_OVERRIDES[streamUrl] ?? + STREAM_URL_OVERRIDE_BY_IDENTITY.get(streamOverrideIdentity(streamUrl) ?? "") + ); +} + export function toPlaybackInput( radio: Radio, sourceKind?: RadioSourceKind ): PlaybackInput { const src = isRadioBlackoutStreamUrl(radio.streamUrl) ? RADIO_BLACKOUT_STREAM_URL - : (STREAM_URL_OVERRIDES[radio.streamUrl] ?? radio.streamUrl); + : (resolveStreamUrlOverride(radio.streamUrl) ?? radio.streamUrl); const format = radio.streamFormat ?? (radio.platformMetadata?.platform === "radio-browser" && diff --git a/apps/radio/src/lib/node-playback.test.ts b/apps/radio/src/lib/node-playback.test.ts index 8179d11af..6912e0171 100644 --- a/apps/radio/src/lib/node-playback.test.ts +++ b/apps/radio/src/lib/node-playback.test.ts @@ -1562,7 +1562,7 @@ describe("Node Playback starts", () => { expect(getPlaybackChannelRuntime(channelOf("bad")).error).toMatchObject({ code: "PLAY_ERROR", message: - "The stream could not be reached. Check the station URL and try again.", + "Playback could not start. Check the station stream and try again.", }); expect(harness.context.reportError).toHaveBeenCalledTimes(1); expect(harness.context.reportError).toHaveBeenCalledWith( diff --git a/apps/radio/src/lib/playback-action-errors.test.ts b/apps/radio/src/lib/playback-action-errors.test.ts index 0eca5e2f5..c3ae25ce7 100644 --- a/apps/radio/src/lib/playback-action-errors.test.ts +++ b/apps/radio/src/lib/playback-action-errors.test.ts @@ -43,6 +43,13 @@ test("support limits preserve guidance; ordinary media failures still reach Sent mode: "single", }); expect(unsupportedAction.userMessage).toBe( + "This audio format is not supported. Check the station stream or try another source." + ); + const unreachableAction = createPlaybackActionError({ + cause: new Error("Audio stream failed to load"), + mode: "single", + }); + expect(unreachableAction.userMessage).toBe( "The stream could not be reached. Check the station URL and try again." ); capturePlaybackActionError(unsupportedAction); diff --git a/apps/radio/src/lib/playback-action-errors.ts b/apps/radio/src/lib/playback-action-errors.ts index f68a69a16..5f64073dc 100644 --- a/apps/radio/src/lib/playback-action-errors.ts +++ b/apps/radio/src/lib/playback-action-errors.ts @@ -94,7 +94,22 @@ function getFriendlyPlaybackErrorMessage( ) { return "Playback source is no longer available. Reload the station and try again."; } - if (messageIncludesAny(rawMessage, ["network", "fetch", "stream"])) { + // mediaElementError phrases: format/decode before reachability. Do not match + // bare "stream" — that mislabels format failures as URL problems. + if (messageIncludesAny(rawMessage, ["format is not supported"])) { + return "This audio format is not supported. Check the station stream or try another source."; + } + if (messageIncludesAny(rawMessage, ["could not be decoded"])) { + return "The stream could not be decoded. Try another station or format."; + } + if ( + messageIncludesAny(rawMessage, [ + "network", + "fetch", + "failed to load", + "timed out", + ]) + ) { return "The stream could not be reached. Check the station URL and try again."; } From ae93ba0074bf82e9328a977e90fd832a36e66cb4 Mon Sep 17 00:00:00 2001 From: Francesco Castrovilli Date: Sun, 8 Nov 2026 00:24:26 +0100 Subject: [PATCH 3/3] fix(radio): Preserve distinct stream origins in playback overrides --- .../src/lib/audio/playback/playback-input.test.ts | 12 ++++++++++++ apps/radio/src/lib/audio/playback/playback-input.ts | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/radio/src/lib/audio/playback/playback-input.test.ts b/apps/radio/src/lib/audio/playback/playback-input.test.ts index 1e8e1e70e..cb9712fad 100644 --- a/apps/radio/src/lib/audio/playback/playback-input.test.ts +++ b/apps/radio/src/lib/audio/playback/playback-input.test.ts @@ -55,6 +55,7 @@ describe("toPlaybackInput", () => { "https://n03.radiojar.com/78cxy6wkxtzuv", "https://n03.radiojar.com/78cxy6wkxtzuv?source=radio", "https://N03.RadioJar.com/78cxy6wkxtzuv#legacy", + "https://n03.radiojar.com:443/78cxy6wkxtzuv/", ]) { expect( toPlaybackInput({ @@ -92,6 +93,17 @@ describe("toPlaybackInput", () => { }); }); + test.each([ + "https://n03.radiojar.com:8443/78cxy6wkxtzuv", + "http://n03.radiojar.com:8080/78cxy6wkxtzuv?source=radio", + "https://radio.syg.ma:8443/audio.ogg", + "https://stream-relay-geo.ntslive.net:8443/stream", + ])("preserves a distinct stream origin (%s)", (streamUrl) => { + expect(toPlaybackInput({ name: "Other origin", streamUrl })).toMatchObject({ + src: streamUrl, + }); + }); + test("upgrades persisted NTS relay URLs to Web Audio compatible sources", () => { expect( toPlaybackInput({ diff --git a/apps/radio/src/lib/audio/playback/playback-input.ts b/apps/radio/src/lib/audio/playback/playback-input.ts index c73269578..ef8620484 100644 --- a/apps/radio/src/lib/audio/playback/playback-input.ts +++ b/apps/radio/src/lib/audio/playback/playback-input.ts @@ -25,7 +25,7 @@ const STREAM_URL_OVERRIDES: Readonly> = { "https://streams.radiomast.io/nts2", }; -/** Host + path identity only; query/hash and trailing slash must not bypass. */ +/** Preserve the origin; query/hash and trailing slash must not bypass. */ function streamOverrideIdentity(url: string): string | null { try { const parsed = new URL(url); @@ -36,7 +36,7 @@ function streamOverrideIdentity(url: string): string | null { parsed.pathname.length > 1 && parsed.pathname.endsWith("/") ? parsed.pathname.slice(0, -1) : parsed.pathname; - return `${parsed.protocol}//${parsed.hostname.toLowerCase()}${path}`; + return `${parsed.origin}${path}`; } catch { return null; }