From ab2738484d3d3e874a181678e0e99d5b4be9deb7 Mon Sep 17 00:00:00 2001 From: Florcita Date: Wed, 1 Jul 2026 11:40:49 -0400 Subject: [PATCH] test: cover REES render contract --- .../test/render-contract.test.ts | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 review-enrichment/test/render-contract.test.ts diff --git a/review-enrichment/test/render-contract.test.ts b/review-enrichment/test/render-contract.test.ts new file mode 100644 index 0000000000..0e70009275 --- /dev/null +++ b/review-enrichment/test/render-contract.test.ts @@ -0,0 +1,99 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; + +import { buildBrief } from "../dist/brief.js"; +import { renderBrief } from "../dist/render.js"; +import type { AnalyzerRegistry } from "../dist/analyzers/types.js"; + +test("renderBrief renders descriptor-owned sections and built-in fallback sections", () => { + const dependency = { + ecosystem: "npm", + package: "left-pad", + from: null, + to: "1.3.0", + direction: "add" as const, + cves: [ + { + id: "GHSA-render-test", + severity: "high" as const, + summary: "fixture vulnerability", + fixedIn: "1.3.1", + }, + ], + }; + const actionPin = { + file: ".github/workflows/ci.yml", + line: 12, + action: "actions/checkout", + ref: "v4", + }; + + const { promptSection, systemSuffix } = renderBrief({ + dependency: [dependency], + actionPin: [actionPin], + }); + + assert.match(promptSection, /Dependency vulnerabilities/); + assert.match(promptSection, /left-pad@1\.3\.0/); + assert.match(promptSection, /Unpinned GitHub Actions/); + assert.match(promptSection, /actions\/checkout@v4/); + assert.match(systemSuffix, /EXTERNAL REVIEW BRIEF/); +}); + +test("renderBrief omits descriptor-owned and fallback sections for empty finding lists", () => { + const { promptSection, systemSuffix } = renderBrief({ + dependency: [], + actionPin: [], + }); + + assert.equal(promptSection, ""); + assert.equal(systemSuffix, ""); +}); + +test("buildBrief reports partial analyzer results as degraded", async () => { + const analyzers: AnalyzerRegistry = { + dependency: async () => [ + { + ecosystem: "npm", + package: "fixture-lib", + from: null, + to: "2.0.0", + direction: "add", + partial: true, + cves: [ + { + id: "GHSA-partial-test", + severity: "medium", + summary: "fixture partial vulnerability", + fixedIn: null, + }, + ], + }, + ], + }; + + const brief = await buildBrief( + { + repoFullName: "JSONbored/gittensory", + prNumber: 2037, + analyzers: ["dependency"], + files: [ + { + path: "package.json", + patch: '@@ -1,0 +1,1 @@\n+{"dependencies":{"fixture-lib":"2.0.0"}}', + }, + ], + budget: { timeoutMs: 1000 }, + }, + analyzers, + ); + + assert.equal(brief.partial, true); + assert.equal(brief.analyzerStatus.dependency, "degraded"); + assert.equal(brief.telemetry.analyzers.dependency?.partialStatus, "partial"); + assert.equal( + brief.telemetry.analyzers.dependency?.partialReason, + "analyzer_partial", + ); + assert.match(brief.promptSection, /GHSA-partial-test/); +});