Skip to content

Commit 7d612f6

Browse files
author
Zoo (VP)
committed
test(mimo): cover no-Authorization fetch and filtered MiMo router request
What: add a fetcher test asserting getMimoModels omits the Authorization header when no apiKey is provided, and a webviewMessageHandler test for a single-provider requestRouterModels call (values.provider: mimo) with stored credentials, asserting only MiMo is fetched and the filtered routerModels response carries the mimo entry. Why: CodeRabbit pre-merge Regression Evidence check flagged both gaps; the production useRouterModels path for a selected MiMo provider issues the filtered request, and the optional apiKey branch had no negative test. Impact: no behavior change, coverage only. eslint suppression counts unchanged (no new any).
1 parent d7a6bc9 commit 7d612f6

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

‎src/api/providers/fetchers/__tests__/mimo.spec.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ describe("getMimoModels", () => {
132132
)
133133
})
134134

135+
it("omits the Authorization header when no apiKey is provided", async () => {
136+
const fetchSpy = vi.fn().mockResolvedValue({
137+
ok: true,
138+
json: vi.fn().mockResolvedValue({ data: [] }),
139+
})
140+
globalThis.fetch = fetchSpy as unknown as typeof fetch
141+
142+
await getMimoModels("https://token-plan-sgp.xiaomimimo.com/v1")
143+
144+
const fetchInit = fetchSpy.mock.calls[0]?.[1] as RequestInit
145+
expect(fetchInit.headers).not.toHaveProperty("Authorization")
146+
})
147+
135148
it("mixes known and unknown models in same response", async () => {
136149
globalThis.fetch = vi.fn().mockResolvedValue({
137150
ok: true,

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,46 @@ describe("webviewMessageHandler - requestRouterModels provider filter", () => {
636636
})
637637
})
638638

639+
it("fetches only MiMo for a single-provider request with stored credentials", async () => {
640+
mockProvider.getState.mockResolvedValue({
641+
apiConfiguration: {
642+
mimoApiKey: "stored-mimo-key",
643+
mimoBaseUrl: "https://token-plan-sgp.xiaomimimo.com/v1",
644+
},
645+
})
646+
647+
getModelsMock.mockImplementation(async (options?: { provider?: string }) => {
648+
if (options?.provider === providerIdentifiers.mimo) {
649+
return { "mimo-v2.6-pro": { contextWindow: 1_048_576, supportsPromptCache: false } }
650+
}
651+
return {}
652+
})
653+
654+
await webviewMessageHandler(mockProvider, {
655+
type: RouterModelsMessageType.requestRouterModels,
656+
values: { provider: providerIdentifiers.mimo },
657+
})
658+
659+
const mimoCalls = getModelsMock.mock.calls.filter((c) => c[0]?.provider === providerIdentifiers.mimo)
660+
expect(mimoCalls).toHaveLength(1)
661+
expect(mimoCalls[0][0]).toEqual({
662+
provider: providerIdentifiers.mimo,
663+
apiKey: "stored-mimo-key",
664+
baseUrl: "https://token-plan-sgp.xiaomimimo.com/v1",
665+
})
666+
667+
const response = mockProvider.postMessageToWebview.mock.calls.find(
668+
(call) => call[0]?.type === RouterModelsMessageType.routerModels,
669+
)
670+
expect(response).toBeDefined()
671+
if (!response) throw new Error("Expected routerModels response")
672+
// Filtered responses carry only the requested provider's entry.
673+
expect(Object.keys(response[0].routerModels)).toEqual([providerIdentifiers.mimo])
674+
expect(response[0].routerModels.mimo).toEqual({
675+
"mimo-v2.6-pro": { contextWindow: 1_048_576, supportsPromptCache: false },
676+
})
677+
})
678+
639679
it("flushes MiMo cache when explicit credentials are provided via message values", async () => {
640680
getModelsMock.mockResolvedValue({
641681
"mimo-v2.6-pro": { contextWindow: 1_048_576, supportsPromptCache: false },

0 commit comments

Comments
 (0)