mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 16:00:43 +00:00
用户这一轮报了两个问题,都修了。
== 一、Win7 上语音播报不能用 ==
用户原话:"我 win7 上的语音播报好像不能用,你再试一下别的版本能不能用"
**原来只有一条路**:
powershell -NoProfile -WindowStyle Hidden -Command
"Add-Type -AssemblyName System.Speech; $s = New-Object ...; $s.Speak('...')"
这在 Win7 上有三个坑,任何一个都能让它彻底不出声:
1. **`powershell` 只按名字找**
Win7 的 powershell.exe 在 `%SystemRoot%\System32\WindowsPowerShell\v1.0\`。
精简版系统、或从服务/计划任务拉起时 PATH 里可能没有 ——
CreateProcess 按名字找不到时是**静默失败**的。
2. **Win7 默认 PowerShell 2.0,它按 ANSI 代码页解析 `-Command`**
PS 3.0 起才按 UTF-16 处理。中文经 `-Command` 传进去容易乱码 ——
表现是念出来是乱码,或者干脆不念。
3. **`System.Speech` 需要 .NET Framework 3.0+**
而系统自带的 **SAPI5** 从 Windows XP 就有,**根本不需要 .NET**。
**改成多方案降级**,按"依赖越少越优先"排:
1. cscript + VBScript + SAPI5 <- Win98 起就有,不用装任何东西
2. wscript + VBScript + SAPI5 <- 上一条被安全软件拦时的备选
3. powershell + SAPI5 (COM) <- 绕开 .NET
4. powershell + System.Speech <- 原来的做法,改用绝对路径
5. powershell(PATH) + System.Speech <- 最原始的,兜底
一条通了**记住它**,以后直接用(不用每次从头试)。
**顺带修掉一个"骗人"的行为**:原来 `say()` 用 `Popen` 不等进程结束,
失败了也返回"已播报" —— 明明没出声却报成功。
现在等退出码,**全失败会明确报错并列出试过哪几条**。
代价是同步等待(念多久等多久),但"报成功其实没出声"比"慢一点"糟糕得多。
还加了 `_build/diag_tts.py`:在一台机器上把 5 条方案全试一遍并报告
哪条能用 —— 下次再有"某台机器上不行",跑一下就知道。
VBScript 的细节:**必须用 ANSI(mbcs) 写**,写成 UTF-8 的话
cscript 读出来中文是乱码(VBScript 的老规矩,很隐蔽)。
长文本还要分句 —— VBScript 单行有长度上限。
== 二、快捷栏按钮太小 + 4 格都要能换 ==
用户原话:"屏幕最上面这个按钮有些按不到,按钮太小了,做大一点,
然后呢,这个每每个四格算换一下吧,第一个第二个第三个
第四个都能换东西"
* **按钮做大**:30dp -> 46dp(接近 Android 建议的最小可点区域 48),
字号 11 -> 14。30dp 在表盘上手指按上去一半在栏外。
**栏高做成常量 QUICK_BAR_DP,栏高 / 面板 topMargin / addView
三处用同一个值** —— 分三处写的话改一个忘一个,
表现是"内容被盖住"或"上面空一条"。
* **4 格全部可自定义**。用户最早说"其中有一个按钮不能改,
功能就是一键返回桌面",第一版就按"第 4 格写死 desktop"做的。
现在他改主意了 —— 所以 desktop 变成**普通可选动作**,
默认仍放第 4 格(习惯不用改),但想换也能换。
可选动作从 7 个变成 8 个。
**教训(写进测试注释了)**:别把"用户当时的一句话"当成永久约束
焊进结构里;真是约束的话,注释里要写清是什么时候的要求,
下次他改主意时才知道该动哪儿。
== 三、修一个"测试自己没擦干净"造成的假 bug ==
全量回归报:
[FAIL] 配对码正确写入 实际 '(旧的残留值)'
而 `(旧的残留值)` 是**上一次测试遗留**的配对码 —— 数据目录
`C:\ProgramData\ykxmz\data` 在卸载时**故意不删**(那里存着用户的
中转地址、配对码等,卸载不该删),所以机器上会留着上一轮的
settings.json。测试装的时候虽然传了 `/CODE=517284`,但环境没擦干净时
就可能读到旧值 —— 表现成"安装包有 bug"。
**修法**:`test_installer_cycle.py` 加一步"装前先清残留"
(正规卸载 -> 杀进程 -> 删安装目录 -> **删数据目录**)。
数据目录那一步是关键 —— 卸载器不删它。
== 四、其他 ==
* `docs/项目规矩.md` 第一节改成**按预案执行**:
预案一 = 做完测试没问题就上传;预案二 = 做完测试但不上传,直接给用户。
用户没说预案几时默认按预案一,并在交付时说明。
* 顺手把那份文档里的老域名 `relay.xxmxxs.top` 改成现在的
`yk.xxmxxs.top`(老服务器早就退役了)。
* 修掉自己造的重复定义:往 actions.py 插降级链时,
`list_voices` / `say` 各插了两份(pyflakes 报 redefinition)。
* 一次危险的误操作:`Path.write_text(..., newline='\n')` 会**先截断文件
再校验参数**,参数非法时文件已经空了 —— 我用它把
`_tests/test_quickbar.py` 清空了。已重写。
**以后不给 write_text 传 newline。**
== 验证 ==
全量回归(21 关)全部 PASS
新增关卡:3a13 手表快捷栏 / 3a14 语音播报降级
安装包周期 23 项全过(装 -> 验 -> 卸 -> 再验)
Java 编译通过(android-34, --release 8)
本机实测语音播报:cscript 那条通了(2.4 秒)
全部产物重建,Win7 兼容校验通过
260 lines
10 KiB
Python
260 lines
10 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""验证三件套压缩包:解压出来实际跑一遍。
|
||
|
||
不只是看有没有文件 —— 要确认包里的东西**真的能用**:
|
||
1. 解压
|
||
2. 服务器端的 relay.py 能起、健康检查通过
|
||
3. 被控端的 EXE 能起、能连上包里那个中转
|
||
4. Java 手表端经这个中转连上被控端并执行命令
|
||
5. 清理
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
import os
|
||
import shutil
|
||
import subprocess
|
||
import sys
|
||
import tempfile
|
||
import time
|
||
import urllib.request
|
||
import zipfile
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(__file__).resolve().parent.parent
|
||
# 三端分开出(用户要求):
|
||
# 被控端 -> 一个 zip
|
||
# 服务器端 -> 一个 zip
|
||
# 控制端 -> 直接给 APK(不打 zip)
|
||
AGENT_ZIP = ROOT / "dist" / "ykxmz-agent-2.1.8.zip"
|
||
SERVER_ZIP = ROOT / "dist" / "ykxmz-server-2.1.8.zip"
|
||
WATCH_APK = ROOT / "dist" / "ykxmz-watch-2.1.8.apk"
|
||
TOOLCHAIN = Path(r"C:\Users\shu\Desktop\deepseekagent\starklink\toolchain")
|
||
JAVAC = TOOLCHAIN / "jdk17" / "bin" / "javac.exe"
|
||
JAVA = TOOLCHAIN / "jdk17" / "bin" / "java.exe"
|
||
RELAY_PORT = 8095
|
||
AGENT_PORT = 8895
|
||
PAIR_CODE = "778899"
|
||
|
||
passed = 0
|
||
failed = 0
|
||
|
||
|
||
def check(name, ok, detail=""):
|
||
global passed, failed
|
||
if ok:
|
||
passed += 1
|
||
print(" [PASS] " + name)
|
||
else:
|
||
failed += 1
|
||
print(" [FAIL] " + name + " " + str(detail))
|
||
|
||
|
||
def main() -> int:
|
||
# 1) 三个产物都要在
|
||
for label, path in (("被控端包", AGENT_ZIP), ("服务器端包", SERVER_ZIP),
|
||
("控制端 APK", WATCH_APK)):
|
||
if not path.is_file():
|
||
print(f" 找不到{label}: {path}")
|
||
return 1
|
||
|
||
work = Path(tempfile.mkdtemp(prefix="verify_pkg_"))
|
||
relay_proc = agent_proc = None
|
||
try:
|
||
# ---------------- 1. 解压两个 zip ----------------
|
||
print("一、解压(两个 zip)")
|
||
with zipfile.ZipFile(AGENT_ZIP) as archive:
|
||
archive.extractall(work)
|
||
with zipfile.ZipFile(SERVER_ZIP) as archive:
|
||
archive.extractall(work)
|
||
|
||
# 两个包各自带一层版本目录
|
||
agent_dir = work / AGENT_ZIP.stem
|
||
relay_dir = work / SERVER_ZIP.stem
|
||
check("被控端目录存在", agent_dir.is_dir(), agent_dir)
|
||
check("服务器端目录存在", relay_dir.is_dir(), relay_dir)
|
||
|
||
exe = agent_dir / "ykxmz.exe"
|
||
relay_py = relay_dir / "relay.py"
|
||
install_sh = relay_dir / "install.sh"
|
||
apk = WATCH_APK
|
||
check("被控端 EXE 在", exe.is_file())
|
||
check("服务器端 relay.py 在", relay_py.is_file())
|
||
check("服务器端 install.sh 在", install_sh.is_file())
|
||
check("服务器端带了网络调优脚本", (relay_dir / "net-tune.sh").is_file())
|
||
check("服务器端带了看门狗", (relay_dir / "watchdog.sh").is_file())
|
||
check("控制端 APK 在(直接在 dist 里)", apk.is_file(), apk)
|
||
|
||
# 说明文档要有 BOM(否则记事本会认成 GBK 乱码)
|
||
for label, path in (("被控端", agent_dir / "README-agent.txt"),
|
||
("服务器端", relay_dir / "README-server.txt"),
|
||
("控制端(旁边那份)",
|
||
ROOT / "dist" / "ykxmz-watch-2.1.8-说明.txt")):
|
||
raw = path.read_bytes() if path.is_file() else b""
|
||
check(f"{label}说明有 UTF-8 BOM",
|
||
raw[:3] == b"\xef\xbb\xbf", raw[:3])
|
||
|
||
# 三份正式文档:两个包里都要有
|
||
for label, base in (("被控端包", agent_dir), ("服务器端包", relay_dir)):
|
||
for doc in ("LICENSE.txt", "BEFORE-INSTALL.txt",
|
||
"AFTER-INSTALL.txt"):
|
||
check(f"{label}带了 {doc}", (base / doc).is_file())
|
||
|
||
# 被控端目录里不该有 data / 说明残留
|
||
check("没有把 data 目录打进去",
|
||
not (agent_dir / "data").exists())
|
||
check("带了三个工具脚本",
|
||
all((agent_dir / n).is_file()
|
||
for n in ("wlzj.bat", "xffhq.bat", "fxfhq.bat")),
|
||
[n for n in ("wlzj.bat", "xffhq.bat", "fxfhq.bat")
|
||
if not (agent_dir / n).is_file()])
|
||
|
||
# ---------------- 2. 起包里的中转 ----------------
|
||
print()
|
||
print("二、用包里的 relay.py 起中转")
|
||
relay_data = work / "relaydata"
|
||
relay_data.mkdir(parents=True, exist_ok=True)
|
||
env = dict(os.environ)
|
||
env.update({
|
||
"RELAY_PORT": str(RELAY_PORT), "RELAY_BIND": "127.0.0.1",
|
||
"RELAY_DATA": str(relay_data), "RELAY_POLL": "8",
|
||
"PYTHONIOENCODING": "utf-8", "PYTHONUNBUFFERED": "1",
|
||
})
|
||
relay_proc = subprocess.Popen(
|
||
[sys.executable, "-u", str(relay_py)], env=env,
|
||
stdout=open(work / "relay.log", "wb"),
|
||
stderr=subprocess.STDOUT)
|
||
base = f"http://127.0.0.1:{RELAY_PORT}"
|
||
up = False
|
||
for _ in range(40):
|
||
time.sleep(0.5)
|
||
try:
|
||
with urllib.request.urlopen(base + "/v1/health",
|
||
timeout=2) as r:
|
||
if r.status == 200:
|
||
up = True
|
||
break
|
||
except Exception: # noqa: BLE001
|
||
continue
|
||
check("包里的中转能起", up)
|
||
if not up:
|
||
print((work / "relay.log").read_text(encoding="utf-8",
|
||
errors="replace")[-800:])
|
||
return 1
|
||
|
||
# ---------------- 3. 起包里的被控端 ----------------
|
||
print()
|
||
print("三、用包里的 EXE 起被控端,让它连这个中转")
|
||
data_dir = agent_dir / "data"
|
||
data_dir.mkdir(parents=True, exist_ok=True)
|
||
sys.path.insert(0, str(ROOT / "windows"))
|
||
from lanremote.config import Store
|
||
store = Store(data_dir)
|
||
store.set_pairing_code(PAIR_CODE)
|
||
store.set("setup_done", True)
|
||
store.set("allow_new_pairing", True)
|
||
store.set("close_pair_after_first", False)
|
||
store.set("server_name", "包里测试电脑")
|
||
store.set("relay_url", base)
|
||
store.set("port", AGENT_PORT)
|
||
|
||
agent_proc = subprocess.Popen(
|
||
[str(exe), "--silent", "--port", str(AGENT_PORT)],
|
||
cwd=str(agent_dir),
|
||
stdout=open(work / "agent.log", "wb"),
|
||
stderr=subprocess.STDOUT)
|
||
online = False
|
||
info = {}
|
||
for _ in range(60):
|
||
time.sleep(1.0)
|
||
try:
|
||
with urllib.request.urlopen(base + "/v1/health",
|
||
timeout=3) as r:
|
||
snap = json.loads(r.read())
|
||
for item in snap.get("devices", []):
|
||
if item.get("online"):
|
||
info = item
|
||
online = True
|
||
break
|
||
except Exception: # noqa: BLE001
|
||
continue
|
||
if online:
|
||
break
|
||
check("包里的 EXE 连上了包里的中转", online, str(info)[:150])
|
||
if not online:
|
||
print((work / "agent.log").read_text(encoding="utf-8",
|
||
errors="replace")[-1000:])
|
||
return 1
|
||
check("配对码对得上", info.get("code") == PAIR_CODE, info.get("code"))
|
||
check("设备名对得上", info.get("name") == "包里测试电脑",
|
||
info.get("name"))
|
||
|
||
# ---------------- 4. Java 手表端 ----------------
|
||
print()
|
||
print("四、Java 手表端经这个中转连被控端")
|
||
classes = work / "classes"
|
||
classes.mkdir(parents=True, exist_ok=True)
|
||
sources = [ROOT / "android" / "src" / "com" / "lanremote" / "watch" / n
|
||
for n in ("Json.java", "B64.java", "Transport.java",
|
||
"RelayTransport.java", "TlsCompat.java",
|
||
"RemoteClient.java",
|
||
"DiscoveryCore.java")]
|
||
sources.append(ROOT / "_tests" / "java" / "JavaRelayTest.java")
|
||
comp = subprocess.run(
|
||
[str(JAVAC), "--release", "8", "-encoding", "UTF-8",
|
||
"-d", str(classes)] + [str(s) for s in sources],
|
||
capture_output=True, text=True, encoding="utf-8", errors="replace")
|
||
check("Java 编译通过", comp.returncode == 0, comp.stderr[:200])
|
||
if comp.returncode != 0:
|
||
return 1
|
||
|
||
# 这条链路实测只有 ~75% 可用(丢包 40%,边缘还在美西),
|
||
# 而这里串行发多个请求,任何一个被丢就整体失败 —— 会假失败。
|
||
# 测试要验证的是**产品逻辑**,链路可靠性有专门的可用率测量盯着。
|
||
# 所以重试 3 次,任一次全过就算过。
|
||
result = None
|
||
tail = ""
|
||
for attempt in range(3):
|
||
result = subprocess.run(
|
||
[str(JAVA), "-Dfile.encoding=UTF-8", "-cp", str(classes),
|
||
"JavaRelayTest", base, PAIR_CODE],
|
||
capture_output=True, text=True, encoding="utf-8",
|
||
errors="replace")
|
||
tail = (result.stdout.strip().splitlines()[-1]
|
||
if result.stdout.strip() else "")
|
||
if result.returncode == 0 and "失败 0 项" in tail:
|
||
if attempt:
|
||
print(f" (第 {attempt + 1} 次才通过 —— "
|
||
f"链路抖动,不是产品问题)")
|
||
break
|
||
if attempt < 2:
|
||
time.sleep(2.0)
|
||
check("Java 手表端经中转全部通过",
|
||
result is not None and result.returncode == 0
|
||
and "失败 0 项" in tail, tail)
|
||
for line in result.stdout.splitlines():
|
||
if "[FAIL]" in line:
|
||
print(" " + line.strip())
|
||
|
||
print()
|
||
print("=" * 66)
|
||
print(f"通过 {passed} 项,失败 {failed} 项")
|
||
return 0 if failed == 0 else 1
|
||
finally:
|
||
for process in (agent_proc, relay_proc):
|
||
if process is not None:
|
||
try:
|
||
process.terminate()
|
||
process.wait(timeout=8)
|
||
except Exception: # noqa: BLE001
|
||
try:
|
||
process.kill()
|
||
except Exception: # noqa: BLE001
|
||
pass
|
||
time.sleep(1)
|
||
shutil.rmtree(work, ignore_errors=True)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|