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

fix: keep Suno Hook windows reachable and aligned (#11636)

[._.]/8c283a2b996a
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.js
index e39a9eba8a..a77ec813e0 100644
--- a/scripts/ci-test-plan.js
+++ b/scripts/ci-test-plan.js
@@ -50,6 +50,7 @@ export const BROWSER_SUITES = [
'server/services/musicVideo/documentTemplates/shared/lyricType.browser.test.js',
'server/services/musicVideo/documentTemplates/shared/toonWorld.browser.test.js',
'server/services/musicVideo/publish/linkedin.browser.test.js',
+ 'server/services/musicVideo/publish/sunoHook.browser.test.js',
];
const browserSuitesIn = (paths) => uniqueSorted(paths.filter((path) => BROWSER_SUITES.includes(path)));
diff --git a/server/services/musicVideo/publish/index.test.js b/server/services/musicVideo/publish/index.test.js
index dacdf67d48..45971b6be1 100644
--- a/server/services/musicVideo/publish/index.test.js
+++ b/server/services/musicVideo/publish/index.test.js
@@ -74,6 +74,24 @@ async function readyProject() {
}
describe('publish drafts (#9282)', () => {
+ it('rejects an unreachable Hook cut before connecting a browser or uploading', async () => {
+ const { id } = await projects.createProject({ name: 'Synthetic hook' });
+ await projects.mutateProjectRecord(id, current => ({ project: { ...current,
+ audioAnalysis: { durationSec: 258 }, publishKit: {
+ links: { song: 'https://suno.com/song/12345678-abcd-4abc-8abc-123456789abc' },
+ master: { renderHistoryId: current.renderHistoryId },
+ exports: [{ kind: 'vertical-9x16', filename: 'late.mp4', startSec: 199, endSec: 225 }],
+ },
+ } }));
+ const { connect } = fakeBrowser();
+ const hook = adapter({ label: 'Suno Hook' });
+ await expect(preparePublishDraft(id, 'sunoHook', {}, { connect, adapters: { sunoHook: hook },
+ platforms: { sunoHook: { enabled: true, account: null } },
+ })).rejects.toMatchObject({ status: 422, message: expect.stringMatching(/latest Suno Hook window start 3:18/) });
+ expect(connect).not.toHaveBeenCalled();
+ expect(hook.prepare).not.toHaveBeenCalled();
+ });
+
it('fills a Substack post on the publication named under Where you post', async () => {
const { id } = await projects.createProject({ name: 'Release' });
await projects.mutateProjectRecord(id, (current) => ({ project: { ...current, publishKit: {
diff --git a/server/services/musicVideo/publish/payloads.js b/server/services/musicVideo/publish/payloads.js
index a28731454b..f0648c202f 100644
--- a/server/services/musicVideo/publish/payloads.js
+++ b/server/services/musicVideo/publish/payloads.js
@@ -303,11 +303,17 @@ const BUILDERS = {
const cut = pickVerticalCut(project, options);
const caption = text(kit.copy?.tiktok?.caption) || text(kit.copy?.shorts?.description).slice(0, 300);
const duration = Number(project?.audioAnalysis?.durationSec);
+ if (!Number.isFinite(duration) || duration <= 0) throw missing('Analyze the song audio first so the Suno Hook window can be checked against its duration');
+ const startSec = Math.max(0, Number(cut.startSec) || 0);
+ const latestStart = Math.max(0, duration - 60);
+ // Keep the rendered video and its audio together. A 60-second window must
+ // fit; for shorter songs, only zero is eligible. Never shift only the audio.
+ if (startSec > latestStart) throw missing(`This cut starts at ${clock(startSec)}, after the latest Suno Hook window start ${clock(latestStart)}. Choose or render an earlier 9:16 cut`);
return {
video: { dir: 'videos', name: cut.filename }, songUrl: song, songId, title: text(project?.name),
- durationSec: Number.isFinite(duration) && duration > 0 ? duration : null,
+ durationSec: duration,
// The audio window opens where the cut's own audio does.
- startSec: Math.max(0, Number(cut.startSec) || 0),
+ startSec,
cutLayout: cut.layout,
caption, showLyrics: options.showLyrics === true,
};
diff --git a/server/services/musicVideo/publish/sunoHook.browser.test.js b/server/services/musicVideo/publish/sunoHook.browser.test.js
new file mode 100644
index 0000000000..f7f02fd527
--- /dev/null
+++ b/server/services/musicVideo/publish/sunoHook.browser.test.js
@@ -0,0 +1,110 @@
+import { afterAll, beforeAll, describe, expect, it } from 'vitest';
+import { existsSync } from 'node:fs';
+import { writeFile } from 'node:fs/promises';
+import { join } from 'node:path';
+import { chromium } from 'playwright-core';
+import { browserSuiteCanRun } from '../../../lib/browserSuiteGate.js';
+import { startOwnedBrowserFixture } from '../../../test/browserFixture.js';
+import { sunoHookAdapter } from './sunoHook.js';
+
+const chrome = [process.env.CHROME_PATH, chromium.executablePath(),
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '/usr/bin/google-chrome', '/usr/bin/chromium',
+].find(path => path && existsSync(path));
+const canRun = browserSuiteCanRun('Suno Hook draft browser', { Chrome: chrome });
+const ID = '12345678-abcd-4abc-8abc-123456789abc';
+
+// Every request is intercepted. This synthetic page deliberately gives the
+// waveform an offscreen midpoint, as a translated long song strip would have.
+function fixtureHtml(kind, initiallyOn) {
+ return String.raw`<!doctype html><html><head><style>
+ body { margin: 0; overflow: hidden; }
+ [hidden] { display: none !important; }
+ .waveform { position: absolute; left: -3873px; top: 150px; width: 5550px; height: 80px; background: gray; }
+ #pill { position: absolute; top: 100px; }
+ #songs { position: absolute; top: 300px; }
+ #post { position: absolute; top: 400px; }
+ </style></head><body>
+ <input type="file" accept="video/mp4"><button id="select">Select Song</button>
+ <div id="songs" role="dialog" hidden><textarea placeholder="Search by song name"></textarea>
+ <div><a href="/song/${ID}">Synthetic song</a><button id="use">Use</button><button>A</button><button>B</button></div>
+ </div>
+ <span id="pill" class="rounded-full font-mono">2:38</span><div class="waveform"></div>
+ <button id="next">Next</button>
+ <section id="post" hidden><textarea placeholder="Add a caption..."></textarea><div id="lyrics"></div><button id="publish">Post</button></section>
+ <script>
+ window.windowAt = 158; window.publishClicks = 0; window.points = []; window.dragCount = 0;
+ const strip = document.querySelector('.waveform');
+ let down = null;
+ strip.addEventListener('mousedown', event => { down = event.clientX; window.points.push([event.clientX, event.clientY]); });
+ document.addEventListener('mouseup', event => {
+ if (down === null) return;
+ window.points.push([event.clientX, event.clientY]); window.dragCount++;
+ window.windowAt = Math.max(0, window.windowAt - (event.clientX - down) / 21.4);
+ document.getElementById('pill').textContent = Math.floor(window.windowAt / 60) + ':' + String(Math.floor(window.windowAt % 60)).padStart(2, '0');
+ down = null;
+ });
+ document.getElementById('select').onclick = () => document.getElementById('songs').hidden = false;
+ document.getElementById('use').onclick = () => document.getElementById('songs').hidden = true;
+ document.getElementById('next').onclick = () => document.getElementById('post').hidden = false;
+ document.getElementById('publish').onclick = () => window.publishClicks++;
+ const kind = '${kind}';
+ const host = document.getElementById('lyrics');
+ const root = kind === 'shadow' ? host.attachShadow({ mode: 'open' }) : host;
+ const checked = ${initiallyOn};
+ const toggle = named => '<button role="switch" ' + (named ? 'aria-label="Show Lyrics" ' : '') + 'aria-checked="' + checked + '">Toggle</button>';
+ if (kind === 'checkbox') root.innerHTML = '<label>Show Lyrics<input type="checkbox" ' + (checked ? 'checked' : '') + '></label>';
+ else if (kind === 'fallback') root.innerHTML = '<div><span>Show Lyrics</span>' + toggle(false) + '</div>';
+ else if (kind !== 'missing') root.innerHTML = toggle(true) + (kind === 'ambiguous' ? toggle(true) : '');
+ for (const button of root.querySelectorAll('[role=switch]')) button.onclick = () => setTimeout(() => button.setAttribute('aria-checked', button.getAttribute('aria-checked') !== 'true'), 50);
+ </script></body></html>`;
+}
+
+describe.skipIf(!canRun)('Suno Hook synthetic draft UI in Chrome', () => {
+ let fixture;
+ let video;
+ beforeAll(async () => {
+ fixture = await startOwnedBrowserFixture({ chromium, launchOptions: { executablePath: chrome, headless: true } });
+ video = join(fixture.temp, 'synthetic.mp4');
+ await writeFile(video, 'Synthetic upload fixture');
+ }, 30000);
+ afterAll(() => fixture?.close());
+
+ it.each([
+ { kind: 'checkbox', initial: true, wanted: false },
+ { kind: 'shadow', initial: false, wanted: true },
+ { kind: 'fallback', initial: true, wanted: false },
+ { kind: 'ambiguous', initial: true, wanted: false, problem: /multiple Show Lyrics controls/ },
+ { kind: 'missing', initial: true, wanted: false, problem: /no unambiguous Show Lyrics label/ },
+ ])('drags the visible strip and verifies $kind lyrics without posting', async ({ kind, initial, wanted, problem }) => {
+ const context = await fixture.browser.newContext({ viewport: { width: 1000, height: 700 }, serviceWorkers: 'block' });
+ const page = await context.newPage();
+ const errors = [], unexpected = [];
+ page.on('pageerror', error => errors.push(error.message));
+ page.waitForTimeout = async () => { expect(errors).toEqual([]); };
+ await context.route('**/*', route => {
+ if (route.request().url() === 'https://suno.com/hooks/create' && route.request().resourceType() === 'document') {
+ return route.fulfill({ contentType: 'text/html', body: fixtureHtml(kind, initial) });
+ }
+ unexpected.push(route.request().resourceType());
+ return route.abort();
+ });
+ try {
+ const prepare = sunoHookAdapter.prepare(page, { video: { path: video }, songId: ID, title: 'Synthetic song',
+ durationSec: 258, startSec: 20, caption: 'Synthetic caption', showLyrics: wanted });
+ if (problem) await expect(prepare).rejects.toThrow(problem);
+ else {
+ expect(await prepare).toMatchObject({ showLyrics: wanted, caption: 'Synthetic caption' });
+ const control = page.locator('[role=switch],input[type=checkbox]');
+ expect(await control.evaluate(el => el.getAttribute('aria-checked') === 'true' || el.checked === true)).toBe(wanted);
+ }
+ const state = await page.evaluate(() => ({ at: window.windowAt, points: window.points, drags: window.dragCount, posts: window.publishClicks }));
+ expect(Math.abs(state.at - 20)).toBeLessThanOrEqual(1);
+ expect(state.drags).toBeGreaterThan(1);
+ expect(state.points.every(([x, y]) => x >= 0 && x < 1000 && y >= 150 && y <= 230)).toBe(true);
+ expect(state.posts).toBe(0);
+ expect(await page.locator('input[type=file]').evaluate(input => input.files[0].name)).toBe('synthetic.mp4');
+ expect(unexpected).toEqual([]);
+ expect(errors).toEqual([]);
+ } finally { await context.close(); }
+ }, 30000);
+});
diff --git a/server/services/musicVideo/publish/sunoHook.js b/server/services/musicVideo/publish/sunoHook.js
index 129b6929f1..6c040748ab 100644
--- a/server/services/musicVideo/publish/sunoHook.js
+++ b/server/services/musicVideo/publish/sunoHook.js
@@ -81,9 +81,15 @@ async function setWindowStart(page, startSec) {
if (Math.abs(at - target) <= READBACK_TOLERANCE_SEC) return at;
const box = await page.locator(WAVEFORM).first().boundingBox();
if (!box) throw new Error('no waveform to set the window on');
- const x = box.x + box.width / 2;
- const y = box.y + box.height / 2;
- const reach = Math.max(20, box.width / 2 - 16); // a drag from the middle stays on the waveform
+ const viewport = page.viewportSize() ?? await page.evaluate(() => ({ width: innerWidth, height: innerHeight }));
+ // The strip may be thousands of pixels wide and translated offscreen. Its
+ // bounding-box midpoint is then outside the browser, where dragging does nothing.
+ const left = Math.max(0, box.x), right = Math.min(viewport.width, box.x + box.width);
+ const top = Math.max(0, box.y), bottom = Math.min(viewport.height, box.y + box.height);
+ if (right - left <= 32 || bottom <= top) throw new Error('no visible waveform area to drag');
+ const x = (left + right) / 2;
+ const y = (top + bottom) / 2;
+ const reach = (right - left) / 2 - 16;
let pxPerSec = WAVEFORM_PX_PER_SEC;
let direction = 1; // +1: dragging right moves the window earlier
let still = 0;
@@ -110,6 +116,41 @@ async function setWindowStart(page, startSec) {
return at;
}
+async function setShowLyrics(page, wanted) {
+ const named = page.getByRole('switch', { name: /^Show Lyrics$/i })
+ .or(page.getByRole('checkbox', { name: /^Show Lyrics$/i }));
+ let control = named;
+ const count = await named.count();
+ if (count > 1) throw new Error('multiple Show Lyrics controls');
+ if (!count) {
+ // Older UI labels an adjacent control rather than giving it an accessible
+ // name. Locator traversal also works inside open shadow roots.
+ let row = page.getByText('Show Lyrics', { exact: true });
+ if (await row.count() !== 1) throw new Error('no unambiguous Show Lyrics label');
+ for (let depth = 0; depth < 8; depth += 1) {
+ row = row.locator('..');
+ control = row.locator('[role=switch],input[type=checkbox]');
+ const matches = await control.count();
+ if (matches > 1) throw new Error('multiple controls beside Show Lyrics');
+ if (matches === 1) break;
+ }
+ if (await control.count() !== 1) throw new Error('no Show Lyrics switch');
+ }
+ const read = () => control.evaluate(el => {
+ const aria = el.getAttribute('aria-checked');
+ return aria === 'true' ? true : aria === 'false' ? false : typeof el.checked === 'boolean' ? el.checked : null;
+ });
+ const before = await read();
+ if (before === null) throw new Error('cannot read Show Lyrics state');
+ if (before !== wanted) await control.click({ timeout: T });
+ await page.waitForFunction(({ element, wanted }) => {
+ const aria = element.getAttribute('aria-checked');
+ const state = aria === 'true' ? true : aria === 'false' ? false : typeof element.checked === 'boolean' ? element.checked : null;
+ return state === wanted;
+ }, { element: await control.elementHandle(), wanted }, { timeout: T });
+ return wanted;
+}
+
export const sunoHookAdapter = {
label,
async prepare(page, payload) {
@@ -127,25 +168,7 @@ export const sunoHookAdapter = {
await page.locator('textarea[placeholder="Add a caption..."]').first().waitFor({ timeout: T });
});
if (payload.caption) await step(label, 'write the caption', () => page.locator('textarea[placeholder="Add a caption..."]').first().fill(payload.caption));
- // Show Lyrics is on by default; a cut that carries its own lyric text would show them twice.
- const lyrics = payload.showLyrics ? true : await step(label, 'turn off Show Lyrics', async () => {
- const state = await page.evaluate(() => {
- const text = [...document.querySelectorAll('span,div,label')].find((e) => e.children.length === 0 && e.textContent.trim() === 'Show Lyrics');
- let node = text;
- for (let i = 0; i < 8 && node; i += 1) {
- node = node.parentElement;
- const sw = node?.querySelector('[role=switch],input[type=checkbox]');
- if (sw) {
- const on = sw.getAttribute('aria-checked') === 'true' || sw.checked === true;
- if (on) sw.click();
- return true;
- }
- }
- return null;
- });
- if (state === null) throw new Error('no Show Lyrics switch');
- return false;
- });
+ const lyrics = await step(label, 'set Show Lyrics', () => setShowLyrics(page, payload.showLyrics === true));
return {
songUrl: payload.songUrl, windowStart, caption: payload.caption, showLyrics: lyrics,
...(payload.cutLayout === 'fit' ? { cut: 'Fitted: the 16:9 frame over a blurred fill, so it reads as a square' } : {}),
diff --git a/server/services/musicVideo/publish/sunoHook.test.js b/server/services/musicVideo/publish/sunoHook.test.js
index 48ba3f44ab..5c96f664e4 100644
--- a/server/services/musicVideo/publish/sunoHook.test.js
+++ b/server/services/musicVideo/publish/sunoHook.test.js
@@ -27,6 +27,24 @@ describe('Suno Hook payload', () => {
} });
expect(buildPublishPayload('sunoHook', fitted)).toMatchObject({ startSec: 20, cutLayout: 'fit', video: { name: 'kit.mp4' } });
});
+ const fitted = (duration, startSec) => project({ audioAnalysis: { durationSec: duration }, excerpts: [], publishKit: {
+ ...project().publishKit, master: { renderHistoryId: 'r1' },
+ exports: [{ kind: 'vertical-9x16', filename: 'window.mp4', startSec, endSec: startSec + 20, layout: 'fit' }],
+ } });
+ it('uses the actual fractional duration and restricts shorter songs to zero', () => {
+ expect(buildPublishPayload('sunoHook', fitted(258.75, 198.75)).startSec).toBe(198.75);
+ expect(() => buildPublishPayload('sunoHook', fitted(258.75, 198.76))).toThrow(/earlier 9:16 cut/);
+ expect(buildPublishPayload('sunoHook', fitted(40, 0))).toMatchObject({ durationSec: 40, startSec: 0 });
+ expect(() => buildPublishPayload('sunoHook', fitted(40, 1))).toThrow(/earlier 9:16 cut/);
+ expect(() => buildPublishPayload('sunoHook', fitted(null, 0))).toThrow(/Analyze the song audio/);
+ });
+ it('rejects a late default cut but keeps an explicitly selected earlier video and audio together', () => {
+ const p = project();
+ p.excerpts.push({ id: 'late', status: 'complete', aspect: '9:16', filename: 'late.mp4', startSec: 150, endSec: 170,
+ dependencies: captureMusicVideoEvidence(p, { startSec: 150, endSec: 170 }) });
+ expect(() => buildPublishPayload('sunoHook', p)).toThrow(/latest Suno Hook window start 2:07/);
+ expect(buildPublishPayload('sunoHook', p, { cutId: 'e1' })).toMatchObject({ startSec: 42, video: { name: 'cut.mp4' } });
+ });
it('refuses a missing song URL and a project with no vertical cut', () => {
expect(() => buildPublishPayload('sunoHook', project({ publishKit: {} }))).toThrow(/Suno song URL/);
expect(() => buildPublishPayload('sunoHook', project({ excerpts: [] }))).toThrow(/9:16/);
@@ -51,7 +69,7 @@ describe('pickSongRow', () => {
const fmt = (sec) => `${Math.floor(sec / 60)}:${String(Math.floor(sec % 60)).padStart(2, '0')}`;
const PILL = 'pointer-events-none rounded-full border-2 px-2 pt-1 pb-1.5 font-mono text-xs';
function hookPage({ windowAt = 158, pxPerSec = 22.2, stuckAt = null, restored = false } = {}) {
- const state = { windowAt, clicked: [], drags: 0 };
+ const state = { windowAt, clicked: [], drags: 0, lyrics: true };
const leaf = (text, cls, parentText = text) => ({ children: [], textContent: text, className: cls, offsetParent: {}, parentElement: { textContent: parentText } });
const dom = {
'span,div': () => [
@@ -86,6 +104,14 @@ function hookPage({ windowAt = 158, pxPerSec = 22.2, stuckAt = null, restored =
url: () => 'https://suno.com/hooks/create',
waitForTimeout: async () => {},
locator: (sel) => locator(sel),
+ viewportSize: () => ({ width: 1280, height: 800 }),
+ getByRole: () => ({ or: () => ({
+ count: async () => 1,
+ evaluate: async fn => fn({ getAttribute: () => String(state.lyrics) }),
+ elementHandle: async () => ({ getAttribute: () => String(state.lyrics) }),
+ click: async () => { state.lyrics = !state.lyrics; state.clicked.push('Show Lyrics'); },
+ }) }),
+ waitForFunction: async (fn, arg) => { if (!fn(arg)) throw new Error('state did not change'); },
evaluate: async (fn, arg) => {
globalThis.document = { querySelectorAll: (sel) => dom[(Array.isArray(arg) && arg[0]) || sel]?.() ?? [] };
return fn(arg);