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

scope the X publish composer to its modal so the timeline's inline composer can't collide

[._.]/ Adam Eivy4b518297b9e0
diff --git a/server/services/musicVideo/publish/x.js b/server/services/musicVideo/publish/x.js
index 609378b261..b5203f15a1 100644
--- a/server/services/musicVideo/publish/x.js
+++ b/server/services/musicVideo/publish/x.js
@@ -11,6 +11,16 @@ import { PUBLISH_STEP_TIMEOUT_MS as T, loginRequired, pasteText, step } from './
const COMPOSE_URL = 'https://x.com/compose/post';
const label = 'X';
+/**
+ * The CSS prefix that scopes selectors to the composer we opened. /compose/post opens as a modal over the
+ * home timeline, whose own inline composer reuses the same data-testids (tweetTextarea_0, tweetButton,
+ * 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] ' : '';
+}
+
export const xAdapter = {
label,
async prepare(page, payload) {
@@ -18,9 +28,10 @@ export const xAdapter = {
await page.waitForTimeout(4000);
if (/\/login|\/i\/flow/.test(page.url())) throw loginRequired(label, COMPOSE_URL);
const account = await page.evaluate(() => (document.querySelector('[data-testid=AppTabBar_Profile_Link]')?.getAttribute('href') || '').replace(/^\//, '') || null).catch(() => null);
+ const scope = await composerScope(page);
for (const [i, post] of payload.posts.entries()) {
- const editor = `[data-testid=tweetTextarea_${i}]`;
- if (i > 0) await step(label, `add post ${i + 1}`, () => page.locator('[data-testid=addButton]').click({ timeout: T }));
+ const editor = `${scope}[data-testid=tweetTextarea_${i}]`;
+ if (i > 0) await step(label, `add post ${i + 1}`, () => page.locator(`${scope}[data-testid=addButton]`).click({ timeout: T }));
await step(label, `write post ${i + 1}`, async () => {
await page.locator(editor).waitFor({ timeout: T });
await pasteText(page, editor, post.text);
@@ -28,20 +39,21 @@ export const xAdapter = {
if (post.media) {
await step(label, `attach media to post ${i + 1}`, async () => {
await page.locator(editor).click();
- await page.locator('input[data-testid=fileInput]').first().setInputFiles(post.media.path, { timeout: T });
+ await page.locator(`${scope}input[data-testid=fileInput]`).first().setInputFiles(post.media.path, { timeout: T });
});
}
}
- await step(label, 'wait for the uploads', () => page.waitForFunction(() => {
- const button = document.querySelector('[data-testid=tweetButton]');
- const uploading = [...document.querySelectorAll('[data-testid=attachments]')].some((a) => /Uploading|Processing/i.test(a.innerText));
+ await step(label, 'wait for the uploads', () => page.waitForFunction((sc) => {
+ const button = document.querySelector(`${sc}[data-testid=tweetButton]`);
+ const uploading = [...document.querySelectorAll(`${sc}[data-testid=attachments]`)].some((a) => /Uploading|Processing/i.test(a.innerText));
return button && button.getAttribute('aria-disabled') !== 'true' && !uploading;
- }, null, { timeout: 600_000 }));
- const lengths = await page.evaluate((n) => Array.from({ length: n }, (_, i) => document.querySelector(`[data-testid=tweetTextarea_${i}]`)?.innerText.length ?? 0), payload.posts.length);
+ }, scope, { timeout: 600_000 }));
+ const lengths = await page.evaluate(([n, sc]) => Array.from({ length: n }, (_, i) => document.querySelector(`${sc}[data-testid=tweetTextarea_${i}]`)?.innerText.length ?? 0), [payload.posts.length, scope]);
return { account, posts: payload.posts.length, lengths };
},
async submit(page, payload) {
- await step(label, 'post the thread', () => page.locator('[data-testid=tweetButton]').click({ timeout: T }));
+ const scope = await composerScope(page);
+ await step(label, 'post the thread', () => page.locator(`${scope}[data-testid=tweetButton]`).click({ timeout: T }));
await step(label, 'wait for it to send', () => page.waitForURL((url) => !/compose/.test(url.toString()), { timeout: 180_000 }));
const url = await step(label, 'find the new thread', async () => {
const profile = await page.locator('[data-testid=AppTabBar_Profile_Link]').getAttribute('href', { timeout: T });
diff --git a/server/services/musicVideo/publish/x.test.js b/server/services/musicVideo/publish/x.test.js
new file mode 100644
index 0000000000..0983d58ae2
--- /dev/null
+++ b/server/services/musicVideo/publish/x.test.js
@@ -0,0 +1,42 @@
+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 }) => {
+ const calls = { pasted: [], clicked: [], waited: [] };
+ const page = {
+ calls,
+ goto: async () => {},
+ url: () => 'https://x.com/compose/post',
+ waitForTimeout: async () => {},
+ 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) && 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 () => {} }),
+ }),
+ };
+ return page;
+};
+
+describe('X composer scope', () => {
+ it('scopes every composer selector to the modal when /compose/post opens over the timeline', async () => {
+ const page = fakePage({ dialog: true });
+ await xAdapter.prepare(page, { posts: [{ text: 'one' }, { text: 'two' }] });
+ expect(page.calls.pasted).toEqual(['[role=dialog] [data-testid=tweetTextarea_0]', '[role=dialog] [data-testid=tweetTextarea_1]']);
+ expect(page.calls.clicked).toContain('[role=dialog] [data-testid=addButton]');
+ expect(page.calls.waited).toContain('[role=dialog] ');
+ });
+
+ 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]']);
+ });
+});