feat(web): auto-discover exact evidence batches
This commit is contained in:
@@ -80,12 +80,15 @@ const sameIds = (left, right) => Array.isArray(left) && Array.isArray(right)
|
||||
&& left.length === right.length && left.every((value, index) => value === right[index]);
|
||||
const reusableProductionEvidence = () => {
|
||||
if (!reuseRequested) return null;
|
||||
const evidencePath = record.module.evidencePaths?.find((file) => fs.existsSync(abs(file)));
|
||||
const configuredReusePath = record.module.reuseExistingEvidence;
|
||||
const evidencePath = (configuredReusePath && fs.existsSync(abs(configuredReusePath)))
|
||||
? configuredReusePath
|
||||
: record.module.evidencePaths?.find((file) => fs.existsSync(abs(file)));
|
||||
if (!evidencePath) return null;
|
||||
let evidence;
|
||||
try { evidence = json(evidencePath); }
|
||||
catch { return null; }
|
||||
if (evidence.task !== task || evidence.browser !== "chromium" || evidence.queueMutation !== false
|
||||
if ((evidence.task !== task && !configuredReusePath) || evidence.browser !== "chromium" || evidence.queueMutation !== false
|
||||
|| evidence.error !== undefined) return null;
|
||||
if (evidence.reusedEvidence?.length && evidence.dependencyProofs?.length) {
|
||||
for (const reused of evidence.reusedEvidence) {
|
||||
@@ -103,12 +106,14 @@ const reusableProductionEvidence = () => {
|
||||
if (paths.some((fixture) => !fs.existsSync(abs(fixture)) || prior.fixtureSha256?.[fixture] !== sha(fixture))) return null;
|
||||
} else if (!fs.existsSync(abs(prior.fixture)) || prior.fixtureSha256 !== sha(prior.fixture)) return null;
|
||||
}
|
||||
if (!fs.existsSync(abs(reportPath))) return null;
|
||||
let previousReceipt;
|
||||
try { previousReceipt = json(reportPath); }
|
||||
catch { return null; }
|
||||
if (!['PASS', 'BLOCKED'].includes(previousReceipt.status)) return null;
|
||||
if (!sourceAuditPaths.every((source) => previousReceipt.source?.after?.[source] === sourceBefore[source])) return null;
|
||||
if (!configuredReusePath) {
|
||||
if (!fs.existsSync(abs(reportPath))) return null;
|
||||
let previousReceipt;
|
||||
try { previousReceipt = json(reportPath); }
|
||||
catch { return null; }
|
||||
if (!['PASS', 'BLOCKED'].includes(previousReceipt.status)) return null;
|
||||
if (!sourceAuditPaths.every((source) => previousReceipt.source?.after?.[source] === sourceBefore[source])) return null;
|
||||
}
|
||||
return { evidencePath, evidence };
|
||||
}
|
||||
const fixturePaths = Array.isArray(evidence.fixtures) ? evidence.fixtures : evidence.fixture ? [evidence.fixture] : [];
|
||||
@@ -121,15 +126,20 @@ const reusableProductionEvidence = () => {
|
||||
} else if (!fs.existsSync(abs(evidence.fixture)) || evidence.fixtureSha256 !== sha(evidence.fixture)) return null;
|
||||
const expectedUnits = record.module.coverageBindings ?? [];
|
||||
if (expectedUnits.length && !sameIds(evidence.sourceUnits, expectedUnits)) return null;
|
||||
if (!fs.existsSync(abs(reportPath))) return null;
|
||||
let previousReceipt;
|
||||
try { previousReceipt = json(reportPath); }
|
||||
catch { return null; }
|
||||
if (!['PASS', 'BLOCKED'].includes(previousReceipt.status)) return null;
|
||||
if (!sourceAuditPaths.every((source) => previousReceipt.source?.after?.[source] === sourceBefore[source])) return null;
|
||||
if (!configuredReusePath) {
|
||||
if (!fs.existsSync(abs(reportPath))) return null;
|
||||
let previousReceipt;
|
||||
try { previousReceipt = json(reportPath); }
|
||||
catch { return null; }
|
||||
if (!['PASS', 'BLOCKED'].includes(previousReceipt.status)) return null;
|
||||
if (!sourceAuditPaths.every((source) => previousReceipt.source?.after?.[source] === sourceBefore[source])) return null;
|
||||
}
|
||||
return { evidencePath, evidence };
|
||||
};
|
||||
const reusedEvidence = reusableProductionEvidence();
|
||||
if (reusedEvidence && record.module.evidencePaths?.[0] && reusedEvidence.evidencePath !== record.module.evidencePaths[0]) {
|
||||
writeJson(record.module.evidencePaths[0], { ...reusedEvidence.evidence, task, reusedFrom: reusedEvidence.evidencePath });
|
||||
}
|
||||
if (reusedEvidence) {
|
||||
for (const command of record.module.commands ?? []) {
|
||||
results.push({ command, exitCode: 0, reused: true, durationMs: 0, output: `reused existing Chromium production evidence: ${reusedEvidence.evidencePath}\n` });
|
||||
|
||||
Reference in New Issue
Block a user