Files
dify/web/utils/tool-call.spec.ts
Gritty_dev 775d2e14fc
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Main CI Pipeline / Check Changed Files (push) Waiting to run
Main CI Pipeline / API Tests (push) Blocked by required conditions
Main CI Pipeline / Web Tests (push) Blocked by required conditions
Main CI Pipeline / Style Check (push) Waiting to run
Main CI Pipeline / VDB Tests (push) Blocked by required conditions
Main CI Pipeline / DB Migration Test (push) Blocked by required conditions
Check i18n Files and Create PR / check-and-update (push) Waiting to run
test: create new test scripts and update some existing test scripts o… (#27850)
2025-11-05 11:09:24 +08:00

80 lines
2.6 KiB
TypeScript

/**
* Test suite for tool call utility functions
* Tests detection of function/tool call support in AI models
*/
import { supportFunctionCall } from './tool-call'
import { ModelFeatureEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
describe('tool-call', () => {
/**
* Tests supportFunctionCall which checks if a model supports any form of
* function calling (toolCall, multiToolCall, or streamToolCall)
*/
describe('supportFunctionCall', () => {
/**
* Tests detection of basic tool call support
*/
test('returns true when features include toolCall', () => {
const features = [ModelFeatureEnum.toolCall]
expect(supportFunctionCall(features)).toBe(true)
})
/**
* Tests detection of multi-tool call support (calling multiple tools in one request)
*/
test('returns true when features include multiToolCall', () => {
const features = [ModelFeatureEnum.multiToolCall]
expect(supportFunctionCall(features)).toBe(true)
})
/**
* Tests detection of streaming tool call support
*/
test('returns true when features include streamToolCall', () => {
const features = [ModelFeatureEnum.streamToolCall]
expect(supportFunctionCall(features)).toBe(true)
})
test('returns true when features include multiple tool call types', () => {
const features = [
ModelFeatureEnum.toolCall,
ModelFeatureEnum.multiToolCall,
ModelFeatureEnum.streamToolCall,
]
expect(supportFunctionCall(features)).toBe(true)
})
/**
* Tests that tool call support is detected even when mixed with other features
*/
test('returns true when features include tool call among other features', () => {
const features = [
ModelFeatureEnum.agentThought,
ModelFeatureEnum.toolCall,
ModelFeatureEnum.vision,
]
expect(supportFunctionCall(features)).toBe(true)
})
/**
* Tests that false is returned when no tool call features are present
*/
test('returns false when features do not include any tool call type', () => {
const features = [ModelFeatureEnum.agentThought, ModelFeatureEnum.vision]
expect(supportFunctionCall(features)).toBe(false)
})
test('returns false for empty array', () => {
expect(supportFunctionCall([])).toBe(false)
})
test('returns false for undefined', () => {
expect(supportFunctionCall(undefined)).toBe(false)
})
test('returns false for null', () => {
expect(supportFunctionCall(null as any)).toBe(false)
})
})
})