import { describe, expect, mock, test } from "bun:test";
mock.module("cloudflare:workers", () => ({
env: {},
waitUntil: () => undefined,
}));
const { agentReview, requireHumanForMerge, UNCONFIRMED_APPROVAL } = await import("./review-outcome");
describe("agent reviews", () => {
test("an approval without human confirmation is stored as a comment that does not count", () => {
const review = agentReview("approve", false, "LGTM");
expect(review.state).toBe("commented");
expect(review.unconfirmed).toBe(true);
expect(review.text.startsWith(UNCONFIRMED_APPROVAL)).toBe(true);
});
test("a human-confirmed approval counts", () => {
expect(agentReview("approve", true, "LGTM")).toEqual({
state: "approved",
text: "LGTM",
unconfirmed: false,
});
});
test("other events keep their state", () => {
expect(agentReview("request_changes", false, "no").state).toBe("changes_requested");
expect(agentReview("comment", false, "hm").state).toBe("commented");
});
test("merging refuses when no human can confirm", () => {
expect(() => requireHumanForMerge(false)).toThrow("human");
expect(() => requireHumanForMerge(true)).not.toThrow();
});
});