diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-08-16 15:28:28 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-08-16 15:28:28 +0200 |
| commit | 0bd3f805ffbd04b40b5150474336a5e5d200e72b (patch) | |
| tree | 2a92a21e02bae823e9ed52d489d74ba8db3de9b6 /packages/meshbay-hub/tests/test_groups_self_service.py | |
| parent | 0231d240b92a2a11042fa62c0222d4c4b96a859d (diff) | |
| download | meshbay-0bd3f805ffbd04b40b5150474336a5e5d200e72b.tar.gz | |
feat(hub): leaving a group, a cap on public ones, and hosting as a precondition
Leaving is its own endpoint rather than a relaxation of the owner's removal
check — an authorization rule with an exception in it is the one that gets read
wrong later. The owner cannot leave: the group would be left with nobody able
to admit, edit or delete it, which is the answer removal and account deletion
already give.
Public groups are capped at ten live ones per owner. They are the ones that
cost other people something — listed in Discover, joinable by anyone — so a
script that opens hundreds fills the directory for everybody. Private groups
are invisible to non-members and are not capped. Hub staff are exempt; the cap
is anti-spam, not a rule about running an instance. Creation is the only place
it can be checked, and deliberately so, because PATCH refuses to change
visibility at all.
A group is now listed only once a node has announced that it hosts it. Before
that it has no files, no key and nothing to connect to, so showing it to a
member produces a name they cannot open and cannot be told why; its owner still
sees it while they set the node up. `meshbay-hub prune-groups` collects the
ones that never got a node, meant for cron, with --dry-run. The migration
backfills hosted_at from created_at: without that the first run would have
deleted every live group.
Presence rides on the group list itself, read from the signaling registry the
hub already keeps — no poll, no timer. It says a node is connected *to the hub*,
which is not a promise that this browser can reach it and not something a
dishonest hub could not fake; the client downgrades it on a connection it tried
and failed, which is the evidence that concerns the reader.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-hub/tests/test_groups_self_service.py')
| -rw-r--r-- | packages/meshbay-hub/tests/test_groups_self_service.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/packages/meshbay-hub/tests/test_groups_self_service.py b/packages/meshbay-hub/tests/test_groups_self_service.py index a60209d..3202658 100644 --- a/packages/meshbay-hub/tests/test_groups_self_service.py +++ b/packages/meshbay-hub/tests/test_groups_self_service.py @@ -40,6 +40,16 @@ async def _create_group(client, token, name="test-group", visibility="public", return r.json()["group_id"] + +async def _mark_hosted(db_session, *group_ids): + """Pretend a node announced these groups, as /v1/nodes/ws would.""" + from datetime import datetime, timezone + from meshbay_hub.db.models import Group + for gid in group_ids: + (await db_session.get(Group, gid)).hosted_at = datetime.now(timezone.utc) + await db_session.commit() + + @pytest.mark.asyncio async def test_create_group(client): await _register(client, "alice", email="a@x.com") @@ -73,8 +83,11 @@ async def test_join_open_group(client): async def test_join_invite_group_rejected(client): await _register(client, "alice", email="a@x.com") alice_token = await _login(client, "alice") + # Private: invite-only is refused on a public group now, since a group + # everyone can find and nobody can enter is a dead end. What is under test + # here — /join refusing a group that is not open — is unchanged. gid = await _create_group(client, alice_token, "invite-group", - join_policy="invite") + visibility="private", join_policy="invite") await _register(client, "bob", email="b@x.com") bob_token = await _login(client, "bob") @@ -132,11 +145,14 @@ async def test_group_members_non_member_denied(client): @pytest.mark.asyncio -async def test_group_search(client): +async def test_group_search(client, db_session): await _register(client, "alice", email="a@x.com") token = await _login(client, "alice") - await _create_group(client, token, "alpha-team") - await _create_group(client, token, "beta-team") + a = await _create_group(client, token, "alpha-team") + b = await _create_group(client, token, "beta-team") + # The directory shows groups a node has announced. Marked here so this test + # exercises the search filter rather than the hosting one. + await _mark_hosted(db_session, a, b) r = await client.get("/v1/groups?q=alpha") assert r.status_code == 200 |