Skip to content

ci: build the site with pnpm run build and add a unit-test entrypoint - #740

Open
markd3ng wants to merge 2 commits into
CuteLeaf:masterfrom
markd3ng:ff/toolchain-ci
Open

markd3ng wants to merge 2 commits into
CuteLeaf:masterfrom
markd3ng:ff/toolchain-ci

Conversation

@markd3ng

@markd3ng markd3ng commented Nov 29, 2026 •

Copy link
Copy Markdown

Finding IDs: FF-6, FF-12.

问题

1. CI 构建的和发布的不是同一条链路。 build.yml 的构建任务跑 pnpm astro build,而实际部署的 deploy.yml 跑 pnpm run build。后者的 build 脚本还包含 GitHub 卡片数据、LQIP、VNDB 封面、astro build --force、PIO 资源裁剪、字体子集化、内联脚本压缩与 Pagefind 索引。CI 因此只覆盖了链路的第一段:scripts/ 里的任何一步在生产构建里报错,或产物(字体子集、pagefind 索引、裁剪后的 PIO 资源)发生变化,CI 全绿也发现不了。

2. 仓库没有单元测试入口。 唯一可运行的测试是 pnpm test:code-groups(Playwright),而 playwright.config.ts:7-8 把 testDir 与 testMatch 限定为 src/components/features/CodeGroupManager.spec.ts 一个文件;src/utils 下大量纯函数(日期、URL、schema、feed 等)没有任何回归测试,往 src/ 任意位置放 *.test.ts 也不会被执行。

变更

  • .github/workflows/build.yml:构建步骤改为 pnpm run build,与部署命令对齐;步骤名相应改为 Run Site Build。
  • .github/workflows/build.yml:构建任务在装完依赖后新增 pnpm test:unit 步骤(Node 22 / 24 两个矩阵都跑)。
  • package.json:新增 "test:unit": "node --import tsx --test \"src/**/*.test.ts\"",复用仓库已有的 tsx 依赖,不引入新依赖、不改 Playwright 配置(Playwright 的 testMatch 保持只跑那个 spec,否则会把 node:test 文件当成 Playwright 用例)。
  • src/utils/date-utils.test.ts:首个单元测试,用 node:test + node:assert/strict,只断言与运行时区无关的分支,保证 CI 结果稳定:
    • isDateOnly:"2026-11-29" / 带空格同串为纯日期,"2026-11-29T08:00:00+08:00" 与 2026-11-29T00:00:01Z 不是;
    • formatDateToYYYYMMDD:纯日期输入不随运行时区倒退一天,空串与非法日期返回空串;
    • formatDynamicDate:纯日期补 00:00:00,带时刻的值按 UTC 输出,空串返回空串;
    • formatTimezoneOffset:GMT+08:00 → UTC+8、GMT+05:30 → UTC+5:30(去掉前导零、保留半小时偏移)。

验证

  • pnpm test:unit:tests 6 / suites 4 / pass 6 / fail 0,耗时约 0.35s。
  • pnpm run check(astro check):Result (264 files): - 0 errors - 0 warnings - 0 hints。
  • pnpm run type-check(tsc --noEmit --isolatedDeclarations):无报错。
  • pnpm run build 全链路本地跑通:Pagefind Indexed 18 pages / 5211 words,Finished in 0.147 seconds,构建结束后工作区除本 PR 的三处改动外无产物文件被改写(src/constants/github-card-data.json 未变动)。
  • pnpm exec biome check ./src:仅仓库既有的 biome.json schema 2.6.3 与 CLI 2.6.8 版本提示。

需要留意的是:构建任务现在会执行需要访问外部接口的脚本(GitHub API、VNDB)。这些脚本对失败是宽容的——单个仓库拉取失败会回落到已缓存数据并打印 [GITHUB-CARD] Failed to refresh ...,VNDB 封面失败也只 console.warn,因此不会把 CI 变红,只是相应数据保持上一次的值。

Sourcery 摘要

在 CI 中验证完整的生产构建,并添加可复用的单元测试入口,初步覆盖日期工具函数。

新功能:

  • 添加基于 Node 的单元测试入口,用于运行 src 下的 TypeScript 测试。
  • 添加回归测试,覆盖日期解析、格式化和时区工具函数。

改进:

  • 使 CI 中的网站构建与生产构建命令保持一致,以验证完整的构建流程。
  • 在 CI 矩阵中先运行单元测试,再构建网站。

CI:

  • 更新构建工作流,使其在受支持的 Node 版本上运行单元测试和 pnpm run build。

测试:

  • 添加六个单元测试,覆盖日期工具函数的行为和时区格式化。
Original summary in English

Sourcery 总结

在 CI 中验证生产构建,并建立可复用的单元测试工作流,初步覆盖日期工具函数。

