test(providers): dedupe replay policy assertions

This commit is contained in:
Vincent Koc
2026-04-12 03:12:16 +01:00
parent ab6a386896
commit 9463661a84
5 changed files with 73 additions and 124 deletions

View File

@@ -2,26 +2,16 @@ import type { StreamFn } from "@mariozechner/pi-agent-core";
import type { Context, Model } from "@mariozechner/pi-ai";
import { describe, expect, it } from "vitest";
import { registerSingleProviderPlugin } from "../../test/helpers/plugins/plugin-registration.js";
import { expectPassthroughReplayPolicy } from "../../test/helpers/provider-replay-policy.ts";
import plugin from "./index.js";
describe("kilocode provider plugin", () => {
it("owns passthrough-gemini replay policy for Gemini-backed models", async () => {
const provider = await registerSingleProviderPlugin(plugin);
expect(
provider.buildReplayPolicy?.({
provider: "kilocode",
modelApi: "openai-completions",
modelId: "gemini-2.5-pro",
} as never),
).toMatchObject({
applyAssistantFirstOrderingFix: false,
validateGeminiTurns: false,
validateAnthropicTurns: false,
sanitizeThoughtSignatures: {
allowBase64Only: true,
includeCamelCase: true,
},
await expectPassthroughReplayPolicy({
plugin,
providerId: "kilocode",
modelId: "gemini-2.5-pro",
sanitizeThoughtSignatures: true,
});
});

View File

@@ -1,48 +1,22 @@
import { describe, expect, it } from "vitest";
import { registerSingleProviderPlugin } from "../../test/helpers/plugins/plugin-registration.js";
import { describe, it } from "vitest";
import { expectPassthroughReplayPolicy } from "../../test/helpers/provider-replay-policy.ts";
import plugin from "./index.js";
describe("opencode-go provider plugin", () => {
it("owns passthrough-gemini replay policy for Gemini-backed models", async () => {
const provider = await registerSingleProviderPlugin(plugin);
expect(
provider.buildReplayPolicy?.({
provider: "opencode-go",
modelApi: "openai-completions",
modelId: "gemini-2.5-pro",
} as never),
).toMatchObject({
applyAssistantFirstOrderingFix: false,
validateGeminiTurns: false,
validateAnthropicTurns: false,
sanitizeThoughtSignatures: {
allowBase64Only: true,
includeCamelCase: true,
},
await expectPassthroughReplayPolicy({
plugin,
providerId: "opencode-go",
modelId: "gemini-2.5-pro",
sanitizeThoughtSignatures: true,
});
});
it("keeps non-Gemini replay policy minimal on passthrough routes", async () => {
const provider = await registerSingleProviderPlugin(plugin);
expect(
provider.buildReplayPolicy?.({
provider: "opencode-go",
modelApi: "openai-completions",
modelId: "qwen3-coder",
} as never),
).toMatchObject({
applyAssistantFirstOrderingFix: false,
validateGeminiTurns: false,
validateAnthropicTurns: false,
await expectPassthroughReplayPolicy({
plugin,
providerId: "opencode-go",
modelId: "qwen3-coder",
});
expect(
provider.buildReplayPolicy?.({
provider: "opencode-go",
modelApi: "openai-completions",
modelId: "qwen3-coder",
} as never),
).not.toHaveProperty("sanitizeThoughtSignatures");
});
});

View File

@@ -1,48 +1,22 @@
import { describe, expect, it } from "vitest";
import { registerSingleProviderPlugin } from "../../test/helpers/plugins/plugin-registration.js";
import { describe, it } from "vitest";
import { expectPassthroughReplayPolicy } from "../../test/helpers/provider-replay-policy.ts";
import plugin from "./index.js";
describe("opencode provider plugin", () => {
it("owns passthrough-gemini replay policy for Gemini-backed models", async () => {
const provider = await registerSingleProviderPlugin(plugin);
expect(
provider.buildReplayPolicy?.({
provider: "opencode",
modelApi: "openai-completions",
modelId: "gemini-2.5-pro",
} as never),
).toMatchObject({
applyAssistantFirstOrderingFix: false,
validateGeminiTurns: false,
validateAnthropicTurns: false,
sanitizeThoughtSignatures: {
allowBase64Only: true,
includeCamelCase: true,
},
await expectPassthroughReplayPolicy({
plugin,
providerId: "opencode",
modelId: "gemini-2.5-pro",
sanitizeThoughtSignatures: true,
});
});
it("keeps non-Gemini replay policy minimal on passthrough routes", async () => {
const provider = await registerSingleProviderPlugin(plugin);
expect(
provider.buildReplayPolicy?.({
provider: "opencode",
modelApi: "openai-completions",
modelId: "claude-opus-4.6",
} as never),
).toMatchObject({
applyAssistantFirstOrderingFix: false,
validateGeminiTurns: false,
validateAnthropicTurns: false,
await expectPassthroughReplayPolicy({
plugin,
providerId: "opencode",
modelId: "claude-opus-4.6",
});
expect(
provider.buildReplayPolicy?.({
provider: "opencode",
modelApi: "openai-completions",
modelId: "claude-opus-4.6",
} as never),
).not.toHaveProperty("sanitizeThoughtSignatures");
});
});

View File

@@ -1,45 +1,21 @@
import { describe, expect, it, vi } from "vitest";
import { registerSingleProviderPlugin } from "../../test/helpers/plugins/plugin-registration.js";
import { expectPassthroughReplayPolicy } from "../../test/helpers/provider-replay-policy.ts";
import openrouterPlugin from "./index.js";
describe("openrouter provider hooks", () => {
it("owns passthrough-gemini replay policy for Gemini-backed models", async () => {
const provider = await registerSingleProviderPlugin(openrouterPlugin);
expect(
provider.buildReplayPolicy?.({
provider: "openrouter",
modelApi: "openai-completions",
modelId: "gemini-2.5-pro",
} as never),
).toMatchObject({
applyAssistantFirstOrderingFix: false,
validateGeminiTurns: false,
validateAnthropicTurns: false,
sanitizeThoughtSignatures: {
allowBase64Only: true,
includeCamelCase: true,
},
await expectPassthroughReplayPolicy({
plugin: openrouterPlugin,
providerId: "openrouter",
modelId: "gemini-2.5-pro",
sanitizeThoughtSignatures: true,
});
expect(
provider.buildReplayPolicy?.({
provider: "openrouter",
modelApi: "openai-completions",
modelId: "openai/gpt-5.4",
} as never),
).toMatchObject({
applyAssistantFirstOrderingFix: false,
validateGeminiTurns: false,
validateAnthropicTurns: false,
await expectPassthroughReplayPolicy({
plugin: openrouterPlugin,
providerId: "openrouter",
modelId: "openai/gpt-5.4",
});
expect(
provider.buildReplayPolicy?.({
provider: "openrouter",
modelApi: "openai-completions",
modelId: "openai/gpt-5.4",
} as never),
).not.toHaveProperty("sanitizeThoughtSignatures");
});
it("owns native reasoning output mode", async () => {

View File

@@ -0,0 +1,35 @@
import { expect } from "vitest";
import { registerSingleProviderPlugin } from "./plugins/plugin-registration.js";
export async function expectPassthroughReplayPolicy(params: {
modelId: string;
plugin: unknown;
providerId: string;
sanitizeThoughtSignatures?: boolean;
}) {
const provider = await registerSingleProviderPlugin(params.plugin as never);
const policy = provider.buildReplayPolicy?.({
provider: params.providerId,
modelApi: "openai-completions",
modelId: params.modelId,
} as never);
expect(policy).toMatchObject({
applyAssistantFirstOrderingFix: false,
validateGeminiTurns: false,
validateAnthropicTurns: false,
});
if (params.sanitizeThoughtSignatures) {
expect(policy).toMatchObject({
sanitizeThoughtSignatures: {
allowBase64Only: true,
includeCamelCase: true,
},
});
} else {
expect(policy).not.toHaveProperty("sanitizeThoughtSignatures");
}
return provider;
}