Skip to content

Commit f584618

Browse files
committed
fix(choro): /choro/modules 补 relPath,修好地志页导入知识点(#607)
面板「仓库地志 → 导入知识库」这条路此前是哑的:选完模块点导入,永远只会弹 「请先选模块」。根因在契约两侧只对了一半——面板按 §3.6 读 mod.relPath,而后端 moduleMap() 直出 SQL 行,字段是 snake_case 的 page_rel_path,camelCase 那个从来 不存在,relPath 恒 undefined。功能看着在位,一点就把后端缺字段说成用户没选, 与 #607 同类:假成功比报错更难查。 改法: - src/wiki/queries.js 的 moduleMap() 纯加法补 relPath: r.page_rel_path ?? null, 原 snake_case 字段一律保留(choro_module_map 的 render 吃 file_count/page_status, choro-command 与 wiki-store 测试也吃原字段,改形状会波及它们);同一文件的 outline() 早就是这个正确写法,moduleMap 是漏的那一处。 - lib/client.js 缺 relPath 另立一条 kb.repo.noRelPath(中英各一),不再复用 kb.repo.pickFirst——后端缺字段与用户没点是两件事,混成一句就是把 bug 说成操作问题。 回归锁: - test/wiki-queries.test.js 断言 relPath 与 page_rel_path 同值且是 .md、原字段仍在。 - test/wiki-api.test.js 在 /choro/modules 的真实回执上断言每个有页模块的 relPath。 - test/client.test.js 反向断言缺 relPath 不许报成「请先选模块」。 验证:真装配(createStore + runChoroT0 + createChoroQueries + createKb)跑临时 git 仓库,T0 生成的两个模块经「rootPath + relPath」拼绝对路径后 ingest 各成 6 块、 search 命中,不再需要走 CLI。全量 node --test test/*.test.js 2941 用例 / 2940 通过 / 0 失败 / 1 跳过;check-sync 99 一致。 已知边界:面板本身仍未在真机宿主里点过(渲染与事件绑定只有代码级验证);本机 只登记 dsh-baleen 一个仓库且 claims=0,T1 语义正文为空。
1 parent 5c41d31 commit f584618

7 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎dsh-mneme/CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
- **切块严格按行连续、一个空行都不剥**:`readDoc` 靠「块用 `\n` 拼接 === 原文逐字节」还原,行号靠 `cursor += 块行数`(不 +`1`)算准。幂等判据是**正文 sha256** 而不是 mtime——同一个文件重新入库是 no-op,改一个字符才重建。集合不存在**不静默建**(拼错的 key 会把资料塞进一个凭空出现的集合,用户永远找不到);来源级失败(`file-not-found`/`too-large`/`http-404`)回 **200 + `ok:false`** 而不是 4xx:`kb_docs` 里已经落了 `status='error'` 的留痕行,回 4xx 会让面板把它当成「请求本身错了」而丢掉记录,用户看到的就是「点了没反应」。
1616
- **`kbEnabled`(默认关)与两条闸不许混**:`409 {error:"disabled",reason:"kb-not-enabled"}` = 用户没开开关(文案写明去哪里开);`503 {error:"unavailable"}` = 这台宿主没装配 kb(headless / 测试)。混成一个码,面板就没法分辨「去设置里打开」和「这台宿主不支持」——`test/kb-api-wiring.test.js` 首条用例就是锁这个分叉。
1717
- **面板第三个座位 `dsh-mneme-kb`**:左侧集合列表(建/删,删除两步确认)+ 右侧文档列表 + 三种入库来源;地志页「导入知识库」的 `rootPath` 只从 `/choro/repos` 取、`relPath` 从 `/choro/modules` 取,拿不到就停手给人话、**不发必然 404 的请求**。所有新文案中英按键名成对(`test/client.test.js` 的「每键恰好两次」检查),颜色只走 `--mneme-*` 语义层。
18+
- **端到端冒烟查出的真 bug:`/choro/modules` 不回 `relPath`,地志页导入整条路是哑的**。`queries.js` 的 `moduleMap()` 直出 SQL 行,字段是 snake_case 的 `page_rel_path`;面板按契约读 `mod.relPath` 恒 `undefined`,于是**选完模块点导入永远弹「请先选模块」**——功能看着在、一点就说是你没选,正是 #607 那类「把后端缺陷说成用户操作问题」的假成功。修法是在 `moduleMap()` 里**纯加法**补一个 `relPath: r.page_rel_path ?? null`(原 snake_case 字段一律保留,`choro_module_map` 的 render 与 CLI 都在吃);面板侧缺字段的提示另立一条 `kb.repo.noRelPath`,不再复用 `pickFirst`。两处回归锁:`test/wiki-queries.test.js` 断言 `relPath` 与 `page_rel_path` 同值且原字段仍在,`test/client.test.js` 反向断言「缺 relPath 不许报成请先选模块」。真装配复验:T0 生成的两页模块经「根路径 + relPath」拼出绝对路径后 `ingest` 各成 6 块、`search` 命中,不再经过 CLI。
1819
- **验证**:全量 `node --test test/*.test.js` 2941 用例 / 2940 通过 / 0 失败 / 1 跳过;check-sync 99 一致。新增 `test/kb-collections.test.js`(8)、`test/kb-routes.test.js`(7)、`test/kb-api-wiring.test.js`(4)、`test/wiki-t1-jobs.test.js`(状态机,注入桩);`test/wiki-api.test.js` 13→18 条、`test/client.test.js` 109 条(座位数 2→3 已同步)、`test/api.test.js` 旗标计数锁 114→117。SECURITY.md 两侧路由清单已按 policy 声明补齐(`test/security-doc.test.js` 双向比对绿)。
19-
- **已知边界**:T1 的测试全程走注入桩,**真 T1 一次没跑**(花钱的不进 CI);知识库页只做了代码级验证,没在真机宿主里端到端点过——真机上若 `/kb/docs` 回执字段有出入,只需改 `loadDocs`/`docRows` 一处。
20+
- **已知边界**:T1 的测试全程走注入桩,**真 T1 一次没跑**(花钱的不进 CI);后端七条 KB 路由与七条 choro 路由已用真装配(createApi + createStore + createKb + createChoroQueries)发真 HTTP 逐个冒烟过,但**面板本身没在真机宿主里点过**——渲染与事件绑定仍只有代码级验证;真机上若 `/kb/docs` 回执字段有出入,只需改 `loadDocs`/`docRows` 一处。本机目前只登记 `dsh-baleen` 一个仓库且 `claims=0`(T0 骨架有、T1 语义正文为空),所以打开面板第一眼看到的仍是「骨架、无语义」的地志。
2021

2122
- **「Agent 眼中的你」按段化第一期:注入渲染函数产出段边界(`segments`),面板从此能按段读(#600)**。`renderUserSettingsBlock` 原先只回一整串 `text`,面板那张卡只能整段只读显示——想改注入文本里的某一句,得走「整段提取 → 复制 → 粘进画像框」的剪贴板中转,而画像段是手写原文、人格段是结构化卡、事实段是逐条维护的行,三者写回语义完全不同。段边界是这三条路能分开走的前提。
2223

‎dsh-mneme/lib/client.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ window.__ModuleLoader__.load({
394394
"kb.repo.pickFirst": "先在上面选一个仓库",
395395
"kb.repo.none": "还没有登记的仓库:先去「仓库地志」页生成一次,再回来导入。",
396396
"kb.repo.noPath": "这个仓库的根路径拿不到(后端没回 rootPath),拼不出地志页的绝对路径。",
397+
"kb.repo.noRelPath": "这个模块还没生成骨架页(后端没回 relPath),先回「仓库地志」页生成一次再来导入。",
397398
"kb.load.failed": "加载失败",
398399
"memory.tab.all": "全部",
399400
"memory.tab.preference": "偏好",
@@ -1364,6 +1365,7 @@ window.__ModuleLoader__.load({
13641365
"kb.repo.pickFirst": "Pick a repository above first",
13651366
"kb.repo.none": "No repository registered yet: generate one on the Repo Atlas page first, then come back to import.",
13661367
"kb.repo.noPath": "This repository's root path is unavailable (the backend did not return rootPath), so the atlas page's absolute path cannot be composed.",
1368+
"kb.repo.noRelPath": "This module has no skeleton page yet (the backend did not return relPath). Generate it on the Repo Atlas page first, then import.",
13671369
"kb.load.failed": "Failed to load",
13681370
"memory.tab.all": "All",
13691371
"memory.tab.preference": "Preferences",
@@ -11500,7 +11502,9 @@ window.__ModuleLoader__.load({
1150011502
const relPath = mod && mod.relPath ? String(mod.relPath) : "";
1150111503
// 拿不到根路径就停在这儿给一句人话——发出去必然是 404,用户只会更糊涂。
1150211504
if (!rootPath) { patch({ toast: t("kb.repo.noPath") }); return; }
11503-
if (!relPath) { patch({ toast: t("kb.repo.pickFirst") }); return; }
11505+
// 缺 relPath 与「没选模块」是两件事:前者是后端回执少字段、后者是用户没点。
11506+
// 用同一句「请先选模块」会把真 bug 说成操作问题(#607 那种假成功),故分开。
11507+
if (!relPath) { patch({ toast: t("kb.repo.noRelPath") }); return; }
1150411508
source = rootPath.replace(/[\\/]+$/, "") + "/" + relPath.replace(/^[\\/]+/, "");
1150511509
}
1150611510
if (!source) { patch({ toast: t("kb.doc.source") }); return; }

‎dsh-mneme/lib/wiki/queries.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ export function createChoroQueries({ store }) {
189189
`SELECT from_slug, to_slug, weight FROM choro_edges WHERE repo_id = ?
190190
ORDER BY from_slug, to_slug`
191191
).all(repoId);
192+
// 纯加法补一个 camelCase 的 relPath:面板从地志页导入知识点要拼「根路径 + 页相对
193+
// 路径」,而这里历史上直出 SQL 行的 snake_case(page_rel_path)。C 线按契约读的是
194+
// mod.relPath,字段一缺就恒 undefined,用户选完模块点导入只会看到「请先选模块」。
195+
// 原字段一律保留——src/tools.js 的 render 与 choro-command 都还在吃 file_count /
196+
// page_status,改形状会波及它们;outline() 里的同名映射是这件事的正确写法。
197+
for (const m of modules) m.relPath = m.page_rel_path ?? null;
192198
return { modules, edges };
193199
}
194200

‎dsh-mneme/src/wiki/queries.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ export function createChoroQueries({ store }) {
189189
`SELECT from_slug, to_slug, weight FROM choro_edges WHERE repo_id = ?
190190
ORDER BY from_slug, to_slug`
191191
).all(repoId);
192+
// 纯加法补一个 camelCase 的 relPath:面板从地志页导入知识点要拼「根路径 + 页相对
193+
// 路径」,而这里历史上直出 SQL 行的 snake_case(page_rel_path)。C 线按契约读的是
194+
// mod.relPath,字段一缺就恒 undefined,用户选完模块点导入只会看到「请先选模块」。
195+
// 原字段一律保留——src/tools.js 的 render 与 choro-command 都还在吃 file_count /
196+
// page_status,改形状会波及它们;outline() 里的同名映射是这件事的正确写法。
197+
for (const m of modules) m.relPath = m.page_rel_path ?? null;
192198
return { modules, edges };
193199
}
194200

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ test("knowledge base page exposes the §3.6 routes and explains every empty stat
261261
assert.ok(fn.includes('t("kb.empty.unavailable")'), "503 must render the unavailable explanation");
262262
assert.ok(fn.includes('t("kb.empty.collections")'), "an empty collection list must explain what to do next");
263263
assert.ok(fn.includes('t("kb.repo.noPath")'), "a missing rootPath must stop before composing a guaranteed 404");
264+
// 后端 /choro/modules 曾只回 snake_case 的 page_rel_path,面板读 mod.relPath 恒 undefined,
265+
// 于是「选完模块点导入」永远弹「请先选模块」——把后端缺陷说成用户没点(#607 同型)。
266+
// 现在后端补了 relPath,缺字段时也必须落到独立的解释上,不许复用 pickFirst。
267+
assert.ok(fn.includes('t("kb.repo.noRelPath")'), "a module without relPath needs its own explanation");
268+
assert.ok(
269+
!/if \(!relPath\) \{ patch\(\{ toast: t\("kb\.repo\.pickFirst"\) \}\); return; \}/.test(fn),
270+
"a missing relPath must not be reported as 'pick a module first'"
271+
);
264272
assert.ok(fn.includes("kb/collections?key="), "deleting a collection addresses it by key");
265273

266274
// 文案本身锁一次:说清这是 mneme 的功能、开关在哪儿。

‎dsh-mneme/test/wiki-api.test.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ test("快乐路径:repos / modules / page / search 全通", async () => {
120120
assert.equal(modules.status, 200);
121121
assert.ok(modules.body.modules.length >= 2);
122122
assert.ok(Array.isArray(modules.body.edges));
123+
// 面板的地志页导入要把「根路径 + 页相对路径」拼成磁盘绝对路径(契约 §3.6),
124+
// 回执里缺 relPath 时它会静默回落到「请先选模块」——这条锁的就是那个真机 bug。
125+
const withPage = modules.body.modules.filter((m) => m.page_rel_path);
126+
assert.ok(withPage.length >= 1, "fixture 里至少一个模块有骨架页");
127+
for (const m of withPage) assert.equal(m.relPath, m.page_rel_path);
123128

124129
const page = await invoke(handler(routes, "/api/dsh-mneme/choro/page"), `/api/dsh-mneme/choro/page?repo=${repoId}&slug=src`);
125130
assert.equal(page.status, 200);

‎dsh-mneme/test/wiki-queries.test.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ test("moduleMap:模块、页面状态与跨模块边同源返回", () => {
165165
assert.deepEqual(slugs, ["root", "src"]);
166166
const src = modules.find((m) => m.slug === "src");
167167
assert.equal(src.page_status, "skeleton");
168+
// 面板从地志页导入知识点时读的是 mod.relPath(契约 §3.6);SQL 行里只有
169+
// page_rel_path,缺这层映射会让「选完模块点导入」永远提示请先选模块(#607)。
170+
// 同时锁住原 snake_case 字段还在——choro_module_map 的 render 与 CLI 都在用。
171+
assert.equal(typeof src.relPath, "string", "relPath 必须与 page_rel_path 同值");
172+
assert.equal(src.relPath, src.page_rel_path);
173+
assert.ok(src.relPath.endsWith(".md"), "页相对路径是磁盘上真实存在的 .md");
174+
assert.equal(typeof src.file_count, "number", "file_count 原字段必须保留(choro_module_map 的 render 在吃)");
168175
// fixture 的引用全在 src 模块内部(a→b→b2),left-pad 是外部依赖,root 只有
169176
// package.json 没有代码——跨模块边应为空集。跨模块聚erge本身由 wiki-store 的
170177
// 整仓替换用例与 t0 的 moduleEdges 排序覆盖。

0 commit comments

Comments
 (0)