import { describe, expect, it } from "bun:test"; import { extractCron } from "../src/agent/cron.ts"; describe("extractCron", () => { it("passes through a clean 5-field expression", () => { expect(extractCron("*/5 * * * *")).toBe("*/5 * * * *"); }); it("passes through a clean 6-field expression", () => { expect(extractCron("*/5 * * * * *")).toBe("*/5 * * * * *"); }); it("strips surrounding backticks", () => { expect(extractCron("`*/5 * * * *`")).toBe("*/5 * * * *"); }); it("strips triple backticks with language tag", () => { expect(extractCron("```cron\n*/5 * * * *\n```")).toBe("*/5 * * * *"); }); it("extracts cron from verbose multiline LLM output", () => { const verbose = ["Here is the cron expression:", "*/5 * * * *", "This runs every 5 minutes."].join("\n"); expect(extractCron(verbose)).toBe("*/5 * * * *"); }); it("extracts 6-field cron from explanation text", () => { const verbose = "For every 5 seconds: */5 * * * * *"; expect(extractCron(verbose)).toBe("*/5 * * * * *"); }); it("handles leading/trailing whitespace", () => { expect(extractCron(" 0 9 * * 1-5 ")).toBe("0 9 * * 1-5"); }); it("handles cron with commas and ranges", () => { expect(extractCron("0,30 9-17 * * 1-5")).toBe("0,30 9-17 * * 1-5"); }); it("returns cleaned input as fallback when no cron pattern matches", () => { expect(extractCron("not a cron")).toBe("not a cron"); }); });