fix: 发布前预校验标题长度,超限直接报错避免静默失败
在 _fill_publish_form 填写标题输入框前,使用 calc_title_length 计算标题长度。 超过 20 时立即抛出 TitleTooLongError,由 AI 根据 SKILL.md 指引重新生成标题。
Showing
1 changed file
with
7 additions
and
1 deletions
| @@ -321,7 +321,13 @@ def _fill_publish_form( | @@ -321,7 +321,13 @@ def _fill_publish_form( | ||
| 321 | # 从正文末尾提取 hashtag 并合并到 tags | 321 | # 从正文末尾提取 hashtag 并合并到 tags |
| 322 | content, tags = _extract_hashtags_from_content(content, tags) | 322 | content, tags = _extract_hashtags_from_content(content, tags) |
| 323 | 323 | ||
| 324 | - # 标题 | 324 | + # 标题——填写前先校验长度,超限直接报错(由 AI 重新生成标题) |
| 325 | + from title_utils import calc_title_length | ||
| 326 | + | ||
| 327 | + title_len = calc_title_length(title) | ||
| 328 | + if title_len > 20: | ||
| 329 | + raise TitleTooLongError(str(title_len), "20") | ||
| 330 | + | ||
| 325 | page.input_text(TITLE_INPUT, title) | 331 | page.input_text(TITLE_INPUT, title) |
| 326 | time.sleep(0.5) | 332 | time.sleep(0.5) |
| 327 | _check_title_max_length(page) | 333 | _check_title_max_length(page) |
-
Please register or login to post a comment