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,16 +41,16 @@ tap.test('VAL-09: Semantic Level Validation - Data Type Validation', async (tool
if (test.valid) {
expect(parseResult).toBeTruthy();
tools.log(`✓ Valid numeric value '${test.value}' accepted for ${test.field}`);
console.log(`✓ Valid numeric value '${test.value}' accepted for ${test.field}`);
} else {
// Should either fail parsing or validation
const validationResult = await invoice.validate();
expect(validationResult.valid).toBe(false);
tools.log(`✓ Invalid numeric value '${test.value}' rejected for ${test.field}`);
expect(validationResult.valid).toBeFalse();
console.log(`✓ Invalid numeric value '${test.value}' rejected for ${test.field}`);
}
} catch (error) {
if (!test.valid) {
tools.log(`✓ Invalid numeric value '${test.value}' properly rejected with error: ${error.message}`);
console.log(`✓ Invalid numeric value '${test.value}' properly rejected with error: ${error.message}`);
} else {
throw error;
}
@ -58,7 +58,7 @@ tap.test('VAL-09: Semantic Level Validation - Data Type Validation', async (tool
}
const duration = Date.now() - startTime;
PerformanceTracker.recordMetric('semantic-validation-datatypes', duration);
// PerformanceTracker.recordMetric('semantic-validation-datatypes', duration);
});
tap.test('VAL-09: Semantic Level Validation - Date Format Validation', async (tools) => {
@ -94,18 +94,18 @@ tap.test('VAL-09: Semantic Level Validation - Date Format Validation', async (to
expect(parseResult).toBeTruthy();
const validationResult = await invoice.validate();
expect(validationResult.valid).toBeTrue();
tools.log(`✓ Valid date '${test.value}' accepted`);
console.log(`✓ Valid date '${test.value}' accepted`);
} else {
// Should either fail parsing or validation
if (parseResult) {
const validationResult = await invoice.validate();
expect(validationResult.valid).toBe(false);
expect(validationResult.valid).toBeFalse();
}
tools.log(`✓ Invalid date '${test.value}' rejected`);
console.log(`✓ Invalid date '${test.value}' rejected`);
}
} catch (error) {
if (!test.valid) {
tools.log(`✓ Invalid date '${test.value}' properly rejected with error: ${error.message}`);
console.log(`✓ Invalid date '${test.value}' properly rejected with error: ${error.message}`);
} else {
throw error;
}
@ -113,7 +113,7 @@ tap.test('VAL-09: Semantic Level Validation - Date Format Validation', async (to
}
const duration = Date.now() - startTime;
PerformanceTracker.recordMetric('semantic-validation-dates', duration);
// PerformanceTracker.recordMetric('semantic-validation-dates', duration);
});
tap.test('VAL-09: Semantic Level Validation - Currency Code Validation', async (tools) => {
@ -154,18 +154,18 @@ tap.test('VAL-09: Semantic Level Validation - Currency Code Validation', async (
if (test.valid) {
expect(parseResult).toBeTruthy();
tools.log(`✓ Valid currency code '${test.code}' accepted`);
console.log(`✓ Valid currency code '${test.code}' accepted`);
} else {
// Should either fail parsing or validation
if (parseResult) {
const validationResult = await invoice.validate();
expect(validationResult.valid).toBe(false);
expect(validationResult.valid).toBeFalse();
}
tools.log(`✓ Invalid currency code '${test.code}' rejected`);
console.log(`✓ Invalid currency code '${test.code}' rejected`);
}
} catch (error) {
if (!test.valid) {
tools.log(`✓ Invalid currency code '${test.code}' properly rejected with error: ${error.message}`);
console.log(`✓ Invalid currency code '${test.code}' properly rejected with error: ${error.message}`);
} else {
throw error;
}
@ -173,7 +173,7 @@ tap.test('VAL-09: Semantic Level Validation - Currency Code Validation', async (
}
const duration = Date.now() - startTime;
PerformanceTracker.recordMetric('semantic-validation-currency', duration);
// PerformanceTracker.recordMetric('semantic-validation-currency', duration);
});
tap.test('VAL-09: Semantic Level Validation - Cross-Field Dependencies', async (tools) => {
@ -233,19 +233,19 @@ tap.test('VAL-09: Semantic Level Validation - Cross-Field Dependencies', async (
if (test.valid) {
expect(validationResult.valid).toBeTrue();
tools.log(`${test.name}: Valid cross-field dependency accepted`);
console.log(`${test.name}: Valid cross-field dependency accepted`);
} else {
expect(validationResult.valid).toBe(false);
tools.log(`${test.name}: Invalid cross-field dependency rejected`);
expect(validationResult.valid).toBeFalse();
console.log(`${test.name}: Invalid cross-field dependency rejected`);
}
} else if (!test.valid) {
tools.log(`${test.name}: Invalid dependency rejected at parse time`);
console.log(`${test.name}: Invalid dependency rejected at parse time`);
} else {
throw new Error(`Expected valid parse for ${test.name}`);
}
} catch (error) {
if (!test.valid) {
tools.log(`${test.name}: Invalid dependency properly rejected with error: ${error.message}`);
console.log(`${test.name}: Invalid dependency properly rejected with error: ${error.message}`);
} else {
throw error;
}
@ -253,7 +253,7 @@ tap.test('VAL-09: Semantic Level Validation - Cross-Field Dependencies', async (
}
const duration = Date.now() - startTime;
PerformanceTracker.recordMetric('semantic-validation-dependencies', duration);
// PerformanceTracker.recordMetric('semantic-validation-dependencies', duration);
});
tap.test('VAL-09: Semantic Level Validation - Value Range Validation', async (tools) => {
@ -314,18 +314,18 @@ tap.test('VAL-09: Semantic Level Validation - Value Range Validation', async (to
if (test.valid) {
expect(parseResult).toBeTruthy();
tools.log(`${test.description}: Valid value '${test.value}' accepted for ${test.field}`);
console.log(`${test.description}: Valid value '${test.value}' accepted for ${test.field}`);
} else {
// Should either fail parsing or validation
if (parseResult) {
const validationResult = await invoice.validate();
expect(validationResult.valid).toBe(false);
expect(validationResult.valid).toBeFalse();
}
tools.log(`${test.description}: Invalid value '${test.value}' rejected for ${test.field}`);
console.log(`${test.description}: Invalid value '${test.value}' rejected for ${test.field}`);
}
} catch (error) {
if (!test.valid) {
tools.log(`${test.description}: Invalid value properly rejected with error: ${error.message}`);
console.log(`${test.description}: Invalid value properly rejected with error: ${error.message}`);
} else {
throw error;
}
@ -333,7 +333,7 @@ tap.test('VAL-09: Semantic Level Validation - Value Range Validation', async (to
}
const duration = Date.now() - startTime;
PerformanceTracker.recordMetric('semantic-validation-ranges', duration);
// PerformanceTracker.recordMetric('semantic-validation-ranges', duration);
});
tap.test('VAL-09: Semantic Level Validation - Corpus Semantic Validation', { timeout: testTimeout }, async (tools) => {
@ -366,7 +366,7 @@ tap.test('VAL-09: Semantic Level Validation - Corpus Semantic Validation', { tim
if (hasSemanticErrors) {
semanticErrors++;
tools.log(`Semantic validation errors in ${plugins.path.basename(filePath)}`);
console.log(`Semantic validation errors in ${plugins.path.basename(filePath)}`);
}
}
}
@ -375,35 +375,35 @@ tap.test('VAL-09: Semantic Level Validation - Corpus Semantic Validation', { tim
if (processedFiles % 5 === 0) {
const currentDuration = Date.now() - startTime;
const avgPerFile = currentDuration / processedFiles;
tools.log(`Processed ${processedFiles} files, avg ${avgPerFile.toFixed(0)}ms per file`);
console.log(`Processed ${processedFiles} files, avg ${avgPerFile.toFixed(0)}ms per file`);
}
} 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 successRate = processedFiles > 0 ? (validFiles / processedFiles) * 100 : 0;
const semanticErrorRate = processedFiles > 0 ? (semanticErrors / processedFiles) * 100 : 0;
tools.log(`Semantic validation completed:`);
tools.log(`- Processed: ${processedFiles} files`);
tools.log(`- Valid: ${validFiles} files (${successRate.toFixed(1)}%)`);
tools.log(`- Semantic errors: ${semanticErrors} files (${semanticErrorRate.toFixed(1)}%)`);
console.log(`Semantic validation completed:`);
console.log(`- Processed: ${processedFiles} files`);
console.log(`- Valid: ${validFiles} files (${successRate.toFixed(1)}%)`);
console.log(`- Semantic errors: ${semanticErrors} files (${semanticErrorRate.toFixed(1)}%)`);
// Semantic validation should have high success rate for well-formed corpus
expect(successRate).toBeGreaterThan(70);
} catch (error) {
tools.log(`Corpus semantic validation failed: ${error.message}`);
console.log(`Corpus semantic validation failed: ${error.message}`);
throw error;
}
const totalDuration = Date.now() - startTime;
PerformanceTracker.recordMetric('semantic-validation-corpus', totalDuration);
// PerformanceTracker.recordMetric('semantic-validation-corpus', totalDuration);
// Performance expectation: should complete within reasonable time
expect(totalDuration).toBeLessThan(60000); // 60 seconds max
tools.log(`Semantic validation performance: ${totalDuration}ms total`);
console.log(`Semantic validation performance: ${totalDuration}ms total`);
});
tap.test('VAL-09: Performance Summary', async (tools) => {
@ -419,7 +419,13 @@ tap.test('VAL-09: 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;