@@ -8,6 +8,13 @@ import { createServer } from 'node:net';
|
||||
|
||||
const id = crypto.randomBytes(6).toString('hex');
|
||||
const workspace = path.resolve('C:/laragon/www/compras');
|
||||
const standaloneOnly = process.argv.includes('--standalone-runtime-only');
|
||||
const standaloneBusiness = process.argv.includes('--standalone-business-only');
|
||||
if (standaloneOnly && process.argv.slice(2).some(flag => flag !== '--standalone-runtime-only')) throw Error('Standalone composition requires its own isolated invocation');
|
||||
if (standaloneBusiness && process.argv.slice(2).some(flag => flag !== '--standalone-business-only')) throw Error('Standalone business regression requires its own isolated invocation');
|
||||
const standaloneRoot = path.join(workspace, 'storage/framework/testing/compras-standalone-3320fac5a70fe44e');
|
||||
const standalonePin = '3320fac5a70fe44ed54e11af90385b5da6b204ef854984cd934882a4378211e1';
|
||||
const standaloneArchivePin = 'a544d5930feb916c4d4941ed8ef0b453985c1629720e9d0224bdbf0d322fb536';
|
||||
const reviewDurationArgs = process.argv.filter(flag => flag.startsWith('--review-minutes='));
|
||||
const reviewDurationMinutes = reviewDurationArgs.length === 0 ? 20 : Number(reviewDurationArgs[0].slice('--review-minutes='.length));
|
||||
if (reviewDurationArgs.length > 1 || !Number.isInteger(reviewDurationMinutes) || reviewDurationMinutes < 1 || reviewDurationMinutes > 60 || (reviewDurationArgs.length > 0 && !process.argv.includes('--native-review'))) throw Error('Native review duration must be one explicit value from1to60minutes');
|
||||
@@ -78,8 +85,8 @@ const root = path.join(privateParent, `rq01-ledger-qa-${id}`);
|
||||
const cluster = path.join(root, 'postgres');
|
||||
if (path.dirname(root) !== privateParent || !/^rq01-ledger-qa-[a-f0-9]{12}$/.test(path.basename(root))) throw Error('Private QA root refused');
|
||||
fs.mkdirSync(root);
|
||||
const database = `compras_receipts_test_${id}`;
|
||||
const role = `payable_history_native_${id}`;
|
||||
const database = standaloneOnly ? `compras_standalone_qa_${id}` : `compras_receipts_test_${id}`;
|
||||
const role = standaloneOnly ? `compras_standalone_app_${id}` : `payable_history_native_${id}`;
|
||||
const password = crypto.randomBytes(30).toString('hex');
|
||||
const adminPassword = crypto.randomBytes(30).toString('hex');
|
||||
const passwordFile = path.join(root, 'admin-password.txt');
|
||||
@@ -119,10 +126,21 @@ try {
|
||||
sql(`CREATE DATABASE ${database} OWNER ${role};`);
|
||||
createdDatabase = true;
|
||||
sql(`REVOKE ALL ON DATABASE ${database} FROM PUBLIC;`);
|
||||
let activeStandaloneRoot = standaloneRoot;
|
||||
if (standaloneOnly) {
|
||||
const archive = standaloneRoot+'.zip';
|
||||
if (fs.lstatSync(archive).isSymbolicLink() || crypto.createHash('sha256').update(fs.readFileSync(archive)).digest('hex') !== standaloneArchivePin) throw Error('Pinned standalone archive mismatch');
|
||||
activeStandaloneRoot = path.join(root, 'runtime');
|
||||
fs.mkdirSync(activeStandaloneRoot);
|
||||
const code = '$z=new ZipArchive; if($z->open($argv[1])!==true||$z->numFiles!==67||!$z->extractTo($argv[2]))throw new LogicException("Owned candidate extraction failed");$z->close();echo "extracted";';
|
||||
const extracted = spawnSync('php', ['-r', code, archive, activeStandaloneRoot], { windowsHide: true, encoding: 'utf8' });
|
||||
if (extracted.status !== 0 || extracted.stdout !== 'extracted') throw Error('Owned standalone extraction failed');
|
||||
verifyPrivateRuntime(activeStandaloneRoot, standalonePin, 66);
|
||||
}
|
||||
const environment = { ...process.env, APP_ENV: 'testing', APP_DEBUG: 'false', APP_KEY: 'base64:'+crypto.randomBytes(32).toString('base64'), DB_CONNECTION: 'pgsql', DB_URL: '', DB_HOST: '127.0.0.1', DB_PORT: '55439',
|
||||
DB_DATABASE: database, DB_USERNAME: role, DB_PASSWORD: password, CACHE_STORE: 'array', SESSION_DRIVER: 'array',
|
||||
MAIL_MAILER: 'array', QUEUE_CONNECTION: 'sync', BROADCAST_CONNECTION: 'null',
|
||||
COMMON_BUDGET_PATH: frozenRuntime ? path.join(budgetRoot, 'budget-control') : 'C:/laragon/www/sgf-tempo/packages/budget-control',
|
||||
COMMON_BUDGET_PATH: standaloneOnly || standaloneBusiness ? path.join(activeStandaloneRoot, 'budget-control') : frozenRuntime ? path.join(budgetRoot, 'budget-control') : 'C:/laragon/www/sgf-tempo/packages/budget-control',
|
||||
RQ01_LEDGER_QA_SOURCE: frozenRuntime ? path.join(financeRoot, 'general-ledger') : 'C:/laragon/www/sgf-tempo/packages/general-ledger',
|
||||
RQ01_LEDGER_INTEGRATED_SCHEMA: process.argv.includes('--integrated-schema') ? '1' : '0',
|
||||
RQ01_NATIVE_OFFICE_JOURNEY: process.argv.some(flag => ['--native-office-http-only', '--native-office-preview'].includes(flag)) ? '1' : '0',
|
||||
@@ -140,6 +158,15 @@ try {
|
||||
RQ01_QA_PRINT_PAGINATION: process.argv.includes('--print-pagination-preview') ? '1' : '0' };
|
||||
delete environment.COMMON_FINANCE_BUNDLE_ROOT;
|
||||
delete environment.COMMON_FINANCE_BUNDLE_SHA256;
|
||||
if (standaloneOnly || standaloneBusiness) {
|
||||
environment.COMPRAS_RUNTIME_ENABLED = 'false';
|
||||
environment.COMMON_PAYABLES_PATH = path.join(activeStandaloneRoot, 'payables');
|
||||
environment.COMMON_PURCHASING_PATH = path.join(activeStandaloneRoot, 'purchasing');
|
||||
environment.COMPRAS_RUNTIME_ROOT = activeStandaloneRoot;
|
||||
environment.COMPRAS_RUNTIME_SHA256 = standalonePin;
|
||||
environment.COMPRAS_RUNTIME_INSTALLATION_ID = crypto.randomUUID();
|
||||
environment.COMPRAS_STANDALONE_BUSINESS_QA = standaloneBusiness ? '1' : '0';
|
||||
}
|
||||
if (frozenRuntime) {
|
||||
environment.COMMON_FINANCE_BUNDLE_ROOT = financeRoot;
|
||||
environment.COMMON_FINANCE_BUNDLE_SHA256 = financePin;
|
||||
@@ -153,7 +180,7 @@ try {
|
||||
const nativeOfficePreview = process.argv.includes('--native-office-preview');
|
||||
const nativeOfficeOnly = process.argv.includes('--native-office-http-only') || nativeOfficePreview;
|
||||
const nativeReview = process.argv.includes('--native-review') || nativeFixtureOnly || nativeHttpOnly || nativeOfficeOnly || nativeAuditSchemaOnly;
|
||||
const setupOnly = raceOnly || recoveryOnly || nativeReview;
|
||||
const setupOnly = standaloneOnly || raceOnly || recoveryOnly || nativeReview;
|
||||
const args = setupOnly ? ['artisan', 'migrate', '--force', '--no-interaction'] : process.argv.includes('--integrated-release-journeys') ? ['vendor/bin/pest', '--compact', 'tests/Feature/RequisitionLedgerAccountsTest.php', 'tests/Feature/RequisitionBudgetCyclesTest.php', 'tests/Feature/PurchaseAwardOrderTest.php', 'tests/Feature/ImportLandedCostsTest.php', '--filter=RequisitionBudgetCyclesTest|ImportLandedCostsTest|native office purchase|native partial-order|native consolidated order|native delivery analysis'] : process.argv.includes('--integrated-import-costs-only') ? ['vendor/bin/pest', '--compact', 'tests/Feature/ImportLandedCostsTest.php'] : process.argv.includes('--integrated-orders-only') ? ['vendor/bin/pest', '--compact', 'tests/Feature/PurchaseAwardOrderTest.php', '--filter=native partial-order|native consolidated order|native delivery analysis'] : process.argv.includes('--integrated-cycles-only') ? ['vendor/bin/pest', '--compact', 'tests/Feature/RequisitionBudgetCyclesTest.php'] : process.argv.includes('--office-process-only') ? ['vendor/bin/pest', '--compact', 'tests/Feature/RequisitionLedgerAccountsTest.php', '--filter=native office purchase'] : ['vendor/bin/pest', '--compact', 'tests/Feature/RequisitionLedgerAccountsTest.php', 'tests/Feature/PurchaseAwardOrderTest.php',
|
||||
'--filter=minimal purchasing catalogue|chart references reject|native line account assignment|classified line requires|native submission requires account|zero monetary line retains|native order preserves common ledger|native office purchase'];
|
||||
if (process.argv.includes('--runtime-guard-only')) {
|
||||
@@ -193,12 +220,86 @@ try {
|
||||
if (setupOnly || !frozenRuntime || !process.argv.includes('--integrated-schema')) throw Error('Expiry history regression requires the complete pinned isolated composition');
|
||||
args.splice(0, args.length, 'vendor/bin/pest', '--compact', 'tests/Feature/RequisitionBudgetCyclesTest.php', '--filter=native expiry returns the same request');
|
||||
}
|
||||
if (standaloneBusiness) args.splice(0, args.length, 'vendor/bin/pest', '--compact', 'tests/Feature/StandaloneBusinessCompositionTest.php');
|
||||
const result = spawnSync('php', args, {
|
||||
cwd: process.cwd(), windowsHide: true, encoding: 'utf8', maxBuffer: 1024 * 1024, env: environment,
|
||||
});
|
||||
if (!setupOnly || result.status !== 0) process.stdout.write((result.stdout || '').replaceAll(password, '[private]'));
|
||||
process.stderr.write((result.stderr || '').replaceAll(password, '[private]'));
|
||||
process.exitCode = result.status === 0 ? 0 : 1;
|
||||
if (result.status === 0 && standaloneOnly) {
|
||||
const standaloneEnvironment = { ...environment, APP_ENV: 'standalone-qa',
|
||||
COMPRAS_RUNTIME_ROOT: activeStandaloneRoot, COMPRAS_RUNTIME_SHA256: standalonePin,
|
||||
COMPRAS_RUNTIME_INSTALLATION_ID: crypto.randomUUID(), SGC_STANDALONE_QA_ROOT: root,
|
||||
PAYABLE_SOURCE_INSTANCE: `standalone-synthetic-${id}`,
|
||||
COMPRAS_CAPITAL_REGISTER_ENABLED: 'true', COMPRAS_OPERATIONAL_ORDERS_ENABLED: 'true',
|
||||
COMPRAS_PRIVATE_AUDIT_ENABLED: 'true', COMPRAS_CONFLICT_RELEASES_ENABLED: 'true',
|
||||
COMPRAS_URGENT_REVIEWS_ENABLED: 'true', COMPRAS_URGENT_QUOTATIONS_ENABLED: 'true' };
|
||||
for (const feature of ['BUDGET_DISTRIBUTIONS', 'REQUISITION_ACCOUNTS', 'REQUISITION_EXPIRY', 'EXPENSE_ALLOCATIONS',
|
||||
'AGREEMENT_LIMITS', 'ORDER_PARTS', 'IMPORT_TARIFFS', 'IMPORT_LEGAL', 'IMPORT_DOSSIER', 'IMPORT_BANK_SUPPORT',
|
||||
'IMPORT_READINESS', 'IMPORT_ESTIMATES', 'IMPORT_LANDED_COSTS', 'SUPPLIER_PAYABLES', 'GENERAL_LEDGER',
|
||||
'SUPPLIER_SETTLEMENTS', 'GENERAL_LEDGER_CYCLE']) standaloneEnvironment[`COMPRAS_${feature}_ENABLED`] = 'true';
|
||||
for (const mode of ['prepare', 'verify']) {
|
||||
const check = spawnSync('php', ['tests/Support/standalone-runtime-worker.php', database, mode], {
|
||||
cwd: workspace, windowsHide: true, encoding: 'utf8', maxBuffer: 1024 * 1024,
|
||||
env: { ...standaloneEnvironment, COMPRAS_RUNTIME_ENABLED: mode === 'verify' ? 'true' : 'false' },
|
||||
});
|
||||
process.stdout.write((check.stdout || '').replaceAll(password, '[private]'));
|
||||
process.stderr.write((check.stderr || '').replaceAll(password, '[private]'));
|
||||
const expected = mode === 'prepare' ? 'prepared' : 'verified';
|
||||
let receipt = null;
|
||||
try { receipt = JSON.parse((check.stdout || '').trim()); } catch {}
|
||||
if (check.status !== 0 || receipt?.[expected] !== true) { process.exitCode = 1; break; }
|
||||
}
|
||||
if (process.exitCode === 0) {
|
||||
for (const mode of ['reject-foreign', 'reject-pin', 'reject-dependency', 'reject-old']) {
|
||||
const invalid = { ...standaloneEnvironment, COMPRAS_RUNTIME_ENABLED: 'true' };
|
||||
if (mode === 'reject-pin') invalid.COMPRAS_RUNTIME_SHA256 = '0'.repeat(64);
|
||||
if (mode === 'reject-dependency') invalid.COMPRAS_IMPORT_DOSSIER_ENABLED = 'false';
|
||||
if (mode === 'reject-old') {
|
||||
invalid.COMPRAS_RUNTIME_ROOT = path.join(workspace, 'storage/framework/testing/compras-standalone-730845de0bddd000');
|
||||
invalid.COMPRAS_RUNTIME_SHA256 = '730845de0bddd0007845dd57599c084c4002f3c0672d05e89c582d8e0346fc7b';
|
||||
}
|
||||
const check = spawnSync('php', ['tests/Support/standalone-runtime-worker.php', database, mode], {
|
||||
cwd: workspace, windowsHide: true, encoding: 'utf8', maxBuffer: 1024 * 1024, env: invalid,
|
||||
});
|
||||
process.stdout.write((check.stdout || '').replaceAll(password, '[private]'));
|
||||
process.stderr.write((check.stderr || '').replaceAll(password, '[private]'));
|
||||
let receipt = null;
|
||||
try { receipt = JSON.parse((check.stdout || '').trim()); } catch {}
|
||||
if (check.status !== 0 || receipt?.rejected !== true) { process.exitCode = 1; break; }
|
||||
}
|
||||
}
|
||||
if (process.exitCode === 0) {
|
||||
const pgCommand = (binary, args, env) => {
|
||||
const check = spawnSync(path.join(pg, binary), args, { windowsHide: true, encoding: 'utf8',
|
||||
env: { ...process.env, PGHOST: '127.0.0.1', PGPORT: '55439', PGUSER: env.DB_USERNAME, PGPASSWORD: env.DB_PASSWORD } });
|
||||
if (check.status !== 0) throw Error('Standalone private backup/restore failed');
|
||||
};
|
||||
const dump = path.join(root, 'standalone.dump');
|
||||
pgCommand('pg_dump.exe', ['--format=custom', '--no-owner', '--no-acl', '--file='+dump, '--dbname='+database], environment);
|
||||
const restoredPassword = crypto.randomBytes(30).toString('hex');
|
||||
restoreRole = role+'_restored';
|
||||
restoreDatabase = database+'_restored';
|
||||
sql(`CREATE ROLE ${restoreRole} LOGIN PASSWORD '${restoredPassword}' NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION NOBYPASSRLS;`);
|
||||
sql(`CREATE DATABASE ${restoreDatabase} OWNER ${restoreRole}; REVOKE ALL ON DATABASE ${restoreDatabase} FROM PUBLIC;`);
|
||||
const restored = { ...standaloneEnvironment, DB_DATABASE: restoreDatabase, DB_USERNAME: restoreRole, DB_PASSWORD: restoredPassword };
|
||||
pgCommand('pg_restore.exe', ['--no-owner', '--no-acl', '--exit-on-error', '--dbname='+restoreDatabase, dump], restored);
|
||||
for (const mode of ['reject-restore', 'rebind', 'verify']) {
|
||||
if (mode === 'rebind') restored.COMPRAS_RUNTIME_INSTALLATION_ID = crypto.randomUUID();
|
||||
const check = spawnSync('php', ['tests/Support/standalone-runtime-worker.php', restoreDatabase, mode], {
|
||||
cwd: workspace, windowsHide: true, encoding: 'utf8', maxBuffer: 1024 * 1024,
|
||||
env: { ...restored, COMPRAS_RUNTIME_ENABLED: mode === 'rebind' ? 'false' : 'true' },
|
||||
});
|
||||
process.stdout.write((check.stdout || '').replaceAll(restoredPassword, '[private]'));
|
||||
process.stderr.write((check.stderr || '').replaceAll(restoredPassword, '[private]'));
|
||||
let receipt = null;
|
||||
try { receipt = JSON.parse((check.stdout || '').trim()); } catch {}
|
||||
const expected = mode === 'reject-restore' ? 'rejected' : mode === 'rebind' ? 'prepared' : 'verified';
|
||||
if (check.status !== 0 || receipt?.[expected] !== true) { process.exitCode = 1; break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result.status === 0 && raceOnly) {
|
||||
const race = spawnSync('php', ['tests/Concurrency/requisition-account-worker.php', database, 'race'], {
|
||||
cwd: process.cwd(), windowsHide: true, encoding: 'utf8', maxBuffer: 1024 * 1024, env: environment,
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
// Build only: no application bootstrap, database connection, installation or activation.
|
||||
use App\Services\StandaloneArtifact;
|
||||
use App\Services\StandaloneRuntime;
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
$options = getopt('', ['financial-source:', 'output:']);
|
||||
$source = isset($options['financial-source']) && is_string($options['financial-source']) ? realpath($options['financial-source']) : false;
|
||||
$output = isset($options['output']) && is_string($options['output']) ? realpath($options['output']) : false;
|
||||
if ($source === false || $output === false || ! is_dir($source) || ! is_dir($output) || is_link($options['output'])) {
|
||||
throw new LogicException('Explicit existing canonical source and output directories required.');
|
||||
}
|
||||
$sources = [];
|
||||
foreach (StandaloneArtifact::PACKAGES as $package) {
|
||||
$directory = $package === 'purchasing' ? dirname(__DIR__).'/packages/purchasing' : $source.'/'.$package;
|
||||
foreach (['bootstrap.php', 'README.md', 'module.json'] as $file) {
|
||||
if (is_file($directory.'/'.$file)) {
|
||||
$sources[$package.'/'.$file] = $directory.'/'.$file;
|
||||
}
|
||||
}
|
||||
foreach (['src', 'ui'] as $subdirectory) {
|
||||
if (! is_dir($directory.'/'.$subdirectory)) {
|
||||
continue;
|
||||
}
|
||||
foreach (new DirectoryIterator($directory.'/'.$subdirectory) as $file) {
|
||||
if ($file->isDot()) {
|
||||
continue;
|
||||
}
|
||||
if (! $file->isFile() || $file->isLink() || ! preg_match('/^[A-Za-z0-9_-]+\.php$/D', $file->getFilename())) {
|
||||
throw new LogicException('Unexpected canonical runtime file.');
|
||||
}
|
||||
$sources[$package.'/'.$subdirectory.'/'.$file->getFilename()] = $file->getPathname();
|
||||
}
|
||||
}
|
||||
}
|
||||
ksort($sources, SORT_STRING);
|
||||
$content = [];
|
||||
$files = [];
|
||||
foreach ($sources as $name => $file) {
|
||||
if (is_link($file) || ! is_file($file)) {
|
||||
throw new LogicException('Canonical source must contain regular files.');
|
||||
}
|
||||
$bytes = file_get_contents($file);
|
||||
if (! is_string($bytes)) {
|
||||
throw new LogicException('Unable to read canonical runtime source.');
|
||||
}
|
||||
$content[$name] = $bytes;
|
||||
$files[] = ['file' => $name, 'sha256' => hash('sha256', $bytes)];
|
||||
}
|
||||
$manifest = json_encode(['contract' => StandaloneArtifact::CONTRACT, 'product' => 'compras', 'version' => 1,
|
||||
'capabilities' => StandaloneRuntime::FEATURES, 'files' => $files], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR)."\n";
|
||||
$pin = hash('sha256', $manifest);
|
||||
$target = $output.'/compras-standalone-'.substr($pin, 0, 16);
|
||||
if (! file_exists($target)) {
|
||||
if (! mkdir($target, 0700)) {
|
||||
throw new LogicException('Unable to create candidate directory.');
|
||||
}
|
||||
foreach ($content as $name => $bytes) {
|
||||
$destination = $target.'/'.$name;
|
||||
if (! is_dir(dirname($destination)) && ! mkdir(dirname($destination), 0700, true)) {
|
||||
throw new LogicException('Unable to create candidate package directory.');
|
||||
}
|
||||
$handle = fopen($destination, 'x');
|
||||
if ($handle === false || fwrite($handle, $bytes) !== strlen($bytes)) {
|
||||
throw new LogicException('Unable to write candidate package.');
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
$handle = fopen($target.'/manifest.json', 'x');
|
||||
if ($handle === false || fwrite($handle, $manifest) !== strlen($manifest)) {
|
||||
throw new LogicException('Unable to write candidate manifest.');
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
(new StandaloneArtifact)->verify($target, $pin);
|
||||
$archive = $target.'.zip';
|
||||
if (is_link($archive)) {
|
||||
throw new LogicException('Candidate archive links refused.');
|
||||
}
|
||||
if (! file_exists($archive)) {
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open($archive, ZipArchive::CREATE | ZipArchive::EXCL) !== true) {
|
||||
throw new LogicException('Unable to create candidate archive.');
|
||||
}
|
||||
foreach (array_keys($content) as $name) {
|
||||
if (! $zip->addFile($target.'/'.$name, $name)) {
|
||||
throw new LogicException('Unable to archive candidate package file.');
|
||||
}
|
||||
}
|
||||
$zip->addFile($target.'/manifest.json', 'manifest.json');
|
||||
if (! $zip->close()) {
|
||||
throw new LogicException('Unable to finish candidate archive.');
|
||||
}
|
||||
}
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open($archive) !== true || $zip->numFiles !== count($files) + 1) {
|
||||
throw new LogicException('Candidate archive inventory mismatch.');
|
||||
}
|
||||
$expected = ['manifest.json' => $manifest, ...$content];
|
||||
$seen = [];
|
||||
for ($i = 0; $i < $zip->numFiles; $i++) {
|
||||
$name = $zip->getNameIndex($i);
|
||||
if (! is_string($name) || isset($seen[$name]) || ! isset($expected[$name]) || $zip->getFromIndex($i) !== $expected[$name]) {
|
||||
throw new LogicException('Candidate archive bytes mismatch.');
|
||||
}
|
||||
$seen[$name] = true;
|
||||
}
|
||||
$zip->close();
|
||||
$archiveHash = hash_file('sha256', $archive);
|
||||
if (! is_string($archiveHash)) {
|
||||
throw new LogicException('Unable to hash candidate archive.');
|
||||
}
|
||||
echo json_encode(['root' => $target, 'manifest_sha256' => $pin, 'files' => count($files),
|
||||
'archive' => $archive, 'archive_sha256' => $archiveHash,
|
||||
'state' => 'candidate_requires_operational_validation', 'installed_or_activated' => false], JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
Reference in New Issue
Block a user