import * as fs from "node:fs"; import * as path from "node:path"; import * as os from "node:os"; import { SolutionWriterAgent } from "../agents/solution-writer.js"; describe("SolutionWriterAgent", () => { let tempDir: string; beforeEach(() => { tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "ciagent-solution-writer-test-")); fs.mkdirSync(path.join(tempDir, ".ciagent"), { recursive: true }); }); afterEach(() => { fs.rmSync(tempDir, { recursive: true, force: true }); }); it("reads PLAN.md and produces implementation plan section", () => { fs.writeFileSync( path.join(tempDir, ".ciagent", "PLAN.md"), "# Plan\n\n| T-01 | Setup | 1 | none | Files exist | REQ-01 |\n|-----|-------|---|------|------------|--------|\n" ); const agent = new SolutionWriterAgent(); const result = agent.mechanicalSolutionWrite(tempDir); expect(result).toContain("# Solution Document"); expect(result).toContain("## Implementation Plan"); expect(result).toContain("T-01"); }); it("reads REQUIREMENTS.md and extracts verification criteria", () => { fs.writeFileSync( path.join(tempDir, ".ciagent", "REQUIREMENTS.md"), "# Requirements\n\nREQ-01: System must boot\nREQ-02: System must respond\n" ); const agent = new SolutionWriterAgent(); const result = agent.mechanicalSolutionWrite(tempDir); expect(result).toContain("## Verification Criteria"); expect(result).toContain("REQ-01"); expect(result).toContain("REQ-02"); }); it("reads ARCHITECTURE.md and populates approach and risk sections", () => { fs.writeFileSync( path.join(tempDir, ".ciagent", "ARCHITECTURE.md"), "# Architecture\n\n## Approach\n\nModular monolith with clear boundaries.\n\n## Risks\n\n- Single point of failure in gateway\n" ); const agent = new SolutionWriterAgent(); const result = agent.mechanicalSolutionWrite(tempDir); expect(result).toContain("## Approach"); expect(result).toContain("Modular monolith"); expect(result).toContain("## Risk Assessment"); expect(result).toContain("gateway"); }); it("produces structured markdown with all five sections", () => { const agent = new SolutionWriterAgent(); const result = agent.mechanicalSolutionWrite(tempDir); expect(result).toContain("# Solution Document"); expect(result).toContain("## Problem Statement"); expect(result).toContain("## Approach"); expect(result).toContain("## Implementation Plan"); expect(result).toContain("## Verification Criteria"); expect(result).toContain("## Risk Assessment"); }); it("extracts problem statement from requirements objective section", () => { fs.writeFileSync( path.join(tempDir, ".ciagent", "REQUIREMENTS.md"), "# Objective\n\nBuild a fast CLI tool.\n\n## Requirements\n\nREQ-01: Speed" ); const agent = new SolutionWriterAgent(); const result = agent.mechanicalSolutionWrite(tempDir); expect(result).toContain("Build a fast CLI tool"); }); it("agent name is solution-writer", () => { const agent = new SolutionWriterAgent(); expect(agent.name).toBe("solution-writer"); }); });