From 45671a70efb2673860eda5a8b8e2e1d86fb9426f Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Tue, 25 Apr 2023 15:21:58 +0200 Subject: [PATCH 01/10] Add restart test that fails too fast --- .eslintrc.js | 2 +- test/exclude-members.test.js | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 22dfa17..bf7549e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,7 +13,7 @@ module.exports = { SharedArrayBuffer: 'readonly', }, parserOptions: { - ecmaVersion: 2020, + ecmaVersion: 2021, sourceType: 'module', }, rules: { diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index ec51c3a..7c03de7 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -607,3 +607,83 @@ test('Can exclude a person in a group with a lot of members', async (t) => { await p(alice.close)(true) await Promise.all(peers.map((peer) => p(peer.close)(true))) }) + +test("restarting the client doesn't make us rejoin old stuff", async (t) => { + const alice = Testbot({ + keys: ssbKeys.generate(null, 'alice'), + mfSeed: Buffer.from( + '000000000000000000000000000000000000000000000000000000000000a1ce', + 'hex' + ), + }) + let bob = Testbot({ + name: 'bobrestart', + keys: ssbKeys.generate(null, 'bob'), + mfSeed: Buffer.from( + '0000000000000000000000000000000000000000000000000000000000000b0b', + 'hex' + ), + }) + + await Promise.all([alice.tribes2.start(), bob.tribes2.start()]) + + const bobRoot = await p(bob.metafeeds.findOrCreate)() + + await replicate(alice, bob).catch(t.error) + + const { id: groupId } = await alice.tribes2 + .create() + .catch((err) => t.error(err, 'alice failed to create group')) + + await alice.tribes2 + .addMembers(groupId, [bobRoot.id]) + .then(() => t.pass('added bob')) + .catch((err) => t.error(err, 'add bob fail')) + + await replicate(alice, bob).catch(t.error) + + await bob.tribes2.acceptInvite(groupId) + + await replicate(alice, bob).catch(t.error) + + await alice.tribes2 + .excludeMembers(groupId, [bobRoot.id]) + .then(() => t.pass('alice excluded bob')) + .catch((err) => t.error(err, 'remove member fail')) + + await replicate(alice, bob).catch(t.error) + + t.deepEquals( + await bob.tribes2.get(groupId), + { id: groupId, excluded: true }, + "bob knows he's excluded from the group before restart" + ) + + await p(bob.close)(true).then(() => t.pass("bob's client was closed")) + bob = Testbot({ + rimraf: false, + name: 'bobrestart', + keys: ssbKeys.generate(null, 'bob'), + mfSeed: Buffer.from( + '0000000000000000000000000000000000000000000000000000000000000b0b', + 'hex' + ), + }) + t.pass('bob got a new client') + await bob.tribes2.start().then(() => t.pass('bob restarted')) + + t.deepEquals( + await bob.tribes2.get(groupId), + { id: groupId, excluded: true }, + "bob knows he's excluded from the group after restart" + ) + + // TODO list() + + // TODO listInvites() + + // TODO acceptInvite() + + await p(alice.close)(true) + await p(bob.close)(true) +}) From 4d9c728039367d4608f143c66c6ecd3391109495 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 27 Apr 2023 15:05:34 +0200 Subject: [PATCH 02/10] Use box2 that doesn't remove readKeys on exclude --- index.js | 14 ++++++++++---- package.json | 2 +- test/exclude-members.test.js | 3 +++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 3d574f6..be80ed9 100644 --- a/index.js +++ b/index.js @@ -477,16 +477,21 @@ module.exports = { function start(cb) { if (cb === undefined) return promisify(start)() + console.log('running start for', ssb.id) + console.log('about to find additions feed') findOrCreateAdditionsFeed((err) => { // prettier-ignore if (err) return cb(clarify(err, 'Error finding or creating additions feed when starting ssb-tribes2')) + console.log('got additions feed') return cb() }) + console.log('about to find root feed') ssb.metafeeds.findOrCreate((err, myRoot) => { // prettier-ignore if (err) return cb(clarify(err, 'Error getting own root in start()')) + console.log('got root feed') // check if we've been excluded pull( @@ -503,7 +508,10 @@ module.exports = { pull.drain( (msg) => { const groupId = msg.value.content.recps[0] - ssb.box2.excludeGroupInfo(groupId, null) + ssb.box2.excludeGroupInfo(groupId, (err) => { + // prettier-ignore + if (err) return cb(clarify(err, 'Error on excluding group info after finding exclusion of ourselves')) + }) }, (err) => { // prettier-ignore @@ -528,9 +536,7 @@ module.exports = { paraMap((msg, cb) => { pull( ssb.box2.listGroupIds(), - pull.filter((groupId) => - groupId === msg.value.content.recps[0] - ), + pull.filter((groupId) => groupId === msg.value.content.recps[0]), pull.take(1), pull.collect((err, groupIds) => { // prettier-ignore diff --git a/package.json b/package.json index 3f8b89d..f7fbfd7 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "pull-stream": "^3.7.0", "set.prototype.difference": "^1.0.2", "ssb-bfe": "^3.7.0", - "ssb-box2": "^6.1.0", + "ssb-box2": "ssbc/ssb-box2#exclude-keep-readkeys", "ssb-crut": "^4.6.2", "ssb-db2": "^6.3.3", "ssb-meta-feeds": "^0.39.0", diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 7c03de7..51a499b 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -659,6 +659,9 @@ test("restarting the client doesn't make us rejoin old stuff", async (t) => { "bob knows he's excluded from the group before restart" ) + // TODO remove probably? + await p(setTimeout)(3000) + await p(bob.close)(true).then(() => t.pass("bob's client was closed")) bob = Testbot({ rimraf: false, From 7fa2e29f0f05034113f90265f40bc25b2685218b Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Tue, 2 May 2023 13:31:34 +0200 Subject: [PATCH 03/10] Use new box2 release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f7fbfd7..fd04aae 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "pull-stream": "^3.7.0", "set.prototype.difference": "^1.0.2", "ssb-bfe": "^3.7.0", - "ssb-box2": "ssbc/ssb-box2#exclude-keep-readkeys", + "ssb-box2": "^7.0.0", "ssb-crut": "^4.6.2", "ssb-db2": "^6.3.3", "ssb-meta-feeds": "^0.39.0", From f8e0e57081a60d0c72ca774958e9c1ff9e2d85f5 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Tue, 2 May 2023 16:51:19 +0200 Subject: [PATCH 04/10] Adapt restart test to new excluded group format --- test/exclude-members.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 1f20936..3f6c75a 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -652,9 +652,10 @@ test("restarting the client doesn't make us rejoin old stuff", async (t) => { await replicate(alice, bob).catch(t.error) - t.deepEquals( - await bob.tribes2.get(groupId), - { id: groupId, excluded: true }, + const beforeGroup = await bob.tribes2.get(groupId) + t.equals(beforeGroup.id, groupId, 'correct group id') + t.true( + beforeGroup.excluded, "bob knows he's excluded from the group before restart" ) @@ -674,9 +675,8 @@ test("restarting the client doesn't make us rejoin old stuff", async (t) => { t.pass('bob got a new client') await bob.tribes2.start().then(() => t.pass('bob restarted')) - t.deepEquals( - await bob.tribes2.get(groupId), - { id: groupId, excluded: true }, + t.true( + (await bob.tribes2.get(groupId)).excluded, "bob knows he's excluded from the group after restart" ) From 088d1bb2d08253d5587d2e823f5161b976885094 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 3 May 2023 13:54:15 +0200 Subject: [PATCH 05/10] Test list() after restart --- test/exclude-members.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 3f6c75a..4bdd737 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -607,7 +607,7 @@ test('Can exclude a person in a group with a lot of members', async (t) => { await Promise.all(all.map((peer) => p(peer.close)(true))) }) -test("restarting the client doesn't make us rejoin old stuff", async (t) => { +test.only("restarting the client doesn't make us rejoin old stuff", async (t) => { const alice = Testbot({ keys: ssbKeys.generate(null, 'alice'), mfSeed: Buffer.from( @@ -680,7 +680,8 @@ test("restarting the client doesn't make us rejoin old stuff", async (t) => { "bob knows he's excluded from the group after restart" ) - // TODO list() + const list = await pull(bob.tribes2.list(), pull.collectAsPromise()) + t.equal(list.length, 0, "there aren't any groups in bob's group list anymore") // TODO listInvites() From 6c1eecf7917cf5c64cd2c55029a4155875026c18 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 3 May 2023 13:58:17 +0200 Subject: [PATCH 06/10] Test listInvites after exclude and restart --- test/exclude-members.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 4bdd737..c80e1b8 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -683,7 +683,8 @@ test.only("restarting the client doesn't make us rejoin old stuff", async (t) => const list = await pull(bob.tribes2.list(), pull.collectAsPromise()) t.equal(list.length, 0, "there aren't any groups in bob's group list anymore") - // TODO listInvites() + const invites = await pull(bob.tribes2.listInvites(), pull.collectAsPromise()) + t.equal(invites.length, 0, "bob doesn't have any invites") // TODO acceptInvite() From 23f37bb2035952af73b1ff51e55b0b590bffab0e Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 3 May 2023 14:05:11 +0200 Subject: [PATCH 07/10] Bob can't accept invite again after being excluded --- test/exclude-members.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index c80e1b8..680539e 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -686,7 +686,10 @@ test.only("restarting the client doesn't make us rejoin old stuff", async (t) => const invites = await pull(bob.tribes2.listInvites(), pull.collectAsPromise()) t.equal(invites.length, 0, "bob doesn't have any invites") - // TODO acceptInvite() + await bob.tribes2 + .acceptInvite(groupId) + .then(() => t.fail("bob didn't error when trying to accept invalid invite")) + .catch(() => t.pass("bob couldn't accept old invite we were excluded from")) await p(alice.close)(true) await p(bob.close)(true) From 0336c02a568061614f300984ccdbfa4a6ad28235 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 3 May 2023 14:08:04 +0200 Subject: [PATCH 08/10] Remove .only --- test/exclude-members.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 680539e..224f9cf 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -198,7 +198,7 @@ test('Verify that you actually get excluded from a group', async (t) => { await Promise.all([alice.tribes2.start(), bob.tribes2.start()]) t.pass('tribes2 started for both alice and bob') - const [aliceId, bobId] = await getRootIds([alice, bob], t) + const [, bobId] = await getRootIds([alice, bob], t) await replicate(alice, bob) t.pass('alice and bob replicate their trees') @@ -323,7 +323,7 @@ test("If you're not the excluder nor the excludee then you should still be in th ]) t.pass('tribes2 started for everyone') - const [aliceId, bobId, carolId] = await getRootIds([alice, bob, carol], t) + const [, bobId, carolId] = await getRootIds([alice, bob, carol], t) await replicate(alice, bob) await replicate(alice, carol) @@ -450,7 +450,7 @@ test('Get added to an old epoch but still find newer epochs', async (t) => { ]) t.pass('tribes2 started for everyone') - const [aliceId, bobId, carolId] = await getRootIds([alice, bob, carol], t) + const [, bobId, carolId] = await getRootIds([alice, bob, carol], t) await replicate(alice, bob) await replicate(alice, carol) @@ -607,7 +607,7 @@ test('Can exclude a person in a group with a lot of members', async (t) => { await Promise.all(all.map((peer) => p(peer.close)(true))) }) -test.only("restarting the client doesn't make us rejoin old stuff", async (t) => { +test("restarting the client doesn't make us rejoin old stuff", async (t) => { const alice = Testbot({ keys: ssbKeys.generate(null, 'alice'), mfSeed: Buffer.from( From 83ce6d6105d29c28f16dcd12714f5013c3338de0 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 3 May 2023 14:08:33 +0200 Subject: [PATCH 09/10] Remove old logs --- index.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/index.js b/index.js index be80ed9..b3de9c6 100644 --- a/index.js +++ b/index.js @@ -477,21 +477,16 @@ module.exports = { function start(cb) { if (cb === undefined) return promisify(start)() - console.log('running start for', ssb.id) - console.log('about to find additions feed') findOrCreateAdditionsFeed((err) => { // prettier-ignore if (err) return cb(clarify(err, 'Error finding or creating additions feed when starting ssb-tribes2')) - console.log('got additions feed') return cb() }) - console.log('about to find root feed') ssb.metafeeds.findOrCreate((err, myRoot) => { // prettier-ignore if (err) return cb(clarify(err, 'Error getting own root in start()')) - console.log('got root feed') // check if we've been excluded pull( From a31bd5da0639e4ef3fe009c2d76900e39ee020f5 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 3 May 2023 14:12:19 +0200 Subject: [PATCH 10/10] Remove setTimeout --- test/exclude-members.test.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/exclude-members.test.js b/test/exclude-members.test.js index 224f9cf..8aae0e3 100644 --- a/test/exclude-members.test.js +++ b/test/exclude-members.test.js @@ -659,9 +659,6 @@ test("restarting the client doesn't make us rejoin old stuff", async (t) => { "bob knows he's excluded from the group before restart" ) - // TODO remove probably? - await p(setTimeout)(3000) - await p(bob.close)(true).then(() => t.pass("bob's client was closed")) bob = Testbot({ rimraf: false,