From 25f889c6d87feba73ff6457edb31de1f6d2eed6b Mon Sep 17 00:00:00 2001 From: jkooe <62494645+jkooe@users.noreply.github.com> Date: Wed, 7 Oct 2026 02:00:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20ps1-encoding=20=E5=AE=88=E5=8D=AB?= =?UTF-8?q?=E6=94=B9=E7=94=A8=20fileURLToPath=EF=BC=88Windows=20=E4=B8=8A?= =?UTF-8?q?=20URL.pathname=20=E4=BC=9A=E5=A4=9A=E4=B8=80=E6=A0=B9=E5=89=8D?= =?UTF-8?q?=E5=AF=BC=E6=96=9C=E6=9D=A0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **这是 Windows CI 一上线就抓到的真 bug** —— 新加的 CI 单测步骤当场回本。 根因:测试用 new URL('../../', import.meta.url).pathname 取仓库根。macOS 上得到 /Users/... 可用;Windows 上得到 /D:/a/nodeagent/...(盘符前多一根斜杠), readdirSync 直接 ENOENT → 整个文件 22 个用例全灭。 本地(macOS)永远测不出来,只有 Windows runner 会炸。 修法:改用 fileURLToPath(new URL(...)) —— Node 官方的跨平台转换。 全仓已无同类残留。本地 195 单测 / 29 e2e 复跑全绿。 --- tests/unit/ps1-encoding.test.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/ps1-encoding.test.mjs b/tests/unit/ps1-encoding.test.mjs index efe217d..35ffb21 100644 --- a/tests/unit/ps1-encoding.test.mjs +++ b/tests/unit/ps1-encoding.test.mjs @@ -21,8 +21,9 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync, readdirSync } from 'node:fs'; import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; -const ROOT = new URL('../../', import.meta.url).pathname; +const ROOT = fileURLToPath(new URL('../../', import.meta.url)); const PS_DIR = join(ROOT, 'scripts'); /** 收集仓库里所有需要分发的 .ps1(含子目录) */