Fix MVP audit evidence pipeline

This commit is contained in:
2026-06-08 08:33:15 +02:00
parent a45b92ea0a
commit ff18fc202e
16 changed files with 771 additions and 52 deletions

View File

@@ -224,6 +224,50 @@ test("persistAuditGenerationResult inserts into auditGenerations", () => {
);
});
test("getAuditGenerationEvidence loads latest successful website enrichment evidence by lead", () => {
const evidenceSource = extractExportSource("getAuditGenerationEvidence");
assert.equal(
hasPattern(
evidenceSource,
/query\("agentRuns"\)[\s\S]*withIndex\("by_type_and_status_and_leadId"[\s\S]*eq\("type",\s*"website_enrichment"\)[\s\S]*eq\("status",\s*"succeeded"\)[\s\S]*eq\("leadId",\s*lead\._id\)[\s\S]*order\("desc"\)[\s\S]*take\(1\)/,
),
true,
"Evidence query should locate the latest successful website_enrichment run for the same lead.",
);
assert.equal(
hasPattern(
evidenceSource,
/const\s+enrichmentEvidenceRunId\s*=\s*latestSuccessfulEnrichmentRun\[0\]\?\._id\s*\?\?\s*args\.runId/,
),
true,
"Evidence query should fall back to the audit run only when no enrichment run exists.",
);
for (const table of [
"websiteCrawlPages",
"websiteTechnicalChecks",
]) {
assert.equal(
hasPattern(
evidenceSource,
new RegExp(
`query\\("${table}"\\)[\\s\\S]*withIndex\\("by_runId"[\\s\\S]*eq\\("runId",\\s*enrichmentEvidenceRunId\\)`,
),
),
true,
`${table} should be loaded from the enrichment evidence run.`,
);
}
assert.equal(
hasPattern(
evidenceSource,
/const\s+screenshots\s*=\s*\[\s*\.\.\.auditCaptureScreenshotsByRun,\s*\.\.\.enrichmentScreenshotsByRun\s*\]/,
),
true,
"Evidence query should include audit-run ScreenshotOne captures and enrichment screenshots.",
);
});
test("truncateWithMarker is byte-capped and marker-safe in persistence", () => {
assert.equal(
hasPattern(auditGenerationSource, /const markerBytes = byteLength\(TRUNCATION_MARKER\);/),