v0.2.0: Git-native architecture (#1)
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import * as os from "node:os";
|
||||
import { initCI, loadConfig, saveConfig, isCIInitialized, ensureCIDir } from "../core/config.js";
|
||||
import { DEFAULT_CI_CONFIG } from "../types/config.js";
|
||||
|
||||
describe("CI Config", () => {
|
||||
let tempDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "ci-config-test-"));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe("initCI", () => {
|
||||
it("initializes a new CI project with default config", () => {
|
||||
const config = initCI(tempDir);
|
||||
expect(config.autonomy.level).toBe("full");
|
||||
expect(isCIInitialized(tempDir)).toBe(true);
|
||||
});
|
||||
|
||||
it("initializes with custom config merged on top of defaults", () => {
|
||||
const config = initCI(tempDir, {
|
||||
autonomy: { ...DEFAULT_CI_CONFIG.autonomy, level: "guided" },
|
||||
});
|
||||
expect(config.autonomy.level).toBe("guided");
|
||||
expect(config.autonomy.clarify_budget).toBe(10);
|
||||
expect(config.model_profile).toBe("quality");
|
||||
});
|
||||
|
||||
it("creates .ci/ directory structure", () => {
|
||||
initCI(tempDir);
|
||||
expect(fs.existsSync(path.join(tempDir, ".ci"))).toBe(true);
|
||||
expect(fs.existsSync(path.join(tempDir, ".ci", "config.json"))).toBe(true);
|
||||
});
|
||||
|
||||
it("deep merges nested config", () => {
|
||||
const config = initCI(tempDir, {
|
||||
autonomy: { ...DEFAULT_CI_CONFIG.autonomy, level: "supervised" },
|
||||
});
|
||||
expect(config.autonomy.level).toBe("supervised");
|
||||
expect(config.autonomy.max_revision_iterations).toBe(3);
|
||||
expect(config.autonomy.escalation_hooks).toEqual(["deploy", "delete_data", "merge_to_main"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadConfig", () => {
|
||||
it("returns default config when no config file exists", () => {
|
||||
const config = loadConfig(tempDir);
|
||||
expect(config).toEqual(DEFAULT_CI_CONFIG);
|
||||
});
|
||||
|
||||
it("loads and deep merges config from file", () => {
|
||||
initCI(tempDir, { autonomy: { ...DEFAULT_CI_CONFIG.autonomy, decision_confidence_threshold: 0.85 } });
|
||||
const config = loadConfig(tempDir);
|
||||
expect(config.autonomy.decision_confidence_threshold).toBe(0.85);
|
||||
expect(config.autonomy.level).toBe("full");
|
||||
expect(config.autonomy.clarify_budget).toBe(10);
|
||||
});
|
||||
|
||||
it("preserves nested objects that are not overridden", () => {
|
||||
initCI(tempDir, { git: { ...DEFAULT_CI_CONFIG.git, auto_push: true } });
|
||||
const config = loadConfig(tempDir);
|
||||
expect(config.git.auto_push).toBe(true);
|
||||
expect(config.git.auto_commit).toBe(true);
|
||||
expect(config.git.branching_strategy).toBe("phase");
|
||||
});
|
||||
});
|
||||
|
||||
describe("saveConfig", () => {
|
||||
it("saves and reloads config correctly", () => {
|
||||
ensureCIDir(tempDir);
|
||||
const customConfig = {
|
||||
...DEFAULT_CI_CONFIG,
|
||||
autonomy: { ...DEFAULT_CI_CONFIG.autonomy, level: "guided" as const },
|
||||
};
|
||||
saveConfig(tempDir, customConfig);
|
||||
const loaded = loadConfig(tempDir);
|
||||
expect(loaded.autonomy.level).toBe("guided");
|
||||
});
|
||||
});
|
||||
|
||||
describe("isCIInitialized", () => {
|
||||
it("returns false for uninitialized directory", () => {
|
||||
expect(isCIInitialized(tempDir)).toBe(false);
|
||||
});
|
||||
|
||||
it("returns true after initCI", () => {
|
||||
initCI(tempDir);
|
||||
expect(isCIInitialized(tempDir)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ensureCIDir", () => {
|
||||
it("creates .ci directory", () => {
|
||||
ensureCIDir(tempDir);
|
||||
expect(fs.existsSync(path.join(tempDir, ".ci"))).toBe(true);
|
||||
});
|
||||
|
||||
it("is idempotent", () => {
|
||||
ensureCIDir(tempDir);
|
||||
ensureCIDir(tempDir);
|
||||
expect(fs.existsSync(path.join(tempDir, ".ci"))).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user