"""Use only generated images; never send screenshots or desktop input.""" import json from pathlib import Path import subprocess import sys import time ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT)) import lc_mcp as app from PIL import Image, ImageDraw, ImageFont out = ROOT / 'validation-artifacts' out.mkdir(exist_ok=True) results = {} image = Image.new('RGB', (900, 300), 'white') draw = ImageDraw.Draw(image) font = ImageFont.truetype('C:/Windows/Fonts/msyh.ttc', 52) draw.text((40, 30), '开始 测试', font=font, fill='black') draw.text((40, 130), 'TEST 123', font=font, fill='black') path = out / 'ocr-synthetic.png' image.save(str(path)) start = time.monotonic() items, error = app.ocr_image(str(path)) results['remote_ocr'] = {'url': app.OCR_URL, 'seconds': round(time.monotonic() - start, 3), 'items': items, 'error': error, 'input': str(path)} print(json.dumps({'remote_ocr': results['remote_ocr']}, ensure_ascii=True), flush=True) # Exact script-generation expression from platform/win.py, with isolated paths. job = str(out / 'nonexistent-test-job.ps1') vbs = out / 'run-original.vbs' vbs.write_text('CreateObject("WScript.Shell").Run "powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%s"", 0, False\n' % job, encoding='utf-8') r = subprocess.run(['cscript.exe', '//nologo', str(vbs)], capture_output=True, timeout=10) results['windows_vbs'] = {'returncode': r.returncode, 'stdout': r.stdout.decode('mbcs', errors='replace'), 'stderr': r.stderr.decode('mbcs', errors='replace'), 'script': vbs.read_text(encoding='utf-8')} print(json.dumps({'windows_vbs': results['windows_vbs']}, ensure_ascii=True), flush=True) for name in ('sendinput', 'interception'): try: backend = app.get_input_backend(name, 'win') results[name + '_initialization'] = {'ok': True} except Exception as e: results[name + '_initialization'] = {'ok': False, 'error': str(e)} (ROOT / 'live-service-results.json').write_text(json.dumps(results, ensure_ascii=False, indent=2), encoding='utf-8') print(json.dumps(results, ensure_ascii=True), flush=True)