Something went wrong. Try again.
A live media wall for your Bluesky follows
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223import assert from 'node:assert/strict';import { test } from 'node:test';import type { InteractionUpdate } from './feed.js';import { createInteractionController } from './interaction-controller.js';import type { createInteractions } from './interactions.js';
const actor = 'did:plc:author';const post = { uri: `at://${actor}/app.bsky.feed.post/example`, cid: 'bafyreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'};const likeUri = 'at://did:plc:viewer/app.bsky.feed.like/like';const repostUri = 'at://did:plc:viewer/app.bsky.feed.repost/repost';const blockUri = 'at://did:plc:viewer/app.bsky.graph.block/block';const followUri = 'at://did:plc:viewer/app.bsky.graph.follow/follow';
type Controller = ReturnType<typeof createInteractionController>;const actions: { method: string; run: (controller: Controller) => Promise<unknown>; args: unknown[]; update: InteractionUpdate; result?: string;}[] = [ { method: 'like', run: (c) => c.like(post), args: [post], update: { kind: 'post', ...post, changes: { likeUri } }, result: likeUri }, { method: 'unlike', run: (c) => c.unlike(post, likeUri), args: [post.uri, likeUri], update: { kind: 'post', ...post, changes: { likeUri: null } } }, { method: 'repost', run: (c) => c.repost(post), args: [post], update: { kind: 'post', ...post, changes: { repostUri } }, result: repostUri }, { method: 'unrepost', run: (c) => c.unrepost(post, repostUri), args: [post.uri, repostUri], update: { kind: 'post', ...post, changes: { repostUri: null } } }, { method: 'bookmark', run: (c) => c.bookmark(post), args: [post], update: { kind: 'post', ...post, changes: { bookmarked: true } } }, { method: 'unbookmark', run: (c) => c.unbookmark(post), args: [post.uri], update: { kind: 'post', ...post, changes: { bookmarked: false } } }, { method: 'follow', run: (c) => c.follow(actor), args: [actor], update: { kind: 'actor', did: actor, following: followUri }, result: followUri }, { method: 'unfollow', run: (c) => c.unfollow(actor, followUri), args: [actor, followUri], update: { kind: 'actor', did: actor, following: null } }, { method: 'mute', run: (c) => c.mute(actor), args: [actor], update: { kind: 'actor', did: actor, muted: true } }, { method: 'unmute', run: (c) => c.unmute(actor), args: [actor], update: { kind: 'actor', did: actor, muted: false } }, { method: 'block', run: (c) => c.block(actor), args: [actor], update: { kind: 'actor', did: actor, blocking: blockUri }, result: blockUri }, { method: 'unblock', run: (c) => c.unblock(actor, blockUri), args: [actor, blockUri], update: { kind: 'actor', did: actor, blocking: null } }];
function fixture() { const calls: { method: string; args: unknown[] }[] = []; const updates: InteractionUpdate[] = []; let error: Error | undefined; let gate: Promise<void> | undefined; let closes = 0; const record = async (method: string, args: unknown[]) => { calls.push({ method, args }); await gate; if (error) throw error; }; const service = { async like(...args) { await record('like', args); return likeUri; }, async unlike(...args) { await record('unlike', args); }, async repost(...args) { await record('repost', args); return repostUri; }, async unrepost(...args) { await record('unrepost', args); }, async bookmark(...args) { await record('bookmark', args); }, async unbookmark(...args) { await record('unbookmark', args); }, async follow(...args) { await record('follow', args); return followUri; }, async unfollow(...args) { await record('unfollow', args); }, async mute(...args) { await record('mute', args); }, async unmute(...args) { await record('unmute', args); }, async block(...args) { await record('block', args); return blockUri; }, async unblock(...args) { await record('unblock', args); }, close() { closes++; } } satisfies ReturnType<typeof createInteractions>; return { controller: createInteractionController(service, (update) => { updates.push(update); }), calls, updates, get closes() { return closes; }, fail(value: Error) { error = value; }, pause() { let release!: () => void; gate = new Promise<void>((resolve) => { release = resolve; }); return release; } };}
for (const action of actions) { void test(`${action.method} reconciles exactly once only after confirmed success`, async () => { const f = fixture(); const release = f.pause(); const pending = action.run(f.controller); assert.deepEqual(f.calls, [{ method: action.method, args: action.args }]); assert.deepEqual(f.updates, []); release(); assert.equal(await pending, action.result); assert.deepEqual(f.updates, [action.update]); });
void test(`${action.method} propagates failure without reconciliation or retries`, async () => { const f = fixture(); const error = new Error('write failed'); f.fail(error); await assert.rejects(action.run(f.controller), (actual) => actual === error); assert.deepEqual(f.calls, [{ method: action.method, args: action.args }]); assert.deepEqual(f.updates, []); });
void test(`${action.method} may finish after close but cannot reconcile`, async () => { const f = fixture(); const release = f.pause(); const pending = action.run(f.controller); f.controller.close(); assert.equal(f.closes, 1); release(); assert.equal(await pending, action.result); assert.deepEqual(f.updates, []); });
void test(`${action.method} rejects new writes after close without calling the service`, async () => { const f = fixture(); f.controller.close(); f.controller.close(); await assert.rejects(action.run(f.controller), /closed/); assert.equal(f.closes, 1); assert.deepEqual(f.calls, []); assert.deepEqual(f.updates, []); });}