| … | … | @@ -4,7 +4,7 @@ |
| 4 | 4 | // ops linearize through the owner (sole indexer) — the write layer. |
| 5 | 5 | // Bare-native (Autobase/Hyperbee need a disk path). Run: bare test/community-room.test.mjs |
| 6 | 6 | import Corestore from 'corestore' |
| 7 | | import { CommunityRoom } from '../index.js' |
| 7 | import { CommunityRoom, CommunityRooms } from '../index.js' |
| 8 | 8 | |
| 9 | 9 | const assert = (c, m) => { if (!c) { console.error('FAIL:', m); process.exit(1) } console.log(' ok -', m) } |
| 10 | 10 | const sleep = (ms) => new Promise((r) => setTimeout(r, ms)) |
| … | … | @@ -67,7 +67,25 @@ assert(await until(async () => { const m = await reader.members(); return m.incl |
| 67 | 67 | const final = (await owner.members()).sort() |
| 68 | 68 | assert(final.length === 2 && final.includes(C) && final.includes(D), 'final roster = {C,D} (A banned by mod, B banned by owner)') |
| 69 | 69 | |
| 70 | | console.log('\nFAVELA-COMMUNITY OK (Bare-native): keyless read + mod admission + co-writer membership/moderation linearize through the owner') |
| 70 | // ── ROSTER WATCHER: a member added AFTER watch starts reaches the consumer with no re-open ── |
| 71 | // This is favela-web's path: index members added to a room LATER without a restart (DESIGN §7). We drive |
| 72 | // replication by hand (no swarm) and assert the watcher fires a baseline AND a delta. |
| 73 | const watchStore = new Corestore('data/cc-watch-' + stamp) |
| 74 | const crooms = new CommunityRooms(watchStore, null) // no swarm — wire replication manually below |
| 75 | const seen = [] |
| 76 | const unwatch = await crooms.watch(ROOM, (dids) => { seen.push(dids.slice().sort()) }, { debounceMs: 50 }) |
| 77 | const watchReader = await crooms.room(ROOM) // same replica watch() opened |
| 78 | const unwireW = wire(owner, watchReader) |
| 79 | // current roster at this point = {C, D} (A + B banned above) |
| 80 | assert(await until(() => seen.length > 0 && seen[seen.length - 1].includes(D) && seen[seen.length - 1].includes(C)), 'watch BASELINE: consumer sees the current roster {C,D} after replication') |
| 81 | const E = 'did:plc:erin2222222222222222222222' |
| 82 | await owner.addMember(E) |
| 83 | assert(await until(() => seen[seen.length - 1].includes(E)), 'watch DELTA: a member (E) added AFTER watch started reaches the consumer with NO re-open') |
| 84 | await unwatch() |
| 85 | unwireW() |
| 86 | |
| 87 | console.log('\nFAVELA-COMMUNITY OK (Bare-native): keyless read + mod admission + co-writer membership/moderation linearize through the owner + roster watcher (baseline + delta)') |
| 71 | 88 | unwireR(); unwireM() |
| 72 | 89 | await owner.close(); await reader.close(); await mod.close() |
| 73 | | try { await ownerStore.close(); await readerStore.close(); await modStore.close() } catch {} |
| 90 | try { await crooms.close() } catch {} |
| 91 | try { await ownerStore.close(); await readerStore.close(); await modStore.close(); await watchStore.close() } catch {} |