Spaces:
Running
Running
File size: 5,597 Bytes
518343a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | /**
* compliance_edge.test.ts
* Doctrine v6 R3 — Vertical Governance Receipts
* 10 EDGE cases: boundary conditions, degenerate-but-valid inputs, and
* schema-legal extremes that must validate correctly (or reject as expected).
*
* Test framework: Jest / ts-jest
* Run: npx jest tests/compliance/compliance_edge.test.ts
*/
import Ajv from "ajv";
import addFormats from "ajv-formats";
import * as fs from "fs";
import * as path from "path";
const SCHEMA_PATH = path.resolve(__dirname, "../../a11oy-knowledge.schema.json");
function buildValidator() {
const ajv = new Ajv({ allErrors: true, strict: false });
addFormats(ajv);
const schema = JSON.parse(fs.readFileSync(SCHEMA_PATH, "utf8"));
return ajv.compile(schema);
}
function basePolicy(overrides: Partial<any> = {}): any {
return Object.assign(
{
schema_version: "1.0.0",
vertical: "financial",
regime: "SOX/Dodd-Frank",
effective_date: "2025-01-01",
jurisdiction: "US-Federal",
meta: {
title: "Financial AI Policy base for edge testing",
description: "Base policy for edge case compliance testing with sufficient description length.",
authority: "Pub. L. 107-204; Pub. L. 111-203",
receipt_chain_required: true,
merkle_root_algorithm: "SHA3-256",
},
regulatory_clauses: Array.from({ length: 8 }, (_, i) => ({
clause_id: `SOX-EDGE-${String(i + 1).padStart(3, "0")}`,
title: `Edge test clause ${i + 1}`,
citation: `17 CFR § 240.${i + 10}`,
full_ref: `Full reference: 17 C.F.R. § 240.${i + 10} — Edge test clause for compliance testing`,
lambda_axes: [
{ axis: "Λ7", label: "Auditability", weight: 1.0, enforcement: "mandatory", rationale: "Tamper-evident receipt chain required for all financial AI decisions." },
],
})),
compliance_thresholds: {
minimum_lambda_coverage: 7,
mandatory_axes: ["Λ2", "Λ7"],
receipt_retention_days: 2555,
},
receipt_chain: {
algorithm: "SHA3-256",
chaining: "merkle_dag",
quorum: "2-of-3",
nodes: ["primary", "secondary", "audit"],
},
},
overrides
);
}
describe("Compliance EDGE — boundary and degenerate-valid cases", () => {
const validate = buildValidator();
// EDGE-001: Exactly 8 regulatory_clauses (lower boundary, must pass)
test("EDGE-001: exactly 8 regulatory_clauses (lower bound) is accepted", () => {
const p = basePolicy();
expect(p.regulatory_clauses.length).toBe(8);
expect(validate(p)).toBe(true);
});
// EDGE-002: Exactly 12 regulatory_clauses (upper boundary, must pass)
test("EDGE-002: exactly 12 regulatory_clauses (upper bound) is accepted", () => {
const p = basePolicy();
p.regulatory_clauses = Array.from({ length: 12 }, (_, i) => ({
clause_id: `SOX-UP-${String(i + 1).padStart(3, "0")}`,
title: `Upper bound clause ${i + 1}`,
citation: `17 CFR § 240.${i + 50}`,
full_ref: `Full reference: 17 C.F.R. § 240.${i + 50} — upper boundary test clause`,
lambda_axes: [
{ axis: "Λ2", label: "Accountability", weight: 0.8, enforcement: "mandatory", rationale: "Accountability requirement for financial AI systems under SOX." },
],
}));
expect(validate(p)).toBe(true);
});
// EDGE-003: weight exactly 0.0 (minimum) is accepted
test("EDGE-003: lambda weight 0.0 (minimum) is accepted", () => {
const p = basePolicy();
p.regulatory_clauses[0].lambda_axes[0].weight = 0.0;
expect(validate(p)).toBe(true);
});
// EDGE-004: weight exactly 1.0 (maximum) is accepted
test("EDGE-004: lambda weight 1.0 (maximum) is accepted", () => {
const p = basePolicy();
p.regulatory_clauses[0].lambda_axes[0].weight = 1.0;
expect(validate(p)).toBe(true);
});
// EDGE-005: mandatory_axes with single element (minimum array) is accepted
test("EDGE-005: mandatory_axes with 1 element is accepted", () => {
const p = basePolicy();
p.compliance_thresholds.mandatory_axes = ["Λ7"];
expect(validate(p)).toBe(true);
});
// EDGE-006: mandatory_axes with all 10 axes (maximum) is accepted
test("EDGE-006: mandatory_axes with all 10 Λ-axes is accepted", () => {
const p = basePolicy();
p.compliance_thresholds.mandatory_axes = ["Λ1","Λ2","Λ3","Λ4","Λ5","Λ6","Λ7","Λ8","Λ9","Λ10"];
expect(validate(p)).toBe(true);
});
// EDGE-007: receipt_retention_days exactly 365 (minimum) is accepted
test("EDGE-007: receipt_retention_days 365 (minimum) is accepted", () => {
const p = basePolicy();
p.compliance_thresholds.receipt_retention_days = 365;
expect(validate(p)).toBe(true);
});
// EDGE-008: nodes array with exactly 2 elements (minimum) is accepted
test("EDGE-008: receipt_chain nodes with 2 elements (minimum) is accepted", () => {
const p = basePolicy();
p.receipt_chain.nodes = ["primary", "backup"];
expect(validate(p)).toBe(true);
});
// EDGE-009: nodes array with 7 elements (maximum) is accepted
test("EDGE-009: receipt_chain nodes with 7 elements (maximum) is accepted", () => {
const p = basePolicy();
p.receipt_chain.nodes = ["n1","n2","n3","n4","n5","n6","n7"];
expect(validate(p)).toBe(true);
});
// EDGE-010: nodes array with 8 elements (exceeds maximum 7) is rejected
test("EDGE-010: receipt_chain nodes with 8 elements (> max 7) is rejected", () => {
const p = basePolicy();
p.receipt_chain.nodes = ["n1","n2","n3","n4","n5","n6","n7","n8"];
expect(validate(p)).toBe(false);
});
});
|