Skip to content

Commit c683cb8

Browse files
committed
refactor paths for windows test fail
1 parent 6c3d6ab commit c683cb8

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

packages/core/src/codewhisperer/nextEditPrediction/PredictionTracker.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import * as codewhispererClient from '../client/codewhisperer'
1010
import { predictionTrackerDefaultConfig } from '../models/constants'
1111
import globals from '../../shared/extensionGlobals'
1212

13-
const logger = getLogger('nextEditPrediction')
14-
1513
// defaul values are stored in codewhisperer/model/constants
1614
export interface FileTrackerConfig {
1715
maxFiles: number
@@ -33,6 +31,7 @@ export interface FileSnapshot {
3331

3432
export class PredictionTracker {
3533
private snapshots: Map<string, FileSnapshot[]> = new Map()
34+
private logger = getLogger('nextEditPrediction')
3635
readonly config: FileTrackerConfig
3736
private storageSize: number = 0
3837

@@ -81,14 +80,14 @@ export class PredictionTracker {
8180
fileSnapshots.push(snapshot)
8281
this.snapshots.set(filePath, fileSnapshots)
8382
this.storageSize += size
84-
logger.debug(
83+
this.logger.debug(
8584
`Snapshot taken for file: ${filePath}, total snapshots: ${this.getTotalSnapshotCount()}, total size: ${Math.round(this.storageSize / 1024)} KB`
8685
)
8786

8887
await this.enforceMemoryLimits()
8988
this.enforceTimeLimits(snapshot)
9089
} catch (err) {
91-
logger.error(`Failed to save snapshot: ${err}`)
90+
this.logger.error(`Failed to save snapshot: ${err}`)
9291
}
9392
}
9493

@@ -110,7 +109,7 @@ export class PredictionTracker {
110109
if (fileSnapshots.length === 0) {
111110
this.snapshots.delete(snapshot.filePath)
112111
}
113-
logger.debug(
112+
this.logger.debug(
114113
`Snapshot deleted (aged out) for file: ${snapshot.filePath}, remaining snapshots: ${this.getTotalSnapshotCount()}, new size: ${Math.round(this.storageSize / 1024)} KB`
115114
)
116115
}
@@ -136,7 +135,7 @@ export class PredictionTracker {
136135
const removedSnapshot = fileSnapshots.shift()
137136
if (removedSnapshot) {
138137
this.storageSize -= removedSnapshot.size
139-
logger.debug(
138+
this.logger.debug(
140139
`Snapshot deleted (memory limit) for file: ${removedSnapshot.filePath}, remaining snapshots: ${this.getTotalSnapshotCount()}, new size: ${Math.round(this.storageSize / 1024)} KB`
141140
)
142141
}

packages/core/src/test/codewhisperer/nextEditPrediction/PredictionTracker.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as vscode from 'vscode'
77
import * as sinon from 'sinon'
88
import assert from 'assert'
9+
import * as path from 'path'
910
import {
1011
FileSnapshot,
1112
FileTrackerConfig,
@@ -51,7 +52,7 @@ describe('PredictionTracker', function () {
5152
let mockDocument: vscode.TextDocument
5253

5354
beforeEach(function () {
54-
filePath = '/path/to/file.js'
55+
filePath = path.join('path', 'to', 'file.js')
5556
previousContent = 'previous content'
5657
tracker = new PredictionTracker(mockExtensionContext)
5758

@@ -126,8 +127,8 @@ describe('PredictionTracker', function () {
126127
}
127128
tracker = new PredictionTracker(mockExtensionContext, customConfig)
128129

129-
const file1 = '/path/to/file1.js'
130-
const file2 = '/path/to/file2.js'
130+
const file1 = path.join('path', 'to', 'file1.js')
131+
const file2 = path.join('path', 'to', 'file2.js')
131132

132133
const initialTime = globals.clock.Date.now()
133134

@@ -160,12 +161,12 @@ describe('PredictionTracker', function () {
160161
})
161162

162163
it('should return empty array for non-existent file', function () {
163-
const result = tracker.getFileSnapshots('/non-existent/file.js')
164+
const result = tracker.getFileSnapshots(path.join('non-existent', 'file.js'))
164165
assert.deepStrictEqual(result, [])
165166
})
166167

167168
it('should return snapshots for existing file', async function () {
168-
const file = '/path/to/file.js'
169+
const file = path.join('path', 'to', 'file.js')
169170
const content = 'file content'
170171
const mockDocument = createMockDocument(content, file)
171172
await tracker.processEdit(mockDocument, content)
@@ -184,7 +185,7 @@ describe('PredictionTracker', function () {
184185

185186
beforeEach(async function () {
186187
tracker = new PredictionTracker(mockExtensionContext)
187-
file = '/path/to/file.js'
188+
file = path.join('path', 'to', 'file.js')
188189
snapshotContent = 'snapshot content'
189190
const mockDocument = createMockDocument(snapshotContent, file)
190191
await tracker.processEdit(mockDocument, snapshotContent)
@@ -207,7 +208,7 @@ describe('PredictionTracker', function () {
207208

208209
// Mock active editor, we only care about document
209210
mockEditor = {
210-
document: createMockDocument('current content', '/path/to/active.js'),
211+
document: createMockDocument('current content', path.join('path', 'to', 'active.js')),
211212
selection: new vscode.Selection(0, 0, 0, 0),
212213
selections: [new vscode.Selection(0, 0, 0, 0)],
213214
options: {},
@@ -233,7 +234,7 @@ describe('PredictionTracker', function () {
233234
})
234235

235236
it('should generate and return supplemental contexts', async function () {
236-
const filePath = '/path/to/active.js'
237+
const filePath = path.join('path', 'to', 'active.js')
237238
const initialTime = globals.clock.Date.now()
238239

239240
const mockDoc = createMockDocument('old content 1', filePath)

0 commit comments

Comments
 (0)