Use verified CLI preparations when web PHP cannot execute processes
tests / ci (push) Waiting to run
tests / ci (push) Waiting to run
This commit is contained in:
@@ -198,6 +198,41 @@ final class DemographyTest extends TestCase
|
||||
$migration->down();
|
||||
}
|
||||
|
||||
public function test_cli_preparation_imports_without_process_execution_and_keeps_exact_values(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
$disk = Storage::disk('local');
|
||||
$original = 'SYNTHETIC prepared original'; $sha = hash('sha256', $original);
|
||||
$directory = 'prepared/'.$sha; $disk->makeDirectory($directory);
|
||||
$disk->put('synthetic.xlsx', $original);
|
||||
$row = ['province' => 'SYNTHETIC province', 'territory' => 'SYNTHETIC province', 'level' => 'province',
|
||||
'year' => 2026, 'indicator' => 'population', 'sex' => 'all', 'residence' => 'all', 'age_group' => 'all', 'unit' => 'pessoas',
|
||||
'data_kind' => 'projected', 'original_value' => '100.125', 'numeric_value' => '100.125', 'sheet' => '2026', 'cell' => 'B4'];
|
||||
$records = json_encode($row, JSON_THROW_ON_ERROR)."\n";
|
||||
$report = ['sha256' => $sha, 'source' => 'SYNTHETIC QA ONLY', 'record_count' => 1, 'records_file_sha256' => hash('sha256', $records),
|
||||
'territories' => [['SYNTHETIC province', 'SYNTHETIC province', 'province']], 'issues' => [], 'issue_counts' => []];
|
||||
$preview = json_encode($report, JSON_THROW_ON_ERROR);
|
||||
$receipt = ['sha256' => $sha, 'baseline_year' => null, 'parser_sha256' => hash_file('sha256', base_path('tools/demography_workbook.py')),
|
||||
'preview_sha256' => hash('sha256', $preview), 'records_sha256' => hash('sha256', $records), 'record_count' => 1];
|
||||
$disk->put($directory.'/preview.json', $preview); $disk->put($directory.'/records.ndjson', $records);
|
||||
$disk->put($directory.'/preparation.json', json_encode($receipt, JSON_THROW_ON_ERROR));
|
||||
config(['demography.prepared_directory' => $disk->path('prepared'), 'demography.python' => '/missing-python-must-not-run']);
|
||||
$this->mock(\App\Services\Malware\MalwareScanner::class)->shouldReceive('scan')->once()->andReturn([
|
||||
'result' => 'clean', 'engine' => 'synthetic', 'engine_version' => 'test']);
|
||||
$service = app(DemographicImport::class);
|
||||
$this->assertTrue($service->preparedSourcesReady(['synthetic.xlsx' => ['sha256' => $sha, 'records' => 1]]));
|
||||
$result = $service->prepare($this->manager, $disk->path('synthetic.xlsx'), 'synthetic.xlsx', 'SYNTHETIC', null);
|
||||
$this->assertSame(0, DB::table('demographic_observations')->where('import_id', $result['id'])->count());
|
||||
$service->confirm($this->manager, $result['id'], $sha, [], 'Synthetic authenticated import from CLI preparation.');
|
||||
$this->assertSame('100.125', DB::table('demographic_observations')->where('import_id', $result['id'])->value('numeric_value'));
|
||||
$this->assertSame('imported', DB::table('demographic_imports')->where('id', $result['id'])->value('status'));
|
||||
$disk->put($directory.'/records.ndjson', 'TAMPERED');
|
||||
try { $service->preparedSource($sha, null); $this->fail('Changed prepared records must be refused.'); }
|
||||
catch (\Symfony\Component\HttpKernel\Exception\HttpException $error) { $this->assertSame(409, $error->getStatusCode()); }
|
||||
$receipt['parser_sha256'] = str_repeat('0', 64); $disk->put($directory.'/preparation.json', json_encode($receipt, JSON_THROW_ON_ERROR));
|
||||
$this->assertFalse($service->preparedSourcesReady(['synthetic.xlsx' => ['sha256' => $sha, 'records' => 1]]));
|
||||
}
|
||||
|
||||
public function test_remote_consultation_requires_explicit_activation_and_preserves_versions(): void
|
||||
{
|
||||
$environment = app()->environment();
|
||||
|
||||
Reference in New Issue
Block a user