Five ways the scripted output lied, and the name that crashed it

The review pass found the CLI breaking its own written rules.

A node broadcasts its own name, so every name the CLI prints is remote
data — and Rich read `[...]` in it as a style tag. A node called
`[bold]Loud` printed as `Loud`, silently no longer the string that
identifies it; a node called `[/]Bob` raised MarkupError and took the
command down. The log handler then failed the same way while reporting
it, replacing the diagnostic with a traceback about the diagnostic. No
log line and no scripted line is ever marked up, so all three consoles
now say so.

`right=` never right-aligned anything. Rich's `Text.wrap` returns early
on `overflow="ignore"`, above the justify step, so asking for one threw
the other away — every numeric lane in the CLI was left-aligned while
CLAUDE.md, script.py's own docstring and the manual all said otherwise.
"crop" refuses to elide just as firmly and still aligns.

`config show` printed an empty string as `""` and `config set` read
those two characters literally, so feeding a dump back in replaced every
empty setting with a pair of quote marks — and the next dump looked
identical, so nothing ever said so. It also masked an *unreported* PIN
behind six bullets, telling the reader the radio was PIN-locked when it
was not: `conceal` already declined to mask the menu's absence token and
had simply never been shown the CLI's.

`meshterm about` drew the `---` above its colophon as a rule sized to
the console, which on a 16384-cell console is one 48KB line in a 4KB
page. A rule is a frame; the scripted copy drops it with the QR.

The contract fixture set only `--db`, which moves the history and
nothing else — so the suite read whatever was in the developer's own
~/.meshterm. That is how `[/]Bob`, planted by hand on one machine, could
crash the suite there and pass everywhere else. $MESHTERM_HOME moves the
whole directory.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-09-08 02:17:41 -04:00
1 parent 4a91845651
commit 369e29e44a
9 files changed
+194 -22

No files matched your search

+76 -2
View File
@@ -41,10 +41,20 @@ _LISTINGS: list[tuple[str, list[str], list[str]]] = [
@pytest.fixture()
def run(tmp_path: Path): # noqa: ANN201 - a closure over the runner
"""Invoke the real CLI against the simulator and a scratch database."""
def run(tmp_path: Path, monkeypatch: pytest.MonkeyPatch): # noqa: ANN201 - a closure
"""Invoke the real CLI against the simulator, in a config directory of its own.
``--db`` moves the history and *nothing else*: the contact cache, the outbox, the
channel cache, the stored admin passwords and any device profiles all live in the
config directory regardless. So a suite that set only ``--db`` read whatever was in
the developer's own ``~/.meshterm`` — which is how a contact named ``[/]Bob``, planted
by hand on one machine, could crash this suite on that machine and pass everywhere
else. ``$MESHTERM_HOME`` is the override that moves the whole directory, and it is
the one a test wants.
"""
from meshterm.cli import app
monkeypatch.setenv("MESHTERM_HOME", str(tmp_path / "home"))
runner = CliRunner()
def invoke(*args: str): # noqa: ANN202
@@ -120,6 +130,70 @@ def test_a_config_line_can_be_typed_back_into_config_set(run) -> None: # noqa:
assert run("config", "get", "name").output.strip() == "MockCompanion"
def test_every_setting_show_prints_is_one_set_takes_back(run) -> None: # noqa: ANN001
"""The round-trip claim, checked on every setting rather than on the two easy ones.
``config show > f`` and feeding ``f`` back in is the obvious thing to do with a dump,
and the failure mode is silent: an empty string printed as ``""`` used to parse back
as *the two quote characters*, and the next dump looked identical, so nothing ever
said the setting had been replaced. A refusal is fine here — you cannot set a value
the firmware never reported — but a value that parses to something else is not.
"""
from meshterm.core import device_config as dc
from meshterm.tools.config import _script_value
probes = {
"str": ["", "Yagi-Repeater", "a name with spaces"],
"bool": [True, False],
"int": [0, 1, 12],
"float": [0.0, 3.5],
}
checked = 0
for _category, specs in dc.settings_by_category():
for spec in specs:
if spec.value_type == "enum" and spec.choices:
values: list = list(spec.choices)
else:
values = probes.get(spec.value_type, [])
for value in values:
printed = _script_value(spec, value)
try:
parsed = dc.parse_value(spec, printed, {})
except dc.DeviceConfigError:
continue # a loud refusal is honest; a wrong value is not
checked += 1
assert parsed == value, f"{spec.key}: show printed {printed!r} -> {parsed!r}"
assert checked > 40, f"only {checked} round-trips exercised"
def test_an_unreported_pin_is_not_masked_as_though_one_were_set(run) -> None: # noqa: ANN001
"""Bullets say "there is a secret here". An absence must not borrow that claim.
``conceal`` already declines to mask the *menu's* absence token for exactly this
reason, but the scripted token is ``-``, which it had never been shown — so a radio
that had never reported a PIN dumped six bullets, and the reader (or the bug report
they pasted it into) read that as PIN-locked.
"""
from meshterm.ui import script
from meshterm.ui.config_editor import MASK_MARK, conceal
# The rule at the boundary where it broke: a real value is masked, an absence is not,
# and each surface says which glyph it writes an absence with.
assert conceal("1234", absent=script.NONE) == MASK_MARK * 6
assert conceal(script.NONE, absent=script.NONE) == script.NONE
assert conceal("?") == "?"
# And the two surfaces must never disagree about the same radio: `show` wears bullets
# only where `get` has something to conceal.
values = dict(
line.split(None, 1) for line in result_lines(run("config", "show")) if " " in line
)
got = run("config", "get", "device_pin").output.strip()
assert (MASK_MARK in values["device_pin"]) == (got != script.NONE), (
f"show says {values['device_pin']!r} while get says {got!r}"
)
def test_config_get_prints_the_bare_value(run) -> None: # noqa: ANN001
"""The caller named the key; repeating it back is one more thing to strip off."""
assert run("config", "get", "tx_power").output.strip() == "20"