Skip to content

Commit 9d31fe7

Browse files
committed
test(api): cover remaining service tier branches
1 parent 224824a commit 9d31fe7

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

src/api/providers/__tests__/openai-native.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,48 @@ describe("OpenAiNativeHandler", () => {
217217
expect(chunks).toContainEqual(expect.objectContaining({ type: "usage", totalCost: 0.00275 }))
218218
})
219219

220+
it("captures the resolved tier from a manual SSE completion event", async () => {
221+
mockResponsesCreate.mockRejectedValue(new Error("SDK not available"))
222+
const mockFetch = vitest.fn().mockResolvedValue({
223+
ok: true,
224+
body: new ReadableStream({
225+
start(controller) {
226+
controller.enqueue(
227+
new TextEncoder().encode(
228+
`data: ${JSON.stringify({
229+
type: "response.completed",
230+
response: { [SERVICE_TIER_KEY]: OpenAiServiceTier.Priority },
231+
})}\n\n`,
232+
),
233+
)
234+
controller.enqueue(
235+
new TextEncoder().encode(
236+
`data: ${JSON.stringify({
237+
type: "response.usage",
238+
usage: { input_tokens: 100, output_tokens: 20 },
239+
})}\n\n`,
240+
),
241+
)
242+
controller.enqueue(new TextEncoder().encode("data: [DONE]\n\n"))
243+
controller.close()
244+
},
245+
}),
246+
})
247+
global.fetch = mockFetch as typeof fetch
248+
handler = new OpenAiNativeHandler({
249+
...mockOptions,
250+
apiModelId: "gpt-5.6-sol",
251+
openAiNativeServiceTier: OpenAiServiceTier.Default,
252+
})
253+
254+
const chunks = []
255+
for await (const chunk of handler.createMessage(systemPrompt, messages)) {
256+
chunks.push(chunk)
257+
}
258+
259+
expect(chunks).toContainEqual(expect.objectContaining({ type: "usage", totalCost: 0.00275 }))
260+
})
261+
220262
it("should handle streaming responses via Responses API", async () => {
221263
// Mock fetch for Responses API fallback
222264
const mockFetch = vitest.fn().mockResolvedValue({

webview-ui/src/components/settings/__tests__/ModelInfoView.spec.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,24 @@ describe("ModelInfoView service tier pricing", () => {
106106

107107
expect(screen.queryByText("Service tier pricing")).not.toBeInTheDocument()
108108
})
109+
110+
it("shows unavailable prices when neither the tier nor Standard defines them", () => {
111+
render(
112+
<ModelInfoView
113+
{...defaultProps}
114+
apiProvider={providerIdentifiers.openaiNative}
115+
modelInfo={{
116+
contextWindow: 128_000,
117+
supportsPromptCache: false,
118+
tiers: [
119+
{ name: OpenAiServiceTier.Flex, contextWindow: 128_000 },
120+
{ name: OpenAiServiceTier.Priority, contextWindow: 128_000 },
121+
],
122+
}}
123+
/>,
124+
)
125+
126+
expect(getPricingRowValues("Flex")).toEqual(["Flex", "—", "—", "—"])
127+
expect(getPricingRowValues("Priority")).toEqual(["Priority", "—", "—", "—"])
128+
})
109129
})

0 commit comments

Comments
 (0)