|
| 1 | +// ***************************************************************************** |
| 2 | +// Copyright (C) 2025 EclipseSource GmbH. |
| 3 | +// |
| 4 | +// This program and the accompanying materials are made available under the |
| 5 | +// terms of the Eclipse Public License v. 2.0 which is available at |
| 6 | +// http://www.eclipse.org/legal/epl-2.0. |
| 7 | +// |
| 8 | +// This Source Code may also be made available under the following Secondary |
| 9 | +// Licenses when the conditions for such availability set forth in the Eclipse |
| 10 | +// Public License v. 2.0 are satisfied: GNU General Public License, version 2 |
| 11 | +// with the GNU Classpath Exception which is available at |
| 12 | +// https://www.gnu.org/software/classpath/license.html. |
| 13 | +// |
| 14 | +// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 |
| 15 | +// ***************************************************************************** |
| 16 | +import { expect } from 'chai'; |
| 17 | +import { ToolRequest } from '../common/language-model'; |
| 18 | + |
| 19 | +describe('isToolRequestParameters', () => { |
| 20 | + it('should return true for valid ToolRequestParameters', () => { |
| 21 | + const validParams = { |
| 22 | + type: 'object', |
| 23 | + properties: { |
| 24 | + param1: { |
| 25 | + type: 'string' |
| 26 | + }, |
| 27 | + param2: { |
| 28 | + type: 'number' |
| 29 | + } |
| 30 | + }, |
| 31 | + required: ['param1'] |
| 32 | + }; |
| 33 | + expect(ToolRequest.isToolRequestParameters(validParams)).to.be.true; |
| 34 | + }); |
| 35 | + |
| 36 | + it('should return false for ToolRequestParameters without type or anyOf', () => { |
| 37 | + const paramsWithoutType = { |
| 38 | + properties: { |
| 39 | + param1: { |
| 40 | + description: 'string' |
| 41 | + } |
| 42 | + }, |
| 43 | + required: ['param1'] |
| 44 | + }; |
| 45 | + expect(ToolRequest.isToolRequestParameters(paramsWithoutType)).to.be.false; |
| 46 | + }); |
| 47 | + |
| 48 | + it('should return false for invalid ToolRequestParameters with wrong property type', () => { |
| 49 | + const invalidParams = { |
| 50 | + type: 'object', |
| 51 | + properties: { |
| 52 | + param1: { |
| 53 | + type: 123 |
| 54 | + } |
| 55 | + } |
| 56 | + }; |
| 57 | + expect(ToolRequest.isToolRequestParameters(invalidParams)).to.be.false; |
| 58 | + }); |
| 59 | + |
| 60 | + it('should return false if properties is not an object', () => { |
| 61 | + const invalidParams = { |
| 62 | + type: 'object', |
| 63 | + properties: 'not-an-object', |
| 64 | + }; |
| 65 | + expect(ToolRequest.isToolRequestParameters(invalidParams)).to.be.false; |
| 66 | + }); |
| 67 | + |
| 68 | + it('should return true if required is missing', () => { |
| 69 | + const missingRequiredParams = { |
| 70 | + type: 'object', |
| 71 | + properties: { |
| 72 | + param1: { |
| 73 | + type: 'string' |
| 74 | + } |
| 75 | + } |
| 76 | + }; |
| 77 | + expect(ToolRequest.isToolRequestParameters(missingRequiredParams)).to.be.true; |
| 78 | + }); |
| 79 | + |
| 80 | + it('should return false if required is not an array', () => { |
| 81 | + const invalidRequiredParams = { |
| 82 | + type: 'object', |
| 83 | + properties: { |
| 84 | + param1: { |
| 85 | + type: 'string' |
| 86 | + } |
| 87 | + }, |
| 88 | + required: 'param1' |
| 89 | + }; |
| 90 | + expect(ToolRequest.isToolRequestParameters(invalidRequiredParams)).to.be.false; |
| 91 | + }); |
| 92 | + |
| 93 | + it('should return false if a required field is not a string', () => { |
| 94 | + const invalidRequiredParams = { |
| 95 | + type: 'object', |
| 96 | + properties: { |
| 97 | + param1: { |
| 98 | + type: 'string' |
| 99 | + } |
| 100 | + }, |
| 101 | + required: [123] |
| 102 | + }; |
| 103 | + expect(ToolRequest.isToolRequestParameters(invalidRequiredParams)).to.be.false; |
| 104 | + }); |
| 105 | + |
| 106 | + it('should validate properties with anyOf correctly', () => { |
| 107 | + const paramsWithAnyOf = { |
| 108 | + type: 'object', |
| 109 | + properties: { |
| 110 | + param1: { |
| 111 | + anyOf: [ |
| 112 | + { type: 'string' }, |
| 113 | + { type: 'number' } |
| 114 | + ] |
| 115 | + } |
| 116 | + }, |
| 117 | + required: ['param1'] |
| 118 | + }; |
| 119 | + expect(ToolRequest.isToolRequestParameters(paramsWithAnyOf)).to.be.true; |
| 120 | + }); |
| 121 | +}); |
0 commit comments