mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05:00
Merge pull request #457 from RooVetGit/add_diffs_to_preview
Add diff strategy to system prompt preview
This commit is contained in:
5
.changeset/poor-adults-fetch.md
Normal file
5
.changeset/poor-adults-fetch.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"roo-cline": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix bug where apply_diff wasn't showing up in system prompt preview
|
||||||
@@ -10,6 +10,7 @@ import { downloadTask } from "../../integrations/misc/export-markdown"
|
|||||||
import { openFile, openImage } from "../../integrations/misc/open-file"
|
import { openFile, openImage } from "../../integrations/misc/open-file"
|
||||||
import { selectImages } from "../../integrations/misc/process-images"
|
import { selectImages } from "../../integrations/misc/process-images"
|
||||||
import { getTheme } from "../../integrations/theme/getTheme"
|
import { getTheme } from "../../integrations/theme/getTheme"
|
||||||
|
import { getDiffStrategy } from "../diff/DiffStrategy"
|
||||||
import WorkspaceTracker from "../../integrations/workspace/WorkspaceTracker"
|
import WorkspaceTracker from "../../integrations/workspace/WorkspaceTracker"
|
||||||
import { McpHub } from "../../services/mcp/McpHub"
|
import { McpHub } from "../../services/mcp/McpHub"
|
||||||
import { ApiConfiguration, ApiProvider, ModelInfo } from "../../shared/api"
|
import { ApiConfiguration, ApiProvider, ModelInfo } from "../../shared/api"
|
||||||
@@ -962,7 +963,16 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|||||||
preferredLanguage,
|
preferredLanguage,
|
||||||
browserViewportSize,
|
browserViewportSize,
|
||||||
mcpEnabled,
|
mcpEnabled,
|
||||||
|
fuzzyMatchThreshold,
|
||||||
|
experimentalDiffStrategy,
|
||||||
} = await this.getState()
|
} = await this.getState()
|
||||||
|
|
||||||
|
// Create diffStrategy based on current model and settings
|
||||||
|
const diffStrategy = getDiffStrategy(
|
||||||
|
apiConfiguration.apiModelId || apiConfiguration.openRouterModelId || "",
|
||||||
|
fuzzyMatchThreshold,
|
||||||
|
experimentalDiffStrategy,
|
||||||
|
)
|
||||||
const cwd =
|
const cwd =
|
||||||
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || ""
|
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || ""
|
||||||
|
|
||||||
@@ -979,7 +989,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
|||||||
cwd,
|
cwd,
|
||||||
apiConfiguration.openRouterModelInfo?.supportsComputerUse ?? false,
|
apiConfiguration.openRouterModelInfo?.supportsComputerUse ?? false,
|
||||||
mcpEnabled ? this.mcpHub : undefined,
|
mcpEnabled ? this.mcpHub : undefined,
|
||||||
undefined,
|
diffStrategy,
|
||||||
browserViewportSize ?? "900x600",
|
browserViewportSize ?? "900x600",
|
||||||
mode,
|
mode,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,6 +70,13 @@ jest.mock(
|
|||||||
{ virtual: true },
|
{ virtual: true },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Mock DiffStrategy
|
||||||
|
jest.mock("../../diff/DiffStrategy", () => ({
|
||||||
|
getDiffStrategy: jest.fn().mockImplementation(() => ({
|
||||||
|
getToolDescription: jest.fn().mockReturnValue("apply_diff tool description"),
|
||||||
|
})),
|
||||||
|
}))
|
||||||
|
|
||||||
// Mock dependencies
|
// Mock dependencies
|
||||||
jest.mock("vscode", () => ({
|
jest.mock("vscode", () => ({
|
||||||
ExtensionContext: jest.fn(),
|
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 () => {
|
test("uses correct mode-specific instructions when mode is specified", async () => {
|
||||||
// Mock getState to return architect mode instructions
|
// Mock getState to return architect mode instructions
|
||||||
jest.spyOn(provider, "getState").mockResolvedValue({
|
jest.spyOn(provider, "getState").mockResolvedValue({
|
||||||
|
|||||||
Reference in New Issue
Block a user