فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(a02): localdb restored schema inventory must pass no-business-row contract
davoodmehraban89 committed
Oct 30, 2026 at 20:00 UTC
ec1b6218558a5e970475ce571bf7c8f11f457862
1 file changed
+46
scripts/a02-synthetic-sql-localdb-restore-smoke.ps1
+46
@@ -96,6 +96,52 @@ try{
96
[Environment]::NewLine+'RESTORE DATABASE ['+$restored+'] '+$from+', RECOVERY;')
97
$phase='dbcc-checkdb'
98
ExecSql $conn ('DBCC CHECKDB(['+$restored+']) WITH NO_INFOMSGS;')
99
+ $phase='isolated-schema-inventory'
100
+ # Execute the schema-only command against the real restored synthetic DB.
101
+ # No table names/column names or private data are logged.
102
+ $inventoryScript=Join-Path $PSScriptRoot 'a02-isolated-schema-inventory.ps1'
103
+ $inventoryLines=@(& powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File $inventoryScript -Mode Inspect -InstanceName $instance -DatabaseName $restored)
104
+ Require ($LASTEXITCODE -eq 0) 'A02_SCHEMA_INVENTORY_INTEGRATION_FAILED'
105
+ $inventory=($inventoryLines | Out-String | ConvertFrom-Json)
106
+ Require ($inventory.status -eq 'isolated-schema-inventoried' -and
107
+ $inventory.tableCount -eq 1 -and $inventory.columnCount -eq 2 -and
108
+ $inventory.fingerprintSha256 -cmatch '^[0-9a-f]{64} $row=QuerySql $conn ('SELECT COUNT_BIG(*) AS C,SUM(amount) AS T FROM ['+$restored+'].dbo.A02Synthetic;')
109
+ Require ($row.Rows.Count -eq 1 -and [long]$row.Rows[0]['C'] -eq 2 -and
110
+ [long]$row.Rows[0]['T'] -eq 80235) 'A02_RESTORED_SYNTHETIC_TOTALS_MISMATCH'
111
+ [pscustomobject]@{
112
+ status='synthetic-localdb-restore-verified';ownerBackupUsed=$false
113
+ headerVerified=$true;fileListVerified=$true;verifyOnlyPassed=$true
114
+ restoreExecuted=$true;dbccPassed=$true;syntheticRecords=2
115
+ syntheticTotal=80235;schemaOnlyInventoryVerified=$true
116
+ financialMigrationPerformed=$false;canImport=$false
117
+ }|ConvertTo-Json -Compress
118
+}catch{
119
+ # Only a bounded phase and exception *type* are public; never emit raw SQL,
120
+ # paths, backup bytes, identity, or exception messages.
121
+ $kind=$_.Exception.GetType().Name
122
+ Write-Error ('A02_SYNTHETIC_LOCALDB_RESTORE_FAILED phase='+$phase+' type='+$kind)
123
+ exit 2
124
+}finally{
125
+ if($null -ne $conn){
126
+ try{
127
+ foreach($name in @($restored,$source)){
128
+ ExecSql $conn ('IF DB_ID('+(Literal $name)+') IS NOT NULL BEGIN '+
129
+ 'ALTER DATABASE ['+$name+'] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; '+
130
+ 'DROP DATABASE ['+$name+']; END;')
131
+ }
132
+ }catch{}
133
+ $conn.Dispose()
134
+ }
135
+ if($created){
136
+ try{& $localdb stop $instance -k | Out-Null}catch{}
137
+ try{& $localdb delete $instance | Out-Null}catch{}
138
+ }
139
+ if([IO.Directory]::Exists($folder)){try{[IO.Directory]::Delete($folder,$true)}catch{}}
140
+}
141
+ -and
142
+ $inventory.userRowsRead -eq $false -and
143
+ $inventory.databaseModified -eq $false -and
144
+ $inventory.canImport -eq $false) 'A02_SCHEMA_INVENTORY_CONTRACT_FAILED'
145
$phase='synthetic-reconciliation'
146
$row=QuerySql $conn ('SELECT COUNT_BIG(*) AS C,SUM(amount) AS T FROM ['+$restored+'].dbo.A02Synthetic;')
147
Require ($row.Rows.Count -eq 1 -and [long]$row.Rows[0]['C'] -eq 2 -and