feat(watch,server): t3_watch to turn thread events off and back on

This commit is contained in:
hh
2026-09-01 13:37:04 +00:00
parent a98211b79f
commit a29c526ee9
5 changed files with 159 additions and 11 deletions
+61
View File
@@ -589,3 +589,64 @@ async def test_dispatch_tracks_thread(client: Client, registry: Registry) -> Non
"t3-smoke",
"track me",
)
def test_tracker_watch_flag(tmp_path) -> None:
from t3code_mcp.watch import Tracker
tracker = Tracker(tmp_path / "state.json")
tracker.track("t1", "dell", "projects", "quiet", watch=False)
tracker.apply("dell", shell_thread("t1", "running"))
assert tracker.apply("dell", shell_thread("t1", "completed")) == []
assert tracker.threads["t1"].state == "completed"
tracker.set_watch("t1", enabled=True)
tracker.apply("dell", shell_thread("t1", "running"))
assert [e.kind for e in tracker.apply("dell", shell_thread("t1", "completed"))] == [
"completed"
]
assert Tracker(tmp_path / "state.json").threads["t1"].watch is True
async def test_watch_tool_lists_and_toggles(client: Client) -> None:
async with client:
loud = data(
await client.call_tool(
"t3_dispatch",
{"machine": "mac", "project": "t3-smoke", "prompt": "tell me"},
)
)
quiet = data(
await client.call_tool(
"t3_dispatch",
{
"machine": "mac",
"project": "t3-smoke",
"prompt": "leave me alone",
"watch": False,
},
)
)
assert (loud["watch"], quiet["watch"]) == (True, False)
view = data(await client.call_tool("t3_watch"))
assert [t["thread_id"] for t in view["watched"]] == [loud["thread_id"]]
assert [t["thread_id"] for t in view["unwatched"]] == [quiet["thread_id"]]
view = data(
await client.call_tool(
"t3_watch", {"thread_id": loud["thread_id"], "enabled": False}
)
)
assert view["watched"] == []
assert {t["thread_id"] for t in view["unwatched"]} == {
loud["thread_id"],
quiet["thread_id"],
}
view = data(
await client.call_tool(
"t3_watch", {"thread_id": quiet["thread_id"], "enabled": True}
)
)
assert [t["thread_id"] for t in view["watched"]] == [quiet["thread_id"]]
with pytest.raises(ToolError, match="nothing to unwatch"):
await client.call_tool("t3_watch", {"thread_id": "nope", "enabled": False})
with pytest.raises(ToolError, match="enabled=true or enabled=false"):
await client.call_tool("t3_watch", {"thread_id": loud["thread_id"]})