合并 codex/mcp-runtime-reliability: 运行可靠性、局状态与决策交接
与 main 上的审查修复及 2131f89 (story-test) 合并, 冲突处理:
- mcp_session: 保留超时/取消客户端, 补回 raise_on_error
- 执行器: 局状态改用 run_state (run_id 绑定), 取代完成后归档 context;
Jev 请求统一经 jev_client.request_answer (支持 baseUrl/curl, 返回置信度与概率);
保留截图解码缓存、地图模板缓存、按坐标点按钮、use_last_error 单实例互斥;
刷新计数与开战标记只在动作成功后更新
- battle_batch: 取消/预算框架 + 只在看到胜率按钮时点胜率再回车;
回合标签改为包含匹配 (OCR 常输出 'wave1')
- 文档采用 reliability 版本 (已是仓库相对路径), 注明 jev_client
- 测试: 互斥量桩改为 WinDLL/get_last_error, 战斗批次测试按胜率语义重写,
Jev 测试改为对 jev_client 打桩, 生命周期测试改为轮询; 145 项通过
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+56
-1
@@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""不需要 Windows/AALC 的测试: python -m unittest discover -s tests"""
|
"""不需要 Windows/AALC 的测试: python -m unittest discover -s tests"""
|
||||||
import json
|
import json
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -84,6 +85,55 @@ class ProtocolTest(unittest.TestCase):
|
|||||||
self.assertIn('bad arguments', r['error'])
|
self.assertIn('bad arguments', r['error'])
|
||||||
self.assertFalse(call(self.s, 'click')['ok'])
|
self.assertFalse(call(self.s, 'click')['ok'])
|
||||||
|
|
||||||
|
def test_invalid_request_shapes_do_not_escape_or_send_input(self):
|
||||||
|
for params in (['invalid'], 'invalid', 1, True, None):
|
||||||
|
response = self.s.handle({'jsonrpc': '2.0', 'id': 7, 'method': 'tools/call', 'params': params})
|
||||||
|
self.assertEqual(response['error']['code'], -32602)
|
||||||
|
for arguments in ([], 'invalid', 1, True, None):
|
||||||
|
response = self.s.handle({'jsonrpc': '2.0', 'id': 8, 'method': 'tools/call',
|
||||||
|
'params': {'name': 'click', 'arguments': arguments}})
|
||||||
|
self.assertEqual(response['error']['code'], -32602)
|
||||||
|
self.assertEqual(self.engine.actions, [])
|
||||||
|
|
||||||
|
def test_notifications_never_reply_or_perform_request_only_actions(self):
|
||||||
|
message = {'jsonrpc': '2.0', 'method': 'tools/call',
|
||||||
|
'params': {'name': 'click', 'arguments': {'x': 1, 'y': 2}}}
|
||||||
|
self.assertIsNone(self.s.handle(message))
|
||||||
|
self.assertEqual(self.engine.actions, [])
|
||||||
|
self.assertIsNotNone(self.s.handle(dict(message, id=None)))
|
||||||
|
|
||||||
|
def test_malformed_messages_allow_following_valid_request(self):
|
||||||
|
messages = ['null', '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":[1]}',
|
||||||
|
'{"jsonrpc":"2.0","id":2,"method":"ping"}']
|
||||||
|
stdin, stdout = io.StringIO('\n'.join(messages) + '\n'), io.StringIO()
|
||||||
|
srv_mod.serve_lines(self.s, stdin.readline, stdout.write)
|
||||||
|
responses = [json.loads(line) for line in stdout.getvalue().splitlines()]
|
||||||
|
self.assertEqual([r.get('error', {}).get('code') for r in responses[:2]], [-32600, -32602])
|
||||||
|
self.assertEqual(responses[2], {'jsonrpc': '2.0', 'id': 2, 'result': {}})
|
||||||
|
|
||||||
|
def test_invalid_envelope_returns_request_error(self):
|
||||||
|
for updates in ({'jsonrpc': '1.0'}, {'method': []}, {'id': True}, {'id': []}):
|
||||||
|
message = dict({'jsonrpc': '2.0', 'id': 9, 'method': 'ping'}, **updates)
|
||||||
|
self.assertEqual(self.s.handle(message)['error']['code'], -32600)
|
||||||
|
|
||||||
|
def test_task_start_cannot_race_an_input_already_in_progress(self):
|
||||||
|
entered, release = threading.Event(), threading.Event()
|
||||||
|
self.engine.click = lambda *args: (entered.set(), release.wait(3))
|
||||||
|
worker = threading.Thread(target=lambda: call(self.s, 'click', x=1, y=2))
|
||||||
|
worker.start()
|
||||||
|
try:
|
||||||
|
self.assertTrue(entered.wait(2))
|
||||||
|
started = time.monotonic()
|
||||||
|
response = call(self.s, 'run_task', task='mirror')
|
||||||
|
self.assertFalse(response['ok'])
|
||||||
|
self.assertIsNone(self.tasks.proc)
|
||||||
|
self.assertLess(time.monotonic() - started, 1)
|
||||||
|
self.assertEqual(call(self.s, 'task_status')['state'], 'idle')
|
||||||
|
self.assertTrue(call(self.s, 'stop_task')['ok'])
|
||||||
|
finally:
|
||||||
|
release.set()
|
||||||
|
worker.join(3)
|
||||||
|
|
||||||
def test_drag_duration_and_rejected_arguments(self):
|
def test_drag_duration_and_rejected_arguments(self):
|
||||||
r = call(self.s, 'drag', from_x=200, from_y=300, to_x=200, to_y=600, duration=1.5)
|
r = call(self.s, 'drag', from_x=200, from_y=300, to_x=200, to_y=600, duration=1.5)
|
||||||
self.assertTrue(r['ok'])
|
self.assertTrue(r['ok'])
|
||||||
@@ -123,8 +173,13 @@ class ProtocolTest(unittest.TestCase):
|
|||||||
self.assertIn('stop_task', call(self.s, 'drag', from_x=1, from_y=2,
|
self.assertIn('stop_task', call(self.s, 'drag', from_x=1, from_y=2,
|
||||||
to_x=3, to_y=4)['error'])
|
to_x=3, to_y=4)['error'])
|
||||||
self.assertTrue(call(self.s, 'get_state')['ok']) # 只读工具仍可用
|
self.assertTrue(call(self.s, 'get_state')['ok']) # 只读工具仍可用
|
||||||
time.sleep(0.5)
|
# 轮询等子进程输出, 不用固定等待 (机器负载高时 0.5s 不够)
|
||||||
|
deadline = time.time() + 10
|
||||||
|
while True:
|
||||||
st = call(self.s, 'task_status')
|
st = call(self.s, 'task_status')
|
||||||
|
if st['log_tail'] or time.time() > deadline:
|
||||||
|
break
|
||||||
|
time.sleep(0.05)
|
||||||
self.assertEqual(st['state'], 'running')
|
self.assertEqual(st['state'], 'running')
|
||||||
self.assertEqual(st['params'], {'count': 2})
|
self.assertEqual(st['params'], {'count': 2})
|
||||||
self.assertIn("child ['mirror', '{\"count\": 2}']", '\n'.join(st['log_tail']))
|
self.assertIn("child ['mirror', '{\"count\": 2}']", '\n'.join(st['log_tail']))
|
||||||
|
|||||||
Reference in New Issue
Block a user