mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-08 23:33:16 +08:00
Cache inventory MCP lists and accept YES as WhatsApp confirm.
Extend short TTL reuse to listManagedNe/queryUmeNeInventory to cut list self-loops, and treat short YES/continue as confirmation when a token is pending. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
f1d025ed60
commit
d3f621b58b
6 changed files with 130 additions and 42 deletions
13
tests/test_confirm_affirmative.py
Normal file
13
tests/test_confirm_affirmative.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from runtime.orchestration.security import has_explicit_confirmation_token
|
||||
|
||||
|
||||
def test_whatsapp_yes_confirms_outstanding_token() -> None:
|
||||
assert has_explicit_confirmation_token("@bot YES", "abc123")
|
||||
assert has_explicit_confirmation_token("YES", "abc123")
|
||||
assert has_explicit_confirmation_token("please continue", "abc123")
|
||||
assert has_explicit_confirmation_token("确认", "abc123")
|
||||
assert not has_explicit_confirmation_token("YES", None)
|
||||
assert not has_explicit_confirmation_token("maybe later", "abc123")
|
||||
assert has_explicit_confirmation_token("confirm abc123", "abc123")
|
||||
|
|
@ -70,22 +70,41 @@ class McpTimeoutAndCacheTests(unittest.TestCase):
|
|||
"tool_name": "listCliTargets",
|
||||
"description": "list",
|
||||
"parameters": {"type": "object", "properties": {}},
|
||||
}
|
||||
},
|
||||
{
|
||||
"tool_name": "queryUmeNeInventory",
|
||||
"description": "inventory",
|
||||
"parameters": {"type": "object", "properties": {}},
|
||||
},
|
||||
{
|
||||
"tool_name": "listManagedNe",
|
||||
"description": "managed",
|
||||
"parameters": {"type": "object", "properties": {}},
|
||||
},
|
||||
],
|
||||
)
|
||||
spec = next(s for s in materialize_mcp_tools(store) if s.name.endswith("listCliTargets"))
|
||||
specs = {s.name: s for s in materialize_mcp_tools(store)}
|
||||
calls = {"n": 0}
|
||||
|
||||
def fake_call_tool(self, tool_name, arguments=None): # type: ignore[no-untyped-def]
|
||||
calls["n"] += 1
|
||||
return {"ok": True, "data": {"items": [{"ne_id": "1"}]}}
|
||||
return {"ok": True, "data": {"items": [{"ne_id": "1"}], "tool": tool_name}}
|
||||
|
||||
with patch("runtime.tools.mcp.adapter.McpProcessRuntime.call_tool", fake_call_tool):
|
||||
first = spec.handler({"keyword": "PE", "source": "ume"})
|
||||
second = spec.handler({"keyword": "PE", "source": "ume"})
|
||||
self.assertEqual(calls["n"], 1)
|
||||
cli = specs["mcp__netx__listCliTargets"]
|
||||
inv = specs["mcp__netx__queryUmeNeInventory"]
|
||||
managed = specs["mcp__netx__listManagedNe"]
|
||||
first = cli.handler({"keyword": "PE", "source": "ume"})
|
||||
second = cli.handler({"keyword": "PE", "source": "ume"})
|
||||
inv1 = inv.handler({"keyword": "core"})
|
||||
inv2 = inv.handler({"keyword": "core"})
|
||||
m1 = managed.handler({"keyword": "x", "vendor": "huawei", "connect_status": "online"})
|
||||
m2 = managed.handler({"keyword": "x", "vendor": "huawei", "connect_status": "online"})
|
||||
self.assertEqual(calls["n"], 3)
|
||||
self.assertFalse(first.get("cache_hit"))
|
||||
self.assertTrue(second.get("cache_hit"))
|
||||
self.assertTrue(inv2.get("cache_hit"))
|
||||
self.assertTrue(m2.get("cache_hit"))
|
||||
self.assertEqual(second.get("data", {}).get("items", [])[0]["ne_id"], "1")
|
||||
clear_list_cli_targets_cache()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue