mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-25 01:35:31 +00:00
Preserve conversations when directory capitalization differs (#10555)
* Use the filesystem’s capitalization in directory suggestions * fix(server): preserve conversations across path casing changes A case-insensitive volume can resolve the old and new record paths to the file installed by the same atomic write. Check file identity before removing the old entry so startup recovery preserves both the record and its workspace. * fix(server): keep case-only symlink names in directory suggestions A case-sensitive volume can store a symlink whose name differs from its target only by capitalization. Inspect the changed components before using the resolved spelling so Add Project receives the visible path. * fix(server): preserve symlinks under case-distinct parents A symlink can point into a parent whose name differs only in case while keeping the same basename. Inspect each changed path component before choosing the resolved spelling. --------- Co-authored-by: yz <43207690+yzim@users.noreply.github.com>
This commit is contained in:
@@ -299,10 +299,7 @@ jobs:
|
||||
run: npm run test:integration --workspace=@getpaseo/server
|
||||
env: *server_test_env
|
||||
|
||||
# native-recursive.ts serves darwin and win32, but windows-latest above is the only
|
||||
# runner that exercises it. macOS — the platform the reported watcher bug was on —
|
||||
# otherwise has no server-test coverage. Keep this job scoped to regressions
|
||||
# reported on macOS.
|
||||
# Keep this job scoped to regressions reported on macOS.
|
||||
server-tests-macos:
|
||||
name: server-tests (macos-latest, file observation)
|
||||
needs: changes
|
||||
@@ -330,6 +327,13 @@ jobs:
|
||||
src/server/workspace-git-service.observation.integration.test.ts \
|
||||
--bail=1
|
||||
|
||||
- name: Verify path casing on macOS
|
||||
run: |
|
||||
npm run test:unit --workspace=@getpaseo/server -- \
|
||||
src/server/agent/agent-storage.test.ts \
|
||||
src/utils/directory-suggestions.test.ts \
|
||||
--bail=1
|
||||
|
||||
- name: Verify plugin compiler children are reaped
|
||||
run: |
|
||||
npm run test:unit --workspace=@getpaseo/server -- \
|
||||
|
||||
@@ -156,6 +156,60 @@ describe("AgentStorage", () => {
|
||||
rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test("preserves records after saving and reloading a directory with different capitalization", async () => {
|
||||
const cwd = path.join(tmpDir, "Work");
|
||||
const alternateCwd = path.join(tmpDir, "work");
|
||||
await fs.mkdir(cwd);
|
||||
const needsAlias = !existsSync(alternateCwd);
|
||||
if (needsAlias) await fs.symlink(cwd, alternateCwd, "junction");
|
||||
const timestamp = "2026-01-01T00:00:00.000Z";
|
||||
const first = {
|
||||
id: "first",
|
||||
provider: "codex",
|
||||
cwd,
|
||||
workspaceId: "one",
|
||||
createdAt: timestamp,
|
||||
updatedAt: timestamp,
|
||||
labels: {},
|
||||
};
|
||||
const second = { ...first, id: "second", workspaceId: "two" };
|
||||
await storage.upsert(first);
|
||||
await storage.upsert(second);
|
||||
|
||||
// An existing record can use one cwd spelling in JSON and another in its path.
|
||||
const recordPath = findRecordFile(storagePath, first.id);
|
||||
if (needsAlias) {
|
||||
// Exercise the same on-disk alias on case-sensitive CI filesystems.
|
||||
const recordDir = path.dirname(recordPath);
|
||||
await fs.symlink(recordDir, recordDir.replace(/Work$/, "work"), "junction");
|
||||
}
|
||||
await fs.writeFile(recordPath, JSON.stringify({ ...first, cwd: alternateCwd }));
|
||||
const loaded = new AgentStorage(storagePath, logger);
|
||||
const saved = { ...first, cwd: alternateCwd, title: "Updated conversation" };
|
||||
await loaded.upsert(saved);
|
||||
|
||||
const restarted = new AgentStorage(storagePath, logger);
|
||||
await expect(restarted.listByWorkspace("one")).resolves.toMatchObject([saved]);
|
||||
await expect(restarted.listByWorkspace("two")).resolves.toMatchObject([second]);
|
||||
expect((await fs.readdir(path.dirname(recordPath))).sort()).toEqual([
|
||||
`${first.id}.json`,
|
||||
`${second.id}.json`,
|
||||
]);
|
||||
});
|
||||
|
||||
test("removes the previous record file when the cwd moves to a distinct directory", async () => {
|
||||
const id = "moved-agent";
|
||||
await storage.applySnapshot(createManagedAgent({ id, cwd: "/tmp/first-project" }));
|
||||
const previousPath = findRecordFile(storagePath, id);
|
||||
await storage.applySnapshot(createManagedAgent({ id, cwd: "/tmp/second-project" }));
|
||||
|
||||
expect(existsSync(previousPath)).toBe(false);
|
||||
await expect(new AgentStorage(storagePath, logger).get(id)).resolves.toMatchObject({
|
||||
id,
|
||||
cwd: "/tmp/second-project",
|
||||
});
|
||||
});
|
||||
|
||||
test("workspace and active queries follow updates, removal, and reload", async () => {
|
||||
const base = {
|
||||
provider: "codex",
|
||||
|
||||
@@ -340,7 +340,15 @@ export class AgentStorage {
|
||||
|
||||
if (previousPath && previousPath !== nextPath) {
|
||||
try {
|
||||
await fs.unlink(previousPath);
|
||||
// Compare the entries after the atomic replacement. On a case-insensitive
|
||||
// volume both spellings can now address the file we just wrote.
|
||||
const [previous, next] = await Promise.all([
|
||||
fs.lstat(previousPath, { bigint: true }),
|
||||
fs.lstat(nextPath, { bigint: true }),
|
||||
]);
|
||||
if (previous.dev !== next.dev || previous.ino !== next.ino) {
|
||||
await fs.unlink(previousPath);
|
||||
}
|
||||
} catch {
|
||||
// ignore cleanup errors
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createHook } from "node:async_hooks";
|
||||
import { execFileSync, spawn, type ChildProcess } from "node:child_process";
|
||||
import {
|
||||
existsSync,
|
||||
mkdtempSync,
|
||||
mkdirSync,
|
||||
realpathSync,
|
||||
@@ -780,6 +781,50 @@ describe("rooted queries with a typed parent", () => {
|
||||
).resolves.toEqual([path.join(homeDir, "Developer", "pasta")]);
|
||||
});
|
||||
|
||||
it.for(["~/developer/pas", "~/developer/PASTA"])(
|
||||
"returns the on-disk spelling exactly once for %s",
|
||||
async (query, { skip }) => {
|
||||
if (!existsSync(path.join(homeDir, "developer"))) {
|
||||
skip("Requires a case-insensitive filesystem");
|
||||
}
|
||||
await expect(searchAbsoluteDirectoryPaths({ homeDir, query })).resolves.toEqual([
|
||||
path.join(homeDir, "Developer", "pasta"),
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
it.for(["~/developer/pas", "~/developer/pasta", "~/developer/"])(
|
||||
"keeps the visible spelling of a symlink for %s",
|
||||
async (query, { skip }) => {
|
||||
const link = path.join(homeDir, "developer");
|
||||
if (existsSync(link)) skip("Requires a case-sensitive filesystem");
|
||||
symlinkSync(path.join(homeDir, "Developer"), link, "junction");
|
||||
|
||||
const suggestions = await searchAbsoluteDirectoryPaths({ homeDir, query });
|
||||
expect(suggestions).toContain(path.join(link, "pasta"));
|
||||
expect(suggestions).not.toContain(path.join(homeDir, "Developer", "pasta"));
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps a symlink under a parent whose spelling differs from the target's parent", async ({
|
||||
skip,
|
||||
}) => {
|
||||
const parent = path.join(homeDir, "developer");
|
||||
if (existsSync(parent)) skip("Requires a case-sensitive filesystem");
|
||||
const target = path.join(homeDir, "Developer", "pasta");
|
||||
const link = path.join(parent, "pasta");
|
||||
mkdirSync(parent);
|
||||
mkdirSync(path.join(target, "children"));
|
||||
symlinkSync(target, link, "junction");
|
||||
|
||||
await expect(
|
||||
searchAbsoluteDirectoryPaths({ homeDir, query: "~/developer/pasta", limit: 1 }),
|
||||
).resolves.toEqual([link]);
|
||||
await expect(
|
||||
searchAbsoluteDirectoryPaths({ homeDir, query: "~/developer/pasta/ch" }),
|
||||
).resolves.toEqual([path.join(link, "children")]);
|
||||
});
|
||||
|
||||
it("matches the whole tree when the typed parent does not exist", async () => {
|
||||
await expect(searchAbsoluteDirectoryPaths({ homeDir, query: "~/Devel/pas" })).resolves.toEqual([
|
||||
path.join(homeDir, "Developer", "pasta"),
|
||||
|
||||
@@ -233,7 +233,30 @@ async function resolveTypedParent(input: SearchInput): Promise<WalkStart | null>
|
||||
const resolvedPath = await realpath(visiblePath).catch(() => null);
|
||||
if (!resolvedPath || !isPathInsideRoot(input.root, resolvedPath)) return null;
|
||||
const info = await stat(resolvedPath).catch(() => null);
|
||||
return info?.isDirectory() ? { visiblePath, resolvedPath } : null;
|
||||
if (!info?.isDirectory()) return null;
|
||||
return {
|
||||
visiblePath: await withResolvedSpelling(visiblePath, resolvedPath),
|
||||
resolvedPath,
|
||||
};
|
||||
}
|
||||
|
||||
async function withResolvedSpelling(visiblePath: string, resolvedPath: string): Promise<string> {
|
||||
if (visiblePath.toLowerCase() !== resolvedPath.toLowerCase()) return visiblePath;
|
||||
|
||||
// Check the entire changed suffix. A symlink can keep its basename while redirecting
|
||||
// into a parent directory that differs only in case.
|
||||
let visible = visiblePath;
|
||||
let resolved = resolvedPath;
|
||||
while (visible !== resolved && visible !== path.parse(visible).root) {
|
||||
const entryPath = visible;
|
||||
const entry = await sharedFilesystemCall(`lstat:${entryPath}`, () => fs.lstat(entryPath)).catch(
|
||||
() => null,
|
||||
);
|
||||
if (!entry || entry.isSymbolicLink()) return visiblePath;
|
||||
visible = path.dirname(visible);
|
||||
resolved = path.dirname(resolved);
|
||||
}
|
||||
return resolvedPath;
|
||||
}
|
||||
|
||||
async function resolveExistingPaths(paths: readonly string[]): Promise<Set<string>> {
|
||||
@@ -296,7 +319,8 @@ async function findExactEntry(input: SearchInput): Promise<DirectorySuggestionEn
|
||||
(kind === "file" && !input.includeFiles)
|
||||
)
|
||||
return null;
|
||||
return formatEntry({ path: visiblePath, kind }, input.root, input.pathFormat);
|
||||
const entryPath = await withResolvedSpelling(visiblePath, resolvedPath);
|
||||
return formatEntry({ path: entryPath, kind }, input.root, input.pathFormat);
|
||||
}
|
||||
|
||||
interface SearchInput {
|
||||
@@ -317,10 +341,11 @@ interface SearchInput {
|
||||
}
|
||||
|
||||
async function searchChildren(input: SearchInput): Promise<RankedEntry[]> {
|
||||
const visibleParent = path.resolve(input.root, input.plan.parentPart || ".");
|
||||
const parent = await realpath(visibleParent).catch(() => null);
|
||||
const typedParent = path.resolve(input.root, input.plan.parentPart || ".");
|
||||
const parent = await realpath(typedParent).catch(() => null);
|
||||
if (!parent || !isPathInsideRoot(input.root, parent)) return [];
|
||||
if (isGitIgnoredPath(parent, input)) return [];
|
||||
const visibleParent = await withResolvedSpelling(typedParent, parent);
|
||||
// Browsing inside an excluded path is explicit: the caller typed it, so list what is there.
|
||||
const discoveryInput = isInsideExcludedPath(parent, input)
|
||||
? { ...input, excludedDiscoveryPaths: new Set<string>() }
|
||||
|
||||
Reference in New Issue
Block a user