From f7917bdde37fe089485bb2b65c5504315dcc9c56 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Wed, 2 Sep 2026 00:38:27 +0200 Subject: fix(hub): fall back to the group's first app when the landing tab is absent A group could open on a tab that rendered nothing: no panel, no tab shown active, and nothing on screen to explain it. The landing tab is chosen at mount from a preference -- default_tab for the group, else the account-wide one, else 'chat'. Which applications the group runs comes from the node, in the handshake ack, several awaits later. A preference is a preference, not a promise that the app exists here, so the two disagree in two ordinary cases: the group has Chat disabled while 'chat' is everyone's default, or the reader prefers an app this group does not run. `apps.map(a => tab === a.key && ...)` then matches nothing. The first app the group does offer answers both. Two more cases come free: a preference naming an app that no longer exists, and an operator disabling the app someone is currently looking at -- enabledApps changes live over apps_enabled, and being moved to a working tab beats staring at an empty panel. Settings is exempt: it is not an application, and the create-group wizard lands on it deliberately. `const apps` moves above the effect that reads it; a const further down would be in its temporal dead zone, which is the hook-ordering trap already recorded in CLAUDE.md. tests/harness/group_tab_probe.py renders the real GroupPage against a stub node answering a chosen enabled_apps and reads the tab bar back, over five cases. With the fix reverted the three fallback cases report no active tab at all and four of the six tests fail; the two that pass either way are the ones that must not change -- a group running everything, and a preference the group does honour (Videos stays selected, so the fallback has not become "always the first app"). Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01W8oRqEHhnKUr1NfmTVdcyL --- .../meshbay-hub/tests/test_group_tab_fallback.py | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 packages/meshbay-hub/tests/test_group_tab_fallback.py (limited to 'packages/meshbay-hub/tests/test_group_tab_fallback.py') diff --git a/packages/meshbay-hub/tests/test_group_tab_fallback.py b/packages/meshbay-hub/tests/test_group_tab_fallback.py new file mode 100644 index 0000000..6310b9c --- /dev/null +++ b/packages/meshbay-hub/tests/test_group_tab_fallback.py @@ -0,0 +1,75 @@ +""" +A group always opens on a tab that exists. + +The landing tab comes from a preference and is chosen at mount; which +applications the group runs comes from the node, several awaits later. When the +two disagree — Chat disabled here while 'chat' is the default, or a preferred +app this group does not offer — the page used to render no panel at all, with +no tab shown active and nothing on screen to explain it. + +A string comparison against a list that arrives later is not something reading +`group-page.js` makes obvious, so this renders the real `GroupPage` against a +stub node and reads the tab bar back. +""" +import json +import shutil +import subprocess +from pathlib import Path + +import pytest + +HARNESS = Path(__file__).parent / "harness" / "group_tab_probe.py" +STATIC = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static" + +pytestmark = pytest.mark.skipif( + shutil.which("google-chrome") is None or not (STATIC / "group-page.js").exists(), + reason="Chrome or the SPA sources are not available") + + +@pytest.fixture(scope="module") +def cases(): + run = subprocess.run(["python3", str(HARNESS)], capture_output=True, timeout=180) + assert run.returncode == 0, run.stderr.decode()[-2000:] + return {c["name"]: c for c in json.loads(run.stdout.decode())} + + +# Asserted by position, not by label: the harness renders in whatever language +# the browser resolves to. + +def test_every_case_lands_somewhere(cases): + """The bug, stated once: a tab bar with nothing selected and nothing under + it.""" + for name, case in cases.items(): + assert case["active"] >= 0, f"{name}: no tab is active" + assert case["panelDrawn"], f"{name}: a tab is active but no panel was drawn" + + +def test_the_default_is_the_first_app(cases): + """Nothing changes for a group running everything.""" + case = cases["every app, default chat"] + assert case["active"] == 0 + + +def test_a_disabled_default_falls_back(cases): + """'chat' is the default for everyone, and a group may not run it.""" + case = cases["chat disabled"] + assert case["active"] == 0, "should have fallen back to the group's first app" + assert len(case["tabs"]) == 3, "Files, Videos and Settings, with no Chat tab" + + +def test_a_preference_for_an_absent_app_falls_back(cases): + """The preference is global; the app list is per group.""" + assert cases["preferred app absent"]["active"] == 0 + + +def test_a_preference_that_names_nothing_falls_back(cases): + """A stale or hand-edited preference must not strand anyone either.""" + assert cases["preference names nothing real"]["active"] == 0 + + +def test_a_preference_the_group_offers_is_kept(cases): + """The fallback must not become 'always the first app'.""" + case = cases["preferred app present"] + assert case["active"] == 2, ( + "Videos was enabled and preferred; the reader should have landed on it, " + f"not on tab {case['active']}") -- cgit v1.2.3