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
wait for a late TikTok tour, press only its own buttons, and re-check before later clicks
[._.]/ Adam Eivyce208574e6f3
diff --git a/server/services/musicVideo/publish/tiktok.js b/server/services/musicVideo/publish/tiktok.jsindex 20c106698b..bcbc0ba751 100644--- a/server/services/musicVideo/publish/tiktok.js+++ b/server/services/musicVideo/publish/tiktok.js@@ -9,23 +9,31 @@ import { PUBLISH_STEP_TIMEOUT_MS as T, clickVisibleText, loginRequired, replaceEconst UPLOAD_URL = 'https://www.tiktok.com/tiktokstudio/upload';const label = 'TikTok';const TOUR = '.react-joyride__overlay';+// Joyride renders each step's tooltip (stock or custom) inside its floater.+const TOUR_BUTTONS = '.__floater button, .react-joyride__tooltip button';/*** Close TikTok Studio's onboarding tooltips ("Preview your video on your* phone"…). Their overlay covers the whole form, so every click times out- * until it is gone. A tour can chain several steps, and once dismissed it does- * not come back for the account.+ * until it is gone. Joyride mounts a step a beat after the upload, so the+ * first check waits `waitMs` for one to appear. A tour can chain several+ * steps, and once dismissed it does not come back for the account. Only the+ * tooltip's own buttons are pressed; Escape is the fallback.*/-async function dismissStudioTour(page, { attempts = 5 } = {}) {+async function dismissStudioTour(page, { attempts = 5, waitMs = 3000 } = {}) {+ if (waitMs) await page.locator(TOUR).first().waitFor({ state: 'attached', timeout: waitMs }).catch(() => {});for (let i = 0; i < attempts; i += 1) {if (!(await page.locator(TOUR).count())) return true;- const closed = await clickVisibleText(page, 'Got it').then(() => true, () => clickVisibleText(page, 'Skip').then(() => true, () => false));- if (!closed) await page.keyboard.press('Escape');+ const press = (text) => clickVisibleText(page, text, { selector: TOUR_BUTTONS }).then(() => true, () => false);+ if (!(await press('Got it')) && !(await press('Skip'))) await page.keyboard.press('Escape');await page.waitForTimeout(800);}return !(await page.locator(TOUR).count());}+/** Close a tour step that mounted after the last check, before a click it would swallow. */+const clearTour = (page) => dismissStudioTour(page, { waitMs: 0 });+export const tiktokAdapter = {label,async prepare(page, payload) {@@ -44,6 +52,7 @@ export const tiktokAdapter = {let cover = false;if (payload.cover) {await step(label, 'set the cover frame', async () => {+ await clearTour(page);await page.locator('text=Edit cover').first().click({ timeout: T });await page.locator('input[type=file][accept*=image]').first().setInputFiles(payload.cover.path, { timeout: T });await page.waitForTimeout(2500);@@ -52,7 +61,10 @@ export const tiktokAdapter = {});cover = true;}- await step(label, 'open the post settings', () => page.locator('text=Show more').first().click({ timeout: T }));+ await step(label, 'open the post settings', async () => {+ await clearTour(page);+ await page.locator('text=Show more').first().click({ timeout: T });+ });const aiLabel = await step(label, 'turn on the AI-generated label', async () => {const was = await page.evaluate(() => {const text = [...document.querySelectorAll('*')].find((e) => e.children.length === 0 && e.textContent.trim() === 'AI-generated content');diff --git a/server/services/musicVideo/publish/tiktok.test.js b/server/services/musicVideo/publish/tiktok.test.jsindex 7b2ea2c759..5b1b695f6f 100644--- a/server/services/musicVideo/publish/tiktok.test.js+++ b/server/services/musicVideo/publish/tiktok.test.js@@ -1,26 +1,46 @@import { describe, it, expect } from 'vitest';import { tiktokAdapter } from './tiktok.js';+const OVERLAY = '.react-joyride__overlay';+// TikTok Studio's upload page with `tourSteps` onboarding tooltips over the-// form. Each "Got it" closes one; the overlay swallows clicks while it is up.-const fakePage = ({ tourSteps = 0, closes = true } = {}) => {- let tour = tourSteps;- const calls = { editorClickedUnderTour: false, editorClicked: false, escapes: 0 };+// form. `buttons` are the tooltip's own buttons (each press closes one step),+// `escape` says whether Escape closes a step, and `late` mounts the tour only+// once the adapter waits for it. The overlay swallows clicks while it is up.+const fakePage = ({ tourSteps = 0, buttons = ['Got it'], escape = false, late = false } = {}) => {+ let tour = late ? 0 : tourSteps;+ let pending = late ? tourSteps : 0;+ const calls = { editorClicked: false, editorClickedUnderTour: false, pressed: [], escapes: 0, buttonSelectors: new Set() };const page = {calls,goto: async () => {},url: () => 'https://www.tiktok.com/tiktokstudio/upload',waitForTimeout: async () => {},- keyboard: { press: async (k) => { if (k === 'Escape') calls.escapes += 1; } },+ keyboard: {+ press: async (k) => {+ if (k !== 'Escape') return;+ calls.escapes += 1;+ if (tour && escape) tour -= 1;+ },+ },evaluate: async (_fn, arg) => {- if (Array.isArray(arg) && arg[1] === 'Got it') { if (!tour) return false; if (closes) tour -= 1; return true; }- if (Array.isArray(arg) && arg[1] === 'Skip') return false;+ if (Array.isArray(arg) && (arg[1] === 'Got it' || arg[1] === 'Skip')) {+ calls.buttonSelectors.add(arg[0]);+ if (!tour || !buttons.includes(arg[1])) return false;+ calls.pressed.push(arg[1]);+ tour -= 1;+ return true;+ }return true;},locator: (sel) => {const node = {- count: async () => (sel === '.react-joyride__overlay' ? (tour ? 1 : 0) : 1),- waitFor: async () => {},+ count: async () => (sel === OVERLAY ? (tour ? 1 : 0) : 1),+ waitFor: async () => {+ if (sel !== OVERLAY) return;+ if (pending) { tour = pending; pending = 0; }+ if (!tour) throw new Error('timeout');+ },setInputFiles: async () => {},click: async () => {if (sel === '[contenteditable=true]') { calls.editorClicked = true; if (tour) calls.editorClickedUnderTour = true; }@@ -35,24 +55,56 @@ const fakePage = ({ tourSteps = 0, closes = true } = {}) => {};const payload = { video: { path: '/tmp/v.mp4' }, caption: 'hello' };+const run = (page) => expect(tiktokAdapter.prepare(page, payload)).rejects.toThrow(/stop here/);describe('TikTok Studio tour', () => {- it('closes every onboarding tooltip before writing the caption', async () => {+ it('presses Got it on every tooltip step before writing the caption', async () => {const page = fakePage({ tourSteps: 2 });- await expect(tiktokAdapter.prepare(page, payload)).rejects.toThrow(/stop here/);+ await run(page);+ expect(page.calls.pressed).toEqual(['Got it', 'Got it']);expect(page.calls.editorClicked).toBe(true);expect(page.calls.editorClickedUnderTour).toBe(false);});+ it('waits for a tour that mounts after the caption editor appears', async () => {+ const page = fakePage({ tourSteps: 1, late: true });+ await run(page);+ expect(page.calls.pressed).toEqual(['Got it']);+ expect(page.calls.editorClickedUnderTour).toBe(false);+ });++ it('presses Skip when the step has no Got it', async () => {+ const page = fakePage({ tourSteps: 1, buttons: ['Skip'] });+ await run(page);+ expect(page.calls.pressed).toEqual(['Skip']);+ expect(page.calls.editorClickedUnderTour).toBe(false);+ });++ it('falls back to Escape when the tooltip has neither button', async () => {+ const page = fakePage({ tourSteps: 1, buttons: [], escape: true });+ await run(page);+ expect(page.calls.pressed).toEqual([]);+ expect(page.calls.escapes).toBe(2); // the tour's, then the hashtag popup's after the caption+ expect(page.calls.editorClickedUnderTour).toBe(false);+ });++ it("only presses the tooltip's own buttons", async () => {+ const page = fakePage({ tourSteps: 1, buttons: [], escape: true });+ await run(page);+ expect([...page.calls.buttonSelectors]).toEqual(['.__floater button, .react-joyride__tooltip button']);+ });+it('goes straight on when there is no tour', async () => {const page = fakePage();- await expect(tiktokAdapter.prepare(page, payload)).rejects.toThrow(/stop here/);- expect(page.calls.escapes).toBeGreaterThanOrEqual(1); // only the hashtag-popup Escape after the caption+ await run(page);+ expect(page.calls.pressed).toEqual([]);+ expect(page.calls.escapes).toBe(1); // only the hashtag-popup Escape after the caption});it('names the tooltip instead of timing out on the caption when it will not close', async () => {- const page = fakePage({ tourSteps: 1, closes: false });+ const page = fakePage({ tourSteps: 1, buttons: [], escape: false });await expect(tiktokAdapter.prepare(page, payload)).rejects.toThrow(/close the Studio tour.*onboarding tooltip/);+ expect(page.calls.escapes).toBe(5);expect(page.calls.editorClicked).toBe(false);});});