import assert from 'node:assert/strict'; import test from 'node:test'; import { resolvePostAgentRunChatState, shouldPromoteSessionIdToStreaming, } from './chat-agent-run-gate.mjs'; test('resolvePostAgentRunChatState keeps idle when Finish beat agent-run gate', () => { assert.equal( resolvePostAgentRunChatState({ chatState: 'idle', finishedViaPortalDirectChat: false }), 'idle', ); }); test('resolvePostAgentRunChatState returns streaming while still waiting for session Finish', () => { assert.equal(resolvePostAgentRunChatState({ chatState: 'waiting' }), 'streaming'); assert.equal(resolvePostAgentRunChatState({ chatState: 'streaming' }), 'streaming'); }); test('resolvePostAgentRunChatState prefers portal direct chat completion', () => { assert.equal( resolvePostAgentRunChatState({ chatState: 'streaming', finishedViaPortalDirectChat: true }), 'idle', ); }); test('shouldPromoteSessionIdToStreaming skips re-streaming after Finish', () => { assert.equal(shouldPromoteSessionIdToStreaming('idle'), false); assert.equal(shouldPromoteSessionIdToStreaming('waiting'), true); assert.equal(shouldPromoteSessionIdToStreaming('streaming'), true); });