Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(seed): 补齐历史表迁移与集成校验

longmeidaod2dc9b22899c
diff --git a/.claude/skills/peach-ledger-write/SKILL.md b/.claude/skills/peach-ledger-write/SKILL.md
index a6cd9426d..8afc75b23 100644
--- a/.claude/skills/peach-ledger-write/SKILL.md
+++ b/.claude/skills/peach-ledger-write/SKILL.md
@@ -5,8 +5,8 @@ description: 在用户说迁移、migrate、--apply、合并实体、merge_entit
# 真实 ledger 写入流程
-最后复核:2026-10-02
-证据来源:`docs/HANDOFF.md`「数据安全」「身份、来源与标识采集」、ADR-0005、ADR-0015、ADR-0017、ADR-0052、ADR-0091。
+最后复核:2026-10-17
+证据来源:`docs/HANDOFF.md`「数据安全」「身份、来源与标识采集」、ADR-0005、ADR-0015、ADR-0017、ADR-0052、ADR-0091、ADR-0106。
真实库:当前写入者本机 `PEACH_DATA_ROOT/database/ledger.db`(WAL)。绝不能把共享传输副本或
另一台机器的副本当当前真实库;测试只用临时 SQLite 与临时媒体。
@@ -42,10 +42,9 @@ Windows 写者的托盘在启动与「重启服务」时、子服务停着的间
只产候选,人复核后才 `approved`;撤不回的(合并、改规范名)判据再确定也要授权。
- 运维脚本默认 dry-run:`scrape_codes.py` 默认只写复核 CSV,`clean_names.py` 默认只生成
改名计划且 `--apply` 前备份 SQLite 并在数据库更新失败时回滚文件名。
-- 种子包(ADR-0073、0075):导入只给已有实体填空、不造实体,只换 `auto:seed@…` 自己写过的归属、
- 片商与资料行,与人写的不一致记 `seed-landing.csv`;归属 `auto:seed@<版本>`。`export` 只读,
- 内容变了必须换更新的版本串(版本串是导入的幂等键,不比现有文件新的会被脚本拒绝),数据包单独提交,
- 推不推公开仓库由用户看字段决定。
+- 种子包按 ADR-0073、0075、[0106](../../../docs/adr/0106-seed-correction-history-and-explicit-withdrawals.md) 校验;只匹配已有实体,保留源置信度与非种子归属,冲突记 `seed-landing.csv`。
+ 只精确撤销 `auto:seed` 拥有的旧断言,不依据缺席撤销。`export` 只读;更新须递增版本与修订号、继承累计撤销,
+ 经差异复核后独立提交数据包。内容摘要与永久历史校验由导入入口执行;公开推送由用户看字段决定。
## 实体合并
diff --git a/docs/OPERATIONS.md b/docs/OPERATIONS.md
index 8fa8beb27..f195ff194 100644
--- a/docs/OPERATIONS.md
+++ b/docs/OPERATIONS.md
@@ -161,7 +161,7 @@ Windows 测试包在 Peach 配置「应用与维护 → 卸载 Peach」里卸载
### 本机诊断
-托盘「导出诊断报告」和系统诊断页「下载诊断报告」提供脱敏 ZIP。启动失败时,弹窗给出自动保存的报告位置。报告包含版本、系统信息、选定日志的末尾和可取得的系统检查;配置文件、凭据、账本和媒体不进入报告。日志中的网址、本机路径、IP、邮箱和常见凭据字段会脱敏,发送前仍应检查报告内容。
+托盘「导出诊断报告」和系统诊断页「下载诊断报告」提供脱敏 ZIP。托盘导出完成后可打开目录、打开文件或关闭窗口;启动失败时,弹窗给出自动保存的报告位置。报告包含版本、系统信息、选定日志的末尾和可取得的系统检查;配置文件、凭据、账本和媒体不进入报告。日志中的网址、本机路径、IP、邮箱和常见凭据字段会脱敏,发送前仍应检查报告内容。
独立包支持 `Peach.exe --diagnostic-report`,无需启动服务即可保存报告;指定目标文件时放在该参数后,已有文件不会覆盖。源码环境可用 `python -m peach.support_bundle` 取得同类报告。默认报告与错误日志保存在数据目录的 `logs`,目录不可写时使用系统临时目录下的 `Peach/logs`。
@@ -261,13 +261,16 @@ Windows 上 TLS 私钥禁用了权限继承,只允许实际运行服务的账
## 播放与转码
-浏览器能直接播放的格式(例如常见的 MP4)不需要额外软件。转码、探测和缩略图需要 FFmpeg 与 ffprobe,需要自己安装。配置页「运行信息」缺少它们时会给出 FFmpeg 下载入口;首次设置缺少 OpenSSL 时也会给出下载入口。
+浏览器能直接播放的格式(例如常见的 MP4)不需要额外软件。Windows 安装版和绿色版携带 FFmpeg、ffprobe 与修复损坏 MP4 索引用的 untrunc。源码部署需要自行提供这些工具;配置页「运行信息」缺少它们时会给出下载入口。首次设置缺少 OpenSSL 时也会给出下载入口。
Peach 按下面的顺序找 FFmpeg 和 ffprobe:
1. 显式设置的环境变量。
-2. 数据目录下的 `tools/ffmpeg/bin`。
-3. PATH。
+2. 独立程序目录下的 `tools/ffmpeg/bin`。
+3. 数据目录下的 `tools/ffmpeg/bin`。
+4. PATH。
+
+untrunc 按相同顺序查找,对应目录为 `tools/untrunc`。独立程序优先使用随包验证的版本;环境变量仍可显式指定工具路径。
播放时:
diff --git a/docs/PRODUCT_BACKLOG.md b/docs/PRODUCT_BACKLOG.md
index bb5e67aba..a7eb8ecc9 100644
--- a/docs/PRODUCT_BACKLOG.md
+++ b/docs/PRODUCT_BACKLOG.md
@@ -203,7 +203,7 @@
合计:**74 项开放需求**,其中 7 项已有骨架,67 项其他开放需求。已完成的需求不在这里留痕,去 Git 历史查。
-## 待执行的操作(41 项)
+## 待执行的操作(42 项)
这里包含可直接开发的修复,以及需要另行授权、外部条件或人工判断的操作与复核批次,比上面的需求细一层;做完就删,不在这里留痕。待办只放这一处:[docs/STATUS.md](STATUS.md) 每次会话开头都要读,队列不该常驻在那种入口文件里。
diff --git a/docs/STATUS.md b/docs/STATUS.md
index 279776b3a..d8e6baa16 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -31,17 +31,17 @@
- Windows doctor、诊断页通过 CA;本地目录缺失,115/PikPak 可读;密码未开、历史失败为警告。
- Python 最低与默认 3.14;Windows FFmpeg/ffprobe 在 `peach-data/tools/ffmpeg`,macOS 走 PATH。
- amane 0.20.0,安装一致;[功能与接入](reference-snapshots/upstream-review.md)。
-- 发行名 `peach`、目录名 `peach-app`。macOS 按待办第 26 条处理后重启菜单栏;无口令的 `peach serve --host 0.0.0.0` 拒绝启动。
+- 发行名 `peach`、目录名 `peach-app`;Mac 维护与重启见待办 26。
- 扫描、采集 120 秒无进展预警;资料 90 秒、封面 240 秒超时可重试;见 `state/library-processing-<job_id>.issues.jsonl`。
- 口味、复核、关注按账本、文件版本缓存;女优资料后继每轮存量至多 16 条。
- 下载后处理:16 条旧失败任务保留,部分资产已移动;`task_run` 外键异常 242 条未清理。
- [标签归一](reference-snapshots/tag-vocabulary-audit.md)
-- 实体种子 `2026-10-17.1`:1,199 实体、723 份资料,13 项有证据的精确撤销;v2 保留源置信度,永久历史与累计撤销防旧包回放(ADR-0106)。只读导出,真实账本未应用 `0047`;冲突与重复身份在 `generated/seed-landing.csv`。
-- 诊断报告弹窗提供打开目录、打开文件与关闭;原生 6 种操作通过,源码托盘已重启,HTTPS 就绪使用项目 CA 严格校验通过。
-- Windows 安装包与目录包携带 FFmpeg 9.0.2、ffprobe、untrunc `9d86ec9` 及完整对应源码;构建与独立 EXE 冒烟通过,配置页没有工具缺失项,软件/GPU 转码、抽帧、损坏 MP4 恢复通过。候选未发布,安装包本机仅编译,真实安装留给干净 CI 验收。
+- 种子 `2026-10-17.1`:1,199 实体、13 撤销(ADR-0106);`0047` 未应用。
+- 诊断报告操作、托盘重启与严格 CA HTTPS 通过。
+- Windows 工具候选构建与 EXE 冒烟通过;未发布,安装/卸载未验证。
- 推送发现开:本地 watch 加 CloudDrive 云端前缀 `/115open→B:`、`/Pikpak→A:`;关注每 60 分钟轮询;自动更新关闭。
- Cloudflare 公网入口默认关,配置页启停前须设密码;临时链接写状态文件,命名隧道限源码部署、令牌存设置文件;整站 `noindex` 与 `/robots.txt`。
-- FC2PPV-DB、JAVten 与被拦时的 minnano-av 经本机 Chrome 取页(ADR-0065),profile 在 `secrets/browser/`,免贴 Cookie。
+- FC2PPV-DB、JAVten、被拦的 minnano-av 经本机 Chrome 取页(ADR-0065),profile 在 `secrets/browser/`。
## 批处理进度
diff --git a/migrations/0047_seed_pack_history.sql b/migrations/0047_seed_pack_history.sql
index 1dfa9d333..d94a483aa 100644
--- a/migrations/0047_seed_pack_history.sql
+++ b/migrations/0047_seed_pack_history.sql
@@ -9,3 +9,14 @@ CREATE TABLE seed_pack_history(
CREATE UNIQUE INDEX idx_seed_pack_history_revision
ON seed_pack_history(revision) WHERE revision > 0;
+
+INSERT INTO ledger_revision(tbl) VALUES('seed_pack_history');
+CREATE TRIGGER rev_seed_pack_history_insert AFTER INSERT ON seed_pack_history BEGIN
+ UPDATE ledger_revision SET n=n+1 WHERE tbl='seed_pack_history';
+END;
+CREATE TRIGGER rev_seed_pack_history_update AFTER UPDATE ON seed_pack_history BEGIN
+ UPDATE ledger_revision SET n=n+1 WHERE tbl='seed_pack_history';
+END;
+CREATE TRIGGER rev_seed_pack_history_delete AFTER DELETE ON seed_pack_history BEGIN
+ UPDATE ledger_revision SET n=n+1 WHERE tbl='seed_pack_history';
+END;
diff --git a/scripts/import_windows_media_tools.ps1 b/scripts/import_windows_media_tools.ps1
index f3a703ba7..d7fc398c8 100644
--- a/scripts/import_windows_media_tools.ps1
+++ b/scripts/import_windows_media_tools.ps1
@@ -54,7 +54,7 @@ if ($Roots.Count -eq 0) {
"$env:ProgramData\scoop\apps\ffmpeg\current",
"$env:ProgramData\chocolatey\lib\ffmpeg",
"$env:ProgramData\chocolatey\lib\ffmpeg-full",
- "$env:ProgramFiles\ffmpeg", "$env:LOCALAPPDATA\Programs\ffmpeg", 'C:\ffmpeg',
+ "$env:ProgramFiles\ffmpeg", "$env:LOCALAPPDATA\Programs\ffmpeg", 'C:\ffmpeg', 'C:\FF',
"$env:USERPROFILE\Downloads"
)
foreach ($ToolName in @('ffmpeg.exe', 'ffprobe.exe', 'untrunc.exe')) {
diff --git a/scripts/seed_pack.py b/scripts/seed_pack.py
index 293e6b171..177b46298 100644
--- a/scripts/seed_pack.py
+++ b/scripts/seed_pack.py
@@ -77,8 +77,8 @@ def export(args: argparse.Namespace) -> int:
# 版本串按字典序比:ISO 日期加 `.n` 后缀在同一天十次以内单调;缺省的当天日期退不回已发过的 `.1`。
if changed and current is not None and pack["version"] <= current:
print(json.dumps({**summary, "written": False,
- "error": f"内容变了而版本串 {pack['version']} 不比文件里的 {current} 新:导入以"
- " seed-import:<版本> 判有没有导过,导过旧内容的机器会跳过这份新内容;换一个新版本串再导"},
+ "error": f"种子版本 {pack['version']} 必须比现有文件的 {current} 新:永久导入历史"
+ "拒绝同版本的不同内容;换一个新版本串再导"},
ensure_ascii=False))
return 2
if changed:
diff --git a/tests/test_media_tool_import.py b/tests/test_media_tool_import.py
index e3f3b1d83..23fc5b0f2 100644
--- a/tests/test_media_tool_import.py
+++ b/tests/test_media_tool_import.py
@@ -30,7 +30,7 @@ class MediaToolImportTests(unittest.TestCase):
result = subprocess.run([PWSH, "-NoProfile", "-File",
str(ROOT / "scripts/import_windows_media_tools.ps1"),
"-DataRoot", str(data), "-SearchRoots", str(root / "WinGet")],
- capture_output=True, text=True, timeout=30)
+ capture_output=True, text=True, encoding="utf-8", timeout=30)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
for name in ("ffmpeg.exe", "ffprobe.exe", "avcodec.dll"):
self.assertEqual((target / name).read_bytes(), (installed / name).read_bytes())
@@ -46,7 +46,7 @@ class MediaToolImportTests(unittest.TestCase):
result = subprocess.run([PWSH, "-NoProfile", "-File",
str(ROOT / "scripts/import_windows_media_tools.ps1"),
"-DataRoot", str(root), "-SearchRoots", str(root)],
- capture_output=True, text=True, timeout=30)
+ capture_output=True, text=True, encoding="utf-8", timeout=30)
self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
self.assertIn("NOT FOUND", result.stdout)
self.assertEqual((root / "ledger.db").read_bytes(), b"kept")
diff --git a/tests/test_migrations.py b/tests/test_migrations.py
index 94d79d297..5b6c03d2a 100644
--- a/tests/test_migrations.py
+++ b/tests/test_migrations.py
@@ -24,7 +24,7 @@ class MigrationTests(unittest.TestCase):
connection.execute("INSERT INTO asset(id,location,path,medium,disposal) VALUES(1,'local','sample.mp4','video','trash')")
connection.execute("INSERT INTO asset_tag(asset_id,tag,source) VALUES(1,'示例','user')")
connection.commit()
- self.assertEqual([migration.version for migration in upgrade(self.db, MIGRATIONS)], ['0046'])
+ self.assertEqual([migration.version for migration in upgrade(self.db, MIGRATIONS)], ['0046', '0047'])
self.assertEqual(connection.execute("SELECT disposal,disposal_reason FROM asset WHERE id=1").fetchone(), ('trash', None))
self.assertEqual(connection.execute("SELECT tag,source FROM asset_tag WHERE asset_id=1").fetchall(), [('示例', 'user')])
self.assertEqual(connection.execute("SELECT count(*) FROM asset").fetchone()[0], 1)
@@ -43,7 +43,7 @@ class MigrationTests(unittest.TestCase):
sqlite3.connect(self.db).close()
backup = self.root / "before.db"
done = upgrade(self.db, MIGRATIONS, backup)
- self.assertEqual([m.version for m in done], [f'{number:04d}' for number in range(47)])
+ self.assertEqual([m.version for m in done], [f'{number:04d}' for number in range(48)])
self.assertTrue(backup.exists())
con = sqlite3.connect(self.db)
tables = {row[0] for row in con.execute(
@@ -60,8 +60,8 @@ class MigrationTests(unittest.TestCase):
"playlist", "playlist_item",
"asset_tag_preference", "asset_search", "follow_playback",
"genre_decision", "asset_subtitle", "task_run", "performer_profile", "code_sample_image",
- "entity_classification", "entity_identity_link", "schema_migration"} <= tables)
- self.assertEqual(versions, [f'{number:04d}' for number in range(47)])
+ "entity_classification", "entity_identity_link", "seed_pack_history", "schema_migration"} <= tables)
+ self.assertEqual(versions, [f'{number:04d}' for number in range(48)])
self.assertEqual(upgrade(self.db, MIGRATIONS), [])
self.assertEqual(plan(self.db, MIGRATIONS)[1], [])
@@ -341,12 +341,9 @@ class MigrationTests(unittest.TestCase):
base_migrations = self.root / "base-migrations"
base_migrations.mkdir()
for path in sorted(MIGRATIONS.glob("*.sql")):
- # 0024 重建 follow_playback,必须与建表的 0022 一起排除;0038 给每张表挂
- # 版本号触发器、0039 清 follow_playback 的孤儿行、0040 给墓碑表登记版本号、0041 给新表挂
- # 版本号触发器、0042 的想要清单、0043 的下载任务和 0044 的身份表挂版本号触发器,
- # 被排除的迁移建的表这时还不存在,它们也要等到后面一起应用。
- if not path.name.startswith(("0020_", "0021_", "0022_", "0024_", "0038_", "0039_", "0040_",
- "0041_", "0042_", "0043_", "0044_", "0045_")):
+ # 历史基线停在 0037,follow_playback 建表与重建随 0020/0021 统一应用。
+ # 0038 起的版本号触发器依赖这些表,留在后续的完整迁移链中。
+ if path.name < "0038_" and not path.name.startswith(("0020_", "0021_", "0022_", "0024_")):
shutil.copyfile(path, base_migrations / path.name)
sqlite3.connect(self.db).close()
upgrade(self.db, base_migrations)
diff --git a/tests/test_untrunc_build.py b/tests/test_untrunc_build.py
index 5b6c063c6..2fb4b5d5d 100644
--- a/tests/test_untrunc_build.py
+++ b/tests/test_untrunc_build.py
@@ -108,7 +108,7 @@ class UntruncNativeRecoveryTests(unittest.TestCase):
archive = bundle.parent / manifest['source_archive']['name']
self.assertEqual(build.digest(archive), manifest['source_archive']['sha256'])
version = subprocess.run([str(executable), '-V'], check=True, capture_output=True,
- text=True, timeout=15).stdout
+ text=True, encoding='utf-8', timeout=15).stdout
self.assertIn(manifest['version'], version)
self.assertIn("ffmpeg '8.1.3'", version)