@@ -0,0 +1,27 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
const source = await fs.readFile('scripts/supplier-evaluation-check.mjs', 'utf8');
|
||||
const common = source.slice(source.indexOf('const base ='), source.indexOf('const author ='));
|
||||
await new Function('fs', 'assert', 'return (async()=>{' + common + `
|
||||
const results=[];
|
||||
for(const role of ['admin','procurement','finance','warehouse']) {
|
||||
const viewer=client(); await viewer.enter(role);
|
||||
assert.equal((await viewer.request('/contexto','POST',{area:'procurement',option:'procurement.internal'})).status,302);
|
||||
const response=await viewer.request('/compras/pesquisa?q=TEST');
|
||||
assert.equal(response.status,200);
|
||||
const financial=['admin','finance'].includes(role);
|
||||
assert.equal(response.page.props.invoiceSearchAvailable,financial);
|
||||
assert.equal(response.page.props.groups.length,role==='warehouse'?5:financial?8:7);
|
||||
results.push({role,path:'/compras/pesquisa?q=TEST',status:200,financial_search:financial,sources:response.page.props.groups.map(group=>group.key)});
|
||||
if(role==='admin') {
|
||||
const parameters=await viewer.request('/administracao/parametrizacao');
|
||||
assert.equal(parameters.status,200);
|
||||
assert.equal(parameters.page.props.approvalLevelsReady,true);
|
||||
assert.equal(parameters.page.props.approvalLevels,null);
|
||||
results.push({role,path:'/administracao/parametrizacao',status:200,additional_approval_capability:true,company_plan_created:false});
|
||||
}
|
||||
}
|
||||
await fs.writeFile('docs/proofs/approval-search-pilot-http.json',JSON.stringify({environment:base,result:'passed',results,business_commands:false,session_context_only:true,visual_review:false},null,2));
|
||||
console.log(JSON.stringify({http_checks:results.length,result:'passed',business_commands:false}));
|
||||
`+'})()')(fs,assert);
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
$root = dirname(__DIR__);
|
||||
$proof = json_decode(file_get_contents($root.'/storage/framework/testing/distribution-visual-running.json'), true, 32, JSON_THROW_ON_ERROR);
|
||||
if ($proof['url'] !== 'http://127.0.0.1:8006' || ! preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', $proof['database'])) {
|
||||
throw new LogicException('Only the private disposable QA review may be checked.');
|
||||
}
|
||||
$fonts = glob($root.'/storage/framework/testing/sgc-distribution-integrated-qa-20261122/assets/*.woff*');
|
||||
if (count($fonts) !== 6) {
|
||||
throw new RuntimeException('Expected six local candidate fonts.');
|
||||
}
|
||||
foreach ($fonts as $font) {
|
||||
$url = $proof['url'].'/build/assets/'.rawurlencode(basename($font));
|
||||
$stream = fopen($url, 'rb', false, stream_context_create(['http' => ['timeout' => 3]]));
|
||||
if ($stream === false) {
|
||||
throw new RuntimeException('Unable to read a private candidate font.');
|
||||
}
|
||||
$headers = stream_get_meta_data($stream)['wrapper_data'] ?? [];
|
||||
$body = stream_get_contents($stream);
|
||||
fclose($stream);
|
||||
$woff2 = str_ends_with($font, '.woff2');
|
||||
$type = $woff2 ? 'font/woff2' : 'font/woff';
|
||||
if (! is_string($body) || ! str_starts_with($body, $woff2 ? 'wOF2' : 'wOFF')
|
||||
|| ! in_array('Content-Type: '.$type, $headers, true) || hash('sha256', $body) !== hash_file('sha256', $font)) {
|
||||
throw new RuntimeException('A candidate font is missing, corrupted or served with an invalid MIME type.');
|
||||
}
|
||||
}
|
||||
echo json_encode(['private_font_regression_passed' => true, 'fonts' => count($fonts)], JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
$root = dirname(__DIR__);
|
||||
$proof = json_decode(file_get_contents($root.'/storage/framework/testing/distribution-visual-running.json'), true, 32, JSON_THROW_ON_ERROR);
|
||||
$expected = 'C:/laragon/data/sgf-tempo/qa/distribution-visual-'.$proof['database'];
|
||||
if (! preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', $proof['database']) || str_replace('\\', '/', dirname($proof['stop_file'])) !== $expected) {
|
||||
throw new LogicException('Invalid private visual QA identity.');
|
||||
}
|
||||
$settings = json_decode(file_get_contents($expected.'/settings.json'), true, 32, JSON_THROW_ON_ERROR);
|
||||
if ($settings['DB_DATABASE'] !== $proof['database'] || $settings['APP_ENV'] !== 'testing' || $settings['DB_HOST'] !== '127.0.0.1') {
|
||||
throw new LogicException('Private QA settings do not match the review.');
|
||||
}
|
||||
foreach ($settings as $key => $value) {
|
||||
putenv($key.'='.$value);
|
||||
$_ENV[$key] = $_SERVER[$key] = $value;
|
||||
}
|
||||
require $root.'/vendor/autoload.php';
|
||||
$app = require $root.'/bootstrap/app.php';
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
if (DB::getDriverName() !== 'pgsql' || DB::connection()->getDatabaseName() !== $proof['database']) {
|
||||
throw new LogicException('Review verification database mismatch.');
|
||||
}
|
||||
$request = DB::table('requisitions')->where('id', $proof['synthetic_fixture']['draft'])->first();
|
||||
$plan = json_decode($request->budget_distribution_preparation, true, 32, JSON_THROW_ON_ERROR);
|
||||
if ((int) $request->process_version !== 3 || $request->status !== 'draft' || count($plan['allocations']) !== 2
|
||||
|| array_column($plan['allocations'], 'subtotal_minor') !== [5000, 5000] || array_column($plan['allocations'], 'total_minor') !== [5000, 5000]
|
||||
|| DB::table('budget_distributions')->where('requisition_id', $request->id)->exists()
|
||||
|| DB::table('audit_logs')->where('requisition_id', $request->id)->where('action', 'requisition.allocations_prepared')->count() !== 2) {
|
||||
throw new RuntimeException('Browser correction did not preserve the draft, exact values and absence of financial effects.');
|
||||
}
|
||||
echo json_encode(['native_browser_draft_saved' => true, 'version' => 3, 'failed_attempt_no_effects' => true,
|
||||
'two_explicit_allocations' => true, 'no_reservation_on_prepare' => true], JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
if (in_array('--amended', $argv, true)) {
|
||||
$order = DB::table('purchase_orders')->where('id', $proof['synthetic_fixture']['foreign_order'])->first();
|
||||
$source = DB::table('budget_distributions')->where('requisition_id', $order->requisition_id)->first();
|
||||
$current = json_decode($source->snapshot, true, 32, JSON_THROW_ON_ERROR);
|
||||
$original = json_decode(DB::table('budget_distribution_events')->where('distribution_id', $source->id)->where('kind', 'commit')->value('snapshot'), true, 32, JSON_THROW_ON_ERROR);
|
||||
$document = json_decode($order->snapshot, true, 32, JSON_THROW_ON_ERROR);
|
||||
$values = array_column($current['allocations'], 'total_minor');
|
||||
sort($values);
|
||||
if ($current['amendment_version'] !== 1 || $values !== [4999, 5001] || array_column($original['allocations'], 'total_minor') !== [5000, 5000]
|
||||
|| array_sum(array_column($current['allocations'], 'subtotal_minor')) !== 10000 || $document['budget_control']['plan_hash'] !== $original['plan_hash']
|
||||
|| $document['exchange_basis']['rate'] !== '1.0000000000' || $order->currency !== 'USD' || (int) $order->total_minor !== 10000
|
||||
|| DB::table('budget_distribution_events')->where('distribution_id', $source->id)->count() !== 4
|
||||
|| DB::table('audit_logs')->where('requisition_id', $order->requisition_id)->where('action', 'budget.distribution_amended')->count() !== 1) {
|
||||
throw new RuntimeException('Native browser amendment did not preserve the original document, exact total, version and history.');
|
||||
}
|
||||
if (DB::table('invoices')->count() !== 0 || DB::table('purchase_awards')->where('requisition_id', $proof['synthetic_fixture']['award'])->exists()) {
|
||||
throw new RuntimeException('Read-only invoice/adjudication review unexpectedly registered a business document.');
|
||||
}
|
||||
echo json_encode(['native_browser_finance_amendment' => true, 'version' => 1, 'original_commitment_and_rate_preserved' => true,
|
||||
'one_amendment_and_audit' => true], JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
$app = require dirname(__DIR__).'/bootstrap/app.php';
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
if (in_array('--refresh-running-preview', $argv, true)) {
|
||||
$proof = json_decode(file_get_contents(storage_path('framework/testing/distribution-visual-running.json')), true, 32, JSON_THROW_ON_ERROR);
|
||||
$private = 'C:/laragon/data/sgf-tempo/qa/distribution-visual-'.$proof['database'];
|
||||
if (! preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', $proof['database']) || str_replace('\\', '/', dirname($proof['stop_file'])) !== $private
|
||||
|| ! is_file($private.'/settings.json')) {
|
||||
throw new LogicException('Private review identity mismatch.');
|
||||
}
|
||||
$candidate = storage_path('framework/testing/sgc-distribution-integrated-qa-20261122');
|
||||
$expected = $argv[array_search('--refresh-running-preview', $argv, true) + 1] ?? '';
|
||||
if (! preg_match('/^[a-f0-9]{64}$/D', $expected) || hash_file('sha256', $candidate.'/manifest.json') !== $expected) {
|
||||
throw new LogicException('Explicit validated private manifest hash required.');
|
||||
}
|
||||
$target = $private.'/public/build';
|
||||
$previous = hash_file('sha256', $target.'/manifest.json');
|
||||
copy($target.'/manifest.json', $private.'/manifest-before-'.$previous.'.json');
|
||||
(new Filesystem)->copyDirectory($candidate.'/assets', $target.'/assets');
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($candidate.'/assets', FilesystemIterator::SKIP_DOTS)) as $file) {
|
||||
$relative = substr($file->getPathname(), strlen($candidate.'/assets'));
|
||||
if (hash_file('sha256', $file->getPathname()) !== hash_file('sha256', $target.'/assets'.$relative)) {
|
||||
throw new RuntimeException('Private candidate asset verification failed.');
|
||||
}
|
||||
}
|
||||
copy($candidate.'/fonts-manifest.json', $target.'/fonts-manifest.json');
|
||||
copy($candidate.'/manifest.json', $target.'/manifest.next.json');
|
||||
if (! rename($target.'/manifest.next.json', $target.'/manifest.json')) {
|
||||
throw new RuntimeException('Private manifest replacement failed.');
|
||||
}
|
||||
$proof['private_manifest_sha256'] = $expected;
|
||||
file_put_contents(storage_path('framework/testing/distribution-visual-running.json'), json_encode($proof, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
|
||||
echo json_encode(['private_preview_refreshed' => true, 'previous_manifest' => $previous, 'manifest_sha256' => $expected, 'published_assets_changed' => false], JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
if (! in_array('--prepare-private-review', $argv, true)) {
|
||||
throw new LogicException('Explicit private QA review switch required.');
|
||||
}
|
||||
$socket = @stream_socket_server('tcp://127.0.0.1:8006', $errorCode, $error);
|
||||
if ($socket === false) {
|
||||
throw new RuntimeException('QA port 8006 is already in use; no existing server was altered.');
|
||||
}
|
||||
fclose($socket);
|
||||
$config = DB::connection('pgsql')->getConfig();
|
||||
unset($config['name']);
|
||||
if ($config['host'] !== '127.0.0.1') {
|
||||
throw new LogicException('Only local PostgreSQL QA is supported.');
|
||||
}
|
||||
$database = 'compras_receipts_test_'.bin2hex(random_bytes(6));
|
||||
$private = 'C:/laragon/data/sgf-tempo/qa/distribution-visual-'.$database;
|
||||
if (! mkdir($private.'/public', 0700, true) && ! is_dir($private.'/public')) {
|
||||
throw new RuntimeException('Private review directory creation failed.');
|
||||
}
|
||||
$candidate = storage_path('framework/testing/sgc-distribution-integrated-qa-20261122');
|
||||
if (hash_file('sha256', $candidate.'/manifest.json') !== '1edb9ab0aa62fcf4e9c9075ce6e405de5435dc8ea4799d1949535a96c718df4e') {
|
||||
throw new RuntimeException('The private candidate differs from the validated build.');
|
||||
}
|
||||
(new Filesystem)->copyDirectory($candidate, $private.'/public/build');
|
||||
foreach (['favicon.ico', 'favicon.svg'] as $file) {
|
||||
if (is_file(public_path($file))) {
|
||||
copy(public_path($file), $private.'/public/'.$file);
|
||||
}
|
||||
}
|
||||
$environment = ['APP_ENV' => 'testing', 'APP_DEBUG' => 'false', 'APP_KEY' => config('app.key'), 'APP_NAME' => 'SGC QA sintética',
|
||||
'APP_URL' => 'http://127.0.0.1:8006', 'ASSET_URL' => 'http://127.0.0.1:8006', 'DB_CONNECTION' => 'pgsql', 'DB_URL' => '',
|
||||
'DB_HOST' => $config['host'], 'DB_PORT' => (string) $config['port'], 'DB_DATABASE' => $database, 'DB_USERNAME' => $config['username'], 'DB_PASSWORD' => $config['password'],
|
||||
'CACHE_STORE' => 'array', 'SESSION_DRIVER' => 'file', 'SESSION_COOKIE' => 'sgc_distribution_qa_'.substr($database, -12),
|
||||
'MAIL_MAILER' => 'array', 'QUEUE_CONNECTION' => 'sync', 'BROADCAST_CONNECTION' => 'null', 'BCRYPT_ROUNDS' => '4',
|
||||
'COMMON_BUDGET_PATH' => 'C:/laragon/www/sgf-tempo/packages/budget-control', 'SGC_BUDGET_DISTRIBUTIONS_QA_ENABLED' => 'true',
|
||||
'SGC_DISTRIBUTION_QA_PUBLIC' => $private.'/public'];
|
||||
file_put_contents($private.'/settings.json', json_encode($environment, JSON_THROW_ON_ERROR));
|
||||
config(['database.connections.distribution_visual_admin' => [...$config, 'database' => 'postgres', 'url' => null]]);
|
||||
$admin = DB::connection('distribution_visual_admin');
|
||||
if (! preg_match('/^compras_receipts_test_[a-f0-9]{12}$/D', $database) || $database === $config['database']) {
|
||||
throw new LogicException('Invalid disposable visual database.');
|
||||
}
|
||||
$admin->statement('CREATE DATABASE "'.$database.'"');
|
||||
$server = null;
|
||||
try {
|
||||
foreach ([[PHP_BINARY, 'tests/Concurrency/quotation-exchange-worker.php', $database, 'migrate'],
|
||||
[PHP_BINARY, 'tests/Concurrency/budget-distribution-visual-seed.php', $database]] as $command) {
|
||||
$process = new Process($command, dirname(__DIR__), $environment, timeout: 60);
|
||||
$process->mustRun();
|
||||
$seedOutput = $process->getOutput();
|
||||
}
|
||||
$seed = json_decode(trim($seedOutput), true, 32, JSON_THROW_ON_ERROR);
|
||||
$server = new Process([PHP_BINARY, '-S', '127.0.0.1:8006', '-t', $private.'/public', 'tests/Support/distribution-visual-router.php'],
|
||||
dirname(__DIR__), [...$environment, 'SGC_DISTRIBUTION_QA_SETTINGS_FILE' => $private.'/settings.json'], timeout: null);
|
||||
$server->start();
|
||||
$proof = ['status' => 'private_review_running', 'url' => 'http://127.0.0.1:8006', 'database' => $database,
|
||||
'stop_file' => $private.'/stop', 'synthetic_fixture' => $seed, 'published_assets_changed' => false, 'separate_session_cookie' => true];
|
||||
file_put_contents(storage_path('framework/testing/distribution-visual-running.json'), json_encode($proof, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
|
||||
echo json_encode($proof, JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
$deadline = microtime(true) + 3600;
|
||||
while (! is_file($private.'/stop') && microtime(true) < $deadline) {
|
||||
if (! $server->isRunning()) {
|
||||
throw new RuntimeException('Private QA server stopped unexpectedly.');
|
||||
}
|
||||
$server->getIncrementalOutput();
|
||||
$server->getIncrementalErrorOutput();
|
||||
usleep(100000);
|
||||
}
|
||||
} finally {
|
||||
$server?->stop();
|
||||
$admin->statement('DROP DATABASE "'.$database.'" WITH (FORCE)');
|
||||
if (is_file($private.'/settings.json')) {
|
||||
unlink($private.'/settings.json');
|
||||
}
|
||||
if (isset($proof)) {
|
||||
$proof['status'] = 'private_review_stopped';
|
||||
$proof['isolated_database_removed'] = true;
|
||||
$proof['private_settings_removed'] = true;
|
||||
file_put_contents(storage_path('framework/testing/distribution-visual-running.json'), json_encode($proof, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
|
||||
}
|
||||
echo json_encode(['private_server_stopped' => true, 'isolated_database_removed' => true, 'private_settings_removed' => true], JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
$root = dirname(__DIR__);
|
||||
$proof = $root.'/docs/proofs/approval-search-pilot-installation.json';
|
||||
$settingsFile = 'C:/laragon/data/sgf-tempo/secrets/payables-demo-compras.json';
|
||||
$authorization = json_decode(file_get_contents($root.'/docs/proofs/approval-search-pilot-authorization.json'), true, 32, JSON_THROW_ON_ERROR);
|
||||
$proposal = json_decode(file_get_contents($root.'/docs/proofs/approval-search-pilot-proposal.json'), true, 32, JSON_THROW_ON_ERROR);
|
||||
if (! in_array('--apply-authorized', $argv, true) || $authorization['status'] !== 'approved'
|
||||
|| $authorization['environment'] !== 'http://127.0.0.1:8005' || $authorization['proposal'] !== 'approval-search-pilot-proposal.json'
|
||||
|| file_exists($proof)) {
|
||||
throw new LogicException('Explicit authorization required; never repeat a recorded installation.');
|
||||
}
|
||||
$migration = 'database/migrations/2026_11_22_000003_add_configured_requisition_levels.php';
|
||||
if ($proposal['migration']['file'] !== $migration || hash_file('sha256', $root.'/'.$migration) !== $authorization['migration_sha256']
|
||||
|| $proposal['migration']['sha256'] !== $authorization['migration_sha256']
|
||||
|| hash_file('sha256', $root.'/public/build/manifest.json') !== $authorization['manifest_sha256']) {
|
||||
throw new LogicException('Reviewed migration or installed assets changed.');
|
||||
}
|
||||
$candidate = $root.'/storage/framework/testing/sgc-product-review-candidate-20261122';
|
||||
$manifest = json_decode(file_get_contents($root.'/public/build/manifest.json'), true, 512, JSON_THROW_ON_ERROR);
|
||||
$assets = [];
|
||||
foreach ($manifest as $entry) {
|
||||
foreach ([$entry['file'], ...($entry['css'] ?? []), ...($entry['assets'] ?? [])] as $file) {
|
||||
if (! str_starts_with($file, 'assets/') || str_contains($file, '..')
|
||||
|| hash_file('sha256', $candidate.'/'.$file) !== hash_file('sha256', $root.'/public/build/'.$file)) {
|
||||
throw new LogicException('Installed asset differs from the verified candidate.');
|
||||
}
|
||||
$assets[$file] = true;
|
||||
}
|
||||
}
|
||||
$settingsBytes = file_get_contents($settingsFile);
|
||||
$settingsHash = hash('sha256', $settingsBytes);
|
||||
$s = json_decode($settingsBytes, true, 32, JSON_THROW_ON_ERROR);
|
||||
if (($s['APP_ENV'] ?? '') !== 'payable-testing' || ($s['DB_HOST'] ?? '') !== '127.0.0.1' || realpath($s['HOST_ROOT'] ?? '') !== realpath($root)
|
||||
|| ! preg_match('/^compras_receipts_test_([a-f0-9]{12})$/D', $s['DB_DATABASE'] ?? '', $match) || $s['DB_USERNAME'] !== 'payable_qa_'.$match[1]) {
|
||||
throw new LogicException('Named pilot identity not confirmed.');
|
||||
}
|
||||
$flagNames = ['SGC_REQUISITION_APPROVAL_LEVELS_ENABLED', 'SGC_PROCUREMENT_FINANCE_SEARCH_ENABLED'];
|
||||
foreach ($flagNames as $flag) {
|
||||
if (filter_var($s[$flag] ?? false, FILTER_VALIDATE_BOOLEAN) || ($proposal['private_deployment_settings'][$flag] ?? null) !== true) {
|
||||
throw new LogicException('Unexpected capability state; inspect without reapplying.');
|
||||
}
|
||||
}
|
||||
$app = require $root.'/bootstrap/app.php';
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
$owner = DB::connection('pgsql')->getConfig();
|
||||
unset($owner['name']);
|
||||
if ($owner['host'] !== '127.0.0.1') {
|
||||
throw new LogicException('Administrative server must be local.');
|
||||
}
|
||||
$qa = [...$owner, 'url' => null, 'host' => $s['DB_HOST'], 'database' => $s['DB_DATABASE'], 'username' => $s['DB_USERNAME'], 'password' => $s['DB_PASSWORD']];
|
||||
config(['database.connections.approval_install' => $qa, 'database.connections.approval_owner' => [...$owner, 'database' => 'postgres', 'url' => null]]);
|
||||
DB::setDefaultConnection('approval_install');
|
||||
$db = DB::connection();
|
||||
$admin = DB::connection('approval_owner');
|
||||
$identity = $db->selectOne('select current_database() as db, current_user as role');
|
||||
if ($identity->db !== $s['DB_DATABASE'] || $identity->role !== $s['DB_USERNAME']) {
|
||||
throw new LogicException('Effective database identity mismatch.');
|
||||
}
|
||||
$schema = $db->getSchemaBuilder();
|
||||
if ($schema->hasColumn('tenants', 'requisition_approval_policy') || $schema->hasColumn('approval_steps', 'routing')) {
|
||||
throw new LogicException('Schema already present; do not reapply.');
|
||||
}
|
||||
$tables = array_column($db->select("select tablename from pg_tables where schemaname='public' order by tablename"), 'tablename');
|
||||
$columns = $keys = [];
|
||||
foreach ($tables as $table) {
|
||||
$columns[$table] = $schema->getColumnListing($table);
|
||||
$keys[$table] = $schema->getForeignKeys($table);
|
||||
}
|
||||
$fingerprint = static function ($connection) use ($columns): array {
|
||||
$out = [];
|
||||
foreach ($columns as $table => $names) {
|
||||
$selected = implode(',', array_map(fn ($name) => '"'.str_replace('"', '""', $name).'"', $names));
|
||||
$rows = $connection->select('select row_to_json(t)::text as row from (select '.$selected.' from "'.$table.'") t order by row_to_json(t)::text');
|
||||
$out[$table] = hash('sha256', json_encode(array_column($rows, 'row'), JSON_THROW_ON_ERROR));
|
||||
}
|
||||
|
||||
return $out;
|
||||
};
|
||||
$pg = static function ($binary, array $args, array $connection): void {
|
||||
$process = new Process(['C:/Program Files/PostgreSQL/17/bin/'.$binary.'.exe', ...$args], null, ['PGHOST' => $connection['host'],
|
||||
'PGPORT' => (string) $connection['port'], 'PGUSER' => $connection['username'], 'PGPASSWORD' => $connection['password']], timeout: 120);
|
||||
$process->run();
|
||||
if (! $process->isSuccessful()) {
|
||||
throw new RuntimeException('Backup/restore failed; do not install.');
|
||||
}
|
||||
};
|
||||
$directory = 'C:/laragon/data/sgf-tempo/backups/compras-approval-search-'.gmdate('Ymd-His').'-'.bin2hex(random_bytes(3));
|
||||
if (! mkdir($directory, 0700, true) || file_put_contents($directory.'/settings.before.json', $settingsBytes) !== strlen($settingsBytes)
|
||||
|| ! copy($root.'/public/build/manifest.json', $directory.'/manifest.before.json')) {
|
||||
throw new RuntimeException('Could not preserve deployment state.');
|
||||
}
|
||||
$dump = $directory.'/before.dump';
|
||||
$restore = 'compras_pilot_restore_'.bin2hex(random_bytes(6));
|
||||
$created = false;
|
||||
$migrateAndCheck = static function ($connection, string $name, array $baseline, int $migrationCount) use ($migration, $fingerprint, $keys): void {
|
||||
$previous = DB::getDefaultConnection();
|
||||
DB::setDefaultConnection($name);
|
||||
try {
|
||||
if (Artisan::call('migrate', ['--database' => $name, '--path' => [$migration], '--force' => true]) !== 0) {
|
||||
throw new RuntimeException('Exact migration failed.');
|
||||
}
|
||||
$after = $fingerprint($connection);
|
||||
unset($after['migrations'], $baseline['migrations']);
|
||||
if ($after !== $baseline || $connection->table('migrations')->count() !== $migrationCount + 1
|
||||
|| $connection->table('tenants')->whereNotNull('requisition_approval_policy')->exists()
|
||||
|| $connection->table('approval_steps')->whereNotNull('routing')->exists()) {
|
||||
throw new LogicException('Old data changed or new columns are not empty.');
|
||||
}
|
||||
foreach ($keys as $table => $expected) {
|
||||
if ($connection->getSchemaBuilder()->getForeignKeys($table) !== $expected) {
|
||||
throw new LogicException('Foreign keys changed.');
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
DB::setDefaultConnection($previous);
|
||||
}
|
||||
};
|
||||
try {
|
||||
$db->beginTransaction();
|
||||
$db->statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
|
||||
$baseline = $fingerprint($db);
|
||||
$migrationCount = $db->table('migrations')->count();
|
||||
$snapshot = $db->selectOne('select pg_export_snapshot() as snapshot')->snapshot;
|
||||
$pg('pg_dump', ['--format=custom', '--snapshot='.$snapshot, '--file='.$dump, '--dbname='.$qa['database']], $qa);
|
||||
$db->commit();
|
||||
$admin->statement('CREATE DATABASE "'.$restore.'" OWNER "'.$s['DB_USERNAME'].'"');
|
||||
$created = true;
|
||||
$pg('pg_restore', ['--no-owner', '--no-privileges', '--exit-on-error', '--dbname='.$restore, $dump], $qa);
|
||||
config(['database.connections.approval_restore' => [...$qa, 'database' => $restore]]);
|
||||
$restored = DB::connection('approval_restore');
|
||||
if ($fingerprint($restored) !== $baseline) {
|
||||
throw new LogicException('Same-role restore differs from backup snapshot.');
|
||||
}
|
||||
$migrateAndCheck($restored, 'approval_restore', $baseline, $migrationCount);
|
||||
$db->transaction(function () use ($db, $tables, $baseline, $fingerprint, $migrateAndCheck, $migrationCount, $settingsHash, $settingsFile) {
|
||||
$db->statement("SET LOCAL lock_timeout = '5s'");
|
||||
foreach ($tables as $table) {
|
||||
$db->statement('LOCK TABLE "'.$table.'" IN SHARE MODE');
|
||||
}
|
||||
if ($fingerprint($db) !== $baseline || hash_file('sha256', $settingsFile) !== $settingsHash) {
|
||||
throw new LogicException('Pilot changed after backup; installation refused.');
|
||||
}
|
||||
$migrateAndCheck($db, 'approval_install', $baseline, $migrationCount);
|
||||
});
|
||||
$result = ['environment' => 'http://127.0.0.1:8005', 'schema_installed' => true, 'capabilities_enabled' => false,
|
||||
'backup' => $dump, 'backup_sha256' => hash_file('sha256', $dump), 'settings_backup' => $directory.'/settings.before.json',
|
||||
'restored_tables_checked' => count($tables), 'previous_business_tables_preserved' => count($tables) - 1,
|
||||
'same_restore_role' => true, 'foreign_keys_preserved' => true, 'new_values_null' => true, 'migration_delta' => 1,
|
||||
'assets_verified' => count($assets), 'manifest_sha256' => $authorization['manifest_sha256'], 'business_commands' => false, 'grants_changed' => false];
|
||||
file_put_contents($proof, json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).PHP_EOL);
|
||||
if (hash_file('sha256', $settingsFile) !== $settingsHash) {
|
||||
throw new LogicException('Settings changed before activation; schema retained, capabilities not enabled.');
|
||||
}
|
||||
$after = [...$s, $flagNames[0] => 'true', $flagNames[1] => 'true'];
|
||||
$protected = $after;
|
||||
foreach ($flagNames as $flag) {
|
||||
unset($protected[$flag]);
|
||||
}
|
||||
$beforeProtected = $s;
|
||||
foreach ($flagNames as $flag) {
|
||||
unset($beforeProtected[$flag]);
|
||||
}
|
||||
if ($protected !== $beforeProtected) {
|
||||
throw new LogicException('Unrelated deployment settings changed.');
|
||||
}
|
||||
$temporary = $settingsFile.'.approval-search.tmp';
|
||||
$bytes = json_encode($after, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
if (file_put_contents($temporary, $bytes) !== strlen($bytes) || ! rename($temporary, $settingsFile)) {
|
||||
throw new RuntimeException('Could not atomically activate approved capabilities.');
|
||||
}
|
||||
$result['capabilities_enabled'] = json_decode(file_get_contents($settingsFile), true, 32, JSON_THROW_ON_ERROR) === $after;
|
||||
$result['other_settings_preserved'] = true;
|
||||
$result['changed_settings'] = $flagNames;
|
||||
} finally {
|
||||
if ($db->transactionLevel() > 0) {
|
||||
$db->rollBack();
|
||||
}
|
||||
DB::purge('approval_restore');
|
||||
if ($created) {
|
||||
$admin->statement('DROP DATABASE "'.$restore.'" WITH (FORCE)');
|
||||
}
|
||||
}
|
||||
$result['restore_database_removed'] = true;
|
||||
file_put_contents($proof, json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).PHP_EOL);
|
||||
echo json_encode($result, JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
@@ -0,0 +1,22 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
const source = await fs.readFile('scripts/supplier-evaluation-check.mjs', 'utf8');
|
||||
const common = source.slice(source.indexOf('const base ='), source.indexOf('const author ='));
|
||||
await new Function('fs', 'assert', 'return (async()=>{' + common + `
|
||||
const results=[];
|
||||
for(const role of ['admin','procurement','finance']) {
|
||||
const viewer=client(); await viewer.enter(role);
|
||||
assert.equal((await viewer.request('/contexto','POST',{area:'procurement',option:'procurement.internal'})).status,302);
|
||||
const response=await viewer.request('/relatorios');
|
||||
assert.equal(response.status,200);
|
||||
const available=['admin','finance'].includes(role) && response.page.props.payablesAvailable===true;
|
||||
assert.equal(response.page.props.payableInsights!==null,available);
|
||||
const csv=await viewer.request('/relatorios/obrigacoes.csv','GET',undefined,false);
|
||||
assert.equal(csv.status,available?200:403);
|
||||
if(available) assert.ok(csv.text.includes('Principal (centavos)'));
|
||||
results.push({role,report_status:response.status,native_positions_available:available,csv_status:csv.status});
|
||||
}
|
||||
await fs.writeFile('docs/proofs/payable-insights-pilot-http.json',JSON.stringify({environment:base,result:'passed',results,business_commands:false,session_context_only:true,visual_review:false},null,2));
|
||||
console.log(JSON.stringify({http_checks:results.length*2,result:'passed',business_commands:false}));
|
||||
`+'})()')(fs,assert);
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
// Frozen private QA export of the authorised canonical source; never updates installed packages.
|
||||
$root = dirname(__DIR__);
|
||||
$source = realpath('C:/laragon/www/sgf-tempo/packages/budget-control');
|
||||
if ($source === false || str_replace('\\', '/', $source) !== 'C:/laragon/www/sgf-tempo/packages/budget-control') {
|
||||
throw new LogicException('Canonical common source mismatch.');
|
||||
}
|
||||
$files = ['bootstrap.php', 'src/BudgetContext.php', 'src/BudgetFailure.php', 'src/BudgetControl.php', 'src/BudgetDistributionPlan.php', 'src/BudgetDistributions.php', 'README.md'];
|
||||
$hashes = [];
|
||||
foreach ($files as $file) {
|
||||
$hashes[$file] = hash_file('sha256', $source.'/'.$file);
|
||||
}
|
||||
$fingerprint = hash('sha256', json_encode($hashes, JSON_THROW_ON_ERROR));
|
||||
$relative = 'storage/framework/testing/budget-distribution-qa-'.substr($fingerprint, 0, 16);
|
||||
$target = $root.'/'.$relative;
|
||||
if (! is_dir($target.'/src') && ! mkdir($target.'/src', 0700, true)) {
|
||||
throw new RuntimeException('Unable to create the private artifact directory.');
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
if (is_file($target.'/'.$file) && hash_file('sha256', $target.'/'.$file) !== $hashes[$file]) {
|
||||
throw new RuntimeException('An existing frozen artifact differs; it was not overwritten.');
|
||||
}
|
||||
if (! is_file($target.'/'.$file)) {
|
||||
copy($source.'/'.$file, $target.'/'.$file);
|
||||
}
|
||||
if (hash_file('sha256', $target.'/'.$file) !== $hashes[$file]) {
|
||||
throw new RuntimeException('Artifact byte verification failed.');
|
||||
}
|
||||
}
|
||||
$archive = $target.'.zip';
|
||||
if (! is_file($archive)) {
|
||||
if (! class_exists(ZipArchive::class)) {
|
||||
throw new RuntimeException('Native ZipArchive is unavailable; verified directory preserved.');
|
||||
}
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open($archive, ZipArchive::CREATE | ZipArchive::EXCL) !== true) {
|
||||
throw new RuntimeException('Unable to create the private artifact ZIP.');
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
$zip->addFile($target.'/'.$file, $file);
|
||||
}
|
||||
$zip->close();
|
||||
}
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open($archive) !== true || $zip->numFiles !== count($files)) {
|
||||
throw new RuntimeException('Private ZIP inventory mismatch.');
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
if (hash('sha256', $zip->getFromName($file)) !== $hashes[$file]) {
|
||||
throw new RuntimeException('Private ZIP differs from the canonical source.');
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
$proof = ['date' => '2026-11-22', 'status' => 'private_qa_artifact_prepared_not_published', 'path' => $relative,
|
||||
'archive' => $relative.'.zip', 'archive_sha256' => hash_file('sha256', $archive), 'canonical_fingerprint' => $fingerprint, 'files' => $hashes,
|
||||
'host_schema' => 'database/qa-migrations/2026_11_22_000004_create_budget_distributions.php',
|
||||
'host_schema_sha256' => hash_file('sha256', $root.'/database/qa-migrations/2026_11_22_000004_create_budget_distributions.php'),
|
||||
'installed_financial_packages_changed' => false, 'pilot_or_sgf_activation' => false];
|
||||
file_put_contents($root.'/docs/proofs/rq01-distribution-artifact.json', json_encode($proof, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR).PHP_EOL);
|
||||
echo json_encode(['private_artifact_prepared' => true, 'files' => count($files), 'archive_sha256' => $proof['archive_sha256'], 'path' => $relative], JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
@@ -0,0 +1,51 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { createHash } from 'node:crypto';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
assert.ok(process.argv.includes('--apply-qa-preview'), 'Explicit QA preview switch required.');
|
||||
const root = await fs.realpath(process.cwd());
|
||||
const settings = JSON.parse(await fs.readFile('C:/laragon/data/sgf-tempo/secrets/payables-demo-compras.json', 'utf8'));
|
||||
assert.equal(settings.APP_ENV, 'payable-testing');
|
||||
assert.equal(settings.DB_HOST, '127.0.0.1');
|
||||
assert.equal(await fs.realpath(settings.HOST_ROOT), root);
|
||||
const authorization = JSON.parse(await fs.readFile('docs/proofs/rq01-source-authorization.json', 'utf8'));
|
||||
assert.equal(authorization.owner_decision, 'autorizo as melhorias propostas');
|
||||
const sha = async file => createHash('sha256').update(await fs.readFile(file)).digest('hex');
|
||||
const definitions = {
|
||||
'--product-review': ['ee6e7404da9960181980c10b68b3c84c92d3667c163355442036b3fc0f53ab93', 'sgc-product-review-candidate-20261122', 'product-review', 'QA product presentation and order compatibility correction'],
|
||||
'--history-review': ['9bbca2dc15b40c05f268b118e4f16178a3120ae19329fdbe19403178e22cf251', 'sgc-history-candidate-20261122', 'history-review', 'Requisition preparation in native encrypted browser history'],
|
||||
'--financial-review': ['4b4801f658ef0cbbc3f83311afbb610add0c7985916ba25c21af2a8b77cf683f', 'sgc-payable-insights-candidate-20261122', 'financial-review', 'Read-only native payable positions and CSV for existing financial viewers'],
|
||||
'--history-clean-review': ['aad78d2d79f03e3d95ca880875e331973bb2f2702288945852a818837a259057', 'sgc-history-clean-candidate-20261122', 'history-clean-review', 'Correct false dirty state caused by restored technical identities; preserve protection of edited preparation'],
|
||||
};
|
||||
const selected = Object.keys(definitions).filter(flag => process.argv.includes(flag));
|
||||
assert.ok(selected.length <= 1, 'Select exactly one reviewed delta.');
|
||||
const [previous, directory, label, scope] = selected.length ? definitions[selected[0]] : ['c2203372527050e083f6cc0aab47a1e08534015d692b3a8781a26ddf65109c23', 'rq01-production-candidate-20261122', 'rq01-production', 'QA presentation of approved production destination increment'];
|
||||
const proofNames = { 'product-review': 'product-review', 'history-review': 'requisition-history', 'financial-review': 'payable-insights', 'history-clean-review': 'requisition-history-clean', 'rq01-production': 'production-destination' };
|
||||
const currentManifest = path.join(root, 'public/build/manifest.json');
|
||||
assert.equal(await sha(currentManifest), previous, 'Preview target changed; review before updating.');
|
||||
const candidate = path.join(root, 'storage/framework/testing', directory);
|
||||
const manifest = JSON.parse(await fs.readFile(path.join(candidate, 'manifest.json'), 'utf8'));
|
||||
const files = new Map();
|
||||
for (const entry of Object.values(manifest)) {
|
||||
for (const file of [entry.file, ...(entry.css ?? []), ...(entry.assets ?? [])]) {
|
||||
assert.ok(file.startsWith('assets/') && !file.includes('..') && !path.isAbsolute(file));
|
||||
files.set(file, await sha(path.join(candidate, file)));
|
||||
}
|
||||
}
|
||||
const backup = path.join(root, `storage/framework/testing/manifest-before-${label}-20261122.json`);
|
||||
await fs.copyFile(currentManifest, backup, fs.constants.COPYFILE_EXCL);
|
||||
for (const [file, expected] of files) {
|
||||
const target = path.join(root, 'public/build', file);
|
||||
await fs.mkdir(path.dirname(target), { recursive: true });
|
||||
try { await fs.copyFile(path.join(candidate, file), target, fs.constants.COPYFILE_EXCL); }
|
||||
catch (error) { if (error.code !== 'EEXIST') throw error; }
|
||||
assert.equal(await sha(target), expected, 'Never replace an existing divergent chunk.');
|
||||
}
|
||||
assert.equal(await sha(currentManifest), previous);
|
||||
const temporary = path.join(root, 'public/build/manifest.rq01-preview.tmp');
|
||||
await fs.copyFile(path.join(candidate, 'manifest.json'), temporary);
|
||||
await fs.rename(temporary, currentManifest);
|
||||
const proof = { environment: 'http://127.0.0.1:8005', scope, authorization: 'rq01-source-authorization.json', assets_verified: files.size, previous_manifest_sha256: previous, manifest_sha256: await sha(currentManifest), previous_manifest_backup: backup, schemas_changed: false, business_commands: false, capability_settings_changed: false, visual_review: false };
|
||||
await fs.writeFile(`docs/proofs/${proofNames[label]}-preview.json`, JSON.stringify(proof, null, 2) + '\n');
|
||||
console.log(JSON.stringify({ result: 'passed', assets_verified: files.size, manifest_sha256: proof.manifest_sha256, business_commands: false }));
|
||||
@@ -44,6 +44,41 @@ try {
|
||||
$draftMode = in_array('--draft-preparation-only', $argv, true);
|
||||
$searchMode = in_array('--procurement-search-only', $argv, true);
|
||||
$productionMode = in_array('--warehouse-production-only', $argv, true);
|
||||
$configuredLevelsMode = in_array('--configured-approval-levels-only', $argv, true);
|
||||
$orderDocumentMode = in_array('--order-document-only', $argv, true);
|
||||
$payableInsightsMode = in_array('--payable-insights-only', $argv, true);
|
||||
$budgetDistributionMode = in_array('--budget-distribution-only', $argv, true);
|
||||
if ($budgetDistributionMode) {
|
||||
$environment['COMMON_BUDGET_PATH'] = 'C:/laragon/www/sgf-tempo/packages/budget-control';
|
||||
$commands = [[PHP_BINARY, 'vendor/bin/pest', '--compact', 'tests/Feature/BudgetDistributionContractTest.php', 'tests/Feature/BudgetTest.php', 'tests/Feature/BudgetReinforcementTest.php', 'tests/Feature/InvoiceTest.php']];
|
||||
if (in_array('--award-focused', $argv, true)) {
|
||||
$commands = [[PHP_BINARY, 'vendor/bin/pest', '--compact', 'tests/Feature/PurchaseAwardOrderTest.php', '--filter=distributed approved synthetic|foreign award approves|foreign order cancellation|changed prices or matrix|repeated issuance|fractional quantities and VAT']];
|
||||
}
|
||||
if (in_array('--distribution-concurrency', $argv, true)) {
|
||||
$commands = [[PHP_BINARY, 'tests/Concurrency/quotation-exchange-worker.php', $database, 'migrate'],
|
||||
[PHP_BINARY, 'tests/Concurrency/budget-distribution-worker.php', $database, 'race']];
|
||||
}
|
||||
if (in_array('--distribution-recovery', $argv, true)) {
|
||||
$commands = [[PHP_BINARY, 'tests/Concurrency/quotation-exchange-worker.php', $database, 'migrate'],
|
||||
[PHP_BINARY, 'tests/Concurrency/budget-distribution-recovery-worker.php', $database]];
|
||||
}
|
||||
if (in_array('--distribution-visual-seed-check', $argv, true)) {
|
||||
$commands = [[PHP_BINARY, 'tests/Concurrency/quotation-exchange-worker.php', $database, 'migrate'],
|
||||
[PHP_BINARY, 'tests/Concurrency/budget-distribution-visual-seed.php', $database]];
|
||||
}
|
||||
if (in_array('--distribution-schema', $argv, true)) {
|
||||
$commands = [[PHP_BINARY, 'vendor/bin/pest', '--compact', 'tests/Feature/BudgetDistributionSchemaTest.php', 'tests/Feature/BudgetDistributionContractTest.php']];
|
||||
}
|
||||
}
|
||||
if ($payableInsightsMode) {
|
||||
$commands = [[PHP_BINARY, 'vendor/bin/pest', '--compact', 'tests/Feature/ProcurementPayableInsightsTest.php', ...(in_array('--focused', $argv, true) ? [] : ['tests/Feature/SupplierPayableIntegrationTest.php', 'tests/Feature/ProcurementReportsTest.php'])]];
|
||||
}
|
||||
if ($orderDocumentMode) {
|
||||
$commands = [[PHP_BINARY, 'vendor/bin/pest', '--compact', 'tests/Feature/PurchaseDocumentCompatibilityTest.php', 'tests/Feature/PurchaseAwardOrderTest.php', '--filter=older synthetic|print|issuance|discount evidence']];
|
||||
}
|
||||
if ($configuredLevelsMode) {
|
||||
$commands = [[PHP_BINARY, 'vendor/bin/pest', '--compact', 'tests/Feature/RequisitionApprovalLevelsTest.php', 'tests/Feature/InternalRequisitionCandidateTest.php', 'tests/Feature/OrganizationConfigurationTest.php', 'tests/Feature/WorkflowTaskInboxTest.php', 'tests/Feature/PurchaseProcessTest.php']];
|
||||
}
|
||||
if ($productionMode) {
|
||||
$commands = [[PHP_BINARY, 'vendor/bin/pest', '--compact', 'tests/Feature/WarehouseRequestsTest.php', 'tests/Feature/WarehouseFulfilmentTest.php', 'tests/Feature/AutomaticPurchasesTest.php']];
|
||||
}
|
||||
@@ -83,7 +118,7 @@ try {
|
||||
throw new RuntimeException('Validação PostgreSQL não aprovada.');
|
||||
}
|
||||
}
|
||||
if ($conversionMode || $agreementMode || $orderLimitMode || $upgradeMode || $benchmarkMode || $draftMode || $searchMode || $productionMode) {
|
||||
if ($conversionMode || $agreementMode || $orderLimitMode || $upgradeMode || $benchmarkMode || $draftMode || $searchMode || $productionMode || $configuredLevelsMode || $orderDocumentMode || $payableInsightsMode || $budgetDistributionMode) {
|
||||
return;
|
||||
}
|
||||
config(['database.connections.quotation_fx_proof' => [...$config, 'database' => $database, 'url' => null]]);
|
||||
|
||||
Reference in New Issue
Block a user