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

Type the LinkedIn first comment only once per draft

Claudeae1ac243ed31
diff --git a/server/services/musicVideo/publish/linkedin.js b/server/services/musicVideo/publish/linkedin.js
index 97be27bacb..af37034df8 100644
--- a/server/services/musicVideo/publish/linkedin.js
+++ b/server/services/musicVideo/publish/linkedin.js
@@ -21,6 +21,8 @@ const SIGN_IN = /linkedin\.com\/(?:login|authwall|checkpoint|uas\/login|signup)/
const DIALOG = '[role=dialog]';
const EDITOR = `${DIALOG} .ql-editor[contenteditable=true]`;
const COMMENT_EDITOR = '.comments-comment-box .ql-editor[contenteditable=true], .comments-comment-texteditor .ql-editor[contenteditable=true]';
+// Drafts whose first comment was already typed: a reload of the post page must not type it twice.
+const commented = new WeakSet();
const POST_URL = /^https:\/\/www\.linkedin\.com\/feed\/update\/urn:li:(?:activity|share|ugcPost):\d+/;
/** The post's opening words, as the post page shows them (its first line; LinkedIn folds the rest under "see more"). */
@@ -82,7 +84,8 @@ export const linkedinAdapter = {
},
async findPost(page, payload) {
const url = await landedOnPost(page, POST_URL, opening(payload.text), ([match]) => `${match}/`);
- if (url && payload.firstComment) {
+ if (url && payload.firstComment && !commented.has(payload)) {
+ commented.add(payload);
// Typed, never sent: the director presses Comment. A miss still records the post.
await page.locator(COMMENT_EDITOR).first().click({ timeout: 10_000 })
.then(() => pasteText(page, COMMENT_EDITOR, payload.firstComment))
diff --git a/server/services/musicVideo/publish/linkedin.test.js b/server/services/musicVideo/publish/linkedin.test.js
index 498542c939..016bd4ec73 100644
--- a/server/services/musicVideo/publish/linkedin.test.js
+++ b/server/services/musicVideo/publish/linkedin.test.js
@@ -55,6 +55,9 @@ describe('LinkedIn adapter', () => {
await expect(linkedinAdapter.findPost(page, payload)).resolves.toBe('https://www.linkedin.com/feed/update/urn:li:activity:7123456789/');
expect(page.log.filter(([kind]) => kind === 'paste').map(([, , text]) => text)).toEqual([payload.firstComment]);
expect(page.log.filter(([kind]) => kind === 'click').every(([, sel]) => /comment/.test(sel))).toBe(true);
+ // A reload of the post page records it again but never types the comment twice.
+ await linkedinAdapter.findPost(page, payload);
+ expect(page.log.filter(([kind]) => kind === 'paste')).toHaveLength(1);
});
it('ignores the feed and other posts', async () => {
@@ -68,7 +71,7 @@ describe('LinkedIn adapter', () => {
const page = fakePage({ url: 'https://www.linkedin.com/feed/update/urn:li:activity:7/', shows: 'I made a music video.' });
page.locator = () => ({ first() { return this; }, click: async () => { throw new Error('no comment box'); } });
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
- await expect(linkedinAdapter.findPost(page, payload)).resolves.toBe('https://www.linkedin.com/feed/update/urn:li:activity:7/');
+ await expect(linkedinAdapter.findPost(page, { ...payload })).resolves.toBe('https://www.linkedin.com/feed/update/urn:li:activity:7/');
expect(warn).toHaveBeenCalled();
warn.mockRestore();
});