test(funding): demonstrate B03 B06 with documentary institutions in QA
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
// Read-only QA audit: compare source values, allowing JSONB object key ordering.
|
||||
require __DIR__.'/continuity-qa-bootstrap.php';
|
||||
$app = require 'bootstrap/app.php';
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
if (DB::connection()->getDatabaseName() !== 'continuity_20261120_test') {
|
||||
throw new Exception('QA only');
|
||||
}
|
||||
$f = json_decode(file_get_contents('outputs/funding-b03-b06-20261120/fixture.json'), true);
|
||||
$refs = json_decode(file_get_contents('database/data/funding-institutions-nov2026.json'), true)['references'];
|
||||
foreach ($f['records'] as $key => $r) {
|
||||
$row = DB::table('funding_programmes')->where('id', $r['id'])->first();
|
||||
if (json_decode($row->draft, true) != $refs[$key]['draft']) {
|
||||
throw new Exception('Original draft mismatch');
|
||||
}
|
||||
}
|
||||
echo json_encode(['source_unchanged' => hash_file('sha256', 'database/data/funding-institutions-nov2026.json') === $f['source_sha256'], 'original_drafts_unchanged' => count($f['records']), 'invented_institutions' => 0, 'originals_modified' => false, 'operational_writes' => false], JSON_PRETTY_PRINT);
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
// Only QA fixtures from supplied real institutions; no operational publication.
|
||||
require __DIR__.'/continuity-qa-bootstrap.php';
|
||||
$app = require 'bootstrap/app.php';
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
use App\Services\FundingInstitutionDetails;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
$i = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
||||
if ($i->name !== 'continuity_20261120_test' || $i->port != 55441) {
|
||||
throw new Exception('QA only');
|
||||
}
|
||||
$outputDirectory = base_path('outputs/funding-b03-b06-20261120');
|
||||
if (! is_dir($outputDirectory)) {
|
||||
mkdir($outputDirectory, 0700, true);
|
||||
}
|
||||
$package = json_decode(file_get_contents('database/data/funding-institutions-nov2026.json'), true);
|
||||
$snapshotPath = $argv[1] ?? throw new RuntimeException('Supply the existing read-only public geography snapshot');
|
||||
$snapshot = json_decode(file_get_contents($snapshotPath), true);
|
||||
if (! $snapshot['read_only']) {
|
||||
throw new Exception('Original snapshot required');
|
||||
}
|
||||
$result = DB::transaction(function () use ($snapshot, $package) {
|
||||
foreach ($snapshot['records'] as $g) {
|
||||
DB::table('geo_locations')->insertOrIgnore($g);
|
||||
}
|
||||
$provinceIds = collect($snapshot['records'])->where('location_type', 'province')->keyBy('name');
|
||||
$actor = DB::table('users')->first()->id;
|
||||
$out = [];
|
||||
foreach (['moza', 'bci', 'standard-bank', 'ac-microbanco'] as $key) {
|
||||
$ref = $package['references'][$key];
|
||||
$p = $ref['draft'];
|
||||
foreach ($ref['location_territory_names'] ?? [] as $index => $name) {
|
||||
$matches = $provinceIds->filter(fn ($g) => Str::lower(Str::ascii($g['name'])) === Str::lower(Str::ascii($name)));
|
||||
if ($matches->count() === 1) {
|
||||
$p['locations'][$index]['territory_id'] = $matches->first()['id'];
|
||||
}
|
||||
}
|
||||
$p = [...$p, ...app(FundingInstitutionDetails::class)->normalize($p, true)];
|
||||
$code = 'qa-b03-b06-'.$key;
|
||||
$id = DB::table('funding_programmes')->where('code', $code)->value('id');
|
||||
if (! $id) {
|
||||
$id = (string) Str::uuid();
|
||||
$v = (string) Str::uuid();
|
||||
DB::table('funding_programmes')->insert(['id' => $id, 'code' => $code, 'version' => 1, 'draft' => json_encode($ref['draft']), 'created_by' => $actor, 'created_at' => now(), 'updated_at' => now()]);
|
||||
DB::table('funding_programme_versions')->insert(['id' => $v, 'programme_id' => $id, 'version' => 1, 'payload' => json_encode($p), 'reason' => 'QA-only fixture from unchanged supplied source, no editorial or operational publication', 'actor_id' => $actor, 'published_at' => now()]);
|
||||
DB::table('funding_programmes')->where('id', $id)->update(['published_version_id' => $v]);
|
||||
}
|
||||
$out[$key] = ['id' => $id, 'title' => $p['title'], 'products' => array_column($p['products'], 'availability')];
|
||||
}
|
||||
|
||||
return ['source_sha256' => hash_file('sha256', 'database/data/funding-institutions-nov2026.json'), 'records' => $out, 'provinces' => $provinceIds->map(fn ($g) => $g['id'])->all()];
|
||||
});
|
||||
$bytes = json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
|
||||
file_put_contents(base_path('outputs/funding-b03-b06-20261120/fixture.json'), $bytes);
|
||||
echo $bytes;
|
||||
Reference in New Issue
Block a user