51 lines
2.9 KiB
JavaScript
51 lines
2.9 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import crypto from "node:crypto";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
const absolute = (file) => path.join(root, file);
|
|
const read = (file) => fs.readFileSync(absolute(file), "utf8");
|
|
const json = (file) => JSON.parse(read(file));
|
|
const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(absolute(file))).digest("hex");
|
|
|
|
const historicalPath = "tests/golden/WBV2-P0-002/source-hashes.json";
|
|
const currentPath = "tests/golden/WBV2-P10-001/current-source-hashes.json";
|
|
const reportPath = "tests/golden/WBV2-P10-001/inventory-rebaseline-report.json";
|
|
const dependencyPath = "tests/golden/WBV2-P10-001/dependency-inventory.current.json";
|
|
const historicalDependencyPath = "tests/golden/M13-05C/dependency-inventory.json";
|
|
const historical = json(historicalPath);
|
|
const current = json(currentPath);
|
|
const report = json(reportPath);
|
|
const dependency = json(dependencyPath);
|
|
const historicalDependency = json(historicalDependencyPath);
|
|
|
|
assert.equal(current.schemaVersion, 1);
|
|
assert.equal(current.task, "WBV2-P10-001");
|
|
assert.equal(current.operation, "CURRENT_WBV2_SOURCE_HASH_BASELINE");
|
|
assert.equal(current.historicalSourceHashesSha256, sha256(historicalPath));
|
|
const drift = [];
|
|
for (const [file, expected] of Object.entries(historical.sources)) {
|
|
const actual = sha256(file);
|
|
assert.equal(current.sources[file], actual, `current source hash drift: ${file}`);
|
|
if (actual !== expected) drift.push({ file, expected, actual });
|
|
}
|
|
assert.deepEqual(drift, current.drift.map(({ file, expected, actual }) => ({ file, expected, actual })));
|
|
assert.deepEqual(drift.map((entry) => entry.file), ["docs/BLENDER_WEB_PARITY_TASK_PLAN_V2.json"]);
|
|
assert.equal(drift[0].actual, "0f4750e45f2d1ca7d68faa35743e5b758ea8091f18d1d0e312ab548228d6f782");
|
|
assert.equal(report.status, "PASS");
|
|
assert.equal(report.task, "WBV2-P10-001");
|
|
assert.equal(report.currentSourceBaseline.sha256, sha256(currentPath));
|
|
assert.equal(report.currentSourceBaseline.planSha256, drift[0].actual);
|
|
assert.equal(report.historical.sourceHashesSha256, sha256(historicalPath));
|
|
assert.equal(report.dependency.lockfileHashStable, true);
|
|
assert.equal(report.dependency.rootsStable, true);
|
|
assert.equal(report.dependency.closureStable, true);
|
|
assert.deepEqual(dependency.roots, historicalDependency.roots);
|
|
assert.deepEqual(dependency.categoryCounts, historicalDependency.categoryCounts);
|
|
assert.deepEqual(dependency.packages, historicalDependency.packages);
|
|
assert.equal(dependency.lockfile.sha256, historicalDependency.lockfile.sha256);
|
|
assert.equal(dependency.packages.length, 144);
|
|
process.stdout.write(`wbv2-inventory-rebaseline-ok task=WBV2-P10-001 planDrift=${drift.length} dependencyPackages=${dependency.packages.length} closureStable=1 historicalHashesPreserved=1\n`);
|