refactor(test): share sandbox fs bridge builder

This commit is contained in:
Peter Steinberger
2026-02-15 15:47:49 +00:00
parent df95ddc771
commit c6c6e9f741
2 changed files with 29 additions and 69 deletions

View File

@@ -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);
}