Skip to content

Commit 710b01b

Browse files
test(config): make export() token-filter tests deterministic & isolation-safe (#161)
The GLM export test passed on ubuntu/local but failed on Windows CI, which runs vitest with poolOptions.forks.singleFork. ProviderSettingsManager.spec used the real buildApiHandler, so a sibling spec's module-level vi.mock("../../../api") (e.g. importExport.spec) could bleed in under reduced isolation, making supportsMaxTokens read as undefined and dropping modelMaxTokens. Mock buildApiHandler in this file, deriving model capabilities from the real @roo-code/types definitions via importActual. The Export tests now exercise the token-field filtering deterministically and are immune to cross-file api mocks, while still validating real model capabilities (glm-5.1 supportsMaxTokens, etc.).
1 parent 6cdbb6b commit 710b01b

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/core/config/__tests__/ProviderSettingsManager.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@ import type { ProviderSettings } from "@roo-code/types"
66

77
import { ProviderSettingsManager, ProviderProfiles, SyncCloudProfilesResult } from "../ProviderSettingsManager"
88

9+
// `export()` builds an API handler per profile to read model capabilities. Mock
10+
// buildApiHandler so the Export tests exercise the token-field filtering logic
11+
// deterministically, driven by the REAL provider model definitions (pulled from
12+
// @roo-code/types via importActual) rather than instantiating live handlers.
13+
//
14+
// This also keeps the suite isolated from sibling specs that mock "../../../api"
15+
// (e.g. importExport.spec): under Windows CI's `singleFork` pool an un-isolated
16+
// module mock from another file could otherwise leak in here, making
17+
// supportsMaxTokens read as undefined and silently dropping modelMaxTokens. #161 / #274.
18+
vi.mock("../../../api", async () => {
19+
const types = await vi.importActual<typeof import("@roo-code/types")>("@roo-code/types")
20+
const zaiModels = { ...types.internationalZAiModels, ...types.mainlandZAiModels } as Record<string, unknown>
21+
const anthropicModels = types.anthropicModels as Record<string, unknown>
22+
const modelInfoFor = (config: { apiProvider?: string; apiModelId?: string }) => {
23+
const id = config?.apiModelId ?? ""
24+
switch (config?.apiProvider) {
25+
case "zai":
26+
return zaiModels[id] ?? {}
27+
case "anthropic":
28+
return anthropicModels[id] ?? {}
29+
default:
30+
return {}
31+
}
32+
}
33+
return {
34+
buildApiHandler: (config: any) => ({
35+
getModel: () => ({ id: config?.apiModelId ?? "", info: modelInfoFor(config) }),
36+
}),
37+
}
38+
})
39+
940
// Mock VSCode ExtensionContext
1041
const mockSecrets = {
1142
get: vi.fn(),

0 commit comments

Comments
 (0)