import assert from 'node:assert/strict'; import test from 'node:test'; import { reconcileSessionEventRequestContext, 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); }); test('reconcileSessionEventRequestContext adopts Goose request id while agent-run gate waits', () => { assert.deepEqual( reconcileSessionEventRequestContext({ activeRequestId: 'portal-req', chatState: 'waiting', eventType: 'ActiveRequests', activeRequestIds: ['goose-req'], }), { activeRequestId: 'goose-req', promoteStreaming: true, allowMissingGrace: false }, ); assert.deepEqual( reconcileSessionEventRequestContext({ activeRequestId: 'portal-req', chatState: 'waiting', eventType: 'Message', eventRequestId: 'goose-req', }), { activeRequestId: 'goose-req', promoteStreaming: true, allowMissingGrace: false }, ); });