Skip to content

Commit 3ebad83

Browse files
committed
Address typings and duration
1 parent dd6862f commit 3ebad83

7 files changed

Lines changed: 51 additions & 41 deletions

File tree

tools/lspClient/LspClient.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import {
77
IPCMessageReader,
88
IPCMessageWriter,
99
TextDocumentContentChangeEvent,
10+
ConfigurationParams,
1011
} from 'vscode-languageserver-protocol/node';
12+
import { Hover, CompletionList } from 'vscode-languageserver-types';
1113
import { randomBytes } from 'crypto';
1214
import { CompactEncrypt } from 'jose';
1315
import { LspClientConfig, LspConnection } from './LspConnection';
@@ -70,14 +72,12 @@ export class LspClient implements LspConnection {
7072

7173
// Handle workspace/configuration requests from server
7274

73-
this.connection.onRequest('workspace/configuration', (params: any) => {
74-
// Extract the specific configuration section requested
75+
this.connection.onRequest('workspace/configuration', (params: ConfigurationParams) => {
7576
if (params?.items?.length > 0) {
76-
const results = params.items.map((item: any) => {
77+
const results = params.items.map((item) => {
7778
if (item.section === 'aws.cloudformation') {
78-
// Return just the CloudFormation config part
7979
const fullConfig = this.workspaceConfig[0] ?? {};
80-
return (fullConfig as any)['aws.cloudformation'] ?? {};
80+
return fullConfig['aws.cloudformation'] ?? {};
8181
}
8282
return {};
8383
});
@@ -208,21 +208,21 @@ export class LspClient implements LspConnection {
208208
});
209209
}
210210

211-
async hover(uri: string, line: number, character: number): Promise<any> {
211+
async hover(uri: string, line: number, character: number): Promise<Hover | null> {
212212
return await this.connection!.sendRequest('textDocument/hover', {
213213
textDocument: { uri },
214214
position: { line, character },
215215
});
216216
}
217217

218-
async completion(uri: string, line: number, character: number): Promise<any> {
218+
async completion(uri: string, line: number, character: number): Promise<CompletionList | null> {
219219
return await this.connection!.sendRequest('textDocument/completion', {
220220
textDocument: { uri },
221221
position: { line, character },
222222
});
223223
}
224224

225-
async changeConfiguration(params: { settings: any }): Promise<void> {
225+
async changeConfiguration(params: { settings: Record<string, unknown> }): Promise<void> {
226226
// Store the new configuration
227227
if (params.settings) {
228228
const currentConfig = this.workspaceConfig[0] ?? {};
@@ -281,7 +281,7 @@ export class LspClient implements LspConnection {
281281
}
282282

283283
async getSystemStatus(): Promise<GetSystemStatusResponse> {
284-
return await this.sendRequest('aws/system/status', {});
284+
return (await this.sendRequest('aws/system/status', {})) as GetSystemStatusResponse;
285285
}
286286

287287
async shutdown(): Promise<void> {

tools/stability/Monitoring.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export type TestMetrics = {
66
minDuration: number | null;
77
maxDuration: number | null;
88
lastDuration: number | null;
9-
durations: number[];
109
};
1110

1211
const createEmptyMetrics = (): TestMetrics => ({
@@ -15,7 +14,6 @@ const createEmptyMetrics = (): TestMetrics => ({
1514
minDuration: null,
1615
maxDuration: null,
1716
lastDuration: null,
18-
durations: [],
1917
});
2018

2119
const metrics: Record<OperationType, TestMetrics> = {} as Record<OperationType, TestMetrics>;
@@ -34,7 +32,6 @@ export function recordOperation(duration: number, operationType: OperationType):
3432
metric.minDuration = metric.minDuration === null ? duration : Math.min(metric.minDuration, duration);
3533
metric.maxDuration = metric.maxDuration === null ? duration : Math.max(metric.maxDuration, duration);
3634
metric.lastDuration = duration;
37-
metric.durations.push(duration);
3835
}
3936

4037
let startTime: number;
@@ -61,8 +58,8 @@ export function logProgress(): void {
6158
}
6259
}
6360

64-
export function generateFinalReport(testStartTime: number): void {
65-
const runtime = Date.now() - testStartTime;
61+
export function generateFinalReport(): void {
62+
const runtime = Date.now() - startTime;
6663

6764
console.log('Final Test Report');
6865
console.log('='.repeat(50));

tools/stability/TestOrchestrator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { initializeMonitoring, logProgress, checkPerformanceDegradation } from '
44
import { HoverTester } from './testers/HoverTester';
55
import { CompletionTester } from './testers/CompletionTester';
66
import { TEST_TEMPLATES } from './Templates';
7+
import { nextDocumentVersion, resetDocumentVersion } from './testers/TesterUtils';
78
import { AwsRegion } from '../../src/utils/Region';
89
import { WaitFor } from '../../tst/utils/Utils';
910
import { existsSync } from 'fs';
@@ -141,12 +142,13 @@ export class TestOrchestrator {
141142
const uri = `file:///test/${template.fileName}`;
142143

143144
try {
145+
resetDocumentVersion();
144146
await this.client.openDocument(uri, template.contents);
145147

146148
await this.validateLsp(uri);
147149

148150
// Revert document to original state after tests
149-
await this.client.updateDocument(uri, 6, template.contents);
151+
await this.client.updateDocument(uri, nextDocumentVersion(), template.contents);
150152
} finally {
151153
try {
152154
await this.client.closeDocument(uri);

tools/stability/runStabilityTest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ async function main(): Promise<void> {
77
try {
88
await orchestrator.initialize();
99
await orchestrator.runTests();
10-
generateFinalReport(Date.now());
10+
generateFinalReport();
1111
} catch (error) {
12-
generateFinalReport(Date.now());
12+
generateFinalReport();
1313
console.error('Test failed:', error);
1414
throw error;
1515
} finally {

tools/stability/testers/CompletionTester.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { LspClient } from '../../lspClient/LspClient';
2+
import { CompletionList } from 'vscode-languageserver-types';
23
import { OperationTester, OperationType } from './TesterTypes';
3-
import { retryOperationWithPerformance } from './TesterUtils';
4+
import { retryOperationWithPerformance, nextDocumentVersion } from './TesterUtils';
45

56
export class CompletionTester implements OperationTester {
67
constructor(private readonly client: LspClient) {}
78

8-
private validateCompletionItems(result: any, requiredLabels: string[], context: string): void {
9-
if (!result?.items || !Array.isArray(result.items) || result.items.length === 0) {
9+
private validateCompletionItems(result: CompletionList | null, requiredLabels: string[], context: string): void {
10+
if (!result?.items || result.items.length === 0) {
1011
throw new Error(`${context} returned no items`);
1112
}
1213

13-
const labels = new Set(result.items.map((item: any) => item.label as string));
14+
const labels = new Set(result.items.map((item) => item.label));
1415
for (const required of requiredLabels) {
1516
if (!labels.has(required)) {
1617
throw new Error(`${context} missing ${required}`);
@@ -23,11 +24,12 @@ export class CompletionTester implements OperationTester {
2324
const basicTemplate = `AWSTemplateFormatVersion: '2010-09-09'
2425
`;
2526

26-
await this.client.updateDocument(uri, 4, basicTemplate);
27+
await this.client.updateDocument(uri, nextDocumentVersion(), basicTemplate);
2728

2829
await retryOperationWithPerformance(
2930
() => this.client.completion(uri, 1, 0),
30-
(result: any) => this.validateCompletionItems(result, ['Resources', 'Parameters'], 'Top-level completion'),
31+
(result: CompletionList | null) =>
32+
this.validateCompletionItems(result, ['Resources', 'Parameters'], 'Top-level completion'),
3133
OperationType.COMPLETION,
3234
);
3335

@@ -39,7 +41,7 @@ Resources:
3941
Properties:
4042
`;
4143

42-
await this.client.updateDocument(uri, 5, [
44+
await this.client.updateDocument(uri, nextDocumentVersion(), [
4345
{
4446
range: { start: { line: 1, character: 0 }, end: { line: 1, character: 0 } },
4547
text: resourceSection,
@@ -48,7 +50,8 @@ Resources:
4850

4951
await retryOperationWithPerformance(
5052
() => this.client.completion(uri, 6, 6),
51-
(result: any) => this.validateCompletionItems(result, ['BucketName', 'Tags'], 'S3 bucket completion'),
53+
(result: CompletionList | null) =>
54+
this.validateCompletionItems(result, ['BucketName', 'Tags'], 'S3 bucket completion'),
5255
OperationType.COMPLETION,
5356
);
5457
}

tools/stability/testers/HoverTester.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import { LspClient } from '../../lspClient/LspClient';
2+
import { Hover, MarkupContent } from 'vscode-languageserver-types';
23
import { OperationTester, OperationType } from './TesterTypes';
3-
import { retryOperationWithPerformance } from './TesterUtils';
4+
import { retryOperationWithPerformance, nextDocumentVersion } from './TesterUtils';
45

56
export class HoverTester implements OperationTester {
67
constructor(private readonly client: LspClient) {}
78

8-
private extractHoverContent(hoverResult: any): string {
9-
if (typeof hoverResult.contents === 'string') {
10-
return hoverResult.contents as string;
11-
} else if (Array.isArray(hoverResult.contents)) {
12-
return hoverResult.contents.length > 0 ? JSON.stringify(hoverResult.contents) : '';
13-
} else if (
14-
hoverResult.contents &&
15-
typeof hoverResult.contents === 'object' &&
16-
'value' in hoverResult.contents
17-
) {
18-
return hoverResult.contents.value as string;
9+
private extractHoverContent(hoverResult: Hover): string {
10+
const contents = hoverResult.contents;
11+
if (typeof contents === 'string') {
12+
return contents;
13+
} else if (Array.isArray(contents)) {
14+
return contents.length > 0 ? JSON.stringify(contents) : '';
15+
} else if ('value' in contents) {
16+
return (contents as MarkupContent).value;
1917
}
2018
return '';
2119
}
@@ -43,11 +41,11 @@ Resources:
4341
BucketName: TestName
4442
`;
4543

46-
await this.client.updateDocument(uri, 2, s3Template);
44+
await this.client.updateDocument(uri, nextDocumentVersion(), s3Template);
4745

4846
await retryOperationWithPerformance(
4947
() => this.client.hover(uri, 3, 15),
50-
(result: any) => {
48+
(result: Hover | null) => {
5149
if (!result?.contents) {
5250
throw new Error('Hover on resource type returned no content');
5351
}
@@ -66,7 +64,7 @@ Parameters:
6664
Default: TestValue
6765
`;
6866

69-
await this.client.updateDocument(uri, 3, [
67+
await this.client.updateDocument(uri, nextDocumentVersion(), [
7068
{
7169
range: { start: { line: 6, character: 0 }, end: { line: 6, character: 0 } },
7270
text: parametersSection,
@@ -75,7 +73,7 @@ Parameters:
7573

7674
await retryOperationWithPerformance(
7775
() => this.client.hover(uri, 8, 10),
78-
(result: any) => {
76+
(result: Hover | null) => {
7977
if (!result?.contents) {
8078
throw new Error('Hover on parameter returned no content');
8179
}

tools/stability/testers/TesterUtils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import { OperationType, TESTER_CONFIG } from './TesterTypes';
44

55
const RETRY_INTERVAL_MS = 250;
66

7+
let documentVersion = 1;
8+
9+
export function nextDocumentVersion(): number {
10+
return ++documentVersion;
11+
}
12+
13+
export function resetDocumentVersion(): void {
14+
documentVersion = 1;
15+
}
16+
717
export async function retryOperationWithPerformance<T>(
818
operation: () => Promise<T>,
919
validate: (result: T) => void,

0 commit comments

Comments
 (0)