d10bb2ab6f
`scripts/run_tests.sh tests/<dir>/` is how a change gets its regression
coverage run, so a test filed under the wrong directory is a test nobody
runs when that code changes. Two kinds of drift had accumulated.
Parallel directories for one source package, folded into the mirror:
tests/acp -> tests/acp_adapter (its __init__/conftest move with it)
tests/cli -> tests/hermes_cli (prompt_toolkit fixture merged into
hermes_cli/conftest.py)
tests/run_agent -> tests/agent (backoff fixture becomes
agent/conftest.py)
tests/relay -> tests/gateway/relay
tests/state -> tests/hermes_state
246 loose files at tests/ root, routed by the package they import/patch:
hermes_cli, hermes_state, agent, gateway, tools, plugins, tui_gateway, cron.
Installer and desktop-update script tests go to tests/scripts/{install,
desktop_update}/. 43 tests of root-level modules (batch_runner, utils,
hermes_constants, packaging) stay at the root.
Filenames drop their issue numbers (95 files: test_89315_x.py -> test_x.py);
the number stays in the module docstring where it has context.
Collisions: test_cli_skin_integration.py existed in both tests/ and tests/cli
with different subsets — merged into one (10 tests, all kept);
run_agent/test_pre_compress_memory_context.py -> agent/..._handoff.py;
tests/test_account_usage.py -> agent/test_account_usage_fetch.py;
tests/test_web_server.py -> hermes_cli/test_web_server_ws_ping.py.
Deleted: test_minisweagent_path.py (empty since PR #2804),
test_model_picker_scroll.py (tested a private copy of the logic, imported
nothing), test_process_loop_event_loop_warning.py (asserted asyncio behaviour,
imported nothing from Hermes).
Repo-root path arithmetic (Path(__file__).parents[N], dirname chains) is
bumped for the 202 files that changed depth and verified by evaluating every
such expression against the new location. classify_changes' desktop-updater
lane prefix, tests-os.yml's ignore glob and every in-tree path comment follow
the moves. tests/test_tests_tree_layout.py keeps the tree from drifting back.
85 lines
3.5 KiB
Python
85 lines
3.5 KiB
Python
"""Modified kitty keypad keys must behave like their non-keypad twins (#97290)."""
|
|
|
|
import asyncio
|
|
|
|
import pytest
|
|
from prompt_toolkit.input.ansi_escape_sequences import ANSI_SEQUENCES
|
|
from prompt_toolkit.input.vt100_parser import Vt100Parser
|
|
|
|
from hermes_cli import pt_input_extras
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _aliases_installed():
|
|
pt_input_extras.install_shift_enter_alias()
|
|
pt_input_extras.install_ctrl_enter_alias()
|
|
pt_input_extras.install_modify_other_keys_aliases()
|
|
pt_input_extras.install_keypress_data_normalization()
|
|
|
|
|
|
def _parse(sequence):
|
|
presses = []
|
|
parser = Vt100Parser(presses.append)
|
|
for char in sequence:
|
|
parser.feed(char)
|
|
parser.flush()
|
|
return [press.key for press in presses]
|
|
|
|
|
|
def test_modified_keypad_mirrors_its_non_keypad_twin():
|
|
"""Every supported modifier inherits its twin, including lock bits, only in CSI-u."""
|
|
twins = {
|
|
57414: "\x1b[13;{mod}u",
|
|
**{code: "\x1b[1;{mod}" + suffix for code, suffix in
|
|
zip((57417, 57418, 57419, 57420, 57423, 57424), "DCABHF")},
|
|
**{code: f"\x1b[{number};{{mod}}~" for code, number in
|
|
((57421, 5), (57422, 6), (57425, 2), (57426, 3))},
|
|
**{57399 + digit: f"\x1b[{ord(str(digit))};{{mod}}u" for digit in range(10)},
|
|
}
|
|
for code, template in twins.items():
|
|
for base_mod in range(2, 9):
|
|
for offset in (0, 64, 128, 192):
|
|
modifier = base_mod + offset
|
|
sequence = f"\x1b[{code};{modifier}u"
|
|
twin = template.format(mod=modifier)
|
|
if twin in ANSI_SEQUENCES:
|
|
assert _parse(sequence) == _parse(twin), (code, modifier)
|
|
else:
|
|
assert sequence not in ANSI_SEQUENCES
|
|
assert f"\x1b[27;{modifier};{code}~" not in ANSI_SEQUENCES
|
|
|
|
# First-writer-wins applies to the twin too, even when this builder stages a default.
|
|
from prompt_toolkit.keys import Keys
|
|
installed = dict(ANSI_SEQUENCES)
|
|
installed["\x1b[13;3u"] = Keys.ControlA
|
|
aliases = pt_input_extras._modify_other_keys_aliases(installed, Keys)
|
|
assert aliases["\x1b[57414;3u"] == installed["\x1b[13;3u"]
|
|
|
|
|
|
@pytest.mark.parametrize("prefix", ["alpha", "alpha ", "alpha!?.,", "[Pasted text #1: 15 lines]"])
|
|
def test_keypad_alt_enter_inserts_newlines_at_the_cursor(prefix):
|
|
"""Extended Enter must reach the newline handler, never self-insert raw CSI text."""
|
|
from prompt_toolkit import Application
|
|
from prompt_toolkit.buffer import Buffer
|
|
from prompt_toolkit.document import Document
|
|
from prompt_toolkit.input import create_pipe_input
|
|
from prompt_toolkit.key_binding import KeyBindings
|
|
from prompt_toolkit.layout import BufferControl, Layout, Window
|
|
from prompt_toolkit.output import DummyOutput
|
|
|
|
from hermes_cli.cli_tui_mixin import CLITuiMixin
|
|
|
|
async def probe(sequence):
|
|
buf = Buffer(document=Document(prefix + "suffix", len(prefix)))
|
|
kb = KeyBindings()
|
|
kb.add("escape", "enter")(CLITuiMixin()._tui_insert_newline)
|
|
kb.add("c-q")(lambda event: event.app.exit(result=buf.text))
|
|
with create_pipe_input() as inp:
|
|
app = Application(layout=Layout(Window(BufferControl(buf))), key_bindings=kb,
|
|
input=inp, output=DummyOutput())
|
|
return await asyncio.wait_for(app.run_async(
|
|
pre_run=lambda: inp.send_text(sequence * 2 + "\x11")), timeout=5)
|
|
|
|
for sequence in ("\x1b[57414;3u", "\x1b[57414;131u", "\x1b[13;3u", "\x1b\r"):
|
|
assert asyncio.run(probe(sequence)) == prefix + "\n\nsuffix"
|