Skip to content

test(session-usage): 多帧反证改数帧头,不再依赖 Node 的 zstd 整块解语义 - #490

Merged
modusensus merged 1 commit into
mainfrom
fix/legacy-zstd-assertion
Oct 19, 2026
Merged

modusensus merged 1 commit into
mainfrom
fix/legacy-zstd-assertion

Conversation

@modusensus

Copy link
Copy Markdown
Collaborator

背景

test/session-usage.test.js:68 的反证断言 zlib.zstdDecompressSync(buf) 只能拿到第一帧,依赖的是 Node 的「整块解只吐第一帧」旧行为。

Node 24.22.0 起解码跨 chunk 边界也能解出所有帧(nodejs/node#65865),这条断言随之过期。CI 的 legacy 腿装 latest 24.x,所以 main 下次 runner 升到 24.22.0 就会红。

产品代码 src/session-usage.js 的 forEachFrame 自己逐帧解,不受影响。

改动

改成数 zstd magic 帧头,不绑定解码器语义:

  • 既与产品代码 forEachFrame 的切帧判据同源(它也是用 indexOf(ZSTD_MAGIC) 找帧界),把「夹具形状 = 代码假设」一并锁住;
  • 第二行断言用 stat.frames + stat.failed:帧头数 = 成功数 + 失败数 是实现契约,而「帧头数 = 成功数」只在 failed 恒为 0 时成立,是巧合不是规矩。

已知局限(写进注释,不谎报覆盖)

这条锁的是「切帧判据仍是 magic」,不是碰撞免疫。payload 里撞上 28 b5 2f fd 时,计数器与解码器会一起错(半片也解得出来),实测 frames 同样变成 4,这条测不出来。真要堵得在 magic 后再验帧头描述符,另属一条车道。

验证

  • npm run sync:74 文件,无额外 diff
  • npm test:2257 tests / 2256 pass / 0 fail / 1 skip
  • 提交署名 modusensus <guanqishi26@gmail.com>,无 AI 署名

原反证断言 zstdDecompressSync(buf) 只能拿到第一帧,依赖的是「整块解只吐第一帧」这一
Node 旧行为。24.22.0 起解码跨 chunk 边界也能解出所有帧(nodejs/node#65865),断言在
legacy 腿(装 latest 24.x)上过期,main 下次 runner 升到 24.22.0 就会红。

改成数 zstd magic 帧头:既与产品代码 orEachFrame 的切帧判据同源,又不绑定解码器语义。
第二行断言用 stat.frames + stat.failed——帧头数 = 成功数 + 失败数 是实现契约,而
「帧头数 = 成功数」只在 failed 恒为 0 时成立,是巧合不是规矩。

已知局限写进注释:这条锁的是「切帧判据仍是 magic」,不是碰撞免疫。payload 里撞上
magic 时计数器与解码器会一起错(半片也解得出来),实测 frames 同样变成 4,这条测不出来。
Copilot AI lite review requested due to automatic review settings October 19, 2026 17:48

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.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@modusensus
modusensus merged commit 15ef630 into main Oct 19, 2026
10 checks passed
@modusensus
modusensus deleted the fix/legacy-zstd-assertion branch October 19, 2026 17:55
@modusensus modusensus mentioned this pull request Oct 19, 2026
andimial pushed a commit to andimial/mneme that referenced this pull request Oct 20, 2026
- CHANGELOG 0.9.3:把 [Unreleased] 攒的 7 条搬入新版本节,并补 slow-stack#487 / slow-stack#489 评审 / slow-stack#490 三条此前未登记的修复

- 双 README 版本表填 v0.9.3 主题描述;根 README 中英 News 表各加 v0.9.3 头条

- 根 README 路线图状态格跟到 v0.9.3

- 版本号 0.9.2 -> 0.9.3(package.json + package-lock.json)

- 测试徽章 2230 -> 2257(本地全量 npm test:tests 2257 / pass 2256 / fail 0 / skip 1)
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