52 lines
4.5 KiB
JavaScript
52 lines
4.5 KiB
JavaScript
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 }));
|