lc-mcp v0.5: 语义化操控(MCP stdio) — OCR文本化+语义点击, win/linux/mac 截图与输入后端
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""后端/协议测试(本机直接跑,无需 Windows)。"""
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
sys.path.insert(0, HERE)
|
||||||
|
|
||||||
|
from platform import detect_platform, get_input_backend # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
def test_mock_backend():
|
||||||
|
b = get_input_backend('mock')
|
||||||
|
assert b.click(100, 200)['ok']
|
||||||
|
assert b.move(10, 10)['ok']
|
||||||
|
assert b.keypress('p')['ok']
|
||||||
|
assert b.type_text('ok')['ok']
|
||||||
|
acts = [x['act'] for x in b.log]
|
||||||
|
assert acts == ['click', 'move', 'keypress', 'type_text'], acts
|
||||||
|
print('mock backend: OK', acts)
|
||||||
|
|
||||||
|
|
||||||
|
def test_scancode_table():
|
||||||
|
from backends.interception_win import SCAN, UPPER_SCAN
|
||||||
|
assert SCAN['a'] == 0x1E and SCAN['p'] == 0x19 and SCAN['z'] == 0x2C
|
||||||
|
assert SCAN['enter'] == 0x1C and SCAN['esc'] == 0x01
|
||||||
|
assert UPPER_SCAN['!'] == 0x02
|
||||||
|
# 连续无缺失
|
||||||
|
for ch in 'abcdefghijklmnopqrstuvwxyz0123456789':
|
||||||
|
assert ch in SCAN, 'missing %s' % ch
|
||||||
|
print('scancode table: OK')
|
||||||
|
|
||||||
|
|
||||||
|
def test_mcp_roundtrip_mock():
|
||||||
|
env = dict(os.environ, INPUT_BACKEND='mock')
|
||||||
|
p = subprocess.Popen([sys.executable, os.path.join(HERE, 'lc_mcp.py')],
|
||||||
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE, text=True, encoding='utf-8',
|
||||||
|
errors='replace', env=env)
|
||||||
|
def call(obj):
|
||||||
|
p.stdin.write(json.dumps(obj) + '\n')
|
||||||
|
p.stdin.flush()
|
||||||
|
return json.loads(p.stdout.readline())
|
||||||
|
r = call({'jsonrpc': '2.0', 'id': 1, 'method': 'initialize', 'params': {}})
|
||||||
|
assert r['result']['serverInfo']['name'] == 'lc-mcp'
|
||||||
|
r = call({'jsonrpc': '2.0', 'id': 2, 'method': 'tools/list', 'params': {}})
|
||||||
|
names = [t['name'] for t in r['result']['tools']]
|
||||||
|
assert 'get_state' in names and 'click_text' in names and 'wait_for_text' in names and 'wait_for_text_gone' in names, names
|
||||||
|
assert 'screenshot' in names and 'keypress' in names, names
|
||||||
|
r = call({'jsonrpc': '2.0', 'id': 3, 'method': 'tools/call',
|
||||||
|
'params': {'name': 'move', 'arguments': {'x': 5, 'y': 5}}})
|
||||||
|
assert 'mock' in r['result']['content'][0]['text']
|
||||||
|
p.kill()
|
||||||
|
print('mcp roundtrip(mock): OK', names)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
test_mock_backend()
|
||||||
|
test_scancode_table()
|
||||||
|
test_mcp_roundtrip_mock()
|
||||||
|
print('ALL TESTS PASSED')
|
||||||
Reference in New Issue
Block a user