Skip to content

test: fix spa_catchall blog fixtures to match #31 regex (green CI)#32

Merged
study8677 merged 1 commit into
mainfrom
fix/ci-blog-fixtures
May 22, 2026
Merged

test: fix spa_catchall blog fixtures to match #31 regex (green CI)#32
study8677 merged 1 commit into
mainfrom
fix/ci-blog-fixtures

Conversation

@study8677
Copy link
Copy Markdown
Owner

Problem

main CI is red. PR #31 (homepage white-screen fix) 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 <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_metadata
  • test_spa_catchall_zh_blog_route_injects_localized_metadata

Fix

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).

…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 study8677 merged commit 5139305 into main May 22, 2026
Copy link
Copy Markdown
Owner Author

@study8677 study8677 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

总体评价

这是一个精准的单文件测试修复 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant