From c02a7917fa05bb7ee7eb2c5090ee6311cb00cc33 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Mon, 5 Oct 2026 23:36:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(tests):=20=E4=BF=AE=E4=B8=A4=E5=A4=84?= =?UTF-8?q?=E8=B7=A8=E5=B9=B3=E5=8F=B0=E6=B5=8B=E8=AF=95=E7=BC=BA=E9=99=B7?= =?UTF-8?q?=EF=BC=88ci-windows=20=E7=BA=A2=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 两处都只在 Windows 上暴露,本机 macOS 全绿所以合入时没看出来: ① tests/fs-create-file.spec.ts:对 readdir 结果做**未排序**的 toEqual,而目录项顺序由文件系统决定 (Windows 与 ext4/APFS 不同)→ 改为比较排序后的名字集合。 ② tests/open-external.spec.ts:reveal 失败用例用字面量 '/a/b.txt' 做夹具,但被测代码用**宿主**路径 模块规范化路径并推导父目录——'/a/b.txt' 在 win32 上不是绝对路径(会按当前盘符解析),于是 期望的 args ['/a'] 与实到的父目录不一致 → 夹具与期望值都改为由宿主 path 模块推导 (resolve('/', 'a', 'b.txt') / dirname(file)),两个平台跑同一份语义断言。 判别依据:本机 macOS 上两条 spec 47 例全绿;真 Windows 由 ci-windows lane 复验(`pnpm test:windows`)。 --- tests/fs-create-file.spec.ts | 4 +++- tests/open-external.spec.ts | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/fs-create-file.spec.ts b/tests/fs-create-file.spec.ts index 1c939900..0503aa5b 100644 --- a/tests/fs-create-file.spec.ts +++ b/tests/fs-create-file.spec.ts @@ -91,7 +91,9 @@ describe('createWorkspaceFile', () => { for (const name of ['console.txt', 'conx', 'COM10', 'LPT', 'null.md', 'auxiliary']) { await expect(createWorkspaceFile({ cwd: root, path: root, name })).resolves.toEqual({ path: join(root, name) }) } - expect(await readdir(root)).toEqual(['COM10', 'LPT', 'auxiliary', 'console.txt', 'conx', 'null.md']) + // `readdir` order is filesystem-defined (Windows returns a different order than + // ext4/APFS), so compare the sorted name set instead of the raw listing. + expect((await readdir(root)).sort()).toEqual(['COM10', 'LPT', 'auxiliary', 'console.txt', 'conx', 'null.md']) }) it('refuses an existing destination with the same conflict code as rename and mkdir', async () => { diff --git a/tests/open-external.spec.ts b/tests/open-external.spec.ts index e1160a00..4959370a 100644 --- a/tests/open-external.spec.ts +++ b/tests/open-external.spec.ts @@ -4,6 +4,7 @@ * OS handlers are not launched in unit tests. */ import { EventEmitter } from 'node:events' +import { dirname, resolve } from 'node:path' import { describe, expect, it, vi } from 'vitest' import { launchExternal, @@ -284,10 +285,11 @@ describe('launchExternal Windows branch order and failure reporting', () => { it('reports a reveal failure with the same shape (one branch, `path` subject)', async () => { const fake = recordingSpawn() - // Path absoluteness is checked with the HOST path module, so this case uses - // the linux branch (an absolute POSIX path) to pin the aggregated message - // of the reveal half. - const pending = launchExternal('reveal', '/a/b.txt', { + // The path is normalized and its parent derived with the HOST path module, + // so the fixture must be host-absolute too — a literal `/a/b.txt` is not an + // absolute path on Windows (win32 resolves it against the current drive). + const file = resolve('/', 'a', 'b.txt') + const pending = launchExternal('reveal', file, { platform: 'linux', wsl: false, spawn: fake.spawn, @@ -296,7 +298,7 @@ describe('launchExternal Windows branch order and failure reporting', () => { const error = await pending.then(() => null, (reason: unknown) => reason) expect(fake.calls.map(call => ({ command: call.command, args: call.args }))).toEqual([ - { command: 'xdg-open', args: ['/a'] }, + { command: 'xdg-open', args: [dirname(file)] }, ]) expect((error as SidebarError).message).toBe( 'failed to launch external opener for the path: "xdg-open" (spawn xdg-open ENOENT)',