refactor(sandbox): share container-path utils and tighten fs bridge tests

This commit is contained in:
Peter Steinberger
2026-02-25 01:59:43 +00:00
parent c736778b3f
commit eb4a93a8db
5 changed files with 41 additions and 30 deletions

View File

@@ -8,6 +8,7 @@ import {
type SandboxResolvedFsPath,
type SandboxFsMount,
} from "./fs-paths.js";
import { isPathInsideContainerRoot, normalizeContainerPath } from "./path-utils.js";
import type { SandboxContext, SandboxWorkspaceAccess } from "./types.js";
type RunCommandOptions = {
@@ -277,7 +278,7 @@ class SandboxFsBridgeImpl implements SandboxFsBridge {
private resolveMountByContainerPath(containerPath: string): SandboxFsMount | null {
const normalized = normalizeContainerPath(containerPath);
for (const mount of this.mountsByContainer) {
if (isPathInsidePosix(normalizeContainerPath(mount.containerRoot), normalized)) {
if (isPathInsideContainerRoot(normalizeContainerPath(mount.containerRoot), normalized)) {
return mount;
}
}
@@ -351,18 +352,6 @@ function coerceStatType(typeRaw?: string): "file" | "directory" | "other" {
return "other";
}
function normalizeContainerPath(value: string): string {
const normalized = path.posix.normalize(value);
return normalized === "." ? "/" : normalized;
}
function isPathInsidePosix(root: string, target: string): boolean {
if (root === "/") {
return true;
}
return target === root || target.startsWith(`${root}/`);
}
async function assertNoHostSymlinkEscape(params: {
absolutePath: string;
rootPath: string;