GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: add regression test for setCacheKey option · toastdriven/opencode@f9d0850

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode/test/provider
    • transform.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/test/provider/transform.test.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/test/provider/transform.test.ts
+70Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,76 @@ import { ProviderTransform } from "../../src/provider/transform"
33

44
const OUTPUT_TOKEN_MAX = 32000
55

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+
676
describe("ProviderTransform.maxOutputTokens", () => {
777
test("returns 32k when modelLimit > 32k", () => {
878
const modelLimit = 100000

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.