@@ -14,9 +14,13 @@ const componentProfile = process.argv.includes('--standalone-component-profile')
|
||||
if (componentProfile && (!standaloneOnly || financePreview)) throw Error('Component profile requires its own standalone invocation');
|
||||
if (financePreview && !standaloneOnly) throw Error('Finance preview requires the isolated standalone runtime');
|
||||
const standaloneUpgrade = process.argv.includes('--standalone-upgrade-only');
|
||||
const standaloneBusiness = process.argv.includes('--standalone-business-only') || standaloneUpgrade;
|
||||
const standaloneAnalyticsPreview = process.argv.includes('--standalone-analytics-preview');
|
||||
const standaloneCancellationPreview = process.argv.includes('--standalone-cancellation-preview');
|
||||
const standaloneConversionPreview = process.argv.includes('--standalone-conversion-preview') || standaloneCancellationPreview || standaloneAnalyticsPreview;
|
||||
const standaloneConversion = process.argv.includes('--standalone-conversion-only') || standaloneConversionPreview;
|
||||
const standaloneBusiness = process.argv.includes('--standalone-business-only') || standaloneUpgrade || standaloneConversion;
|
||||
if (standaloneOnly && process.argv.slice(2).some(flag => !['--standalone-runtime-only', '--standalone-finance-preview', '--standalone-component-profile'].includes(flag))) throw Error('Standalone composition requires its own isolated invocation');
|
||||
if (standaloneBusiness && process.argv.slice(2).some(flag => flag !== (standaloneUpgrade ? '--standalone-upgrade-only' : '--standalone-business-only'))) throw Error('Standalone business regression requires its own isolated invocation');
|
||||
if (standaloneBusiness && process.argv.slice(2).some(flag => flag !== (standaloneAnalyticsPreview ? '--standalone-analytics-preview' : standaloneCancellationPreview ? '--standalone-cancellation-preview' : standaloneConversionPreview ? '--standalone-conversion-preview' : standaloneConversion ? '--standalone-conversion-only' : standaloneUpgrade ? '--standalone-upgrade-only' : '--standalone-business-only'))) throw Error('Standalone business regression requires its own isolated invocation');
|
||||
const standaloneRoot = path.join(workspace, 'storage/framework/testing/compras-standalone-80483320a54af6f1');
|
||||
const standalonePin = '80483320a54af6f123498e43c1435a20922455f65860be88bd259e90efcbc0b7';
|
||||
const standaloneArchivePin = 'bbc1d953061d5a297d4336a3cb746a11af5d6930c6fc7d0b5d64b5bff3046e76';
|
||||
@@ -132,6 +136,18 @@ try {
|
||||
createdDatabase = true;
|
||||
sql(`REVOKE ALL ON DATABASE ${database} FROM PUBLIC;`);
|
||||
let activeStandaloneRoot = standaloneRoot;
|
||||
let inventoryRoot = null;
|
||||
if (standaloneConversion) {
|
||||
const pin = '8608e6551dea6448983ead401ba900b440ffdeb1446ce52de6509d5eba0e87bd';
|
||||
const archive = path.join(privateParent, `compras-inventory-${pin}.zip`);
|
||||
if (fs.lstatSync(archive).isSymbolicLink() || crypto.createHash('sha256').update(fs.readFileSync(archive)).digest('hex') !== 'dbb7e3d172f2ce5168f678993b96d9d94ce2e0c1737b581743cf2bbb6d4d00b8') throw Error('Pinned inventory archive mismatch');
|
||||
inventoryRoot = path.join(root, 'inventory-runtime');
|
||||
fs.mkdirSync(inventoryRoot);
|
||||
const code = '$z=new ZipArchive; if($z->open($argv[1])!==true||$z->numFiles!==4||!$z->extractTo($argv[2]))throw new LogicException("Owned inventory extraction failed");$z->close();';
|
||||
const extracted = spawnSync('php', ['-r', code, archive, inventoryRoot], { windowsHide: true, encoding: 'utf8' });
|
||||
if (extracted.status !== 0) throw Error('Owned inventory extraction failed');
|
||||
verifyPrivateRuntime(inventoryRoot, pin, 3);
|
||||
}
|
||||
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');
|
||||
@@ -180,6 +196,8 @@ try {
|
||||
environment.COMPRAS_RUNTIME_INSTALLATION_ID = crypto.randomUUID();
|
||||
environment.COMPRAS_STANDALONE_BUSINESS_QA = standaloneBusiness ? '1' : '0';
|
||||
environment.COMPRAS_STANDALONE_UPGRADE_QA = standaloneUpgrade ? '1' : '0';
|
||||
environment.COMPRAS_STANDALONE_CONVERSION_QA = standaloneConversion ? '1' : '0';
|
||||
if (inventoryRoot !== null) environment.COMPRAS_INVENTORY_ROOT = inventoryRoot;
|
||||
}
|
||||
if (frozenRuntime) {
|
||||
environment.COMMON_FINANCE_BUNDLE_ROOT = financeRoot;
|
||||
@@ -234,13 +252,75 @@ 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', standaloneUpgrade ? 'tests/Feature/StandaloneComponentUpgradeTest.php' : 'tests/Feature/StandaloneBusinessCompositionTest.php');
|
||||
if (standaloneBusiness) args.splice(0, args.length, 'vendor/bin/pest', '--compact', standaloneConversion ? 'tests/Conversion/ReceiptQuantityConversionTest.php' : standaloneUpgrade ? 'tests/Feature/StandaloneComponentUpgradeTest.php' : 'tests/Feature/StandaloneBusinessCompositionTest.php');
|
||||
if (standaloneConversionPreview) args.splice(0, args.length, 'artisan', 'migrate', '--force', '--no-interaction', '--quiet');
|
||||
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 && standaloneConversion) {
|
||||
const prepared = spawnSync('php', ['tests/Concurrency/unit-conversion-worker.php', database, 'prepare-runtime'], {
|
||||
cwd: workspace, windowsHide: true, encoding: 'utf8', env: environment,
|
||||
});
|
||||
if (prepared.status !== 0 || prepared.stdout !== 'synthetic_standalone_inventory_prepared') throw Error('Inventory runtime preparation failed: '+(prepared.stderr || prepared.stdout || ''));
|
||||
const operationalEnvironment = { ...environment, APP_ENV: 'standalone-qa', COMPRAS_RUNTIME_ENABLED: 'true',
|
||||
COMPRAS_RUNTIME_PREPARE_ONLY: 'false', COMPRAS_INVENTORY_CONVERSION_ENABLED: 'true' };
|
||||
for (const match of fs.readFileSync(path.join(workspace, 'config/standalone-runtime.php'), 'utf8').matchAll(/env\('(COMPRAS_[A-Z_]+_ENABLED)'/g)) operationalEnvironment[match[1]] = 'true';
|
||||
if (standaloneConversionPreview) {
|
||||
if (standaloneCancellationPreview) operationalEnvironment.COMPRAS_ORDER_CANCELLATION_ENABLED = 'true';
|
||||
const { reviewStandaloneInventory } = await import('./standalone-inventory-preview.mjs');
|
||||
await reviewStandaloneInventory({ workspace, root, database, environment: operationalEnvironment, cancellation: standaloneCancellationPreview, analytics: standaloneAnalyticsPreview });
|
||||
} else {
|
||||
const raced = spawnSync('php', ['tests/Concurrency/unit-conversion-worker.php', database, 'race'], {
|
||||
cwd: workspace, windowsHide: true, encoding: 'utf8', maxBuffer: 1024 * 1024, env: operationalEnvironment,
|
||||
});
|
||||
process.stdout.write((raced.stdout || '').replaceAll(password, '[private]'));
|
||||
process.stderr.write((raced.stderr || '').replaceAll(password, '[private]'));
|
||||
if (raced.status !== 0) throw Error('Operational inventory contention failed');
|
||||
console.log(JSON.stringify({ inventory_archive_extracted: true, operational_environment: 'standalone-qa', qa_conversion_disabled: true, operational_changes: false }));
|
||||
}
|
||||
if (!standaloneConversionPreview || standaloneCancellationPreview) {
|
||||
operationalEnvironment.SGC_STANDALONE_QA_ROOT = root;
|
||||
operationalEnvironment.COMPRAS_QA_ORIGINAL_INSTALLATION_ID = environment.COMPRAS_RUNTIME_INSTALLATION_ID;
|
||||
const inspectInventory = (mode, env) => {
|
||||
const check = spawnSync('php', ['tests/Support/standalone-inventory-recovery-worker.php', env.DB_DATABASE, mode], {
|
||||
cwd: workspace, windowsHide: true, encoding: 'utf8', maxBuffer: 1024 * 1024, env,
|
||||
});
|
||||
if (check.status !== 0) throw Error('Isolated inventory recovery check failed: '+(check.stderr || check.stdout || '').replaceAll(env.DB_PASSWORD, '[private]'));
|
||||
try { return JSON.parse(check.stdout); }
|
||||
catch { throw Error('Inventory recovery returned an invalid receipt: '+(check.stdout || '').replaceAll(env.DB_PASSWORD, '[private]').slice(0, 2000)); }
|
||||
};
|
||||
const readMode = standaloneCancellationPreview ? 'read-cancellation' : 'read';
|
||||
const original = inspectInventory(readMode, operationalEnvironment);
|
||||
const pgInventory = (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('Synthetic inventory backup/restore failed');
|
||||
};
|
||||
const dump = path.join(root, 'inventory-recovery.dump');
|
||||
pgInventory('pg_dump.exe', ['--format=custom', '--no-owner', '--no-acl', '--file='+dump, '--dbname='+database], operationalEnvironment);
|
||||
const restoredPassword = crypto.randomBytes(30).toString('hex');
|
||||
restoreRole = role+'_restored';
|
||||
sql(`CREATE ROLE ${restoreRole} LOGIN PASSWORD '${restoredPassword}' NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION NOBYPASSRLS;`);
|
||||
restoreDatabase = database+'_restored';
|
||||
sql(`CREATE DATABASE ${restoreDatabase} OWNER ${restoreRole}; REVOKE ALL ON DATABASE ${restoreDatabase} FROM PUBLIC;`);
|
||||
const restored = { ...operationalEnvironment, DB_DATABASE: restoreDatabase, DB_USERNAME: restoreRole, DB_PASSWORD: restoredPassword };
|
||||
pgInventory('pg_restore.exe', ['--no-owner', '--no-acl', '--exit-on-error', '--dbname='+restoreDatabase, dump], restored);
|
||||
const rejected = inspectInventory('reject-restore', restored);
|
||||
if (rejected.rejected !== true) throw Error('Restored inventory binding was not refused');
|
||||
restored.COMPRAS_RUNTIME_INSTALLATION_ID = crypto.randomUUID();
|
||||
const rebound = inspectInventory('rebind', { ...restored, COMPRAS_RUNTIME_ENABLED: 'false', COMPRAS_RUNTIME_PREPARE_ONLY: 'true' });
|
||||
if (rebound.state !== 'rebound') throw Error('Inventory recovery binding not recorded');
|
||||
const recovered = inspectInventory(readMode, restored);
|
||||
if (JSON.stringify(original) !== JSON.stringify(recovered)) throw Error('Recovered inventory business data or legacy installation changed');
|
||||
console.log(JSON.stringify({ inventory_backup_restored: !standaloneCancellationPreview, cancellation_backup_restored: standaloneCancellationPreview,
|
||||
incompatible_binding_rejected: true, explicit_rebind: true, preserved_business_tables: recovered.business_tables,
|
||||
recovered_converted_movements: recovered.converted_movements, recovered_cancellations: recovered.approved_cancellations,
|
||||
source_cycle: recovered.source_cycle, exact_replays: recovered.exact_replays }));
|
||||
}
|
||||
}
|
||||
if (result.status === 0 && componentProfile) {
|
||||
const profile = spawnSync('php', ['tests/Support/standalone-runtime-worker.php', database, 'prepare-component-profile'], {
|
||||
cwd: workspace, windowsHide: true, encoding: 'utf8', env: { ...environment, APP_ENV: 'standalone-qa', SGC_STANDALONE_QA_ROOT: root },
|
||||
|
||||
Reference in New Issue
Block a user