Aplicar Pint e formatação de frontend; delimitar o âmbito do lint
Só formatação automática (pint, vp check --fix), sem alterar comportamento. Excluídos da formatação os registos e artefactos com bytes fixos: docs/, integrations/, storage/, tmp/, output/, resources/data/, tests/Fixtures/, compras-release.json e AGENTS*.md. Scripts operacionais, integrations e auxiliares de teste ficam fora do lint (usam new Function; limpeza na fase 2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,48 +2,138 @@ import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { spawn, spawnSync } from 'node:child_process';
|
||||
|
||||
export async function verifyConfigurationConcurrency(workspace, root, database, environment) {
|
||||
if (environment.COMPRAS_RUNTIME_ENABLED !== 'true' || environment.COMPRAS_RUNTIME_PREPARE_ONLY !== 'false') throw Error('Verified standalone configuration required');
|
||||
export async function verifyConfigurationConcurrency(
|
||||
workspace,
|
||||
root,
|
||||
database,
|
||||
environment,
|
||||
) {
|
||||
if (
|
||||
environment.COMPRAS_RUNTIME_ENABLED !== 'true' ||
|
||||
environment.COMPRAS_RUNTIME_PREPARE_ONLY !== 'false'
|
||||
)
|
||||
throw Error('Verified standalone configuration required');
|
||||
const worker = (mode, round) => {
|
||||
const result = spawnSync('php', ['tests/Support/standalone-runtime-worker.php', database, mode, round], {
|
||||
cwd: workspace, windowsHide: true, encoding: 'utf8', env: environment,
|
||||
});
|
||||
if (result.status !== 0) throw Error('Standalone configuration fixture/read worker failed');
|
||||
const result = spawnSync(
|
||||
'php',
|
||||
[
|
||||
'tests/Support/standalone-runtime-worker.php',
|
||||
database,
|
||||
mode,
|
||||
round,
|
||||
],
|
||||
{
|
||||
cwd: workspace,
|
||||
windowsHide: true,
|
||||
encoding: 'utf8',
|
||||
env: environment,
|
||||
},
|
||||
);
|
||||
if (result.status !== 0)
|
||||
throw Error('Standalone configuration fixture/read worker failed');
|
||||
return JSON.parse(result.stdout.trim());
|
||||
};
|
||||
for (const round of ['same', 'different']) {
|
||||
if (worker('prepare-configuration-race', round).prepared !== true) throw Error('Race fixture not prepared');
|
||||
const children = [0, 1].map(index => {
|
||||
const child = spawn('php', ['tests/Support/standalone-runtime-worker.php', database, 'run-configuration-race', round, String(index)], {
|
||||
cwd: workspace, windowsHide: true, env: environment,
|
||||
});
|
||||
if (worker('prepare-configuration-race', round).prepared !== true)
|
||||
throw Error('Race fixture not prepared');
|
||||
const children = [0, 1].map((index) => {
|
||||
const child = spawn(
|
||||
'php',
|
||||
[
|
||||
'tests/Support/standalone-runtime-worker.php',
|
||||
database,
|
||||
'run-configuration-race',
|
||||
round,
|
||||
String(index),
|
||||
],
|
||||
{
|
||||
cwd: workspace,
|
||||
windowsHide: true,
|
||||
env: environment,
|
||||
},
|
||||
);
|
||||
let output = '';
|
||||
child.stdout.on('data', chunk => { output += chunk.toString(); });
|
||||
child.stdout.on('data', (chunk) => {
|
||||
output += chunk.toString();
|
||||
});
|
||||
child.stderr.on('data', () => {});
|
||||
const complete = new Promise(resolve => child.on('close', code => resolve({ code, output })));
|
||||
const complete = new Promise((resolve) =>
|
||||
child.on('close', (code) => resolve({ code, output })),
|
||||
);
|
||||
return { child, complete };
|
||||
});
|
||||
try {
|
||||
const until = Date.now() + 15000;
|
||||
while (![0, 1].every(index => fs.existsSync(path.join(root, `configuration-${round}-${index}.ready`)))) {
|
||||
if (Date.now() > until || children.some(({ child }) => child.exitCode !== null)) throw Error('Concurrent candidate workers did not reach the gate');
|
||||
await new Promise(resolve => setTimeout(resolve, 20));
|
||||
while (
|
||||
![0, 1].every((index) =>
|
||||
fs.existsSync(
|
||||
path.join(
|
||||
root,
|
||||
`configuration-${round}-${index}.ready`,
|
||||
),
|
||||
),
|
||||
)
|
||||
) {
|
||||
if (
|
||||
Date.now() > until ||
|
||||
children.some(({ child }) => child.exitCode !== null)
|
||||
)
|
||||
throw Error(
|
||||
'Concurrent candidate workers did not reach the gate',
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
}
|
||||
fs.writeFileSync(path.join(root, `configuration-${round}.go`), 'go', { flag: 'wx' });
|
||||
fs.writeFileSync(
|
||||
path.join(root, `configuration-${round}.go`),
|
||||
'go',
|
||||
{ flag: 'wx' },
|
||||
);
|
||||
const results = await Promise.race([
|
||||
Promise.all(children.map(({ complete }) => complete)),
|
||||
new Promise((_, reject) => { const timer = setTimeout(() => reject(Error('Concurrent candidate writers timed out')), 20000); timer.unref(); }),
|
||||
new Promise((_, reject) => {
|
||||
const timer = setTimeout(
|
||||
() =>
|
||||
reject(
|
||||
Error('Concurrent candidate writers timed out'),
|
||||
),
|
||||
20000,
|
||||
);
|
||||
timer.unref();
|
||||
}),
|
||||
]);
|
||||
if (results.some(result => result.code !== 0)) throw Error('Concurrent candidate writer failed');
|
||||
const outcomes = results.map(result => JSON.parse(result.output.trim()));
|
||||
if (outcomes.filter(result => result.state === 'saved' && result.replayed === false).length !== 1
|
||||
|| (round === 'same' ? outcomes.filter(result => result.state === 'saved' && result.replayed === true).length !== 1
|
||||
: outcomes.filter(result => result.state === 'stale').length !== 1)) throw Error('Unexpected concurrent configuration outcome');
|
||||
if (results.some((result) => result.code !== 0))
|
||||
throw Error('Concurrent candidate writer failed');
|
||||
const outcomes = results.map((result) =>
|
||||
JSON.parse(result.output.trim()),
|
||||
);
|
||||
if (
|
||||
outcomes.filter(
|
||||
(result) =>
|
||||
result.state === 'saved' && result.replayed === false,
|
||||
).length !== 1 ||
|
||||
(round === 'same'
|
||||
? outcomes.filter(
|
||||
(result) =>
|
||||
result.state === 'saved' &&
|
||||
result.replayed === true,
|
||||
).length !== 1
|
||||
: outcomes.filter((result) => result.state === 'stale')
|
||||
.length !== 1)
|
||||
)
|
||||
throw Error('Unexpected concurrent configuration outcome');
|
||||
const proof = worker('read-configuration-race', round);
|
||||
if (proof.verified !== true) throw Error('Concurrent configuration conservation missing');
|
||||
console.log(JSON.stringify({ standalone_configuration_concurrency: true, ...proof, outcomes }));
|
||||
if (proof.verified !== true)
|
||||
throw Error('Concurrent configuration conservation missing');
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
standalone_configuration_concurrency: true,
|
||||
...proof,
|
||||
outcomes,
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
for (const { child } of children) if (child.exitCode === null) child.kill();
|
||||
for (const { child } of children)
|
||||
if (child.exitCode === null) child.kill();
|
||||
await Promise.all(children.map(({ complete }) => complete));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user