新功能:

  • 为 src 下的 TypeScript 测试添加可复用的基于 Node 的单元测试入口。
  • 添加回归测试,覆盖日期解析、格式化和时区工具函数。

改进:

  • 统一 CI 中的网站构建与生产构建命令,以验证完整的构建流程。

CI:

  • 在 CI 中,针对受支持的 Node.js 版本矩阵运行单元测试和完整的网站构建。

文档:

  • 更新测试指南,说明 Node 单元测试工作流。

测试:

  • 添加六个单元测试,覆盖日期工具函数的行为和时区格式化。
Original summary in English

Summary by Sourcery

Validate the production build in CI and establish a reusable unit-testing workflow with initial date utility coverage.

New Features:

  • Add a reusable Node-based unit-test entry point for TypeScript tests under src.
  • Add regression coverage for date parsing, formatting, and timezone utilities.

Enhancements:

  • Align CI site builds with the production build command so the complete build pipeline is validated.

CI:

  • Run unit tests and the full site build across the supported Node.js matrix in CI.

Documentation:

  • Update testing guidelines to document the Node unit-test workflow.

Tests:

  • Add six unit tests covering date utility behavior and timezone formatting.

- build.yml 的构建步骤改为 pnpm run build,与 deploy.yml 的部署命令一致,
  避免 CI 校验的产物与实际发布的产物不是同一条链路
- 新增 pnpm test:unit(node --import tsx --test "src/**/*.test.ts")作为单元测试入口,
  并在 CI 构建任务里执行;playwright 的 testDir/testMatch 仍限定 CodeGroupManager.spec.ts,
  单元测试不会被它发现,因此需要独立入口
- 首个单测覆盖 date-utils 的纯日期判定、YYYY-MM-DD 格式化守卫、动态日期与偏移量归一化
@netlify

netlify Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

👷 Deploy request for demo-firefly pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit a51ceaa

@sourcery-ai

sourcery-ai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

审阅者指南

配置

添加单元测试脚本,并更新 CI,使其在完整生产构建之前运行该脚本。

  • .github/workflows/build.yml L66-70
  • package.json L25-26

文档

更新测试指南,说明新的基于 Node 的单元测试入口。

  • AGENTS.md L26

测试

添加回归测试,覆盖仅日期检测、日期格式化和时区偏移规范化。

  • src/utils/date-utils.test.ts L1-52

提示和命令

与 Sourcery 交互

  • 触发新的审阅: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 根据审阅评论创建 GitHub issue: 回复审阅评论,请 Sourcery 根据该评论创建 issue。你也可以回复审阅评论并输入 @sourcery-ai issue,以此创建 issue。
  • 生成拉取请求标题: 随时在拉取请求标题中的任意位置输入 @sourcery-ai,即可生成标题。你也可以在拉取请求中评论 @sourcery-ai title,随时生成或重新生成标题。
  • 生成拉取请求摘要: 随时在拉取请求正文中你希望显示摘要的位置输入 @sourcery-ai summary,即可生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,随时生成或重新生成摘要。
  • 生成审阅者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时生成或重新生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已处理完所有评论且不想再看到它们,这会很有用。
  • 隐藏所有 Sourcery 审阅: 在拉取请求中评论 @sourcery-ai dismiss,即可隐藏所有现有的 Sourcery 审阅。如果你想从头开始进行新的审阅,这尤其有用——别忘了评论 @sourcery-ai review 来触发新的审阅!

自定义使用体验

访问你的控制面板,以便:

  • 启用或禁用审阅功能,例如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Configuration

Add the unit-test script and update CI to run it before the full production build.

  • .github/workflows/build.yml L66-70
  • package.json L25-26

Documentation

Update testing guidance to document the new Node-based unit-test entrypoint.

  • AGENTS.md L26

Tests

Add regression tests for date-only detection, date formatting, and timezone-offset normalization.

  • src/utils/date-utils.test.ts L1-52

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

嗨,我发现了 2 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".github/workflows/build.yml" line_range="70" />
<code_context>
+        run: pnpm test:unit
+
+      - name: Run Site Build
+        run: pnpm run build

       - name: Install Chromium for code group tests
</code_context>
<issue_to_address>
**VNDB outages block CI builds**

When VNDB is enabled in static mode and its API is unavailable or stalls, `pnpm run build` runs `generate-vndb-covers.ts` before Astro; its VNDB list request has no timeout or catch, so a stalled request hangs the build and a failed request aborts it before site generation.

Add a timeout and handle VNDB list-fetch failures so the build can use cached data or skip cover generation.
</issue_to_address>

### Comment 2
<location path="package.json" line_range="26" />
<code_context>
     "github-cards": "npx tsx scripts/generate-github-card-data.ts",
