/** * Tests for the workflow YAML-subset parser, including the folded multi-line * directive support. */ import { describe, expect, test } from "bun:test"; import { parseWorkflowScript } from "./script.ts"; describe("parseWorkflowScript", () => { test("parses a flat single-line workflow", () => { const script = parseWorkflowScript(` name: my-workflow phases: - name: research directive: "Explore the codebase for the auth module." - name: implement directive: "Implement the change." `); expect(script.name).toBe("my-workflow"); expect(script.phases.length).toBe(2); expect(script.phases[0]!.name).toBe("research"); expect(script.phases[0]!.directive).toBe("Explore the codebase for the auth module."); }); test("folds an indented multi-line directive into one string", () => { const script = parseWorkflowScript(` name: audit phases: - name: analyze directive: | Look at two things: first, how auth is wired; second, where secrets are stored. `); expect(script.phases.length).toBe(1); const d = script.phases[0]!.directive; expect(d).toContain("Look at two things:"); expect(d).toContain("second, where secrets are stored."); // Line breaks are preserved as folded content, not flattened. expect(d).toContain("\n"); }); test("an indented continuation does not swallow the next phase", () => { const script = parseWorkflowScript(` phases: - name: a directive: first and more - name: b directive: second `); expect(script.phases.length).toBe(2); expect(script.phases[0]!.directive).toContain("and more"); expect(script.phases[1]!.name).toBe("b"); expect(script.phases[1]!.directive).toBe("second"); }); test("empty or unparseable yaml yields no phases", () => { expect(parseWorkflowScript("").phases.length).toBe(0); expect(parseWorkflowScript("name: x\n").phases.length).toBe(0); }); });