136 lines · 5.6 KB
import { describe, expect, test } from "bun:test";
import { describeMessages, diffExcerpt, isLockfile, mockSuggestion, parseSuggestion } from "./prompt";
import type { DescribeInput } from "./prompt";

function file(path: string, extra: Partial<DescribeInput["diff"]["files"][number]> = {}) {
  return {
    path,
    oldPath: null,
    status: "modified" as const,
    oldSha: "a",
    newSha: "b",
    oldMode: "100644",
    newMode: "100644",
    additions: 1,
    deletions: 1,
    binary: false,
    truncated: false,
    ...extra,
  };
}

function chunk(path: string, body = "@@ -1 +1 @@\n-old\n+new\n"): string {
  return `diff --git a/${path} b/${path}\nindex 1..2 100644\n--- a/${path}\n+++ b/${path}\n${body}`;
}

const input: DescribeInput = {
  base: "main",
  head: "feature/retry",
  commits: [
    { subject: "feat: add retry to uploader", message: "feat: add retry to uploader\n\nThree attempts with backoff." },
    { subject: "chore: bump deps", message: "chore: bump deps" },
  ],
  diff: {
    patch:
      chunk("src/upload.ts") + chunk("bun.lock") + chunk("logo.png", "Binary files a/logo.png and b/logo.png differ\n"),
    files: [file("src/upload.ts"), file("bun.lock", { additions: 400 }), file("logo.png", { binary: true })],
  },
};

describe("describeMessages", () => {