fix(compliance): improve compliance
This commit is contained in:
@@ -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 = 300000; // 5 minutes timeout for corpus processing
|
||||
|
||||
@@ -85,17 +85,17 @@ tap.test('VAL-10: Business Level Validation - Invoice Totals Consistency', async
|
||||
|
||||
if (test.valid) {
|
||||
expect(validationResult.valid).toBeTrue();
|
||||
tools.log(`✓ ${test.name}: Valid business logic accepted`);
|
||||
console.log(`✓ ${test.name}: Valid business logic accepted`);
|
||||
} else {
|
||||
expect(validationResult.valid).toBe(false);
|
||||
tools.log(`✓ ${test.name}: Invalid business logic rejected`);
|
||||
expect(validationResult.valid).toBeFalse();
|
||||
console.log(`✓ ${test.name}: Invalid business logic rejected`);
|
||||
}
|
||||
} else if (!test.valid) {
|
||||
tools.log(`✓ ${test.name}: Invalid invoice rejected at parse time`);
|
||||
console.log(`✓ ${test.name}: Invalid invoice rejected at parse time`);
|
||||
}
|
||||
} catch (error) {
|
||||
if (!test.valid) {
|
||||
tools.log(`✓ ${test.name}: Invalid business logic properly rejected: ${error.message}`);
|
||||
console.log(`✓ ${test.name}: Invalid business logic properly rejected: ${error.message}`);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ tap.test('VAL-10: Business Level Validation - Invoice Totals Consistency', async
|
||||
}
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
PerformanceTracker.recordMetric('business-validation-totals', duration);
|
||||
// PerformanceTracker.recordMetric('business-validation-totals', duration);
|
||||
});
|
||||
|
||||
tap.test('VAL-10: Business Level Validation - Tax Calculation Consistency', async (tools) => {
|
||||
@@ -189,26 +189,26 @@ tap.test('VAL-10: Business Level Validation - Tax Calculation Consistency', asyn
|
||||
);
|
||||
|
||||
if (!hasOnlyRoundingErrors) {
|
||||
tools.log(`Validation failed for ${test.name}: ${errors.map(e => e.message).join(', ')}`);
|
||||
console.log(`Validation failed for ${test.name}: ${errors.map(e => e.message).join(', ')}`);
|
||||
}
|
||||
}
|
||||
tools.log(`✓ ${test.name}: Tax calculation processed`);
|
||||
console.log(`✓ ${test.name}: Tax calculation processed`);
|
||||
} else {
|
||||
expect(validationResult.valid).toBe(false);
|
||||
tools.log(`✓ ${test.name}: Invalid tax calculation rejected`);
|
||||
expect(validationResult.valid).toBeFalse();
|
||||
console.log(`✓ ${test.name}: Invalid tax calculation rejected`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (!test.valid) {
|
||||
tools.log(`✓ ${test.name}: Invalid calculation properly rejected: ${error.message}`);
|
||||
console.log(`✓ ${test.name}: Invalid calculation properly rejected: ${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('business-validation-tax', duration);
|
||||
// PerformanceTracker.recordMetric('business-validation-tax', duration);
|
||||
});
|
||||
|
||||
tap.test('VAL-10: Business Level Validation - Payment Terms Validation', async (tools) => {
|
||||
@@ -270,23 +270,23 @@ tap.test('VAL-10: Business Level Validation - Payment Terms Validation', async (
|
||||
|
||||
if (test.valid) {
|
||||
// Valid payment terms should be accepted
|
||||
tools.log(`✓ ${test.name}: Valid payment terms accepted`);
|
||||
console.log(`✓ ${test.name}: Valid payment terms accepted`);
|
||||
} else {
|
||||
expect(validationResult.valid).toBe(false);
|
||||
tools.log(`✓ ${test.name}: Invalid payment terms rejected`);
|
||||
expect(validationResult.valid).toBeFalse();
|
||||
console.log(`✓ ${test.name}: Invalid payment terms rejected`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (!test.valid) {
|
||||
tools.log(`✓ ${test.name}: Invalid payment terms properly rejected: ${error.message}`);
|
||||
console.log(`✓ ${test.name}: Invalid payment terms properly rejected: ${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('business-validation-payment', duration);
|
||||
// PerformanceTracker.recordMetric('business-validation-payment', duration);
|
||||
});
|
||||
|
||||
tap.test('VAL-10: Business Level Validation - Business Rules Compliance', async (tools) => {
|
||||
@@ -344,17 +344,17 @@ tap.test('VAL-10: Business Level Validation - Business Rules Compliance', async
|
||||
|
||||
if (test.valid) {
|
||||
expect(validationResult.valid).toBeTrue();
|
||||
tools.log(`✓ ${test.name}: Business rule compliance verified`);
|
||||
console.log(`✓ ${test.name}: Business rule compliance verified`);
|
||||
} else {
|
||||
expect(validationResult.valid).toBe(false);
|
||||
tools.log(`✓ ${test.name}: Business rule violation detected`);
|
||||
expect(validationResult.valid).toBeFalse();
|
||||
console.log(`✓ ${test.name}: Business rule violation detected`);
|
||||
}
|
||||
} else if (!test.valid) {
|
||||
tools.log(`✓ ${test.name}: Invalid invoice rejected at parse time`);
|
||||
console.log(`✓ ${test.name}: Invalid invoice rejected at parse time`);
|
||||
}
|
||||
} catch (error) {
|
||||
if (!test.valid) {
|
||||
tools.log(`✓ ${test.name}: Business rule violation properly caught: ${error.message}`);
|
||||
console.log(`✓ ${test.name}: Business rule violation properly caught: ${error.message}`);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
@@ -362,7 +362,7 @@ tap.test('VAL-10: Business Level Validation - Business Rules Compliance', async
|
||||
}
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
PerformanceTracker.recordMetric('business-validation-rules', duration);
|
||||
// PerformanceTracker.recordMetric('business-validation-rules', duration);
|
||||
});
|
||||
|
||||
tap.test('VAL-10: Business Level Validation - Multi-Line Invoice Logic', async (tools) => {
|
||||
@@ -438,18 +438,18 @@ tap.test('VAL-10: Business Level Validation - Multi-Line Invoice Logic', async (
|
||||
|
||||
// Multi-line business logic should be valid
|
||||
if (!validationResult.valid) {
|
||||
tools.log(`Multi-line validation issues: ${validationResult.errors?.map(e => e.message).join(', ')}`);
|
||||
console.log(`Multi-line validation issues: ${validationResult.errors?.map(e => e.message).join(', ')}`);
|
||||
}
|
||||
|
||||
tools.log(`✓ Multi-line invoice business logic validation completed`);
|
||||
console.log(`✓ Multi-line invoice business logic validation completed`);
|
||||
|
||||
} catch (error) {
|
||||
tools.log(`Multi-line invoice test failed: ${error.message}`);
|
||||
console.log(`Multi-line invoice test failed: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
|
||||
const duration = Date.now() - startTime;
|
||||
PerformanceTracker.recordMetric('business-validation-multiline', duration);
|
||||
// PerformanceTracker.recordMetric('business-validation-multiline', duration);
|
||||
});
|
||||
|
||||
tap.test('VAL-10: Business Level Validation - Corpus Business Logic', { timeout: testTimeout }, async (tools) => {
|
||||
@@ -481,36 +481,36 @@ tap.test('VAL-10: Business Level Validation - Corpus Business Logic', { timeout:
|
||||
|
||||
if (hasBusinessErrors) {
|
||||
businessLogicErrors++;
|
||||
tools.log(`Business logic errors in ${plugins.path.basename(filePath)}`);
|
||||
console.log(`Business logic errors in ${plugins.path.basename(filePath)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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 businessLogicSuccessRate = processedFiles > 0 ? (validBusinessLogic / processedFiles) * 100 : 0;
|
||||
const businessErrorRate = processedFiles > 0 ? (businessLogicErrors / processedFiles) * 100 : 0;
|
||||
|
||||
tools.log(`Business logic validation completed:`);
|
||||
tools.log(`- Processed: ${processedFiles} files`);
|
||||
tools.log(`- Valid business logic: ${validBusinessLogic} files (${businessLogicSuccessRate.toFixed(1)}%)`);
|
||||
tools.log(`- Business logic errors: ${businessLogicErrors} files (${businessErrorRate.toFixed(1)}%)`);
|
||||
console.log(`Business logic validation completed:`);
|
||||
console.log(`- Processed: ${processedFiles} files`);
|
||||
console.log(`- Valid business logic: ${validBusinessLogic} files (${businessLogicSuccessRate.toFixed(1)}%)`);
|
||||
console.log(`- Business logic errors: ${businessLogicErrors} files (${businessErrorRate.toFixed(1)}%)`);
|
||||
|
||||
// Business logic should have reasonable success rate
|
||||
expect(businessLogicSuccessRate).toBeGreaterThan(60);
|
||||
|
||||
} catch (error) {
|
||||
tools.log(`Corpus business validation failed: ${error.message}`);
|
||||
console.log(`Corpus business validation failed: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
|
||||
const totalDuration = Date.now() - startTime;
|
||||
PerformanceTracker.recordMetric('business-validation-corpus', totalDuration);
|
||||
// PerformanceTracker.recordMetric('business-validation-corpus', totalDuration);
|
||||
|
||||
expect(totalDuration).toBeLessThan(120000); // 2 minutes max
|
||||
tools.log(`Business validation performance: ${totalDuration}ms total`);
|
||||
console.log(`Business validation performance: ${totalDuration}ms total`);
|
||||
});
|
||||
|
||||
tap.test('VAL-10: Performance Summary', async (tools) => {
|
||||
@@ -526,7 +526,13 @@ tap.test('VAL-10: Performance Summary', async (tools) => {
|
||||
for (const operation of operations) {
|
||||
const summary = await PerformanceTracker.getSummary(operation);
|
||||
if (summary) {
|
||||
tools.log(`${operation}: avg=${summary.average}ms, min=${summary.min}ms, max=${summary.max}ms, p95=${summary.p95}ms`);
|
||||
console.log(`${operation}: avg=${summary.average}ms, min=${summary.min}ms, max=${summary.max}ms, p95=${summary.p95}ms`);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Start the test
|
||||
tap.start();
|
||||
|
||||
// Export for test runner compatibility
|
||||
export default tap;
|
Reference in New Issue
Block a user