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
@@ -290,7 +290,10 @@ async def test_new_with_bot_suffix_does_not_persist_command(tmp_path: Path) -> N
|
||||
@pytest.mark.parametrize(
|
||||
("content", "expected"),
|
||||
[
|
||||
("/neaw", 'Unknown command "/neaw". Did you mean "/new"?'),
|
||||
(
|
||||
"/stop now",
|
||||
'Command "/stop" does not accept arguments. Did you mean "/stop"?',
|
||||
),
|
||||
(
|
||||
"/status now",
|
||||
'Command "/status" does not accept arguments. Did you mean "/status"?',
|
||||
@@ -327,6 +330,32 @@ async def test_invalid_slash_command_is_rejected_without_calling_provider(
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("channel", "content"), [
|
||||
("websocket", "/tmp 看看这个目录"),
|
||||
("weixin", "/home/user/project"),
|
||||
("cli", "/new/file.txt"),
|
||||
])
|
||||
async def test_absolute_path_reaches_provider_as_chat(tmp_path, channel, content) -> None:
|
||||
loop = _make_full_loop(tmp_path)
|
||||
loop.provider.aclose = AsyncMock()
|
||||
try:
|
||||
response = await loop._process_message(InboundMessage(
|
||||
channel=channel, sender_id="user", chat_id="path", content=content,
|
||||
))
|
||||
|
||||
assert response is not None and response.content == "Test title"
|
||||
request = loop.provider.chat_stream_with_retry.await_args.kwargs
|
||||
assert any(
|
||||
message["role"] == "user" and content in message["content"]
|
||||
for message in request["messages"]
|
||||
)
|
||||
session = loop.sessions.get_or_create(f"{channel}:path")
|
||||
assert session.get_history()[0]["content"] == content
|
||||
assert not session.messages[0].get("_command")
|
||||
finally:
|
||||
await loop.aclose()
|
||||
|
||||
|
||||
def test_clean_generated_title_strips_reasoning_tags() -> None:
|
||||
assert clean_generated_title("<think>reasoning</think> WebUI polish") == "WebUI polish"
|
||||
assert clean_generated_title("Title: <think> The user said hello") == ""
|
||||
|
||||
@@ -98,3 +98,45 @@ async def test_session_message_text_is_not_dispatched_as_a_slash_command(
|
||||
finally:
|
||||
loop.stop()
|
||||
await asyncio.wait_for(task, timeout=2)
|
||||
|
||||
|
||||
async def test_path_followup_reaches_running_turn(tmp_path: Path) -> None:
|
||||
loop = _loop(tmp_path)
|
||||
first_call = asyncio.Event()
|
||||
release = asyncio.Event()
|
||||
calls = []
|
||||
path = "/home/user/project"
|
||||
|
||||
async def respond(**kwargs):
|
||||
calls.append(str(kwargs["messages"]))
|
||||
if len(calls) == 1:
|
||||
first_call.set()
|
||||
await release.wait()
|
||||
return LLMResponse(content="Reviewed")
|
||||
|
||||
loop.provider.chat_stream_with_retry = AsyncMock(side_effect=respond)
|
||||
run = asyncio.create_task(loop.run())
|
||||
try:
|
||||
await loop.bus.publish_inbound(InboundMessage(
|
||||
channel="weixin", sender_id="user", chat_id="path", content="Review the project",
|
||||
))
|
||||
await asyncio.wait_for(first_call.wait(), 3)
|
||||
await loop.bus.publish_inbound(InboundMessage(
|
||||
channel="weixin", sender_id="user", chat_id="path", content=path,
|
||||
))
|
||||
async with asyncio.timeout(3):
|
||||
while loop._pending_queues["weixin:path"].empty():
|
||||
await asyncio.sleep(0)
|
||||
release.set()
|
||||
await asyncio.wait_for(asyncio.gather(*loop._active_tasks["weixin:path"]), 5)
|
||||
|
||||
assert len(calls) == 2
|
||||
assert path in calls[1]
|
||||
session = loop.sessions.get_or_create("weixin:path")
|
||||
visible = [public_history_message(row) for row in session.messages]
|
||||
assert any(row["content"] == path for row in visible)
|
||||
assert not any(row.get("_command") for row in session.messages)
|
||||
finally:
|
||||
release.set()
|
||||
loop.stop()
|
||||
await asyncio.wait_for(run, 5)
|
||||
Reference in new issue
Block a user