# -*- coding: utf-8 -*- """让 verify_all 的每个 python 阶段都打印 FAIL 详情。 原来一律 `Select-Object -Last 4`,只看到最后几行 —— 失败了却不知道是哪几条,得手动再跑一遍。 改成:FAIL 行 + 最后一行汇总,一次就能看到问题。 """ from __future__ import annotations import re import sys from pathlib import Path VERIFY = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\_tests" r"\verify_all.ps1") def main() -> int: raw = VERIFY.read_bytes() had_bom = raw.startswith(b"\xef\xbb\xbf") text = raw.decode("utf-8-sig") if "Show-Fails" in text: print(" 已经加过") return 0 # 加一个辅助函数 helper_anchor = "function Stop-Strays {" helper = '''function Show-Fails($lines) { # 失败的阶段光看最后几行没用,得把 [FAIL] 打出来 $fails = $lines | Select-String -Pattern '\\[FAIL\\]' if ($fails) { $fails | Select-Object -First 8 | ForEach-Object { Write-Host " $($_.Line.Trim())" -ForegroundColor Red } } $lines | Select-Object -Last 1 | ForEach-Object { Write-Host " $($_.Trim())" } } ''' + helper_anchor text = text.replace(helper_anchor, helper, 1) print(" 加了 Show-Fails 辅助函数") # 把所有 `2>&1 | Select-Object -Last N` 换成先收集再 Show-Fails pattern = re.compile( r"& python \(Join-Path \$root \"([^\"]+)\"\) 2>&1 \|\r?\n" r"\s*Select-Object -Last \d+") def repl(match): script = match.group(1) return (f'$out = & python (Join-Path $root "{script}") 2>&1\r\n' f' Show-Fails $out') text, count = pattern.subn(repl, text) print(f" 改了 {count} 个 python 阶段") VERIFY.write_bytes((b"\xef\xbb\xbf" if had_bom else b"") + text.replace("\r\n", "\n").encode("utf-8")) print(f" BOM {'保留' if had_bom else '无'}") return 0 if __name__ == "__main__": sys.exit(main())