11import { LLMClient } from "./llm-client.js"
22import { HoleFiller , parseGhostResponse } from "../services/ghost/classic-auto-complete/HoleFiller.js"
33import { FimPromptBuilder } from "../services/ghost/classic-auto-complete/FillInTheMiddle.js"
4- import { AutocompleteInput } from "../services/ghost/types.js"
5- import * as vscode from "vscode"
6- import crypto from "crypto"
4+ import { extractPrefixSuffix , contextToAutocompleteInput , GhostContextProvider } from "../services/ghost/types.js"
75import { createContext } from "./utils.js"
8-
9- // Mock context provider for standalone testing
10- function createMockContextProvider ( prefix : string , suffix : string , filepath : string ) {
11- return {
12- getProcessedSnippets : async ( ) => ( {
13- filepathUri : `file://${ filepath } ` ,
14- helper : {
15- filepath : `file://${ filepath } ` ,
16- lang : { name : "typescript" , singleLineComment : "//" } ,
17- prunedPrefix : prefix ,
18- prunedSuffix : suffix ,
19- } ,
20- snippetsWithUris : [ ] ,
21- workspaceDirs : [ ] ,
22- } ) ,
23- } as any
24- }
25-
26- /**
27- * Check if a model supports FIM (Fill-In-Middle) completions.
28- * This mirrors the logic in KilocodeOpenrouterHandler.supportsFim()
29- */
30- function modelSupportsFim ( modelId : string ) : boolean {
31- return modelId . includes ( "codestral" )
32- }
6+ import { createMockContextProvider , modelSupportsFim } from "./mock-context-provider.js"
337
348export class GhostProviderTester {
359 private llmClient : LLMClient
@@ -45,25 +19,15 @@ export class GhostProviderTester {
4519 testCaseName : string = "test" ,
4620 ) : Promise < { prefix : string ; completion : string ; suffix : string } > {
4721 const context = createContext ( code , testCaseName )
48-
49- const position = context . range ?. start ?? new vscode . Position ( 0 , 0 )
50- const offset = context . document . offsetAt ( position )
51- const text = context . document . getText ( )
52- const prefix = text . substring ( 0 , offset )
53- const suffix = text . substring ( offset )
22+ const { prefix, suffix } = extractPrefixSuffix (
23+ context . document ,
24+ context . range ?. start ?? context . document . positionAt ( 0 ) ,
25+ )
26+ const autocompleteInput = contextToAutocompleteInput ( context )
5427 const languageId = context . document . languageId || "javascript"
55- const filepath = context . document . uri . fsPath
5628
57- // Common setup
58- const mockContextProvider = createMockContextProvider ( prefix , suffix , filepath )
59- const autocompleteInput : AutocompleteInput = {
60- isUntitledFile : false ,
61- completionId : crypto . randomUUID ( ) ,
62- filepath,
63- pos : { line : position . line , character : position . character } ,
64- recentlyVisitedRanges : [ ] ,
65- recentlyEditedRanges : [ ] ,
66- }
29+ // Create mock context provider
30+ const mockContextProvider = createMockContextProvider ( prefix , suffix , autocompleteInput . filepath )
6731
6832 // Auto-detect strategy based on model capabilities
6933 const supportsFim = modelSupportsFim ( this . model )
@@ -75,8 +39,8 @@ export class GhostProviderTester {
7539 }
7640
7741 private async getFimCompletion (
78- contextProvider : ReturnType < typeof createMockContextProvider > ,
79- autocompleteInput : AutocompleteInput ,
42+ contextProvider : GhostContextProvider ,
43+ autocompleteInput : ReturnType < typeof contextToAutocompleteInput > ,
8044 ) : Promise < string > {
8145 const fimPromptBuilder = new FimPromptBuilder ( contextProvider )
8246 const prompt = await fimPromptBuilder . getFimPrompts ( autocompleteInput , this . model )
@@ -85,8 +49,8 @@ export class GhostProviderTester {
8549 }
8650
8751 private async getHoleFillerCompletion (
88- contextProvider : ReturnType < typeof createMockContextProvider > ,
89- autocompleteInput : AutocompleteInput ,
52+ contextProvider : GhostContextProvider ,
53+ autocompleteInput : ReturnType < typeof contextToAutocompleteInput > ,
9054 languageId : string ,
9155 prefix : string ,
9256 suffix : string ,
0 commit comments