فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(holoo): audit live lab SQL schema read-only
Davood Mehraban committed
Nov 22, 2026 at 20:56 UTC
1f000e8d37e44f9d052155c83cb11e417810de82
2 files changed
+52
scripts/holoo-schema-audit.ps1
new
+25
@@ -0,0 +1,25 @@
1
+# Read-only structural audit of the approved Holoo backup lab database.
2
+[CmdletBinding()]
3
+param([switch]$Json)
4
+$ErrorActionPreference='Stop'
5
+$preflight=Join-Path $PSScriptRoot 'holoo-direct-sql-readiness.ps1'
6
+$raw=& powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File $preflight -Json
7
+if($LASTEXITCODE -ne 0){throw 'Approved SQL lab preflight failed'}
8
+$ready=$raw|ConvertFrom-Json
9
+if(-not $ready.readyForLabSql){throw 'Approved SQL lab preflight did not pass'}
10
+Add-Type -AssemblyName System.Data
11
+$c=New-Object System.Data.SqlClient.SqlConnection('Server=ARAM\TNC;Database=HolooBackup_050808_LAB_20261110;Integrated Security=True;Connection Timeout=5;Application Name=FinoraHolooReadOnlyAudit')
12
+try {
13
+ $c.Open()
14
+ $q=$c.CreateCommand();$q.CommandTimeout=15
15
+ $q.CommandText="SELECT t.name AS table_name, (SELECT COUNT(*) FROM sys.foreign_keys f WHERE f.parent_object_id=t.object_id) AS outbound_fk, (SELECT COUNT(*) FROM sys.triggers g WHERE g.parent_id=t.object_id) AS trigger_count, (SELECT COUNT(*) FROM sys.check_constraints k WHERE k.parent_object_id=t.object_id) AS check_count, (SELECT COUNT(*) FROM sys.key_constraints k WHERE k.parent_object_id=t.object_id AND k.type='PK') AS primary_key_count FROM sys.tables t WHERE t.name IN ('FACTURE','FACTART','SANAD') ORDER BY t.name"
16
+ $r=$q.ExecuteReader()
17
+ 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'}
22
+ if($Json){$result|ConvertTo-Json -Depth 6}else{$tables|Format-Table -AutoSize;Write-Output ('COMPLETE='+$result.complete)}
23
+ if(-not $result.complete){exit 2}
24
+} finally {$c.Dispose()}
25
+
tests/holoo-schema-audit.test.mjs
new
+27
@@ -0,0 +1,27 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { readFileSync } from 'node:fs';
4
+import { fileURLToPath } from 'node:url';
5
+import { spawnSync } from 'node:child_process';
6
+const path = fileURLToPath(new URL('../scripts/holoo-schema-audit.ps1', import.meta.url));
7
+const script = readFileSync(path, 'utf8');
8
+test('schema audit uses approved preflight and read-only catalog queries', () => {
9
+ assert.match(script, /holoo-direct-sql-readiness\.ps1/);
10
+ assert.match(script, /sys\.foreign_keys/);
11
+ assert.match(script, /sys\.key_constraints/);
12
+ assert.match(script, /sys\.check_constraints/);
13
+ assert.match(script, /sys\.triggers/);
14
+ assert.doesNotMatch(script, /\b(?:INSERT\s+INTO|UPDATE\s+\w+\s+SET|DELETE\s+FROM|DROP\s+DATABASE|ALTER\s+DATABASE)\b/i);
15
+});
16
+test('real lab structural audit returns three complete primary-keyed tables', {skip: process.platform !== 'win32'}, () => {
17
+ const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-File', path, '-Json'], {encoding:'utf8', timeout:30000});
18
+ assert.equal(result.status, 0, result.stderr);
19
+ const audit = JSON.parse(result.stdout);
20
+ assert.equal(audit.complete, true);
21
+ assert.equal(audit.readOnlyAudit, true);
22
+ assert.deepEqual(audit.tables.map(t => t.table), ['FACTART','FACTURE','SANAD']);
23
+ for (const table of audit.tables) {
24
+ assert.equal(table.primaryKeys, 1);
25
+ for(const key of ['outboundForeignKeys','triggers','checkConstraints']) assert.ok(Number.isInteger(table[key]) && table[key]>=0);
26
+ }
27
+});