Archived
fix: list and open sessions across project directories
Sessions outside the server's launch directory were invisible and returned 404 on open, leaving the model picker empty. List without the SDK's process-cwd filter and normalize working directories at the API boundary and when reading stored session data, tolerating separator/normalization differences (including Windows backslash vs forward slash). Requires Pi coding agent SDK 0.78.0 or newer.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { join, sep } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { canonicalizeStoredCwd, cwdPathsEqual, normalizeRequestCwd } from "./workingDirectory.js";
|
||||
|
||||
const absoluteBase = join(sep, "srv", "projects", "demo");
|
||||
|
||||
describe("normalizeRequestCwd", () => {
|
||||
it("returns absolute paths in canonical form", () => {
|
||||
expect(normalizeRequestCwd(absoluteBase)).toBe(absoluteBase);
|
||||
expect(normalizeRequestCwd(`${absoluteBase}${sep}`)).toBe(absoluteBase);
|
||||
expect(normalizeRequestCwd(join(absoluteBase, ".", "nested", ".."))).toBe(absoluteBase);
|
||||
});
|
||||
|
||||
it("treats Windows backslash and forward-slash paths as equal", () => {
|
||||
if (process.platform !== "win32") return;
|
||||
expect(normalizeRequestCwd("C:/Users/dev/project")).toBe("C:\\Users\\dev\\project");
|
||||
});
|
||||
|
||||
it("rejects missing, empty, and non-string values", () => {
|
||||
expect(() => normalizeRequestCwd(undefined)).toThrow("cwd is required");
|
||||
expect(() => normalizeRequestCwd("")).toThrow("cwd is required");
|
||||
expect(() => normalizeRequestCwd(42)).toThrow("cwd is required");
|
||||
});
|
||||
|
||||
it("rejects relative paths instead of resolving them against the process cwd", () => {
|
||||
expect(() => normalizeRequestCwd("relative/path")).toThrow("cwd must be an absolute path");
|
||||
expect(() => normalizeRequestCwd(".")).toThrow("cwd must be an absolute path");
|
||||
});
|
||||
});
|
||||
|
||||
describe("canonicalizeStoredCwd", () => {
|
||||
it("canonicalizes absolute paths", () => {
|
||||
expect(canonicalizeStoredCwd(`${absoluteBase}${sep}`)).toBe(absoluteBase);
|
||||
});
|
||||
|
||||
it("preserves legacy empty and relative values instead of resolving against the process cwd", () => {
|
||||
expect(canonicalizeStoredCwd("")).toBe("");
|
||||
expect(canonicalizeStoredCwd("relative/path")).toBe("relative/path");
|
||||
});
|
||||
});
|
||||
|
||||
describe("cwdPathsEqual", () => {
|
||||
it("matches paths that differ only by normalization", () => {
|
||||
expect(cwdPathsEqual(absoluteBase, `${absoluteBase}${sep}`)).toBe(true);
|
||||
expect(cwdPathsEqual(absoluteBase, join(absoluteBase, "."))).toBe(true);
|
||||
});
|
||||
|
||||
it("treats Windows backslash and forward-slash paths as equal", () => {
|
||||
if (process.platform !== "win32") return;
|
||||
expect(cwdPathsEqual("C:\\Users\\dev\\project", "C:/Users/dev/project")).toBe(true);
|
||||
});
|
||||
|
||||
it("distinguishes different paths", () => {
|
||||
expect(cwdPathsEqual(join(absoluteBase, "a"), join(absoluteBase, "b"))).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user