返回 Bug 清单
BUG-1379project-12低已修复python-logic
pytest test_knowledge_freshness.py 有 UTF-8 BOM 导致 collection error SyntaxError
发现:2026-10-15验证:2026-10-15置信度:85%
症状
pytest collection error 中断全量测试;743 items collected 但 1 error 导致 --maxfail=1 时整个 session 停;test_knowledge_freshness.py 的 9 个测试从来没跑过
根因
Windows PowerShell 写 UTF-8 文件默认带 BOM (byte order mark 0xEF 0xBB 0xBF = U+FEFF)。Python 3 源码解析器只接受 UTF-8 without BOM——任何 .py 文件开头有 BOM 都会在 import/collection 时报 SyntaxError。这个文件是之前某个 AI agent 或工具在 Windows 下创建时带进去的。整个 pytest session 因此被 --ignore= 跳过,永远没执行过。
修复方案
用 PowerShell [System.IO.File]::ReadAllText + UTF8Encoding($false) 重写去掉 BOM。修复命令: $c=[IO.File]::ReadAllText($f); [IO.File]::WriteAllText($f, $c.TrimStart([char]0xFEFF), [Text.UTF8Encoding]$false)。修完后 9 tests collected 正常,但 4 个因 auth fixture 问题 401。
错误签名
SyntaxError: invalid non-printable character U+FEFF技术信息
来源项目
project-12
涉及文件
backend/tests/test_knowledge_freshness.py
标签
project-12, mcp-reported, source-agent