feat(hands): vibegram read takes since and last for a non-consuming look at history
This commit is contained in:
1 parent
78a0293819
commit
9bf897a809
2 files changed
+124
-10
No files matched your search
+73
-1
@@ -6,7 +6,7 @@ from beaver_gateway.mcp.wrap import build_python_tool_server
|
||||
from fastmcp import Client
|
||||
from fastmcp.exceptions import ToolError
|
||||
|
||||
from beaver_agent.hands.vibegram import PAGE, Vibegram, _cards, _event, _work
|
||||
from beaver_agent.hands.vibegram import PAGE, PAGES, Vibegram, _cards, _event, _work
|
||||
|
||||
|
||||
def test_events_render_and_unknown_kinds_are_skipped():
|
||||
@@ -127,3 +127,75 @@ async def test_window_of_an_empty_room_is_full_and_empty(monkeypatch):
|
||||
_, room = _hub(monkeypatch, [])
|
||||
window = await room.window(25)
|
||||
assert window.full and window.events == []
|
||||
|
||||
|
||||
async def test_read_since_walks_history_without_touching_the_cursor(monkeypatch):
|
||||
events = [
|
||||
_raw(i, "message" if i % 4 else "agent_join", f"строка {i}")
|
||||
for i in range(1, 12)
|
||||
]
|
||||
calls, room = _hub(monkeypatch, events)
|
||||
|
||||
out = await room.vibegram("read", since=8)
|
||||
|
||||
assert out.splitlines() == [
|
||||
"#9 [09-23 05:00] claude-kai: строка 9",
|
||||
"#10 [09-23 05:00] claude-kai: строка 10",
|
||||
"#11 [09-23 05:00] claude-kai: строка 11",
|
||||
]
|
||||
assert not any("pending" in p for p in calls)
|
||||
|
||||
|
||||
async def test_read_last_shows_only_the_tail(monkeypatch):
|
||||
events = [_raw(i, "message", f"строка {i}") for i in range(1, 12)]
|
||||
_, room = _hub(monkeypatch, events)
|
||||
|
||||
out = await room.vibegram("read", last=2)
|
||||
|
||||
assert out.splitlines() == [
|
||||
"#10 [09-23 05:00] claude-kai: строка 10",
|
||||
"#11 [09-23 05:00] claude-kai: строка 11",
|
||||
]
|
||||
with pytest.raises(ValueError, match="last"):
|
||||
await room.vibegram("read", last=0)
|
||||
|
||||
|
||||
async def test_read_since_on_a_silent_room_says_history_is_read_out(monkeypatch):
|
||||
_, room = _hub(monkeypatch, [_raw(3, "message", "строка 3")])
|
||||
|
||||
assert await room.vibegram("read", since=3) == (
|
||||
"после #3 сообщений нет (история дочитана)"
|
||||
)
|
||||
|
||||
|
||||
async def test_read_since_admits_an_unfinished_window(monkeypatch):
|
||||
events = [_raw(i, "message", f"строка {i}") for i in range(1, PAGES * PAGE + 2)]
|
||||
_, room = _hub(monkeypatch, events)
|
||||
|
||||
out = await room.vibegram("read", since=0)
|
||||
|
||||
assert out.splitlines()[0] == "окно неполное: до конца истории не дочитали"
|
||||
|
||||
|
||||
async def test_plain_read_keeps_the_cursor_and_numbers_the_lines(monkeypatch):
|
||||
seen = []
|
||||
|
||||
async def call(self, method, path, body):
|
||||
seen.append(path)
|
||||
return {"events": [_raw(7, "message", "привет")]}
|
||||
|
||||
monkeypatch.setattr(Vibegram, "_call", call)
|
||||
room = Vibegram(hub="http://hub", token="t", nick="beaver-test")
|
||||
|
||||
assert await room.vibegram("read") == "#7 [09-23 05:00] claude-kai: привет"
|
||||
assert seen == ["/api/pending?limit=50"]
|
||||
|
||||
|
||||
async def test_tool_schema_exposes_since_and_last():
|
||||
tool = Vibegram(hub="http://127.0.0.1:9", token="t", nick="beaver-test")
|
||||
server = build_python_tool_server(
|
||||
McpServer.python_tool(name="vibegram", tools=[tool.vibegram])
|
||||
)
|
||||
async with Client(server) as client:
|
||||
(spec,) = await client.list_tools()
|
||||
assert {"since", "last"} <= set(spec.inputSchema["properties"])
|
||||
Reference in new issue
Block a user