summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/tool-registry.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/core/src/tools/tool-registry.test.ts')
-rw-r--r--packages/core/src/tools/tool-registry.test.ts109
1 files changed, 77 insertions, 32 deletions
diff --git a/packages/core/src/tools/tool-registry.test.ts b/packages/core/src/tools/tool-registry.test.ts
index fba48c17..853f6458 100644
--- a/packages/core/src/tools/tool-registry.test.ts
+++ b/packages/core/src/tools/tool-registry.test.ts
@@ -326,6 +326,83 @@ describe('ToolRegistry', () => {
});
describe('sanitizeParameters', () => {
+ it('should remove default when anyOf is present', () => {
+ const schema: Schema = {
+ anyOf: [{ type: Type.STRING }, { type: Type.NUMBER }],
+ default: 'hello',
+ };
+ sanitizeParameters(schema);
+ expect(schema.default).toBeUndefined();
+ });
+
+ it('should recursively sanitize items in anyOf', () => {
+ const schema: Schema = {
+ anyOf: [
+ {
+ anyOf: [{ type: Type.STRING }],
+ default: 'world',
+ },
+ { type: Type.NUMBER },
+ ],
+ };
+ sanitizeParameters(schema);
+ expect(schema.anyOf![0].default).toBeUndefined();
+ });
+
+ it('should recursively sanitize items in items', () => {
+ const schema: Schema = {
+ items: {
+ anyOf: [{ type: Type.STRING }],
+ default: 'world',
+ },
+ };
+ sanitizeParameters(schema);
+ expect(schema.items!.default).toBeUndefined();
+ });
+
+ it('should recursively sanitize items in properties', () => {
+ const schema: Schema = {
+ properties: {
+ prop1: {
+ anyOf: [{ type: Type.STRING }],
+ default: 'world',
+ },
+ },
+ };
+ sanitizeParameters(schema);
+ expect(schema.properties!.prop1.default).toBeUndefined();
+ });
+
+ it('should handle complex nested schemas', () => {
+ const schema: Schema = {
+ properties: {
+ prop1: {
+ items: {
+ anyOf: [{ type: Type.STRING }],
+ default: 'world',
+ },
+ },
+ prop2: {
+ anyOf: [
+ {
+ properties: {
+ nestedProp: {
+ anyOf: [{ type: Type.NUMBER }],
+ default: 123,
+ },
+ },
+ },
+ ],
+ },
+ },
+ };
+ sanitizeParameters(schema);
+ expect(schema.properties!.prop1.items!.default).toBeUndefined();
+ const nestedProp =
+ schema.properties!.prop2.anyOf![0].properties!.nestedProp;
+ expect(nestedProp?.default).toBeUndefined();
+ });
+
it('should remove unsupported format from a simple string property', () => {
const schema: Schema = {
type: Type.OBJECT,
@@ -356,25 +433,6 @@ describe('sanitizeParameters', () => {
expect(schema).toEqual(originalSchema);
});
- it('should handle nested objects recursively', () => {
- const schema: Schema = {
- type: Type.OBJECT,
- properties: {
- user: {
- type: Type.OBJECT,
- properties: {
- email: { type: Type.STRING, format: 'email' },
- },
- },
- },
- };
- sanitizeParameters(schema);
- expect(schema.properties?.['user']?.properties?.['email']).toHaveProperty(
- 'format',
- undefined,
- );
- });
-
it('should handle arrays of objects', () => {
const schema: Schema = {
type: Type.OBJECT,
@@ -414,19 +472,6 @@ describe('sanitizeParameters', () => {
expect(() => sanitizeParameters(undefined)).not.toThrow();
});
- it('should handle cyclic schemas without crashing', () => {
- const schema: any = {
- type: Type.OBJECT,
- properties: {
- name: { type: Type.STRING, format: 'hostname' },
- },
- };
- schema.properties.self = schema;
-
- expect(() => sanitizeParameters(schema)).not.toThrow();
- expect(schema.properties.name).toHaveProperty('format', undefined);
- });
-
it('should handle complex nested schemas with cycles', () => {
const userNode: any = {
type: Type.OBJECT,