From 75f7ae5f6f3da3e6285f1a40bc32e8812c1fef90 Mon Sep 17 00:00:00 2001 From: waleedcodes <110061477+waleedcodes@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:26:15 +0500 Subject: [PATCH 1/3] test(quickfix): scaffold code action provider test suite --- tests/codeActionProvider.test.ts | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/codeActionProvider.test.ts diff --git a/tests/codeActionProvider.test.ts b/tests/codeActionProvider.test.ts new file mode 100644 index 0000000..7a8a948 --- /dev/null +++ b/tests/codeActionProvider.test.ts @@ -0,0 +1,35 @@ +import { describe, expect, it } from 'vitest'; +import * as vscode from 'vscode'; +import { ProofCodeCodeActionProvider } from '../src/ui/codeActionProvider'; + +describe('ProofCodeCodeActionProvider', () => { + const mockDocument: any = { + uri: vscode.Uri.file('/src/auth.ts'), + lineAt: (line: number) => ({ + text: ' const user = await db.user.findUnique({ where: { id } });', + range: new vscode.Range(line, 0, line, 60) + }) + }; + + it('should return empty actions when no ProofCode diagnostics are present', () => { + const provider = new ProofCodeCodeActionProvider(); + const actions = provider.provideCodeActions( + mockDocument, + new vscode.Range(0, 0, 0, 0), + { + diagnostics: [ + new vscode.Diagnostic( + new vscode.Range(0, 0, 0, 0), + 'Some external linter error', + vscode.DiagnosticSeverity.Error + ) + ] + } as any, + {} as any + ); + + expect(actions).toEqual([]); + }); + + it('should provide QuickFix to wrap unhandled async operation in try/catch (PC-REL-006)', () => { + const provider = new ProofCodeCodeActionProvider(); From 64cf50ab1565c7f3b65c47fe385dcf647f89ce88 Mon Sep 17 00:00:00 2001 From: waleedcodes <110061477+waleedcodes@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:26:15 +0500 Subject: [PATCH 2/3] test(quickfix): test try/catch wrap quick fix for PC-REL-006 --- tests/codeActionProvider.test.ts | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/codeActionProvider.test.ts b/tests/codeActionProvider.test.ts index 7a8a948..8de5b19 100644 --- a/tests/codeActionProvider.test.ts +++ b/tests/codeActionProvider.test.ts @@ -33,3 +33,43 @@ describe('ProofCodeCodeActionProvider', () => { it('should provide QuickFix to wrap unhandled async operation in try/catch (PC-REL-006)', () => { const provider = new ProofCodeCodeActionProvider(); + const diag = new vscode.Diagnostic( + new vscode.Range(1, 4, 1, 30), + '[PC-REL-006] Unhandled Asynchronous Operation', + vscode.DiagnosticSeverity.Information + ); + diag.source = 'ProofCode'; + diag.code = 'PC-REL-006'; + + const actions = provider.provideCodeActions( + mockDocument, + new vscode.Range(1, 0, 1, 0), + { diagnostics: [diag] } as any, + {} as any + ); + + expect(actions.length).toBe(1); + expect(actions[0].title).toContain('Wrap in try/catch block'); + expect(actions[0].edit).toBeDefined(); + expect(actions[0].isPreferred).toBe(true); + }); + + it('should provide QuickFixes for unhandled null database result (PC-DATA-001)', () => { + const provider = new ProofCodeCodeActionProvider(); + const diag = new vscode.Diagnostic( + new vscode.Range(1, 4, 1, 30), + '[PC-DATA-001] Unhandled Null/Undefined Database Result (user)', + vscode.DiagnosticSeverity.Warning + ); + diag.source = 'ProofCode'; + diag.code = 'PC-DATA-001'; + + const actions = provider.provideCodeActions( + mockDocument, + new vscode.Range(1, 0, 1, 0), + { diagnostics: [diag] } as any, + {} as any + ); + + expect(actions.length).toBeGreaterThanOrEqual(1); + const guardAction = actions.find((a) => a.title.includes('null guard')); From f01c29bc431c329255ea4118a939f99bc061c907 Mon Sep 17 00:00:00 2001 From: waleedcodes <110061477+waleedcodes@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:26:15 +0500 Subject: [PATCH 3/3] test(quickfix): test null guard and session auth insertion quick fixes --- tests/codeActionProvider.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/codeActionProvider.test.ts b/tests/codeActionProvider.test.ts index 8de5b19..c8c6d8e 100644 --- a/tests/codeActionProvider.test.ts +++ b/tests/codeActionProvider.test.ts @@ -73,3 +73,29 @@ describe('ProofCodeCodeActionProvider', () => { expect(actions.length).toBeGreaterThanOrEqual(1); const guardAction = actions.find((a) => a.title.includes('null guard')); + expect(guardAction).toBeDefined(); + expect(guardAction?.title).toContain('if (!user)'); + }); + + it('should provide QuickFix for missing authorization in API route (PC-AUTH-001)', () => { + const provider = new ProofCodeCodeActionProvider(); + const diag = new vscode.Diagnostic( + new vscode.Range(0, 0, 0, 20), + '[PC-AUTH-001] Missing Authorization Check in API Route (GET)', + vscode.DiagnosticSeverity.Error + ); + diag.source = 'ProofCode'; + diag.code = 'PC-AUTH-001'; + + const actions = provider.provideCodeActions( + mockDocument, + new vscode.Range(0, 0, 0, 0), + { diagnostics: [diag] } as any, + {} as any + ); + + expect(actions.length).toBe(1); + expect(actions[0].title).toContain('session authentication guard'); + expect(actions[0].edit).toBeDefined(); + }); +});