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 Hook: set the audio window from where Suno opens it, and flag fitted cuts

Claude6a59cab84aef
diff --git a/client/src/components/musicVideo/PublishPostingPanel.jsx b/client/src/components/musicVideo/PublishPostingPanel.jsx
index 9c1e22ed07..b61f2c858f 100644
--- a/client/src/components/musicVideo/PublishPostingPanel.jsx
+++ b/client/src/components/musicVideo/PublishPostingPanel.jsx
@@ -45,19 +45,61 @@ const summaryRows = (summary) => Object.entries(summary || {})
const VERTICAL_TARGETS = ['shorts', 'tiktok', 'instagram'];
const fmtSec = (n) => `${Math.floor(n / 60)}:${String(Math.floor(n % 60)).padStart(2, '0')}`;
-/** Postable 9:16 cuts, oldest first (mirrors the server's pick; it still refuses a stale one). */
+/** Postable 9:16 cuts, oldest first (mirrors the server's list and pick in publish/payloads.js). */
function verticalCutChoices(project) {
const kit = project?.publishKit || {};
const cuts = (project?.excerpts || [])
.filter((e) => e?.status === 'complete' && e.aspect === '9:16' && e.filename)
- .map((e) => ({ id: e.id, label: `Social cut ${fmtSec(e.startSec ?? 0)}-${fmtSec(e.endSec ?? 0)}` }));
+ .map((e) => ({ id: e.id, layout: 'native', stale: e.dependencyState?.status === 'stale', label: `Social cut ${fmtSec(e.startSec ?? 0)}-${fmtSec(e.endSec ?? 0)}` }));
const crop = (kit.exports || []).find((e) => e.kind === 'vertical-9x16' && e.filename);
if (crop && (kit.master?.renderHistoryId ?? null) === (project?.renderHistoryId ?? null)) {
- cuts.unshift({ id: 'kit-vertical', label: `Kit vertical (fit) ${fmtSec(crop.startSec ?? 0)}-${fmtSec(crop.endSec ?? 0)}` });
+ const layout = crop.layout === 'native' ? 'native' : 'fit';
+ cuts.unshift({ id: 'kit-vertical', layout, stale: false, fitReason: crop.fitReason, startSec: crop.startSec ?? 0, endSec: crop.endSec ?? 0,
+ label: `Kit vertical (${layout}) ${fmtSec(crop.startSec ?? 0)}-${fmtSec(crop.endSec ?? 0)}` });
}
return cuts;
}
+/** The cut a fill posts: the director's pick, else the newest fresh one. */
+const postedCut = (cuts, cutId) => (cutId ? cuts.find((c) => c.id === cutId) : cuts.filter((c) => !c.stale).at(-1)) || null;
+
+const FIT_REASONS = {
+ changed: 'the composition changed after the final render',
+ unavailable: 'the composition has no 9:16 layout, or its 9:16 render failed',
+ footage: 'a footage edit has no 9:16 layout of its own',
+};
+const SEEKED_MODES = ['document', 'code', 'eidoverse'];
+
+/**
+ * A fitted cut (the 16:9 master over a blurred fill of itself) reads as a square on a phone
+ * (#10860). Say so, and for a composition that can lay itself out at 9:16, offer a native render
+ * of the same window: it becomes the newest cut, so the next fill posts it.
+ */
+function FittedCutNotice({ project, cut, excerpts }) {
+ const canRender = SEEKED_MODES.includes(project?.composition?.mode) && excerpts?.startExcerpt;
+ const failed = (project?.excerpts || []).filter((e) => e?.aspect === '9:16' && e.status === 'error' && e.error).at(-1);
+ return (
+ <div role="status" className="sm:col-span-2 rounded border border-port-warning/40 bg-port-warning/10 p-2 text-xs space-y-1.5">
+ <p>
+ This cut is fitted: the 16:9 frame over a blurred copy of itself, so it reads as a square on a phone
+ {FIT_REASONS[cut.fitReason] ? ` (${FIT_REASONS[cut.fitReason]})` : ''}.
+ </p>
+ {canRender && (
+ excerpts.rendering ? (
+ <p className="text-port-text-muted">Rendering a native 9:16 cut… {Math.round(excerpts.progress || 0)}%</p>
+ ) : (
+ <button type="button" disabled={excerpts.occupied}
+ onClick={() => excerpts.startExcerpt(cut.startSec, cut.endSec, { aspect: '9:16', fade: true })}
+ className="border border-port-border disabled:opacity-50 rounded px-2 py-1.5 min-h-[44px] sm:min-h-0">
+ Render a native 9:16 cut of {fmtSec(cut.startSec)}-{fmtSec(cut.endSec)}
+ </button>
+ )
+ )}
+ {canRender && !excerpts.rendering && failed && <p className="text-port-error break-words">The last 9:16 render failed: {failed.error}</p>}
+ </div>
+ );
+}
+
/** The story reply's image, picked by sight: a tile per video frame plus "No image". */
function StoryImagePicker({ idFor, thumbnails, value, onChange }) {
const tile = (selected) => `relative rounded overflow-hidden border-2 aspect-video min-h-[44px] ${selected ? 'border-port-accent ring-2 ring-port-accent/40' : 'border-port-border'}`;
@@ -83,7 +125,7 @@ function StoryImagePicker({ idFor, thumbnails, value, onChange }) {
);
}
-function TargetOptions({ target, kit, project, options, setOption, flairs, idFor, account }) {
+function TargetOptions({ target, kit, project, options, setOption, flairs, idFor, account, excerpts }) {
const field = (key, label, input) => (
<div key={key} className="space-y-0.5 min-w-0">
<label htmlFor={idFor(key)} className="block text-[11px] text-port-text-muted">{label}</label>
@@ -95,8 +137,10 @@ function TargetOptions({ target, kit, project, options, setOption, flairs, idFor
const area = (key, label) => field(key, label,
<textarea id={idFor(key)} value={options[key] || ''} rows={3} onChange={(e) => setOption(key, e.target.value)} className={inputCls} />);
+ const cuts = verticalCutChoices(project);
+ const cut = postedCut(cuts, options.cutId);
+ const fitted = cut?.layout === 'fit' ? <FittedCutNotice key="fitted" project={project} cut={cut} excerpts={excerpts} /> : null;
const cutPicker = () => {
- const cuts = verticalCutChoices(project);
if (cuts.length < 2) return null;
return field('cutId', 'Vertical cut to post', (
<select id={idFor('cutId')} aria-label="Vertical cut to post" value={options.cutId || ''} onChange={(e) => setOption('cutId', e.target.value)} className={inputCls}>
@@ -104,7 +148,7 @@ function TargetOptions({ target, kit, project, options, setOption, flairs, idFor
{[...cuts].reverse().map((c) => <option key={c.id} value={c.id}>{c.label}</option>)}
</select>));
};
- if (VERTICAL_TARGETS.includes(target)) return cutPicker();
+ if (VERTICAL_TARGETS.includes(target)) return <div className="grid sm:grid-cols-2 gap-2 items-end">{cutPicker()}{fitted}</div>;
if (target === 'sunoHook') {
return (
<div className="grid sm:grid-cols-2 gap-2 items-end">
@@ -113,6 +157,7 @@ function TargetOptions({ target, kit, project, options, setOption, flairs, idFor
<label className="flex items-center gap-1.5 text-xs min-h-[44px] sm:min-h-0">
<input type="checkbox" checked={options.showLyrics === true} onChange={(e) => setOption('showLyrics', e.target.checked)} /> Show Suno's lyrics (off when the cut has its own)
</label>
+ {fitted}
</div>
);
}
@@ -291,7 +336,7 @@ function UndoDone({ label, onUndo }) {
const STATUS = { posted: ['Done', 'text-port-success border-port-success/40'], draft: ['Draft open', 'text-port-warning border-port-warning/40'], none: ['To do', 'text-port-text-muted border-port-border'] };
-function TargetRow({ project, kit, entry, publishing }) {
+function TargetRow({ project, kit, entry, publishing, excerpts }) {
const { target, label, note, linkPlaceholder } = entry;
const idFor = (key) => `mv-post-${project.id}-${target}-${key}`;
const [options, setOptions] = useState(() => {
@@ -393,7 +438,7 @@ function TargetRow({ project, kit, entry, publishing }) {
</>
)
: <ManualLink idFor={idFor} label={label} placeholder={linkPlaceholder} onSave={(body) => publishing.recordPost(target, body)} />}
- <TargetOptions target={target} kit={kit} project={project} options={options} setOption={setOption} flairs={flairs} idFor={idFor} account={account} />
+ <TargetOptions target={target} kit={kit} project={project} options={options} setOption={setOption} flairs={flairs} idFor={idFor} account={account} excerpts={excerpts} />
{error && (
<div role="alert" className="text-[11px] text-port-error space-y-0.5">
<div className="flex items-center gap-1">{error.code === 'PUBLISH_LOGIN_REQUIRED' && <LogIn size={11} />}{error.message}</div>
@@ -438,7 +483,7 @@ function TargetRow({ project, kit, entry, publishing }) {
* a new tab, with the director's signed-in sessions) and shown back here as
* a screenshot and summary. Publication is performed manually on the platform.
*/
-export default function PublishPostingPanel({ project, publishing }) {
+export default function PublishPostingPanel({ project, publishing, excerpts = null }) {
const kit = project?.publishKit || {};
if (!kit.builtAt) return null;
// Only the platforms the director turned on (#9287), in posting order.
@@ -450,7 +495,7 @@ export default function PublishPostingPanel({ project, publishing }) {
<p className="text-port-text-muted">Sign in to each platform in the PortOS Browser first. Fill draft opens a new tab there and fills the post from the kit and copy above; review and publish yourself on the platform. PortOS cannot submit posts.</p>
{!targets.length && <p className="text-port-text-muted">Turn on the platforms you use under Where you post to prepare drafts. Final publication happens on each platform.</p>}
<ul className="space-y-2">
- {targets.map((entry) => <TargetRow key={`${project.id}-${entry.target}`} project={project} kit={kit} entry={entry} publishing={publishing} />)}
+ {targets.map((entry) => <TargetRow key={`${project.id}-${entry.target}`} project={project} kit={kit} entry={entry} publishing={publishing} excerpts={excerpts} />)}
</ul>
</PublishCard>
);
diff --git a/client/src/components/musicVideo/PublishPostingPanel.test.jsx b/client/src/components/musicVideo/PublishPostingPanel.test.jsx
index ed8a1795c5..feeb3b291b 100644
--- a/client/src/components/musicVideo/PublishPostingPanel.test.jsx
+++ b/client/src/components/musicVideo/PublishPostingPanel.test.jsx
@@ -261,4 +261,23 @@ describe('PublishPostingPanel (#9282)', () => {
expect(document.getElementById('mv-post-youtube')).not.toBeNull();
localStorage.clear();
});
+
+ it('flags a fitted Hook cut and renders a native 9:16 one of the same window (#10860)', () => {
+ const fittedKit = { master: { renderHistoryId: null }, exports: [{ kind: 'vertical-9x16', filename: 'v.mp4', startSec: 20, endSec: 50, layout: 'fit', fitReason: 'changed' }] };
+ const excerpts = { startExcerpt: vi.fn(), occupied: false, rendering: false, progress: 0 };
+ const p = { ...project(fittedKit), composition: { mode: 'document' } };
+ const { unmount } = render(<PublishPostingPanel project={p} publishing={hook({ enabledTargets: ['sunoHook'] })} excerpts={excerpts} />);
+ expandAll();
+ const card = row('Suno Hook');
+ expect(within(card).getByRole('status')).toHaveTextContent(/fitted.*reads as a square.*composition changed after the final render/);
+ fireEvent.click(within(card).getByRole('button', { name: 'Render a native 9:16 cut of 0:20-0:50' }));
+ expect(excerpts.startExcerpt).toHaveBeenCalledWith(20, 50, { aspect: '9:16', fade: true });
+ unmount();
+
+ // Once a native cut exists it is the default pick, and the warning goes.
+ const native = { ...p, excerpts: [{ id: 'e1', status: 'complete', aspect: '9:16', filename: 'n.mp4', startSec: 20, endSec: 50 }] };
+ render(<PublishPostingPanel project={native} publishing={hook({ enabledTargets: ['sunoHook'] })} excerpts={excerpts} />);
+ expandAll();
+ expect(within(row('Suno Hook')).queryByRole('status')).not.toBeInTheDocument();
+ });
});
diff --git a/client/src/components/musicVideo/stages/PublishStage.jsx b/client/src/components/musicVideo/stages/PublishStage.jsx
index 7530f62cc6..026d8df159 100644
--- a/client/src/components/musicVideo/stages/PublishStage.jsx
+++ b/client/src/components/musicVideo/stages/PublishStage.jsx
@@ -11,12 +11,12 @@ import PromotionPlanPanel from '../PromotionPlanPanel.jsx';
* steps for the director with reminders.
*/
export default function PublishStage({ board }) {
- const { project, locked, publishKit, publishing } = board;
+ const { project, locked, publishKit, publishing, excerpts } = board;
return (
<fieldset id="mv-publish-kit" disabled={locked} className="min-w-0 space-y-3">
{publishing && <PublishPlatformsPanel projectId={project?.id} publishing={publishing} />}
<PublishKitPanel project={project} publishKit={publishKit} enabledTargets={publishing?.enabledTargets} />
- {publishing && <PublishPostingPanel project={project} publishing={publishing} />}
+ {publishing && <PublishPostingPanel project={project} publishing={publishing} excerpts={excerpts} />}
<PromotionPlanPanel project={project} />
</fieldset>
);
diff --git a/server/services/musicVideo/publish/payloads.js b/server/services/musicVideo/publish/payloads.js
index 80939e9688..9d84dab6a9 100644
--- a/server/services/musicVideo/publish/payloads.js
+++ b/server/services/musicVideo/publish/payloads.js
@@ -31,15 +31,17 @@ const isVerticalCut = (e) => e?.status === 'complete' && e.aspect === '9:16' &&
/**
* The vertical cuts a director can post (#10150), newest last: finished 9:16
* excerpts flagged stale when the project changed since, plus the kit's
- * fit-with-blurred-fill 9:16 encode (16:9 renders) while the kit is fresh.
+ * 9:16 encode (16:9 renders) while the kit is fresh. `layout` says whether a
+ * cut was laid out at 9:16 ('native') or is the master fitted over a blurred
+ * fill of itself ('fit', which reads as a square on a phone).
*/
function verticalCuts(project) {
const kit = kitOf(project);
const cuts = (project?.excerpts || []).filter(isVerticalCut)
- .map((e) => ({ id: e.id ?? null, filename: e.filename, startSec: e.startSec, endSec: e.endSec, stale: musicVideoDependencyChanges(project, e.dependencies).length > 0 }));
+ .map((e) => ({ id: e.id ?? null, filename: e.filename, startSec: e.startSec, endSec: e.endSec, layout: 'native', stale: musicVideoDependencyChanges(project, e.dependencies).length > 0 }));
const crop = (kit.exports || []).find((e) => e.kind === 'vertical-9x16' && e.filename);
if (crop && (kit.master?.renderHistoryId ?? null) === (project?.renderHistoryId ?? null)) {
- cuts.unshift({ id: 'kit-vertical', filename: crop.filename, startSec: crop.startSec ?? 0, endSec: crop.endSec ?? 0, stale: false });
+ cuts.unshift({ id: 'kit-vertical', filename: crop.filename, startSec: crop.startSec ?? 0, endSec: crop.endSec ?? 0, layout: crop.layout === 'native' ? 'native' : 'fit', stale: false });
}
return cuts;
}
@@ -221,6 +223,7 @@ const BUILDERS = {
durationSec: Number.isFinite(duration) && duration > 0 ? duration : null,
// The audio window opens where the cut's own audio does.
startSec: Math.max(0, Number(cut.startSec) || 0),
+ cutLayout: cut.layout,
caption, showLyrics: options.showLyrics === true,
};
},
diff --git a/server/services/musicVideo/publish/sunoHook.js b/server/services/musicVideo/publish/sunoHook.js
index 8a9664cc07..129b6929f1 100644
--- a/server/services/musicVideo/publish/sunoHook.js
+++ b/server/services/musicVideo/publish/sunoHook.js
@@ -4,29 +4,36 @@
* vertical cut, picks the song, sets the audio window to the cut's start and
* writes the caption; submit() presses Post. Nothing is posted before then.
*
- * The window is a fixed box over a waveform with no numeric field, so it is set
- * in two tries: keyboard nudges on a slider role when the page exposes one,
- * else a drag calibrated at WAVEFORM_PX_PER_SEC. Either way the page's own m:ss
- * label is read back and the fill fails rather than post the wrong stretch.
+ * The window is a fixed box over a waveform with no numeric field or slider,
+ * and it opens wherever Suno suggests (not 0:00). Its start is the m:ss pill
+ * above the box; the player clock ("0:00 / 0:26") beside it is not. So the
+ * window is set by read, drag, re-read: each drag is sized from the gap at the
+ * current px-per-second estimate, recalibrated from what the drag moved, and
+ * the fill fails rather than post the wrong stretch (#10860).
*/
import { pickSongRow } from '../../../lib/sunoSongPicker.js';
import { PUBLISH_STEP_TIMEOUT_MS as T, clickVisibleText, loginRequired, step } from './browser.js';
const CREATE_URL = 'https://suno.com/hooks/create';
const label = 'Suno Hook';
-// Measured on the 2026-10 picker: one waveform second is about this many CSS px; dragging right moves the window earlier.
-const WAVEFORM_PX_PER_SEC = 23.6;
+// Measured on the 2026-10 picker (200 px moved 2:38 to 2:29); only the first drag's estimate, each drag recalibrates it.
+const WAVEFORM_PX_PER_SEC = 22.2;
// The page's readout is a rounded m:ss, so a one-second miss is the finest check it can support.
const READBACK_TOLERANCE_SEC = 1;
+// One drag stays on the waveform, so a window far from the target takes several.
+const MAX_DRAGS = 20;
+const WAVEFORM = '[class*=waveform], [data-testid*=waveform], canvas';
const fmtClock = (sec) => `${Math.floor(sec / 60)}:${String(Math.floor(sec % 60)).padStart(2, '0')}`;
const parseClock = (text) => {
const m = String(text).match(/(\d+):(\d{2})/);
return m ? Number(m[1]) * 60 + Number(m[2]) : null;
};
+const clamp = (n, lo, hi) => Math.min(hi, Math.max(lo, n));
async function selectSong(page, payload) {
- await page.locator('text=Select Song').first().click({ timeout: T });
+ // A restored draft shows Replace Song and keeps a hidden Select Song; only a visible one can be clicked.
+ await page.locator('button:visible').filter({ hasText: /Replace Song|Select Song/ }).first().click({ timeout: T });
await page.locator('[role=dialog]').first().waitFor({ timeout: T });
const search = page.locator('textarea[placeholder*="Search by song name"]').first();
await search.fill(payload.title, { timeout: T });
@@ -44,38 +51,63 @@ async function selectSong(page, payload) {
await page.waitForTimeout(1500);
}
+/**
+ * The window's start among the page's visible m:ss labels (`{ text, cls, parentText }`), in
+ * seconds: the rounded-full font-mono pill above the box, never the player clock ("0:00 / 0:26").
+ * Without a pill, a lone label that isn't the clock; null when it can't be told.
+ */
+function pickWindowStart(labels) {
+ const isClock = (l) => /\d+:\d{2}\s*\/\s*\d+:\d{2}/.test(l.parentText || '');
+ const candidates = labels.filter((l) => !isClock(l));
+ const pills = candidates.filter((l) => /(^|\s)rounded-full(\s|$)/.test(l.cls || '') && /(^|\s)font-mono(\s|$)/.test(l.cls || ''));
+ const pick = pills.length ? pills : candidates;
+ return pick.length === 1 ? parseClock(pick[0].text) : null;
+}
+
/** The window's start as the page reports it, in seconds (null when no readout is found). */
-const readWindowStart = (page) => page.evaluate(() => {
- const el = [...document.querySelectorAll('span,div')].find((e) => e.children.length === 0 && /^\d+:\d{2}$/.test(e.textContent.trim()) && e.offsetParent);
- return el ? el.textContent.trim() : null;
-}).then((text) => (text ? parseClock(text) : null));
+const readWindowStart = (page) => page.evaluate(() => [...document.querySelectorAll('span,div')]
+ .filter((e) => e.children.length === 0 && /^\d+:\d{2}$/.test(e.textContent.trim()) && e.offsetParent)
+ .map((e) => ({ text: e.textContent.trim(), cls: String(e.className || ''), parentText: (e.parentElement?.textContent || '').trim() })))
+ .then(pickWindowStart);
+/**
+ * Move the window to `startSec` from wherever Suno opened it: read the pill, drag the waveform
+ * under the fixed box (right moves the window earlier), re-read, repeat until within a second.
+ */
async function setWindowStart(page, startSec) {
- if (!(startSec > 0)) return 0; // the page opens the window at 0:00
- const slider = page.locator('[role=slider]').first();
- if (await slider.count()) {
- await slider.focus();
- for (let i = 0; i < 400; i += 1) {
- const now = Number(await slider.getAttribute('aria-valuenow'));
- const gap = startSec - now;
- if (Number.isFinite(now) && Math.abs(gap) <= 0.1) return now;
- await page.keyboard.press(gap > 0 ? 'ArrowRight' : 'ArrowLeft');
- }
- }
- const box = await page.locator('[class*=waveform], [data-testid*=waveform], canvas').first().boundingBox();
+ const target = Math.max(0, Number(startSec) || 0);
+ let at = await readWindowStart(page);
+ if (at == null) throw new Error('no window label to read');
+ 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;
- await page.mouse.move(x, y);
- await page.mouse.down();
- await page.mouse.move(x - startSec * WAVEFORM_PX_PER_SEC, y, { steps: 20 }); // dragging right moves the window earlier
- await page.mouse.up();
- await page.waitForTimeout(500);
- const got = await readWindowStart(page);
- if (got == null || Math.abs(got - startSec) > READBACK_TOLERANCE_SEC) {
- throw new Error(`the window reads ${got == null ? 'nothing' : fmtClock(got)}, wanted ${fmtClock(startSec)}`);
+ const reach = Math.max(20, box.width / 2 - 16); // a drag from the middle stays on the waveform
+ let pxPerSec = WAVEFORM_PX_PER_SEC;
+ let direction = 1; // +1: dragging right moves the window earlier
+ let still = 0;
+ for (let drag = 0; drag < MAX_DRAGS && Math.abs(at - target) > READBACK_TOLERANCE_SEC; drag += 1) {
+ const dx = clamp((at - target) * pxPerSec * direction, -reach, reach);
+ await page.mouse.move(x, y);
+ await page.mouse.down();
+ await page.mouse.move(x + dx, y, { steps: 20 });
+ await page.mouse.up();
+ await page.waitForTimeout(500);
+ const now = await readWindowStart(page);
+ if (now == null) throw new Error(`the window label went missing (it read ${fmtClock(at)}, wanted ${fmtClock(target)})`);
+ const moved = at - now; // seconds earlier
+ // A drag that moved the window the other way flips the direction; the rate comes from what it moved.
+ if (moved !== 0 && Math.sign(moved) !== Math.sign(dx) * direction) direction = -direction;
+ if (Math.abs(moved) >= 2) pxPerSec = clamp(Math.abs(dx / moved), 2, 400);
+ still = moved === 0 ? still + 1 : 0;
+ at = now;
+ if (still >= 2) break; // the window no longer moves (the song's edge, or the drag missed the waveform)
+ }
+ if (Math.abs(at - target) > READBACK_TOLERANCE_SEC) {
+ throw new Error(`the window reads ${fmtClock(at)}, wanted ${fmtClock(target)}`);
}
- return got;
+ return at;
}
export const sunoHookAdapter = {
@@ -114,7 +146,10 @@ export const sunoHookAdapter = {
if (state === null) throw new Error('no Show Lyrics switch');
return false;
});
- return { songUrl: payload.songUrl, windowStart, caption: payload.caption, showLyrics: lyrics };
+ 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' } : {}),
+ };
},
async submit(page) {
await step(label, 'post', () => clickVisibleText(page, 'Post'));
diff --git a/server/services/musicVideo/publish/sunoHook.test.js b/server/services/musicVideo/publish/sunoHook.test.js
index 28f44f9dfd..48ba3f44ab 100644
--- a/server/services/musicVideo/publish/sunoHook.test.js
+++ b/server/services/musicVideo/publish/sunoHook.test.js
@@ -1,4 +1,5 @@
-import { describe, it, expect } from 'vitest';
+import { describe, it, expect, afterEach } from 'vitest';
+import { sunoHookAdapter } from './sunoHook.js';
import { pickSongRow } from '../../../lib/sunoSongPicker.js';
import { buildPublishPayload } from './payloads.js';
import { captureMusicVideoEvidence } from '../../../lib/musicVideoDependencies.js';
@@ -18,6 +19,14 @@ describe('Suno Hook payload', () => {
const p = buildPublishPayload('sunoHook', project());
expect(p).toMatchObject({ songId: ID, title: 'Night Drive', durationSec: 187, startSec: 42, caption: 'Hook caption', showLyrics: false, video: { dir: 'videos', name: 'cut.mp4' } });
});
+ it('says whether the cut it posts is native 9:16 or the fitted master', () => {
+ expect(buildPublishPayload('sunoHook', project()).cutLayout).toBe('native');
+ const fitted = project({ excerpts: [], renderHistoryId: 'r1', publishKit: {
+ ...project().publishKit, master: { renderHistoryId: 'r1' },
+ exports: [{ kind: 'vertical-9x16', filename: 'kit.mp4', startSec: 20, endSec: 50, layout: 'fit', fitReason: 'unavailable' }],
+ } });
+ expect(buildPublishPayload('sunoHook', fitted)).toMatchObject({ startSec: 20, cutLayout: 'fit', video: { name: 'kit.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/);
@@ -35,3 +44,98 @@ describe('pickSongRow', () => {
expect(pickSongRow([row('Night Drive 2:10')], { songId: ID, title: 'Night Drive' })).toBe(0);
});
});
+
+// The Create Hook page as the adapter sees it (#10860): the player clock ("0:00 / 0:26") beside the
+// window pill, a window that opens at Suno's own suggestion, and a waveform where 22.2 px of drag
+// moves the window one second (dragging right moves it earlier). `stuckAt` stops the window there.
+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 leaf = (text, cls, parentText = text) => ({ children: [], textContent: text, className: cls, offsetParent: {}, parentElement: { textContent: parentText } });
+ const dom = {
+ 'span,div': () => [
+ leaf('0:00', 'text-foreground-primary', '0:00 / 0:26'),
+ leaf(fmt(state.windowAt), PILL),
+ leaf('3:42', 'text-xs'), leaf('3:42', 'text-xs'),
+ ],
+ '[role=dialog] button': () => [{ innerText: 'Use', innerHTML: '', parentElement: { querySelectorAll: () => [1, 2, 3] } }],
+ 'button,[role=button]': () => [{ offsetParent: {}, innerText: 'Next', click: () => state.clicked.push('Next') }],
+ 'span,div,label': () => [{ children: [], textContent: 'Show Lyrics', parentElement: { querySelector: () => ({ getAttribute: () => 'true', click: () => state.clicked.push('Show Lyrics') }) } }],
+ };
+ const visibleSongButton = restored ? 'Replace Song' : 'Select Song';
+ const locator = (sel, hasText) => ({
+ first: () => locator(sel, hasText),
+ nth: () => locator(sel, hasText),
+ filter: (o) => locator(sel, o.hasText),
+ count: async () => 1,
+ waitFor: async () => {},
+ fill: async () => {},
+ setInputFiles: async () => {},
+ boundingBox: async () => ({ x: 100, y: 400, width: 600, height: 80 }),
+ click: async () => {
+ if (sel === 'text=Select Song' && restored) throw new Error('element is not visible');
+ if (sel === 'button:visible' && !hasText.test(visibleSongButton)) throw new Error('no visible song button');
+ state.clicked.push(sel === 'button:visible' ? visibleSongButton : sel);
+ },
+ });
+ let downX = null;
+ const page = {
+ state,
+ goto: async () => {},
+ url: () => 'https://suno.com/hooks/create',
+ waitForTimeout: async () => {},
+ locator: (sel) => locator(sel),
+ evaluate: async (fn, arg) => {
+ globalThis.document = { querySelectorAll: (sel) => dom[(Array.isArray(arg) && arg[0]) || sel]?.() ?? [] };
+ return fn(arg);
+ },
+ mouse: {
+ move: async (x) => { page.lastX = x; },
+ down: async () => { downX = page.lastX ?? 400; },
+ up: async () => {
+ state.drags += 1;
+ const moved = ((page.lastX ?? downX) - downX) / pxPerSec;
+ let next = Math.max(0, state.windowAt - moved);
+ if (stuckAt != null && next < stuckAt) next = stuckAt;
+ state.windowAt = next;
+ downX = null;
+ },
+ },
+ };
+ return page;
+}
+
+const hookPayload = (over = {}) => ({ video: { path: '/tmp/cut.mp4' }, songId: ID, title: 'Night Drive', durationSec: 222, startSec: 20, caption: 'Hook caption', showLyrics: false, cutLayout: 'native', ...over });
+
+describe('Suno Hook fill (#10860)', () => {
+ afterEach(() => { delete globalThis.document; });
+
+ it('moves a window Suno opened at 2:38 to 0:20, reading the pill rather than the player clock', async () => {
+ const page = hookPage({ windowAt: 158 });
+ const summary = await sunoHookAdapter.prepare(page, hookPayload());
+ expect(Math.abs(summary.windowStart - 20)).toBeLessThanOrEqual(1);
+ expect(Math.abs(page.state.windowAt - 20)).toBeLessThanOrEqual(1);
+ expect(page.state.drags).toBeGreaterThan(1); // the waveform is narrower than 138 s of drag
+ expect(page.state.clicked).not.toContain('Post');
+ expect(summary).not.toHaveProperty('cut');
+ });
+
+ it('recalibrates when the page drags at another rate, and moves a window that opened early later', async () => {
+ const page = hookPage({ windowAt: 5, pxPerSec: 40 });
+ const summary = await sunoHookAdapter.prepare(page, hookPayload({ startSec: 95 }));
+ expect(Math.abs(summary.windowStart - 95)).toBeLessThanOrEqual(1);
+ });
+
+ it('fails clearly when it cannot get the window within a second', async () => {
+ const page = hookPage({ windowAt: 158, stuckAt: 60 });
+ await expect(sunoHookAdapter.prepare(page, hookPayload())).rejects.toThrow('Suno Hook: set the audio window (the window reads 1:00, wanted 0:20)');
+ });
+
+ it('picks the song through the visible Replace Song button of a restored draft, and says a fitted cut is fitted', async () => {
+ const page = hookPage({ windowAt: 158, restored: true });
+ const summary = await sunoHookAdapter.prepare(page, hookPayload({ cutLayout: 'fit' }));
+ expect(page.state.clicked).toContain('Replace Song');
+ expect(summary).toMatchObject({ caption: 'Hook caption', showLyrics: false, cut: expect.stringMatching(/Fitted/) });
+ });
+});
diff --git a/server/services/musicVideo/publishKit.js b/server/services/musicVideo/publishKit.js
index 71fbe1474f..332fb4c03f 100644
--- a/server/services/musicVideo/publishKit.js
+++ b/server/services/musicVideo/publishKit.js
@@ -165,6 +165,7 @@ async function beginPublishKitBuild(projectId, jobId) {
// cancels and leaves no partial file behind.
const renderNative = async (encode, out) => {
if (!matchesMaster) {
+ encode.fitReason = 'changed';
console.log(`📐 ${encode.label} [${tag}]: the composition changed since the final render (or was never recorded), fitting the master`);
return false;
}
@@ -172,11 +173,13 @@ async function beginPublishKitBuild(projectId, jobId) {
const slot = done;
const progress = (fraction) => broadcastSse(job, { type: 'progress', progress: Math.min(0.99, (slot + Math.max(0, Math.min(1, fraction))) / total) });
if (await encode.native(out, progress)) { encode.layout = 'native'; return true; }
+ encode.fitReason = 'footage';
} catch (error) {
if (job.abort.signal.aborted) {
await unlink(out).catch(() => {});
throw error;
}
+ encode.fitReason = 'unavailable';
console.warn(`⚠️ Native ${encode.label} unavailable [${tag}], fitting the master instead: ${error.message}`);
}
await unlink(out).catch(() => {});
@@ -214,7 +217,7 @@ async function beginPublishKitBuild(projectId, jobId) {
...kit,
builtAt: new Date().toISOString(),
master: { filename: entry.filename, renderHistoryId: project.renderHistoryId },
- exports: encodes.map(({ kind, label, filename, window, layout }) => ({ kind, label, filename, ...(window ? { startSec: window.startSec, endSec: window.endSec } : {}), ...(layout ? { layout } : {}) })),
+ exports: encodes.map(({ kind, label, filename, window, layout, fitReason }) => ({ kind, label, filename, ...(window ? { startSec: window.startSec, endSec: window.endSec } : {}), ...(layout ? { layout } : {}), ...(layout === 'fit' && fitReason ? { fitReason } : {}) })),
thumbnails,
thumbnail: thumbnails.includes(kit.thumbnail) ? kit.thumbnail : (thumbnails[0] || null),
captionsFilename,
diff --git a/server/services/musicVideo/publishKit.test.js b/server/services/musicVideo/publishKit.test.js
index 2d838728b8..90ee3b6131 100644
--- a/server/services/musicVideo/publishKit.test.js
+++ b/server/services/musicVideo/publishKit.test.js
@@ -228,7 +228,7 @@ describe('publishing kit build (#9281)', () => {
await kit.startPublishKitBuild(id);
await vi.waitFor(async () => expect((await projects.getProject(id)).publishKit?.builtAt).toBeTruthy(), { timeout: 90000, interval: 250 });
const vertical = (await projects.getProject(id)).publishKit.exports.find((e) => e.kind === 'vertical-9x16');
- expect(vertical.layout).toBe('fit');
+ expect(vertical).toMatchObject({ layout: 'fit', fitReason: 'unavailable' });
const probed = await runFfmpegProcess({ bin: ffmpeg, args: ['-hide_banner', '-i', join(PATHS.videos, vertical.filename), '-f', 'null', '-'] });
expect(probed.ok).toBe(true);
expect(warn.mock.calls.some(([m]) => /fitting the master/.test(m))).toBe(true);
@@ -245,7 +245,7 @@ describe('publishing kit build (#9281)', () => {
try {
await kit.startPublishKitBuild(id);
await vi.waitFor(async () => expect((await projects.getProject(id)).publishKit?.builtAt).toBeTruthy(), { timeout: 90000, interval: 250 });
- expect((await projects.getProject(id)).publishKit.exports.find((e) => e.kind === 'vertical-9x16').layout).toBe('fit');
+ expect((await projects.getProject(id)).publishKit.exports.find((e) => e.kind === 'vertical-9x16')).toMatchObject({ layout: 'fit', fitReason: 'changed' });
expect(native).not.toHaveBeenCalled();
} finally {
native.mockRestore();