129 lines
4.6 KiB
JavaScript
129 lines
4.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs/promises';
|
|
import { execFile } from 'node:child_process';
|
|
import { promisify } from 'node:util';
|
|
const run = promisify(execFile);
|
|
const php = 'C:/Users/macbook/.config/investmoz/php-8.5.11/php.exe';
|
|
const sgf = 'C:/laragon/www/sgf-tempo';
|
|
for (const host of ['compras', 'sgf']) {
|
|
const exists = await fs
|
|
.access(`C:/laragon/data/sgf-tempo/secrets/payables-proof-${host}.json`)
|
|
.then(
|
|
() => true,
|
|
() => false,
|
|
);
|
|
assert(
|
|
!exists,
|
|
'An existing proof must be reconciled before creating a new one.',
|
|
);
|
|
}
|
|
async function job(name) {
|
|
const { stdout } = await run(
|
|
php,
|
|
['scripts/payable-history-pg.php', name],
|
|
{
|
|
cwd: process.cwd(),
|
|
windowsHide: true,
|
|
timeout: 90000,
|
|
maxBuffer: 100000,
|
|
},
|
|
);
|
|
return JSON.parse(stdout);
|
|
}
|
|
try {
|
|
await run(php, [`${sgf}/scripts/payables-provision.php`, '--proof'], {
|
|
cwd: sgf,
|
|
windowsHide: true,
|
|
timeout: 180000,
|
|
maxBuffer: 100000,
|
|
});
|
|
const before = await job('setup');
|
|
const fault = await job('fault');
|
|
assert(fault.fault_rolled_back);
|
|
assert.equal(fault.business_fingerprint, before.business_fingerprint);
|
|
const recognised = await Promise.all([job('validate'), job('validate')]);
|
|
assert(recognised.every((result) => result.state === 'recognised'));
|
|
assert.equal(recognised[0].obligation_id, recognised[1].obligation_id);
|
|
const after = await job('inspect');
|
|
assert.equal(after.principal_minor, 1160000);
|
|
assert.equal(after.balance_minor, 860000);
|
|
assert.equal(after.confirmed_minor, 300000);
|
|
assert.equal(after.pending_minor, 100000);
|
|
assert.equal(after.rejected_minor, 50000);
|
|
assert.equal(after.obligations, 1);
|
|
assert.equal(after.imports, 1);
|
|
assert.equal(after.payment_links, 3);
|
|
assert.equal(after.business_fingerprint, before.business_fingerprint);
|
|
assert(after.ui_balance_correct);
|
|
assert(after.changed_history_refused);
|
|
assert.equal(after.due_on, null);
|
|
assert.equal(after.days_overdue, null);
|
|
assert.equal(after.append_only_tables.length, 2);
|
|
if (process.argv.includes('--decisions')) {
|
|
const fault = await job('decision_fault');
|
|
assert(fault.rolled_back);
|
|
assert.equal(fault.balance_minor, 860000);
|
|
const concurrent = await Promise.all([
|
|
job('decision_confirm'),
|
|
job('decision_confirm'),
|
|
]);
|
|
assert(
|
|
concurrent.every(
|
|
(r) => r.balance_minor === 760000 && r.frozen === r.original,
|
|
),
|
|
);
|
|
const final = await job('decision_inspect');
|
|
assert.equal(final.balance_minor, 760000);
|
|
assert.equal(final.confirmed_minor, 400000);
|
|
assert.equal(final.pending_minor, 0);
|
|
assert.equal(final.decisions, 1);
|
|
assert.equal(final.events, 1);
|
|
assert.equal(final.original_status, 'confirmed');
|
|
assert(final.append_only);
|
|
assert(concurrent.every((r) => r.frozen === final.frozen));
|
|
await fs.writeFile(
|
|
'docs/proofs/payable-payment-decisions-pg.json',
|
|
JSON.stringify(
|
|
{
|
|
checked_at: new Date().toISOString(),
|
|
passed: true,
|
|
atomic_rollback: true,
|
|
concurrent_decision_once: true,
|
|
original_import_preserved: true,
|
|
new_transfers_executed: false,
|
|
scenario: final,
|
|
visual_review: false,
|
|
},
|
|
null,
|
|
2,
|
|
) + '\n',
|
|
);
|
|
}
|
|
await fs.writeFile(
|
|
'docs/proofs/payable-history-pg.json',
|
|
JSON.stringify(
|
|
{
|
|
checked_at: new Date().toISOString(),
|
|
passed: true,
|
|
fault_recovery: true,
|
|
concurrent_recognition: true,
|
|
original_business_history_unchanged: true,
|
|
new_transfers_executed: false,
|
|
scenario: after,
|
|
visual_review: false,
|
|
},
|
|
null,
|
|
2,
|
|
) + '\n',
|
|
);
|
|
console.log(
|
|
'PostgreSQL historical import passed: gross principal, single deduction, pending/rejected preservation, concurrency, rollback and immutable history.',
|
|
);
|
|
} finally {
|
|
await run(
|
|
php,
|
|
[`${sgf}/scripts/payables-provision.php`, '--cleanup-proof'],
|
|
{ cwd: sgf, windowsHide: true, timeout: 90000, maxBuffer: 100000 },
|
|
);
|
|
}
|