refactor(agents): dedupe plugin hooks and test helpers

This commit is contained in:
Peter Steinberger
2026-02-22 07:38:24 +00:00
parent 75c1bfbae8
commit 185fba1d22
16 changed files with 661 additions and 579 deletions

View File

@@ -3,67 +3,82 @@ import { describe, expect, it } from "vitest";
import { sanitizeToolsForGoogle } from "./google.js";
describe("sanitizeToolsForGoogle", () => {
it("strips unsupported schema keywords for Google providers", () => {
const tool = {
const createTool = (parameters: Record<string, unknown>) =>
({
name: "test",
description: "test",
parameters: {
type: "object",
additionalProperties: false,
properties: {
foo: {
type: "string",
format: "uuid",
},
parameters,
execute: async () => ({ ok: true, content: [] }),
}) as unknown as AgentTool;
const expectFormatRemoved = (
sanitized: AgentTool,
key: "additionalProperties" | "patternProperties",
) => {
const params = sanitized.parameters as {
additionalProperties?: unknown;
patternProperties?: unknown;
properties?: Record<string, { format?: unknown }>;
};
expect(params[key]).toBeUndefined();
expect(params.properties?.foo?.format).toBeUndefined();
};
it("strips unsupported schema keywords for Google providers", () => {
const tool = createTool({
type: "object",
additionalProperties: false,
properties: {
foo: {
type: "string",
format: "uuid",
},
},
execute: async () => ({ ok: true, content: [] }),
} as unknown as AgentTool;
});
const [sanitized] = sanitizeToolsForGoogle({
tools: [tool],
provider: "google-gemini-cli",
});
const params = sanitized.parameters as {
additionalProperties?: unknown;
properties?: Record<string, { format?: unknown }>;
};
expect(params.additionalProperties).toBeUndefined();
expect(params.properties?.foo?.format).toBeUndefined();
expectFormatRemoved(sanitized, "additionalProperties");
});
it("strips unsupported schema keywords for google-antigravity", () => {
const tool = {
name: "test",
description: "test",
parameters: {
type: "object",
patternProperties: {
"^x-": { type: "string" },
},
properties: {
foo: {
type: "string",
format: "uuid",
},
const tool = createTool({
type: "object",
patternProperties: {
"^x-": { type: "string" },
},
properties: {
foo: {
type: "string",
format: "uuid",
},
},
execute: async () => ({ ok: true, content: [] }),
} as unknown as AgentTool;
});
const [sanitized] = sanitizeToolsForGoogle({
tools: [tool],
provider: "google-antigravity",
});
expectFormatRemoved(sanitized, "patternProperties");
});
const params = sanitized.parameters as {
patternProperties?: unknown;
properties?: Record<string, { format?: unknown }>;
};
it("returns original tools for non-google providers", () => {
const tool = createTool({
type: "object",
additionalProperties: false,
properties: {
foo: {
type: "string",
format: "uuid",
},
},
});
const sanitized = sanitizeToolsForGoogle({
tools: [tool],
provider: "openai",
});
expect(params.patternProperties).toBeUndefined();
expect(params.properties?.foo?.format).toBeUndefined();
expect(sanitized).toEqual([tool]);
expect(sanitized[0]).toBe(tool);
});
});