import { describe, it, expect } from "vitest";
import {
sixThinkingHatsHandler,
logicalFallacyCheckHandler,
causalLoopDiagramHandler,
decisionMatrixHandler,
} from "./agentic.js";
describe("Agentic Tools", () => {
describe("six_thinking_hats", () => {
it("should generate a thinking session for a valid problem", () => {
const result = sixThinkingHatsHandler({
problem: "Should we rewrite the backend in Rust?",
});
const text = result.content[0].text;
expect(text).toContain("Six Thinking Hats Session");
expect(text).toContain("⚪ White Hat");
expect(text).toContain("🔴 Red Hat");
expect(text).toContain("🔵 Blue Hat");
expect(text).toContain("Should we rewrite the backend in Rust?");
});
});
describe("logical_fallacy_check", () => {
it("should return a checklist for the input text", () => {
const result = logicalFallacyCheckHandler({
text: "You are an idiot.",
});
const text = result.content[0].text;
expect(text).toContain("Logical Fallacy Check");
expect(text).toContain("Ad Hominem");
expect(text).toContain("(Trigger: keywords found)");
});
});
describe("decision_matrix", () => {
it("should return a decision analysis with a clear winner", () => {
const result = decisionMatrixHandler({
problem: "Choose a framework",
options: ["React", "Vue"],
criteria: [
{ name: "Popularity", weight: 9 },
{ name: "Ease", weight: 5 },
],
evaluations: [
{ optionIndex: 0, scores: [9, 6] },
{ optionIndex: 1, scores: [7, 8] },
],
});
const text = result.content[0].text;
expect(text).toContain("Decision Analysis: Choose a framework");
expect(text).toContain("Winner: **React**");
expect(text).toContain("Sensitivity Analysis");
});
it("should detect a close call", () => {
const result = decisionMatrixHandler({
problem: "A vs B",
options: ["A", "B"],
criteria: [{ name: "X", weight: 10 }],
evaluations: [
{ optionIndex: 0, scores: [5] }, // 50
{ optionIndex: 1, scores: [4.9] }, // 49
],
});
const text = result.content[0].text;
expect(text).toContain("Close Call");
});
});
describe("causal_loop_diagram", () => {
it("should generate a mermaid diagram from relationships", () => {
const result = causalLoopDiagramHandler({
params: ["Births", "Population", "Deaths"],
relationships: [
{ from: "Births", to: "Population", type: "positive" },
{ from: "Population", to: "Deaths", type: "positive" },
{ from: "Deaths", to: "Population", type: "negative" },
],
});
const text = result.content[0].text;
expect(text).toContain("Causal Loop Diagram");
expect(text).toContain("graph TD");
});
it("should validate relationships for unknown nodes", () => {
const result = causalLoopDiagramHandler({
params: ["A", "B"],
relationships: [
{ from: "A", to: "C", type: "positive" }, // C is unknown
],
});
// @ts-ignore
expect(result.isError).toBe(true);
expect(result.content[0].text).toContain("Unknown target node: C");
});
it("should validate self-loops", () => {
const result = causalLoopDiagramHandler({
params: ["A"],
relationships: [{ from: "A", to: "A", type: "positive" }],
});
// @ts-ignore
expect(result.isError).toBe(true);
expect(result.content[0].text).toContain("Self-loop detected");
});
});
});