Repository navigation
fix(repowiki): repoWiki_query 读取路径被二次拼接 basePath - #8
Merged
xiaolfeng merged 1 commit intoOct 23, 2026
Merged
Conversation
readWikiPage 把 GetWikiPath 的产物(已含 basePath 前缀)直接传给
SanitizePath,而后者契约为 basePath 相对路径、会再拼一次 basePath,
导致 MCP repoWiki_query 恒以 {basePath}/{basePath}/versions/... 读文件
而报 no such file。改为先经 BasePath() 转回相对路径再校验。
附回归测试:REPOWIKI_STORAGE_PATH 为相对路径时 QueryWiki 能读到页面
(未修复时精确复现 {basePath}/{basePath}/... 的 no such file)。
xiaolfeng
approved these changes
Oct 23, 2026
xiaolfeng
left a comment
Owner
There was a problem hiding this comment.
Code review
未发现问题(LGTM)。已完成代码缺陷、历史上下文与 CLAUDE.md / AGENTS.md 规范核查:
- 根因与修复核验:
GetWikiPath产物已含basePath前缀,直接传入按相对路径契约工作的SanitizePath会在REPOWIKI_STORAGE_PATH为相对路径(如默认./.lumina/repowiki)时触发二次拼接。通过WikiStorageService.BasePath()与filepath.Rel(l.svc.storage.BasePath(), wikiPath)先还原为相对basePath的路径再交由SanitizePath校验,兼顾相对与绝对存储路径。 - 安全边界:前置
isWithinDir(wikiPath, page)跨版本目录隔离与SanitizePath存储根防逃逸双重校验保持完整。 - 回归测试:
TestRepoWikiLogic_QueryWiki_RelativeStoragePath已覆盖相对路径配置场景,go vet与go test -race全部通过。
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.
PR:fix(repowiki): repoWiki_query 读取路径被二次拼接 basePath
动机
存储路径为相对值(上游
.env.example默认REPOWIKI_STORAGE_PATH=./.lumina/repowiki)时,MCPrepoWiki_query对任何页面都报:.lumina/repowiki/前缀被拼了两次,Agent 侧无法读取任何已生成的 Wiki。根因
readWikiPage把GetWikiPath()的产物(已经包含 basePath 前缀)直接传给SanitizePath,而
SanitizePath的契约为 basePath 相对路径(函数注释第 3 条:「相对路径拼接到 basePath 之下」),对相对输入会再执行
filepath.Join(s.basePath, ...),产出{basePath}/{basePath}/versions/...。两个原因导致此前不易察觉:
REPOWIKI_STORAGE_PATH=/abs/...)下filepath.IsAbs短路二次拼接,不触发;wiki_reader.go)读页面不经过SanitizePath,一直正常,只有 MCP 查询走这条路。行为变化
repoWiki_query从「恒失败」变为正常返回页面内容。filepath.Rel转相对后再经SanitizePath拼回同一路径)。验证
TestRepoWikiLogic_QueryWiki_RelativeStoragePath(internal/logic/repowiki_logic_test.go):相对 basePath 下
QueryWiki读取页面。未修复时精确复现{basePath}/{basePath}/...的no such file or directory,修复后通过。go test ./...全绿;go vet ./...无告警;gofmt无差异。备注
修复选择了调用方侧(
readWikiPage转相对路径后再校验),保持SanitizePath的既有契约不动;如维护者更倾向让
SanitizePath兼容已含前缀的输入,也愿意按该方向调整。