knowledge control returns stats and toggles enable/disable.
(tmp_path)
| 624 | |
| 625 | @pytest.mark.asyncio |
| 626 | async def test_control_knowledge(tmp_path): |
| 627 | """knowledge control returns stats and toggles enable/disable.""" |
| 628 | from src.tool_system.registry import ToolRegistry |
| 629 | |
| 630 | with contextlib.ExitStack() as stack: |
| 631 | for p in _patches(_TextProvider, ToolRegistry([])): |
| 632 | stack.enter_context(p) |
| 633 | spawn = make_spawn_agent(AgentServerConfig(permission_mode="default")) |
| 634 | handle = await spawn("ds_test", str(tmp_path), None) |
| 635 | gen = handle.messages_from_agent() |
| 636 | try: |
| 637 | init = await asyncio.wait_for(gen.__anext__(), timeout=5) |
| 638 | assert init["subtype"] == "init" |
| 639 | |
| 640 | async def _reply_for(rid, req): |
| 641 | await handle.send_to_agent({"type": "control_request", "request_id": rid, "request": req}) |
| 642 | for _ in range(12): |
| 643 | msg = await asyncio.wait_for(gen.__anext__(), timeout=5) |
| 644 | if msg.get("type") == "control_response" and msg["response"].get("request_id") == rid: |
| 645 | return msg["response"]["response"] |
| 646 | raise AssertionError(f"no reply for {rid}") |
| 647 | |
| 648 | st = await _reply_for("k1", {"subtype": "knowledge", "action": "status"}) |
| 649 | assert st["ok"] is True and "total" in st["stats"] and st["enabled"] is True |
| 650 | |
| 651 | off = await _reply_for("k2", {"subtype": "knowledge", "action": "disable"}) |
| 652 | assert off["enabled"] is False |
| 653 | |
| 654 | lst = await _reply_for("k3", {"subtype": "knowledge", "action": "list"}) |
| 655 | assert lst["ok"] is True and isinstance(lst["entities"], list) |
| 656 | finally: |
| 657 | await handle.shutdown() |
| 658 | with contextlib.suppress(Exception): |
| 659 | await gen.aclose() |
| 660 | |
| 661 | |
| 662 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected