import { describe, expect, test } from "vitest";
import {
	checkToolCallLoop,
	resetToolCallLoopGuard,
} from "../bootstrap/tool-call-loop-guard.js";

describe("tool-call loop guard", () => {
	test("checkToolCallLoop_when_identical_tool_repeats_returns_loop_signal", () => {
		resetToolCallLoopGuard();

		const first = checkToolCallLoop("ask_user_questions", {
			questions: ["continue?"],
		});
		const second = checkToolCallLoop("ask_user_questions", {
			questions: ["continue?"],
		});

		expect(first.block).toBe(false);
		expect(second).toMatchObject({
			block: true,
			count: 2,
			loopSignal: {
				scope: "tool",
				kind: "tool-call:duplicate",
				severity: "fail",
				recommendedAction: "block",
				source: "tool-call-loop-guard",
				evidence: {
					toolName: "ask_user_questions",
					count: 2,
					threshold: 1,
				},
			},
		});
		expect(second.loopSignal.evidence.signature).toBe(second.signature);
	});
});
