fix(coding-agent): restore path alias equivalence

Fixes #935
This commit is contained in:
can1357
2026-05-06 17:23:33 +02:00
parent f55b315165
commit ba2affae7f
4 changed files with 25 additions and 20 deletions
+10 -10
View File
@@ -10,7 +10,15 @@ import * as os from "node:os";
import * as path from "node:path";
import { createInterface } from "node:readline/promises";
import type { ImageContent } from "@oh-my-pi/pi-ai";
import { $env, getProjectDir, logger, postmortem, setProjectDir, VERSION } from "@oh-my-pi/pi-utils";
import {
$env,
getProjectDir,
logger,
normalizePathForComparison,
postmortem,
setProjectDir,
VERSION,
} from "@oh-my-pi/pi-utils";
import chalk from "chalk";
import type { Args } from "./cli/args";
import { processFileArguments } from "./cli/file-processor";
@@ -215,11 +223,6 @@ async function runInteractiveMode(
}
}
function normalizePathForComparison(value: string): string {
const resolved = path.resolve(value);
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
}
async function promptForkSession(session: SessionInfo): Promise<boolean> {
if (!process.stdin.isTTY) {
return false;
@@ -348,10 +351,7 @@ async function maybeAutoChdir(parsed: Args): Promise<void> {
return;
}
const normalizePath = (value: string) => {
const resolved = path.resolve(value);
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
};
const normalizePath = normalizePathForComparison;
const cwd = normalizePath(getProjectDir());
const normalizedHome = normalizePath(home);
@@ -9,7 +9,7 @@ export interface IsolationBackendResolution {
warning: string;
}
type ProcessorEnv = Pick<NodeJS.ProcessEnv, "PROCESSOR_ARCHITECTURE" | "PROCESSOR_ARCHITEW6432">;
type ProcessorEnv = Partial<Pick<NodeJS.ProcessEnv, "PROCESSOR_ARCHITECTURE" | "PROCESSOR_ARCHITEW6432">>;
function isWindowsArm64HostUnderX64Emulation(
platform: NodeJS.Platform,
@@ -28,7 +28,7 @@ export async function resolveIsolationBackendForTaskExecution(
repoRoot: string | null,
platform: NodeJS.Platform = process.platform,
arch: NodeJS.Architecture = process.arch,
env: ProcessorEnv = process.env,
env: ProcessorEnv = process.env as ProcessorEnv,
): Promise<IsolationBackendResolution> {
let effectiveIsolationMode = requestedMode;
let warning = "";
+6 -1
View File
@@ -48,7 +48,12 @@ function standardizeMacOSPath(p: string): string {
}
export function resolveEquivalentPath(inputPath: string): string {
return path.resolve(inputPath);
const resolvedPath = path.resolve(inputPath);
try {
return fs.realpathSync(resolvedPath);
} catch {
return resolvedPath;
}
}
export function normalizePathForComparison(inputPath: string): string {
+7 -7
View File
@@ -8,15 +8,15 @@ describe("issue #935 path equivalence", () => {
vi.restoreAllMocks();
});
it("preserves the lexical project path instead of canonicalizing symlink or junction targets", () => {
it("falls back to the lexical project path when realpath fails", () => {
const inputPath = path.resolve("/sessions/link-project");
const targetPath = path.resolve("/sessions/real-project");
const realpathSpy = vi.spyOn(fs, "realpathSync").mockImplementation(((p: fs.PathLike) => {
if (path.resolve(String(p)) === inputPath) return targetPath;
return path.resolve(String(p));
}) as typeof fs.realpathSync);
const realpathSpy = vi.spyOn(fs, "realpathSync").mockImplementation((() => {
const error = new Error("ENOENT: no such file or directory, realpath");
(error as NodeJS.ErrnoException).code = "ENOENT";
throw error;
}) as unknown as typeof fs.realpathSync);
expect(resolveEquivalentPath(inputPath)).toBe(inputPath);
expect(realpathSpy).not.toHaveBeenCalled();
expect(realpathSpy).toHaveBeenCalledWith(inputPath);
});
});