Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(tooling): use UTF-8 for agent command output

longmeidaobe3430a8dd8f
diff --git a/.claude/skills/peach-web-ui/SKILL.md b/.claude/skills/peach-web-ui/SKILL.md
index a54e93ffd..e91801f7b 100644
--- a/.claude/skills/peach-web-ui/SKILL.md
+++ b/.claude/skills/peach-web-ui/SKILL.md
@@ -77,7 +77,7 @@ description: 在新增、修改或复核 Peach 页面、控件、提示、错误
## 验收门槛
1. 为语义、DOM、ARIA、复用模块和响应式规则补页面源测试;数据语义变更另补 API/数据层测试。
-2. Windows 只从隔离 worktree 根运行 `& .\scripts\test.ps1`;本轮跨多个页面或改规范时跑默认 `full`。
+2. Windows 从隔离 worktree 根运行 `& .\scripts\test.ps1`,默认 `auto`;按影响域补测,规则见 `peach-worktree`。
3. 在本地预览检查桌面与 390×844:页面宽度不大于视口、弹层不越界、菜单内部滚动、键盘 focus 可见、控制台无错误。
4. 接口字段、sidecar 取值和锚点算术走 Python 严格 HTTPS(项目 CA 加 `ProxyHandler({})`)核对,不进浏览器。浏览器只留给布局后才成立的事实:`getComputedStyle`、真实裁切几何、hover/focus 态和实际像素;用读源码顶替这几样是降精度。
5. 一轮验收要读的页面状态先列全,再合成一次 `javascript_tool` 调用取回。私有网络主机(`.local` 与 `10.`/`172.16-31.`/`192.168.` 段的局域网 IP 归同一类)在桌面应用里只能逐次授权,站点级放行只给只读工具,点击与执行 JS 拿不到常驻许可,每多发一次调用就多一次弹窗。
diff --git a/.claude/skills/peach-worktree/SKILL.md b/.claude/skills/peach-worktree/SKILL.md
index dbb5de810..07da5bc9c 100644
--- a/.claude/skills/peach-worktree/SKILL.md
+++ b/.claude/skills/peach-worktree/SKILL.md
@@ -15,12 +15,14 @@ description: 在用户说并行、工作树、暂存、提交、ready、集成
## 流程
-1. 协调者在主目录创建隔离工作树:`& .\.venv\Scripts\python.exe scripts\agent_worktree.py create --agent claude --task <task>`。它建在 `peach-worktrees/`,Codex 和 Claude 共用这一个目录。**不要用 Claude Code 内置的工作树机制(`.claude/worktrees/`)**:它在分支被集成后会被回收,目录却留在原地。
+1. 协调者在主目录创建隔离工作树:`& .\.venv\Scripts\python.exe -X utf8 scripts\agent_worktree.py create --agent claude --task <task>`。它建在 `peach-worktrees/`,Codex 和 Claude 共用这一个目录。**不要用 Claude Code 内置的工作树机制(`.claude/worktrees/`)**:它在分支被集成后会被回收,目录却留在原地。
2. 工作者只在自己的工作树内编辑。`create` 自动锁定工作树,成功集成后解锁;不复制 `.venv`。
3. 测试在当前工作树根目录运行:Windows `& .\scripts\test.ps1`,macOS/Linux `./scripts/test.sh`。默认 `auto` 按改动文件取影响域并集;文档及无改动检查 `checks`,未知影响面、共享测试设施、依赖、构建选 `full`。域清单唯一真相在 `scripts/test_runner.py`;局部调试可显式选域。
两者契约相同:从 Git common directory 定位主项目 venv,强制 `PYTHONPATH=<当前工作树>/src`,
核对 `peach.__file__` 后运行标准库 `unittest`。禁止手工拼接 venv 路径或调用 pytest。
+ 测试入口固定 `PYTHONIOENCODING=utf-8`,覆盖标准输出、错误输出及子进程;其他 Python CLI 使用 `-X utf8`。
+ PowerShell 读 UTF-8 日志显式加 `-Encoding utf8`;编码在输出端固定,不能只给读取端指定编码。
记录绑定完整代码内容、依赖环境和范围,24 小时有效;失败、验证期间改动使记录无效。
有同环境全量基线时,`auto` 对比文件清单,只补跑新增差异的影响域;共享设施或未知文件仍跑全量。
差异补测不延长全量基线有效期;版本号行单独变化归 tooling,包内其他逻辑变化仍按源码判断。
diff --git a/docs/STATUS.md b/docs/STATUS.md
index 813293f6a..da2b154a0 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -6,8 +6,7 @@
## 运行态
-- HTTPS 就绪检查通过;未打标签发布。
-- 开发测试默认 `auto`;`ready` / `integrate` 检查本机验证记录,集成互斥,活动工作树锁定。CI 与部署全量验证,流程见 `peach-worktree` 技能。
+- HTTPS 就绪检查通过;未打标签发布。开发验证默认 `auto`。
- Windows 是当前 ledger writer,入口 `dist\Peach\Peach.exe`;代码、`peach-data`、worktree 和共享传输点同在一个顶层目录,外置盘只提供 `R:\media`。
- 托盘必须以普通权限启动:提升权限后的令牌看不到 CloudDrive 的 `A:` / `B:`,会把 PikPak 和 115 误报为脱盘。
diff --git a/scripts/agent_worktree.py b/scripts/agent_worktree.py
index 120d951f3..97b03aee0 100644
--- a/scripts/agent_worktree.py
+++ b/scripts/agent_worktree.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import argparse
import json
+import os
import re
import shutil
import stat
@@ -485,4 +486,8 @@ def main() -> int:
if __name__ == "__main__":
+ os.environ["PYTHONIOENCODING"] = "utf-8"
+ for stream in (sys.stdout, sys.stderr):
+ if hasattr(stream, "reconfigure"):
+ stream.reconfigure(encoding="utf-8", errors="backslashreplace")
raise SystemExit(main())
diff --git a/scripts/test.ps1 b/scripts/test.ps1
index cbe4b3567..e03d67ee2 100644
--- a/scripts/test.ps1
+++ b/scripts/test.ps1
@@ -26,8 +26,10 @@ if (-not (Test-Path -LiteralPath $Python -PathType Leaf)) {
$SourceRoot = (Resolve-Path -LiteralPath (Join-Path $WorktreeRoot 'src')).Path
$PreviousPythonPath = $env:PYTHONPATH
+$PreviousPythonIoEncoding = $env:PYTHONIOENCODING
$PreviousPath = $env:PATH
$env:PYTHONPATH = $SourceRoot
+$env:PYTHONIOENCODING = 'utf-8'
# Git for Windows 自带项目证书测试所需的 OpenSSL,但默认不会把 usr\bin 放进
# 用户 PATH。只对本次测试进程补齐,不修改系统或用户环境变量。
@@ -57,6 +59,11 @@ try {
exit $LASTEXITCODE
} finally {
Pop-Location
+ if ($null -eq $PreviousPythonIoEncoding) {
+ Remove-Item Env:PYTHONIOENCODING -ErrorAction SilentlyContinue
+ } else {
+ $env:PYTHONIOENCODING = $PreviousPythonIoEncoding
+ }
if ($null -eq $PreviousPythonPath) {
Remove-Item Env:PYTHONPATH -ErrorAction SilentlyContinue
} else {
diff --git a/scripts/test.sh b/scripts/test.sh
index c28c2f331..dd856e2f7 100755
--- a/scripts/test.sh
+++ b/scripts/test.sh
@@ -43,6 +43,7 @@ fi
SOURCE_ROOT="$WORKTREE_ROOT/src"
export PYTHONPATH="$SOURCE_ROOT"
+export PYTHONIOENCODING=utf-8
cd "$WORKTREE_ROOT"
LOADED_MODULE="$("$PYTHON" -c 'import peach; print(peach.__file__)')"
diff --git a/scripts/test_runner.py b/scripts/test_runner.py
index 02f22fa5a..78abc03ac 100644
--- a/scripts/test_runner.py
+++ b/scripts/test_runner.py
@@ -294,7 +294,8 @@ def main(argv: list[str] | None = None) -> int:
needed = tuple(dict.fromkeys((*needed, "tooling")))
if "full" not in needed:
weight = len({p for scope in needed for p in selected_files(scope)})
- choices.append((weight, record, needed))
+ if weight <= len(files):
+ choices.append((weight, record, needed))
if choices:
_, baseline, scopes = min(choices, key=lambda item: item[0])
print(f"复用全量基线 {baseline['state'][:12]};新增差异补测:{' '.join(scopes)}", flush=True)
diff --git a/tests/test_scripts.py b/tests/test_scripts.py
index 5c070e7fb..a6b5e86cd 100644
--- a/tests/test_scripts.py
+++ b/tests/test_scripts.py
@@ -240,6 +240,8 @@ class OperationalScriptTests(unittest.TestCase):
windows = (ROOT / "scripts" / "test.ps1").read_text(encoding="utf-8")
self.assertIn("rev-parse --git-common-dir", windows)
self.assertIn("$env:PYTHONPATH = $SourceRoot", windows)
+ self.assertIn("$env:PYTHONIOENCODING = 'utf-8'", windows)
+ self.assertIn("$env:PYTHONIOENCODING = $PreviousPythonIoEncoding", windows)
self.assertIn("peach.__file__", windows)
self.assertIn("scripts\\test_runner.py --scope $Scope", windows)
self.assertIn("ValidateSet('full', 'auto', 'follow'", windows)
@@ -248,6 +250,7 @@ class OperationalScriptTests(unittest.TestCase):
posix = (ROOT / "scripts" / "test.sh").read_text(encoding="utf-8")
self.assertIn("rev-parse --git-common-dir", posix)
self.assertIn('export PYTHONPATH="$SOURCE_ROOT"', posix)
+ self.assertIn("export PYTHONIOENCODING=utf-8", posix)
self.assertIn("peach.__file__", posix)
self.assertIn('scripts/test_runner.py --scope "$SCOPE"', posix)
self.assertIn('SCOPE="${1:-auto}"', posix)
diff --git a/tests/test_test_evidence.py b/tests/test_test_evidence.py
index 1eedd55d6..36ec3ed0f 100644
--- a/tests/test_test_evidence.py
+++ b/tests/test_test_evidence.py
@@ -138,7 +138,7 @@ class VerificationTests(unittest.TestCase):
with evidence.FileLock(folder / "integration.lock"):
result = subprocess.run(command, capture_output=True, text=True,
encoding="utf-8", timeout=15,
- env={**os.environ, "PYTHONIOENCODING": "utf-8"})
+ env={**os.environ, "PYTHONIOENCODING": "gbk"})
self.assertEqual(result.returncode, 2, result.stderr)
self.assertIn("另一任务正在集成", json.loads(result.stdout)["error"])
self.assertEqual(self.git("rev-parse", "HEAD"), before)
@@ -200,6 +200,17 @@ class VerificationTests(unittest.TestCase):
self.assertEqual(runner.main(["--scope", "auto"]), 0)
build.assert_called_once_with("full")
+ def test_baseline_does_not_expand_a_small_requested_scope(self):
+ self.certify(self.repo, ("full",))
+ (self.repo / "src/peach/__init__.py").write_text('__version__ = "0.7.31"\n')
+ with redirect_stderr(io.StringIO()), redirect_stdout(io.StringIO()), \
+ mock.patch.object(runner, "ROOT", self.repo), \
+ mock.patch.object(runner, "resolve_auto_scope", return_value=(("checks",), "fixture")), \
+ mock.patch.object(runner, "build_suite", return_value=unittest.TestSuite([
+ unittest.FunctionTestCase(lambda: None)])) as build:
+ self.assertEqual(runner.main(["--scope", "auto"]), 0)
+ build.assert_called_once_with("checks")
+
def test_baseline_distinguishes_version_assignment_and_package_logic(self):
self.certify(self.repo, ("full",))
version = self.repo / "src/peach/__init__.py"