65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import { test, expect, describe } from "bun:test";
|
|
import { buildPrompt, SYSTEM_PROMPT } from "../src/prompt";
|
|
import type { ProjectContext } from "../src/types";
|
|
|
|
describe("prompt", () => {
|
|
test("SYSTEM_PROMPT contains Conventional Commits format", () => {
|
|
expect(SYSTEM_PROMPT).toContain("<type>(<scope>)");
|
|
expect(SYSTEM_PROMPT).toContain("feat");
|
|
expect(SYSTEM_PROMPT).toContain("fix");
|
|
});
|
|
|
|
test("buildPrompt with full context", () => {
|
|
const ctx: ProjectContext = {
|
|
readme: "A test project",
|
|
packageDescription: "Test package",
|
|
structure: "src/, tests/",
|
|
recentCommits: ["abc123 feat: initial commit"],
|
|
diff: "+new line\n-old line",
|
|
};
|
|
|
|
const prompt = buildPrompt(ctx);
|
|
|
|
expect(prompt).toContain("## Project Context");
|
|
expect(prompt).toContain("Test package");
|
|
expect(prompt).toContain("src/, tests/");
|
|
expect(prompt).toContain("A test project");
|
|
expect(prompt).toContain("## Recent Commits");
|
|
expect(prompt).toContain("abc123 feat: initial commit");
|
|
expect(prompt).toContain("## Staged Changes");
|
|
expect(prompt).toContain("+new line");
|
|
expect(prompt).toContain("Generate a commit message");
|
|
});
|
|
|
|
test("buildPrompt with minimal context (only diff)", () => {
|
|
const ctx: ProjectContext = {
|
|
readme: null,
|
|
packageDescription: null,
|
|
structure: null,
|
|
recentCommits: [],
|
|
diff: "+added code",
|
|
};
|
|
|
|
const prompt = buildPrompt(ctx);
|
|
|
|
expect(prompt).not.toContain("## Project Context");
|
|
expect(prompt).not.toContain("## Recent Commits");
|
|
expect(prompt).toContain("## Staged Changes");
|
|
expect(prompt).toContain("+added code");
|
|
});
|
|
|
|
test("buildPrompt includes diff as-is (truncation is caller's responsibility)", () => {
|
|
const diff = "+short diff content";
|
|
const ctx: ProjectContext = {
|
|
readme: null,
|
|
packageDescription: null,
|
|
structure: null,
|
|
recentCommits: [],
|
|
diff,
|
|
};
|
|
|
|
const prompt = buildPrompt(ctx);
|
|
expect(prompt).toContain(diff);
|
|
});
|
|
});
|