Files
boc/EOS/policy-regression-matrix.mjs
T

98 lines
3.2 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
// ═══════════════════════════════════════════════════════════════════════════
// Policy Regression Matrix — Fullständig testmatris
// ═══════════════════════════════════════════════════════════════════════════
/**
* Policy Regression Matrix
*
* Inte bara Test → PASS, utan:
*
* | Policy | Acceptance | Regression | Runtime |
* |--------|------------|------------|---------|
* | SSH | PASS | PASS | PASS |
* | ... | ... | ... | ... |
*/
import { POLICIES } from './policy-registry.mjs';
class PolicyRegressionMatrix {
constructor() {
this.results = new Map();
}
/**
* Registrera testresultat för en policy
*/
recordResult(policyId, testType, passed, evidence = null) {
if (!this.results.has(policyId)) {
this.results.set(policyId, {
policy: POLICIES.find(p => p.id === policyId),
acceptance: null,
regression: null,
runtime: null,
evidence: []
});
}
const result = this.results.get(policyId);
result[testType] = passed;
if (evidence) {
result.evidence.push(evidence);
}
}
/**
* Kontrollera om alla tester passerat för en policy
*/
isPolicyFullyVerified(policyId) {
const result = this.results.get(policyId);
if (!result) return false;
return result.acceptance === true &&
result.regression === true &&
result.runtime === true;
}
/**
* Generera matris som text
*/
generateMatrix() {
let output = 'Policy Regression Matrix\n';
output += '════════════════════════\n\n';
output += '| Policy | Name | Acceptance | Regression | Runtime | Status |\n';
output += '|--------|------|------------|------------|---------|--------|\n';
for (const [policyId, result] of this.results) {
const policy = result.policy;
const status = this.isPolicyFullyVerified(policyId) ? '✅ VERIFIED' : '❌ INCOMPLETE';
output += `| ${policyId} | ${policy?.name || 'Unknown'} | `;
output += `${result.acceptance === true ? 'PASS' : result.acceptance === false ? 'FAIL' : 'N/A'} | `;
output += `${result.regression === true ? 'PASS' : result.regression === false ? 'FAIL' : 'N/A'} | `;
output += `${result.runtime === true ? 'PASS' : result.runtime === false ? 'FAIL' : 'N/A'} | `;
output += `${status} |\n`;
}
return output;
}
/**
* Generera sammanfattning
*/
generateSummary() {
const total = this.results.size;
const verified = Array.from(this.results.keys()).filter(id => this.isPolicyFullyVerified(id)).length;
return {
total,
verified,
coverage: total > 0 ? Math.round((verified / total) * 100) : 0,
status: verified === total ? 'ALL_VERIFIED' : 'INCOMPLETE'
};
}
}
export { PolicyRegressionMatrix };