mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 11:09:34 +00:00
feat: separate frontend and backend services
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtemp, mkdir, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { homedir, tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
async function loadSubject() {
|
||||
return import("./directory-browser.ts");
|
||||
}
|
||||
|
||||
test("lists directories and directory symlinks without returning files", async (t) => {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "pi-web-browse-"));
|
||||
try {
|
||||
await mkdir(path.join(root, "project"));
|
||||
await writeFile(path.join(root, "notes.txt"), "test", "utf8");
|
||||
let symlinkCreated = false;
|
||||
try {
|
||||
await symlink(path.join(root, "project"), path.join(root, "linked-project"));
|
||||
symlinkCreated = true;
|
||||
} catch (error) {
|
||||
if (error?.code !== "EPERM") throw error;
|
||||
t.diagnostic("Creating symbolic links requires additional privileges on this platform");
|
||||
}
|
||||
|
||||
const { listDirectories } = await loadSubject();
|
||||
const directories = await listDirectories(root);
|
||||
|
||||
assert.deepEqual(
|
||||
directories.map((entry) => entry.name),
|
||||
symlinkCreated ? ["linked-project", "project"] : ["project"],
|
||||
);
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("expands home-relative paths and rejects missing directories", async () => {
|
||||
const { getBrowseStartDirectory, normalizeDirectory, resolveDirectory } = await loadSubject();
|
||||
assert.equal(getBrowseStartDirectory(), homedir());
|
||||
assert.equal(getBrowseStartDirectory("/project"), "/project");
|
||||
assert.equal(normalizeDirectory("~/project"), path.join(homedir(), "project"));
|
||||
await assert.rejects(resolveDirectory(path.join(tmpdir(), `pi-web-missing-${Date.now()}`)));
|
||||
});
|
||||
|
||||
test("finds parent directories across POSIX and Windows paths", async () => {
|
||||
const { getParentDirectory } = await loadSubject();
|
||||
|
||||
assert.equal(getParentDirectory("/Users/alex/project"), "/Users/alex");
|
||||
assert.equal(getParentDirectory("/"), null);
|
||||
assert.equal(getParentDirectory("C:\\Users\\Alex\\project"), "C:\\Users\\Alex");
|
||||
assert.equal(getParentDirectory("C:\\"), null);
|
||||
});
|
||||
Reference in New Issue
Block a user