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

audit(holoo): capture read-only procedure lexical signals

Davood Mehraban committed Nov 23, 2026 at 08:35 UTC 32222c47a8010555f8e320ed4736e05fd7575000
2 files changed +62
scripts/holoo-financial-procedure-signals.ps1 new
+29
@@ -0,0 +1,29 @@
1 +# Read-only lexical signals from stored-procedure definitions; never execute procedures.
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 -or -not ($raw|ConvertFrom-Json).readyForLabSql){throw 'Approved LAB preflight failed'}
8 +Add-Type -AssemblyName System.Data
9 +$c=New-Object System.Data.SqlClient.SqlConnection('Server=ARAM\TNC;Database=HolooBackup_050808_LAB_20261110;Integrated Security=True;Connection Timeout=5;Application Name=FinoraHolooProcedureSignals')
10 +try {
11 + $c.Open();$q=$c.CreateCommand();$q.CommandTimeout=20
12 + $q.CommandText='SELECT DB_NAME()'
13 + $db=[string]$q.ExecuteScalar()
14 + if($db -ne 'HolooBackup_050808_LAB_20261110'){throw 'Unexpected database'}
15 + $q.CommandText="SELECT DISTINCT p.object_id,SCHEMA_NAME(p.schema_id) AS procedure_schema,p.name AS procedure_name,m.definition FROM sys.procedures p JOIN sys.sql_modules m ON m.object_id=p.object_id WHERE EXISTS (SELECT 1 FROM sys.sql_expression_dependencies d WHERE d.referencing_id=p.object_id AND (d.referenced_entity_name IN ('FACTURE','FACTART','SANAD') OR d.referenced_id IN (OBJECT_ID('dbo.FACTURE'),OBJECT_ID('dbo.FACTART'),OBJECT_ID('dbo.SANAD')))) ORDER BY procedure_schema,procedure_name"
16 + $reader=$q.ExecuteReader();$rows=@()
17 + try {
18 + while($reader.Read()){
19 + $definition=if($reader.IsDBNull(3)){$null}else{[string]$reader.GetString(3)}
20 + $signals=@{}
21 + foreach($term in @('FACTURE','FACTART','SANAD','Sum_Price','Takhfif','Sum_Levy','Sum_Scot','Tedad','Buy_Price','Price_BS','INSERT','UPDATE','DELETE','EXEC','sp_executesql')){
22 + $signals[$term]=if($null -eq $definition){$null}else{[regex]::Matches($definition,'(?i)\b'+[regex]::Escape($term)+'\b').Count}
23 + }
24 + $rows += [pscustomobject]@{schema=$reader.GetString(1);name=$reader.GetString(2);definitionAvailable=($null -ne $definition);signals=$signals}
25 + }
26 + }finally{$reader.Close()}
27 + $result=[pscustomobject]@{schemaVersion=1;database=$db;metadataOnly=$true;procedureCount=$rows.Count;procedures=@($rows);lexicalOnly=$true;dynamicSqlAndIndirectCallsUnresolved=$true;financialSemanticsVerified=$false;productionWriteGate='NO-GO';note='Token counts are lexical hints, not execution paths or accounting formulas; procedure bodies are not exported'}
28 + if($Json){$result|ConvertTo-Json -Depth 7 -Compress}else{$result|Format-List}
29 +}finally{$c.Dispose()}
tests/holoo-financial-procedure-signals.test.mjs new
+33
@@ -0,0 +1,33 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import { readFileSync } from 'node:fs';
4 +import { spawnSync } from 'node:child_process';
5 +import { fileURLToPath } from 'node:url';
6 +import { resolve, dirname } from 'node:path';
7 +
8 +const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
9 +const script = resolve(root, 'scripts/holoo-financial-procedure-signals.ps1');
10 +
11 +test('procedure signals are catalog-only and preflight-gated', () => {
12 + const source = readFileSync(script, 'utf8');
13 + assert.match(source, /holoo-direct-sql-readiness\.ps1/);
14 + assert.match(source, /sys\.sql_modules/);
15 + assert.match(source, /sys\.sql_expression_dependencies/);
16 + assert.match(source, /productionWriteGate='NO-GO'/);
17 + assert.doesNotMatch(source, /\.ExecuteNonQuery\s*\(/i);
18 + assert.doesNotMatch(source, /\bEXEC(?:UTE)?\s+dbo\./i);
19 +});
20 +
21 +test('live lab signal output is explicitly non-authoritative', { skip: process.platform !== 'win32' }, () => {
22 + const run = spawnSync('powershell.exe', ['-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-File',script,'-Json'], { encoding:'utf8', timeout:60000 });
23 + assert.equal(run.status, 0, run.stderr);
24 + const report = JSON.parse(run.stdout);
25 + assert.equal(report.database, 'HolooBackup_050808_LAB_20261110');
26 + assert.equal(report.metadataOnly, true);
27 + assert.equal(report.lexicalOnly, true);
28 + assert.equal(report.financialSemanticsVerified, false);
29 + assert.equal(report.productionWriteGate, 'NO-GO');
30 + assert.equal(report.procedureCount, report.procedures.length);
31 + assert.ok(report.procedureCount > 0);
32 + assert.ok(report.procedures.every(p => typeof p.name === 'string' && typeof p.signals.FACTURE === 'number'));
33 +});