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 = 300000; // 5 minutes timeout for corpus processing
@@ -41,7 +41,7 @@ tap.test('VAL-11: Custom Validation Rules - Invoice Number Format Rules', async
];
for (const rule of invoiceNumberRules) {
tools.log(`Testing custom rule: ${rule.name}`);
console.log(`Testing custom rule: ${rule.name}`);
for (const testValue of rule.testValues) {
const xml = `<?xml version="1.0" encoding="UTF-8"?>
@@ -62,20 +62,20 @@ tap.test('VAL-11: Custom Validation Rules - Invoice Number Format Rules', async
if (testValue.valid) {
expect(isValid).toBeTrue();
tools.log(`✓ Valid format '${testValue.value}' accepted by ${rule.name}`);
console.log(`✓ Valid format '${testValue.value}' accepted by ${rule.name}`);
} else {
expect(isValid).toBe(false);
tools.log(`✓ Invalid format '${testValue.value}' rejected by ${rule.name}`);
expect(isValid).toBeFalse();
console.log(`✓ Invalid format '${testValue.value}' rejected by ${rule.name}`);
}
}
} catch (error) {
tools.log(`Error testing '${testValue.value}': ${error.message}`);
console.log(`Error testing '${testValue.value}': ${error.message}`);
}
}
}
const duration = Date.now() - startTime;
PerformanceTracker.recordMetric('custom-validation-invoice-format', duration);
// PerformanceTracker.recordMetric('custom-validation-invoice-format', duration);
});
tap.test('VAL-11: Custom Validation Rules - Supplier Registration Validation', async (tools) => {
@@ -151,23 +151,23 @@ tap.test('VAL-11: Custom Validation Rules - Supplier Registration Validation', a
if (test.valid) {
expect(isValidVAT).toBeTrue();
tools.log(`${test.name}: Valid VAT number accepted`);
console.log(`${test.name}: Valid VAT number accepted`);
} else {
expect(isValidVAT).toBe(false);
tools.log(`${test.name}: Invalid VAT number rejected`);
expect(isValidVAT).toBeFalse();
console.log(`${test.name}: Invalid VAT number rejected`);
}
}
} catch (error) {
if (!test.valid) {
tools.log(`${test.name}: Invalid VAT properly rejected: ${error.message}`);
console.log(`${test.name}: Invalid VAT 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('custom-validation-vat', duration);
// PerformanceTracker.recordMetric('custom-validation-vat', duration);
});
tap.test('VAL-11: Custom Validation Rules - Industry-Specific Rules', async (tools) => {
@@ -240,15 +240,15 @@ tap.test('VAL-11: Custom Validation Rules - Industry-Specific Rules', async (too
if (test.valid) {
expect(passesIndustryRules).toBeTrue();
tools.log(`${test.name}: Industry rule compliance verified`);
console.log(`${test.name}: Industry rule compliance verified`);
} else {
expect(passesIndustryRules).toBe(false);
tools.log(`${test.name}: Industry rule violation detected`);
expect(passesIndustryRules).toBeFalse();
console.log(`${test.name}: Industry rule violation detected`);
}
}
} catch (error) {
if (!test.valid) {
tools.log(`${test.name}: Industry rule violation properly caught: ${error.message}`);
console.log(`${test.name}: Industry rule violation properly caught: ${error.message}`);
} else {
throw error;
}
@@ -256,7 +256,7 @@ tap.test('VAL-11: Custom Validation Rules - Industry-Specific Rules', async (too
}
const duration = Date.now() - startTime;
PerformanceTracker.recordMetric('custom-validation-industry', duration);
// PerformanceTracker.recordMetric('custom-validation-industry', duration);
});
tap.test('VAL-11: Custom Validation Rules - Payment Terms Constraints', async (tools) => {
@@ -335,29 +335,29 @@ tap.test('VAL-11: Custom Validation Rules - Payment Terms Constraints', async (t
// Weekend check (Saturday = 6, Sunday = 0)
if (dayOfWeek === 0 || dayOfWeek === 6) {
// This would normally trigger an adjustment rule
tools.log(`Due date falls on weekend: ${test.dueDate}`);
console.log(`Due date falls on weekend: ${test.dueDate}`);
}
}
if (test.valid) {
expect(passesPaymentRules).toBeTrue();
tools.log(`${test.name}: Payment terms validation passed`);
console.log(`${test.name}: Payment terms validation passed`);
} else {
expect(passesPaymentRules).toBe(false);
tools.log(`${test.name}: Payment terms validation failed as expected`);
expect(passesPaymentRules).toBeFalse();
console.log(`${test.name}: Payment terms validation failed as expected`);
}
}
} catch (error) {
if (!test.valid) {
tools.log(`${test.name}: Payment terms properly rejected: ${error.message}`);
console.log(`${test.name}: 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('custom-validation-payment-terms', duration);
// PerformanceTracker.recordMetric('custom-validation-payment-terms', duration);
});
tap.test('VAL-11: Custom Validation Rules - Document Sequence Validation', async (tools) => {
@@ -440,23 +440,23 @@ tap.test('VAL-11: Custom Validation Rules - Document Sequence Validation', async
if (test.valid) {
expect(passesSequenceRules).toBeTrue();
tools.log(`${test.name}: Document sequence validation passed`);
console.log(`${test.name}: Document sequence validation passed`);
} else {
expect(passesSequenceRules).toBe(false);
tools.log(`${test.name}: Document sequence validation failed as expected`);
expect(passesSequenceRules).toBeFalse();
console.log(`${test.name}: Document sequence validation failed as expected`);
}
} catch (error) {
if (!test.valid) {
tools.log(`${test.name}: Sequence validation properly rejected: ${error.message}`);
console.log(`${test.name}: Sequence validation 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('custom-validation-sequence', duration);
// PerformanceTracker.recordMetric('custom-validation-sequence', duration);
});
tap.test('VAL-11: Custom Validation Rules - Corpus Custom Rules Application', { timeout: testTimeout }, async (tools) => {
@@ -493,31 +493,31 @@ tap.test('VAL-11: Custom Validation Rules - Corpus Custom Rules Application', {
}
}
} 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 customRulesSuccessRate = processedFiles > 0 ? (customRulesPassed / processedFiles) * 100 : 0;
const customRulesViolationRate = processedFiles > 0 ? (customRulesViolations / processedFiles) * 100 : 0;
tools.log(`Custom rules validation completed:`);
tools.log(`- Processed: ${processedFiles} files`);
tools.log(`- Passed custom rules: ${customRulesPassed} files (${customRulesSuccessRate.toFixed(1)}%)`);
tools.log(`- Custom rule violations: ${customRulesViolations} files (${customRulesViolationRate.toFixed(1)}%)`);
console.log(`Custom rules validation completed:`);
console.log(`- Processed: ${processedFiles} files`);
console.log(`- Passed custom rules: ${customRulesPassed} files (${customRulesSuccessRate.toFixed(1)}%)`);
console.log(`- Custom rule violations: ${customRulesViolations} files (${customRulesViolationRate.toFixed(1)}%)`);
// Custom rules should have reasonable success rate
expect(customRulesSuccessRate).toBeGreaterThan(50);
} catch (error) {
tools.log(`Corpus custom validation failed: ${error.message}`);
console.log(`Corpus custom validation failed: ${error.message}`);
throw error;
}
const totalDuration = Date.now() - startTime;
PerformanceTracker.recordMetric('custom-validation-corpus', totalDuration);
// PerformanceTracker.recordMetric('custom-validation-corpus', totalDuration);
expect(totalDuration).toBeLessThan(90000); // 90 seconds max
tools.log(`Custom validation performance: ${totalDuration}ms total`);
console.log(`Custom validation performance: ${totalDuration}ms total`);
});
tap.test('VAL-11: Performance Summary', async (tools) => {
@@ -533,7 +533,13 @@ tap.test('VAL-11: 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;