fix(compliance): improve compliance

This commit is contained in:
2025-05-30 04:29:13 +00:00
parent 960bbc2208
commit 0ba55dcb60
14 changed files with 1270 additions and 1095 deletions

View File

@ -1,8 +1,8 @@
import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as plugins from '../../../ts/plugins.ts';
import { EInvoice } from '../../../ts/classes.xinvoice.ts';
import { CorpusLoader } from '../../helpers/corpus.loader.ts';
import { PerformanceTracker } from '../../helpers/performance.tracker.ts';
import * as plugins from '../../../ts/plugins.js';
import { EInvoice } from '../../../ts/index.js';
import { CorpusLoader } from '../../helpers/corpus.loader.js';
import { PerformanceTracker } from '../../helpers/performance.tracker.js';
const testTimeout = 600000; // 10 minutes timeout for performance testing
@ -99,7 +99,7 @@ tap.test('VAL-12: Validation Performance - Single Invoice Validation Speed', asy
expect(validationResult).toBeTruthy();
} catch (error) {
tools.log(`Validation failed for ${test.name}: ${error.message}`);
console.log(`Validation failed for ${test.name}: ${error.message}`);
throw error;
}
}
@ -109,20 +109,20 @@ tap.test('VAL-12: Validation Performance - Single Invoice Validation Speed', asy
const maxTime = Math.max(...times);
const p95Time = times.sort((a, b) => a - b)[Math.floor(times.length * 0.95)];
tools.log(`${test.name} validation performance:`);
tools.log(` Average: ${avgTime.toFixed(1)}ms`);
tools.log(` Min: ${minTime}ms, Max: ${maxTime}ms`);
tools.log(` P95: ${p95Time}ms`);
console.log(`${test.name} validation performance:`);
console.log(` Average: ${avgTime.toFixed(1)}ms`);
console.log(` Min: ${minTime}ms, Max: ${maxTime}ms`);
console.log(` P95: ${p95Time}ms`);
// Performance expectations
expect(avgTime).toBeLessThan(test.expectedMaxTime);
expect(p95Time).toBeLessThan(test.expectedMaxTime * 2);
PerformanceTracker.recordMetric(`validation-performance-${test.name.toLowerCase().replace(/\s+/g, '-')}`, avgTime);
// PerformanceTracker.recordMetric(`validation-performance-${test.name.toLowerCase().replace(/\s+/g, '-')}`, avgTime);
}
const duration = Date.now() - startTime;
PerformanceTracker.recordMetric('validation-performance-single', duration);
// PerformanceTracker.recordMetric('validation-performance-single', duration);
});
tap.test('VAL-12: Validation Performance - Concurrent Validation', { timeout: testTimeout }, async (tools) => {
@ -165,25 +165,25 @@ tap.test('VAL-12: Validation Performance - Concurrent Validation', { timeout: te
const avgTimePerValidation = concurrentDuration / concurrency;
tools.log(`Concurrent validation (${concurrency} parallel):`);
tools.log(` Total time: ${concurrentDuration}ms`);
tools.log(` Avg per validation: ${avgTimePerValidation.toFixed(1)}ms`);
tools.log(` Throughput: ${(1000 / avgTimePerValidation).toFixed(1)} validations/sec`);
console.log(`Concurrent validation (${concurrency} parallel):`);
console.log(` Total time: ${concurrentDuration}ms`);
console.log(` Avg per validation: ${avgTimePerValidation.toFixed(1)}ms`);
console.log(` Throughput: ${(1000 / avgTimePerValidation).toFixed(1)} validations/sec`);
// Performance expectations
expect(avgTimePerValidation).toBeLessThan(100); // 100ms max per validation
expect(concurrentDuration).toBeLessThan(5000); // 5 seconds max total
PerformanceTracker.recordMetric(`validation-performance-concurrent-${concurrency}`, avgTimePerValidation);
// PerformanceTracker.recordMetric(`validation-performance-concurrent-${concurrency}`, avgTimePerValidation);
} catch (error) {
tools.log(`Concurrent validation failed at level ${concurrency}: ${error.message}`);
console.log(`Concurrent validation failed at level ${concurrency}: ${error.message}`);
throw error;
}
}
const totalDuration = Date.now() - startTime;
PerformanceTracker.recordMetric('validation-performance-concurrent', totalDuration);
// PerformanceTracker.recordMetric('validation-performance-concurrent', totalDuration);
});
tap.test('VAL-12: Validation Performance - Large Invoice Handling', { timeout: testTimeout }, async (tools) => {
@ -241,24 +241,24 @@ tap.test('VAL-12: Validation Performance - Large Invoice Handling', { timeout: t
const timePerLine = largeInvoiceDuration / lineCount;
tools.log(`Large invoice validation (${lineCount} lines):`);
tools.log(` Total time: ${largeInvoiceDuration}ms`);
tools.log(` Time per line: ${timePerLine.toFixed(2)}ms`);
console.log(`Large invoice validation (${lineCount} lines):`);
console.log(` Total time: ${largeInvoiceDuration}ms`);
console.log(` Time per line: ${timePerLine.toFixed(2)}ms`);
// Performance expectations scale with line count
const maxExpectedTime = Math.max(100, lineCount * 2); // 2ms per line minimum
expect(largeInvoiceDuration).toBeLessThan(maxExpectedTime);
PerformanceTracker.recordMetric(`validation-performance-large-${lineCount}-lines`, largeInvoiceDuration);
// PerformanceTracker.recordMetric(`validation-performance-large-${lineCount}-lines`, largeInvoiceDuration);
} catch (error) {
tools.log(`Large invoice validation failed (${lineCount} lines): ${error.message}`);
console.log(`Large invoice validation failed (${lineCount} lines): ${error.message}`);
throw error;
}
}
const totalDuration = Date.now() - startTime;
PerformanceTracker.recordMetric('validation-performance-large', totalDuration);
// PerformanceTracker.recordMetric('validation-performance-large', totalDuration);
});
tap.test('VAL-12: Validation Performance - Memory Usage Monitoring', async (tools) => {
@ -296,17 +296,17 @@ tap.test('VAL-12: Validation Performance - Memory Usage Monitoring', async (tool
const heapGrowth = memoryAfter.heapUsed - memoryBefore.heapUsed;
const rssGrowth = memoryAfter.rss - memoryBefore.rss;
tools.log(`Memory usage for ${iterations} validations:`);
tools.log(` Heap growth: ${(heapGrowth / 1024 / 1024).toFixed(2)} MB`);
tools.log(` RSS growth: ${(rssGrowth / 1024 / 1024).toFixed(2)} MB`);
tools.log(` Heap per validation: ${(heapGrowth / iterations / 1024).toFixed(2)} KB`);
console.log(`Memory usage for ${iterations} validations:`);
console.log(` Heap growth: ${(heapGrowth / 1024 / 1024).toFixed(2)} MB`);
console.log(` RSS growth: ${(rssGrowth / 1024 / 1024).toFixed(2)} MB`);
console.log(` Heap per validation: ${(heapGrowth / iterations / 1024).toFixed(2)} KB`);
// Memory expectations
const heapPerValidation = heapGrowth / iterations;
expect(heapPerValidation).toBeLessThan(50 * 1024); // Less than 50KB per validation
const duration = Date.now() - startTime;
PerformanceTracker.recordMetric('validation-performance-memory', duration);
// PerformanceTracker.recordMetric('validation-performance-memory', duration);
});
tap.test('VAL-12: Validation Performance - Corpus Performance Analysis', { timeout: testTimeout }, async (tools) => {
@ -353,20 +353,20 @@ tap.test('VAL-12: Validation Performance - Corpus Performance Analysis', { timeo
});
} catch (error) {
tools.log(`Failed to process ${plugins.path.basename(filePath)}: ${error.message}`);
console.log(`Failed to process ${plugins.path.basename(filePath)}: ${error.message}`);
}
}
const categoryTime = Date.now() - categoryStart;
const avgCategoryTime = categoryValidations > 0 ? categoryTime / categoryValidations : 0;
tools.log(`${category} performance:`);
tools.log(` Files processed: ${categoryValidations}`);
tools.log(` Total time: ${categoryTime}ms`);
tools.log(` Avg per file: ${avgCategoryTime.toFixed(1)}ms`);
console.log(`${category} performance:`);
console.log(` Files processed: ${categoryValidations}`);
console.log(` Total time: ${categoryTime}ms`);
console.log(` Avg per file: ${avgCategoryTime.toFixed(1)}ms`);
} catch (error) {
tools.log(`Failed to process category ${category}: ${error.message}`);
console.log(`Failed to process category ${category}: ${error.message}`);
}
}
@ -376,11 +376,11 @@ tap.test('VAL-12: Validation Performance - Corpus Performance Analysis', { timeo
const avgSize = performanceResults.reduce((sum, r) => sum + r.sizeKB, 0) / performanceResults.length;
const avgTimePerKB = performanceResults.reduce((sum, r) => sum + r.timePerKB, 0) / performanceResults.length;
tools.log(`Overall corpus performance analysis:`);
tools.log(` Total validations: ${totalValidations}`);
tools.log(` Average time: ${avgTime.toFixed(1)}ms`);
tools.log(` Average file size: ${avgSize.toFixed(1)}KB`);
tools.log(` Average time per KB: ${avgTimePerKB.toFixed(2)}ms/KB`);
console.log(`Overall corpus performance analysis:`);
console.log(` Total validations: ${totalValidations}`);
console.log(` Average time: ${avgTime.toFixed(1)}ms`);
console.log(` Average file size: ${avgSize.toFixed(1)}KB`);
console.log(` Average time per KB: ${avgTimePerKB.toFixed(2)}ms/KB`);
// Performance expectations
expect(avgTime).toBeLessThan(200); // 200ms max average
@ -391,22 +391,22 @@ tap.test('VAL-12: Validation Performance - Corpus Performance Analysis', { timeo
.sort((a, b) => b.time - a.time)
.slice(0, 3);
tools.log(`Slowest files:`);
console.log(`Slowest files:`);
for (const file of slowestFiles) {
tools.log(` ${file.file}: ${file.time}ms (${file.sizeKB.toFixed(1)}KB)`);
console.log(` ${file.file}: ${file.time}ms (${file.sizeKB.toFixed(1)}KB)`);
}
}
} catch (error) {
tools.log(`Corpus performance analysis failed: ${error.message}`);
console.log(`Corpus performance analysis failed: ${error.message}`);
throw error;
}
const totalDuration = Date.now() - startTime;
PerformanceTracker.recordMetric('validation-performance-corpus', totalDuration);
// PerformanceTracker.recordMetric('validation-performance-corpus', totalDuration);
expect(totalDuration).toBeLessThan(300000); // 5 minutes max
tools.log(`Corpus performance analysis completed in ${totalDuration}ms`);
console.log(`Corpus performance analysis completed in ${totalDuration}ms`);
});
tap.test('VAL-12: Validation Performance - Stress Testing', { timeout: testTimeout }, async (tools) => {
@ -441,7 +441,7 @@ tap.test('VAL-12: Validation Performance - Stress Testing', { timeout: testTimeo
// Log progress every 50 iterations
if ((i + 1) % 50 === 0) {
const currentAvg = stressTimes.slice(-50).reduce((a, b) => a + b, 0) / 50;
tools.log(`Stress test progress: ${i + 1}/${stressIterations}, avg last 50: ${currentAvg.toFixed(1)}ms`);
console.log(`Stress test progress: ${i + 1}/${stressIterations}, avg last 50: ${currentAvg.toFixed(1)}ms`);
}
}
@ -458,11 +458,11 @@ tap.test('VAL-12: Validation Performance - Stress Testing', { timeout: testTimeo
const secondHalfAvg = secondHalf.reduce((a, b) => a + b, 0) / secondHalf.length;
const degradation = ((secondHalfAvg - firstHalfAvg) / firstHalfAvg) * 100;
tools.log(`Stress test results (${stressIterations} iterations):`);
tools.log(` Average time: ${avgStressTime.toFixed(1)}ms`);
tools.log(` Min: ${minStressTime}ms, Max: ${maxStressTime}ms`);
tools.log(` Standard deviation: ${stdDev.toFixed(1)}ms`);
tools.log(` Performance degradation: ${degradation.toFixed(1)}%`);
console.log(`Stress test results (${stressIterations} iterations):`);
console.log(` Average time: ${avgStressTime.toFixed(1)}ms`);
console.log(` Min: ${minStressTime}ms, Max: ${maxStressTime}ms`);
console.log(` Standard deviation: ${stdDev.toFixed(1)}ms`);
console.log(` Performance degradation: ${degradation.toFixed(1)}%`);
// Performance expectations
expect(avgStressTime).toBeLessThan(50); // 50ms average max
@ -470,14 +470,14 @@ tap.test('VAL-12: Validation Performance - Stress Testing', { timeout: testTimeo
expect(stdDev).toBeLessThan(avgStressTime); // Standard deviation should be reasonable
} catch (error) {
tools.log(`Stress test failed: ${error.message}`);
console.log(`Stress test failed: ${error.message}`);
throw error;
}
const totalDuration = Date.now() - startTime;
PerformanceTracker.recordMetric('validation-performance-stress', totalDuration);
// PerformanceTracker.recordMetric('validation-performance-stress', totalDuration);
tools.log(`Stress test completed in ${totalDuration}ms`);
console.log(`Stress test completed in ${totalDuration}ms`);
});
tap.test('VAL-12: Performance Summary', async (tools) => {
@ -490,15 +490,21 @@ tap.test('VAL-12: Performance Summary', async (tools) => {
'validation-performance-stress'
];
tools.log(`\n=== Validation Performance Summary ===`);
console.log(`\n=== Validation Performance Summary ===`);
for (const operation of operations) {
const summary = await PerformanceTracker.getSummary(operation);
if (summary) {
tools.log(`${operation}:`);
tools.log(` avg=${summary.average}ms, min=${summary.min}ms, max=${summary.max}ms, p95=${summary.p95}ms`);
console.log(`${operation}:`);
console.log(` avg=${summary.average}ms, min=${summary.min}ms, max=${summary.max}ms, p95=${summary.p95}ms`);
}
}
tools.log(`\nValidation performance testing completed successfully.`);
});
console.log(`\nValidation performance testing completed successfully.`);
});
// Start the test
tap.start();
// Export for test runner compatibility
export default tap;