# -*- coding: utf-8 -*- """把「开机零窗口」测试接进 verify_all.ps1,并清理引用已删测试的残留。""" from __future__ import annotations import re import sys from pathlib import Path TARGET = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\_tests\verify_all.ps1") ANCHOR = 'Record "首次设置窗口" ($setupCode2 -eq 0)' ADDITION = '''Record "首次设置窗口" ($setupCode2 -eq 0) # ---------------------------------------------------------------- 1l Banner "1l/7 开机零窗口(照注册表里的自启命令真跑一遍)" Stop-Strays & python (Join-Path $root "_tests\\test_boot_silent.py") *> (Join-Path $env:TEMP "lr_boot.txt") $bootCode = $LASTEXITCODE Get-Content (Join-Path $env:TEMP "lr_boot.txt") -Encoding UTF8 -ErrorAction SilentlyContinue | Select-Object -Last 3 Record "开机零窗口" ($bootCode -eq 0)''' def main() -> int: raw = TARGET.read_bytes() bom = raw[:3] == b"\xef\xbb\xbf" text = raw.decode("utf-8-sig") if "test_boot_silent.py" not in text: if ANCHOR not in text: print(" [失败] 锚点没找到") return 1 text = text.replace(ANCHOR, ADDITION, 1) print(" verify_all.ps1: 已插入「开机零窗口」阶段") # 清理引用已删测试的残留行 for name in ("test_pc_gui.py", "test_simple_ui.py", "test_quit.py"): if name in text: lines = text.splitlines(keepends=True) kept = [l for l in lines if name not in l] removed = len(lines) - len(kept) text = "".join(kept) print(f" 清掉 {name} 残留 {removed} 行") data = text.encode("utf-8") if bom: data = b"\xef\xbb\xbf" + data TARGET.write_bytes(data) # 看看还剩哪些阶段 names = re.findall(r'Record "([^"]+)"', text) print(f"\n 当前 {len(names)} 个验证阶段:") for name in names: print(f" - {name}") return 0 if __name__ == "__main__": sys.exit(main())