43 lines
4.2 KiB
JavaScript
43 lines
4.2 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { createHash } from 'node:crypto';
|
|
import { validateInstalledVersion } from '../src/core/desktop/install-manager.mjs';
|
|
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
const read = file => JSON.parse(fs.readFileSync(file));
|
|
const release = read('releases/latest.json'), commit = read('.qa/embedded-browser-d-code-baseline.json').codeCommit;
|
|
assert.equal(release.installer.version, '1.22.0'); assert.equal(release.installer.qaFixture, null);
|
|
assert.equal(execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8', windowsHide: true }).trim(), commit);
|
|
assert.equal(execFileSync('git', ['status', '--porcelain', '--', 'src', 'scripts', 'tests', 'package.json', 'package-lock.json'], { encoding: 'utf8', windowsHide: true }).trim(), '');
|
|
const paths = execFileSync('git', ['ls-tree', '-r', '--name-only', commit, '--', 'src', 'scripts', 'tests', 'package.json', 'package-lock.json', 'vite.config.ts', 'tsconfig.json', 'index.html', 'mobile.html'], { encoding: 'utf8', windowsHide: true }).trim().split('\n');
|
|
const blobOutput = execFileSync('git', ['cat-file', '--batch'], { input: paths.map(file => commit + ':' + file).join('\n') + '\n', windowsHide: true, maxBuffer: 64 * 1024 * 1024 });
|
|
let position = 0; const inputs = [];
|
|
for (const file of paths) {
|
|
const end = blobOutput.indexOf(10, position), header = blobOutput.subarray(position, end).toString(); assert.match(header, /^[a-f0-9]+ blob \d+$/);
|
|
const length = Number(header.split(' ').at(-1)), committed = blobOutput.subarray(end + 1, end + 1 + length); position = end + 2 + length;
|
|
const bytes = fs.readFileSync(path.join(release.sourceRoot, file));
|
|
const equal = bytes.equals(committed), normalized = bytes.toString('utf8').replaceAll('\r\n', '\n');
|
|
if (!equal) assert.equal(normalized, committed.toString('utf8'), 'Only CRLF normalization allowed: ' + file);
|
|
assert.deepEqual(bytes, fs.readFileSync(file), 'Source candidate matches frozen input: ' + file);
|
|
inputs.push({ path: file, bytes: bytes.length, sha256: hash(bytes), gitSha256: hash(committed), ...(equal ? {} : { normalization: 'Complete CRLF to LF equality' }) });
|
|
}
|
|
assert.equal(position, blobOutput.length);
|
|
const compiled = [];
|
|
for (const directory of ['dist-client', 'dist-server', 'dist-desktop']) {
|
|
const walk = relative => { for (const entry of fs.readdirSync(path.join(directory, relative), { withFileTypes: true })) {
|
|
const file = path.posix.join(directory, relative, entry.name); if (entry.isDirectory()) walk(path.posix.join(relative, entry.name)); else {
|
|
const bytes = fs.readFileSync(file); assert.deepEqual(bytes, fs.readFileSync(path.join(release.portableRoot, file))); compiled.push({ path: file, bytes: bytes.length, sha256: hash(bytes) });
|
|
}
|
|
} }; walk('');
|
|
}
|
|
const identity = validateInstalledVersion(release.portableRoot), sourceManifest = read(path.join(release.sourceRoot, 'MANIFEST.json'));
|
|
assert.equal(sourceManifest.version, '1.22.0');
|
|
for (const artifact of [release.portable, release.source, release.installer]) { assert.equal(fs.statSync(artifact.path).size, artifact.bytes); assert.equal(hash(fs.readFileSync(artifact.path)), artifact.sha256); }
|
|
const result = { success: true, version: '1.22.0', sourceCommit: commit, portableRoot: release.portableRoot, sourceRoot: release.sourceRoot,
|
|
portableIdentity: identity.identitySha256, portableManifestSha256: identity.manifestSha256, sourceManifestSha256: hash(fs.readFileSync(path.join(release.sourceRoot, 'MANIFEST.json'))),
|
|
setupSha256: release.installer.sha256, portable: release.portable, source: release.source, installer: release.installer, inputs, compiled,
|
|
scope: 'Every committed source/test/script/build input bound to frozen Git blobs with full CRLF-only normalization; all current compiled files identical; portable full manifest validated; source/archive/installer identity checked. No model calls.' };
|
|
fs.writeFileSync('.qa/embedded-browser-d-package-binding.json', JSON.stringify(result, null, 2), { flag: 'wx' });
|
|
console.log(JSON.stringify({ success: true, inputs: inputs.length, compiled: compiled.length, portableRoot: release.portableRoot }));
|