Repository navigation
fix(411): 回收的两张皮收口到一份口径 - #413
Merged
Merged
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (13)
✨ Finishing Touches
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. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
modusensus
force-pushed
the
fix/411-reclaim-unify
branch
from
October 12, 2026 10:42
b92058e to
8db7d95
Compare
面板路由 /api/dsh-mneme/maintenance/reclaim 与 Bearer 数据面 POST /maintenance/reclaim 底下是同一份 src/maintenance.js,但 HTTP 外壳一直是 整段复制的。于是 #410 修好面板侧之后,数据面还停在旧形态:窗口没有上界 (1e20 也是整数,maintenance 拿它算 now() - days * 86400000 再 toISOString() 抛 RangeError——而它发生在 readBody 的回调里,外层 try 那时已经退栈,调用方 拿到的是一个字节都没回,不是 500),确认门里那份 dry-run 报告同样没兜错。 口径(错误码字符串、默认值、报告形状、窗口上界、确认提示、warn 文案)现在只 写在新的 src/reclaim-http.js 里,两个入口都调 parseReclaimQuery / parseReclaimJson / readReclaimFields / reclaimReply,各自只留鉴权与路径。 顺序也是契约的一部分:invalid-json → invalid-body → 503 maintenance-unavailable → 字段校验。端点整个没接线时报「窗口不合法」是误导 (调用方会去改窗口,改完照样 503),两侧都补了锁钉住这个先后。 防复发不靠注释(段头那句「改这里时那边一起改」正是漂移发生的地方),靠 test/reclaim-http.test.js 的静态锁:六个字面量在 src/api.js 与 src/api-standalone.js 里一个都不许出现,同时两个文件必须真的 import 共用模块 并调用它——光删字面量不接线等于把功能删了。 新增测试 14 条。11 条变异逐条打回坏状态全部转红。 Refs #411
modusensus
force-pushed
the
fix/411-reclaim-unify
branch
from
October 12, 2026 10:46
8db7d95 to
2001b3c
Compare
Merged
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.
背景
#410把面板路由/api/dsh-mneme/maintenance/reclaim的窗口上界与确认门兜错修好了,但数据面POST /maintenance/reclaim还停在旧形态 —— 因为这两张皮一直是整段复制的。段头那句注释「改这里时那边一起改」没能拦住任何事,它正是漂移发生的地方。Closes #411
改了什么
口径只有一份实现,放在新的
src/reclaim-http.js:MAX_RECLAIM_WINDOW_DAYS = 3650llmAudit.retentionDays/recallRetentionDays同线)parseReclaimQuery(raw)?olderThanDays:只收十进制整数字面量,缺省才落默认parseReclaimJson(text)invalid-json与invalid-body是两个错)readReclaimFields(body)vacuum只收布尔、confirm只认真布尔)reclaimReply({...}){status, body};报告不加包装层RECLAIM_UNAVAILABLE/RECLAIM_CONFIRM_HINT/reclaimWarnMessage两个入口各自只剩鉴权与路径不同:
src/api.js净减 64 行、src/api-standalone.js净减 52 行。顺序也是契约:
invalid-json→invalid-body→503 maintenance-unavailable→ 字段校验。端点整个没接线时报「窗口不合法」是误导 —— 调用方会去改窗口,改完照样 503。两侧都补了锁钉住这个先后。防复发:不靠注释,靠静态锁
test/reclaim-http.test.js断言这六个字面量在src/api.js与src/api-standalone.js里一个都不许出现:invalid-older-than-days/invalid-vacuum/confirm-required/maintenance-unavailable/storage reclaim failed/MAX_RECLAIM_WINDOW_DAYS同时反向也锁:两个文件必须真的
import共用模块并调用reclaimReply(/readReclaimFields(—— 光删字面量不接线等于把功能删了。证据
test/reclaim-http.test.js13 +test/maintenance.test.js1 条从数据面自己的端口打真 HTTP)src/与lib/一致(58 个文件)数据面那条测试覆盖:窗口上界(
3651/1e20→ 400、3650→ 200)、确认门报告复述被问的那个窗口、勾了 VACUUM 就真透传(vacuum.ran === true)、没接线时503赢过字段校验。顺手带的
AGENTS.md模块地图加一行(AGENTS.md:3要求「改完结构顺手更新这里」,新模块不登记就是让地图骗人);test/maintenance.test.js里一个挂死:那个「没接线」的实例建在try内、只在断言之后内联关,断言一旦先炸 server 句柄就留着,node --test永不退出(变异检验里实测挂了 26 分钟)。改成try外建、finally里关,同一组测试 26 分钟 → 2 秒。Refs #411
Summary by CodeRabbit