Skip to content

Commit bacc23a

Browse files
committed
test(friendli): cover spent-deadline guard, provider filter, and static-only ID validation
1 parent eed57af commit bacc23a

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎src/api/providers/__tests__/friendli.spec.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,18 @@ describe("FriendliHandler", () => {
329329
expect(mockCreate).toHaveBeenLastCalledWith(expect.anything(), { timeout: 2000 })
330330
})
331331

332+
it("completePrompt should time out without a chat request when a resolved catalog wait spends the deadline", async () => {
333+
let now = 1_000
334+
vi.spyOn(Date, "now").mockImplementation(() => now)
335+
mockGetModels.mockImplementationOnce(async () => {
336+
now += 3_000
337+
return {}
338+
})
339+
340+
await expect(handler.completePrompt("a", { timeoutMs: 3000 })).rejects.toMatchObject({ name: "TimeoutError" })
341+
expect(mockCreate).not.toHaveBeenCalled()
342+
})
343+
332344
it("completePrompt should time out without a chat request when the catalog wait uses the deadline", async () => {
333345
mockGetModels.mockReturnValueOnce(new Promise(() => {}))
334346

‎src/core/webview/__tests__/webviewMessageHandler.spec.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,30 @@ describe("webviewMessageHandler - requestRouterModels", () => {
13501350
expect(mockFlushModels).not.toHaveBeenCalled()
13511351
})
13521352

1353+
it("fetches only Friendli when the provider filter is friendli", async () => {
1354+
mockClineProvider.getState = vi.fn().mockResolvedValue({ apiConfiguration: {} })
1355+
mockGetModels.mockResolvedValue({
1356+
"zai-org/GLM-5.2": { maxTokens: 131072, contextWindow: 1000000, supportsPromptCache: true },
1357+
})
1358+
1359+
await webviewMessageHandler(mockClineProvider, {
1360+
type: "requestRouterModels",
1361+
values: { provider: providerIdentifiers.friendli },
1362+
})
1363+
1364+
expect(mockGetModels).toHaveBeenCalledTimes(1)
1365+
expect(mockGetModels).toHaveBeenCalledWith({ provider: providerIdentifiers.friendli }, expect.anything())
1366+
expect(mockClineProvider.postMessageToWebview).toHaveBeenCalledWith({
1367+
type: "routerModels",
1368+
routerModels: {
1369+
friendli: {
1370+
"zai-org/GLM-5.2": expect.objectContaining({ contextWindow: 1000000 }),
1371+
},
1372+
},
1373+
values: { provider: providerIdentifiers.friendli },
1374+
})
1375+
})
1376+
13531377
it("prefers an unsaved NanoGPT key and refreshes the matching key-scoped cache", async () => {
13541378
mockClineProvider.getState = vi.fn().mockResolvedValue({
13551379
apiConfiguration: { nanoGptApiKey: "saved-key" },

‎webview-ui/src/utils/__tests__/validate.spec.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,26 @@ describe("Model Validation Functions", () => {
511511
const result = validateApiConfigurationExcludingModelErrors(config, mockRouterModels, allowAllOrganization)
512512
expect(result).toBeUndefined()
513513
})
514+
515+
// The live catalog is authoritative: a static-only ID it no longer serves is flagged,
516+
// while an empty catalog (failed fetch) keeps the static fallback valid.
517+
it.each([
518+
{
519+
label: "a loaded catalog without the ID",
520+
catalog: { "zai-org/GLM-5.2": {}, "zai-org/GLM-5.1": {} },
521+
flagged: true,
522+
},
523+
{ label: "an empty catalog", catalog: {}, flagged: false },
524+
])("handles a static-only Friendli ID with $label", ({ catalog, flagged }) => {
525+
const config: ProviderSettings = {
526+
apiProvider: providerIdentifiers.friendli,
527+
apiModelId: "deepseek-ai/DeepSeek-V3.2",
528+
}
529+
const routerModels = { ...mockRouterModels, friendli: catalog } as RouterModels
530+
531+
const result = getModelValidationError(config, routerModels, allowAllOrganization)
532+
expect(result?.startsWith("settings:validation.modelAvailability") ?? false).toBe(flagged)
533+
})
514534
})
515535

516536
describe("Zoo Gateway validation", () => {

0 commit comments

Comments
 (0)