فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
feat(holoo): classify invoice and accounting integrity evidence fail-closed
Davood Mehraban committed
Nov 22, 2026 at 23:31 UTC
7fa3a8318e019d8e4a93df1807ff72231ca93ca2
2 files changed
+30
src/holoo-integrity-assessment.cjs
new
+17
@@ -0,0 +1,17 @@
1
+'use strict';
2
+// Deterministic interpretation of a read-only lab snapshot; never authorizes SQL writes.
3
+const FIELDS = ['invoiceHeaders','invoiceLines','accountingDocuments','orphanInvoiceLines','orphanInvoiceLinesExcludingCandidateSentinel','candidateSentinelRows','missingReferencedAccountingDocuments','duplicateInvoiceTypeNumberGroups','invoiceHeadersWithoutAccountingCode'];
4
+function assessHolooIntegrity(audit) {
5
+ const i = audit?.integrity;
6
+ const invalid = !audit || audit.schemaVersion !== 1 || audit.complete !== true || audit.readOnlyAudit !== true || audit.database !== 'HolooBackup_050808_LAB_20261110' || audit.productionWriteGate?.status !== 'NO-GO' || audit.productionWriteGate?.productionWritesAuthorized !== false || !i || FIELDS.some(k => !Number.isSafeInteger(i[k]) || i[k] < 0) || i.orphanInvoiceLines > i.invoiceLines || i.orphanInvoiceLinesExcludingCandidateSentinel > i.orphanInvoiceLines || i.candidateSentinelRows > i.invoiceLines;
7
+ if (invalid) return Object.freeze({status:'INVALID_EVIDENCE', productionWritesAuthorized:false, findings:[]});
8
+ const findings = [];
9
+ if (i.orphanInvoiceLinesExcludingCandidateSentinel > 0) findings.push('MEANINGFUL_ORPHAN_LINES');
10
+ if (i.orphanInvoiceLines > 0) findings.push('RAW_ORPHAN_LINES_REQUIRE_REVIEW');
11
+ if (i.candidateSentinelRows > 0) findings.push('UNVERIFIED_SENTINEL_CANDIDATE');
12
+ if (i.missingReferencedAccountingDocuments > 0) findings.push('MISSING_ACCOUNTING_REFERENCES');
13
+ if (i.duplicateInvoiceTypeNumberGroups > 0) findings.push('DUPLICATE_INVOICE_NUMBERS');
14
+ if (i.invoiceHeadersWithoutAccountingCode > 0) findings.push('HEADERS_WITHOUT_ACCOUNTING_CODE');
15
+ return Object.freeze({status:findings.length?'REVIEW_REQUIRED':'NO_ANOMALIES_IN_CHECKED_METRICS',productionWritesAuthorized:false,findings:Object.freeze(findings),counts:Object.freeze(Object.fromEntries(FIELDS.map(k=>[k,i[k]])))});
16
+}
17
+module.exports = {assessHolooIntegrity};
tests/holoo-integrity-assessment.test.mjs
new
+13
@@ -0,0 +1,13 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import {spawnSync} from 'node:child_process';
4
+import {fileURLToPath} from 'node:url';
5
+import {createRequire} from 'node:module';
6
+const require=createRequire(import.meta.url);
7
+const {assessHolooIntegrity}=require('../src/holoo-integrity-assessment.cjs');
8
+const base=()=>({schemaVersion:1,complete:true,readOnlyAudit:true,database:'HolooBackup_050808_LAB_20261110',productionWriteGate:{status:'NO-GO',productionWritesAuthorized:false},integrity:{invoiceHeaders:10,invoiceLines:20,accountingDocuments:8,orphanInvoiceLines:1,orphanInvoiceLinesExcludingCandidateSentinel:0,candidateSentinelRows:1,missingReferencedAccountingDocuments:0,duplicateInvoiceTypeNumberGroups:0,invoiceHeadersWithoutAccountingCode:0}});
9
+test('sentinel candidate never silently erases raw orphan',()=>{const a=assessHolooIntegrity(base());assert.equal(a.status,'REVIEW_REQUIRED');assert.ok(a.findings.includes('RAW_ORPHAN_LINES_REQUIRE_REVIEW'));assert.ok(a.findings.includes('UNVERIFIED_SENTINEL_CANDIDATE'));assert.equal(a.productionWritesAuthorized,false)});
10
+test('meaningful orphan and accounting/invoice anomalies remain independent',()=>{const b=base();Object.assign(b.integrity,{orphanInvoiceLines:2,orphanInvoiceLinesExcludingCandidateSentinel:1,missingReferencedAccountingDocuments:2,duplicateInvoiceTypeNumberGroups:1,invoiceHeadersWithoutAccountingCode:3});const a=assessHolooIntegrity(b);for(const f of ['MEANINGFUL_ORPHAN_LINES','MISSING_ACCOUNTING_REFERENCES','DUPLICATE_INVOICE_NUMBERS','HEADERS_WITHOUT_ACCOUNTING_CODE'])assert.ok(a.findings.includes(f));});
11
+test('incomplete, inconsistent, and unauthorized evidence fails closed',()=>{for(const change of [x=>x.complete=false,x=>x.integrity.orphanInvoiceLines=21,x=>x.integrity.orphanInvoiceLinesExcludingCandidateSentinel=2,x=>x.integrity.invoiceHeaders=-1,x=>x.productionWriteGate.status='GO']){const b=base();change(b);assert.equal(assessHolooIntegrity(b).status,'INVALID_EVIDENCE')}});
12
+test('zero checked anomalies is not permission to write',()=>{const b=base();Object.assign(b.integrity,{orphanInvoiceLines:0,candidateSentinelRows:0});const a=assessHolooIntegrity(b);assert.equal(a.status,'NO_ANOMALIES_IN_CHECKED_METRICS');assert.equal(a.productionWritesAuthorized,false)});
13
+test('live read-only LAB structural snapshot can be classified', {skip:process.platform!=='win32'||process.env.HOLOO_SQL_INTEGRATION!=='1'},()=>{const path=fileURLToPath(new URL('../scripts/holoo-schema-audit.ps1',import.meta.url));const r=spawnSync('powershell.exe',['-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-File',path,'-Json'],{encoding:'utf8',timeout:45000,maxBuffer:2e6});assert.equal(r.status,0,r.stderr);const a=assessHolooIntegrity(JSON.parse(r.stdout));assert.notEqual(a.status,'INVALID_EVIDENCE');assert.equal(a.productionWritesAuthorized,false);});