fix(product-suite): validate item id before generation

This commit is contained in:
chengma
2026-07-22 18:14:50 +08:00
parent 189b5855e9
commit 01b4a05c26
8 changed files with 129 additions and 45 deletions
+7 -2
View File
@@ -3,7 +3,7 @@ id: T-690
title: 商品套图统一商品ID校验与生成前提交
phase: 7
deps: [T-688, T-689]
status: TODO
status: DONE
created: 2026-07-22
---
@@ -52,4 +52,9 @@ created: 2026-07-22
## 执行记录
- 待实现。
- 2026-07-22 完成。
- `app/image_studio.py` 新增 `normalize_item_id_input()`,清除首尾空白和 Unicode 格式控制字符;`is_formal_item_id()` 改为仅接受 ASCII 数字。项目查询、创建和草稿绑定同步使用该规范化逻辑,避免不可见字符形成不同项目键。
- `ProductSuiteTab` 的商品ID输入框增加数字 validator,并抽出 `_commit_item_id()` 作为唯一提交入口。失焦、添加本地原图、拉取蝦皮主图和开始生成都会先规范化、校验、处理草稿绑定或商品切换确认;`_save_controls_to_state()` 不再直接覆写 `state.item_id`,因此非法输入不会污染已绑定项目上下文。
- 已绑定商品ID未变时,点击生成会继续原流程且不重复弹出切换确认;零宽格式字符会被自动清除。非数字、切换取消、项目冲突或绑定失败均保留已提交商品ID与项目,不创建 worker 或 job。
- 已同步 `docs/04-architecture.md`、`docs/routes.md`、`docs/api.md`。新增服务层测试覆盖格式字符和 ASCII 数字判定,新增 GUI 测试覆盖已绑定项目的零宽字符规范化、非法生成入口阻断与取消切换恢复。
- 验证通过:`py -3.10 -m unittest tests.test_image_studio tests.test_product_suite tests.test_product_suite_gui`(107项)、`py -3.10 -m unittest discover -s tests`(674项)、`py -3.10 -m ruff check app tests main.py`、`py -3.10 -m compileall app main.py`、`git diff --check`。离屏 PySide6 有字体目录/插件告警,但无测试失败。