Files
Investidor-V2/outputs/investmoz-legado-setores-lote20-QA-20261015/DELTA-IMPORTADOR.patch
T
nala 6a76aac80f
tests / ci (push) Canceled after 0s
versao compilada 1
2026-10-16 09:17:28 +02:00

109 lines
8.0 KiB
Diff

--- ativo/ImportDocumentBatch.php
+++ candidata-QA/ImportDocumentBatch.php
@@ -14,7 +14,7 @@
class ImportDocumentBatch extends Command
{
- protected $signature = 'documents:import-batch {manifest : JSON manifest inside storage/app/private/document-import-staging} {--apply : Register private drafts and queue malware scans} {--actor= : Existing user ID responsible for an applied import} {--pilot-agronegocio : Restrict to the approved two-original pilot} {--backup-proof= : Fresh verified destination backup receipt for active pilot apply}';
+ protected $signature = 'documents:import-batch {manifest : JSON manifest inside storage/app/private/document-import-staging} {--apply : Register private drafts and queue malware scans} {--actor= : Existing user ID responsible for an applied import} {--pilot-agronegocio : Restrict to the approved two-original pilot} {--sectors-lot20 : Restrict to the named 20-resource sector batch} {--backup-proof= : Fresh verified destination backup receipt for active pilot apply}';
protected $description = 'Preview or idempotently import a document batch into the existing private library';
@@ -25,6 +25,31 @@
private const PILOT_HASHES = [
'legacy-tempo-post-171985-20260420' => '0929184a6d4645b9046512675394ad4f60575273f6dab0955f71cc7474a6a4e2',
'legacy-tempo-agronegocio-image-5e3840705cf98226' => '5e3840705cf98226d1f189cf665aaa98cb05da96c645159a1332a1d429d642eb',
+ ];
+
+ private const SECTORS_MANIFEST_SHA256 = 'ade9a00c031534f4341e8f6bd5e425b502ee03efc9fcfaec4f463a10fb28201b';
+
+ private const SECTORS_HASHES = [
+ 'legacy-tempo-post-171981-20260430' => '26a70f16cd511c579f08633655ff312db05122f81e44852dd4b163fa6eef85f1',
+ 'legacy-tempo-post-172679-20260430' => '2003755b7dac53b43f4608e707321db6d2f29878926a0e74f4cf27627b70a9cb',
+ 'legacy-tempo-post-172674-20260430' => '3ae780f082a8fa7c767635cce98563f5bc027c9656c9f41f8788843a17fa1f54',
+ 'legacy-tempo-post-171990-20260616' => '8cab862be245382dd4c1fd5fcb423c47aed7be3a22e0a7f8d5521510cc36bc72',
+ 'legacy-tempo-post-172263-20260414' => '538495cd5b31047ac1c5993fdaf298ec1303330368248b251c87d201d31ff211',
+ 'legacy-tempo-post-172256-20260414' => 'dcc29cbd36cf57e0a5c88dd312c84ee03c32a3d18ae9216d3715dc7b5a6960bf',
+ 'legacy-tempo-post-172261-20260414' => '88177fccd78d8516dba670c6f71272af062cc981d52d97adefe5bf77c613b16a',
+ 'legacy-tempo-post-172258-20260417' => '48314a576dea2f2dadf47d8f1eadd7ab58030606b02eebe17aa9bd6badffb7e9',
+ 'legacy-tempo-post-172253-20260414' => 'e90e39e49ba65bbbcbbc303c6eca456e445238daf9acc935ab03690819281678',
+ 'legacy-tempo-post-172240-20260414' => '8c5e91c937032680883793a12844f1128f7ac99e97c63b68c23d1396e009ba9d',
+ 'legacy-tempo-post-172237-20260417' => 'a62a43e31da32795a7286f4c152a93d5dc829233e72023b00ea61fd8e2fcb58c',
+ 'legacy-tempo-post-172233-20260417' => '345dfd72d8ebf459eae8eb025d699afddbae751df55ffa8d053568cd08096c97',
+ 'legacy-tempo-post-172230-20260414' => '4f4570f7bbd5599cb925ed996c1734a23582362fe485736931a53b9266565d4e',
+ 'legacy-tempo-post-172223-20260414' => '514a9d88c097d234038fa6341f5a5b01e8938cb6a9535a807145c84c37010a4d',
+ 'legacy-tempo-post-172219-20260414' => '0d468ae0de9a76d2b140bc8cb5c555f29626fb6422287c917762bec3e615a70c',
+ 'legacy-tempo-post-171992-20260430' => '05eb492dd6cfca6a7f305b633658a16723c315168f4b2c75103f22d1fac84032',
+ 'legacy-tempo-image-0a2c50d91dad3a60' => '0a2c50d91dad3a6007544634540e0f61b11d3506682a5a19066bae03cdcba490',
+ 'legacy-tempo-image-28f41f12e10ab345' => '28f41f12e10ab34545d8e432f6e8c74f86960e17e0c4a9956f514bcde4881eaa',
+ 'legacy-tempo-image-fe9a2e382e385b35' => 'fe9a2e382e385b35f6e61ae320e199a979678677fd327fb7d4b07d8ce0111c11',
+ 'legacy-tempo-image-8e58544e49e719f9' => '8e58544e49e719f9c865c91e07ef1030155a9e3d59260e6dc93e9c9e25674e39',
];
public function handle(): int
@@ -66,16 +91,22 @@
$apply = (bool) $this->option('apply');
$actorId = $this->option('actor');
$pilot = (bool) $this->option('pilot-agronegocio');
- if ($pilot) {
+ $sectors = (bool) $this->option('sectors-lot20');
+ if ($pilot && $sectors) {
+ $this->error('Select exactly one named batch; agribusiness scope is unchanged.');
+
+ return self::FAILURE;
+ }
+ if ($pilot || $sectors) {
try {
- $this->validatePilot($manifestPath, $manifestBytes, $manifest, $stagingReal, $apply, $actorId);
+ $this->validatePilot($manifestPath, $manifestBytes, $manifest, $stagingReal, $apply, $actorId, $sectors);
} catch (Throwable $exception) {
$this->error('Pilot refused before import: '.$exception->getMessage());
return self::FAILURE;
}
}
- if ($apply && ! $pilot) {
+ if ($apply && ! $pilot && ! $sectors) {
// CLI attribution is not an authenticated active installation. Rehearsals stay isolated.
$target = DB::selectOne('SELECT current_database() AS database,inet_server_port() AS port');
if (! app()->environment('testing') || ! str_ends_with($target->database, '_test') || (int) $target->port !== 55441
@@ -105,7 +136,7 @@
$label = is_array($record) ? (string) ($record['external_id'] ?? '#'.($index + 1)) : '#'.($index + 1);
try {
$validated = $this->validateRecord($record, $stagingReal);
- if ($pilot && ! hash_equals(self::PILOT_HASHES[$validated['external_id']] ?? '', $validated['sha256'])) {
+ if (($pilot || $sectors) && ! hash_equals(($sectors ? self::SECTORS_HASHES : self::PILOT_HASHES)[$validated['external_id']] ?? '', $validated['sha256'])) {
throw new RuntimeException('Approved pilot bytes changed after preview validation.');
}
$hash = $validated['sha256'];
@@ -237,12 +268,15 @@
}
/** The extra CLI path is a named, byte-bound pilot; it is not a general active import gate. */
- private function validatePilot(string $manifestPath, string $manifestBytes, array $manifest, string $staging, bool $apply, mixed $actorId): void
+ private function validatePilot(string $manifestPath, string $manifestBytes, array $manifest, string $staging, bool $apply, mixed $actorId, bool $sectors = false): void
{
- if ($manifestPath !== realpath($staging.'/legacy-agronegocio/manifest.json')
- || ! hash_equals(self::PILOT_MANIFEST_SHA256, hash('sha256', $manifestBytes))
- || count($manifest['documents']) !== 2) {
- throw new RuntimeException('Only the exact approved agribusiness manifest and its two entries are allowed.');
+ $allowed = $sectors ? self::SECTORS_HASHES : self::PILOT_HASHES;
+ $manifestName = $sectors ? 'legacy-setores-lote20-20261015/manifest.json' : 'legacy-agronegocio/manifest.json';
+ $manifestHash = $sectors ? self::SECTORS_MANIFEST_SHA256 : self::PILOT_MANIFEST_SHA256;
+ if ($manifestPath !== realpath($staging.'/'.$manifestName)
+ || ! hash_equals($manifestHash, hash('sha256', $manifestBytes))
+ || count($manifest['documents']) !== count($allowed)) {
+ throw new RuntimeException('Only the exact selected manifest and its fixed resource list are allowed.');
}
$target = DB::selectOne('SELECT current_database() AS database,inet_server_port() AS port');
$host = config('database.connections.pgsql.host');
@@ -262,7 +296,7 @@
}
foreach ($manifest['documents'] as $record) {
$entry = $this->validateRecord($record, $staging);
- if (! hash_equals(self::PILOT_HASHES[$entry['external_id']] ?? '', $entry['sha256'])) {
+ if (! hash_equals($allowed[$entry['external_id']] ?? '', $entry['sha256'])) {
throw new RuntimeException('Article or image differs from the approved SHA-256.');
}
$existing = DB::table('documents')->where('sha256', $entry['sha256'])->whereNull('deleted_at')->first();