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:
2026-11-30 23:01:42 +02:00
co-authored by Claude Opus 5.5
parent 9f719695e3
commit ec934455e7
148 changed files with 9455 additions and 2413 deletions
+119 -57
View File
@@ -7,35 +7,76 @@ import { spawnSync } from 'node:child_process';
const boundary = await fs.realpath('storage/framework/testing');
const verifier = path.resolve('scripts/verify-compras-release.php');
const hash = bytes => crypto.createHash('sha256').update(bytes).digest('hex');
const hash = (bytes) => crypto.createHash('sha256').update(bytes).digest('hex');
async function fixture(run) {
const root = await fs.mkdtemp(path.join(boundary, 'release-verifier-'));
try {
await fs.mkdir(path.join(root, 'public/build/assets'), { recursive: true });
const source = '<?php exit(99); // verification must never execute product code';
await fs.mkdir(path.join(root, 'public/build/assets'), {
recursive: true,
});
const source =
'<?php exit(99); // verification must never execute product code';
await fs.writeFile(path.join(root, 'main.php'), source);
await fs.writeFile(path.join(root, 'public/build/manifest.json'), '{}');
await fs.writeFile(path.join(root, 'public/build/assets/a.js'), 'test');
const manifest = { contract: 'compras.release.v1', product: 'compras', source_files: { 'main.php': hash(source) },
frontend: { manifest_sha256: hash('{}'), files: { 'assets/a.js': hash('test') } }, components: [] };
const manifest = {
contract: 'compras.release.v1',
product: 'compras',
source_files: { 'main.php': hash(source) },
frontend: {
manifest_sha256: hash('{}'),
files: { 'assets/a.js': hash('test') },
},
components: [],
};
for (const [index, list] of [true, false].entries()) {
const component = path.join(root, 'component-'+index);
const component = path.join(root, 'component-' + index);
await fs.mkdir(component);
await fs.writeFile(path.join(component, 'writer.php'), 'not executable');
const files = list ? [{ file: 'writer.php', sha256: hash('not executable') }] : { 'writer.php': hash('not executable') };
await fs.writeFile(
path.join(component, 'writer.php'),
'not executable',
);
const files = list
? [{ file: 'writer.php', sha256: hash('not executable') }]
: { 'writer.php': hash('not executable') };
const bytes = JSON.stringify({ files });
await fs.writeFile(path.join(component, 'manifest.json'), bytes);
manifest.components.push({ setting: 'COMPONENT_'+index, manifest_sha256: hash(bytes) });
manifest.components.push({
setting: 'COMPONENT_' + index,
manifest_sha256: hash(bytes),
});
}
await fs.writeFile(path.join(root, '.env'), 'COMPRAS_RUNTIME_ENABLED="true"\n'+manifest.components.map((entry, index) => entry.setting+'="'+path.join(root, 'component-'+index).replaceAll('\\', '/')+'"').join('\n'));
await fs.writeFile(
path.join(root, '.env'),
'COMPRAS_RUNTIME_ENABLED="true"\n' +
manifest.components
.map(
(entry, index) =>
entry.setting +
'="' +
path
.join(root, 'component-' + index)
.replaceAll('\\', '/') +
'"',
)
.join('\n'),
);
const save = async () => {
delete manifest.release_id;
manifest.release_id = 'compras-'+hash(JSON.stringify(manifest)).slice(0, 16);
await fs.writeFile(path.join(root, 'compras-release.json'), JSON.stringify(manifest));
manifest.release_id =
'compras-' + hash(JSON.stringify(manifest)).slice(0, 16);
await fs.writeFile(
path.join(root, 'compras-release.json'),
JSON.stringify(manifest),
);
};
await save();
const verify = (...args) => spawnSync('php', [verifier, root, ...args], { encoding: 'utf8', windowsHide: true });
const verify = (...args) =>
spawnSync('php', [verifier, root, ...args], {
encoding: 'utf8',
windowsHide: true,
});
await run({ root, manifest, save, verify });
} finally {
const resolved = await fs.realpath(root);
@@ -45,47 +86,68 @@ async function fixture(run) {
}
}
test('verifies one source, compiled assets and both component manifest formats without executing product code', () => fixture(async ({ verify }) => {
const result = verify('--installed');
assert.equal(result.status, 0, result.stderr);
assert.equal(JSON.parse(result.stdout).installed_components, 2);
}));
test('rejects changed source', () => fixture(async ({ root, verify }) => {
await fs.writeFile(path.join(root, 'main.php'), 'changed');
assert.notEqual(verify().status, 0);
}));
test('accepts Git LF and Windows CRLF as the same source without accepting changed text', () => fixture(async ({ root, manifest, save, verify }) => {
manifest.source_eol = 'lf';
manifest.source_files['main.php'] = hash('first\nsecond\n');
await save();
await fs.writeFile(path.join(root, 'main.php'), 'first\r\nsecond\r\n');
assert.equal(verify().status, 0);
await fs.writeFile(path.join(root, 'main.php'), 'first\r\nchanged\r\n');
assert.notEqual(verify().status, 0);
}));
test('rejects a changed compiled asset', () => fixture(async ({ root, verify }) => {
await fs.writeFile(path.join(root, 'public/build/assets/a.js'), 'changed');
assert.notEqual(verify('--compiled').status, 0);
}));
test('rejects a changed component', () => fixture(async ({ root, verify }) => {
await fs.writeFile(path.join(root, 'component-1/writer.php'), 'changed');
assert.notEqual(verify('--installed').status, 0);
}));
test('rejects forged identity', () => fixture(async ({ root, manifest, verify }) => {
manifest.release_id = 'compras-forged';
await fs.writeFile(path.join(root, 'compras-release.json'), JSON.stringify(manifest));
assert.notEqual(verify().status, 0);
}));
test('rejects path traversal even with a recomputed descriptor', () => fixture(async ({ manifest, save, verify }) => {
manifest.source_files['../outside.php'] = hash('test');
await save();
assert.notEqual(verify().status, 0);
}));
test('rejects disabled installation', () => fixture(async ({ root, verify }) => {
await fs.writeFile(path.join(root, '.env'), 'COMPRAS_RUNTIME_ENABLED=false');
assert.notEqual(verify('--installed').status, 0);
}));
test('rejects a missing descriptor', () => fixture(async ({ root, verify }) => {
await fs.unlink(path.join(root, 'compras-release.json'));
assert.notEqual(verify().status, 0);
}));
test('verifies one source, compiled assets and both component manifest formats without executing product code', () =>
fixture(async ({ verify }) => {
const result = verify('--installed');
assert.equal(result.status, 0, result.stderr);
assert.equal(JSON.parse(result.stdout).installed_components, 2);
}));
test('rejects changed source', () =>
fixture(async ({ root, verify }) => {
await fs.writeFile(path.join(root, 'main.php'), 'changed');
assert.notEqual(verify().status, 0);
}));
test('accepts Git LF and Windows CRLF as the same source without accepting changed text', () =>
fixture(async ({ root, manifest, save, verify }) => {
manifest.source_eol = 'lf';
manifest.source_files['main.php'] = hash('first\nsecond\n');
await save();
await fs.writeFile(path.join(root, 'main.php'), 'first\r\nsecond\r\n');
assert.equal(verify().status, 0);
await fs.writeFile(path.join(root, 'main.php'), 'first\r\nchanged\r\n');
assert.notEqual(verify().status, 0);
}));
test('rejects a changed compiled asset', () =>
fixture(async ({ root, verify }) => {
await fs.writeFile(
path.join(root, 'public/build/assets/a.js'),
'changed',
);
assert.notEqual(verify('--compiled').status, 0);
}));
test('rejects a changed component', () =>
fixture(async ({ root, verify }) => {
await fs.writeFile(
path.join(root, 'component-1/writer.php'),
'changed',
);
assert.notEqual(verify('--installed').status, 0);
}));
test('rejects forged identity', () =>
fixture(async ({ root, manifest, verify }) => {
manifest.release_id = 'compras-forged';
await fs.writeFile(
path.join(root, 'compras-release.json'),
JSON.stringify(manifest),
);
assert.notEqual(verify().status, 0);
}));
test('rejects path traversal even with a recomputed descriptor', () =>
fixture(async ({ manifest, save, verify }) => {
manifest.source_files['../outside.php'] = hash('test');
await save();
assert.notEqual(verify().status, 0);
}));
test('rejects disabled installation', () =>
fixture(async ({ root, verify }) => {
await fs.writeFile(
path.join(root, '.env'),
'COMPRAS_RUNTIME_ENABLED=false',
);
assert.notEqual(verify('--installed').status, 0);
}));
test('rejects a missing descriptor', () =>
fixture(async ({ root, verify }) => {
await fs.unlink(path.join(root, 'compras-release.json'));
assert.notEqual(verify().status, 0);
}));
@@ -13,17 +13,41 @@ test('legacy transfer adds links once and preserves other capabilities', () => {
});
test('current host keeps its stricter feature guard and complete empty state', () => {
const guard = "const requisitions=unit!==null&&context.purchasing?.internal_requisitions===true&&can('purchasing_requisitions.view',unit);";
const source = legacy.replace('\n', '\n'+guard+'\n').replace('<div className="actions">', '<div className="actions">{requisitions&&<a href="/purchasing/internal-requisitions">Requisições</a>}').replace('!budget&&!payables&&', '!requisitions&&!sourceRequests&&!suppliers&&!budget&&!payables&&');
const guard =
"const requisitions=unit!==null&&context.purchasing?.internal_requisitions===true&&can('purchasing_requisitions.view',unit);";
const source = legacy
.replace('\n', '\n' + guard + '\n')
.replace(
'<div className="actions">',
'<div className="actions">{requisitions&&<a href="/purchasing/internal-requisitions">Requisições</a>}',
)
.replace(
'!budget&&!payables&&',
'!requisitions&&!sourceRequests&&!suppliers&&!budget&&!payables&&',
);
const output = purchasingHomeOverlay(source);
assert.ok(output.includes(guard));
assert.equal((output.match(/const requisitions=/g)??[]).length, 1);
assert.equal((output.match(/href="\/purchasing\/internal-requisitions"/g)??[]).length, 1);
assert.ok(output.includes('!requisitions&&!sourceRequests&&!suppliers&&!budget&&!payables&&'));
assert.equal((output.match(/const requisitions=/g) ?? []).length, 1);
assert.equal(
(output.match(/href="\/purchasing\/internal-requisitions"/g) ?? [])
.length,
1,
);
assert.ok(
output.includes(
'!requisitions&&!sourceRequests&&!suppliers&&!budget&&!payables&&',
),
);
assert.equal(purchasingHomeOverlay(output), output);
});
test('unknown or duplicate declarations refuse preparation', () => {
assert.throws(() => purchasingHomeOverlay('const requisitions=true;\n'+legacy));
assert.throws(() => purchasingHomeOverlay('const requisitions=true;const requisitions=false;'+legacy));
assert.throws(() =>
purchasingHomeOverlay('const requisitions=true;\n' + legacy),
);
assert.throws(() =>
purchasingHomeOverlay(
'const requisitions=true;const requisitions=false;' + legacy,
),
);
});