48 lines
2.2 KiB
Python
48 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
def load_js_process_helpers() -> str:
|
|
patcher_path = Path(__file__).resolve().parents[1] / 'fixes' / 'patch_openclaw_weixin_hermes.py'
|
|
assert patcher_path.exists(), f'missing patcher: {patcher_path}'
|
|
spec = importlib.util.spec_from_file_location('patch_openclaw_weixin_hermes', patcher_path)
|
|
assert spec is not None and spec.loader is not None
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module.JS_PROCESS_HELPERS
|
|
|
|
|
|
def test_looks_like_hermes_image_followup_distinguishes_diagnostics_from_real_image_questions(tmp_path: Path) -> None:
|
|
js_process_helpers = load_js_process_helpers()
|
|
cases = {
|
|
'diag_cache_expired': ('图片缓存已失效,请重新发送图片。', False),
|
|
'diag_copying_text_shows_cache_error': ('为什么我复制发给你的文字,你都显示图片缓存已失效,请重新发送图片。', False),
|
|
'diag_not_image': ('这不是图片,是文字消息', False),
|
|
'diag_no_image_sent': ('我没有发图片', False),
|
|
'diag_system_logs': ('请检查系统日志,从机制上修复错误', False),
|
|
'image_cn_1': ('请看一下这张图片', True),
|
|
'image_cn_2': ('这图是什么', True),
|
|
'image_cn_3': ('识别图片内容', True),
|
|
'image_en': ('Can you take a look at this image?', True),
|
|
}
|
|
node_script = tmp_path / 'hermes_image_followup_check.js'
|
|
node_script.write_text(
|
|
js_process_helpers
|
|
+ '\n\nconst cases = '
|
|
+ json.dumps({key: text for key, (text, _) in cases.items()}, ensure_ascii=False)
|
|
+ ';\nconst results = {};\n'
|
|
+ 'for (const [key, text] of Object.entries(cases)) {\n'
|
|
+ ' results[key] = looksLikeHermesImageFollowup(text);\n'
|
|
+ '}\n'
|
|
+ 'console.log(JSON.stringify(results));\n',
|
|
encoding='utf-8',
|
|
)
|
|
completed = subprocess.run(['node', str(node_script)], check=True, capture_output=True, text=True)
|
|
results = json.loads(completed.stdout.strip())
|
|
for key, (_, expected) in cases.items():
|
|
assert results[key] is expected, f'{key}: expected {expected}, got {results[key]!r}'
|