Skip to content

Commit 4d25bad

Browse files
committed
test(amazon): add more debugging information to inline tests
1 parent 5a9d5e1 commit 4d25bad

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

packages/amazonq/test/e2e/inline/inline.test.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
toTextEditor,
1616
using,
1717
} from 'aws-core-vscode/test'
18-
import { RecommendationHandler, RecommendationService } from 'aws-core-vscode/codewhisperer'
18+
import { RecommendationHandler, RecommendationService, session } from 'aws-core-vscode/codewhisperer'
1919
import { Commands, globals, sleep, waitUntil } from 'aws-core-vscode/shared'
2020
import { loginToIdC } from '../amazonq/utils/setup'
2121

@@ -59,22 +59,38 @@ describe('Amazon Q Inline', async function () {
5959
}
6060

6161
async function waitForRecommendations() {
62-
const ok = await waitUntil(async () => RecommendationHandler.instance.isSuggestionVisible(), waitOptions)
63-
if (!ok) {
64-
assert.fail('Suggestions failed to become visible')
65-
}
66-
}
67-
68-
async function waitForTelemetry() {
6962
const ok = await waitUntil(
7063
async () =>
71-
globals.telemetry.logger.query({
72-
metricName: 'codewhisperer_userTriggerDecision',
73-
}).length > 0,
64+
RecommendationHandler.instance.isSuggestionVisible() || session.getSuggestionState(0) === 'Showed',
7465
waitOptions
7566
)
7667
if (!ok) {
77-
assert.fail('Telemetry failed to be emitted')
68+
assert.fail(
69+
`Suggestions failed to become visible. Suggestion States: ${JSON.stringify(session.suggestionStates)}`
70+
)
71+
}
72+
}
73+
74+
/**
75+
* Waits for a specific telemetry event to be emitted with the expected suggestion state.
76+
* It looks like there might be a potential race condition in codewhisperer causing telemetry
77+
* events to be emitted in different orders
78+
*/
79+
async function waitForTelemetry(metricName: string, suggestionState: string) {
80+
const ok = await waitUntil(async () => {
81+
const events = globals.telemetry.logger.query({
82+
metricName,
83+
})
84+
return events.some((event) => event.codewhispererSuggestionState === suggestionState)
85+
}, waitOptions)
86+
const events = globals.telemetry.logger.query({
87+
metricName,
88+
})
89+
if (!ok) {
90+
assert.fail(`Telemetry failed to be emitted. Current events: ${JSON.stringify(events)}`)
91+
}
92+
if (events.length > 1 && events[events.length - 1].codewhispererSuggestionState !== suggestionState) {
93+
assert.fail(`Telemetry events were emitted in the wrong order. Current events: ${JSON.stringify(events)}`)
7894
}
7995
}
8096

0 commit comments

Comments
 (0)