fix(demography): verify D01-D06 in isolated QA with INE traceability

This commit is contained in:
2026-11-20 20:07:16 +02:00
parent 558c11ef17
commit 3f66201cbe
17 changed files with 570 additions and 89 deletions
+25
View File
@@ -0,0 +1,25 @@
<?php
// Read-only comparison of QA observations with exact INE slices.
require __DIR__.'/continuity-qa-bootstrap.php';
$app = require dirname(__DIR__).'/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\DB;
$identity = DB::selectOne('select current_database() as name, inet_server_port() as port');
throw_unless($identity->name === 'continuity_20261120_test' && (int) $identity->port === 55441, RuntimeException::class, 'Isolated QA only');
$slices = json_decode(file_get_contents(dirname(__DIR__).'/outputs/demography-d01-d06-20261120/source-slices.json'), true, 512, JSON_THROW_ON_ERROR);
$checked = 0;
foreach ($slices as $slice) {
$batch = DB::table('demographic_imports')->where('sha256', $slice['sha256'])->first();
throw_unless($batch && $batch->file_name === $slice['file'], RuntimeException::class, 'Original provenance missing');
foreach ($slice['records'] as $row) {
$stored = DB::table('demographic_observations as o')->join('geo_locations as g', 'g.id', '=', 'o.geo_location_id')
->where('o.import_id', $batch->id)->where('o.sheet', $row['sheet'])->where('o.cell', $row['cell'])->first(['o.*', 'g.name']);
throw_unless($stored && $stored->name === $row['territory'] && $stored->numeric_value === $row['numeric_value'] && $stored->original_value === $row['original_value'], RuntimeException::class, 'Observation mismatch');
$checked++;
}
}
echo json_encode(['database' => $identity->name, 'port' => $identity->port, 'exact_observations_checked' => $checked, 'mismatches' => 0, 'writes' => false, 'traceability_preserved' => true], JSON_PRETTY_PRINT).PHP_EOL;