Files
paseo/packages/server/src/utils/path.test.ts
T
Mohamed BoudraandGitHub a06e4d60e9 Keep workspace Git refreshes responsive at scale (#2979)
* fix(server): prevent Git watcher fanout stalls

Repository metadata events were refreshing every observed worktree, multiplying Git process submissions and starving workspace create and archive requests behind observation work. Route metadata to the workspaces that depend on it, preserve conservative shared-ref refreshes, and admit interactive lifecycle operations ahead of queued background reads.

* fix(server): preserve Git metadata dependencies
2026-08-07 18:50:43 +08:00

71 lines
2.8 KiB
TypeScript

import { mkdtempSync, mkdirSync, rmSync, symlinkSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, expect, test } from "vitest";
import {
areEquivalentPaths,
createPathEquivalenceMatcher,
getRealpathAwareRelativePath,
isPathInsideRoot,
} from "./path.js";
describe("path equivalence", () => {
test.each([
["C:/Users/Administrator/GhostFactory", "C:\\Users\\Administrator\\GhostFactory"],
["d:\\Projects\\paseo", "D:\\Projects\\paseo"],
["C:\\Users\\Administrator\\GhostFactory\\", "C:\\Users\\Administrator\\GhostFactory"],
[String.raw`\\?\C:\Users\Administrator\GhostFactory`, "C:\\Users\\Administrator\\GhostFactory"],
[String.raw`\\?\UNC\server\share\GhostFactory`, String.raw`\\server\share\GhostFactory`],
])("matches Windows-equivalent cwd forms", (left, right) => {
expect(areEquivalentPaths(left, right)).toBe(true);
expect(createPathEquivalenceMatcher(left)(right)).toBe(true);
});
test("keeps POSIX path casing significant", () => {
expect(
areEquivalentPaths("/Users/Administrator/GhostFactory", "/users/administrator/ghostfactory"),
).toBe(false);
});
test("checks POSIX root containment without prefix false positives", () => {
expect(isPathInsideRoot("/opt/paseo", "/opt/paseo/node_modules/@getpaseo/server")).toBe(true);
expect(isPathInsideRoot("/opt/paseo", "/opt/paseo-other")).toBe(false);
});
test("checks Windows root containment case-insensitively", () => {
expect(
isPathInsideRoot("C:\\Paseo\\node_modules", "c:/paseo/node_modules/@getpaseo/server"),
).toBe(true);
expect(isPathInsideRoot("C:\\Paseo\\node_modules", "C:\\Paseo\\node_modules-other")).toBe(
false,
);
});
test("preserves the casing of Windows relative suffixes", () => {
expect(getRealpathAwareRelativePath("C:\\Repo\\.git", "c:\\repo\\.git\\HEAD")).toBe("HEAD");
expect(
getRealpathAwareRelativePath("C:\\Repo\\.git", "c:\\repo\\.git\\refs\\heads\\FeatureCase"),
).toBe("refs\\heads\\FeatureCase");
});
test.skipIf(process.platform === "win32")(
"derives the contained suffix from a realpath-equivalent root",
() => {
const tempDir = mkdtempSync(join(tmpdir(), "paseo-path-"));
try {
const realRoot = join(tempDir, "real-root");
const nestedPath = join(realRoot, "packages", "app");
const aliasRoot = join(tempDir, "root-alias");
mkdirSync(nestedPath, { recursive: true });
symlinkSync(realRoot, aliasRoot, "dir");
expect(getRealpathAwareRelativePath(aliasRoot, nestedPath)).toBe(join("packages", "app"));
expect(getRealpathAwareRelativePath(aliasRoot, tempDir)).toBeNull();
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
},
);
});