spb/khaelor Public
KHAELOR — a terminal-native autonomous engineering agent powered by Anthropic.
TypeScript 82.9%
HTML 14.9%
CSS 1.1%
JavaScript 0.7%
1/**2 * KHAELOR3 * File: tests/repository/fixtures.ts4 * Description: Test fixtures — temp dirs and real `git init` repositories for repository-module tests.5 *6 * Author: Simon-Pierre Boucher7 * Contact: contact@spboucher.ai8 */910import { execFileSync } from "node:child_process";11import { mkdtempSync, mkdirSync, writeFileSync } from "node:fs";12import { tmpdir } from "node:os";13import * as path from "node:path";1415/** Run a real git command in a fixture repo with fully-isolated identity/config. */16export function runGit(dir: string, args: string[]): string {17 return execFileSync("git", args, {18 cwd: dir,19 encoding: "utf8",20 env: {21 ...process.env,22 GIT_CONFIG_NOSYSTEM: "1",23 GIT_CONFIG_GLOBAL: "/dev/null",24 GIT_AUTHOR_NAME: "KHAELOR Test",25 GIT_AUTHOR_EMAIL: "test@spboucher.ai",26 GIT_COMMITTER_NAME: "KHAELOR Test",27 GIT_COMMITTER_EMAIL: "test@spboucher.ai",28 },29 });30}3132/** Create a fresh temp dir (caller removes it in afterEach). */33export function makeTempDir(prefix: string): string {34 return mkdtempSync(path.join(tmpdir(), prefix));35}3637/** `git init -b main` in dir. */38export function initRepo(dir: string): void {39 runGit(dir, ["init", "-qb", "main"]);40}4142/** Stage everything and commit. */43export function commitAll(dir: string, message: string): void {44 runGit(dir, ["add", "-A"]);45 runGit(dir, ["commit", "-qm", message, "--no-gpg-sign"]);46}4748/** Write a file, creating parent directories. */49export function writeFixtureFile(dir: string, rel: string, content: string | Buffer): void {50 const abs = path.join(dir, rel);51 mkdirSync(path.dirname(abs), { recursive: true });52 writeFileSync(abs, content);53}54