mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-20 21:23:23 +00:00
test: trim fs bridge partial mocks
This commit is contained in:
1
src/agents/sandbox/fs-bridge-path-safety.runtime.ts
Normal file
1
src/agents/sandbox/fs-bridge-path-safety.runtime.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { openBoundaryFile, type BoundaryFileOpenResult } from "../../infra/boundary-file-read.js";
|
||||
@@ -1,8 +1,8 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { openBoundaryFile, type BoundaryFileOpenResult } from "../../infra/boundary-file-read.js";
|
||||
import type { PathAliasPolicy } from "../../infra/path-alias-guards.js";
|
||||
import type { SafeOpenSyncAllowedType } from "../../infra/safe-open-sync.js";
|
||||
import { openBoundaryFile, type BoundaryFileOpenResult } from "./fs-bridge-path-safety.runtime.js";
|
||||
import type { SandboxResolvedFsPath, SandboxFsMount } from "./fs-paths.js";
|
||||
import { isPathInsideContainerRoot, normalizeContainerPath } from "./path-utils.js";
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ describe("sandbox fs bridge anchored ops", () => {
|
||||
const opCall = mockedExecDockerRaw.mock.calls.find(
|
||||
([args]) =>
|
||||
typeof args[5] === "string" &&
|
||||
args[5].includes("python3 /dev/fd/3 \"$@\" 3<<'PY'") &&
|
||||
args[5].includes('exec "$python_cmd" -c "$python_script" "$@"') &&
|
||||
getDockerArg(args, 1) === testCase.expectedArgs[0],
|
||||
);
|
||||
expect(opCall).toBeDefined();
|
||||
|
||||
@@ -132,9 +132,9 @@ describe("sandbox fs bridge shell compatibility", () => {
|
||||
|
||||
const scripts = getScriptsFromCalls();
|
||||
expect(scripts.some((script) => script.includes("python3 - \"$@\" <<'PY'"))).toBe(false);
|
||||
expect(scripts.some((script) => script.includes("python3 /dev/fd/3 \"$@\" 3<<'PY'"))).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
scripts.some((script) => script.includes('exec "$python_cmd" -c "$python_script" "$@"')),
|
||||
).toBe(true);
|
||||
expect(scripts.some((script) => script.includes('cat >"$1"'))).toBe(false);
|
||||
expect(scripts.some((script) => script.includes('cat >"$tmp"'))).toBe(false);
|
||||
expect(scripts.some((script) => script.includes("os.replace("))).toBe(true);
|
||||
|
||||
@@ -4,7 +4,7 @@ import path from "node:path";
|
||||
import { beforeEach, expect, vi, type Mock } from "vitest";
|
||||
|
||||
type ExecDockerRawFn = typeof import("./docker.js").execDockerRaw;
|
||||
type OpenBoundaryFileFn = typeof import("../../infra/boundary-file-read.js").openBoundaryFile;
|
||||
type OpenBoundaryFileFn = typeof import("./fs-bridge-path-safety.runtime.js").openBoundaryFile;
|
||||
type ExecDockerArgs = Parameters<ExecDockerRawFn>[0];
|
||||
type ExecDockerRawMock = Mock<ExecDockerRawFn>;
|
||||
type OpenBoundaryFileMock = Mock<OpenBoundaryFileFn>;
|
||||
@@ -27,8 +27,10 @@ vi.mock("./docker.js", () => ({
|
||||
hoisted.execDockerRaw(args, opts),
|
||||
}));
|
||||
|
||||
vi.mock("../../infra/boundary-file-read.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../../infra/boundary-file-read.js")>();
|
||||
vi.mock("./fs-bridge-path-safety.runtime.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./fs-bridge-path-safety.runtime.js")>(
|
||||
"./fs-bridge-path-safety.runtime.js",
|
||||
);
|
||||
actualOpenBoundaryFile = actual.openBoundaryFile;
|
||||
return {
|
||||
...actual,
|
||||
@@ -48,8 +50,10 @@ async function loadFreshFsBridgeModuleForTest() {
|
||||
execDockerRaw: (args: ExecDockerArgs, opts?: Parameters<ExecDockerRawFn>[1]) =>
|
||||
hoisted.execDockerRaw(args, opts),
|
||||
}));
|
||||
vi.doMock("../../infra/boundary-file-read.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../../infra/boundary-file-read.js")>();
|
||||
vi.doMock("./fs-bridge-path-safety.runtime.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./fs-bridge-path-safety.runtime.js")>(
|
||||
"./fs-bridge-path-safety.runtime.js",
|
||||
);
|
||||
actualOpenBoundaryFile = actual.openBoundaryFile;
|
||||
return {
|
||||
...actual,
|
||||
|
||||
Reference in New Issue
Block a user