Skip to content

Commit 9da1589

Browse files
committed
test: Update useSelectedModel tests to reflect new validation behavior
- Fix tests that were expecting old cross-contamination behavior - Update expectations to match new validation logic that prevents using configured model IDs when they don't exist in current provider's models - All tests now pass and validate the correct fallback-to-default behavior
1 parent c1281a5 commit 9da1589

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe("useSelectedModel", () => {
9393
})
9494
})
9595

96-
it("should use only specific provider info when base model info is missing", () => {
96+
it("should fall back to default when configured model doesn't exist in available models", () => {
9797
const specificProviderInfo: ModelInfo = {
9898
maxTokens: 8192,
9999
contextWindow: 16384,
@@ -106,7 +106,18 @@ describe("useSelectedModel", () => {
106106

107107
mockUseRouterModels.mockReturnValue({
108108
data: {
109-
openrouter: {},
109+
openrouter: {
110+
"anthropic/claude-sonnet-4.5": {
111+
maxTokens: 8192,
112+
contextWindow: 200_000,
113+
supportsImages: true,
114+
supportsPromptCache: true,
115+
inputPrice: 3.0,
116+
outputPrice: 15.0,
117+
cacheWritesPrice: 3.75,
118+
cacheReadsPrice: 0.3,
119+
},
120+
},
110121
requesty: {},
111122
glama: {},
112123
unbound: {},
@@ -127,15 +138,29 @@ describe("useSelectedModel", () => {
127138

128139
const apiConfiguration: ProviderSettings = {
129140
apiProvider: "openrouter",
130-
openRouterModelId: "test-model",
141+
openRouterModelId: "test-model", // This model doesn't exist in available models
131142
openRouterSpecificProvider: "test-provider",
132143
}
133144

134145
const wrapper = createWrapper()
135146
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })
136147

137-
expect(result.current.id).toBe("test-model")
138-
expect(result.current.info).toEqual(specificProviderInfo)
148+
// Should fall back to provider default since "test-model" doesn't exist
149+
expect(result.current.id).toBe("anthropic/claude-sonnet-4.5")
150+
// Should still use specific provider info for the default model if specified
151+
expect(result.current.info).toEqual({
152+
...{
153+
maxTokens: 8192,
154+
contextWindow: 200_000,
155+
supportsImages: true,
156+
supportsPromptCache: true,
157+
inputPrice: 3.0,
158+
outputPrice: 15.0,
159+
cacheWritesPrice: 3.75,
160+
cacheReadsPrice: 0.3,
161+
},
162+
...specificProviderInfo,
163+
})
139164
})
140165

141166
it("should demonstrate the merging behavior validates the comment about missing fields", () => {
@@ -244,12 +269,12 @@ describe("useSelectedModel", () => {
244269
expect(result.current.info).toEqual(baseModelInfo)
245270
})
246271

247-
it("should fall back to default when both base and specific provider info are missing", () => {
272+
it("should fall back to default when configured model and provider don't exist", () => {
248273
mockUseRouterModels.mockReturnValue({
249274
data: {
250275
openrouter: {
251-
"anthropic/claude-sonnet-4": {
252-
// Default model
276+
"anthropic/claude-sonnet-4.5": {
277+
// Default model - using correct default model name
253278
maxTokens: 8192,
254279
contextWindow: 200_000,
255280
supportsImages: true,
@@ -285,8 +310,19 @@ describe("useSelectedModel", () => {
285310
const wrapper = createWrapper()
286311
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })
287312

288-
expect(result.current.id).toBe("non-existent-model")
289-
expect(result.current.info).toBeUndefined()
313+
// Should fall back to provider default since "non-existent-model" doesn't exist
314+
expect(result.current.id).toBe("anthropic/claude-sonnet-4.5")
315+
// Should use base model info since provider doesn't exist
316+
expect(result.current.info).toEqual({
317+
maxTokens: 8192,
318+
contextWindow: 200_000,
319+
supportsImages: true,
320+
supportsPromptCache: true,
321+
inputPrice: 3.0,
322+
outputPrice: 15.0,
323+
cacheWritesPrice: 3.75,
324+
cacheReadsPrice: 0.3,
325+
})
290326
})
291327
})
292328

0 commit comments

Comments
 (0)