From 8d2a7b8281f08f97d07cd7eede4a3cc2ec86cdb7 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Tue, 8 Sep 2026 04:07:27 -0400 Subject: [PATCH] --absolute asks for another form of time, not for one fewer fact A never-heard node has no instant to print, so the timestamp language dropped "never" back to the plain absent token and a contacts listing under --absolute could no longer tell "we have not heard from it" from "this row has no heard time". The absent word survives the switch; only the form of a real time changes. Also drops a dead guard in the preferences writer. Co-Authored-By: Claude Opus 5 (1M context) --- meshterm/tools/preferences.py | 2 +- meshterm/ui/fields.py | 15 +++++++++++---- tests/test_cli_contract.py | 4 +++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/meshterm/tools/preferences.py b/meshterm/tools/preferences.py index 1dfccf3..4afc5e5 100644 --- a/meshterm/tools/preferences.py +++ b/meshterm/tools/preferences.py @@ -125,7 +125,7 @@ class PreferencesTool(Tool): if changes: prefs.save() - if scripted and applied is not None and any(op[0] in ("set", "reset") for op in ops): + if scripted and any(op[0] in ("set", "reset") for op in ops): blocks.append(_written(applied, prefs)) plural = "" if changes == 1 else "s" diff --git a/meshterm/ui/fields.py b/meshterm/ui/fields.py index 1f89ae2..c1b0835 100644 --- a/meshterm/ui/fields.py +++ b/meshterm/ui/fields.py @@ -451,10 +451,17 @@ def _flag_cell(value: bool | None) -> str: def _time(value: Any, *, absent: str) -> str: - """Render a time in whichever language this run speaks (see :func:`when`).""" - if isinstance(value, datetime) or value is None: - return script.stamp(value) if _absolute() else script.age(value, absent=absent) - return normalise(value) # pragma: no cover - a row holding something else is a bug + """Render a time in whichever language this run speaks (see :func:`when`). + + ``absent`` survives the switch to timestamps, because it is not a rendering choice: + ``never`` says the event has not happened, and ``--absolute`` was asked for a different + *form* of time, not for one fewer fact. + """ + if not isinstance(value, datetime) and value is not None: + return normalise(value) # pragma: no cover - a row holding something else is a bug + if value is None: + return absent + return script.stamp(value) if _absolute() else script.age(value, absent=absent) def _absolute() -> bool: diff --git a/tests/test_cli_contract.py b/tests/test_cli_contract.py index fbc6166..199bd2d 100644 --- a/tests/test_cli_contract.py +++ b/tests/test_cli_contract.py @@ -269,10 +269,12 @@ def test_contacts_names_every_node_bare_and_ages_every_time(run) -> None: # noq age = line.split()[2] assert age in ("now", "never") or age[-1] in "mhdw" + # `--absolute` asks for a different *form* of time, not for one fewer fact, so + # `never` survives it: a node that has never been heard has no instant to print. absolute = result_lines(run("--absolute", "contacts"))[1:] for line in absolute: stamp = line.split()[2] - assert stamp == "-" or stamp[:4].isdigit() + assert stamp in ("-", "never") or stamp[:4].isdigit() def test_contacts_never_elides_a_key(run) -> None: # noqa: ANN001