test: avoid windows 8.3 short-name diff in realpath assertions
On windows fs.realpathSync and fs.realpath (async) can disagree on 8.3 short-name canonicalization. The github actions windows runner exposes this: fs.realpathSync returns "C:\Users\RUNNER~1\..." while fs.realpath returns "C:\Users\runneradmin\...". Tests that compare a sync helper's output against await fs.realpath fail with the same path printed in two forms. Compare against fs.realpathSync (imported as realpathSync from node:fs) on both sides so the test exercises the same canonical form regardless of which short-name configuration the runner has. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4a1e5d8b72
commit
ecefc5bd53
@ -1,4 +1,5 @@
|
||||
import fs from "node:fs/promises";
|
||||
import { realpathSync } from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { Readable } from "node:stream";
|
||||
@ -242,8 +243,11 @@ describe("path helpers", () => {
|
||||
expect(isSymlinkOpenError(Object.assign(new Error("x"), { code: "ELOOP" }))).toBe(true);
|
||||
expect(isPathInside(root, file)).toBe(true);
|
||||
expect(resolveSafeBaseDir(root)).toBe(`${path.resolve(root)}${path.sep}`);
|
||||
expect(safeRealpathSync(file, cache)).toBe(await fs.realpath(file));
|
||||
expect(safeRealpathSync(file, cache)).toBe(await fs.realpath(file));
|
||||
// Use the sync realpath to compare against safeRealpathSync. On windows
|
||||
// fs.realpathSync and fs.realpath (async) sometimes disagree on 8.3
|
||||
// short-name canonicalization (e.g. "RUNNER~1" vs "runneradmin").
|
||||
expect(safeRealpathSync(file, cache)).toBe(realpathSync(file));
|
||||
expect(safeRealpathSync(file, cache)).toBe(realpathSync(file));
|
||||
expect(safeRealpathSync(path.join(root, "missing"), cache)).toBeNull();
|
||||
expect(isPathInsideWithRealpath(root, file, { cache })).toBe(true);
|
||||
expect(isPathInsideWithRealpath(root, path.join(root, "missing"), { requireRealpath: false }))
|
||||
@ -457,7 +461,7 @@ describe("URL, install, and local-root helpers", () => {
|
||||
label: "media roots",
|
||||
requireFile: true,
|
||||
}),
|
||||
).toMatchObject({ path: await fs.realpath(file) });
|
||||
).toMatchObject({ path: realpathSync(file) });
|
||||
expect(() =>
|
||||
resolveLocalPathFromRootsSync({
|
||||
filePath: "bad\0path",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import fs from "node:fs/promises";
|
||||
import { realpathSync } from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
@ -173,7 +174,10 @@ describe("local roots helpers", () => {
|
||||
const missingPath = path.join(uploadsDir, "new", "later.txt");
|
||||
const outsidePath = path.join(baseDir, "outside.txt");
|
||||
await fs.writeFile(filePath, "ok", "utf8");
|
||||
const uploadsReal = await fs.realpath(uploadsDir);
|
||||
// Use the sync realpath to compare against resolveLocalPathFromRootsSync.
|
||||
// On windows fs.realpathSync and fs.realpath (async) sometimes disagree
|
||||
// on 8.3 short-name canonicalization (e.g. "RUNNER~1" vs "runneradmin").
|
||||
const uploadsReal = realpathSync(uploadsDir);
|
||||
|
||||
expect(
|
||||
resolveLocalPathFromRootsSync({
|
||||
@ -182,7 +186,7 @@ describe("local roots helpers", () => {
|
||||
label: "media roots",
|
||||
requireFile: true,
|
||||
}),
|
||||
).toEqual({ path: await fs.realpath(filePath), root: uploadsReal });
|
||||
).toEqual({ path: realpathSync(filePath), root: uploadsReal });
|
||||
expect(
|
||||
resolveLocalPathFromRootsSync({
|
||||
filePath: missingPath,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user