From fbaad3031abe74a14dc02569eb73d003f23120bb Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Wed, 17 Jun 2026 12:33:56 +0530 Subject: [PATCH] test(cli): URL tokens must not trigger filesystem path completion Regression coverage for the keystroke-latency fix: a URL token contains "/", so the bare-slash path heuristic used to return it as a path word and run os.listdir on every keystroke. Assert _extract_path_word rejects http/https/ssh scheme tokens, that ordinary paths (incl. a bare colon) are unaffected, and that the completer never touches the filesystem for a URL under the cursor. --- tests/hermes_cli/test_path_completion.py | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/hermes_cli/test_path_completion.py b/tests/hermes_cli/test_path_completion.py index b41a36e2ec6..549d8d6a2c1 100644 --- a/tests/hermes_cli/test_path_completion.py +++ b/tests/hermes_cli/test_path_completion.py @@ -59,6 +59,32 @@ class TestExtractPathWord: def test_just_tilde_slash(self): assert SlashCommandCompleter._extract_path_word("~/") == "~/" + def test_url_is_not_treated_as_path(self): + # A URL contains "/" so the bare slash heuristic would otherwise return + # it as a path word, firing os.listdir("https:") on every keystroke. + assert SlashCommandCompleter._extract_path_word("see https://paste.rs/abc") is None + + def test_http_url_is_not_treated_as_path(self): + assert SlashCommandCompleter._extract_path_word("ref http://example.com/x") is None + + def test_scheme_alone_is_enough_to_reject(self): + # The "://" scheme separator is the signal, even before any path part + # has been typed. + assert SlashCommandCompleter._extract_path_word("ssh://host") is None + + def test_path_word_with_colon_but_no_scheme_still_resolves(self): + # Only the "://" scheme separator should reject; a bare colon inside a + # real path token must not regress path detection. + assert ( + SlashCommandCompleter._extract_path_word("open ./a:b/c.py") == "./a:b/c.py" + ) + + def test_ordinary_path_unaffected_by_url_guard(self): + assert ( + SlashCommandCompleter._extract_path_word("edit src/pkg/mod.py") + == "src/pkg/mod.py" + ) + class TestPathCompletions: def test_lists_current_directory(self, tmp_path): @@ -155,6 +181,23 @@ class TestIntegration: completions = list(completer.get_completions(doc, event)) assert completions == [] + def test_url_does_not_touch_filesystem(self, completer, monkeypatch): + # Regression for laggy typing: a URL token contains "/", so before the + # scheme guard it reached _path_completions and called os.listdir on + # every keystroke. Assert no completions AND that the filesystem is + # never touched while a URL is under the cursor. + import hermes_cli.commands as commands_mod + + def _fail(*_args, **_kwargs): + raise AssertionError("os.listdir must not run for a URL token") + + monkeypatch.setattr(commands_mod.os, "listdir", _fail) + + text = "open https://paste.rs/abc" + doc = Document(text, cursor_position=len(text)) + event = MagicMock() + assert list(completer.get_completions(doc, event)) == [] + def test_absolute_path_triggers_completion(self, completer): doc = Document("check /etc/hos", cursor_position=14) event = MagicMock()