فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

fix(holoo): reject impossible accounting integrity metrics

Davood Mehraban committed Nov 23, 2026 at 01:34 UTC 5d884f19686ca0d82c0c63be3f907427d08137ed
2 files changed +11 -3
src/holoo-integrity-assessment.cjs
+2 -2
@@ -1,9 +1,9 @@
1 -'use strict';
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;
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 || i.missingReferencedAccountingDocuments > i.invoiceHeaders || i.invoiceHeadersWithoutAccountingCode > i.invoiceHeaders || i.duplicateInvoiceTypeNumberGroups > Math.floor(i.invoiceHeaders / 2);
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');
tests/holoo-integrity-assessment.test.mjs
+9 -1
@@ -1,4 +1,4 @@
1 -import test from 'node:test';
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';
@@ -11,3 +11,11 @@ test('meaningful orphan and accounting/invoice anomalies remain independent',()=
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);});
14 +
15 +test('rejects impossible accounting and numbering counts without granting writes',()=>{
16 + for(const change of [
17 + x=>x.integrity.missingReferencedAccountingDocuments=11,
18 + x=>x.integrity.invoiceHeadersWithoutAccountingCode=11,
19 + x=>x.integrity.duplicateInvoiceTypeNumberGroups=6
20 + ]){const snapshot=base();change(snapshot);const result=assessHolooIntegrity(snapshot);assert.equal(result.status,'INVALID_EVIDENCE');assert.equal(result.productionWritesAuthorized,false);}
21 +});