| 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", |
| }, |
| }, |
| }); |
| }); |
| }); |
|
|