Inspect constructor values and contexts without unrelated derivation closures (#931)
This commit is contained in:
parent
61881f9cda
commit
4f672d027d
+20
-24
@@ -34,6 +34,7 @@ function identity() {
|
||||
derivation = compiler.drvPath;
|
||||
yarn = compiler.yarn-freestanding.drvPath;
|
||||
source = toString compiler.src;
|
||||
metadata = (import ((/. + ${nixString(source)}) + "/source-qualification-metadata.nix")) compiler;
|
||||
}`;
|
||||
const result = spawnSync(
|
||||
"nix",
|
||||
@@ -52,17 +53,6 @@ function identity() {
|
||||
assert.equal(result.status, 0, result.error?.message ?? result.stderr);
|
||||
return JSON.parse(result.stdout);
|
||||
}
|
||||
function derivationData(file) {
|
||||
const result = spawnSync(
|
||||
"nix",
|
||||
["--store", "local?root=" + process.env.QUIXOS_PROTOCOL_EVALUATION_STORE, "derivation", "show", file],
|
||||
{ encoding: "utf8", timeout: 30000, maxBuffer: 2097152 },
|
||||
);
|
||||
assert.equal(result.status, 0, result.error?.message ?? result.stderr);
|
||||
const entries = Object.values(JSON.parse(result.stdout));
|
||||
assert.equal(entries.length, 1);
|
||||
return entries[0];
|
||||
}
|
||||
function summarized(value) {
|
||||
const text = JSON.stringify(value) ?? "undefined";
|
||||
return text.length < 500
|
||||
@@ -74,7 +64,7 @@ function summarized(value) {
|
||||
};
|
||||
}
|
||||
function structuralDifferences(actual, expected, field = "", result = []) {
|
||||
if (field === "outputs" || field === "env.out" || JSON.stringify(actual) === JSON.stringify(expected)) return result;
|
||||
if (JSON.stringify(actual) === JSON.stringify(expected)) return result;
|
||||
if (
|
||||
Array.isArray(actual) &&
|
||||
Array.isArray(expected) &&
|
||||
@@ -99,15 +89,24 @@ function structuralDifferences(actual, expected, field = "", result = []) {
|
||||
for (const key of new Set([...Object.keys(actual), ...Object.keys(expected)]))
|
||||
structuralDifferences(actual[key], expected[key], field ? field + "." + key : key, result);
|
||||
} else {
|
||||
result.push({ field, actual: summarized(actual), expected: summarized(expected) });
|
||||
const difference = { field, actual: summarized(actual), expected: summarized(expected) };
|
||||
if (typeof actual === "string" && typeof expected === "string" && Math.max(actual.length, expected.length) >= 500) {
|
||||
let offset = 0;
|
||||
while (offset < actual.length && offset < expected.length && actual[offset] === expected[offset]) offset++;
|
||||
difference.offset = offset;
|
||||
difference.actualExcerpt = actual.slice(Math.max(0, offset - 80), offset + 200);
|
||||
difference.expectedExcerpt = expected.slice(Math.max(0, offset - 80), offset + 200);
|
||||
}
|
||||
result.push(difference);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function baselineDifference(baseline) {
|
||||
const { metadata, ...identities } = baseline;
|
||||
console.log(
|
||||
"PROTOCOL_SOURCE_BASELINE: " +
|
||||
JSON.stringify({
|
||||
actual: baseline,
|
||||
actual: identities,
|
||||
expected: config.expected,
|
||||
expectedSource: config.expectedSource,
|
||||
evaluatorVersion: config.evaluatorVersion,
|
||||
@@ -115,15 +114,10 @@ function baselineDifference(baseline) {
|
||||
narHashContext: config.narHashContext,
|
||||
}),
|
||||
);
|
||||
try {
|
||||
const actual = derivationData(baseline.derivation);
|
||||
const expected = derivationData(config.productionDerivation);
|
||||
console.log(
|
||||
"PROTOCOL_SOURCE_BASELINE_DIFF: " + JSON.stringify(structuralDifferences(actual, expected)).slice(0, 10000),
|
||||
);
|
||||
} catch (error) {
|
||||
console.log("PROTOCOL_SOURCE_BASELINE_DIAGNOSTIC_UNAVAILABLE: " + String(error.message).slice(0, 2000));
|
||||
}
|
||||
console.log(
|
||||
"PROTOCOL_SOURCE_BASELINE_DIFF: " +
|
||||
JSON.stringify(structuralDifferences(metadata, config.expectedMetadata)).slice(0, 10000),
|
||||
);
|
||||
}
|
||||
async function edit(file, mutate, check) {
|
||||
const before = await fs.readFile(file, "utf8");
|
||||
@@ -244,7 +238,9 @@ try {
|
||||
JSON.stringify(
|
||||
{
|
||||
codec: "quixos-protocol-source-qualification/1",
|
||||
...baseline,
|
||||
derivation: baseline.derivation,
|
||||
yarn: baseline.yarn,
|
||||
source: baseline.source,
|
||||
cases,
|
||||
metadataContext: config.narHashContext,
|
||||
evaluatorVersion: config.evaluatorVersion,
|
||||
|
||||
Reference in New Issue
Block a user