mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 09:20:43 +00:00
test: tighten apply patch assertions
This commit is contained in:
@@ -84,7 +84,17 @@ async function expectOutsideWriteRejected(params: {
|
||||
}) {
|
||||
const patch = buildAddFilePatch(params.patchTargetPath);
|
||||
await expect(applyPatch(patch, { cwd: params.dir })).rejects.toThrow(/Path escapes sandbox root/);
|
||||
await expect(fs.readFile(params.outsidePath, "utf8")).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await expectMissingPath(fs.readFile(params.outsidePath, "utf8"));
|
||||
}
|
||||
|
||||
async function expectMissingPath(operation: Promise<unknown>) {
|
||||
let error: NodeJS.ErrnoException | undefined;
|
||||
try {
|
||||
await operation;
|
||||
} catch (caught) {
|
||||
error = caught as NodeJS.ErrnoException;
|
||||
}
|
||||
expect(error?.code).toBe("ENOENT");
|
||||
}
|
||||
|
||||
describe("applyPatch", () => {
|
||||
@@ -232,7 +242,7 @@ describe("applyPatch", () => {
|
||||
await expect(applyPatch(patch, { cwd: dir })).rejects.toThrow(
|
||||
/Symlink escapes sandbox root/,
|
||||
);
|
||||
await expect(fs.readFile(outsideFile, "utf8")).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await expectMissingPath(fs.readFile(outsideFile, "utf8"));
|
||||
} finally {
|
||||
await fs.rm(outsideDir, { recursive: true, force: true });
|
||||
}
|
||||
@@ -376,7 +386,7 @@ describe("applyPatch", () => {
|
||||
|
||||
const result = await applyPatch(patch, { cwd: dir });
|
||||
expect(result.summary.deleted).toEqual(["link"]);
|
||||
await expect(fs.lstat(linkDir)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await expectMissingPath(fs.lstat(linkDir));
|
||||
const outsideContents = await fs.readFile(outsideTarget, "utf8");
|
||||
expect(outsideContents).toBe("keep\n");
|
||||
} finally {
|
||||
@@ -456,9 +466,7 @@ describe("applyPatch", () => {
|
||||
);
|
||||
},
|
||||
});
|
||||
await expect(fs.stat(path.join(outside, "nested"))).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectMissingPath(fs.stat(path.join(outside, "nested")));
|
||||
} finally {
|
||||
await fs.rm(outside, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user