fix(cli): consume the stream returned by send

This commit is contained in:
Adam Weidman
2026-03-20 11:19:34 -04:00
committed by Adam Weidman
parent 6d8cee7620
commit c3b5bcb84c
2 changed files with 30 additions and 2 deletions
@@ -277,6 +277,34 @@ describe('runNonInteractive', () => {
// so we no longer expect shutdownTelemetry to be called directly here
});
it('should stream the specific stream started by send', async () => {
const { LegacyAgentSession } = await import(
'../../core/src/agent/legacy-agent-session.js'
);
const streamSpy = vi.spyOn(LegacyAgentSession.prototype, 'stream');
const events: ServerGeminiStreamEvent[] = [
{ type: GeminiEventType.Content, value: 'Hello again' },
{
type: GeminiEventType.Finished,
value: { reason: undefined, usageMetadata: { totalTokenCount: 10 } },
},
];
mockGeminiClient.sendMessageStream.mockReturnValue(
createStreamFromEvents(events),
);
await runNonInteractive({
config: mockConfig,
settings: mockSettings,
input: 'Test input',
prompt_id: 'prompt-id-stream',
});
expect(streamSpy).toHaveBeenCalledWith({
streamId: expect.any(String),
});
});
it('should register activity logger when GEMINI_CLI_ACTIVITY_LOG_TARGET is set', async () => {
vi.stubEnv('GEMINI_CLI_ACTIVITY_LOG_TARGET', '/tmp/test.jsonl');
const events: ServerGeminiStreamEvent[] = [
+2 -2
View File
@@ -294,7 +294,7 @@ export async function runNonInteractive({
});
// Start the agentic loop (runs in background)
await session.send({
const { streamId } = await session.send({
message: geminiPartsToContentParts(query),
});
@@ -351,7 +351,7 @@ export async function runNonInteractive({
// Consume AgentEvents for output formatting
let responseText = '';
let streamEnded = false;
for await (const event of session.stream()) {
for await (const event of session.stream({ streamId })) {
if (streamEnded) break;
switch (event.type) {
case 'message': {