From 61af7dc33943588a27ef9735af6a9ec46f1433d0 Mon Sep 17 00:00:00 2001 From: waleedcodes <110061477+waleedcodes@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:24:19 +0500 Subject: [PATCH 1/3] test(ast): scaffold AST analyzer test suite --- tests/astAnalyzer.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/astAnalyzer.test.ts diff --git a/tests/astAnalyzer.test.ts b/tests/astAnalyzer.test.ts new file mode 100644 index 0000000..ac0f9a4 --- /dev/null +++ b/tests/astAnalyzer.test.ts @@ -0,0 +1,22 @@ +import { describe, expect, it } from 'vitest'; +import { AstAnalyzer } from '../src/analyzer/astAnalyzer'; + +describe('AstAnalyzer', () => { + it('should extract exported functions and their calls', () => { + const code = ` +import { db } from './db'; + +export function getUser(userId: string) { + const user = db.user.findUnique(userId); + return user; +} + +export const updateUser = (userId: string, data: any) => { + db.user.update(userId, data); +}; +`; + + const analysis = AstAnalyzer.analyzeFile('/test/auth.ts', code); + expect(analysis.symbols).toHaveLength(2); + expect(analysis.symbols[0].name).toBe('getUser'); + expect(analysis.symbols[0].isExported).toBe(true); From 7f5a45930a4a35da589d46d492dba1faa18b8721 Mon Sep 17 00:00:00 2001 From: waleedcodes <110061477+waleedcodes@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:24:19 +0500 Subject: [PATCH 2/3] test(ast): test function, class, and variable symbol extraction --- tests/astAnalyzer.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/astAnalyzer.test.ts b/tests/astAnalyzer.test.ts index ac0f9a4..361041f 100644 --- a/tests/astAnalyzer.test.ts +++ b/tests/astAnalyzer.test.ts @@ -20,3 +20,29 @@ export const updateUser = (userId: string, data: any) => { expect(analysis.symbols).toHaveLength(2); expect(analysis.symbols[0].name).toBe('getUser'); expect(analysis.symbols[0].isExported).toBe(true); + expect(analysis.symbols[0].calls).toContain('findUnique'); + + expect(analysis.symbols[1].name).toBe('updateUser'); + expect(analysis.symbols[1].kind).toBe('arrow_function'); + expect(analysis.symbols[1].isExported).toBe(true); + }); + + it('should detect Next.js App Router API endpoints', () => { + const code = ` +export async function GET(request: Request) { + return Response.json({ ok: true }); +} + +export async function POST(request: Request) { + return Response.json({ created: true }); +} +`; + + const analysis = AstAnalyzer.analyzeFile('/app/api/orders/route.ts', code); + expect(analysis.hasApiRoute).toBe(true); + expect(analysis.apiRoutes).toHaveLength(2); + expect(analysis.apiRoutes[0].method).toBe('GET'); + expect(analysis.apiRoutes[1].method).toBe('POST'); + }); + + it('should find symbols intersecting with modified lines', () => { From 739c36d5ba2affc7d2314aac80c26ede5978aa70 Mon Sep 17 00:00:00 2001 From: waleedcodes <110061477+waleedcodes@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:24:19 +0500 Subject: [PATCH 3/3] test(ast): test import/export resolution and Next.js API route detection --- tests/astAnalyzer.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/astAnalyzer.test.ts b/tests/astAnalyzer.test.ts index 361041f..856335f 100644 --- a/tests/astAnalyzer.test.ts +++ b/tests/astAnalyzer.test.ts @@ -46,3 +46,19 @@ export async function POST(request: Request) { }); it('should find symbols intersecting with modified lines', () => { + const code = ` +export function first() { + return 1; +} + +export function second() { + return 2; +} +`; + const analysis = AstAnalyzer.analyzeFile('/test/funcs.ts', code); + // line 2 is in 'first' + const touched = AstAnalyzer.findSymbolsAtLines(analysis.symbols, [3]); + expect(touched).toHaveLength(1); + expect(touched[0].name).toBe('first'); + }); +});