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 the X modal composer before choosing the selector scope
[._.]/ Adam Eivyab685fb677fe
diff --git a/server/services/musicVideo/publish/x.js b/server/services/musicVideo/publish/x.jsindex b5203f15a1..da79f17a29 100644--- a/server/services/musicVideo/publish/x.js+++ b/server/services/musicVideo/publish/x.js@@ -10,6 +10,7 @@ import { PUBLISH_STEP_TIMEOUT_MS as T, loginRequired, pasteText, step } from './const COMPOSE_URL = 'https://x.com/compose/post';const label = 'X';+const DIALOG_WAIT_MS = 8000;/*** The CSS prefix that scopes selectors to the composer we opened. /compose/post opens as a modal over the@@ -17,8 +18,12 @@ const label = 'X';* fileInput), so an unscoped selector matches both. Without a modal (a full-page composer) it is empty.*/async function composerScope(page) {- const inDialog = await page.locator('[role=dialog] [data-testid=tweetTextarea_0]').count().catch(() => 0);- return inDialog > 0 ? '[role=dialog] ' : '';+ // Wait for a composer to exist at all, then give the modal's editor a moment to hydrate before deciding:+ // a snapshot taken too early would fall back to unscoped selectors and hit the inline composer.+ await page.locator('[data-testid=tweetTextarea_0]').first().waitFor({ timeout: T }).catch(() => {});+ const inDialog = await page.locator('[role=dialog] [data-testid=tweetTextarea_0]').first()+ .waitFor({ timeout: DIALOG_WAIT_MS }).then(() => true, () => false);+ return inDialog ? '[role=dialog] ' : '';}export const xAdapter = {diff --git a/server/services/musicVideo/publish/x.test.js b/server/services/musicVideo/publish/x.test.jsindex 0983d58ae2..b3b15cc7a4 100644--- a/server/services/musicVideo/publish/x.test.js+++ b/server/services/musicVideo/publish/x.test.js@@ -1,26 +1,38 @@import { describe, it, expect } from 'vitest';import { xAdapter } from './x.js';-// A page whose modal composer sits over the home timeline's inline one (both carry tweetTextarea_0).-const fakePage = ({ dialog }) => {+// A page whose modal composer (when `dialog`) sits over the home timeline's inline one; both carry+// tweetTextarea_0. `dialogDelay` makes the modal's editor appear only after a while (X still hydrating).+const fakePage = ({ dialog, dialogDelay = 0 }) => {const calls = { pasted: [], clicked: [], waited: [] };+ const born = Date.now();const page = {calls,goto: async () => {},url: () => 'https://x.com/compose/post',waitForTimeout: async () => {},+ waitForURL: async () => { throw new Error('stop here'); },evaluate: async (fn, arg) => {- if (Array.isArray(arg) && typeof arg[1] === 'string' && arg.length === 2 && typeof arg[0] === 'string') { calls.pasted.push(arg[0]); return true; }+ if (Array.isArray(arg) && arg.length === 2 && typeof arg[0] === 'string') { calls.pasted.push(arg[0]); return true; }if (Array.isArray(arg) && typeof arg[0] === 'number') return Array.from({ length: arg[0] }, () => 5);return 'example';},waitForFunction: async (_fn, scope) => { calls.waited.push(scope); },- locator: (sel) => ({- count: async () => (sel.startsWith('[role=dialog]') ? (dialog ? 1 : 0) : 2),- waitFor: async () => { calls.waited.push(sel); },- click: async () => { calls.clicked.push(sel); },- first: () => ({ setInputFiles: async () => {} }),- }),+ locator: (sel) => {+ const isDialog = sel.startsWith('[role=dialog]');+ const waitFor = async ({ timeout } = {}) => {+ if (!isDialog) return;+ if (!dialog) throw new Error('timeout');+ const left = dialogDelay - (Date.now() - born);+ if (left > (timeout ?? Infinity)) throw new Error('timeout');+ if (left > 0) await new Promise((r) => setTimeout(r, left));+ };+ return {+ waitFor: async (o) => { calls.waited.push(sel); return waitFor(o); },+ click: async () => { calls.clicked.push(sel); },+ first: () => ({ waitFor, setInputFiles: async () => {} }),+ };+ },};return page;};@@ -34,9 +46,21 @@ describe('X composer scope', () => {expect(page.calls.waited).toContain('[role=dialog] ');});+ it('waits for a modal that hydrates late instead of falling back to unscoped selectors', async () => {+ const page = fakePage({ dialog: true, dialogDelay: 50 });+ await xAdapter.prepare(page, { posts: [{ text: 'one' }] });+ expect(page.calls.pasted).toEqual(['[role=dialog] [data-testid=tweetTextarea_0]']);+ });+it('leaves selectors unscoped for a full-page composer', async () => {const page = fakePage({ dialog: false });await xAdapter.prepare(page, { posts: [{ text: 'one' }] });expect(page.calls.pasted).toEqual(['[data-testid=tweetTextarea_0]']);});++ it('presses the modal\'s Post button on submit, not the timeline\'s', async () => {+ const page = fakePage({ dialog: true });+ await xAdapter.submit(page, { posts: [{ text: 'one' }] }).catch(() => {});+ expect(page.calls.clicked).toEqual(['[role=dialog] [data-testid=tweetButton]']);+ });});