Skip to content

Commit 30ea80a

Browse files
authored
test(core): assertTelemetry should accept partial metrics (aws#6477)
## Problem assertTelemetry's docstring implies that it can expect partial metric shapes but doing something like: ``` assertTelemetry('codewhisperer_userTriggerDecision', { codewhispererSuggestionState: 'Reject', }) ``` generates a type error. This is because it expects full metrics not partial metrics ## Solution Allow assertTelemetry to accept partial metrics --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 7af0b83 commit 30ea80a

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

packages/core/src/test/codewhisperer/startSecurityScan.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
scansLimitReachedErrorMessage,
2727
} from '../../codewhisperer/models/constants'
2828
import * as model from '../../codewhisperer/models/model'
29-
import { CodewhispererSecurityScan } from '../../shared/telemetry/telemetry.gen'
3029
import * as errors from '../../shared/errors'
3130
import * as timeoutUtils from '../../shared/utilities/timeoutUtils'
3231
import { SecurityIssuesTree } from '../../codewhisperer'
@@ -232,7 +231,7 @@ describe('startSecurityScan', function () {
232231
codewhispererCodeScanIssuesWithFixes: 0,
233232
codewhispererCodeScanScope: 'PROJECT',
234233
passive: false,
235-
} as CodewhispererSecurityScan)
234+
})
236235
})
237236

238237
it('Should cancel a scan if a newer one has started', async function () {
@@ -261,7 +260,7 @@ describe('startSecurityScan', function () {
261260
result: 'Cancelled',
262261
reasonDesc: 'Security scan stopped by user.',
263262
reason: 'DefaultError',
264-
} as unknown as CodewhispererSecurityScan,
263+
},
265264
{
266265
result: 'Succeeded',
267266
},
@@ -323,7 +322,7 @@ describe('startSecurityScan', function () {
323322
reason: 'CodeScanJobFailedError',
324323
reasonDesc: 'CodeScanJobFailedError: Security scan failed.',
325324
passive: false,
326-
} as unknown as CodewhispererSecurityScan)
325+
})
327326
})
328327

329328
it('Should show notification when throttled for project scans', async function () {
@@ -353,7 +352,7 @@ describe('startSecurityScan', function () {
353352
reason: 'ThrottlingException',
354353
reasonDesc: `ThrottlingException: Maximum com.amazon.aws.codewhisperer.StartCodeAnalysis reached for this month.`,
355354
passive: false,
356-
} as unknown as CodewhispererSecurityScan)
355+
})
357356
})
358357

359358
it('Should set monthly quota exceeded when throttled for auto file scans', async function () {
@@ -385,6 +384,6 @@ describe('startSecurityScan', function () {
385384
reason: 'ThrottlingException',
386385
reasonDesc: 'ThrottlingException: Maximum file scans count reached for this month',
387386
passive: true,
388-
} as unknown as CodewhispererSecurityScan)
387+
})
389388
})
390389
})

packages/core/src/test/shared/telemetry/spans.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('TelemetryTracer', function () {
102102
})
103103

104104
assertTelemetry(metricName, { result: 'Succeeded', source: 'bar' })
105-
assertTelemetry('apigateway_copyUrl', {} as MetricShapes['apigateway_copyUrl'])
105+
assertTelemetry('apigateway_copyUrl', {})
106106
})
107107

108108
it('writes to all new spans in the current context', function () {
@@ -112,7 +112,7 @@ describe('TelemetryTracer', function () {
112112
})
113113

114114
assertTelemetry(metricName, { result: 'Succeeded', source: 'bar' })
115-
assertTelemetry('apigateway_copyUrl', { result: 'Succeeded', source: 'bar' } as any)
115+
assertTelemetry('apigateway_copyUrl', { result: 'Succeeded', source: 'bar' })
116116
})
117117

118118
it('does not propagate state outside of the execution', function () {
@@ -310,7 +310,7 @@ describe('TelemetryTracer', function () {
310310
it('attaches the parent id to the child span', function () {
311311
tracer.run(metricName, () => tracer.run(nestedName, () => {}))
312312
assertTelemetry(metricName, { result: 'Succeeded' })
313-
assertTelemetry(nestedName, { result: 'Succeeded', parentId: testId } as any)
313+
assertTelemetry(nestedName, { result: 'Succeeded', parentId: testId })
314314
})
315315

316316
it('should set trace id', function () {

packages/core/src/test/testUtil.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,15 @@ export function assertNoTelemetryMatch(re: RegExp | string): void | never {
313313
*/
314314
export function assertTelemetry<K extends MetricName>(
315315
name: K,
316-
expected: MetricShapes[K] | MetricShapes[K][]
316+
expected: Partial<MetricShapes[K]> | Partial<MetricShapes[K]>[]
317317
): void | never
318318
export function assertTelemetry<K extends MetricName>(
319319
name: K,
320-
expected: MetricShapes[MetricName] | MetricShapes[MetricName][]
320+
expected: Partial<MetricShapes[MetricName]> | Partial<MetricShapes[MetricName]>[]
321321
): void | never
322322
export function assertTelemetry<K extends MetricName>(
323323
name: K,
324-
expected: MetricShapes[K] | MetricShapes[K][]
324+
expected: Partial<MetricShapes[K]> | Partial<MetricShapes[K]>[]
325325
): void | never {
326326
const expectedList = Array.isArray(expected) ? expected : [expected]
327327
const query = { metricName: name }

0 commit comments

Comments
 (0)