import { assertEquals } from "https://deno.land/std@0.224.0/testing/asserts.ts"; /** * Proof of Concept: Orphan Branches (Gen 2) * * Demonstrates isolating state data into an actual orphan branch within an isolated Git repository. */ async function runGitCmd( args: string[], cwd?: string ): Promise<{ success: boolean; stdout: string; stderr: string }> { const cmd = new Deno.Command("git", { args, cwd, stdout: "piped", stderr: "piped", }); const output = await cmd.output(); const stdout = new TextDecoder().decode(output.stdout).trim(); const stderr = new TextDecoder().decode(output.stderr).trim(); return { success: output.success, stdout, stderr }; } if (import.meta.main) { console.log("Running Orphan Branch (Gen 2) tests..."); try { const tempRepoDir = await Deno.makeTempDir(); // Init isolated git repo await runGitCmd(["init"], tempRepoDir); await runGitCmd(["config", "user.name", "Agent Forum"], tempRepoDir); await runGitCmd(["config", "user.email", "agent@forum.local"], tempRepoDir); // Initial commit on main await Deno.writeTextFile(`${tempRepoDir}/main.ts`, "console.log('main code');"); await runGitCmd(["add", "main.ts"], tempRepoDir); await runGitCmd(["commit", "-m", "Initial code commit"], tempRepoDir); // Get default branch name since it might be main or master depending on git config const branchRes = await runGitCmd(["branch", "--show-current"], tempRepoDir); const mainBranch = branchRes.stdout || "master"; // Create an orphan branch for state await runGitCmd(["checkout", "--orphan", "forum/meta-state"], tempRepoDir); await runGitCmd(["rm", "-rf", "."], tempRepoDir); const statePayload = JSON.stringify({ active_task: "task-001", status: "running" }); await Deno.writeTextFile(`${tempRepoDir}/state.json`, statePayload); await runGitCmd(["add", "state.json"], tempRepoDir); await runGitCmd(["commit", "-m", "State update"], tempRepoDir); // Verify main code isn't in this branch const lsTreeState = await runGitCmd(["ls-tree", "HEAD"], tempRepoDir); assertEquals(lsTreeState.stdout.includes("state.json"), true); assertEquals(lsTreeState.stdout.includes("main.ts"), false); // Checkout main, verify state.json isn't there await runGitCmd(["checkout", mainBranch], tempRepoDir); const lsTreeMain = await runGitCmd(["ls-tree", "HEAD"], tempRepoDir); assertEquals(lsTreeMain.stdout.includes("main.ts"), true); assertEquals(lsTreeMain.stdout.includes("state.json"), false); await Deno.remove(tempRepoDir, { recursive: true }); console.log("✅ Orphan Branch (Gen 2) PoC successful: Verified absolute isolation of state vs code."); } catch (err) { console.error("❌ Orphan Branch (Gen 2) PoC failed:", err); Deno.exit(1); } }