Skip to content

Commit 57e7bab

Browse files
committed
fix(panel): 忙碌上报改成同步,刷新不再搭关闭定时器,挂弹层的菜单项一并禁用(#386 第三轮评审)
CodeRabbit 第三轮三条,逐条核过都成立: - 忙碌状态只靠 useEffect 上报,而 effect 要等这次渲染提交后才跑。中间那一拍 父组件的 bootstrapBusy 还是 false,此时点「⋯」照样把弹层卸掉,请求的成功或 失败就再没有地方显示。改成 setBusy(true) 之后同步调 onBusyChange(true)。 - onImported() 排在 900ms 关闭定时器里。切视图会卸载弹层并把 timerRef 清掉, 刷新随之取消——库已经写进去了,列表却还是旧的,而这条路径上用户刚看到 「新建 N 条」,最容易立刻去翻列表。改成同步刷新,只把 onClose 留在定时器。 - 会挂弹层的那五个菜单项在引导请求在飞时仍可点。这些弹层共用同一个绝对定位 锚点,后渲染的会盖住引导弹层那句「新建几条、并入几条」。一律 disabled: bootstrapBusy;两个导出项不挂弹层,照旧可点。 测试侧:把 BootstrapDialog 的切片从「拍脑袋的 3200 字」改成切到下一个弹层的 注释为止——这轮改动静悄悄把窗口撑破,断言于是在一个截断的片段上做,失败信息 还指着「输入框没禁用」这种不存在的毛病。另补三条锁:忙碌必须同步上报、刷新 必须早于关闭定时器、五个菜单项恰好五处 disabled 且导出项一处都没有。 变异自证四条全 KILLED:去掉 share 项的 disabled、去掉同步上报、把 onImported 挪进定时器、把导出项也一起禁用(最后一条是反向断言,应当被抓住)。
1 parent d95edd6 commit 57e7bab

3 files changed

Lines changed: 61 additions & 9 deletions

File tree

‎dsh-mneme/CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
- **顺带发现一处真实的不对称**:`dreamProvider` / `dreamModel` 在 `settings.js` 白名单里,`config.js` 那边却没有 `.default()`,于是面板有输入框、保存也能存,`featureSnapshot()` 的 `if (value !== undefined)` 却把它跳过——留空时它永远不进「当前生效值」。清单把这件事单独列出来,**没有擅自补默认值**:补了会改变「未配置时到底用哪个模型」的既有行为,那是另一个决定。
1111
- **面板**:溢出菜单新增「从目录引导…」(菜单按钮的 onClick 里同步关掉它,否则两个弹层并存——但它现在带一个条件:引导请求在飞时不关,否则等于绕过弹层里那两道 `busy` 禁用的锁);设置页 `connect` 组尾新增「配置键覆盖面」只读卡,默认收起,破折号 chip 一行排开、长键名不截断(这张表的用处就是把 `memoryQualityFilter.archiveThreshold` 这样的名字完整抄进配置文件)。取数失败与「真的没有只读键」分开说——把失败画成 0 条,人会以为清单就是空的。`docs/CONFIGURATION.md` 的读法说明改成指向这张卡,不再逐行标注。
1212
- **评审修掉的七处**(CodeRabbit 第二轮):① 摘要只填三个数时,「其余 {file} 个只能改配置文件」与展开后的清单对不上——`undefaulted`(`dreamProvider` / `dreamModel`)既不在「面板能改」里、也不在「只能改文件」里,现在三类各报一个数、都由服务端算好;② 引导成功路径仍 `setBusy(false)`,900ms 提示期间按钮重新可点,且定时器句柄没人保存、第二次提交的结果会写进已卸载的组件——改成不复位 + 句柄进 `useRef` 并在卸载时 `clearTimeout`;③ 请求在飞时目录输入框仍可改,回来的提示贴在改后的输入框旁却对应上一个目录——`disabled: busy`;④ 「⋯」在请求进行中会把弹层连同在飞的请求一起卸掉,绕过弹层自己那两道锁——父组件持有 `bootstrapBusy`,忙碌时不关;⑤ 引导成功只递增 `reloadKey`,而搜索态走的那条 effect 依赖里没有它,搜索词不变就永远看不到新导入的行——补进依赖;⑥ `bootstrapFromDirectory` 自己又 `dir.trim()` 一次,把协议层「回传原串、交给 fs 报错」的承诺变成了空话(`" /repo "` 被静默读成 `"/repo"`)——只 trim 判空、路径原样交给 `statSync`,并补一条用例锁住「带空格的路径必须报 `dir-not-found`」;⑦ `bootstrapReply` 的 `catch` 里裸调 `warn`,宿主 logger 自己坏掉会从 `catch` 里再抛、请求一个字节都回不去(#410 那类现场)——按 `share-http.js` 的 `warnSafely` 收进层里,而不是在每个调用面上各兜一次。
13+
- **评审修掉的另外三处**(CodeRabbit 第三轮):⑧ 忙碌状态只在 `useEffect` 里上报,而 effect 要等这次渲染提交后才跑——中间那一拍父组件的 `bootstrapBusy` 还是 `false`,此时点「⋯」仍会把弹层卸掉,请求的成功或失败就再没有地方显示,改成 `setBusy(true)` 之后**同步**调 `onBusyChange(true)`;⑨ 刷新(`onImported()`)排在 900ms 关闭定时器里,而切视图会卸载弹层并把 `timerRef` 清掉,刷新随之取消——库已经写进去了、列表却还是旧的,改成同步刷新、只把关闭留在定时器里;⑩ 会挂弹层的那五个菜单项(新建 / 导入 / 引导 / 分享 / 接收)在引导请求在飞时仍可点,这些弹层共用同一个绝对定位锚点,后渲染的会盖住引导弹层那句「新建几条、并入几条」——一律 `disabled: bootstrapBusy`,而两个导出项不挂弹层、照旧可点。
1314
- **顺带**:`src/api-standalone.js` 的 `POST /bootstrap` 原本自己重复了一遍 `JSON.parse` + 三段校验 + `.catch`,现改为共用 `src/bootstrap-http.js` 的三个函数——按 #411 的纪律,两张皮只许剩鉴权与路径不同。
14-
- **验证**:新增 `test/config-keys-routes.test.js`(15 条:policy/鉴权/坏 JSON/顺序锁/真实目录导入/不回值/三桶划分/两处点名键/坏 logger 下仍回 500)+ `test/client.test.js` 一条面板锁(菜单项、弹层挂载与忙碌时不关、请求形状、四种错误码、输入框与定时器、摘要三类数字、搜索 effect 的依赖、11 个 i18n 键中英各在、卡片挂载位置)。变异自证逐条 KILLED——含把 `/bootstrap` 的 policy 改成 open、把 `schemaLeafKeys` 换回解析结果、把 `undefaulted` 折进 `panelEditable`、把能力判定挪到 dir 校验之前、删掉菜单项、把取数失败渲染成空表、「卡片写了但没挂上」,以及评审修复那七处各自反向改回去。全量 2697 tests / 2696 pass / 0 fail / 1 skipped,`check-sync` 85 文件一致。
15+
- **验证**:新增 `test/config-keys-routes.test.js`(15 条:policy/鉴权/坏 JSON/顺序锁/真实目录导入/不回值/三桶划分/两处点名键/坏 logger 下仍回 500)+ `test/client.test.js` 一条面板锁(菜单项、弹层挂载与忙碌时不关、请求形状、四种错误码、输入框与定时器、摘要三类数字、搜索 effect 的依赖、11 个 i18n 键中英各在、卡片挂载位置)。变异自证逐条 KILLED——含把 `/bootstrap` 的 policy 改成 open、把 `schemaLeafKeys` 换回解析结果、把 `undefaulted` 折进 `panelEditable`、把能力判定挪到 dir 校验之前、删掉菜单项、把取数失败渲染成空表、「卡片写了但没挂上」,以及评审修复那七处各自反向改回去;第三轮那三处也各自反向改回去(去掉 share 项的 `disabled: bootstrapBusy`、去掉同步上报、把 `onImported()` 挪进关闭定时器、把导出项也一起禁用),四条全部 KILLED。全量 2697 tests / 2696 pass / 0 fail / 1 skipped,`check-sync` 85 文件一致。
1516

1617
## [0.10.1] - 2026-11-03
1718

‎dsh-mneme/lib/client.js‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7163,6 +7163,10 @@ window.__ModuleLoader__.load({
71637163
const target = String(dir || "").trim();
71647164
if (!target) { setErr(t("memory.explorer.bootstrapNoDir")); return; }
71657165
setBusy(true);
7166+
// 同步告诉父组件,别等下面那个 effect:effect 要等这次渲染提交后才跑,
7167+
// 中间那一拍父组件的 bootstrapBusy 还是 false,此时点「⋯」仍会把弹层卸掉,
7168+
// 请求的成功或失败就再没有地方显示(评审 #4452539705)。
7169+
if (onBusyChange) onBusyChange(true);
71667170
setErr("");
71677171
apiFetch("/api/dsh-mneme/bootstrap", {
71687172
method: "POST",
@@ -7185,7 +7189,11 @@ window.__ModuleLoader__.load({
71857189
setMsg(t("memory.explorer.bootstrapDone")
71867190
.replace("{n}", String((d && d.created) ?? 0))
71877191
.replace("{m}", String((d && d.merged) ?? 0)));
7188-
timerRef.current = setTimeout(() => { onImported(); onClose(); }, 900);
7192+
// onImported 同步调,只把 onClose 留在定时器里:切视图会卸载本组件并清掉
7193+
// timerRef,若刷新也排在那 900ms 之后,这一步就静默丢了——库已经写进去了,
7194+
// 列表却还是旧的(评审 #4452539711)。
7195+
onImported();
7196+
timerRef.current = setTimeout(() => onClose(), 900);
71897197
})
71907198
.catch(() => { setBusy(false); setErr(t("memory.explorer.bootstrapFailed")); });
71917199
};
@@ -8068,19 +8076,22 @@ window.__ModuleLoader__.load({
80688076
}
80698077
}, "⋯"),
80708078
menuOpen && h("div", { className: "mneme-menu", role: "menu" },
8071-
h("button", { type: "button", role: "menuitem", onClick: () => { setCreateOpen(true); setMenuOpen(false); } },
8079+
// 引导请求在飞时,会挂弹层的那几项一律 disabled:这些弹层共用同一个
8080+
// 绝对定位锚点,后渲染的会盖住引导弹层,它那句「新建几条、并入几条」
8081+
// 就没地方看了(评审 #4452539738)。导出两项不挂弹层,照旧可点。
8082+
h("button", { type: "button", role: "menuitem", disabled: bootstrapBusy, onClick: () => { setCreateOpen(true); setMenuOpen(false); } },
80728083
t("memory.explorer.newMemory")),
80738084
h("button", { type: "button", role: "menuitem", onClick: () => { setMenuOpen(false); exportData("json"); } },
80748085
t("memory.explorer.exportJson")),
80758086
h("button", { type: "button", role: "menuitem", onClick: () => { setMenuOpen(false); exportData("markdown"); } },
80768087
t("memory.explorer.exportMarkdown")),
8077-
h("button", { type: "button", role: "menuitem", onClick: () => { setImportOpen(true); setMenuOpen(false); } },
8088+
h("button", { type: "button", role: "menuitem", disabled: bootstrapBusy, onClick: () => { setImportOpen(true); setMenuOpen(false); } },
80788089
t("memory.explorer.importMd")),
8079-
h("button", { type: "button", role: "menuitem", onClick: () => { setBootstrapOpen(true); setMenuOpen(false); } },
8090+
h("button", { type: "button", role: "menuitem", disabled: bootstrapBusy, onClick: () => { setBootstrapOpen(true); setMenuOpen(false); } },
80808091
t("memory.explorer.bootstrap")),
8081-
h("button", { type: "button", role: "menuitem", onClick: () => { setShareOpen(true); setMenuOpen(false); } },
8092+
h("button", { type: "button", role: "menuitem", disabled: bootstrapBusy, onClick: () => { setShareOpen(true); setMenuOpen(false); } },
80828093
t("memory.explorer.sharePack")),
8083-
h("button", { type: "button", role: "menuitem", onClick: () => { setReceiveOpen(true); setMenuOpen(false); } },
8094+
h("button", { type: "button", role: "menuitem", disabled: bootstrapBusy, onClick: () => { setReceiveOpen(true); setMenuOpen(false); } },
80848095
t("memory.explorer.receivePack")),
80858096
),
80868097
importOpen && h(ImportDialog, {

‎dsh-mneme/test/client.test.js‎

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ test("panel can create a memory by hand: menu entry wired to the dialog", () =>
14131413
// 入口在「更多操作」菜单里,且菜单项真的调用 setCreateOpen(true)——只断言文案
14141414
// 存在的话,把 onClick 摘掉测试照样绿。
14151415
assert.ok(clientSource.includes('"memory.explorer.newMemory"'), "menu entry label must exist");
1416-
assert.ok(/role: "menuitem", onClick: \(\) => \{ setCreateOpen\(true\); setMenuOpen\(false\); \}/.test(clientSource),
1416+
assert.ok(/role: "menuitem", (?:disabled: bootstrapBusy, )?onClick: \(\) => \{ setCreateOpen\(true\); setMenuOpen\(false\); \}/.test(clientSource),
14171417
"the menu item must actually open the create dialog");
14181418
assert.ok(clientSource.includes("const [createOpen, setCreateOpen] = useState(false)"),
14191419
"the dialog needs its own open state");
@@ -2741,9 +2741,36 @@ test("panel exposes the bootstrap entry and the config-key coverage card (issue
27412741
/onBusyChange: setBootstrapBusy/.test(clientSource),
27422742
"the dialog must report its busy state up, or the guard reads a stale false"
27432743
);
2744+
// 会挂弹层的菜单项在忙碌时必须禁用(评审 #4452539738):新建 / 导入 / 引导 / 分享 /
2745+
// 接收共五处。这些弹层共用同一个绝对定位锚点,后渲染的会盖住引导弹层那句
2746+
// 「新建几条、并入几条」。数个数而不是逐个锁字符串——少一处就等于留了一条绕过
2747+
// 弹层的路,而这条路的代价是用户看不到自己那次引导的结果。
2748+
assert.equal(
2749+
clientSource.split("disabled: bootstrapBusy").length - 1,
2750+
5,
2751+
"every dialog-mounting menu item must be disabled while bootstrap is busy"
2752+
);
2753+
// 两个导出项不挂弹层,不该被一起禁掉——引导在飞时照样能导出。
2754+
for (const line of clientSource.split("\n")) {
2755+
if (!line.includes("exportData(")) continue;
2756+
assert.ok(
2757+
!line.includes("disabled: bootstrapBusy"),
2758+
"the export items mount no dialog and must stay clickable while bootstrap is busy"
2759+
);
2760+
}
27442761
const bsIdx = clientSource.indexOf("function BootstrapDialog");
2745-
const bsBody = clientSource.slice(bsIdx, bsIdx + 3200);
2762+
// 切到下一个弹层为止,而不是给一个拍脑袋的字符数:这轮改动静悄悄把窗口撑破了,
2763+
// 断言于是在一个截断的片段上做,失败信息还指着「输入框没禁用」这种不存在的毛病。
2764+
const bsEnd = clientSource.indexOf("// --- 分享包弹层 ---", bsIdx);
2765+
const bsBody = clientSource.slice(bsIdx, bsEnd > bsIdx ? bsEnd : bsIdx + 4200);
27462766
assert.ok(bsIdx > 0, "BootstrapDialog must exist");
2767+
// 忙碌状态必须**同步**报上去(评审 #4452539705):只靠上面那个 useEffect 的话,
2768+
// 它要等这次渲染提交后才跑,中间那一拍父组件的 bootstrapBusy 还是 false,此时点
2769+
// 「⋯」仍会把弹层卸掉,请求的成功或失败就再没有地方显示。
2770+
assert.ok(
2771+
/setBusy\(true\);[\s\S]{0,400}?onBusyChange\(true\);/.test(bsBody),
2772+
"busy must be reported up synchronously, not only through the effect"
2773+
);
27472774
assert.ok(
27482775
/apiFetch\("\/api\/dsh-mneme\/bootstrap"/.test(bsBody),
27492776
"the dialog must POST to the bootstrap route"
@@ -2768,6 +2795,19 @@ test("panel exposes the bootstrap entry and the config-key coverage card (issue
27682795
const successTail = bsBody.slice(doneIdx, timerIdx);
27692796
assert.ok(!/setBusy\(false\)/.test(successTail), "the success path must not re-enable the button");
27702797
assert.ok(/clearTimeout\(timerRef\.current\)/.test(bsBody), "the stored timer must actually be cleared on unmount");
2798+
// 刷新必须同步调、不能排进定时器(评审 #4452539711):切视图会卸载本组件并把
2799+
// timerRef 清掉,若刷新也挂在那 900ms 后面,它就静默丢了——库已经写进去了,
2800+
// 列表却还是旧的。而这条路径上用户刚看到「新建 N 条」,最容易立刻去翻列表。
2801+
const importedIdx = bsBody.indexOf("onImported();");
2802+
assert.ok(importedIdx > 0, "the success path must refresh the list");
2803+
assert.ok(
2804+
importedIdx < timerIdx,
2805+
"onImported must run synchronously, not inside the close timer"
2806+
);
2807+
assert.ok(
2808+
!/setTimeout\(\(\)\s*=>\s*\{?\s*onImported/.test(bsBody),
2809+
"the refresh must not be deferred into the close timer"
2810+
);
27712811
// 错误按服务端的码分开说(missing-dir / dir-not-found / not-a-directory /
27722812
// bootstrap-unavailable),不能一律「引导失败」——三种情况下用户该做的事不同。
27732813
assert.ok(

0 commit comments

Comments
 (0)