mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-20 00:32:31 -07:00
fix(cli): consume the stream returned by send
This commit is contained in:
committed by
Adam Weidman
parent
6d8cee7620
commit
c3b5bcb84c
@@ -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[] = [
|
||||
|
||||
@@ -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': {
|
||||
|
||||
Reference in New Issue
Block a user