import { existsSync } from "node:fs"; import { mkdir, writeFile, rm } from "node:fs/promises"; import { join } from "node:path"; import { runInit } from "../../src/commands/init.ts"; import { loadConfig, getChangeDir } from "../../src/core/config.ts"; import type { RuneConfig } from "../../src/types.ts"; const TMP_DIR = join(import.meta.dir, "__tmp_agent_test__"); export function getTempDir(): string { return TMP_DIR; } export async function setupTempDir(): Promise { await rm(TMP_DIR, { recursive: true, force: true }); await mkdir(TMP_DIR, { recursive: true }); } export async function cleanupTempDir(): Promise { await rm(TMP_DIR, { recursive: true, force: true }); } export async function createFreshProject(editors: string[] = ["opencode"]): Promise { await runInit(TMP_DIR, editors); return loadConfig(TMP_DIR); } export async function createChangeDir(changeName: string): Promise { const dir = getChangeDir(TMP_DIR, changeName); await mkdir(dir, { recursive: true }); return dir; } export async function writeDoc( changeName: string, docName: string, content: string, ): Promise { const dir = getChangeDir(TMP_DIR, changeName); await mkdir(dir, { recursive: true }); await writeFile(join(dir, `${docName}.md`), content); } export function changeFileExists(changeName: string, fileName: string): boolean { return existsSync(join(getChangeDir(TMP_DIR, changeName), fileName)); }