Skip to content

Commit e3ed0f7

Browse files
committed
test(export): use parameterized test
1 parent 902e1fc commit e3ed0f7

File tree

1 file changed

+62
-141
lines changed

1 file changed

+62
-141
lines changed

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

Lines changed: 62 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,156 +1718,77 @@ describe("importExport", () => {
17181718
)
17191719
})
17201720

1721-
it("should exclude modelMaxTokens and modelMaxThinkingTokens when supportsReasoningBudget is false", async () => {
1722-
// This test verifies that token fields are excluded when model doesn't support reasoning budget
1723-
// Using claude-code provider which has supportsReasoningBudget: false
1724-
1725-
;(vscode.window.showSaveDialog as Mock).mockResolvedValue({
1726-
fsPath: "/mock/path/roo-code-settings.json",
1727-
})
1728-
1729-
// Use a real ProviderSettingsManager instance to test the actual filtering logic
1730-
const realProviderSettingsManager = new ProviderSettingsManager(mockExtensionContext)
1731-
1732-
// Wait for initialization to complete
1733-
await realProviderSettingsManager.initialize()
1734-
1735-
// Save a claude-code provider config with token fields
1736-
await realProviderSettingsManager.saveConfig("claude-code-provider", {
1737-
apiProvider: "claude-code" as ProviderName,
1738-
apiModelId: "claude-sonnet-4-5",
1739-
id: "claude-code-id",
1740-
modelMaxTokens: 4096, // This should be removed during export
1741-
modelMaxThinkingTokens: 2048, // This should be removed during export
1742-
})
1743-
1744-
// Set this as the current provider
1745-
await realProviderSettingsManager.activateProfile({ name: "claude-code-provider" })
1746-
1747-
const mockGlobalSettings = {
1748-
mode: "code",
1749-
autoApprovalEnabled: true,
1750-
}
1751-
1752-
mockContextProxy.export.mockResolvedValue(mockGlobalSettings)
1753-
;(fs.mkdir as Mock).mockResolvedValue(undefined)
1754-
1755-
await exportSettings({
1756-
providerSettingsManager: realProviderSettingsManager,
1757-
contextProxy: mockContextProxy,
1758-
})
1759-
1760-
// Get the exported data
1761-
const exportedData = (safeWriteJson as Mock).mock.calls[0][1]
1762-
1763-
// Verify that token fields were excluded because supportsReasoningBudget is false
1764-
const provider = exportedData.providerProfiles.apiConfigs["claude-code-provider"]
1765-
expect(provider).toBeDefined()
1766-
expect(provider.apiModelId).toBe("claude-sonnet-4-5")
1767-
expect("modelMaxTokens" in provider).toBe(false) // Should be excluded
1768-
expect("modelMaxThinkingTokens" in provider).toBe(false) // Should be excluded
1769-
})
1770-
1771-
it("should exclude modelMaxTokens and modelMaxThinkingTokens when requiredReasoningBudget is false", async () => {
1772-
// This test verifies that token fields are excluded when model doesn't require reasoning budget
1773-
// Using claude-code provider which has requiredReasoningBudget: false
1774-
1775-
;(vscode.window.showSaveDialog as Mock).mockResolvedValue({
1776-
fsPath: "/mock/path/roo-code-settings.json",
1777-
})
1778-
1779-
// Use a real ProviderSettingsManager instance to test the actual filtering logic
1780-
const realProviderSettingsManager = new ProviderSettingsManager(mockExtensionContext)
1781-
1782-
// Wait for initialization to complete
1783-
await realProviderSettingsManager.initialize()
1784-
1785-
// Save a claude-code provider config with token fields
1786-
await realProviderSettingsManager.saveConfig("claude-code-provider-2", {
1787-
apiProvider: "claude-code" as ProviderName,
1788-
apiModelId: "claude-sonnet-4-5",
1789-
id: "claude-code-id-2",
1790-
apiKey: "test-key",
1791-
modelMaxTokens: 4096, // This should be removed during export
1792-
modelMaxThinkingTokens: 2048, // This should be removed during export
1793-
})
1794-
1795-
// Set this as the current provider
1796-
await realProviderSettingsManager.activateProfile({ name: "claude-code-provider-2" })
1797-
1798-
const mockGlobalSettings = {
1799-
mode: "code",
1800-
autoApprovalEnabled: true,
1801-
}
1802-
1803-
mockContextProxy.export.mockResolvedValue(mockGlobalSettings)
1804-
;(fs.mkdir as Mock).mockResolvedValue(undefined)
1805-
1806-
await exportSettings({
1807-
providerSettingsManager: realProviderSettingsManager,
1808-
contextProxy: mockContextProxy,
1809-
})
1810-
1811-
// Get the exported data
1812-
const exportedData = (safeWriteJson as Mock).mock.calls[0][1]
1813-
1814-
// Verify that token fields were excluded because requiredReasoningBudget is false
1815-
const provider = exportedData.providerProfiles.apiConfigs["claude-code-provider-2"]
1816-
expect(provider).toBeDefined()
1817-
expect(provider.apiModelId).toBe("claude-sonnet-4-5")
1818-
expect("modelMaxTokens" in provider).toBe(false) // Should be excluded
1819-
expect("modelMaxThinkingTokens" in provider).toBe(false) // Should be excluded
1820-
})
1821-
1822-
it("should exclude modelMaxTokens and modelMaxThinkingTokens when both supportsReasoningBudget and requiredReasoningBudget are false", async () => {
1823-
// This test verifies that token fields are excluded when model has both reasoning budget flags set to false
1824-
// Using claude-code provider which has both flags set to false
1721+
it.each([
1722+
{
1723+
testCase: "supportsReasoningBudget is false",
1724+
providerName: "claude-code-provider",
1725+
modelId: "claude-sonnet-4-5",
1726+
providerId: "claude-code-id",
1727+
},
1728+
{
1729+
testCase: "requiredReasoningBudget is false",
1730+
providerName: "claude-code-provider-2",
1731+
modelId: "claude-sonnet-4-5",
1732+
providerId: "claude-code-id-2",
1733+
},
1734+
{
1735+
testCase: "both supportsReasoningBudget and requiredReasoningBudget are false",
1736+
providerName: "claude-code-provider-3",
1737+
modelId: "claude-3-5-haiku-20241022",
1738+
providerId: "claude-code-id-3",
1739+
},
1740+
])(
1741+
"should exclude modelMaxTokens and modelMaxThinkingTokens when $testCase",
1742+
async ({ providerName, modelId, providerId }) => {
1743+
// This test verifies that token fields are excluded when model doesn't support reasoning budget
1744+
// Using claude-code provider which has supportsReasoningBudget: false and requiredReasoningBudget: false
18251745

1826-
;(vscode.window.showSaveDialog as Mock).mockResolvedValue({
1827-
fsPath: "/mock/path/roo-code-settings.json",
1828-
})
1746+
;(vscode.window.showSaveDialog as Mock).mockResolvedValue({
1747+
fsPath: "/mock/path/roo-code-settings.json",
1748+
})
18291749

1830-
// Use a real ProviderSettingsManager instance to test the actual filtering logic
1831-
const realProviderSettingsManager = new ProviderSettingsManager(mockExtensionContext)
1750+
// Use a real ProviderSettingsManager instance to test the actual filtering logic
1751+
const realProviderSettingsManager = new ProviderSettingsManager(mockExtensionContext)
18321752

1833-
// Wait for initialization to complete
1834-
await realProviderSettingsManager.initialize()
1753+
// Wait for initialization to complete
1754+
await realProviderSettingsManager.initialize()
18351755

1836-
// Save a claude-code provider config with token fields
1837-
await realProviderSettingsManager.saveConfig("claude-code-provider-3", {
1838-
apiProvider: "claude-code" as ProviderName,
1839-
apiModelId: "claude-3-5-haiku-20241022", // Use a different model ID
1840-
id: "claude-code-id-3",
1841-
apiKey: "test-key",
1842-
modelMaxTokens: 4096, // This should be removed during export
1843-
modelMaxThinkingTokens: 2048, // This should be removed during export
1844-
})
1756+
// Save a claude-code provider config with token fields
1757+
await realProviderSettingsManager.saveConfig(providerName, {
1758+
apiProvider: "claude-code" as ProviderName,
1759+
apiModelId: modelId,
1760+
id: providerId,
1761+
apiKey: "test-key",
1762+
modelMaxTokens: 4096, // This should be removed during export
1763+
modelMaxThinkingTokens: 2048, // This should be removed during export
1764+
})
18451765

1846-
// Set this as the current provider
1847-
await realProviderSettingsManager.activateProfile({ name: "claude-code-provider-3" })
1766+
// Set this as the current provider
1767+
await realProviderSettingsManager.activateProfile({ name: providerName })
18481768

1849-
const mockGlobalSettings = {
1850-
mode: "code",
1851-
autoApprovalEnabled: true,
1852-
}
1769+
const mockGlobalSettings = {
1770+
mode: "code",
1771+
autoApprovalEnabled: true,
1772+
}
18531773

1854-
mockContextProxy.export.mockResolvedValue(mockGlobalSettings)
1855-
;(fs.mkdir as Mock).mockResolvedValue(undefined)
1774+
mockContextProxy.export.mockResolvedValue(mockGlobalSettings)
1775+
;(fs.mkdir as Mock).mockResolvedValue(undefined)
18561776

1857-
await exportSettings({
1858-
providerSettingsManager: realProviderSettingsManager,
1859-
contextProxy: mockContextProxy,
1860-
})
1777+
await exportSettings({
1778+
providerSettingsManager: realProviderSettingsManager,
1779+
contextProxy: mockContextProxy,
1780+
})
18611781

1862-
// Get the exported data
1863-
const exportedData = (safeWriteJson as Mock).mock.calls[0][1]
1782+
// Get the exported data
1783+
const exportedData = (safeWriteJson as Mock).mock.calls[0][1]
18641784

1865-
// Verify that token fields were excluded because both reasoning budget flags are false
1866-
const provider = exportedData.providerProfiles.apiConfigs["claude-code-provider-3"]
1867-
expect(provider).toBeDefined()
1868-
expect(provider.apiModelId).toBe("claude-3-5-haiku-20241022")
1869-
expect("modelMaxTokens" in provider).toBe(false) // Should be excluded
1870-
expect("modelMaxThinkingTokens" in provider).toBe(false) // Should be excluded
1871-
})
1785+
// Verify that token fields were excluded because reasoning budget is not supported/required
1786+
const provider = exportedData.providerProfiles.apiConfigs[providerName]
1787+
expect(provider).toBeDefined()
1788+
expect(provider.apiModelId).toBe(modelId)
1789+
expect("modelMaxTokens" in provider).toBe(false) // Should be excluded
1790+
expect("modelMaxThinkingTokens" in provider).toBe(false) // Should be excluded
1791+
},
1792+
)
18721793
})
18731794
})

0 commit comments

Comments
 (0)