import { describe, it, beforeEach, afterEach } from "node:test"; import assert from "node:assert"; import { enterMultiMessageMode, exitMultiMessageMode, isMultiMessageMode, setChannelShuffling, getChannelShuffling } from "../plugin/core/channel-modes.ts"; import { initTurnOrder, checkTurn, getTurnDebugInfo, onNewMessage, resetTurn, setWaitingForHuman, isWaitingForHuman } from "../plugin/turn-manager.ts"; describe("Mode Compatibility Tests", () => { const channelId = "test-channel"; beforeEach(() => { resetTurn(channelId); exitMultiMessageMode(channelId); // Ensure clean state }); afterEach(() => { resetTurn(channelId); exitMultiMessageMode(channelId); }); describe("multi-message mode with waiting-for-human", () => { it("should prioritize multi-message mode over waiting-for-human", () => { const botIds = ["agent-a", "agent-b"]; initTurnOrder(channelId, botIds); // Set up waiting for human state setWaitingForHuman(channelId); assert.strictEqual(isWaitingForHuman(channelId), true); // Enter multi-message mode (should take precedence in before-model-resolve) enterMultiMessageMode(channelId); assert.strictEqual(isMultiMessageMode(channelId), true); assert.strictEqual(isWaitingForHuman(channelId), true); // Both states exist but multi-message mode takes priority in hook // Exit multi-message mode exitMultiMessageMode(channelId); assert.strictEqual(isMultiMessageMode(channelId), false); assert.strictEqual(isWaitingForHuman(channelId), true); // Waiting for human state still exists }); }); describe("shuffle mode with dormant state", () => { it("should maintain shuffle setting when dormant", () => { const botIds = ["agent-a", "agent-b"]; initTurnOrder(channelId, botIds); // Enable shuffling setChannelShuffling(channelId, true); assert.strictEqual(getChannelShuffling(channelId), true); // Reset to dormant resetTurn(channelId); const dormantState = getTurnDebugInfo(channelId); assert.strictEqual(dormantState.dormant, true); assert.strictEqual(getChannelShuffling(channelId), true); // Shuffling setting should persist // Reactivate onNewMessage(channelId, "human-user", true); const activeState = getTurnDebugInfo(channelId); assert.strictEqual(activeState.dormant, false); assert.strictEqual(getChannelShuffling(channelId), true); // Setting should still be there }); }); describe("shuffle mode with mention override", () => { it("should handle shuffle mode during mention override", () => { const botIds = ["agent-a", "agent-b", "agent-c"]; initTurnOrder(channelId, botIds); // Enable shuffling setChannelShuffling(channelId, true); assert.strictEqual(getChannelShuffling(channelId), true); // In real implementation, mention override would be set via setMentionOverride function // This test ensures the settings coexist properly const state = getTurnDebugInfo(channelId); assert.ok(state.hasTurnState); assert.strictEqual(getChannelShuffling(channelId), true); }); }); describe("multi-message mode with dormant state", () => { it("should exit multi-message mode properly from dormant state", () => { const botIds = ["agent-a", "agent-b"]; initTurnOrder(channelId, botIds); // Reset to dormant resetTurn(channelId); const dormantState = getTurnDebugInfo(channelId); assert.strictEqual(dormantState.dormant, true); // Enter multi-message mode while dormant enterMultiMessageMode(channelId); assert.strictEqual(isMultiMessageMode(channelId), true); // Exit multi-message mode exitMultiMessageMode(channelId); assert.strictEqual(isMultiMessageMode(channelId), false); // Should still be dormant const stateAfterExit = getTurnDebugInfo(channelId); assert.strictEqual(stateAfterExit.dormant, true); }); }); describe("complete workflow with all modes", () => { it("should handle transitions between all modes", () => { const botIds = ["agent-a", "agent-b", "agent-c"]; initTurnOrder(channelId, botIds); // Start with shuffling enabled setChannelShuffling(channelId, true); assert.strictEqual(getChannelShuffling(channelId), true); // Enter multi-message mode enterMultiMessageMode(channelId); assert.strictEqual(isMultiMessageMode(channelId), true); assert.strictEqual(getChannelShuffling(channelId), true); // Exit multi-message mode exitMultiMessageMode(channelId); assert.strictEqual(isMultiMessageMode(channelId), false); assert.strictEqual(getChannelShuffling(channelId), true); // Set waiting for human setWaitingForHuman(channelId); assert.strictEqual(isWaitingForHuman(channelId), true); assert.strictEqual(getChannelShuffling(channelId), true); // Reactivate with human message onNewMessage(channelId, "human-user", true); const activeState = getTurnDebugInfo(channelId); assert.strictEqual(activeState.dormant, false); assert.strictEqual(isWaitingForHuman(channelId), false); assert.strictEqual(getChannelShuffling(channelId), true); // Test that agents can speak in normal mode with shuffling enabled const turnResult = checkTurn(channelId, "agent-a"); // This would depend on current turn state, but the important thing is no errors occurred assert.ok(typeof turnResult === "object"); }); }); });