From e99e6cf2382498d48061a6cda78602910c522767 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Tue, 28 Jul 2026 19:34:11 -0400 Subject: [PATCH] Contacts: opens on who's out there now, not a roll call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The list's question is who is on the mesh right now, and a freshest-first order answers it on sight — an A→Z roll call makes you read every row. Open the Contacts screen (and the CLI's default) on heard, ascending age; the Ctrl+arrows still steer from there. Co-Authored-By: Claude Opus 5 (1M context) --- meshterm/tools/contacts.py | 7 +++++-- tests/test_device_config.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/meshterm/tools/contacts.py b/meshterm/tools/contacts.py index 591f290..563aaaf 100644 --- a/meshterm/tools/contacts.py +++ b/meshterm/tools/contacts.py @@ -56,7 +56,10 @@ class ContactsTool(Tool): self_name = str(info.get("name") or "this node") self_key = str(info.get("public_key") or "") - sort_name = str(params.get("sort") or "name") + # Opens most-recently-heard first: the list's job is "who's out there right now", + # and a freshest-first order answers that on sight — an A→Z roll call doesn't. The + # Ctrl+arrows re-sort from there (and ``--sort`` picks the CLI's order). + sort_name = str(params.get("sort") or "heard") # In the menu, hand the list to the interactive screen so the Ctrl+arrows re-sort it # live — its ring spans the shared contact list's four columns (hash included); on the @@ -84,7 +87,7 @@ class ContactsTool(Tool): @app.command(name=self.name, help=self.help) def _contacts( sort: str = typer.Option( - "name", "--sort", "-s", help="Order contacts by: name, heard, packets" + "heard", "--sort", "-s", help="Order contacts by: heard, name, packets" ), ) -> None: run_tool_command(self, {"sort": sort}) diff --git a/tests/test_device_config.py b/tests/test_device_config.py index 70b0edb..9710d14 100644 --- a/tests/test_device_config.py +++ b/tests/test_device_config.py @@ -205,6 +205,38 @@ def test_contacts_table_breaks_metric_ties_by_name_ascending() -> None: assert order(ascending=False) == ["Bob", "Alice", "Charlie"] +async def test_contacts_tool_opens_sorted_by_heard(monkeypatch: pytest.MonkeyPatch) -> None: + """The Contacts list opens most-recently-heard first — who's out there now, not a roll call.""" + from meshterm.tools.contacts import ContactsTool + from meshterm.ui import widgets + + captured: dict = {} + + def fake_table(self_name, self_key, contacts, prefix_bytes, counts, sort): + captured["sort"] = sort + return "" + + monkeypatch.setattr(widgets, "contacts_table", fake_table) + + class _Devstate: + async def self_info(self) -> dict: + return {"name": "Us", "public_key": "aa" * 32} + + async def contacts(self) -> list: + return [] + + async def path_hash_mode(self) -> int: + return 0 + + class _Ctx: + devstate = _Devstate() + repo = type("R", (), {"heard_nodes": staticmethod(lambda: [])})() + ui = type("U", (), {"show": staticmethod(lambda *r: None)})() + + await ContactsTool().run(_Ctx(), {}) # type: ignore[arg-type] + assert (captured["sort"].column, captured["sort"].ascending) == ("heard", True) + + def _contacts_sort(name: str = "name"): """The interactive Contacts screen's sort: the shared contact list's four-column ring.""" from meshterm.ui.contactlist import SORT_COLUMNS, SORT_OPENS_ASCENDING