NODEDC_1C/llm_normalizer/backend/tests/assistantAddressToolGateRun...

81 lines
2.8 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { runAssistantAddressToolGateRuntime } from "../src/services/assistantAddressToolGateRuntimeAdapter";
describe("assistant address tool-gate runtime adapter", () => {
it("does nothing when runAddressLane is true", async () => {
const logEvent = vi.fn();
const tryHandleLivingChat = vi.fn(async () => "chat-response");
const result = await runAssistantAddressToolGateRuntime({
sessionId: "asst-1",
userMessage: "вопрос",
addressInputMessage: "вопрос",
orchestrationDecision: { runAddressLane: true },
livingModeDecision: { mode: "chat", reason: "x" },
addressRuntimeMeta: {},
logEvent,
tryHandleLivingChat,
nowIso: () => "2026-04-10T00:00:00.000Z"
});
expect(result.handled).toBe(false);
expect(result.response).toBeNull();
expect(logEvent).not.toHaveBeenCalled();
expect(tryHandleLivingChat).not.toHaveBeenCalled();
});
it("logs skip and returns chat response when chat fallback handles", async () => {
const logEvent = vi.fn();
const tryHandleLivingChat = vi.fn(async () => ({ ok: true }));
const result = await runAssistantAddressToolGateRuntime({
sessionId: "asst-2",
userMessage: "вопрос",
addressInputMessage: "канон",
orchestrationDecision: { runAddressLane: false },
livingModeDecision: { mode: "chat", reason: "predecompose_unsupported_mode" },
addressRuntimeMeta: {
attempted: true,
applied: false,
reason: "normalize_failed",
predecomposeContract: {
intent: "unknown",
aggregation_profile: "unknown",
period: { scope: "unspecified" }
}
},
logEvent,
tryHandleLivingChat,
nowIso: () => "2026-04-10T00:00:00.000Z"
});
expect(result.handled).toBe(true);
expect(result.response).toEqual({ ok: true });
expect(logEvent).toHaveBeenCalledTimes(1);
expect(tryHandleLivingChat).toHaveBeenCalledTimes(1);
});
it("logs skip and returns unhandled when mode is not chat", async () => {
const logEvent = vi.fn();
const tryHandleLivingChat = vi.fn(async () => ({ ok: true }));
const result = await runAssistantAddressToolGateRuntime({
sessionId: "asst-3",
userMessage: "вопрос",
addressInputMessage: "канон",
orchestrationDecision: { runAddressLane: false },
livingModeDecision: { mode: "deep_analysis", reason: "strong_data_signal_detected" },
addressRuntimeMeta: {},
logEvent,
tryHandleLivingChat,
nowIso: () => "2026-04-10T00:00:00.000Z"
});
expect(result.handled).toBe(false);
expect(result.response).toBeNull();
expect(logEvent).toHaveBeenCalledTimes(1);
expect(tryHandleLivingChat).not.toHaveBeenCalled();
});
});