Skip to content

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

Suno publish opens the page song's own menu, not the song a cover was made from

[._.]/ Adam Eivy8f31ea6feba8
diff --git a/client/src/lib/sunoPage.test.js b/client/src/lib/sunoPage.test.js
new file mode 100644
index 0000000000..81b8888cca
--- /dev/null
+++ b/client/src/lib/sunoPage.test.js
@@ -0,0 +1,52 @@
+// The Suno recipe's in-page steps (server/lib/sunoPage.js) run in the browser
+// through page.evaluate, so they are tested here against fixtures of the song
+// page, in the client's DOM environment.
+import { describe, it, expect } from 'vitest';
+import { markSunoSongMenu } from '../../../server/lib/sunoPage.js';
+
+const OWN = '11111111-1111-4111-8111-111111111111';
+const PARENT = '22222222-2222-4222-8222-222222222222';
+const OTHER = '33333333-3333-4333-8333-333333333333';
+const menu = (tag) => `<button aria-label="More options" data-tag="${tag}"></button>`;
+const 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;
+
+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.
+ document.body.innerHTML = `
+ <main><section><div>${card(PARENT, 'parent')}<div><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>`;
+ 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", () => {
+ document.body.innerHTML = `<aside>${card(OTHER, 'similar')}</aside>${card(OWN, 'own')}`;
+ expect(markSunoSongMenu(OWN.toUpperCase())).toBe(true);
+ expect(marked()).toBe('own');
+ });
+
+ it("fails rather than open another song's menu", () => {
+ document.body.innerHTML = `${card(PARENT, 'parent')}<aside>${card(OTHER, 'similar')}</aside>`;
+ expect(markSunoSongMenu(OWN)).toBe(false);
+ expect(marked()).toBeUndefined();
+ });
+
+ it('moves the mark when run again', () => {
+ document.body.innerHTML = `${card(OWN, 'a')}`;
+ markSunoSongMenu(OWN);
+ document.body.insertAdjacentHTML('afterbegin', `<section>${menu('b')}</section>`);
+ 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.js
new file mode 100644
index 0000000000..16263c17e6
--- /dev/null
+++ b/server/lib/sunoPage.js
@@ -0,0 +1,31 @@
+/**
+ * Suno song page (suno.com/song/<id>): in-page steps for the publish recipe.
+ * Each function runs INSIDE the page through Playwright's
+ * `page.evaluate(fn, arg)`, so it reads only `document` and its argument. The
+ * same functions run against fixture documents in the client's DOM tests.
+ */
+
+/**
+ * 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.
+ */
+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()));
+ });
+ 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.js
index 9ff59aeadd..a7bcc063c7 100644
--- a/server/services/musicVideo/publish/suno.js
+++ b/server/services/musicVideo/publish/suno.js
@@ -5,9 +5,12 @@
* Lyrics and styles are left exactly as the director made them.
*/
import { PUBLISH_STEP_TIMEOUT_MS as T, clickVisibleText, ensureToggleBeside, loginRequired, step } from './browser.js';
+import { markSunoSongMenu } from '../../../lib/sunoPage.js';
const label = 'Suno';
+const songIdOf = (url) => String(url).match(/\/song\/([0-9a-f-]{36})/i)?.[1] || null;
+
export const sunoAdapter = {
label,
async prepare(page, payload) {
@@ -15,7 +18,11 @@ export const sunoAdapter = {
await page.waitForTimeout(5000);
if (!(await page.locator("button[aria-label='More options']").count())) throw loginRequired(label, payload.songUrl);
await step(label, 'open the Publish dialog', async () => {
- await page.locator("button[aria-label='More options']").first().click({ timeout: T });
+ // A cover's page lists the song it covers first, with its own menu, so the
+ // page song's menu is picked by which song card it sits in.
+ const songId = songIdOf(payload.songUrl);
+ if (!songId || !(await page.evaluate(markSunoSongMenu, songId))) throw new Error("no menu for this page's own song");
+ 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 });
});