fix(commands): keep slash-prefixed paths in normal chat
This commit is contained in:
1 parent
3fb9417daf
commit
7e00d6a944
7 files changed
+159
-76
No files matched your search
@@ -72,12 +72,13 @@ class TestIsDispatchableCommand:
|
||||
assert router.is_dispatchable_command(" /new ")
|
||||
assert router.is_dispatchable_command(" /pairing list ")
|
||||
|
||||
def test_invalid_slash_commands_match_for_explicit_rejection(
|
||||
def test_only_registered_commands_match_for_argument_validation(
|
||||
self, router: CommandRouter,
|
||||
) -> None:
|
||||
assert router.is_dispatchable_command("/unknown")
|
||||
assert router.is_dispatchable_command("/foo bar")
|
||||
assert not router.is_dispatchable_command("/unknown")
|
||||
assert not router.is_dispatchable_command("/foo bar")
|
||||
assert router.is_dispatchable_command("/status now")
|
||||
assert router.is_dispatchable_command("/STOP extra")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -178,32 +179,24 @@ class TestMidTurnCommandDispatchedDirectly:
|
||||
assert captured_args == ["hello world"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("content", [
|
||||
"hello world", "/", "/tmp", "/tmp 看看这个目录", "/home/user/project",
|
||||
"/Users/alice/report.md", "/new/file.txt", "/model/preset", "/neaw",
|
||||
"/totally-unknown-command", "/tmp/file@new", "请看看 /home/user/project",
|
||||
])
|
||||
async def test_non_command_returns_none(
|
||||
self, router: CommandRouter, fake_loop: MagicMock, fake_msg: MagicMock,
|
||||
content: str,
|
||||
) -> None:
|
||||
"""Regular text returns None from dispatch (not a command)."""
|
||||
ctx = CommandContext(
|
||||
msg=fake_msg, session=None,
|
||||
key="test:chat1", raw="hello world", loop=fake_loop,
|
||||
key="test:chat1", raw=content, loop=fake_loop,
|
||||
)
|
||||
result = await router.dispatch(ctx)
|
||||
assert result is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unknown_command_suggests_close_match(
|
||||
self, router: CommandRouter, fake_loop: MagicMock, fake_msg: MagicMock,
|
||||
) -> None:
|
||||
fake_msg.content = "/neaw"
|
||||
ctx = CommandContext(
|
||||
msg=fake_msg, session=None,
|
||||
key="test:chat1", raw="/neaw", loop=fake_loop,
|
||||
)
|
||||
|
||||
result = await router.dispatch(ctx)
|
||||
|
||||
assert result is not None
|
||||
assert result.content == 'Unknown command "/neaw". Did you mean "/new"?'
|
||||
assert result.metadata["render_as"] == "text"
|
||||
assert not router.is_dispatchable_command(content)
|
||||
assert not router.is_priority(content)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_exact_command_with_arguments_suggests_valid_form(
|
||||
@@ -222,25 +215,6 @@ class TestMidTurnCommandDispatchedDirectly:
|
||||
'Command "/status" does not accept arguments. Did you mean "/status"?'
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unknown_command_without_close_match_points_to_help(
|
||||
self, router: CommandRouter, fake_loop: MagicMock, fake_msg: MagicMock,
|
||||
) -> None:
|
||||
fake_msg.content = "/totally-unknown-command"
|
||||
ctx = CommandContext(
|
||||
msg=fake_msg, session=None,
|
||||
key="test:chat1", raw="/totally-unknown-command", loop=fake_loop,
|
||||
)
|
||||
|
||||
result = await router.dispatch(ctx)
|
||||
|
||||
assert result is not None
|
||||
assert result.content == (
|
||||
'Unknown command "/totally-unknown-command". '
|
||||
'Use "/help" to list available commands.'
|
||||
)
|
||||
|
||||
|
||||
class TestPairingCommandDispatch:
|
||||
"""Verify /pairing works via CommandRouter."""
|
||||
|
||||
|
||||
Reference in new issue
Block a user