test: consolidate pi-tools gating assertions

This commit is contained in:
Peter Steinberger
2026-02-23 19:59:54 +00:00
parent cba8037d90
commit 63e4dfaa9c
2 changed files with 12 additions and 22 deletions

View File

@@ -51,13 +51,12 @@ describe("createOpenClawCodingTools", () => {
expect(values.size).toBeGreaterThanOrEqual(min);
}
});
it("includes exec and process tools by default", () => {
it("enforces apply_patch availability and canonical names across model/provider constraints", () => {
expect(defaultTools.some((tool) => tool.name === "exec")).toBe(true);
expect(defaultTools.some((tool) => tool.name === "process")).toBe(true);
expect(defaultTools.some((tool) => tool.name === "apply_patch")).toBe(false);
});
it("gates apply_patch behind tools.exec.applyPatch for OpenAI models", () => {
const config: OpenClawConfig = {
const enabledConfig: OpenClawConfig = {
tools: {
exec: {
applyPatch: { enabled: true },
@@ -65,21 +64,20 @@ describe("createOpenClawCodingTools", () => {
},
};
const openAiTools = createOpenClawCodingTools({
config,
config: enabledConfig,
modelProvider: "openai",
modelId: "gpt-5.2",
});
expect(openAiTools.some((tool) => tool.name === "apply_patch")).toBe(true);
const anthropicTools = createOpenClawCodingTools({
config,
config: enabledConfig,
modelProvider: "anthropic",
modelId: "claude-opus-4-5",
});
expect(anthropicTools.some((tool) => tool.name === "apply_patch")).toBe(false);
});
it("respects apply_patch allowModels", () => {
const config: OpenClawConfig = {
const allowModelsConfig: OpenClawConfig = {
tools: {
exec: {
applyPatch: { enabled: true, allowModels: ["gpt-5.2"] },
@@ -87,25 +85,24 @@ describe("createOpenClawCodingTools", () => {
},
};
const allowed = createOpenClawCodingTools({
config,
config: allowModelsConfig,
modelProvider: "openai",
modelId: "gpt-5.2",
});
expect(allowed.some((tool) => tool.name === "apply_patch")).toBe(true);
const denied = createOpenClawCodingTools({
config,
config: allowModelsConfig,
modelProvider: "openai",
modelId: "gpt-5-mini",
});
expect(denied.some((tool) => tool.name === "apply_patch")).toBe(false);
});
it("keeps canonical tool names for Anthropic OAuth (pi-ai remaps on the wire)", () => {
const tools = createOpenClawCodingTools({
const oauthTools = createOpenClawCodingTools({
modelProvider: "anthropic",
modelAuthMode: "oauth",
});
const names = new Set(tools.map((tool) => tool.name));
const names = new Set(oauthTools.map((tool) => tool.name));
expect(names.has("exec")).toBe(true);
expect(names.has("read")).toBe(true);
expect(names.has("write")).toBe(true);

View File

@@ -90,11 +90,4 @@ describe("createOpenClawCodingTools", () => {
expect(tools.some((tool) => tool.name === "write")).toBe(false);
expect(tools.some((tool) => tool.name === "edit")).toBe(false);
});
it("filters tools by agent tool policy even without sandbox", () => {
const tools = createOpenClawCodingTools({
config: { tools: { deny: ["browser"] } },
});
expect(tools.some((tool) => tool.name === "exec")).toBe(true);
expect(tools.some((tool) => tool.name === "browser")).toBe(false);
});
});