Files
Agent-Workbench/docs/embedded-browser-release-evidence/verifiers/audit-b-git.mjs
T

25 lines
1.6 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';
const root = 'docs/embedded-browser-b-rejected-candidate-evidence';
const manifest = JSON.parse(fs.readFileSync(root + '/manifest.json'));
const files = ['manifest.json', ...manifest.files.map(row => row.path)].map(file => path.posix.join(root, file));
for (let index = 0; index < files.length; index += 16) {
const batch = files.slice(index, index + 16);
const output = execFileSync('git', ['cat-file', '--batch'], { input: batch.map(file => 'HEAD:' + file).join('\n') + '\n', windowsHide: true, maxBuffer: 64 * 1024 * 1024 });
let position = 0;
for (const file of batch) {
const end = output.indexOf(10, position), header = output.subarray(position, end).toString('utf8');
assert.match(header, /^[a-f0-9]+ blob \d+$/, file);
const length = Number(header.split(' ').at(-1));
assert.deepEqual(output.subarray(end + 1, end + 1 + length), fs.readFileSync(file), file);
position = end + 2 + length;
}
assert.equal(position, output.length);
}
const result = { success: true, exactBlobs: files.length, manifestSha256: createHash('sha256').update(fs.readFileSync(root + '/manifest.json')).digest('hex'), scope: 'Every original rejected B evidence file and manifest is present in local Git with exact bytes, including ignored logs. Original source overall result remains failed.' };
fs.writeFileSync('.qa/embedded-browser-c-b-git-evidence.json', JSON.stringify(result, null, 2) + '\n', { flag: 'wx' });
console.log(JSON.stringify(result));