GeezerVison is showing github.com — test: add regression test for setCacheKey option · toastdriven/opencode@f9d0850
File treeExpand file treeCollapse file tree Open diff view settings packages/opencode/test/provider
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/opencode/test/provider/transform.test.ts +70Lines changed: 70 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,76 @@ import { ProviderTransform } from "../../src/provider/transform" | 3 | 3 |
| 4 | 4 | const OUTPUT_TOKEN_MAX = 32000 | 5 | 5 |
| | 6 | +describe("ProviderTransform.options - setCacheKey", () => { | | 7 | + const sessionID = "test-session-123" | | 8 | + | | 9 | + const mockModel = { | | 10 | + id: "anthropic/claude-3-5-sonnet", | | 11 | + providerID: "anthropic", | | 12 | + api: { | | 13 | + id: "claude-3-5-sonnet-20241022", | | 14 | + url: "https://api.anthropic.com", | | 15 | + npm: "@ai-sdk/anthropic", | | 16 | + }, | | 17 | + name: "Claude 3.5 Sonnet", | | 18 | + capabilities: { | | 19 | + temperature: true, | | 20 | + reasoning: false, | | 21 | + attachment: true, | | 22 | + toolcall: true, | | 23 | + input: { text: true, audio: false, image: true, video: false, pdf: true }, | | 24 | + output: { text: true, audio: false, image: false, video: false, pdf: false }, | | 25 | + interleaved: false, | | 26 | + }, | | 27 | + cost: { | | 28 | + input: 0.003, | | 29 | + output: 0.015, | | 30 | + cache: { read: 0.0003, write: 0.00375 }, | | 31 | + }, | | 32 | + limit: { | | 33 | + context: 200000, | | 34 | + output: 8192, | | 35 | + }, | | 36 | + status: "active", | | 37 | + options: {}, | | 38 | + headers: {}, | | 39 | + } as any | | 40 | + | | 41 | + test("should set promptCacheKey when providerOptions.setCacheKey is true", () => { | | 42 | + const result = ProviderTransform.options(mockModel, sessionID, { setCacheKey: true }) | | 43 | + expect(result.promptCacheKey).toBe(sessionID) | | 44 | + }) | | 45 | + | | 46 | + test("should not set promptCacheKey when providerOptions.setCacheKey is false", () => { | | 47 | + const result = ProviderTransform.options(mockModel, sessionID, { setCacheKey: false }) | | 48 | + expect(result.promptCacheKey).toBeUndefined() | | 49 | + }) | | 50 | + | | 51 | + test("should not set promptCacheKey when providerOptions is undefined", () => { | | 52 | + const result = ProviderTransform.options(mockModel, sessionID, undefined) | | 53 | + expect(result.promptCacheKey).toBeUndefined() | | 54 | + }) | | 55 | + | | 56 | + test("should not set promptCacheKey when providerOptions does not have setCacheKey", () => { | | 57 | + const result = ProviderTransform.options(mockModel, sessionID, {}) | | 58 | + expect(result.promptCacheKey).toBeUndefined() | | 59 | + }) | | 60 | + | | 61 | + test("should set promptCacheKey for openai provider regardless of setCacheKey", () => { | | 62 | + const openaiModel = { | | 63 | + ...mockModel, | | 64 | + providerID: "openai", | | 65 | + api: { | | 66 | + id: "gpt-4", | | 67 | + url: "https://api.openai.com", | | 68 | + npm: "@ai-sdk/openai", | | 69 | + }, | | 70 | + } | | 71 | + const result = ProviderTransform.options(openaiModel, sessionID, {}) | | 72 | + expect(result.promptCacheKey).toBe(sessionID) | | 73 | + }) | | 74 | +}) | | 75 | + | 6 | 76 | describe("ProviderTransform.maxOutputTokens", () => { | 7 | 77 | test("returns 32k when modelLimit > 32k", () => { | 8 | 78 | const modelLimit = 100000 | |
|