Skip to content

fix(docs): 测试数处处一致——替换规则收拢到共用模块 - #346

Merged
modusensus merged 3 commits into
mainfrom
fix/test-count-sync
Sep 30, 2026
Merged

modusensus merged 3 commits into
mainfrom
fix/test-count-sync

Conversation

@modusensus

@modusensus modusensus commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

问题

双 README 里测试数以五种形状重复出现(1 个 shields.io 徽章 + 4 种开发命令注释,root 双语再多一条)。v0.8.11 发版后徽章跳到 1437,四条注释却留在 1431。

根因不是「忘了改」,而是两条写入路径各存了一份替换规则、形状集合还不一样:

路径 触发 原先覆盖的形状
scripts/release-prep.mjs 自动,每次发版 只有徽章 URL
dsh-mneme/scripts/sync-test-badge.mjs 手动 npm run badge:sync 徽章 + 4 种注释

自动路径只管一半,于是它反倒成了漂移来源——下次发版还会再错一遍。

改动

  • 新增 dsh-mneme/scripts/test-count-sync.mjs:把形状集合与 applyTestCount / readTestCounts 收在一处,两条路径共用
  • release-prep.mjs 与 sync-test-badge.mjs 改为调用它(后者逻辑不变,只是不再自带一份正则)
  • 把计数刷到本 PR 合并后的真实值 1441(原先徽章 1437 / 注释 1431 混用):本 PR 自己新增 4 条测试,不跟着刷就又是一处「说明落后于现实」
  • 新增 test/test-count-sync.test.js 四条:直接断言双 README 的徽章与注释同数(跑在真实文件上,就是这次漂移的回归锁)、覆盖全部五种形状、幂等、以及不碰历史版本表里的「N 测试全绿」

验证

A/B 复现 —— 拿「徽章 1437 / 注释 1431」的真实漂移态跑 release-prep 9.9.9 1437:

结果
修复前 徽章=1437 / 注释=1431 ❌ 连一行输出都没有,静默放过,README 仍不一致
修复后 ✓ README.md 测试数 → 1437 / ✓ dsh-mneme/README.md 测试数 → 1437,两处全部一致

变异检验(确认用例不是空转):

  • 把 root README 注释改回 1431 → 一致性用例变红,并精确报出 badge=1437 / comment-cjk=1431
  • 把徽章正则改坏 → 一致性用例与形状用例同时变红

工具端到端:用仓库自己的 npm run badge:sync 刷计数,输出 tests=1441, files changed=2,两个 README 的六处出现一次对齐——这也验证了重构后的 sync-test-badge.mjs 行为不变。

测试 1441 项:1440 通过 / 0 失败 / 1 跳过。check-sync 通过。

与另外两条 PR 的合并关系

本 PR 与 #344(宿主 0.2 对齐)、#345(brace-expansion 钉版本)是三个独立改动,故分开提。已本地试合并验证三者互不冲突(git merge 全部自动合并,无冲突;#344+#345 合并后还实测了 npm ci + npm test 全绿)。

Summary by CodeRabbit

  • 文档
    • README 中的测试徽章及中英文本地开发说明中的测试数量已更新为 1441。
    • README 中展示的源码结构说明与开发命令相关测试数量现已保持一致。

双 README 里测试数以五种形状重复出现(1 个 shields.io 徽章 + 4 种开发命令注释,
root 双语再多一条)。v0.8.11 发版后徽章跳到 1437,四条注释却留在 1431。

根因不是「忘了改」,而是两条写入路径各存了一份替换规则、形状集合还不一样:
  - scripts/release-prep.mjs(Release Prep 工作流,自动,每次发版都跑)
  - dsh-mneme/scripts/sync-test-badge.mjs(npm run badge:sync,手动)
前者只 replace 徽章 URL,注释压根不在它的替换范围内——自动路径反倒成了漂移来源,
下次发版还会再错一遍。A/B 实测:拿「徽章 1437 / 注释 1431」的漂移态跑修复前的
release-prep,它静默放过、README 仍不一致;修复后同一场景两处都刷成 1437。

改动:
- 新增 dsh-mneme/scripts/test-count-sync.mjs,把形状集合(徽章 + 4 种注释)连同
  applyTestCount / readTestCounts 收在一处,两条路径共用;
- release-prep.mjs 与 sync-test-badge.mjs 改为调用它(后者逻辑不变,只是不再自带
  一份正则);
- 修正双 README 里四行落后于徽章的注释(1431 → 1437);
- 新增 test/test-count-sync.test.js 四条:直接断言双 README 的徽章与注释同数
  (跑在真实文件上,就是这次漂移的回归锁)、覆盖全部五种形状、幂等、以及不碰
  历史版本表里的「N 测试全绿」。

变异检验:把 root README 注释改回 1431 → 一致性用例变红,并精确报出
badge=1437 / comment-cjk=1431;把徽章正则改坏 → 一致性用例与形状用例同时变红。
两条都如实变红,用例不是空转。

测试 1441 项:1440 通过 / 0 失败 / 1 跳过(原 1437 + 新增 4)。
Copilot AI lite review requested due to automatic review settings September 30, 2026 11:24

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Repository: slow-stack/mneme/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 9167f1b6-1c38-4d87-9387-a3fdc8554f77

📥 Commits

Reviewing files that changed from the base of the PR and between 8214549 and 4ffd849.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: slow-stack/mneme/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 36caebaf-82c3-4ace-8f0f-8e1bcaa62406

📥 Commits

Reviewing files that changed from the base of the PR and between 421bab7 and 8214549.

📒 Files selected for processing (2)
  • README.md
  • dsh-mneme/README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • README.md
  • dsh-mneme/README.md

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

新增共用的测试数量识别与更新逻辑,并将其用于手动同步和发版准备流程。新增测试验证同步规则。两个 README 中列出的测试数量更新为 1441。

Changes

测试数量同步

Layer / File(s) Summary
测试数量匹配与替换
dsh-mneme/scripts/test-count-sync.mjs
新增 applyTestCount 和 readTestCounts,用于处理测试徽章及中英文说明中的测试数量,并排除历史记录。
手动与发版同步
dsh-mneme/scripts/sync-test-badge.mjs、scripts/release-prep.mjs
两个脚本改为调用共用的 applyTestCount。内容变化时,脚本写回 README。
同步规则测试与 README 数量
dsh-mneme/test/test-count-sync.test.js、README.md、dsh-mneme/README.md
新增测试,覆盖 README 数量一致性、漂移修正、幂等性和历史记录保护。两个 README 中列出的测试数量更新为 1441。

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 82145

The change only updates the documented test counts in both READMEs and centralizes the sync logic. No merge-blocking risk was identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (2 skipped: 2 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更:统一两个 README 的测试数,并将替换规则集中到共用模块。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

本 PR 自己新增了 4 条测试(1437 → 1441),不跟着刷就又是一处「说明落后于现实」——
修漂移的那条 PR 反倒制造新的漂移。用仓库自己的工具刷(npm run badge:sync),
6 处出现(2 个徽章 + 4 条注释)一次对齐。

这次调用同时也是重构后端到端的验证:sync-test-badge.mjs 改为调用共用模块
test-count-sync.mjs 之后行为不变(输出 tests=1441, files changed=2,恰好就是
预期的两个 README)。
Copilot AI lite review requested due to automatic review settings September 30, 2026 12:15

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI lite review requested due to automatic review settings September 30, 2026 12:26

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@modusensus
modusensus merged commit f7b7df7 into main Sep 30, 2026
9 checks passed
@modusensus
modusensus deleted the fix/test-count-sync branch September 30, 2026 14:05
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.

2 participants