import { describe, expect, test } from "bun:test";
import {
  formatReadinessVerdictForHumans,
  stripCodeFenceArtifacts,
} from "@/utils/readiness-display.js";

describe("formatReadinessVerdictForHumans", () => {
  test("PROCEED", () => {
    expect(formatReadinessVerdictForHumans("PROCEED")).toBe("Ready to implement");
  });

  test("NEEDS_INFO", () => {
    expect(formatReadinessVerdictForHumans("NEEDS_INFO")).toBe(
      "Not ready — needs more detail or scope clarity",
    );
  });

  test("RUN_FAILED includes literal label", () => {
    expect(formatReadinessVerdictForHumans("RUN_FAILED")).toContain("RUN_FAILED");
  });
});

describe("stripCodeFenceArtifacts", () => {
  test("removes leading fence line and trailing fence", () => {
    const input = "```\nhello\n```";
    expect(stripCodeFenceArtifacts(input)).toBe("hello");
  });

  test("strips repeatedly until stable", () => {
    const input = "```ts\n```\nbody\n```";
    expect(stripCodeFenceArtifacts(input)).toBe("body");
  });

  test("returns trimmed text when no fences", () => {
    expect(stripCodeFenceArtifacts("  plain  ")).toBe("plain");
  });
});
