mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 04:30:22 +00:00
feat: add remote openshell sandbox mode
This commit is contained in:
@@ -361,4 +361,46 @@ describe("applyPatch", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("uses container paths when the sandbox bridge has no local host path", async () => {
|
||||
const files = new Map<string, string>([["/sandbox/source.txt", "before\n"]]);
|
||||
const bridge = {
|
||||
resolvePath: ({ filePath }: { filePath: string }) => ({
|
||||
relativePath: filePath,
|
||||
containerPath: `/sandbox/${filePath}`,
|
||||
}),
|
||||
readFile: vi.fn(async ({ filePath }: { filePath: string }) =>
|
||||
Buffer.from(files.get(filePath) ?? "", "utf8"),
|
||||
),
|
||||
writeFile: vi.fn(async ({ filePath, data }: { filePath: string; data: Buffer | string }) => {
|
||||
files.set(filePath, Buffer.isBuffer(data) ? data.toString("utf8") : data);
|
||||
}),
|
||||
remove: vi.fn(async ({ filePath }: { filePath: string }) => {
|
||||
files.delete(filePath);
|
||||
}),
|
||||
mkdirp: vi.fn(async () => {}),
|
||||
};
|
||||
|
||||
const patch = `*** Begin Patch
|
||||
*** Update File: source.txt
|
||||
@@
|
||||
-before
|
||||
+after
|
||||
*** End Patch`;
|
||||
|
||||
const result = await applyPatch(patch, {
|
||||
cwd: "/local/workspace",
|
||||
sandbox: {
|
||||
root: "/local/workspace",
|
||||
bridge: bridge as never,
|
||||
},
|
||||
});
|
||||
|
||||
expect(files.get("/sandbox/source.txt")).toBe("after\n");
|
||||
expect(result.summary.modified).toEqual(["source.txt"]);
|
||||
expect(bridge.readFile).toHaveBeenCalledWith({
|
||||
filePath: "/sandbox/source.txt",
|
||||
cwd: "/local/workspace",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user