Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
Suno publish identifies the page song's menu by its title, not by ruling out other songs (#10372)
Adam Eivyef9372ca244f
diff --git a/client/src/lib/sunoPage.test.js b/client/src/lib/sunoPage.test.jsindex 81b8888cca..ea1a4088c4 100644--- a/client/src/lib/sunoPage.test.js+++ b/client/src/lib/sunoPage.test.js@@ -11,25 +11,45 @@ const menu = (tag) => `<button aria-label="More options" data-tag="${tag}"></butconst card = (id, tag) => `<div><div><a href="/song/${id}">Song</a></div><div>${menu(tag)}</div></div>`;const marked = () => document.querySelector('[data-portos-song-menu]')?.dataset.tag;+const title = '<h1>Page song</h1>';+const link = (id) => `<a href="/song/${id}">Song</a>`;+describe('markSunoSongMenu', () => {it("picks the cover's own menu, not the 'Cover of' card above it", () => {// Shaped like a live cover page: the parent's card and its menu come first,- // inside the header that holds the page song's menu.+ // inside the header that holds the page song's title and menu.document.body.innerHTML = `- <main><section><div>${card(PARENT, 'parent')}<div><span>styles</span>${menu('header')}</div></div></section>+ <main><section><div>${card(PARENT, 'parent')}<div>${title}<span>styles</span>${menu('header')}</div></div></section><aside>${card(OTHER, 'similar')}</aside></main><footer>${card(OWN, 'playbar')}</footer>`;expect(markSunoSongMenu(OWN)).toBe(true);expect(marked()).toBe('header');});- it("picks the song's menu on a page with no other song above it", () => {- document.body.innerHTML = `<main><section>${menu('header')}</section><aside>${card(OTHER, 'similar')}</aside></main>`;+ it("picks the page song's menu when the 'Cover of' link and its menu are separate siblings in the header", () => {+ // The shape a Suno redesign could produce: no card wraps the link and its+ // menu, so the header holds both menus. The parent's menu still follows the+ // parent's link; only the title's menu follows the title.+ document.body.innerHTML = `+ <header><div>${link(PARENT)}${menu('parent')}</div>${title}<div><button>Edit</button>${menu('header')}</div></header>+ <aside>${card(OTHER, 'similar')}</aside>`;expect(markSunoSongMenu(OWN)).toBe(true);expect(marked()).toBe('header');});- it("accepts a single-menu card that links to the page's own song, ignoring case", () => {+ it("fails rather than guess when two menus both follow the title", () => {+ document.body.innerHTML = `<header>${title}${menu('a')}${menu('b')}</header>`;+ expect(markSunoSongMenu(OWN)).toBe(false);+ expect(marked()).toBeUndefined();+ });++ it("fails when the parent's menu is the only menu after the title", () => {+ document.body.innerHTML = `<header>${title}${link(PARENT)}${menu('parent')}</header><aside>${card(OTHER, 'similar')}</aside>`;+ expect(markSunoSongMenu(OWN)).toBe(false);+ expect(marked()).toBeUndefined();+ });++ it("accepts a menu that follows a link to the page's own song, ignoring case", () => {document.body.innerHTML = `<aside>${card(OTHER, 'similar')}</aside>${card(OWN, 'own')}`;expect(markSunoSongMenu(OWN.toUpperCase())).toBe(true);expect(marked()).toBe('own');@@ -41,10 +61,15 @@ describe('markSunoSongMenu', () => {expect(marked()).toBeUndefined();});+ it('fails on a page with a menu but no title or own-song link to tie it to', () => {+ document.body.innerHTML = `<main><section>${menu('header')}</section></main>`;+ expect(markSunoSongMenu(OWN)).toBe(false);+ });+it('moves the mark when run again', () => {document.body.innerHTML = `${card(OWN, 'a')}`;markSunoSongMenu(OWN);- document.body.insertAdjacentHTML('afterbegin', `<section>${menu('b')}</section>`);+ document.body.innerHTML = `${title}${menu('b')}`;markSunoSongMenu(OWN);expect(document.querySelectorAll('[data-portos-song-menu]')).toHaveLength(1);expect(marked()).toBe('b');diff --git a/server/lib/sunoPage.js b/server/lib/sunoPage.jsindex 16263c17e6..cac50a01a3 100644--- a/server/lib/sunoPage.js+++ b/server/lib/sunoPage.js@@ -7,24 +7,34 @@/*** Mark the page song's own "More options" button with `data-portos-song-menu`- * and resolve true, or false when there is none. The page shows other songs'- * menus too: a cover's "Cover of" card for the song it covers (rendered above- * the header's menu), the Similar / By-artist list, and the playbar. A menu- * whose nearest song card holds just that one menu and links only to other- * songs belongs to one of those, so it is skipped.+ * and resolve true, or false when it cannot be told apart from another song's.+ * The page shows other songs' menus too: a cover's "Cover of" song for the song+ * it covers, the Similar / By-artist list, and the playbar. A menu is+ * attributed to the nearest song link or title heading before it in document+ * order, and counts as the page song's only when that is the page's `h1` title+ * or a link to the page's own song. The header menu follows the title; another+ * song's menu follows that song's link, wherever the two sit in the markup.+ * Two menus owned by the title is ambiguous, so it fails rather than guess.*/export function markSunoSongMenu(songId) {for (const old of document.querySelectorAll('[data-portos-song-menu]')) old.removeAttribute('data-portos-song-menu');- const menus = [...document.querySelectorAll("button[aria-label='More options']")];- const idOf = (a) => (a.getAttribute('href') || '').match(/\/song\/([0-9a-f-]{36})/i)?.[1]?.toLowerCase();- const own = menus.find((button) => {- let card = button.parentElement;- while (card && !card.querySelector('a[href*="/song/"]')) card = card.parentElement;- if (!card) return true;- const ids = new Set([...card.querySelectorAll('a[href*="/song/"]')].map(idOf).filter(Boolean));- const single = card.querySelectorAll("button[aria-label='More options']").length === 1;- return !(single && !ids.has(songId.toLowerCase()));- });+ const wanted = songId.toLowerCase();+ const byTitle = [];+ const byOwnLink = [];+ let owner = null;+ for (const el of document.querySelectorAll("h1, a[href*='/song/'], button[aria-label='More options']")) {+ if (el.tagName === 'BUTTON') {+ if (owner === 'title') byTitle.push(el);+ else if (owner === 'own') byOwnLink.push(el);+ } else if (el.tagName === 'H1') {+ owner = 'title';+ } else {+ const id = (el.getAttribute('href') || '').match(/\/song\/([0-9a-f-]{36})/i)?.[1]?.toLowerCase();+ owner = id === wanted ? 'own' : 'other';+ }+ }+ if (byTitle.length > 1) return false;+ const own = byTitle[0] || byOwnLink[0];if (!own) return false;own.setAttribute('data-portos-song-menu', '');return true;diff --git a/server/services/musicVideo/publish/suno.js b/server/services/musicVideo/publish/suno.jsindex dd8ff27389..d28b0a00b8 100644--- a/server/services/musicVideo/publish/suno.js+++ b/server/services/musicVideo/publish/suno.js@@ -23,7 +23,7 @@ export const sunoAdapter = {// A share link or redirect can land on the song under another URL; the page's own wins.const songId = songIdOf(page.url()) || songIdOf(payload.songUrl);if (!songId) throw new Error(`no song id in ${payload.songUrl}`);- if (!(await page.evaluate(markSunoSongMenu, songId))) throw new Error("no menu for this page's own song (only other songs' menus were found)");+ if (!(await page.evaluate(markSunoSongMenu, songId))) throw new Error("no menu could be tied to this page's own song (its title or own-song link)");await page.locator('[data-portos-song-menu]').click({ timeout: T });await page.locator('[role=menuitem]').filter({ hasText: /^Publish$/ }).first().click({ timeout: T });await page.locator('[role=dialog]').first().waitFor({ timeout: T });