| … | … | @@ -20,14 +20,18 @@ const post = (rkey, createdAt) => ({ uri: 'x/' + rkey, value: { $type: 'app.bsky |
| 20 | 20 | |
| 21 | 21 | function fakeMembrane ({ members = [WJ, E2], records, revs }) { |
| 22 | 22 | const listeners = [] |
| 23 | const labelListeners = [] |
| 23 | 24 | const state = { members, records, revs, listCalls: 0, watchers: [] } |
| 24 | 25 | const membrane = { |
| 25 | 26 | state, |
| 26 | 27 | extensions: { xrpc: new Map(), ws: new Map() }, |
| 27 | 28 | relay: { seq: { core: { on: (ev, fn) => { if (ev === 'append') listeners.push(fn) }, off: () => {} } } }, |
| 28 | 29 | appendNow: () => { for (const fn of listeners) fn() }, |
| 30 | // The router's onLabels: fires when a DID's front first opens a label core (atproto-did-peer). |
| 31 | labelsAppear: (did) => { for (const fn of labelListeners) fn(did, { labels: {} }) }, |
| 29 | 32 | metrics: () => ({ dids: Object.keys(state.revs).map((did) => ({ did, rev: state.revs[did] })) }), |
| 30 | 33 | peers: { |
| 34 | onLabels: (fn) => { labelListeners.push(fn); return () => { const i = labelListeners.indexOf(fn); if (i >= 0) labelListeners.splice(i, 1) } }, |
| 31 | 35 | isFronted: (did) => did in state.revs, |
| 32 | 36 | front: async (did) => ({ |
| 33 | 37 | listRecords: async (col, { limit = 100, cursor = null } = {}) => { |
| … | … | @@ -207,3 +211,35 @@ test('★ with a projector: every roster change is applied, with the community D |
| 207 | 211 | t.alike(memberLabels.applied[memberLabels.applied.length - 1].members, [WJ], 'a member leaving is applied too') |
| 208 | 212 | t.alike(lens.metrics().memberLabels, { feeds: { 'loser-club': { added: 2 } } }) |
| 209 | 213 | }) |
| 214 | |
| 215 | // ⛔ MEASURED 2026-10-14 on stortron: the projector's only run was at boot, while loser-club's hpp was not yet a |
| 216 | // labeler ("this DID is not a labeler"). hpp was restarted with `labeler: true` and began announcing a label |
| 217 | // core, and nothing re-ran — the roster had not changed, so the badges never appeared. A labeler coming online |
| 218 | // IS the event: the router's onLabels fires when the community DID's front first opens a label core. |
| 219 | test('⛔ the community DID gaining a label core re-runs the projector; another DID does not', async (t) => { |
| 220 | const m = fakeMembrane({ records: baseRecords(), revs: { [WJ]: 'r1', [E2]: 'r1', [LC]: 'r1' } }) |
| 221 | const memberLabels = fakeProjector() |
| 222 | const lens = createLens({ membrane: m, feeds: [{ id: 'loser-club', roomKey: ROOM }], log: () => {}, debounceMs: 5, memberLabels }) |
| 223 | await lens.start() |
| 224 | t.teardown(() => lens.stop()) |
| 225 | const before = memberLabels.applied.length |
| 226 | t.is(before, 1, 'the boot run') |
| 227 | |
| 228 | m.labelsAppear(WJ) |
| 229 | t.is(memberLabels.applied.length, before, 'a member DID\'s label core is not the labeler coming online') |
| 230 | |
| 231 | m.labelsAppear(LC) |
| 232 | t.is(memberLabels.applied.length, before + 1, 'the community DID\'s label core re-runs the projector') |
| 233 | t.alike(memberLabels.applied[before], { id: 'loser-club', communityDid: LC, members: [WJ, E2] }, 'with the current roster') |
| 234 | }) |
| 235 | |
| 236 | test('stop unsubscribes from onLabels — a stopped lens projects nothing', async (t) => { |
| 237 | const m = fakeMembrane({ records: baseRecords(), revs: { [WJ]: 'r1', [E2]: 'r1', [LC]: 'r1' } }) |
| 238 | const memberLabels = fakeProjector() |
| 239 | const lens = createLens({ membrane: m, feeds: [{ id: 'loser-club', roomKey: ROOM }], log: () => {}, debounceMs: 5, memberLabels }) |
| 240 | await lens.start() |
| 241 | await lens.stop() |
| 242 | const n = memberLabels.applied.length |
| 243 | m.labelsAppear(LC) |
| 244 | t.is(memberLabels.applied.length, n) |
| 245 | }) |