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

Add requested starter comments after native Reddit video publishing

[._.]/ Adam Eivy4d3df7797c71
diff --git a/server/services/musicVideo/publish/reddit.js b/server/services/musicVideo/publish/reddit.js
index a0da313dd0..57f791ec25 100644
--- a/server/services/musicVideo/publish/reddit.js
+++ b/server/services/musicVideo/publish/reddit.js
@@ -86,12 +86,15 @@ async function prepareVideo(page, payload) {
async function submitVideo(page, payload) {
await step(label, 'post', () => page.locator('#inner-post-submit-button').click({ timeout: T }));
await step(label, 'wait for it to post', () => page.waitForURL((url) => !/\/submit/.test(url.toString()), { timeout: 180_000 }));
- const url = await step(label, 'find the new post', () => page.evaluate(async (title) => {
+ const url = await step(label, 'find the new post', () => page.evaluate(async ({ title, firstComment }) => {
const me = await (await fetch('/api/me.json', { credentials: 'include' })).json();
const list = await (await fetch(`/user/${me.data.name}/submitted.json?limit=5`, { credentials: 'include' })).json();
const hit = (list?.data?.children || []).map((c) => c.data).find((d) => d.title === title);
+ if (hit?.name && firstComment) {
+ await fetch('/api/comment', { method: 'POST', credentials: 'include', body: new URLSearchParams({ thing_id: hit.name, text: firstComment, api_type: 'json', uh: me.data.modhash }) });
+ }
return hit ? `https://www.reddit.com${hit.permalink}` : null;
- }, payload.title));
+ }, { title: payload.title, firstComment: payload.firstComment }));
return { url };
}
diff --git a/server/services/musicVideo/publish/reddit.test.js b/server/services/musicVideo/publish/reddit.test.js
new file mode 100644
index 0000000000..1d2a386895
--- /dev/null
+++ b/server/services/musicVideo/publish/reddit.test.js
@@ -0,0 +1,45 @@
+/** Adapter contract: explicit starter comments follow the same post returned
+ * to the director for native-video, text and link publishing. No browser or
+ * network is involved; execute the page callback with an isolated session API.
+ */
+import { describe, expect, it, vi } from 'vitest';
+import { runInNewContext } from 'node:vm';
+import { redditAdapter } from './reddit.js';
+
+const post = { name: 't3_example', title: 'Example Video', permalink: '/r/example/comments/example/clip/', url: 'https://old.reddit.com/r/example/comments/example/clip/' };
+
+function sessionPage() {
+ const request = vi.fn(async (url) => {
+ const body = url === '/api/me.json' ? { data: { name: 'example-user', modhash: 'example-modhash' } }
+ : url.includes('/submitted.json') ? { data: { children: [{ data: post }] } }
+ : url === '/api/submit' ? { json: { data: post, errors: [] } }
+ : { json: { errors: [] } };
+ return { json: async () => body };
+ });
+ const page = {
+ locator: vi.fn(() => ({ click: vi.fn(async () => {}) })),
+ waitForURL: vi.fn(async () => {}),
+ evaluate: (callback, input) => runInNewContext(`(${callback.toString()})`, { fetch: request, URLSearchParams })(input),
+ };
+ return { page, request };
+}
+
+describe('Reddit publishing starter comments', () => {
+ it.each(['video', 'self', 'link'])('adds an explicitly requested first comment to the returned %s post', async (kind) => {
+ const { page, request } = sessionPage();
+ const result = await redditAdapter.submit(page, { kind, title: post.title, subreddit: 'example',
+ url: 'https://example.com/video', body: 'Example post body', firstComment: 'Example starter prompt' });
+ expect(result.url).toBe('https://www.reddit.com/r/example/comments/example/clip/');
+ const comments = request.mock.calls.filter(([url]) => url === '/api/comment');
+ expect(comments).toHaveLength(1);
+ expect(comments[0][1]).toMatchObject({ method: 'POST', credentials: 'include' });
+ expect(Object.fromEntries(comments[0][1].body)).toEqual({ thing_id: post.name,
+ text: 'Example starter prompt', api_type: 'json', uh: 'example-modhash' });
+ });
+
+ it('publishes native video without adding a comment when none was requested', async () => {
+ const { page, request } = sessionPage();
+ await expect(redditAdapter.submit(page, { kind: 'video', title: post.title })).resolves.toEqual({ url: 'https://www.reddit.com/r/example/comments/example/clip/' });
+ expect(request.mock.calls.some(([url]) => url === '/api/comment')).toBe(false);
+ });
+});