-    "test:code-groups": "playwright test"
+    "test:code-groups": "playwright test",
+    "test:unit": "node --import tsx --test \"src/**/*.test.ts\""
   },
   "dependencies": {
</code_context>
<issue_to_address>
**Unit tests are now configured**

When the new unit-test script is present and CI runs it, `test:unit` invokes Node’s `node:test` runner, and CI executes that script, so the repository no longer matches the entry’s stated absence of a configured unit-test framework.

Update or remove the knowledge-base entry to reflect the configured Node test runner.
</issue_to_address>

Sourcery 评估

等待批准。 请先处理 1 项发现。

阻塞性发现:.github/workflows/build.yml:70


Sourcery 对开源项目免费——如果您喜欢我们的评审,请考虑分享 ✨
Original comment in English

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".github/workflows/build.yml" line_range="70" />
<code_context>
+        run: pnpm test:unit
+
+      - name: Run Site Build
+        run: pnpm run build

       - name: Install Chromium for code group tests
</code_context>
<issue_to_address>
**VNDB outages block CI builds**

When VNDB is enabled in static mode and its API is unavailable or stalls, `pnpm run build` runs `generate-vndb-covers.ts` before Astro; its VNDB list request has no timeout or catch, so a stalled request hangs the build and a failed request aborts it before site generation.

Add a timeout and handle VNDB list-fetch failures so the build can use cached data or skip cover generation.
</issue_to_address>

### Comment 2
<location path="package.json" line_range="26" />
<code_context>
     "github-cards": "npx tsx scripts/generate-github-card-data.ts",
-    "test:code-groups": "playwright test"
+    "test:code-groups": "playwright test",
+    "test:unit": "node --import tsx --test \"src/**/*.test.ts\""
   },
   "dependencies": {
</code_context>
<issue_to_address>
**Unit tests are now configured**

When the new unit-test script is present and CI runs it, `test:unit` invokes Node’s `node:test` runner, and CI executes that script, so the repository no longer matches the entry’s stated absence of a configured unit-test framework.

Update or remove the knowledge-base entry to reflect the configured Node test runner.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: .github/workflows/build.yml:70


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

run: pnpm test:unit

- name: Run Site Build
run: pnpm run build

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 中 · VNDB 故障会阻塞 CI 构建

当静态模式启用了 VNDB,而其 API 不可用或响应停滞时,pnpm run build 会在运行 Astro 之前执行 generate-vndb-covers.ts;其中的 VNDB 列表请求没有超时设置或错误捕获,因此请求停滞会导致构建挂起,请求失败则会在生成站点之前中止构建。

请添加超时并处理 VNDB 列表获取失败的情况,以便构建可以使用缓存数据或跳过封面生成。

面向 AI 智能体的提示
在 `.github/workflows/build.yml` 第 70 行:

**VNDB 故障会阻塞 CI 构建**

当静态模式启用了 VNDB,而其 API 不可用或响应停滞时,`pnpm run build` 会在运行 Astro 之前执行 `generate-vndb-covers.ts`;其中的 VNDB 列表请求没有超时设置或错误捕获,因此请求停滞会导致构建挂起,请求失败则会在生成站点之前中止构建。

请添加超时并处理 VNDB 列表获取失败的情况,以便构建可以使用缓存数据或跳过封面生成。
Original comment in English

🟡 Medium · VNDB outages block CI builds

When VNDB is enabled in static mode and its API is unavailable or stalls, pnpm run build runs generate-vndb-covers.ts before Astro; its VNDB list request has no timeout or catch, so a stalled request hangs the build and a failed request aborts it before site generation.

Add a timeout and handle VNDB list-fetch failures so the build can use cached data or skip cover generation.

Prompt for AI agents
In `.github/workflows/build.yml` at line 70:

**VNDB outages block CI builds**

When VNDB is enabled in static mode and its API is unavailable or stalls, `pnpm run build` runs `generate-vndb-covers.ts` before Astro; its VNDB list request has no timeout or catch, so a stalled request hangs the build and a failed request aborts it before site generation.

Add a timeout and handle VNDB list-fetch failures so the build can use cached data or skip cover generation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

已核对本 PR 的提交 a51ceaa894:它只把 pnpm test:unit 接入 .github/workflows/build.yml,并在 AGENTS.md 记录该命令;没有引入 VNDB 配置或缺省超时。你指出的 fetch 无 timeout、异常直接向上传播属于既有 external-data 行为,不在 FF-6/FF-12 的范围内;在本 PR 中一并修改会混合关注点。该 thread 保留给 maintainer 决定是否另开修复,暂不 resolve。

Comment thread package.json Resolved
- AGENTS.md no longer claims there is no unit-test framework.

This branch has not been deployed

No deployments
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