Files
Agent-Workbench/docs/model-protocols-f-release-evidence/112-shorten-protocol-source.mjs
T
2026-11-01 00:19:52 +08:00

19 lines
1.9 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { createHash, randomUUID } from 'node:crypto';
const pointerFile = '.qa/archives-validation.json', report = JSON.parse(fs.readFileSync(pointerFile, 'utf8'));
assert.equal(report.success, true); assert.equal(report.version, '1.17.0'); assert.equal(report.shortPhysicalPath, undefined);
const qaRoot = fs.realpathSync.native('D:/AWQA17'), original = fs.realpathSync.native(report.extractionRoot);
assert.ok(original.startsWith(qaRoot + path.sep));
const destination = path.resolve(qaRoot, 's-' + randomUUID().slice(0, 8)); assert.ok(destination.startsWith(qaRoot + path.sep)); assert.equal(fs.existsSync(destination), false);
const originalManifest = fs.readFileSync(path.join(original, 'MANIFEST.json')), manifest = JSON.parse(originalManifest);
fs.renameSync(original, destination);
assert.deepEqual(fs.readFileSync(path.join(destination, 'MANIFEST.json')), originalManifest);
for (const item of manifest.files) { const file = path.resolve(destination, item.path); assert.ok(file.startsWith(destination + path.sep)); const bytes = fs.readFileSync(file); assert.equal(bytes.length, item.bytes); assert.equal(createHash('sha256').update(bytes).digest('hex'), item.sha256, item.path); }
report.extractionRoot = destination;
report.shortPhysicalPath = { original, destination, sameVolumeRename: true, verifiedFiles: manifest.files.length, originalManifestSha256: createHash('sha256').update(originalManifest).digest('hex'), reason: 'Avoid the known Git management path byte limit in nested engineering fixtures; every extracted byte remains unchanged.' };
fs.writeFileSync('.qa/protocol-f-source-short-path.json', JSON.stringify(report, null, 2) + '\n', { flag: 'wx' });
fs.writeFileSync(pointerFile, JSON.stringify(report, null, 2) + '\n');
console.log(JSON.stringify({ success: true, ...report.shortPhysicalPath }));