From 1bd4f9d8b6fe819248abbe2c222effd763ba45cc Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 7 Jan 2026 16:10:50 -0800 Subject: [PATCH] Optimize json-output tests with mock responses (#16102) --- .../json-output.france.responses | 1 + .../json-output.session-id.responses | 1 + integration-tests/json-output.test.ts | 19 ++++++++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 integration-tests/json-output.france.responses create mode 100644 integration-tests/json-output.session-id.responses diff --git a/integration-tests/json-output.france.responses b/integration-tests/json-output.france.responses new file mode 100644 index 0000000000..5c9edce888 --- /dev/null +++ b/integration-tests/json-output.france.responses @@ -0,0 +1 @@ +{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"The capital of France is Paris."}],"role":"model"},"finishReason":"STOP","index":0}],"usageMetadata":{"promptTokenCount":7,"candidatesTokenCount":7,"totalTokenCount":14,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7}]}}]} diff --git a/integration-tests/json-output.session-id.responses b/integration-tests/json-output.session-id.responses new file mode 100644 index 0000000000..c96cbccea4 --- /dev/null +++ b/integration-tests/json-output.session-id.responses @@ -0,0 +1 @@ +{"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"Hello! How can I help you today?"}],"role":"model"},"finishReason":"STOP","index":0}],"usageMetadata":{"promptTokenCount":5,"candidatesTokenCount":9,"totalTokenCount":14,"promptTokensDetails":[{"modality":"TEXT","tokenCount":5}]}}]} \ No newline at end of file diff --git a/integration-tests/json-output.test.ts b/integration-tests/json-output.test.ts index 0221034d3e..215cf21226 100644 --- a/integration-tests/json-output.test.ts +++ b/integration-tests/json-output.test.ts @@ -9,8 +9,7 @@ import { TestRig } from './test-helper.js'; import { join } from 'node:path'; import { ExitCodes } from '@google/gemini-cli-core/src/index.js'; -// TODO: Enable these tests once we figure out why they are flaky in CI. -describe.skip('JSON output', () => { +describe('JSON output', () => { let rig: TestRig; beforeEach(async () => { @@ -22,7 +21,12 @@ describe.skip('JSON output', () => { }); it('should return a valid JSON with response and stats', async () => { - await rig.setup('json-output-response-stats'); + await rig.setup('json-output-france', { + fakeResponsesPath: join( + import.meta.dirname, + 'json-output.france.responses', + ), + }); const result = await rig.run({ args: ['What is the capital of France?', '--output-format', 'json'], }); @@ -37,7 +41,12 @@ describe.skip('JSON output', () => { }); it('should return a valid JSON with a session ID', async () => { - await rig.setup('json-output-session-id'); + await rig.setup('json-output-session-id', { + fakeResponsesPath: join( + import.meta.dirname, + 'json-output.session-id.responses', + ), + }); const result = await rig.run({ args: ['Hello', '--output-format', 'json'], }); @@ -104,7 +113,7 @@ describe.skip('JSON output', () => { }); it('should not exit on tool errors and allow model to self-correct in JSON mode', async () => { - rig.setup('json-output-error', { + await rig.setup('json-output-error', { fakeResponsesPath: join( import.meta.dirname, 'json-output.error.responses',