UNPKG

ctrlshiftleft

Version:

AI-powered toolkit for embedding QA and security testing into development workflows

179 lines (178 loc) 6.2 kB
/** * ctrl.shift.left API * * This module provides programmatic access to ctrl.shift.left functionality, * allowing other tools (like Cursor AI) to leverage test generation, security analysis, * and QA checklist creation capabilities. */ import { TestGenerator } from '../core/testGenerator'; import { TestRunner } from '../core/testRunner'; import { ChecklistGenerator } from '../core/checklistGenerator'; import { EnhancedWatcher } from '../core/enhancedWatcher'; export * from '../types/testTypes'; export * from '../types/checklistTypes'; import type { AISecurityAnalysisResult } from '../ai-security-analyzer'; /** * Options for test generation */ export interface TestGenerationOptions { /** Test format ('playwright' or 'selenium') */ format?: 'playwright' | 'selenium'; /** Output directory for the generated tests */ outputDir?: string; /** Timeout in seconds for test generation */ timeout?: number; /** Whether to create page objects */ pageObjects?: boolean; /** Whether to use visual testing */ visualTesting?: boolean; } /** * Result of test generation */ export interface TestGenerationResult { /** Number of tests generated */ testCount: number; /** Paths to the generated test files */ files: string[]; /** Total generation time in milliseconds */ generationTime: number; } /** * Options for security analysis */ export interface SecurityAnalysisOptions { /** Whether to use AI-enhanced analysis (requires OpenAI API key) */ useAI?: boolean; /** Output file for the security report */ outputFile?: string; /** Output format (markdown or json) */ format?: 'markdown' | 'json'; /** OpenAI API key (optional, will use environment variable if not provided) */ apiKey?: string; /** OpenAI model to use (defaults to gpt-4) */ model?: string; } /** * Result of security analysis */ export interface SecurityAnalysisResult { /** Security score (0-100) */ score: number; /** Number of issues found */ issuesFound: number; /** Issues by severity */ issuesBySeverity: Record<string, number>; /** Path to the generated report */ reportPath: string; /** Whether AI-enhanced analysis was used */ aiEnhanced: boolean; } /** * Options for checklist generation */ export interface ChecklistOptions { /** Type of checklist to generate */ type?: 'all' | 'qa' | 'security'; /** Output format */ format?: 'json' | 'markdown'; /** Output file for the checklist */ outputFile?: string; } /** * Result of checklist generation */ export interface ChecklistResult { /** Number of checklist items */ itemCount: number; /** Path to the generated checklist file */ filePath: string; /** Component or source file name */ componentName: string; /** Categories covered */ categories: string[]; /** Count of passing items */ passingCount: number; /** Count of failing items */ failingCount: number; /** Count of items needing review */ reviewCount: number; } /** * Options for file watching */ export interface WatchOptions { /** Glob patterns to include */ include?: string[]; /** Glob patterns to exclude */ exclude?: string[]; /** Whether to generate tests on file changes */ generateTests?: boolean; /** Whether to analyze security on file changes */ analyzeSecurity?: boolean; /** Whether to generate checklists on file changes */ generateChecklists?: boolean; /** Callback function when a file changes */ onChange?: (filePath: string) => void | Promise<void>; } /** * Generates end-to-end tests for a component or source file * * @param sourcePath - Path to the source file or directory * @param options - Test generation options * @returns Promise resolving to the test generation result */ export declare function generateTests(sourcePath: string, options?: TestGenerationOptions): Promise<TestGenerationResult>; /** * Analyzes code for security vulnerabilities * * @param sourcePath - Path to the source file to analyze * @param options - Security analysis options * @returns Promise resolving to the security analysis result */ export declare function analyzeSecurity(sourcePath: string, options?: SecurityAnalysisOptions): Promise<SecurityAnalysisResult>; /** * Generates a QA and security checklist for a source file or component * * @param sourcePath - Path to the source file or directory * @param options - Checklist generation options * @returns Promise resolving to the checklist generation result */ export declare function generateChecklist(sourcePath: string, options?: ChecklistOptions): Promise<ChecklistResult>; /** * Watches for file changes and triggers actions like test generation or security analysis * * @param directory - Directory to watch for changes * @param options - Watch options * @returns Function to stop watching */ export declare function watch(directory: string, options?: WatchOptions): () => void; /** * Analyze file security using AI-enhanced analysis if available * @param filePath Path to the file to analyze * @param options Analysis options * @returns Analysis result */ export declare function analyzeSecurityWithAI(filePath: string, options?: any): Promise<AISecurityAnalysisResult>; /** * Check if AI security analysis is available * @returns Whether AI security analysis is available */ export declare function isAISecurityAvailable(): boolean; /** * Set the OpenAI API key for AI-enhanced security analysis * @param apiKey OpenAI API key */ export declare function setAISecurityApiKey(apiKey: string): void; export type ChecklistStatus = 'pending' | 'passed' | 'failed' | 'na'; export { TestGenerator, TestRunner, ChecklistGenerator, EnhancedWatcher }; declare const _default: { generateTests: typeof generateTests; analyzeSecurity: typeof analyzeSecurity; generateChecklist: typeof generateChecklist; watch: typeof watch; analyzeSecurityWithAI: typeof analyzeSecurityWithAI; isAISecurityAvailable: typeof isAISecurityAvailable; setAISecurityApiKey: typeof setAISecurityApiKey; }; export default _default;