fix: honor sandboxed built-in tools

This commit is contained in:
Peter Steinberger
2026-01-07 06:12:56 +00:00
parent 03928106c7
commit 50dec39d13
3 changed files with 99 additions and 17 deletions

View File

@@ -1,6 +1,10 @@
import type { AgentTool } from "@mariozechner/pi-agent-core";
import { Type } from "@sinclair/typebox";
import { describe, expect, it } from "vitest";
import { buildEmbeddedSandboxInfo } from "./pi-embedded-runner.js";
import {
buildEmbeddedSandboxInfo,
splitSdkTools,
} from "./pi-embedded-runner.js";
import type { SandboxContext } from "./sandbox.js";
describe("buildEmbeddedSandboxInfo", () => {
@@ -45,3 +49,52 @@ describe("buildEmbeddedSandboxInfo", () => {
});
});
});
function createStubTool(name: string): AgentTool {
return {
name,
label: name,
description: "",
parameters: Type.Object({}),
execute: async () => ({ content: [], details: {} }),
};
}
describe("splitSdkTools", () => {
const tools = [
createStubTool("read"),
createStubTool("bash"),
createStubTool("edit"),
createStubTool("write"),
createStubTool("browser"),
];
it("routes built-ins to custom tools when sandboxed", () => {
const { builtInTools, customTools } = splitSdkTools({
tools,
sandboxEnabled: true,
});
expect(builtInTools).toEqual([]);
expect(customTools.map((tool) => tool.name)).toEqual([
"read",
"bash",
"edit",
"write",
"browser",
]);
});
it("keeps built-ins as SDK tools when not sandboxed", () => {
const { builtInTools, customTools } = splitSdkTools({
tools,
sandboxEnabled: false,
});
expect(builtInTools.map((tool) => tool.name)).toEqual([
"read",
"bash",
"edit",
"write",
]);
expect(customTools.map((tool) => tool.name)).toEqual(["browser"]);
});
});