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

feat(holoo): discover LAB financial column metadata without data access

Davood Mehraban committed Nov 23, 2026 at 03:31 UTC ef6acdeeec788ba6965cdff98ae7880739c23f8e
2 files changed +43
scripts/holoo-financial-column-discovery.ps1 new
+23
@@ -0,0 +1,23 @@
1 +# Metadata-only discovery. No financial formula or column semantics are assumed.
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=FinoraHolooFinancialMetadata')
10 +try {
11 + $c.Open()
12 + $q=$c.CreateCommand();$q.CommandTimeout=15
13 + $q.CommandText="SELECT DB_NAME() AS database_name,SYSTEM_USER AS login_name"
14 + $r=$q.ExecuteReader()
15 + try {if(-not $r.Read() -or $r.GetString(0) -ne 'HolooBackup_050808_LAB_20261110'){throw 'Unexpected database'};$login=$r.GetString(1)}finally{$r.Close()}
16 + $q.CommandText="SELECT t.name AS table_name,c.column_id,c.name AS column_name,ty.name AS sql_type,c.max_length,c.precision,c.scale,c.is_nullable FROM sys.tables t JOIN sys.schemas s ON s.schema_id=t.schema_id JOIN sys.columns c ON c.object_id=t.object_id JOIN sys.types ty ON ty.user_type_id=c.user_type_id WHERE s.name='dbo' AND t.name IN ('FACTURE','FACTART','SANAD') ORDER BY t.name,c.column_id"
17 + $r=$q.ExecuteReader();$columns=@()
18 + try {while($r.Read()){$columns += [pscustomobject]@{table=$r.GetString(0);ordinal=$r.GetInt32(1);name=$r.GetString(2);sqlType=$r.GetString(3);maxLength=$r.GetInt16(4);precision=$r.GetByte(5);scale=$r.GetByte(6);nullable=$r.GetBoolean(7)}}}finally{$r.Close()}
19 + $tables=@($columns|Group-Object table|ForEach-Object {$_.Name})
20 + if(@($tables|Where-Object {$_ -notin @('FACTURE','FACTART','SANAD')}).Count -gt 0 -or $tables.Count -ne 3){throw 'Incomplete or unexpected LAB table metadata'}
21 + $result=[pscustomobject]@{schemaVersion=1;database='HolooBackup_050808_LAB_20261110';login=$login;metadataOnly=$true;columns=@($columns);columnSemanticsVerified=$false;financialReconciliationAuthorized=$false;productionWritesAuthorized=$false;productionWriteGate='NO-GO';note='Catalog names and types only; do not infer VAT, discount, amounts, or stock movements from names'}
22 + if($Json){$result|ConvertTo-Json -Depth 5 -Compress}else{$result|Format-List}
23 +}finally{$c.Dispose()}
tests/holoo-financial-column-discovery.test.mjs new
+20
@@ -0,0 +1,20 @@
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 script=fileURLToPath(new URL('../scripts/holoo-financial-column-discovery.ps1',import.meta.url));
7 +test('financial metadata discovery is scoped to LAB and catalog SELECTs',()=>{
8 + const source=readFileSync(script,'utf8');
9 + assert.match(source,/HolooBackup_050808_LAB_20261110/);
10 + assert.match(source,/sys\.columns/);assert.match(source,/sys\.types/);
11 + assert.match(source,/financialReconciliationAuthorized=\$false/);
12 + assert.doesNotMatch(source,/\b(?:INSERT\s+INTO|UPDATE\s+dbo\.|DELETE\s+FROM|CREATE\s+TABLE|ALTER\s+TABLE|DROP\s+TABLE|EXEC(?:UTE)?\s+dbo\.)\b/i);
13 +});
14 +test('live metadata inventory has all three tables without claiming financial semantics',{skip:process.platform!=='win32'||process.env.HOLOO_SQL_INTEGRATION!=='1'},()=>{
15 + const r=spawnSync('powershell.exe',['-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-File',script,'-Json'],{encoding:'utf8',timeout:30000,maxBuffer:4*1024*1024});
16 + assert.equal(r.status,0,r.stderr);
17 + const x=JSON.parse(r.stdout);assert.equal(x.metadataOnly,true);assert.equal(x.columnSemanticsVerified,false);assert.equal(x.productionWriteGate,'NO-GO');
18 + assert.deepEqual([...new Set(x.columns.map(c=>c.table))].sort(),['FACTART','FACTURE','SANAD']);
19 + assert.ok(x.columns.every(c=>Number.isInteger(c.ordinal)&&c.ordinal>0&&typeof c.sqlType==='string'));
20 +});