Skip to content

Commit 758df4b

Browse files
committed
test(api): cover generator return final response
Add regression ensuring FINAL_RESPONSE_MARKER is not surfaced as assistant text.
1 parent 0f46ab8 commit 758df4b

1 file changed

Lines changed: 49 additions & 5 deletions

File tree

tests/api/AgentOSOrchestrator.spec.ts

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
88
import { AgentOSOrchestrator } from '../../src/api/AgentOSOrchestrator';
99
import type { AgentOSInput, ProcessingOptions } from '../../src/api/types/AgentOSInput';
10+
import { AgentOSResponseChunkType } from '../../src/api/types/AgentOSResponse';
11+
import { GMIOutputChunkType } from '../../src/cognitive_substrate/IGMI';
1012
import type {
1113
GMITurnInput,
1214
IGMI,
1315
GMIOutputChunk,
14-
GMIOutputChunkType,
1516
} from '../../src/cognitive_substrate/IGMI';
1617
import type { GMIManager } from '../../src/cognitive_substrate/GMIManager';
1718
import type { IToolOrchestrator } from '../../src/core/tools/IToolOrchestrator';
@@ -73,25 +74,26 @@ describe('AgentOSOrchestrator (API layer)', () => {
7374
// Capture the input for assertions
7475
capturedGMIInput = input;
7576
yield {
76-
type: 'TEXT_DELTA' as GMIOutputChunkType,
77+
type: GMIOutputChunkType.TEXT_DELTA,
7778
content: 'Hello',
7879
interactionId: 'interaction-1',
7980
timestamp: new Date(),
8081
} as GMIOutputChunk;
8182
yield {
82-
type: 'FINAL_RESPONSE_MARKER' as GMIOutputChunkType,
83+
type: GMIOutputChunkType.FINAL_RESPONSE_MARKER,
8384
content: { finalResponseText: 'Hello' },
8485
interactionId: 'interaction-1',
8586
timestamp: new Date(),
87+
isFinal: true,
8688
} as GMIOutputChunk;
8789
return {
8890
isFinal: true,
89-
finalResponseText: 'Hello',
91+
responseText: 'Hello',
9092
};
9193
}),
9294
handleToolResult: vi.fn().mockImplementation(async function* () {
9395
yield {
94-
type: 'TEXT_DELTA' as GMIOutputChunkType,
96+
type: GMIOutputChunkType.TEXT_DELTA,
9597
content: 'Tool result processed',
9698
interactionId: 'interaction-1',
9799
timestamp: new Date(),
@@ -308,5 +310,47 @@ describe('AgentOSOrchestrator (API layer)', () => {
308310

309311
expect(capturedGMIInput?.metadata?.gmiId).toBe('gmi-1');
310312
});
313+
314+
it('uses the AsyncGenerator return value for finalResponseText (not the FINAL_RESPONSE_MARKER content)', async () => {
315+
// Simulate the real-world scenario: the marker content is a status string, while the
316+
// actual assistant response is returned via the generator return value.
317+
(mockGMI.processTurnStream as any).mockImplementation(async function* (_input: GMITurnInput) {
318+
yield {
319+
type: GMIOutputChunkType.TEXT_DELTA,
320+
content: 'Here are three tips: ',
321+
interactionId: 'interaction-1',
322+
timestamp: new Date(),
323+
} as GMIOutputChunk;
324+
yield {
325+
type: GMIOutputChunkType.FINAL_RESPONSE_MARKER,
326+
content: 'Turn processing sequence complete.',
327+
interactionId: 'interaction-1',
328+
timestamp: new Date(),
329+
isFinal: true,
330+
} as GMIOutputChunk;
331+
return {
332+
isFinal: true,
333+
responseText: 'Here are three tips: 1) Do X 2) Do Y 3) Do Z',
334+
};
335+
});
336+
337+
const input: AgentOSInput = {
338+
userId: 'test-user',
339+
sessionId: 'test-session',
340+
textInput: 'Give me 3 tips',
341+
selectedPersonaId: 'persona-1',
342+
};
343+
344+
await orchestrator.orchestrateTurn(input);
345+
await new Promise((resolve) => setTimeout(resolve, 100));
346+
347+
const pushedChunks = (mockStreamingManager.pushChunk as any).mock.calls.map((call: any[]) => call[1]);
348+
const finalChunk = pushedChunks.find((c: any) => c.type === AgentOSResponseChunkType.FINAL_RESPONSE);
349+
350+
expect(finalChunk).toBeTruthy();
351+
expect(finalChunk.finalResponseText).toBe('Here are three tips: 1) Do X 2) Do Y 3) Do Z');
352+
expect(String(finalChunk.finalResponseText).toLowerCase()).not.toContain('turn processing sequence complete');
353+
expect(mockStreamingManager.closeStream).toHaveBeenCalled();
354+
});
311355
});
312356
});

0 commit comments

Comments
 (0)