Add diff strategy to system prompt preview

This commit is contained in:
Matt Rubens
2025-01-21 11:04:47 -05:00
parent 9a2bfcce64
commit 77fa8b1b31
3 changed files with 69 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"roo-cline": patch
---
Fix bug where apply_diff wasn't showing up in system prompt preview

View File

@@ -10,6 +10,7 @@ import { downloadTask } from "../../integrations/misc/export-markdown"
import { openFile, openImage } from "../../integrations/misc/open-file"
import { selectImages } from "../../integrations/misc/process-images"
import { getTheme } from "../../integrations/theme/getTheme"
import { getDiffStrategy } from "../diff/DiffStrategy"
import WorkspaceTracker from "../../integrations/workspace/WorkspaceTracker"
import { McpHub } from "../../services/mcp/McpHub"
import { ApiConfiguration, ApiProvider, ModelInfo } from "../../shared/api"
@@ -962,7 +963,16 @@ export class ClineProvider implements vscode.WebviewViewProvider {
preferredLanguage,
browserViewportSize,
mcpEnabled,
fuzzyMatchThreshold,
experimentalDiffStrategy,
} = await this.getState()
// Create diffStrategy based on current model and settings
const diffStrategy = getDiffStrategy(
apiConfiguration.apiModelId || apiConfiguration.openRouterModelId || "",
fuzzyMatchThreshold,
experimentalDiffStrategy,
)
const cwd =
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || ""
@@ -979,7 +989,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
cwd,
apiConfiguration.openRouterModelInfo?.supportsComputerUse ?? false,
mcpEnabled ? this.mcpHub : undefined,
undefined,
diffStrategy,
browserViewportSize ?? "900x600",
mode,
{

View File

@@ -70,6 +70,13 @@ jest.mock(
{ virtual: true },
)
// Mock DiffStrategy
jest.mock("../../diff/DiffStrategy", () => ({
getDiffStrategy: jest.fn().mockImplementation(() => ({
getToolDescription: jest.fn().mockReturnValue("apply_diff tool description"),
})),
}))
// Mock dependencies
jest.mock("vscode", () => ({
ExtensionContext: jest.fn(),
@@ -963,6 +970,52 @@ describe("ClineProvider", () => {
)
})
test("passes diffStrategy to SYSTEM_PROMPT when previewing", async () => {
// Mock getState to return experimentalDiffStrategy and fuzzyMatchThreshold
jest.spyOn(provider, "getState").mockResolvedValue({
apiConfiguration: {
apiProvider: "openrouter",
apiModelId: "test-model",
openRouterModelInfo: { supportsComputerUse: true },
},
customPrompts: {},
mode: "code",
mcpEnabled: false,
browserViewportSize: "900x600",
experimentalDiffStrategy: true,
fuzzyMatchThreshold: 0.8,
} as any)
// Mock SYSTEM_PROMPT to verify diffStrategy is passed
const systemPromptModule = require("../../prompts/system")
const systemPromptSpy = jest.spyOn(systemPromptModule, "SYSTEM_PROMPT")
// Trigger getSystemPrompt
const handler = getMessageHandler()
await handler({ type: "getSystemPrompt", mode: "code" })
// Verify SYSTEM_PROMPT was called with correct arguments
expect(systemPromptSpy).toHaveBeenCalledWith(
expect.anything(), // context
expect.any(String), // cwd
true, // supportsComputerUse
undefined, // mcpHub (disabled)
expect.objectContaining({
// diffStrategy
getToolDescription: expect.any(Function),
}),
"900x600", // browserViewportSize
"code", // mode
expect.any(Object), // customPrompts
expect.any(Object), // customModes
undefined, // effectiveInstructions
)
// Run the test again to verify it's consistent
await handler({ type: "getSystemPrompt", mode: "code" })
expect(systemPromptSpy).toHaveBeenCalledTimes(2)
})
test("uses correct mode-specific instructions when mode is specified", async () => {
// Mock getState to return architect mode instructions
jest.spyOn(provider, "getState").mockResolvedValue({