fix(ai): disable OpenCode long cache retention for rejecting routes
closes #5702
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { MODELS } from "../src/models.generated.ts";
|
||||
import { getModel } from "../src/models.ts";
|
||||
import { streamAnthropic } from "../src/providers/anthropic.ts";
|
||||
import { streamOpenAICompletions } from "../src/providers/openai-completions.ts";
|
||||
@@ -13,6 +14,11 @@ class PayloadCaptured extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
interface OpenAICompletionsCachePayload {
|
||||
prompt_cache_key?: string;
|
||||
prompt_cache_retention?: string;
|
||||
}
|
||||
|
||||
function stopAfterPayload<TPayload>(capture: (payload: TPayload) => void): (payload: unknown) => never {
|
||||
return (payload: unknown): never => {
|
||||
capture(payload as TPayload);
|
||||
@@ -455,5 +461,39 @@ describe("Cache Retention (PI_CACHE_RETENTION)", () => {
|
||||
expect(capturedPayload.prompt_cache_key).toBeUndefined();
|
||||
expect(capturedPayload.prompt_cache_retention).toBeUndefined();
|
||||
});
|
||||
|
||||
it.each([
|
||||
MODELS.opencode["deepseek-v4-flash"],
|
||||
MODELS.opencode["deepseek-v4-pro"],
|
||||
MODELS.opencode["kimi-k2.5"],
|
||||
MODELS.opencode["kimi-k2.6"],
|
||||
MODELS.opencode["minimax-m2.7"],
|
||||
MODELS["opencode-go"]["kimi-k2.6"],
|
||||
] as const)("should omit long cache retention for $provider/$id", async (metadata) => {
|
||||
const model = metadata as Model<"openai-completions">;
|
||||
let capturedPayload: OpenAICompletionsCachePayload | undefined;
|
||||
|
||||
try {
|
||||
const s = streamOpenAICompletions(model, context, {
|
||||
apiKey: "fake-key",
|
||||
cacheRetention: "long",
|
||||
sessionId: "session-opencode-long-cache-unsupported",
|
||||
onPayload: stopAfterPayload<OpenAICompletionsCachePayload>((payload) => {
|
||||
capturedPayload = payload;
|
||||
}),
|
||||
});
|
||||
|
||||
for await (const event of s) {
|
||||
if (event.type === "error") break;
|
||||
}
|
||||
} catch {
|
||||
// Expected to fail
|
||||
}
|
||||
|
||||
expect(model.compat?.supportsLongCacheRetention).toBe(false);
|
||||
expect(capturedPayload).toBeDefined();
|
||||
expect(capturedPayload?.prompt_cache_key).toBeUndefined();
|
||||
expect(capturedPayload?.prompt_cache_retention).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user