import { jest, expect, describe, beforeEach, it } from '@jest/globals' import { FixVerifier, createVerifier } from '../fix-verifier' import { Project } from 'ts-morph' // Mock fs and child_process jest.mock('fs', () => ({ existsSync: jest.fn(), readFileSync: jest.fn(), writeFileSync: jest.fn(), unlinkSync: jest.fn(), statSync: jest.fn(), })) jest.mock('child_process', () => ({ execSync: jest.fn(), })) jest.mock('../utils', () => ({ prixExec: jest.fn(), })) describe('FixVerifier', () => { let verifier: FixVerifier let project: Project beforeEach(() => { jest.clearAllMocks() project = new Project() verifier = new FixVerifier({}, project) }) describe('constructor', () => { it('should create verifier with default config', () => { const v = new FixVerifier() expect(v).toBeInstanceOf(FixVerifier) }) it('should merge custom config with defaults', () => { const v = new FixVerifier({ maxRetries: 5, enableTests: true }) expect(v).toBeInstanceOf(FixVerifier) }) }) describe('verify', () => { it('should pass for valid TypeScript code', async () => { const { existsSync } = await import('fs') ;(existsSync as jest.MockedFunction).mockReturnValue(false) const result = await verifier.verify( 'test.ts', 'const x: number = 5;', 1, 1, '/tmp' ) expect(result.passed).toBe(true) expect(result.checks.length).toBeGreaterThan(0) }) it('should fail for invalid syntax', async () => { const { existsSync } = await import('fs') ;(existsSync as jest.MockedFunction).mockReturnValue(false) const result = await verifier.verify( 'test.ts', 'const x = ', // Invalid syntax 1, 1, '/tmp' ) expect(result.passed).toBe(false) expect(result.canRetry).toBe(true) }) it('should support multiple file types', async () => { const { existsSync } = await import('fs') ;(existsSync as jest.MockedFunction).mockReturnValue(false) const jsResult = await verifier.verify('test.js', 'const x = 5;', 1, 1, '/tmp') expect(jsResult).toHaveProperty('passed') const pyResult = await verifier.verify('test.py', 'x = 5', 1, 1, '/tmp') expect(pyResult).toHaveProperty('passed') const goResult = await verifier.verify('test.go', 'package main', 1, 1, '/tmp') expect(goResult).toHaveProperty('passed') }) }) describe('createVerifier', () => { it('should create a verifier with optional project', () => { const v = createVerifier() expect(v).toBeInstanceOf(FixVerifier) }) }) })