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

@@ -3,6 +3,7 @@ import { resolveSandboxInputPath, resolveSandboxPath } from "../sandbox-paths.js
import { splitSandboxBindSpec } from "./bind-spec.js";
import { SANDBOX_AGENT_WORKSPACE_MOUNT } from "./constants.js";
import { resolveSandboxHostPathViaExistingAncestor } from "./host-paths.js";
import { isPathInsideContainerRoot, normalizeContainerPath } from "./path-utils.js";
import type { SandboxContext } from "./types.js";
export type SandboxFsMount = {
@@ -201,7 +202,7 @@ function dedupeMounts(mounts: SandboxFsMount[]): SandboxFsMount[] {
function findMountByContainerPath(mounts: SandboxFsMount[], target: string): SandboxFsMount | null {
for (const mount of mounts) {
if (isPathInsidePosix(mount.containerRoot, target)) {
if (isPathInsideContainerRoot(mount.containerRoot, target)) {
return mount;
}
}
@@ -217,14 +218,6 @@ function findMountByHostPath(mounts: SandboxFsMount[], target: string): SandboxF
return null;
}
function isPathInsidePosix(root: string, target: string): boolean {
const rel = path.posix.relative(root, target);
if (!rel) {
return true;
}
return !(rel.startsWith("..") || path.posix.isAbsolute(rel));
}
function isPathInsideHost(root: string, target: string): boolean {
const canonicalRoot = resolveSandboxHostPathViaExistingAncestor(path.resolve(root));
const resolvedTarget = path.resolve(target);
@@ -259,11 +252,6 @@ function toDisplayRelative(params: {
return params.containerPath;
}
function normalizeContainerPath(value: string): string {
const normalized = path.posix.normalize(value);
return normalized === "." ? "/" : normalized;
}
function normalizePosixInput(value: string): string {
return value.replace(/\\/g, "/").trim();
}