Skip to content

Commit 4cf6fc6

Browse files
committed
fix: update tests to match simplified recordLatency implementation
The simplified implementation only updates debounce delay after exceeding 10 samples (on the 11th sample and beyond), not when exactly 10 samples are collected. Updated tests to reflect this behavior.
1 parent a178750 commit 4cf6fc6

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/services/ghost/classic-auto-complete/GhostInlineCompletionProvider.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,8 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte
289289
// Remove oldest if we exceed the sample size
290290
if (this.latencyHistory.length > LATENCY_SAMPLE_SIZE) {
291291
this.latencyHistory.shift()
292-
}
293292

294-
// Once we have enough samples, update the debounce delay to the average
295-
if (this.latencyHistory.length >= LATENCY_SAMPLE_SIZE) {
293+
// Once we have enough samples, update the debounce delay to the average
296294
const sum = this.latencyHistory.reduce((acc, val) => acc + val, 0)
297295
this.debounceDelayMs = Math.round(sum / this.latencyHistory.length)
298296
}

src/services/ghost/classic-auto-complete/__tests__/GhostInlineCompletionProvider.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,16 +2002,21 @@ describe("GhostInlineCompletionProvider", () => {
20022002
expect(providerAny.debounceDelayMs).toBe(300) // Still initial value
20032003
})
20042004

2005-
it("should update debounce delay to average after 10 samples", () => {
2006-
// Record 10 latencies of 200ms each
2005+
it("should update debounce delay to average after exceeding 10 samples", () => {
2006+
// Record 10 latencies of 200ms each - debounce delay not updated yet
20072007
for (let i = 0; i < 10; i++) {
20082008
provider.recordLatency(200)
20092009
}
20102010

20112011
// Access private field via any cast for testing
20122012
const providerAny = provider as any
20132013
expect(providerAny.latencyHistory.length).toBe(10)
2014-
expect(providerAny.debounceDelayMs).toBe(200) // Average of 200ms
2014+
expect(providerAny.debounceDelayMs).toBe(300) // Still initial value (not updated until > 10)
2015+
2016+
// Record 11th latency - now debounce delay is updated
2017+
provider.recordLatency(200)
2018+
expect(providerAny.latencyHistory.length).toBe(10) // Still 10 (oldest removed)
2019+
expect(providerAny.debounceDelayMs).toBe(200) // Now updated to average
20152020
})
20162021

20172022
it("should maintain rolling window of 10 latencies", () => {
@@ -2029,9 +2034,9 @@ describe("GhostInlineCompletionProvider", () => {
20292034
expect(providerAny.debounceDelayMs).toBe(195)
20302035
})
20312036

2032-
it("should update debounce delay on each new latency after reaching 10 samples", () => {
2033-
// Record 10 latencies of 200ms each
2034-
for (let i = 0; i < 10; i++) {
2037+
it("should update debounce delay on each new latency after exceeding 10 samples", () => {
2038+
// Record 11 latencies of 200ms each (need > 10 to trigger update)
2039+
for (let i = 0; i < 11; i++) {
20352040
provider.recordLatency(200)
20362041
}
20372042

@@ -2062,8 +2067,9 @@ describe("GhostInlineCompletionProvider", () => {
20622067
}
20632068
})
20642069

2065-
// Record 10 latencies of 150ms each to set debounce delay to 150ms
2066-
for (let i = 0; i < 10; i++) {
2070+
// Record 11 latencies of 150ms each to set debounce delay to 150ms
2071+
// (need > 10 to trigger update)
2072+
for (let i = 0; i < 11; i++) {
20672073
provider.recordLatency(150)
20682074
}
20692075

0 commit comments

Comments
 (0)