فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(holoo): detect orphan invoice lines in backup lab
Davood Mehraban committed
Nov 22, 2026 at 20:57 UTC
658bf7496825304b2161118de9355d7c3f3f0862
2 files changed
+11
-1
scripts/holoo-schema-audit.ps1
+8
-1
@@ -18,8 +18,15 @@ try {
18
$tables=@()
19
while($r.Read()){$tables+= [pscustomobject]@{table=$r.GetString(0);outboundForeignKeys=$r.GetInt32(1);triggers=$r.GetInt32(2);checkConstraints=$r.GetInt32(3);primaryKeys=$r.GetInt32(4)}}
20
} finally {$r.Close()}
21
- $result=[pscustomobject]@{schemaVersion=1;database='HolooBackup_050808_LAB_20261110';readOnlyAudit=$true;tables=$tables;complete=($tables.Count -eq 3);note='Structural audit only; no claim of application-level invariants or concurrency safety'}
21
+ $q.CommandText="SELECT (SELECT COUNT_BIG(*) FROM dbo.FACTURE) AS invoiceHeaders,(SELECT COUNT_BIG(*) FROM dbo.FACTART) AS invoiceLines,(SELECT COUNT_BIG(*) FROM dbo.SANAD) AS accountingDocuments,(SELECT COUNT_BIG(*) FROM dbo.FACTART a LEFT JOIN dbo.FACTURE f ON a.Fac_Code=f.Fac_Code AND a.Fac_Type=f.Fac_Type WHERE f.Fac_Code IS NULL) AS orphanInvoiceLines"
22
+ $r=$q.ExecuteReader()
23
+ try {
24
+ if(-not $r.Read()){throw 'Data integrity query returned no row'}
25
+ $integrity=[pscustomobject]@{invoiceHeaders=$r.GetInt64(0);invoiceLines=$r.GetInt64(1);accountingDocuments=$r.GetInt64(2);orphanInvoiceLines=$r.GetInt64(3)}
26
+ } finally {$r.Close()}
27
+ $result=[pscustomobject]@{schemaVersion=1;database='HolooBackup_050808_LAB_20261110';readOnlyAudit=$true;tables=$tables;integrity=$integrity;complete=($tables.Count -eq 3);note='Structural audit only; no claim of application-level invariants or concurrency safety'}
28
if($Json){$result|ConvertTo-Json -Depth 6}else{$tables|Format-Table -AutoSize;Write-Output ('COMPLETE='+$result.complete)}
29
if(-not $result.complete){exit 2}
30
} finally {$c.Dispose()}
31
32
+
tests/holoo-schema-audit.test.mjs
+3
@@ -19,9 +19,12 @@ test('real lab structural audit returns three complete primary-keyed tables', {s
19
const audit = JSON.parse(result.stdout);
20
assert.equal(audit.complete, true);
21
assert.equal(audit.readOnlyAudit, true);
22
+ for (const key of ['invoiceHeaders','invoiceLines','accountingDocuments','orphanInvoiceLines']) assert.ok(Number.isSafeInteger(audit.integrity[key]) && audit.integrity[key] >= 0, key);
23
+ assert.ok(audit.integrity.orphanInvoiceLines <= audit.integrity.invoiceLines);
24
assert.deepEqual(audit.tables.map(t => t.table), ['FACTART','FACTURE','SANAD']);
25
for (const table of audit.tables) {
26
assert.equal(table.primaryKeys, 1);
27
for(const key of ['outboundForeignKeys','triggers','checkConstraints']) assert.ok(Number.isInteger(table[key]) && table[key]>=0);
28
}
29
});
30
+