Files
ykxmz/_build/commit_suite_fixes.py
xmz7891 1e73a789d1 测试套件:锁屏识别 + 退出码取法 + BOM 兜底
一、锁屏时截屏类测试误报
    电脑锁屏后,test_agent_protocol 的 5 项截屏断言、以及两个
    Java 端到端阶段必然失败 —— 但那是环境限制,不是代码问题。
    不区分的话汇总表一片红,真正的失败反而被淹没。
    现在启动时用 OpenInputDesktop 探测,锁屏时这些阶段记
    SKIP(锁屏) 而不是 FAIL,并在开头黄字提示。

二、管道后读 $LASTEXITCODE 不可靠
    形如
        & python xxx.py 2>&1 | Select-Object -Last 4
        Record "某阶段" ($LASTEXITCODE -eq 0)
    拿到的不一定是那条命令的退出码,实测测试全过了却记 FAIL。
    改成先把码存进变量再走管道。共修 4 处。

三、edit 工具会剥掉 .ps1 的 UTF-8 BOM
    没有 BOM 的 .ps1 会被 PowerShell 按 GBK 读,中文全乱码,
    接着一堆 "Unexpected token" 语法错误,脚本直接跑不了。
    这个坑今天踩了两次。加了 _build/fix_ps1_bom.py 统一补 BOM,
    并顺带检查 .bat 是不是 GBK。

跑出来:33 个阶段 —— 30 PASS + 3 SKIP(锁屏),0 FAIL。
2026-10-07 01:57:20 +08:00

72 lines
2.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
r'''提交测试套件的三处修复。'''
from __future__ import annotations
import os
import subprocess
import sys
from pathlib import Path
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
GIT = r"C:\Program Files\Git\bin\git.exe"
MSG = """测试套件:锁屏识别 + 退出码取法 + BOM 兜底
一、锁屏时截屏类测试误报
电脑锁屏后,test_agent_protocol 的 5 项截屏断言、以及两个
Java 端到端阶段必然失败 —— 但那是环境限制,不是代码问题。
不区分的话汇总表一片红,真正的失败反而被淹没。
现在启动时用 OpenInputDesktop 探测,锁屏时这些阶段记
SKIP(锁屏) 而不是 FAIL,并在开头黄字提示。
二、管道后读 $LASTEXITCODE 不可靠
形如
& python xxx.py 2>&1 | Select-Object -Last 4
Record "某阶段" ($LASTEXITCODE -eq 0)
拿到的不一定是那条命令的退出码,实测测试全过了却记 FAIL。
改成先把码存进变量再走管道。共修 4 处。
三、edit 工具会剥掉 .ps1 的 UTF-8 BOM
没有 BOM 的 .ps1 会被 PowerShell 按 GBK 读,中文全乱码,
接着一堆 "Unexpected token" 语法错误,脚本直接跑不了。
这个坑今天踩了两次。加了 _build/fix_ps1_bom.py 统一补 BOM,
并顺带检查 .bat 是不是 GBK。
跑出来:33 个阶段 —— 30 PASS + 3 SKIP(锁屏),0 FAIL。
"""
def main() -> int:
subprocess.run([GIT, "add", "-A"], cwd=str(ROOT), check=False)
msg_file = ROOT / "_build" / "_cmsg3.txt"
msg_file.write_bytes(MSG.encode("utf-8"))
r = subprocess.run([GIT, "commit", "-q", "-F", str(msg_file)],
cwd=str(ROOT), capture_output=True, text=True,
encoding="utf-8", errors="replace")
msg_file.unlink(missing_ok=True)
print(" commit exit=%s" % r.returncode)
show = subprocess.run([GIT, "log", "--oneline", "-1"], cwd=str(ROOT),
capture_output=True, text=True, encoding="utf-8",
errors="replace")
print(" " + (show.stdout or "").strip())
env = dict(os.environ)
env["GIT_SSH_COMMAND"] = r'"C:\Program Files\Git\usr\bin\ssh.exe"'
push = subprocess.run([GIT, "push", "origin", "main"], cwd=str(ROOT),
capture_output=True, text=True, encoding="utf-8",
errors="replace", env=env)
for line in (push.stderr or push.stdout or "").strip().splitlines()[-2:]:
print(" " + line)
status = subprocess.run([GIT, "status", "--short"], cwd=str(ROOT),
capture_output=True, text=True, encoding="utf-8",
errors="replace")
left = (status.stdout or "").strip()
print(" 工作区: %s" % ("干净 ✓" if not left else left[:200]))
return 0
if __name__ == "__main__":
sys.exit(main())