@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user