49 lines
2.9 KiB
JavaScript
49 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 ledgerPath = "tests/golden/WBV2-P12-001/capability-ledger.json";
|
|
const reportPath = "tests/golden/WBV2-P12-001/capability-ledger-report.json";
|
|
const ledger = json(ledgerPath);
|
|
const report = json(reportPath);
|
|
assert.equal(ledger.schemaVersion, 1);
|
|
assert.equal(ledger.task, "WBV2-P12-001");
|
|
assert.equal(ledger.operation, "EXISTING_CAPABILITY_LEDGER");
|
|
assert.equal(report.status, "PASS");
|
|
assert.equal(report.task, "WBV2-P12-001");
|
|
assert.equal(report.ledgerSha256, sha256(ledgerPath));
|
|
assert.equal(ledger.inventory.total, 6900);
|
|
assert.equal(ledger.inventory.pending, 6618);
|
|
assert.equal(ledger.inventory.claimedComplete, 0);
|
|
assert.equal(ledger.sourceManifests.length, 34);
|
|
assert.equal(ledger.policy.reuseReadOnly, true);
|
|
assert.equal(ledger.policy.noRepeatedExecution, true);
|
|
assert.equal(ledger.policy.historicalDriftExplicit, true);
|
|
assert.equal(ledger.engineBoundClaims, 6);
|
|
for (const entry of ledger.sourceManifests) {
|
|
assert.equal(entry.status, "done", `${entry.task} is not done`);
|
|
assert.ok(fs.existsSync(absolute(entry.manifest)), entry.manifest);
|
|
assert.equal(entry.manifestSha256, sha256(entry.manifest), `${entry.task} manifest hash drift`);
|
|
assert.equal(entry.artifactCount, entry.artifacts.length);
|
|
assert.equal(entry.currentDriftCount, entry.artifacts.filter((artifact) => artifact.currentHash !== artifact.recordedSha256).length);
|
|
assert.ok(["EXACT_RECORDED", "ENGINE_BOUND_EXACT", "HISTORICAL_DRIFT_RECORDED"].includes(entry.evidenceClass));
|
|
for (const artifact of entry.artifacts) {
|
|
assert.ok(artifact.path && artifact.recordedSha256);
|
|
assert.equal(artifact.exists, fs.existsSync(absolute(artifact.path)));
|
|
if (artifact.exists) assert.equal(artifact.currentHash, sha256(artifact.path));
|
|
}
|
|
}
|
|
const current = ledger.sourceManifests.filter((entry) => entry.evidenceClass === "ENGINE_BOUND_EXACT");
|
|
assert.deepEqual(current.map((entry) => entry.task), ["WBV2-P10-002", "WBV2-P11-004"]);
|
|
assert.equal(ledger.summary.manifestsDone, 34);
|
|
assert.equal(ledger.summary.historicalDriftManifests, ledger.sourceManifests.filter((entry) => entry.currentDriftCount > 0).length);
|
|
assert.equal(ledger.summary.currentEngineBoundManifests, 2);
|
|
process.stdout.write(`wbv2-capability-ledger-ok task=WBV2-P12-001 manifests=${ledger.sourceManifests.length} engineBound=${ledger.engineBoundClaims} driftManifests=${ledger.summary.historicalDriftManifests} inventoryRemaining=${ledger.inventory.pending}\n`);
|