test(zip): 让两条断言平台正确,修 ci-windows 红

ci-windows(首次在本分支跑)报 tests/zip.spec.ts 两条失败,均为**测试可移植性**问题,不是产品缺陷:

1. 「keeps a backslash as part of the file name (POSIX names are literal)」:
   Windows 上反斜杠就是路径分隔符,join(root, 'a\b.txt') 得到 root\a\b.txt,父目录不存在 →
   writeFileSync 报 ENOENT。该语义在 Windows 上根本不存在 → 按仓库既有约定
   it.skipIf(isWin32) 跳过,并在注释里写明理由。
2. 「passes unzip -t when the binary exists」:断言 outMode === inMode & 0o644 在 Windows 上
   无意义(两边 statSync().mode 都是 0o666 → expected 420, received 438)。CRC 与解压断言保留,
   只把 mode 一致性放进 !isWin32 分支。

本地:tests/zip.spec.ts 37/37 通过;全量 typecheck / lint / test 绿(137 文件 / 1491 通过)。
This commit is contained in:
Menghuan1918
2026-09-28 23:21:06 +08:00
parent 0ac62b3a49
commit 52be73e176
+14 -4
View File
@@ -18,6 +18,9 @@ import { validateHeaderValue } from 'node:http'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { inflateRawSync } from 'node:zlib'
/** Windows has no POSIX file names and no POSIX mode bits (see the two guards below). */
const isWin32 = process.platform === 'win32'
import { apply } from '../src/index.ts'
import { archiveDownloadUrl } from '../src/client/api.ts'
import {
@@ -388,7 +391,10 @@ describe('buildZip', () => {
.rejects.toMatchObject({ code: 'bad-request' })
})
it('keeps a backslash as part of the file name (POSIX names are literal)', async () => {
// POSIX-only: on Windows a backslash IS the separator, so `a\b.txt` can only
// ever mean the file `b.txt` inside the directory `a` (the write below fails
// with ENOENT). The literal-name semantics under test do not exist there.
it.skipIf(isWin32)('keeps a backslash as part of the file name (POSIX names are literal)', async () => {
const root = tempRoot()
// `a\b.txt` is ONE legal POSIX file name; splitting it into a directory
// would silently rename the member (F8).
@@ -427,9 +433,13 @@ describe('buildZip', () => {
const extracted = join(root, 'out')
const unpack = spawnSync('unzip', ['-o', file, '-d', extracted], { encoding: 'utf8' })
expect(unpack.status, unpack.stderr).toBe(0)
const inMode = statSync(join(root, 'a.txt')).mode & 0o777
const outMode = statSync(join(extracted, 'a.txt')).mode & 0o777
expect(outMode).toBe(inMode & 0o644)
if (!isWin32) {
// POSIX-only: Windows maps every file to 0o666 on both sides, so the
// exact-mode parity below can only be asserted where mode bits exist.
const inMode = statSync(join(root, 'a.txt')).mode & 0o777
const outMode = statSync(join(extracted, 'a.txt')).mode & 0o777
expect(outMode).toBe(inMode & 0o644)
}
expect(readFileSync(join(extracted, 'a.txt'), 'utf8')).toBe(content)
expect(readFileSync(join(extracted, 'dir', 'b.txt'), 'utf8')).toBe(content)
})