fix(compliance): improve compliance
This commit is contained in:
@@ -113,7 +113,7 @@ tap.test('VAL-14: Multi-Format Validation - UBL vs CII Validation Consistency',
|
||||
];
|
||||
|
||||
for (const testInvoice of testInvoices) {
|
||||
tools.log(`Testing format consistency for: ${testInvoice.name}`);
|
||||
console.log(`Testing format consistency for: ${testInvoice.name}`);
|
||||
|
||||
try {
|
||||
// Validate UBL version
|
||||
@@ -137,31 +137,31 @@ tap.test('VAL-14: Multi-Format Validation - UBL vs CII Validation Consistency',
|
||||
const ublValid = ublValidationResult.valid;
|
||||
const ciiValid = ciiValidationResult.valid;
|
||||
|
||||
tools.log(` UBL validation: ${ublValid ? 'PASS' : 'FAIL'}`);
|
||||
tools.log(` CII validation: ${ciiValid ? 'PASS' : 'FAIL'}`);
|
||||
console.log(` UBL validation: ${ublValid ? 'PASS' : 'FAIL'}`);
|
||||
console.log(` CII validation: ${ciiValid ? 'PASS' : 'FAIL'}`);
|
||||
|
||||
// Both should have consistent validation results for equivalent content
|
||||
if (ublValid !== ciiValid) {
|
||||
tools.log(` ⚠ Validation inconsistency detected between UBL and CII formats`);
|
||||
console.log(` ⚠ Validation inconsistency detected between UBL and CII formats`);
|
||||
|
||||
if (ublValidationResult.errors) {
|
||||
tools.log(` UBL errors: ${ublValidationResult.errors.map(e => e.message).join(', ')}`);
|
||||
console.log(` UBL errors: ${ublValidationResult.errors.map(e => e.message).join(', ')}`);
|
||||
}
|
||||
if (ciiValidationResult.errors) {
|
||||
tools.log(` CII errors: ${ciiValidationResult.errors.map(e => e.message).join(', ')}`);
|
||||
console.log(` CII errors: ${ciiValidationResult.errors.map(e => e.message).join(', ')}`);
|
||||
}
|
||||
} else {
|
||||
tools.log(` ✓ Validation consistency maintained between formats`);
|
||||
console.log(` ✓ Validation consistency maintained between formats`);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
tools.log(` Error testing ${testInvoice.name}: ${error.message}`);
|
||||
console.log(` Error testing ${testInvoice.name}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
PerformanceTracker.recordMetric('multi-format-validation-consistency', duration);
|
||||
// PerformanceTracker.recordMetric('multi-format-validation-consistency', duration);
|
||||
});
|
||||
|
||||
tap.test('VAL-14: Multi-Format Validation - Cross-Format Business Rule Application', async (tools) => {
|
||||
@@ -218,7 +218,7 @@ tap.test('VAL-14: Multi-Format Validation - Cross-Format Business Rule Applicati
|
||||
];
|
||||
|
||||
for (const test of businessRuleTests) {
|
||||
tools.log(`Testing business rule: ${test.name}`);
|
||||
console.log(`Testing business rule: ${test.name}`);
|
||||
|
||||
const formatResults = {};
|
||||
|
||||
@@ -234,18 +234,18 @@ tap.test('VAL-14: Multi-Format Validation - Cross-Format Business Rule Applicati
|
||||
errors: validationResult.errors || []
|
||||
};
|
||||
|
||||
tools.log(` ${formatName.toUpperCase()}: ${validationResult.valid ? 'PASS' : 'FAIL'}`);
|
||||
console.log(` ${formatName.toUpperCase()}: ${validationResult.valid ? 'PASS' : 'FAIL'}`);
|
||||
if (!validationResult.valid && validationResult.errors) {
|
||||
tools.log(` Errors: ${validationResult.errors.length}`);
|
||||
console.log(` Errors: ${validationResult.errors.length}`);
|
||||
}
|
||||
} else {
|
||||
formatResults[formatName] = { valid: false, errors: ['Parse failed'] };
|
||||
tools.log(` ${formatName.toUpperCase()}: PARSE_FAIL`);
|
||||
console.log(` ${formatName.toUpperCase()}: PARSE_FAIL`);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
formatResults[formatName] = { valid: false, errors: [error.message] };
|
||||
tools.log(` ${formatName.toUpperCase()}: ERROR - ${error.message}`);
|
||||
console.log(` ${formatName.toUpperCase()}: ERROR - ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,24 +254,24 @@ tap.test('VAL-14: Multi-Format Validation - Cross-Format Business Rule Applicati
|
||||
const allSame = validationResults.every(result => result === validationResults[0]);
|
||||
|
||||
if (allSame) {
|
||||
tools.log(` ✓ Business rule applied consistently across formats`);
|
||||
console.log(` ✓ Business rule applied consistently across formats`);
|
||||
|
||||
// Check if result matches expectation
|
||||
if (validationResults[0] === test.expectedValid) {
|
||||
tools.log(` ✓ Validation result matches expectation: ${test.expectedValid}`);
|
||||
console.log(` ✓ Validation result matches expectation: ${test.expectedValid}`);
|
||||
} else {
|
||||
tools.log(` ⚠ Validation result (${validationResults[0]}) differs from expectation (${test.expectedValid})`);
|
||||
console.log(` ⚠ Validation result (${validationResults[0]}) differs from expectation (${test.expectedValid})`);
|
||||
}
|
||||
} else {
|
||||
tools.log(` ⚠ Inconsistent business rule application across formats`);
|
||||
console.log(` ⚠ Inconsistent business rule application across formats`);
|
||||
for (const [format, result] of Object.entries(formatResults)) {
|
||||
tools.log(` ${format}: ${result.valid} (${result.errors.length} errors)`);
|
||||
console.log(` ${format}: ${result.valid} (${result.errors.length} errors)`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
PerformanceTracker.recordMetric('multi-format-validation-business-rules', duration);
|
||||
// PerformanceTracker.recordMetric('multi-format-validation-business-rules', duration);
|
||||
});
|
||||
|
||||
tap.test('VAL-14: Multi-Format Validation - Profile-Specific Validation', async (tools) => {
|
||||
@@ -334,7 +334,7 @@ tap.test('VAL-14: Multi-Format Validation - Profile-Specific Validation', async
|
||||
];
|
||||
|
||||
for (const test of profileTests) {
|
||||
tools.log(`Testing profile-specific validation: ${test.name}`);
|
||||
console.log(`Testing profile-specific validation: ${test.name}`);
|
||||
|
||||
try {
|
||||
const invoice = new EInvoice();
|
||||
@@ -343,44 +343,44 @@ tap.test('VAL-14: Multi-Format Validation - Profile-Specific Validation', async
|
||||
if (parseResult) {
|
||||
const validationResult = await invoice.validate();
|
||||
|
||||
tools.log(` Parse: ${parseResult ? 'SUCCESS' : 'FAILED'}`);
|
||||
tools.log(` Validation: ${validationResult.valid ? 'PASS' : 'FAIL'}`);
|
||||
console.log(` Parse: ${parseResult ? 'SUCCESS' : 'FAILED'}`);
|
||||
console.log(` Validation: ${validationResult.valid ? 'PASS' : 'FAIL'}`);
|
||||
|
||||
if (!validationResult.valid && validationResult.errors) {
|
||||
tools.log(` Errors (${validationResult.errors.length}):`);
|
||||
console.log(` Errors (${validationResult.errors.length}):`);
|
||||
for (const error of validationResult.errors) {
|
||||
tools.log(` - ${error.message}`);
|
||||
console.log(` - ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (test.expectedValid) {
|
||||
// For profile tests, we expect validation to pass or at least parse successfully
|
||||
expect(parseResult).toBeTruthy();
|
||||
tools.log(` ✓ ${test.name} processed successfully`);
|
||||
console.log(` ✓ ${test.name} processed successfully`);
|
||||
} else {
|
||||
expect(validationResult.valid).toBe(false);
|
||||
tools.log(` ✓ ${test.name} correctly rejected`);
|
||||
expect(validationResult.valid).toBeFalse();
|
||||
console.log(` ✓ ${test.name} correctly rejected`);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!test.expectedValid) {
|
||||
tools.log(` ✓ ${test.name} correctly failed to parse`);
|
||||
console.log(` ✓ ${test.name} correctly failed to parse`);
|
||||
} else {
|
||||
tools.log(` ⚠ ${test.name} failed to parse but was expected to be valid`);
|
||||
console.log(` ⚠ ${test.name} failed to parse but was expected to be valid`);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
if (!test.expectedValid) {
|
||||
tools.log(` ✓ ${test.name} correctly threw error: ${error.message}`);
|
||||
console.log(` ✓ ${test.name} correctly threw error: ${error.message}`);
|
||||
} else {
|
||||
tools.log(` ⚠ ${test.name} unexpected error: ${error.message}`);
|
||||
console.log(` ⚠ ${test.name} unexpected error: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
PerformanceTracker.recordMetric('multi-format-validation-profiles', duration);
|
||||
// PerformanceTracker.recordMetric('multi-format-validation-profiles', duration);
|
||||
});
|
||||
|
||||
tap.test('VAL-14: Multi-Format Validation - Corpus Cross-Format Analysis', { timeout: testTimeout }, async (tools) => {
|
||||
@@ -397,7 +397,7 @@ tap.test('VAL-14: Multi-Format Validation - Corpus Cross-Format Analysis', { tim
|
||||
};
|
||||
|
||||
for (const [formatName, category] of Object.entries(formatCategories)) {
|
||||
tools.log(`Analyzing ${formatName} format validation...`);
|
||||
console.log(`Analyzing ${formatName} format validation...`);
|
||||
|
||||
const categoryAnalysis = {
|
||||
totalFiles: 0,
|
||||
@@ -451,7 +451,7 @@ tap.test('VAL-14: Multi-Format Validation - Corpus Cross-Format Analysis', { tim
|
||||
|
||||
} catch (error) {
|
||||
categoryAnalysis.parseErrors++;
|
||||
tools.log(` Parse error in ${plugins.path.basename(filePath)}: ${error.message}`);
|
||||
console.log(` Parse error in ${plugins.path.basename(filePath)}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,26 +463,26 @@ tap.test('VAL-14: Multi-Format Validation - Corpus Cross-Format Analysis', { tim
|
||||
formatAnalysis[formatName] = categoryAnalysis;
|
||||
|
||||
// Display format-specific results
|
||||
tools.log(`${formatName} Analysis Results:`);
|
||||
tools.log(` Total files: ${categoryAnalysis.totalFiles}`);
|
||||
tools.log(` Successful parse: ${categoryAnalysis.successfulParse} (${(categoryAnalysis.successfulParse / categoryAnalysis.totalFiles * 100).toFixed(1)}%)`);
|
||||
tools.log(` Successful validation: ${categoryAnalysis.successfulValidation} (${(categoryAnalysis.successfulValidation / categoryAnalysis.totalFiles * 100).toFixed(1)}%)`);
|
||||
tools.log(` Average validation time: ${categoryAnalysis.averageValidationTime.toFixed(1)}ms`);
|
||||
console.log(`${formatName} Analysis Results:`);
|
||||
console.log(` Total files: ${categoryAnalysis.totalFiles}`);
|
||||
console.log(` Successful parse: ${categoryAnalysis.successfulParse} (${(categoryAnalysis.successfulParse / categoryAnalysis.totalFiles * 100).toFixed(1)}%)`);
|
||||
console.log(` Successful validation: ${categoryAnalysis.successfulValidation} (${(categoryAnalysis.successfulValidation / categoryAnalysis.totalFiles * 100).toFixed(1)}%)`);
|
||||
console.log(` Average validation time: ${categoryAnalysis.averageValidationTime.toFixed(1)}ms`);
|
||||
|
||||
if (Object.keys(categoryAnalysis.errorCategories).length > 0) {
|
||||
tools.log(` Error categories:`);
|
||||
console.log(` Error categories:`);
|
||||
for (const [category, count] of Object.entries(categoryAnalysis.errorCategories)) {
|
||||
tools.log(` ${category}: ${count}`);
|
||||
console.log(` ${category}: ${count}`);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
tools.log(`Failed to analyze ${formatName} format: ${error.message}`);
|
||||
console.log(`Failed to analyze ${formatName} format: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Cross-format comparison
|
||||
tools.log(`\n=== Cross-Format Validation Analysis ===`);
|
||||
console.log(`\n=== Cross-Format Validation Analysis ===`);
|
||||
|
||||
const formats = Object.keys(formatAnalysis);
|
||||
if (formats.length > 1) {
|
||||
@@ -493,7 +493,7 @@ tap.test('VAL-14: Multi-Format Validation - Corpus Cross-Format Analysis', { tim
|
||||
const analysis1 = formatAnalysis[format1];
|
||||
const analysis2 = formatAnalysis[format2];
|
||||
|
||||
tools.log(`\n${format1} vs ${format2}:`);
|
||||
console.log(`\n${format1} vs ${format2}:`);
|
||||
|
||||
const parseRate1 = analysis1.successfulParse / analysis1.totalFiles;
|
||||
const parseRate2 = analysis2.successfulParse / analysis2.totalFiles;
|
||||
@@ -505,15 +505,15 @@ tap.test('VAL-14: Multi-Format Validation - Corpus Cross-Format Analysis', { tim
|
||||
|
||||
const timeDiff = Math.abs(analysis1.averageValidationTime - analysis2.averageValidationTime);
|
||||
|
||||
tools.log(` Parse rate difference: ${parseRateDiff.toFixed(1)}%`);
|
||||
tools.log(` Validation rate difference: ${validationRateDiff.toFixed(1)}%`);
|
||||
tools.log(` Validation time difference: ${timeDiff.toFixed(1)}ms`);
|
||||
console.log(` Parse rate difference: ${parseRateDiff.toFixed(1)}%`);
|
||||
console.log(` Validation rate difference: ${validationRateDiff.toFixed(1)}%`);
|
||||
console.log(` Validation time difference: ${timeDiff.toFixed(1)}ms`);
|
||||
|
||||
// Check for reasonable consistency
|
||||
if (parseRateDiff < 20 && validationRateDiff < 25) {
|
||||
tools.log(` ✓ Reasonable consistency between formats`);
|
||||
console.log(` ✓ Reasonable consistency between formats`);
|
||||
} else {
|
||||
tools.log(` ⚠ Significant differences detected between formats`);
|
||||
console.log(` ⚠ Significant differences detected between formats`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -523,15 +523,15 @@ tap.test('VAL-14: Multi-Format Validation - Corpus Cross-Format Analysis', { tim
|
||||
expect(totalProcessed).toBeGreaterThan(0);
|
||||
|
||||
} catch (error) {
|
||||
tools.log(`Corpus cross-format analysis failed: ${error.message}`);
|
||||
console.log(`Corpus cross-format analysis failed: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
|
||||
const totalDuration = Date.now() - startTime;
|
||||
PerformanceTracker.recordMetric('multi-format-validation-corpus', totalDuration);
|
||||
// PerformanceTracker.recordMetric('multi-format-validation-corpus', totalDuration);
|
||||
|
||||
expect(totalDuration).toBeLessThan(180000); // 3 minutes max
|
||||
tools.log(`Cross-format analysis completed in ${totalDuration}ms`);
|
||||
console.log(`Cross-format analysis completed in ${totalDuration}ms`);
|
||||
});
|
||||
|
||||
tap.test('VAL-14: Multi-Format Validation - Format Detection and Validation Integration', async (tools) => {
|
||||
@@ -584,7 +584,7 @@ tap.test('VAL-14: Multi-Format Validation - Format Detection and Validation Inte
|
||||
];
|
||||
|
||||
for (const test of formatDetectionTests) {
|
||||
tools.log(`Testing format detection integration: ${test.name}`);
|
||||
console.log(`Testing format detection integration: ${test.name}`);
|
||||
|
||||
try {
|
||||
const invoice = new EInvoice();
|
||||
@@ -593,7 +593,7 @@ tap.test('VAL-14: Multi-Format Validation - Format Detection and Validation Inte
|
||||
let detectedFormat = 'UNKNOWN';
|
||||
if (typeof invoice.detectFormat === 'function') {
|
||||
detectedFormat = await invoice.detectFormat(test.xml);
|
||||
tools.log(` Detected format: ${detectedFormat}`);
|
||||
console.log(` Detected format: ${detectedFormat}`);
|
||||
}
|
||||
|
||||
// Then parse and validate
|
||||
@@ -602,15 +602,15 @@ tap.test('VAL-14: Multi-Format Validation - Format Detection and Validation Inte
|
||||
if (parseResult) {
|
||||
const validationResult = await invoice.validate();
|
||||
|
||||
tools.log(` Parse: SUCCESS`);
|
||||
tools.log(` Validation: ${validationResult.valid ? 'PASS' : 'FAIL'}`);
|
||||
console.log(` Parse: SUCCESS`);
|
||||
console.log(` Validation: ${validationResult.valid ? 'PASS' : 'FAIL'}`);
|
||||
|
||||
if (test.expectedValid) {
|
||||
expect(parseResult).toBeTruthy();
|
||||
tools.log(` ✓ ${test.name} processed as expected`);
|
||||
console.log(` ✓ ${test.name} processed as expected`);
|
||||
} else {
|
||||
if (!validationResult.valid) {
|
||||
tools.log(` ✓ ${test.name} correctly failed validation`);
|
||||
console.log(` ✓ ${test.name} correctly failed validation`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -622,23 +622,23 @@ tap.test('VAL-14: Multi-Format Validation - Format Detection and Validation Inte
|
||||
|
||||
} else {
|
||||
if (!test.expectedValid) {
|
||||
tools.log(` ✓ ${test.name} correctly failed to parse`);
|
||||
console.log(` ✓ ${test.name} correctly failed to parse`);
|
||||
} else {
|
||||
tools.log(` ⚠ ${test.name} failed to parse but was expected to be valid`);
|
||||
console.log(` ⚠ ${test.name} failed to parse but was expected to be valid`);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
if (!test.expectedValid) {
|
||||
tools.log(` ✓ ${test.name} correctly threw error: ${error.message}`);
|
||||
console.log(` ✓ ${test.name} correctly threw error: ${error.message}`);
|
||||
} else {
|
||||
tools.log(` ⚠ ${test.name} unexpected error: ${error.message}`);
|
||||
console.log(` ⚠ ${test.name} unexpected error: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
PerformanceTracker.recordMetric('multi-format-validation-detection', duration);
|
||||
// PerformanceTracker.recordMetric('multi-format-validation-detection', duration);
|
||||
});
|
||||
|
||||
tap.test('VAL-14: Performance Summary', async (tools) => {
|
||||
@@ -650,16 +650,19 @@ tap.test('VAL-14: Performance Summary', async (tools) => {
|
||||
'multi-format-validation-detection'
|
||||
];
|
||||
|
||||
tools.log(`\n=== Multi-Format Validation Performance Summary ===`);
|
||||
console.log(`\n=== Multi-Format 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(`\nMulti-format validation testing completed successfully.`);
|
||||
tools.log(`\n🎉 Validation test suite (VAL-01 through VAL-14) implementation complete!`);
|
||||
});
|
||||
console.log(`\nMulti-format validation testing completed successfully.`);
|
||||
console.log(`\n🎉 Validation test suite (VAL-01 through VAL-14) implementation complete!`);
|
||||
});
|
||||
|
||||
// Start the tests
|
||||
tap.start();
|
Reference in New Issue
Block a user