T-566 封面历史归档数据层

This commit is contained in:
chengma
2026-07-09 11:23:18 +08:00
parent fa27134f7c
commit 71e51d0608
6 changed files with 354 additions and 12 deletions
+17 -2
View File
@@ -3,7 +3,7 @@ id: T-566
title: 封面历史归档数据层:重置改名保留旧图 + update_generated_cover + 目录枚举
phase: 7
deps: [T-564]
status: TODO
status: DONE
created: 2026-07-09
---
@@ -84,4 +84,19 @@ created: 2026-07-09
## 执行记录
(做完在这里写:改了什么文件、跑了什么验证命令及结果、遇到的阻塞、关键决策。)
- 2026-07-09 完成 T-566。
- 修改 `app/db.py`:
- `reset_generated(..., reset_cover=True)` 在清空 DB 指针前先把当前 `new_cover_path` 指向的本地文件改名归档为 `{stem}_YYYYMMDDHHMMSS{ext}`;同秒撞名追加 `_2/_3`;旧 `delete_file=True` 不再物理删除,归档取代删除,返回结果新增 `archived_file`,保留 `deleted_file=None` 兼容旧调用。
- 文件不存在时幂等跳过归档;`PermissionError` 抛中文 `DbError` 并保持 DB 指针不变。
- 新增 `update_generated_cover(task_id, new_cover_path)`,只切换当前生效封面指针,写入后退回 `generated/pending`,不增加 attempts,不清 `committed/applied_at/apply_attempts/image_task_id/image_task_key`。
- 修改 `app/image_paths.py`:新增 `list_task_cover_candidates(image_root, task, account=None)`,只读扫描任务目录下 `_new*.jpg` 候选,返回绝对路径,排序为规范名优先、归档时间倒序、同秒后缀数字倒序、异常文件名最后。
- 修改测试:
- `tests/test_db.py` 覆盖归档撞名、文件锁失败 DB 不变、缺失文件幂等、`update_generated_cover` 状态语义、运行中拒绝切换、批次软删除不删图片目录。
- `tests/test_image_paths.py` 覆盖候选图过滤和稳定排序。
- `tests/test_gui.py` 同步重置后本地文件“归档保留而非原名保留”的新语义。
- 验证通过:
- `py -3.10 -m unittest tests.test_db tests.test_image_paths`
- `python -m ruff check app tests main.py`
- `py -3.10 -m compileall app main.py`
- `py -3.10 -m unittest discover -s tests`(285 tests;PySide6 字体目录警告不影响结果)
- `git diff --check`