summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/useToolScheduler.test.ts
diff options
context:
space:
mode:
authorJacob Richman <[email protected]>2025-05-29 22:30:18 +0000
committerGitHub <[email protected]>2025-05-29 15:30:18 -0700
commitdab7517622527a70bf2f36a9d7a9fa5e1a3b56e0 (patch)
tree55b5c8f39b6e7e4fbc28c8a427247e7feb8927ae /packages/cli/src/ui/hooks/useToolScheduler.test.ts
parentf21abdd1f0390ba985ae3bec5c29270b9b953b8d (diff)
Refactor read-file and support images. (#480)
Diffstat (limited to 'packages/cli/src/ui/hooks/useToolScheduler.test.ts')
-rw-r--r--packages/cli/src/ui/hooks/useToolScheduler.test.ts126
1 files changed, 126 insertions, 0 deletions
diff --git a/packages/cli/src/ui/hooks/useToolScheduler.test.ts b/packages/cli/src/ui/hooks/useToolScheduler.test.ts
new file mode 100644
index 00000000..10ba4f28
--- /dev/null
+++ b/packages/cli/src/ui/hooks/useToolScheduler.test.ts
@@ -0,0 +1,126 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { describe, it, expect } from 'vitest';
+import { formatLlmContentForFunctionResponse } from './useToolScheduler.js';
+import { Part, PartListUnion } from '@google/genai';
+
+describe('formatLlmContentForFunctionResponse', () => {
+ it('should handle simple string llmContent', () => {
+ const llmContent = 'Simple text output';
+ const { functionResponseJson, additionalParts } =
+ formatLlmContentForFunctionResponse(llmContent);
+ expect(functionResponseJson).toEqual({ output: 'Simple text output' });
+ expect(additionalParts).toEqual([]);
+ });
+
+ it('should handle llmContent as a single Part with text', () => {
+ const llmContent: Part = { text: 'Text from Part object' };
+ const { functionResponseJson, additionalParts } =
+ formatLlmContentForFunctionResponse(llmContent);
+ expect(functionResponseJson).toEqual({ output: 'Text from Part object' });
+ expect(additionalParts).toEqual([]);
+ });
+
+ it('should handle llmContent as a PartListUnion array with a single text Part', () => {
+ const llmContent: PartListUnion = [{ text: 'Text from array' }];
+ const { functionResponseJson, additionalParts } =
+ formatLlmContentForFunctionResponse(llmContent);
+ expect(functionResponseJson).toEqual({ output: 'Text from array' });
+ expect(additionalParts).toEqual([]);
+ });
+
+ it('should handle llmContent with inlineData', () => {
+ const llmContent: Part = {
+ inlineData: { mimeType: 'image/png', data: 'base64...' },
+ };
+ const { functionResponseJson, additionalParts } =
+ formatLlmContentForFunctionResponse(llmContent);
+ expect(functionResponseJson).toEqual({
+ status: 'Binary content of type image/png was processed.',
+ });
+ expect(additionalParts).toEqual([llmContent]);
+ });
+
+ it('should handle llmContent with fileData', () => {
+ const llmContent: Part = {
+ fileData: { mimeType: 'application/pdf', fileUri: 'gs://...' },
+ };
+ const { functionResponseJson, additionalParts } =
+ formatLlmContentForFunctionResponse(llmContent);
+ expect(functionResponseJson).toEqual({
+ status: 'Binary content of type application/pdf was processed.',
+ });
+ expect(additionalParts).toEqual([llmContent]);
+ });
+
+ it('should handle llmContent as an array of multiple Parts (text and inlineData)', () => {
+ const llmContent: PartListUnion = [
+ { text: 'Some textual description' },
+ { inlineData: { mimeType: 'image/jpeg', data: 'base64data...' } },
+ { text: 'Another text part' },
+ ];
+ const { functionResponseJson, additionalParts } =
+ formatLlmContentForFunctionResponse(llmContent);
+ expect(functionResponseJson).toEqual({
+ status: 'Tool execution succeeded.',
+ });
+ expect(additionalParts).toEqual(llmContent);
+ });
+
+ it('should handle llmContent as an array with a single inlineData Part', () => {
+ const llmContent: PartListUnion = [
+ { inlineData: { mimeType: 'image/gif', data: 'gifdata...' } },
+ ];
+ const { functionResponseJson, additionalParts } =
+ formatLlmContentForFunctionResponse(llmContent);
+ // When the array is a single Part and that part is inlineData
+ expect(functionResponseJson).toEqual({
+ status: 'Binary content of type image/gif was processed.',
+ });
+ expect(additionalParts).toEqual(llmContent);
+ });
+
+ it('should handle llmContent as a generic Part (not text, inlineData, or fileData)', () => {
+ // This case might represent a malformed or unexpected Part type.
+ // For example, a Part that is just an empty object or has other properties.
+ const llmContent: Part = { functionCall: { name: 'test', args: {} } }; // Example of a non-standard part for this context
+ const { functionResponseJson, additionalParts } =
+ formatLlmContentForFunctionResponse(llmContent);
+ expect(functionResponseJson).toEqual({
+ status: 'Tool execution succeeded.',
+ });
+ expect(additionalParts).toEqual([llmContent]);
+ });
+
+ it('should handle empty string llmContent', () => {
+ const llmContent = '';
+ const { functionResponseJson, additionalParts } =
+ formatLlmContentForFunctionResponse(llmContent);
+ expect(functionResponseJson).toEqual({ output: '' });
+ expect(additionalParts).toEqual([]);
+ });
+
+ it('should handle llmContent as an empty array', () => {
+ const llmContent: PartListUnion = [];
+ const { functionResponseJson, additionalParts } =
+ formatLlmContentForFunctionResponse(llmContent);
+ expect(functionResponseJson).toEqual({
+ status: 'Tool execution succeeded.',
+ });
+ expect(additionalParts).toEqual([]);
+ });
+
+ it('should handle llmContent as a Part with undefined inlineData/fileData/text', () => {
+ const llmContent: Part = {}; // An empty part object
+ const { functionResponseJson, additionalParts } =
+ formatLlmContentForFunctionResponse(llmContent);
+ expect(functionResponseJson).toEqual({
+ status: 'Tool execution succeeded.',
+ });
+ expect(additionalParts).toEqual([llmContent]);
+ });
+});