fix: 3-level hierarchy in help paste output
Some checks failed
CI / gitleaks (push) Failing after 4s
CI / lint (push) Failing after 23s
CI / test (3.11) (push) Has been skipped
CI / test (3.12) (push) Has been skipped
CI / test (3.13) (push) Has been skipped
CI / build (push) Has been skipped

Plugin name at column 0, command at indent 4, docstring at indent 8.
Single-command paste keeps command at 0, docstring at 4.
Only paste when actual docstring content exists.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
user
2026-02-23 23:21:10 +01:00
parent ecfa7cea39
commit 20c1d738be
2 changed files with 67 additions and 36 deletions

View File

@@ -237,8 +237,8 @@ class TestHelpCommand:
assert "!widget -- Manage widgets" in bot.replied[0]
assert "https://" not in bot.replied[0]
def test_help_paste_body_indented(self):
"""Paste body has command name flush-left, docstring indented."""
def test_help_cmd_paste_hierarchy(self):
"""Single-command paste: header at 0, docstring at 4."""
bot = _FakeBot()
pastes: list[str] = []
bot.registry._modules["flaskpaste"] = _make_fp_module(capture=pastes)
@@ -250,9 +250,39 @@ class TestHelpCommand:
asyncio.run(_mod.cmd_help(bot, msg))
assert len(pastes) == 1
lines = pastes[0].split("\n")
# First line: command header, no indent
# Level 0: command header flush-left
assert lines[0] == "!widget -- Manage widgets"
# Docstring lines are indented 4 spaces
# Level 1: docstring lines indented 4 spaces
for line in lines[1:]:
if line.strip():
assert line.startswith(" "), f"not indented: {line!r}"
def test_help_list_paste_hierarchy(self):
"""Full reference paste: plugin at 0, command at 4, doc at 8."""
bot = _FakeBot()
pastes: list[str] = []
bot.registry._modules["flaskpaste"] = _make_fp_module(capture=pastes)
mod = types.ModuleType("core")
mod.__doc__ = "Core plugin."
bot.registry._modules["core"] = mod
bot.registry.commands["state"] = _FakeHandler(
name="state", callback=_cmd_with_doc,
help="Inspect state", plugin="core",
)
msg = _Msg(text="!help")
asyncio.run(_mod.cmd_help(bot, msg))
assert len(pastes) == 1
text = pastes[0]
lines = text.split("\n")
# Level 0: plugin header
assert lines[0] == "[core]"
# Level 1: plugin description
assert lines[1] == " Core plugin."
# Blank separator
assert lines[2] == ""
# Level 1: command header at indent 4
assert lines[3] == " !state -- Inspect state"
# Level 2: docstring at indent 8
for line in lines[4:]:
if line.strip():
assert line.startswith(" "), f"not at indent 8: {line!r}"