Describe the bug / 问题描述
On Windows, 9 of the 15 tests in apps/electron-demo/test/sample-vault.test.ts fail. All failures are path-separator mismatches (\ vs /), not actual logic regressions in LinkIndex.
在 Windows 上,apps/electron-demo/test/sample-vault.test.ts 里 15 个测试中有 9 个失败,全部都是路径分隔符(\ 与 /)不一致导致的断言失败,并非 LinkIndex 本身的逻辑回归。
Root cause / 根因
LinkIndex (apps/electron-demo/src/renderer/link-index.ts) normalizes every path internally via normalizeSlashes() (p.replace(/\\/g, "/")) before storing or returning it — resolve(), getBacklinks(), getUnlinkedMentions() etc. all return forward-slash paths regardless of OS.
The test file builds its expected values with path.join(VAULT_ROOT, ...), which uses the native separator. On Windows that's \, so the expected value (C:\Users\...\Topics\AI.md) never matches the actual, already-normalized return value (C:/Users/.../Topics/AI.md) — even though the resolution itself is correct.
LinkIndex(apps/electron-demo/src/renderer/link-index.ts)内部所有路径都会先经过 normalizeSlashes()(p.replace(/\\/g, "/"))统一成正斜杠再存储/返回——resolve()、getBacklinks()、getUnlinkedMentions() 等方法在任何系统上返回的都是正斜杠路径。
而测试文件构造"期望值"时用的是 path.join(VAULT_ROOT, ...),它会用当前系统的原生分隔符——Windows 下就是 \。于是期望值(C:\Users\...\Topics\AI.md)永远对不上已经被规范化过的实际返回值(C:/Users/.../Topics/AI.md),即使解析结果本身是对的。
So this is a test-only bug: the production code already does the cross-platform-correct thing; the test's own expected-value construction doesn't account for that.
所以这是一个纯测试层面的bug:生产代码本身已经做了跨平台正确的处理,问题出在测试文件构造期望值时没有同样做一次规范化。
Steps to reproduce / 复现步骤
git clone https://github.com/floatboatai/Nexus-Editor.git
cd Nexus-Editor
pnpm install
pnpm test
On Windows (tested via Git Bash / MINGW64), this produces 9 failures in sample-vault.test.ts, e.g.:
FAIL apps/electron-demo/test/sample-vault.test.ts > ... > [[AI]] from Daily resolves to Topics/AI.md (globally unique basename)
AssertionError: expected 'C:/Users/.../Topics/AI.md' to be 'C:\Users\...\Topics\AI.md'
On Linux/macOS (where path.join's native separator is already /), the same assertions happen to pass — which is why this wasn't caught in CI if it doesn't run a Windows job.
在 Windows(Git Bash / MINGW64 环境下测试)会产生上述9个失败。在 Linux/macOS 下因为原生分隔符本身就是/,刚好不会暴露这个问题——如果CI没有跑Windows job,这个问题就不会被发现。
Expected behavior / 期望行为
All 15 sample-vault.test.ts tests pass on Windows, Linux, and macOS alike.
sample-vault.test.ts 的全部15个测试应该在 Windows / Linux / macOS 上都能通过。
Suggested fix / 修复建议
Normalize the test's own expected-value construction the same way the production code does — e.g. wrap path.join(...) results with the same normalizeSlashes-equivalent (.replace(/\\/g, "/")) before comparing, or compare via path.relative(...).split(path.sep).join("/"). This only touches the test file; no production code (link-index.ts) needs to change.
建议直接在测试文件里、对 path.join(...) 的结果做一次跟生产代码一致的规范化(.replace(/\\/g, "/")),或者用 path.relative(...).split(path.sep).join("/") 来比较,只需要改测试文件本身,不需要动 link-index.ts 生产代码。
Environment / 环境
- OS: Windows 11 (Git Bash / MINGW64)
- Node: v18.20.8
- pnpm: 9.15.4
Additional context / 补充
Confirmed this is pre-existing on main and unrelated to any specific in-flight PR — verified by running pnpm test on a clean checkout of main with no local changes; the same 9 sample-vault.test.ts failures appear identically (same test names, same line numbers, same expected/received values).
已确认这个问题在 main 分支上本来就存在,跟任何正在进行的PR无关——在没有任何本地修改的情况下clone并跑了一遍 pnpm test,同样的9个失败(测试名、行号、期望值/实际值)完全一致地出现。
Describe the bug / 问题描述
On Windows, 9 of the 15 tests in
apps/electron-demo/test/sample-vault.test.tsfail. All failures are path-separator mismatches (\vs/), not actual logic regressions inLinkIndex.在 Windows 上,
apps/electron-demo/test/sample-vault.test.ts里 15 个测试中有 9 个失败,全部都是路径分隔符(\与/)不一致导致的断言失败,并非LinkIndex本身的逻辑回归。Root cause / 根因
LinkIndex(apps/electron-demo/src/renderer/link-index.ts) normalizes every path internally vianormalizeSlashes()(p.replace(/\\/g, "/")) before storing or returning it —resolve(),getBacklinks(),getUnlinkedMentions()etc. all return forward-slash paths regardless of OS.The test file builds its expected values with
path.join(VAULT_ROOT, ...), which uses the native separator. On Windows that's\, so the expected value (C:\Users\...\Topics\AI.md) never matches the actual, already-normalized return value (C:/Users/.../Topics/AI.md) — even though the resolution itself is correct.LinkIndex(apps/electron-demo/src/renderer/link-index.ts)内部所有路径都会先经过normalizeSlashes()(p.replace(/\\/g, "/"))统一成正斜杠再存储/返回——resolve()、getBacklinks()、getUnlinkedMentions()等方法在任何系统上返回的都是正斜杠路径。而测试文件构造"期望值"时用的是
path.join(VAULT_ROOT, ...),它会用当前系统的原生分隔符——Windows 下就是\。于是期望值(C:\Users\...\Topics\AI.md)永远对不上已经被规范化过的实际返回值(C:/Users/.../Topics/AI.md),即使解析结果本身是对的。So this is a test-only bug: the production code already does the cross-platform-correct thing; the test's own expected-value construction doesn't account for that.
所以这是一个纯测试层面的bug:生产代码本身已经做了跨平台正确的处理,问题出在测试文件构造期望值时没有同样做一次规范化。
Steps to reproduce / 复现步骤
On Windows (tested via Git Bash / MINGW64), this produces 9 failures in
sample-vault.test.ts, e.g.:On Linux/macOS (where
path.join's native separator is already/), the same assertions happen to pass — which is why this wasn't caught in CI if it doesn't run a Windows job.在 Windows(Git Bash / MINGW64 环境下测试)会产生上述9个失败。在 Linux/macOS 下因为原生分隔符本身就是
/,刚好不会暴露这个问题——如果CI没有跑Windows job,这个问题就不会被发现。Expected behavior / 期望行为
All 15
sample-vault.test.tstests pass on Windows, Linux, and macOS alike.sample-vault.test.ts的全部15个测试应该在 Windows / Linux / macOS 上都能通过。Suggested fix / 修复建议
Normalize the test's own expected-value construction the same way the production code does — e.g. wrap
path.join(...)results with the samenormalizeSlashes-equivalent (.replace(/\\/g, "/")) before comparing, or compare viapath.relative(...).split(path.sep).join("/"). This only touches the test file; no production code (link-index.ts) needs to change.建议直接在测试文件里、对
path.join(...)的结果做一次跟生产代码一致的规范化(.replace(/\\/g, "/")),或者用path.relative(...).split(path.sep).join("/")来比较,只需要改测试文件本身,不需要动link-index.ts生产代码。Environment / 环境
Additional context / 补充
Confirmed this is pre-existing on
mainand unrelated to any specific in-flight PR — verified by runningpnpm teston a clean checkout ofmainwith no local changes; the same 9sample-vault.test.tsfailures appear identically (same test names, same line numbers, same expected/received values).已确认这个问题在
main分支上本来就存在,跟任何正在进行的PR无关——在没有任何本地修改的情况下clone并跑了一遍pnpm test,同样的9个失败(测试名、行号、期望值/实际值)完全一致地出现。