UNPKG

@iservu-inc/adf-cli

Version:

CLI tool for AgentDevFramework - AI-assisted development framework with multi-provider AI support

174 lines (139 loc) 7.01 kB
const AnswerQualityAnalyzer = require('../lib/frameworks/answer-quality-analyzer'); describe('AnswerQualityAnalyzer', () => { describe('analyze', () => { it('should score high-quality comprehensive answer highly', () => { const question = { keywords: ['react', 'typescript', 'web'], requiredElements: ['platform', 'technology'] }; const answer = 'I am building a React 18 web dashboard using TypeScript and Node.js. ' + 'The platform is web-based, responsive design for desktop and mobile. ' + 'It will display real-time analytics data fetched from a PostgreSQL database. ' + 'Users can filter data by date range, export to CSV, and create custom views. ' + 'The tech stack includes Next.js 14 for the frontend, Express.js for the API, ' + 'and we will use Chart.js for data visualization. File structure will be ' + 'src/components/, src/api/, src/utils/. The main components are Dashboard, ' + 'DataTable, ChartView, and FilterPanel.'; const metrics = AnswerQualityAnalyzer.analyze(answer, question); expect(metrics.qualityScore).toBeGreaterThan(80); expect(metrics.isComprehensive).toBe(true); expect(metrics.wordCount).toBeGreaterThan(50); expect(metrics.hasKeywords.matched).toContain('react'); expect(metrics.hasKeywords.matched).toContain('typescript'); expect(metrics.hasRequiredElements.detected).toContain('platform'); expect(metrics.hasRequiredElements.detected).toContain('technology'); }); it('should score low-quality vague answer poorly', () => { const question = { keywords: ['react', 'typescript', 'nextjs'], requiredElements: ['platform', 'technology'] }; const answer = 'An app'; const metrics = AnswerQualityAnalyzer.analyze(answer, question); expect(metrics.qualityScore).toBeLessThan(30); expect(metrics.isComprehensive).toBe(false); expect(metrics.wordCount).toBeLessThan(5); expect(metrics.hasKeywords.matched.length).toBe(0); }); it('should detect bullet points and examples', () => { const question = { keywords: [], requiredElements: [] }; const answer = 'The features include user authentication, dashboard, and export. ' + 'This allows for better security. ' + 'For example, users can click the export button to download CSV files.'; const metrics = AnswerQualityAnalyzer.analyze(answer, question); expect(metrics.isDetailed.hasMultipleSentences).toBe(true); expect(metrics.isDetailed.hasExamples).toBe(true); }); it('should detect technical depth', () => { const question = { keywords: [], requiredElements: [] }; const answer = 'Using React 18.2.0 with TypeScript. Will deploy to AWS using Docker containers. ' + 'Database is PostgreSQL 15. API endpoints follow REST conventions.'; const metrics = AnswerQualityAnalyzer.analyze(answer, question); expect(metrics.hasTechnicalDepth.hasTechStack).toBe(true); expect(metrics.hasTechnicalDepth.hasVersions).toBe(true); expect(metrics.hasTechnicalDepth.hasSpecificTools).toBe(true); }); it('should allow skipping follow-ups for excellent answers', () => { const question = { keywords: ['react', 'web', 'api'], requiredElements: ['platform', 'technology', 'user-interaction'] }; const answer = 'Building a React web application with TypeScript and Next.js 14. ' + 'The platform is web-based, responsive design. Users can click buttons to submit forms, ' + 'search and filter data, and view real-time updates. Technology stack includes React 18, ' + 'TypeScript 5, Node.js 20, PostgreSQL 15, and Docker for deployment. ' + 'API endpoints: GET /api/users, POST /api/users, PUT /api/users/:id. ' + 'File structure: src/components/, src/pages/, src/api/, src/utils/. ' + 'Main components: UserList, UserForm, SearchBar, FilterPanel.'; const metrics = AnswerQualityAnalyzer.analyze(answer, question); expect(metrics.canSkipFollowUps).toBe(true); expect(metrics.qualityScore).toBeGreaterThanOrEqual(85); }); }); describe('getFeedback', () => { it('should return excellent feedback for score >= 90', () => { const metrics = { qualityScore: 95 }; const feedback = AnswerQualityAnalyzer.getFeedback(metrics); expect(feedback).toContain('Excellent'); }); it('should return good feedback for score >= 70', () => { const metrics = { qualityScore: 75 }; const feedback = AnswerQualityAnalyzer.getFeedback(metrics); expect(feedback).toContain('Great'); }); it('should return null for low scores', () => { const metrics = { qualityScore: 45 }; const feedback = AnswerQualityAnalyzer.getFeedback(metrics); expect(feedback).toBeNull(); }); }); describe('getWordCount', () => { it('should count words correctly', () => { expect(AnswerQualityAnalyzer.getWordCount('Hello world')).toBe(2); expect(AnswerQualityAnalyzer.getWordCount('This is a test sentence.')).toBe(5); expect(AnswerQualityAnalyzer.getWordCount(' Multiple spaces here ')).toBe(3); }); }); describe('checkKeywords', () => { it('should match keywords case-insensitively', () => { const result = AnswerQualityAnalyzer.checkKeywords( 'Using React and TypeScript', ['react', 'typescript', 'node'] ); expect(result.matched).toContain('react'); expect(result.matched).toContain('typescript'); expect(result.count).toBe(2); expect(result.total).toBe(3); }); }); describe('checkRequiredElements', () => { it('should detect platform element', () => { const result = AnswerQualityAnalyzer.checkRequiredElements( 'This is a web application for mobile users', ['platform'] ); expect(result.detected).toContain('platform'); }); it('should detect technology element', () => { const result = AnswerQualityAnalyzer.checkRequiredElements( 'Built with React and Node.js', ['technology'] ); expect(result.detected).toContain('technology'); }); it('should detect API endpoints', () => { const result = AnswerQualityAnalyzer.checkRequiredElements( 'API has GET /api/users and POST /api/users endpoints', ['api-endpoints'] ); expect(result.detected).toContain('api-endpoints'); }); it('should detect file paths', () => { const result = AnswerQualityAnalyzer.checkRequiredElements( 'Files are in src/components/ and app/utils/helper.ts', ['file-paths'] ); expect(result.detected).toContain('file-paths'); }); }); });