mirror of
https://github.com/morluto/rea.git
synced 2026-12-01 11:01:11 +00:00
fix(process): compare Windows server paths by native realpath (#15044)
* fix(process): compare Windows server paths by native realpath compareServerPaths returned mismatch for every non-equal Windows path, so case, separator, 8.3, and junction spellings of the running server were reported as registration_path_mismatch. Compare native realpaths on Windows, matching registration identity: a different existing file still mismatches and an unresolvable path stays unknown. * test(process): run the server path identity regression on Windows The injected win32 platform only selects the comparison branch; on the Linux source-test host realpathSync.native still uses POSIX rules, so Windows letter case, separators, and junction behavior were unverified. Add Windows-only spelling cases beside the portable regression and include the file in the curated Windows lane, with the lane guard asserting it stays there. * ci(windows): own the server identity regression in the package lane The Windows lane now runs serverIdentity.test.ts, so the package scope must own that path for the native-host lane ownership check. * docs(process): clarify server path comparison authority --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
1 parent
78c6d4c5a8
commit
60de294646
5 files changed
+96
-2
No files matched your search
@@ -1186,6 +1186,7 @@ jobs:
|
||||
tests/boundary/mcp/advertisedDialect.test.ts
|
||||
tests/boundary/mcp/absoluteLocalPathSchema.test.ts
|
||||
tests/boundary/mcp/toolSchemaValidity.test.ts
|
||||
tests/boundary/mcp/serverIdentity.test.ts
|
||||
tests/boundary/filesystem/safeOutputTree.test.ts
|
||||
tests/boundary/filesystem/safeOutputTreePublication.test.ts
|
||||
tests/boundary/providers/native/artifactProvider.archiveSafety.test.ts
|
||||
|
||||
@@ -324,6 +324,7 @@ const PATH_SCOPES = {
|
||||
"tests/boundary/filesystem/directAnalysisSnapshotReplay.test.ts",
|
||||
"tests/boundary/mcp/rawBinaryMcp.test.ts",
|
||||
"tests/boundary/filesystem/windowsTargetSeparators.test.ts",
|
||||
"tests/boundary/mcp/serverIdentity.test.ts",
|
||||
"src/contracts/advertisedDialect*.ts",
|
||||
"tests/boundary/mcp/advertisedDialect.test.ts",
|
||||
// The advertised absolute-path pattern is host-specific (#7151).
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { statSync } from "node:fs";
|
||||
import { realpathSync, statSync } from "node:fs";
|
||||
import { dirname, basename, resolve } from "node:path";
|
||||
|
||||
import { HOST_PLATFORM } from "../platform/HostPlatform.js";
|
||||
@@ -38,13 +38,22 @@ const compareServerPaths = (
|
||||
expected: string,
|
||||
observed: string,
|
||||
runtime: JavaScriptRuntime["id"],
|
||||
platform: NodeJS.Platform,
|
||||
): "aligned" | "mismatch" | "unknown" => {
|
||||
// Select the registered script the way this runtime does: Node resolves it
|
||||
// lexically, while Bun follows native traversal through a symlink before `..`.
|
||||
const script = normalizeEntrypointPath(expected, runtime) ?? expected;
|
||||
if (script === observed) return "aligned";
|
||||
if (HOST_PLATFORM.platform === "win32") return "mismatch";
|
||||
try {
|
||||
// Windows identity comes from the native realpath, matching registration
|
||||
// identity: case, separators, 8.3 names, and junctions to the same file
|
||||
// canonicalize to one path, while a different file stays a mismatch.
|
||||
// Like the POSIX stat below, this inspects a caller-selected filesystem
|
||||
// path and preserves the shared Windows path contract.
|
||||
if (platform === "win32")
|
||||
return realpathSync.native(script) === realpathSync.native(observed)
|
||||
? "aligned"
|
||||
: "mismatch";
|
||||
const selected = statSync(script, { bigint: true });
|
||||
const running = statSync(observed, { bigint: true });
|
||||
return selected.dev === running.dev && selected.ino === running.ino
|
||||
@@ -65,6 +74,8 @@ export const createServerIdentity = (input: {
|
||||
readonly catalog: ReturnType<typeof createCatalogIdentity>;
|
||||
/** The runtime that selected `commandPath`; defaults to the current one. */
|
||||
readonly runtime?: JavaScriptRuntime["id"];
|
||||
/** The platform whose path identity rules apply; defaults to this host. */
|
||||
readonly platform?: NodeJS.Platform;
|
||||
}) => {
|
||||
const catalog = input.catalog;
|
||||
const serverPath = input.commandPath || undefined;
|
||||
@@ -75,6 +86,7 @@ export const createServerIdentity = (input: {
|
||||
input.expected.server_path,
|
||||
serverPath,
|
||||
input.runtime ?? javaScriptRuntime(process.versions).id,
|
||||
input.platform ?? HOST_PLATFORM.platform,
|
||||
);
|
||||
const reasons: string[] = [];
|
||||
if (
|
||||
|
||||
@@ -188,6 +188,85 @@ it.skipIf(process.platform === "win32")(
|
||||
},
|
||||
);
|
||||
|
||||
it("compares Windows server paths by native realpath identity", async () => {
|
||||
const root = await createTestTempDirectory("server-identity-windows-path-");
|
||||
const scripts = join(root, "package", "scripts");
|
||||
const scratch = join(root, "scratch");
|
||||
await mkdir(scripts, { recursive: true });
|
||||
await mkdir(scratch);
|
||||
const canonical = join(scripts, "rea.mjs");
|
||||
const other = join(root, "other.mjs");
|
||||
await writeFile(canonical, "entrypoint");
|
||||
await writeFile(other, "other entrypoint");
|
||||
await symlink(scripts, join(scratch, "link"), "junction");
|
||||
const identity = (server_path: string) =>
|
||||
createServerIdentity({
|
||||
catalog: DEFAULT_CATALOG_IDENTITY,
|
||||
startedAt: "2026-07-13T00:00:00.000Z",
|
||||
commandPath: canonical,
|
||||
expected: { server_path },
|
||||
runtime: "node",
|
||||
platform: "win32",
|
||||
});
|
||||
|
||||
// A junction spelling of the running file is the same registration, while
|
||||
// a different existing file still mismatches and a missing one is unknown.
|
||||
expect(identity(join(scratch, "link", "rea.mjs")).alignment).toMatchObject({
|
||||
state: "aligned",
|
||||
reasons: [],
|
||||
});
|
||||
expect(identity(other).alignment).toMatchObject({
|
||||
state: "mcp_server_restart_required",
|
||||
reasons: ["registration_path_mismatch"],
|
||||
});
|
||||
expect(identity(join(root, "missing.mjs")).alignment).toMatchObject({
|
||||
state: "unknown",
|
||||
reasons: [],
|
||||
});
|
||||
});
|
||||
|
||||
it.skipIf(process.platform !== "win32")(
|
||||
"compares Windows server path spellings by native identity",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory(
|
||||
"server-identity-windows-spelling-",
|
||||
);
|
||||
const scripts = join(root, "package", "scripts");
|
||||
const scratch = join(root, "scratch");
|
||||
await mkdir(scripts, { recursive: true });
|
||||
await mkdir(scratch);
|
||||
const canonical = join(scripts, "rea.mjs");
|
||||
const other = join(root, "other.mjs");
|
||||
await writeFile(canonical, "entrypoint");
|
||||
await writeFile(other, "other entrypoint");
|
||||
await symlink(scripts, join(scratch, "link"), "junction");
|
||||
const identity = (server_path: string) =>
|
||||
createServerIdentity({
|
||||
catalog: DEFAULT_CATALOG_IDENTITY,
|
||||
startedAt: "2026-07-13T00:00:00.000Z",
|
||||
commandPath: canonical,
|
||||
expected: { server_path },
|
||||
runtime: "node",
|
||||
platform: "win32",
|
||||
});
|
||||
|
||||
// Only the native Windows realpath canonicalizes letter case and
|
||||
// separator spellings of the running file to one identity.
|
||||
expect(identity(join(scratch, "LINK", "REA.MJS")).alignment).toMatchObject({
|
||||
state: "aligned",
|
||||
reasons: [],
|
||||
});
|
||||
expect(identity(canonical.split("\\").join("/")).alignment).toMatchObject({
|
||||
state: "aligned",
|
||||
reasons: [],
|
||||
});
|
||||
expect(identity(other).alignment).toMatchObject({
|
||||
state: "mcp_server_restart_required",
|
||||
reasons: ["registration_path_mismatch"],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("reports the connected client and compares caller expectations against the live catalog", async () => {
|
||||
const session = createTestBinarySession(availabilityProvider());
|
||||
const server = createServer({ kind: "session", session });
|
||||
|
||||
@@ -117,6 +117,7 @@ describe("curated Windows test lane", () => {
|
||||
"tests/boundary/filesystem/directAnalysisSnapshotReplay.test.ts",
|
||||
"tests/boundary/mcp/rawBinaryMcp.test.ts",
|
||||
"tests/boundary/filesystem/windowsTargetSeparators.test.ts",
|
||||
"tests/boundary/mcp/serverIdentity.test.ts",
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user