test: fix spa_catchall blog fixtures to match #31 regex (green CI)#32
Merged
Conversation
…xtures #31 tightened the static-copy regex to require translate="yes" so it matches the real <main id="static-site-copy" translate="yes"> element instead of the bare mention inside the head comment. The two blog-route test fixtures still used the old <main id="static-site-copy"> form, so the regex stopped matching and the static copy was never injected — the two assertions failed in CI. Update both fixtures to the real format. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
study8677
commented
May 22, 2026
Owner
Author
study8677
left a comment
There was a problem hiding this comment.
总体评价
这是一个精准的单文件测试修复 PR,变更最小、目标明确:将两处测试 fixture 中的 <main> 标签补上 translate="yes" 属性,使其与 PR #31 收紧后的正则匹配逻辑保持一致,从而恢复绿色 CI。✅ 已合并,质量符合预期。
问题清单
| 级别 | 文件 & 行号 | 描述 | 建议 |
|---|---|---|---|
| 🟢 优化 | tests/test_web.py L1892 & L1927 |
两个测试函数各自内联了几乎相同的 HTML fixture 字符串(仅 <title> / og:locale 等 meta 有差异)。这次同步需要改两处,未来若正则再调整仍需手动同步,存在漂移风险。 |
考虑提取一个 _make_static_html(title, locale, ...) 辅助函数或 @pytest.fixture,消除 fixture 重复,降低后续维护成本。 |
亮点
- 变更范围极小:仅 2 行改动,零副作用,审查成本极低。
- commit message 清晰:
test: fix spa_catchall blog fixtures to match #31 regex (green CI)直接说明了 why,可追溯上游 PR。 - 快速响应:CI 红了即刻修复,保持了主干可用性。
修改示例(可选优化)
# tests/test_web.py — 提取公共 fixture 构造器
def _static_html(*, locale: str = "en", title: str = "Home", desc: str = "home desc") -> str:
return f"""<!DOCTYPE html>
<html lang="{locale}">
<head>
<title>{title}</title>
<meta property="og:locale" content="{locale}" />
<meta name="description" content="{desc}" />
<meta name="twitter:description" content="{desc}" />
</head>
<body>
<main id="static-site-copy" translate="yes"><h1>{title}</h1></main>
</body>
</html>"""
# 然后两个测试均调用:
# html_content = _static_html()
# html_content = _static_html(locale="zh", title="首页", desc="主页描述")这样下次若需要再调整 <main> 的属性,只需改一处。
Generated by Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
mainCI is red. PR #31 (homepage white-screen fix) tightened the static-copy regex to requiretranslate="yes"so it matches the real<main id="static-site-copy" translate="yes">element instead of the bare<main id="static-site-copy">mentioned inside the head comment (matching the comment swallowed the closing-->+ module<script>→ blank page).The two blog-route test fixtures still used the old
<main id="static-site-copy">form, so the regex no longer matched → static copy not injected → 2 failing tests:test_spa_catchall_blog_route_injects_public_metadatatest_spa_catchall_zh_blog_route_injects_localized_metadataFix
Update both fixtures to the real
translate="yes"format. No production code change.Verified
pytest tests/test_web.py→ 76 passed, 3 skipped (was 2 failed).