mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 11:01:24 +00:00
refactor(test): share sandbox fs bridge builder
This commit is contained in:
@@ -3,26 +3,9 @@ import path from "node:path";
|
||||
import type { SandboxFsBridge, SandboxFsStat, SandboxResolvedPath } from "../sandbox/fs-bridge.js";
|
||||
import { resolveSandboxPath } from "../sandbox-paths.js";
|
||||
|
||||
export function createHostSandboxFsBridge(rootDir: string): SandboxFsBridge {
|
||||
const root = path.resolve(rootDir);
|
||||
|
||||
const resolvePath = (filePath: string, cwd?: string): SandboxResolvedPath => {
|
||||
const resolved = resolveSandboxPath({
|
||||
filePath,
|
||||
cwd: cwd ?? root,
|
||||
root,
|
||||
});
|
||||
const relativePath = resolved.relative
|
||||
? resolved.relative.split(path.sep).filter(Boolean).join(path.posix.sep)
|
||||
: "";
|
||||
const containerPath = relativePath ? path.posix.join("/workspace", relativePath) : "/workspace";
|
||||
return {
|
||||
hostPath: resolved.resolved,
|
||||
relativePath,
|
||||
containerPath,
|
||||
};
|
||||
};
|
||||
|
||||
export function createSandboxFsBridgeFromResolver(
|
||||
resolvePath: (filePath: string, cwd?: string) => SandboxResolvedPath,
|
||||
): SandboxFsBridge {
|
||||
return {
|
||||
resolvePath: ({ filePath, cwd }) => resolvePath(filePath, cwd),
|
||||
readFile: async ({ filePath, cwd }) => {
|
||||
@@ -72,3 +55,26 @@ export function createHostSandboxFsBridge(rootDir: string): SandboxFsBridge {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function createHostSandboxFsBridge(rootDir: string): SandboxFsBridge {
|
||||
const root = path.resolve(rootDir);
|
||||
|
||||
const resolvePath = (filePath: string, cwd?: string): SandboxResolvedPath => {
|
||||
const resolved = resolveSandboxPath({
|
||||
filePath,
|
||||
cwd: cwd ?? root,
|
||||
root,
|
||||
});
|
||||
const relativePath = resolved.relative
|
||||
? resolved.relative.split(path.sep).filter(Boolean).join(path.posix.sep)
|
||||
: "";
|
||||
const containerPath = relativePath ? path.posix.join("/workspace", relativePath) : "/workspace";
|
||||
return {
|
||||
hostPath: resolved.resolved,
|
||||
relativePath,
|
||||
containerPath,
|
||||
};
|
||||
};
|
||||
|
||||
return createSandboxFsBridgeFromResolver(resolvePath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user