Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions review-enrichment/test/render-contract.test.ts
Original file line number Diff line number Diff line change
@@ -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/);
});