more
This commit is contained in:
@@ -197,6 +197,18 @@ function initialize(projectRoot = process.cwd(), options = {}) {
|
||||
const registry = new Map();
|
||||
let artifactOutcome;
|
||||
let relitigateSus = false;
|
||||
const inspection = options.inspection || null;
|
||||
if (inspection && typeof inspection.visit !== "function") {
|
||||
throw new Error("Inspection requires a visit(filename) callback");
|
||||
}
|
||||
function inspectVisit(filename) {
|
||||
if (inspection) inspection.visit(filename);
|
||||
}
|
||||
function requireCurrentArtifact(filename, isCurrent) {
|
||||
if (!inspection) return;
|
||||
if (!isCurrent) throw new Error(`Vacuum verification: missing or stale artifact: ${filename}`);
|
||||
inspectVisit(filename);
|
||||
}
|
||||
|
||||
const presentation = settings.get("presentation") || {};
|
||||
const showOnEnsure = presentation.showOnEnsure === true;
|
||||
@@ -214,12 +226,25 @@ function initialize(projectRoot = process.cwd(), options = {}) {
|
||||
}
|
||||
|
||||
function reportBuild(value) {
|
||||
// Diagnostic-only in normal runs; fail closed if a custom transformer
|
||||
// tries to build while the vacuum is inspecting stored results.
|
||||
if (inspection) throw new Error(`Vacuum verification: rebuild attempted: ${displayArtifactLabel(value)}`);
|
||||
if (showOnBuild) console.log(`Building artifact: ${displayArtifactLabel(value)}`);
|
||||
}
|
||||
|
||||
async function projectResolveArtifact(filename, sources, producer) {
|
||||
reportEnsure(filename);
|
||||
const existing = readArtifact(filename);
|
||||
if (inspection) {
|
||||
const matching = existing && sameSourceHash(existing, sources);
|
||||
if (!matching) throw new Error(`Vacuum verification: missing or stale artifact: ${displayArtifactLabel(filename)}`);
|
||||
const expected = statusOf(existing) === STATUS_SUS ? STATUS_SUS : inheritedStatus(sources);
|
||||
if (statusOf(existing) !== expected) {
|
||||
throw new Error(`Vacuum verification: status not reconciled: ${displayArtifactLabel(filename)}`);
|
||||
}
|
||||
inspectVisit(filename);
|
||||
return existing;
|
||||
}
|
||||
if (existing && sameSourceHash(existing, sources)) {
|
||||
const reconciled = reconcileArtifactStatus(filename, existing, sources);
|
||||
if (!(relitigateSus && statusOf(reconciled) === STATUS_SUS)) return reconciled;
|
||||
@@ -263,16 +288,37 @@ function initialize(projectRoot = process.cwd(), options = {}) {
|
||||
buildNode,
|
||||
buildBinaryNode,
|
||||
resolveArtifact: projectResolveArtifact,
|
||||
readArtifact,
|
||||
readArtifact(filename) {
|
||||
const result = readArtifact(filename);
|
||||
if (inspection && result) inspectVisit(filename);
|
||||
return result;
|
||||
},
|
||||
sameSourceHash,
|
||||
statusOf,
|
||||
sus,
|
||||
reconcileArtifactStatus,
|
||||
reconcileArtifactStatus(filename, node, sources = {}) {
|
||||
if (inspection) {
|
||||
const current = statusOf(node);
|
||||
const expected = current === STATUS_SUS ? STATUS_SUS : inheritedStatus(sources);
|
||||
if (current !== expected) throw new Error(`Vacuum verification: status not reconciled: ${displayArtifactLabel(filename)}`);
|
||||
inspectVisit(filename);
|
||||
return node;
|
||||
}
|
||||
return reconcileArtifactStatus(filename, node, sources);
|
||||
},
|
||||
requireCurrentArtifact,
|
||||
shouldRelitigateSus(node) {
|
||||
return relitigateSus && statusOf(node) === STATUS_SUS;
|
||||
},
|
||||
invalidateArtifact,
|
||||
fileNode,
|
||||
invalidateArtifact(filename) {
|
||||
if (inspection) throw new Error(`Vacuum verification: invalidation attempted: ${displayArtifactLabel(filename)}`);
|
||||
return invalidateArtifact(filename);
|
||||
},
|
||||
fileNode(filename) {
|
||||
const result = fileNode(filename);
|
||||
if (inspection) inspectVisit(filename);
|
||||
return result;
|
||||
},
|
||||
codeNode,
|
||||
|
||||
// UI/diagnostic reporting only. These must never participate in
|
||||
|
||||
Reference in New Issue
Block a user