import { describe, expect, it } from "vitest";
import { readToolError, readToolSuccessMessage } from "../router/assistant-tool-results.js";

describe("assistant tool results", () => {
  it("reads structured tool errors from result data or JSON content", () => {
    expect(readToolError({
      content: "",
      data: { error: "Forbidden" },
    })).toBe("Forbidden");

    expect(readToolError({
      content: JSON.stringify({ error: "Validation failed" }),
    })).toBe("Validation failed");

    expect(readToolError({
      content: "plain text",
      data: { ok: true },
    })).toBeNull();
  });

  it("prefers structured success messages and falls back to plain content", () => {
    expect(readToolSuccessMessage({
      content: "",
      data: { message: "Created project Apollo" },
    })).toBe("Created project Apollo");

    expect(readToolSuccessMessage({
      content: JSON.stringify({ description: "Updated allocation" }),
    })).toBe("Updated allocation");

    expect(readToolSuccessMessage({
      content: "Fallback tool response",
    })).toBe("Fallback tool response");
  });
});
