diff --git a/app/listen/[id]/route.ts b/app/listen/[id]/route.ts
index 442c15370..33c472c98 100644
--- a/app/listen/[id]/route.ts
+++ b/app/listen/[id]/route.ts
@@ -15,8 +15,13 @@ export async function GET(
if (value) campaign.set(key, value.slice(0, 100));
}
const suffix = campaign.size ? `?${escape(campaign.toString())}` : "";
+ const spotifyUnconfigured =
+ config.capabilities?.spotify.clientConfiguration === "unconfigured";
+ const spotifyLabel = spotifyUnconfigured
+ ? "Open player"
+ : "Sign in with Spotify";
return new Response(
- `
${escape(config.name)} · Recoup${config.artwork ? `
` : ""}${escape(config.name)}
Choose where to listen.
${config.spotifyUrl ? `Sign in with SpotifyOpen Spotify` : ""}${config.appleUrl ? `Sign in with AppleOpen Apple Music` : ""}`,
+ `${escape(config.name)} · Recoup${config.artwork ? `
` : ""}${escape(config.name)}
Choose where to listen.
${config.spotifyUrl ? `${spotifyUnconfigured ? "Spotify sign-in is unavailable.
" : ""}${!spotifyUnconfigured || config.freePlayback === "audio" ? `${spotifyLabel}` : ""}Open Spotify` : ""}${config.appleUrl ? `Sign in with AppleOpen Apple Music` : ""}`,
{
headers: {
"Content-Type": "text/html; charset=utf-8",
diff --git a/lib/players/__tests__/playerCapabilities.test.ts b/lib/players/__tests__/playerCapabilities.test.ts
new file mode 100644
index 000000000..f8617d10c
--- /dev/null
+++ b/lib/players/__tests__/playerCapabilities.test.ts
@@ -0,0 +1,148 @@
+import { afterEach, beforeEach, expect, it, vi } from "vitest";
+import { getPlayerConfig } from "../getPlayerConfig";
+import { GET } from "@/app/listen/[id]/route";
+import { spotifyRuntimeHarness } from "@/lib/sites/__tests__/fixtures/spotifyRuntimeHarness";
+const id = "10000000-0000-4000-8000-000000000001";
+const capabilities = (configured = false) => ({
+ version: 1,
+ spotify: {
+ clientConfiguration: configured ? "configured" : "unconfigured",
+ releaseConfigured: true,
+ premiumEligibility: "unknown",
+ tokenStatus: "unknown",
+ scopeStatus: "unknown",
+ playbackSupport: "unknown",
+ },
+});
+const base = {
+ playerId: id,
+ name: "Release
",
+ spotifyUrl: "https://open.spotify.com/track/abc",
+ appleUrl: "https://music.apple.com/us/album/song/123",
+ revision: 1,
+ freePlayback: "spotify",
+};
+beforeEach(() => vi.stubGlobal("fetch", vi.fn()));
+afterEach(() => {
+ vi.unstubAllGlobals();
+ vi.unstubAllEnvs();
+});
+function serve(value: unknown) {
+ vi.mocked(fetch).mockImplementation(async () => Response.json(value));
+}
+it("retains a validated v1 observation without exposing unexpected properties", async () => {
+ serve({
+ ...base,
+ capabilities: { ...capabilities(), privateToken: "never" },
+ });
+ expect(await getPlayerConfig(id, new URLSearchParams())).toMatchObject({
+ capabilities: capabilities(),
+ });
+ const result = await getPlayerConfig(id, new URLSearchParams());
+ expect(result).not.toHaveProperty("capabilities.privateToken");
+});
+it.each([
+ undefined,
+ { version: 2, spotify: { clientConfiguration: "unconfigured" } },
+])("ignores legacy/future capability shapes (%j)", async (value) => {
+ serve({ ...base, capabilities: value });
+ expect(
+ (await getPlayerConfig(id, new URLSearchParams())).capabilities,
+ ).toBeUndefined();
+});
+it.each([
+ { version: 1 },
+ { version: 1, spotify: { ...capabilities().spotify, tokenStatus: "valid" } },
+ {
+ version: 1,
+ spotify: { ...capabilities().spotify, releaseConfigured: "yes" },
+ },
+])("rejects malformed v1 (%j)", async (value) => {
+ serve({ ...base, capabilities: value });
+ await expect(getPlayerConfig(id, new URLSearchParams())).rejects.toThrow();
+});
+it.each(["spotify", "audio"])(
+ "avoids an impossible sign-in invitation while retaining %s fallback",
+ async (mode) => {
+ serve({ ...base, freePlayback: mode, capabilities: capabilities() });
+ const response = await GET(
+ new Request(
+ "https://app.recoupable.dev/listen/" +
+ id +
+ "?campaign=%22%3E%3Cscript%3E",
+ ),
+ { params: Promise.resolve({ id }) },
+ );
+ const html = await response.text();
+ expect(html).toContain("Spotify sign-in is unavailable.");
+ expect(html).not.toContain("Sign in with Spotify");
+ expect(html).toContain("Open Spotify");
+ expect(html.includes("Open player")).toBe(mode === "audio");
+ expect(html).toContain("Sign in with Apple");
+ expect(html).toContain("Release <img src=x>");
+ expect(html).not.toContain("