File size: 4,180 Bytes
df23150 d6d84f9 df23150 d6d84f9 df23150 570187b df23150 570187b df23150 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | import { describe, expect, it } from "vitest";
import {
buildOpenAiAgentPatch,
isSupportedAdapterType,
} from "../src/lib/agent-binding.js";
describe("agent binding helpers", () => {
it("recognizes supported adapter types", () => {
expect(isSupportedAdapterType("codex_local")).toBe(true);
expect(isSupportedAdapterType("claude_local")).toBe(false);
});
it("builds a provider-managed agent patch while preserving unrelated env", () => {
const patch = buildOpenAiAgentPatch({
adapterType: "codex_local",
currentAdapterConfig: {
env: {
FOO: { type: "plain", value: "bar" },
OPENAI_API_KEY: { type: "plain", value: "old" },
},
},
provider: {
id: "provider-1",
name: "OpenAI Proxy",
baseUrl: "https://example.test/v1",
},
apiKey: "sk-provider",
model: "gpt-5.4",
syncedAt: "2026-04-30T00:00:00.000Z",
});
expect(patch).toEqual({
adapterConfig: {
env: {
FOO: { type: "plain", value: "bar" },
CODEX_API_KEY: { type: "plain", value: "sk-provider" },
OPENAI_API_KEY: { type: "plain", value: "sk-provider" },
OPENAI_BASE_URL: { type: "plain", value: "https://example.test/v1" },
OPENAI_API_BASE: { type: "plain", value: "https://example.test/v1" },
OPENAI_API_BASE_URL: { type: "plain", value: "https://example.test/v1" },
},
extraArgs: [
"-c",
"model_provider=\"custom\"",
"-c",
"model_providers.custom.name=\"custom\"",
"-c",
"model_providers.custom.wire_api=\"responses\"",
"-c",
"model_providers.custom.requires_openai_auth=true",
"-c",
"model_providers.custom.base_url=\"https://example.test/v1\"",
"-c",
"openai_base_url=\"https://example.test/v1\"",
],
model: "gpt-5.4",
paperclipGlobalOpenAiProviderBinding: {
providerId: "provider-1",
providerName: "OpenAI Proxy",
providerBaseUrl: "https://example.test/v1",
managedByPlugin: true,
syncedAt: "2026-04-30T00:00:00.000Z",
},
},
});
});
it("replaces previously managed codex provider args instead of duplicating them", () => {
const patch = buildOpenAiAgentPatch({
adapterType: "codex_local",
currentAdapterConfig: {
extraArgs: [
"--search",
"-c",
"model_provider=\"custom\"",
"-c",
"model_providers.custom.base_url=\"https://old.example/v1\"",
"-c",
"openai_base_url=\"https://old.example/v1\"",
],
},
provider: {
id: "provider-2",
name: "New Proxy",
baseUrl: "https://new.example/v1",
},
apiKey: "sk-new",
model: "gpt-5.4",
syncedAt: "2026-05-01T00:00:00.000Z",
});
expect(patch).toEqual({
adapterConfig: {
env: {
CODEX_API_KEY: { type: "plain", value: "sk-new" },
OPENAI_API_KEY: { type: "plain", value: "sk-new" },
OPENAI_BASE_URL: { type: "plain", value: "https://new.example/v1" },
OPENAI_API_BASE: { type: "plain", value: "https://new.example/v1" },
OPENAI_API_BASE_URL: { type: "plain", value: "https://new.example/v1" },
},
extraArgs: [
"--search",
"-c",
"model_provider=\"custom\"",
"-c",
"model_providers.custom.name=\"custom\"",
"-c",
"model_providers.custom.wire_api=\"responses\"",
"-c",
"model_providers.custom.requires_openai_auth=true",
"-c",
"model_providers.custom.base_url=\"https://new.example/v1\"",
"-c",
"openai_base_url=\"https://new.example/v1\"",
],
model: "gpt-5.4",
paperclipGlobalOpenAiProviderBinding: {
providerId: "provider-2",
providerName: "New Proxy",
providerBaseUrl: "https://new.example/v1",
managedByPlugin: true,
syncedAt: "2026-05-01T00:00:00.000Z",
},
},
});
});
});
|