fix: update tests to handle new experimental diff option and increase the default confidence to 1

This commit is contained in:
Daniel Riccio
2025-01-15 12:23:51 -05:00
parent 22069e8056
commit 6c8d7f4951
6 changed files with 16 additions and 13 deletions

View File

@@ -107,8 +107,12 @@ export class Cline {
task?: string | undefined, task?: string | undefined,
images?: string[] | undefined, images?: string[] | undefined,
historyItem?: HistoryItem | undefined, historyItem?: HistoryItem | undefined,
experimentalDiffStrategy?: boolean, experimentalDiffStrategy: boolean = false,
) { ) {
if (!task && !images && !historyItem) {
throw new Error('Either historyItem or task/images must be provided');
}
this.taskId = crypto.randomUUID() this.taskId = crypto.randomUUID()
this.api = buildApiHandler(apiConfiguration) this.api = buildApiHandler(apiConfiguration)
this.terminalManager = new TerminalManager() this.terminalManager = new TerminalManager()
@@ -119,7 +123,7 @@ export class Cline {
// Prioritize experimentalDiffStrategy from history item if available // Prioritize experimentalDiffStrategy from history item if available
const effectiveExperimentalDiffStrategy = historyItem?.experimentalDiffStrategy ?? experimentalDiffStrategy const effectiveExperimentalDiffStrategy = historyItem?.experimentalDiffStrategy ?? experimentalDiffStrategy
this.diffStrategy = getDiffStrategy(this.api.getModel().id, fuzzyMatchThreshold, effectiveExperimentalDiffStrategy) this.diffStrategy = getDiffStrategy(this.api.getModel().id, fuzzyMatchThreshold ?? 1.0, effectiveExperimentalDiffStrategy)
this.diffViewProvider = new DiffViewProvider(cwd) this.diffViewProvider = new DiffViewProvider(cwd)
this.providerRef = new WeakRef(provider) this.providerRef = new WeakRef(provider)

View File

@@ -322,7 +322,7 @@ describe('Cline', () => {
expect(cline.diffEnabled).toBe(true); expect(cline.diffEnabled).toBe(true);
expect(cline.diffStrategy).toBeDefined(); expect(cline.diffStrategy).toBeDefined();
expect(getDiffStrategySpy).toHaveBeenCalledWith('claude-3-5-sonnet-20241022', 0.9); expect(getDiffStrategySpy).toHaveBeenCalledWith('claude-3-5-sonnet-20241022', 0.9, false);
getDiffStrategySpy.mockRestore(); getDiffStrategySpy.mockRestore();
}); });
@@ -341,7 +341,7 @@ describe('Cline', () => {
expect(cline.diffEnabled).toBe(true); expect(cline.diffEnabled).toBe(true);
expect(cline.diffStrategy).toBeDefined(); expect(cline.diffStrategy).toBeDefined();
expect(getDiffStrategySpy).toHaveBeenCalledWith('claude-3-5-sonnet-20241022', 1.0); expect(getDiffStrategySpy).toHaveBeenCalledWith('claude-3-5-sonnet-20241022', 1.0, false);
getDiffStrategySpy.mockRestore(); getDiffStrategySpy.mockRestore();
}); });

View File

@@ -7,14 +7,11 @@ import { NewUnifiedDiffStrategy } from './strategies/new-unified'
* @param model The name of the model being used (e.g., 'gpt-4', 'claude-3-opus') * @param model The name of the model being used (e.g., 'gpt-4', 'claude-3-opus')
* @returns The appropriate diff strategy for the model * @returns The appropriate diff strategy for the model
*/ */
export function getDiffStrategy(model: string, fuzzyMatchThreshold?: number, experimentalDiffStrategy?: boolean): DiffStrategy { export function getDiffStrategy(model: string, fuzzyMatchThreshold?: number, experimentalDiffStrategy: boolean = false): DiffStrategy {
if (experimentalDiffStrategy) { if (experimentalDiffStrategy) {
// Use the fuzzyMatchThreshold with a minimum of 0.8 (80%) return new NewUnifiedDiffStrategy(fuzzyMatchThreshold)
const threshold = Math.max(fuzzyMatchThreshold ?? 1.0, 0.8)
return new NewUnifiedDiffStrategy(threshold)
} }
// Default to the stable SearchReplaceDiffStrategy return new SearchReplaceDiffStrategy(fuzzyMatchThreshold)
return new SearchReplaceDiffStrategy()
} }
export type { DiffStrategy } export type { DiffStrategy }

View File

@@ -11,7 +11,7 @@ describe('main', () => {
describe('constructor', () => { describe('constructor', () => {
it('should use default confidence threshold when not provided', () => { it('should use default confidence threshold when not provided', () => {
const defaultStrategy = new NewUnifiedDiffStrategy() const defaultStrategy = new NewUnifiedDiffStrategy()
expect(defaultStrategy['confidenceThreshold']).toBe(0.9) expect(defaultStrategy['confidenceThreshold']).toBe(1)
}) })
it('should use provided confidence threshold', () => { it('should use provided confidence threshold', () => {

View File

@@ -6,8 +6,8 @@ import { DiffResult, DiffStrategy } from "../../types"
export class NewUnifiedDiffStrategy implements DiffStrategy { export class NewUnifiedDiffStrategy implements DiffStrategy {
private readonly confidenceThreshold: number private readonly confidenceThreshold: number
constructor(confidenceThreshold: number = 0.9) { constructor(confidenceThreshold: number = 1) {
this.confidenceThreshold = Math.max(confidenceThreshold, 0.8) this.confidenceThreshold = Math.max(confidenceThreshold, 0.8);
} }
private parseUnifiedDiff(diff: string): Diff { private parseUnifiedDiff(diff: string): Diff {

View File

@@ -610,6 +610,8 @@ describe('ClineProvider', () => {
true, true,
1.0, 1.0,
'Test task', 'Test task',
undefined,
undefined,
undefined undefined
); );
}); });