v0.2.0: Git-native architecture (#1)
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import { execSync } from "node:child_process";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import * as fs from "node:fs";
|
||||
import { GitBranch } from "../core/git-branch.js";
|
||||
|
||||
function createTempRepo(): string {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "ci-branch-test-"));
|
||||
execSync("git init", { cwd: dir, stdio: "pipe" });
|
||||
execSync('git config user.email "test@test.com"', { cwd: dir, stdio: "pipe" });
|
||||
execSync('git config user.name "Test"', { cwd: dir, stdio: "pipe" });
|
||||
fs.writeFileSync(path.join(dir, "file.txt"), "initial", "utf-8");
|
||||
execSync("git add . && git commit -m 'initial'", { cwd: dir, stdio: "pipe" });
|
||||
return dir;
|
||||
}
|
||||
|
||||
function cleanup(dir: string): void {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
describe("GitBranch", () => {
|
||||
let repoDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
repoDir = createTempRepo();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(repoDir);
|
||||
});
|
||||
|
||||
describe("createPhaseBranch", () => {
|
||||
it("creates a phase branch with correct naming", () => {
|
||||
const gitBranch = new GitBranch(repoDir);
|
||||
const result = gitBranch.createPhaseBranch(1, "authentication");
|
||||
|
||||
expect(result.created).toBe(true);
|
||||
expect(result.name).toBe("phase/01-authentication");
|
||||
});
|
||||
|
||||
it("detects already existing phase branch", () => {
|
||||
const gitBranch = new GitBranch(repoDir);
|
||||
gitBranch.createPhaseBranch(1, "authentication");
|
||||
|
||||
const result = gitBranch.createPhaseBranch(1, "authentication");
|
||||
expect(result.alreadyExisted).toBe(true);
|
||||
expect(result.created).toBe(false);
|
||||
});
|
||||
|
||||
it("zero-pads phase numbers", () => {
|
||||
const gitBranch = new GitBranch(repoDir);
|
||||
const result = gitBranch.createPhaseBranch(3, "real-time-notifications");
|
||||
|
||||
expect(result.name).toBe("phase/03-real-time-notifications");
|
||||
});
|
||||
});
|
||||
|
||||
describe("createMilestoneBranch", () => {
|
||||
it("creates a milestone branch with correct naming", () => {
|
||||
const gitBranch = new GitBranch(repoDir);
|
||||
const result = gitBranch.createMilestoneBranch("v1.0", "mvp");
|
||||
|
||||
expect(result.created).toBe(true);
|
||||
expect(result.name).toBe("milestone/v1.0-mvp");
|
||||
});
|
||||
|
||||
it("detects already existing milestone branch", () => {
|
||||
const gitBranch = new GitBranch(repoDir);
|
||||
gitBranch.createMilestoneBranch("v1.0", "mvp");
|
||||
|
||||
const result = gitBranch.createMilestoneBranch("v1.0", "mvp");
|
||||
expect(result.alreadyExisted).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("listPhases", () => {
|
||||
it("lists phase branches with status", () => {
|
||||
const gitBranch = new GitBranch(repoDir);
|
||||
gitBranch.createPhaseBranch(1, "auth");
|
||||
gitBranch.createPhaseBranch(2, "tasks");
|
||||
|
||||
const phases = gitBranch.listPhases();
|
||||
expect(phases.length).toBeGreaterThanOrEqual(2);
|
||||
|
||||
const phase1 = phases.find((p) => p.phaseNumber === 1);
|
||||
expect(phase1).toBeDefined();
|
||||
expect(phase1!.status).toBe("active");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getPhaseStatus", () => {
|
||||
it("returns status for existing phase branch", () => {
|
||||
const gitBranch = new GitBranch(repoDir);
|
||||
gitBranch.createPhaseBranch(1, "auth");
|
||||
|
||||
const status = gitBranch.getPhaseStatus(1);
|
||||
expect(status).not.toBeNull();
|
||||
expect(status!.phaseNumber).toBe(1);
|
||||
expect(status!.status).toBe("active");
|
||||
});
|
||||
|
||||
it("returns null for non-existent phase", () => {
|
||||
const gitBranch = new GitBranch(repoDir);
|
||||
const status = gitBranch.getPhaseStatus(99);
|
||||
expect(status).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("slugify", () => {
|
||||
it("creates correct branch slugs", () => {
|
||||
const gitBranch = new GitBranch(repoDir);
|
||||
const result = gitBranch.createPhaseBranch(1, "Real-Time Notifications & Stuff!");
|
||||
expect(result.name).toMatch(/^phase\/01-/);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user