aiwg
Version:
Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo
216 lines • 6.44 kB
TypeScript
/**
* NFRTestGenerator - Generate automated test suites from NFR specifications
*
* Transforms NFR specifications (from ground truth corpus) into executable
* Vitest test files with statistical assertions, performance targets, and
* accuracy validation.
*
* Features:
* - Generate performance benchmark tests (p95, p99 targets)
* - Generate accuracy validation tests (false positive/negative rates)
* - Generate reliability tests (success rate, retry behavior)
* - Statistical assertions (95% confidence intervals)
* - Ground truth baseline integration
* - Customizable tolerance and strictness
*
* @module testing/nfr-test-generator
*/
/**
* NFR Ground Truth Corpus - Baseline measurements for NFR validation
*/
export interface NFRGroundTruthCorpus {
nfrs: Map<string, NFRBaseline>;
version: string;
lastUpdated: string;
}
/**
* Baseline measurement for a single NFR
*/
export interface NFRBaseline {
nfrId: string;
category: 'Performance' | 'Accuracy' | 'Reliability' | 'Usability' | 'Security';
description: string;
target: number;
unit: string;
baseline: number;
tolerance: number;
priority: 'P0' | 'P1' | 'P2';
measurementMethod: string;
testCases: string[];
}
/**
* Options for test suite generation
*/
export interface GenerateOptions {
/** Include explanatory comments in generated tests */
includeComments?: boolean;
/** Include ground truth baselines as comments */
includeGroundTruth?: boolean;
/** Fail test on any deviation from baseline (no tolerance) */
strictMode?: boolean;
/** Override default tolerance (percentage) */
tolerance?: number;
/** Number of iterations for performance tests */
iterations?: number;
/** Statistical confidence level (0-1) */
confidenceLevel?: number;
}
/**
* Performance test target specification
*/
export interface PerformanceTarget {
nfrId: string;
targetValue: number;
unit: string;
percentile?: number;
tolerance?: number;
baseline?: number;
}
/**
* Accuracy test target specification
*/
export interface AccuracyTarget {
nfrId: string;
expectedAccuracy: number;
falsePositiveRate?: number;
falseNegativeRate?: number;
sampleSize?: number;
}
/**
* Reliability test target specification
*/
export interface ReliabilityTarget {
nfrId: string;
successRate: number;
retryCount?: number;
timeoutMs?: number;
}
/**
* NFRTestGenerator - Transform NFR specifications into executable tests
*
* @example
* ```typescript
* const corpus = createMockCorpus(); // Load NFR baselines
* const generator = new NFRTestGenerator(corpus);
*
* // Generate single performance test
* const testCode = generator.generatePerformanceTest('NFR-PERF-001', {
* nfrId: 'NFR-PERF-001',
* targetValue: 5000,
* unit: 'ms',
* percentile: 95,
* tolerance: 10
* });
*
* // Generate complete test suite for multiple NFRs
* const suite = generator.generateTestSuite(['NFR-PERF-001', 'NFR-ACC-001'], {
* includeComments: true,
* includeGroundTruth: true,
* strictMode: false,
* tolerance: 10
* });
*
* // Write test file to disk
* await generator.generateTestFile(['NFR-PERF-001'], './test/nfr-perf.test.ts');
* ```
*/
export declare class NFRTestGenerator {
private corpus;
constructor(corpus: NFRGroundTruthCorpus);
/**
* Generate complete test suite for multiple NFRs
*
* @param nfrIds - Array of NFR identifiers to generate tests for
* @param options - Test generation options
* @returns Complete test suite code (Vitest format)
*
* @throws {Error} If NFR ID not found in corpus
*/
generateTestSuite(nfrIds: string[], options?: GenerateOptions): string;
/**
* Generate performance benchmark test
*
* Creates test with statistical assertions (p95, p99), confidence intervals,
* and baseline comparison.
*
* @param nfrId - NFR identifier
* @param target - Performance target specification
* @returns Test code (Vitest format)
*/
generatePerformanceTest(nfrId: string, target: PerformanceTarget): string;
/**
* Generate accuracy validation test
*
* Creates test with false positive/negative rate assertions and
* statistical significance testing.
*
* @param nfrId - NFR identifier
* @param target - Accuracy target specification
* @returns Test code (Vitest format)
*/
generateAccuracyTest(nfrId: string, target: AccuracyTarget): string;
/**
* Generate reliability test
*
* Creates test with success rate assertions, retry behavior, and
* timeout handling.
*
* @param nfrId - NFR identifier
* @param target - Reliability target specification
* @returns Test code (Vitest format)
*/
generateReliabilityTest(nfrId: string, target: ReliabilityTarget): string;
/**
* Generate test file and write to disk
*
* @param nfrIds - Array of NFR identifiers
* @param outputPath - File path for generated test file
* @param options - Test generation options
* @returns Promise resolving when file is written
*/
generateTestFile(nfrIds: string[], outputPath: string, options?: GenerateOptions): Promise<void>;
/**
* Generate test files for all NFRs in corpus (one file per category)
*
* @param outputDir - Directory for generated test files
* @param options - Test generation options
* @returns Number of test files generated
*/
generateAllNFRTests(outputDir: string, options?: GenerateOptions): Promise<number>;
/**
* Merge user options with defaults
* @private
*/
private mergeOptions;
/**
* Group NFR IDs by category
* @private
*/
private groupByCategory;
/**
* Generate import statements based on NFR categories
* @private
*/
private generateImports;
/**
* Generate generic test for non-standard NFR categories
* @private
*/
private generateGenericTest;
/**
* Assemble complete test file from components
* @private
*/
private assembleTestFile;
/**
* Generate file header comment
* @private
*/
private generateFileHeader;
/**
* Generate file footer comment
* @private
*/
private generateFileFooter;
}
//# sourceMappingURL=nfr-test-generator.d.ts.map