test(ida): preserve physical workspace traversal controls

This commit is contained in:
morluto
2026-10-24 04:35:00 +08:00
parent fd254b5e37
commit 85292fdb26
2 changed files with 29 additions and 25 deletions
+27 -23
View File
@@ -1,4 +1,4 @@
import { mkdtemp, readdir, rm, writeFile } from "node:fs/promises";
import { mkdir, mkdtemp, readdir, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, expect, it } from "vitest";
@@ -16,28 +16,32 @@ afterEach(async () => {
for (const root of roots.splice(0))
await rm(root, { recursive: true, force: true });
});
it("uses the allocation normalization for readiness without creating entries", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-ida-workspace-parent-"));
roots.push(root);
const path = join(root, "registration.json");
const rawRoot = `${root}/missing/..`;
await writeFile(
path,
JSON.stringify({
command: "python",
mode: "headless",
workspaceRoot: rawRoot,
}),
);
const before = await readdir(root);
const inspection = await inspectIdaRegistration(path, resourceScope);
const after = await readdir(root);
expect(inspection.available).toBe(true);
expect(
inspection.checks.find(({ name }) => name === "private_workspace")?.detail,
).toContain(rawRoot);
expect(after).toEqual(before);
});
it.each([true, false])(
"uses allocation filesystem resolution without creating entries (traversed directory exists=%s)",
async (exists) => {
const root = await mkdtemp(join(tmpdir(), "rea-ida-workspace-parent-"));
roots.push(root);
const path = join(root, "registration.json");
await mkdir(join(root, "existing"));
const rawRoot = exists ? `${root}/existing/..` : `${root}/missing/..`;
await writeFile(
path,
JSON.stringify({
command: "python",
mode: "headless",
workspaceRoot: rawRoot,
}),
);
const before = await readdir(root);
const inspection = await inspectIdaRegistration(path, resourceScope);
const after = await readdir(root);
expect(inspection.available).toBe(exists);
expect(
inspection.checks.find(({ name }) => name === "private_workspace")?.detail,
).toContain(rawRoot);
expect(after).toEqual(before);
},
);
it("marks an unusable system temporary parent unavailable when workspaceRoot is omitted", async () => {
if (process.platform === "win32") return;
@@ -42,9 +42,9 @@ cliTest.skipIf(process.platform !== "darwin").for([true, false])(
const root = await createTestTempDirectory("rea-ida-doctor-parent-");
const parent = join(root, "parent");
await mkdir(parent);
// Keep the caller's unnormalized spelling; allocation normalizes it too.
// Keep the caller's spelling while every traversed component exists.
const workspaceRoot = usable
? `${parent}/missing/../.`
? `${parent}/./`
: join(parent, "absent");
const registration = join(root, "registration.json");
await writeFile(