Repository navigation
test(usage): 补账用例按日期顺序读取账本文件,不再依赖目录列举顺序 - #3616
Merged
Merged
Conversation
用例按 readdirSync 的返回顺序拼接两天的账本文件再断言记录顺序。Node 返回按名 排序的结果,Bun 返回文件系统原始顺序(ext4 哈希序、tmpfs 后建在前),所以 bun-test 上时红时绿。读取后按文件名(UTC 日期)排序。生产代码读账本目录本就 排序,不受影响。 Closes #3615 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 19, 2026 11:28
deepcoldy
commented
Nov 19, 2026
deepcoldy
left a comment
Owner
Author
There was a problem hiding this comment.
复审结论(head 4a6a2120b098eaca2838306c8aee74b1b2f73fb5)
可合并,0 阻断;维持 1 条非阻断 P3。 本 head 仅改 test/usage-ledger.test.ts(+3/-1),不改生产代码。test/usage-ledger.test.ts:747-750 在拼接按 UTC 日期命名的账本文件前先按文件名排序,消除了断言对 readdirSync 返回顺序的依赖,也与 src/services/usage-ledger.ts:206-210 的既有生产读取顺序一致。
非阻断 P3:守卫尚缺确定性的仓内回归用例
test/usage-ledger.test.ts:749 的 .sort() 仍主要依赖 tmpfs 等目录顺序来验证:在目录项本就有序的 runner 上,误删 .sort() 不一定咬红。本次外部变异复验证明它确实修掉已报告的 flake,但仓内没有显式注入逆序目录项的确定性用例。此项属于后续测试加强,不阻断本 PR。
本次实际验证
- 远端 head 已核对为
4a6a2120b098eaca2838306c8aee74b1b2f73fb5;本地 rebase 提交7f18f3b86a51a6588b8d47bcef7e5db2bbc4416b与其 stable patch-id 相同,且该测试文件逐字一致。 bun run test test/usage-ledger.test.ts:38/38 通过。bun test test/usage-ledger.test.ts:38/38 通过。- 修复后在 tmpfs 上跑 Bun 3 次:3/3 均为 38 pass / 0 fail。
- 变异摘掉
.sort()后在 tmpfs 上跑 Bun 3 次:3/3 均由目标用例咬红,37 pass / 1 fail;随后已恢复守卫并确认工作树无残留改动。 git diff --check:通过。
deepcoldy
pushed a commit
that referenced
this pull request
Nov 19, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚀 Released in v3.59.22 |
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.
改了什么
test/usage-ledger.test.ts「keeps recovered events on their original dates and models and does not replay twice」读取账本文件列表后按文件名排序,再拼接内容断言记录顺序。为什么
用例原来按
readdirSync的返回顺序拼接usage-2026-01-01.jsonl与usage-2026-01-02.jsonl。Node 的readdirSync返回按名排序的结果,Bun 返回文件系统原始顺序(ext4 为哈希序、随文件系统而变;tmpfs 为后建在前),所以这条用例只在部分 bun-test runner 上红(PR #3609 的 bun-test (4/4),run 44499294180:2026-01-02一行排到了最前)。生产代码
baselineFromLedger读账本目录后本就.sort(),usage-analytics同样排序,budget-tracker只做求和,都不依赖目录顺序——只改测试。Closes #3615
影响面
只改一条测试的读取顺序,不涉及 src。
测试验证
确定性复现:让测试临时目录落在 tmpfs 上(
/dev/shm,目录顺序为后建在前,对应 CI 的失败形态)。🤖 Generated with Claude Code