|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { |
| 3 | + createObjectTool, |
| 4 | + addFieldTool, |
| 5 | + modifyFieldTool, |
| 6 | + deleteFieldTool, |
| 7 | + listObjectsTool, |
| 8 | + describeObjectTool, |
| 9 | + METADATA_TOOLS, |
| 10 | + METADATA_TOOL_NAMES, |
| 11 | +} from './metadata-tools.zod'; |
| 12 | +import { ToolSchema } from './tool.zod'; |
| 13 | + |
| 14 | +describe('Metadata Tools — individual definitions', () => { |
| 15 | + it('create_object should have correct structure', () => { |
| 16 | + expect(createObjectTool.name).toBe('create_object'); |
| 17 | + expect(createObjectTool.label).toBe('Create Object'); |
| 18 | + expect(createObjectTool.category).toBe('action'); |
| 19 | + expect(createObjectTool.builtIn).toBe(true); |
| 20 | + expect(createObjectTool.requiresConfirmation).toBe(true); |
| 21 | + expect(createObjectTool.permissions).toContain('metadata.object.create'); |
| 22 | + expect(createObjectTool.parameters).toHaveProperty('required'); |
| 23 | + expect((createObjectTool.parameters as Record<string, unknown>).required).toContain('name'); |
| 24 | + expect((createObjectTool.parameters as Record<string, unknown>).required).toContain('label'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('add_field should have correct structure', () => { |
| 28 | + expect(addFieldTool.name).toBe('add_field'); |
| 29 | + expect(addFieldTool.label).toBe('Add Field'); |
| 30 | + expect(addFieldTool.category).toBe('action'); |
| 31 | + expect(addFieldTool.builtIn).toBe(true); |
| 32 | + expect(addFieldTool.requiresConfirmation).toBe(true); |
| 33 | + expect(addFieldTool.permissions).toContain('metadata.field.create'); |
| 34 | + expect((addFieldTool.parameters as Record<string, unknown>).required).toContain('objectName'); |
| 35 | + expect((addFieldTool.parameters as Record<string, unknown>).required).toContain('name'); |
| 36 | + expect((addFieldTool.parameters as Record<string, unknown>).required).toContain('type'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('modify_field should have correct structure', () => { |
| 40 | + expect(modifyFieldTool.name).toBe('modify_field'); |
| 41 | + expect(modifyFieldTool.label).toBe('Modify Field'); |
| 42 | + expect(modifyFieldTool.category).toBe('action'); |
| 43 | + expect(modifyFieldTool.builtIn).toBe(true); |
| 44 | + expect(modifyFieldTool.requiresConfirmation).toBe(true); |
| 45 | + expect(modifyFieldTool.permissions).toContain('metadata.field.update'); |
| 46 | + expect((modifyFieldTool.parameters as Record<string, unknown>).required).toContain('objectName'); |
| 47 | + expect((modifyFieldTool.parameters as Record<string, unknown>).required).toContain('fieldName'); |
| 48 | + expect((modifyFieldTool.parameters as Record<string, unknown>).required).toContain('changes'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('delete_field should have correct structure', () => { |
| 52 | + expect(deleteFieldTool.name).toBe('delete_field'); |
| 53 | + expect(deleteFieldTool.label).toBe('Delete Field'); |
| 54 | + expect(deleteFieldTool.category).toBe('action'); |
| 55 | + expect(deleteFieldTool.builtIn).toBe(true); |
| 56 | + expect(deleteFieldTool.requiresConfirmation).toBe(true); |
| 57 | + expect(deleteFieldTool.permissions).toContain('metadata.field.delete'); |
| 58 | + expect((deleteFieldTool.parameters as Record<string, unknown>).required).toContain('objectName'); |
| 59 | + expect((deleteFieldTool.parameters as Record<string, unknown>).required).toContain('fieldName'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('list_objects should have correct structure', () => { |
| 63 | + expect(listObjectsTool.name).toBe('list_objects'); |
| 64 | + expect(listObjectsTool.label).toBe('List Objects'); |
| 65 | + expect(listObjectsTool.category).toBe('data'); |
| 66 | + expect(listObjectsTool.builtIn).toBe(true); |
| 67 | + expect(listObjectsTool.requiresConfirmation).toBe(false); |
| 68 | + expect(listObjectsTool.permissions).toContain('metadata.object.read'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('describe_object should have correct structure', () => { |
| 72 | + expect(describeObjectTool.name).toBe('describe_object'); |
| 73 | + expect(describeObjectTool.label).toBe('Describe Object'); |
| 74 | + expect(describeObjectTool.category).toBe('data'); |
| 75 | + expect(describeObjectTool.builtIn).toBe(true); |
| 76 | + expect(describeObjectTool.requiresConfirmation).toBe(false); |
| 77 | + expect(describeObjectTool.permissions).toContain('metadata.object.read'); |
| 78 | + expect((describeObjectTool.parameters as Record<string, unknown>).required).toContain('objectName'); |
| 79 | + }); |
| 80 | +}); |
| 81 | + |
| 82 | +describe('Metadata Tools — schema validation', () => { |
| 83 | + it('every tool should pass ToolSchema validation', () => { |
| 84 | + METADATA_TOOLS.forEach(tool => { |
| 85 | + expect(() => ToolSchema.parse(tool)).not.toThrow(); |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + it('every tool should have a description for LLM consumption', () => { |
| 90 | + METADATA_TOOLS.forEach(tool => { |
| 91 | + expect(tool.description.length).toBeGreaterThan(20); |
| 92 | + }); |
| 93 | + }); |
| 94 | + |
| 95 | + it('every tool should have parameters as a JSON Schema object', () => { |
| 96 | + METADATA_TOOLS.forEach(tool => { |
| 97 | + expect(tool.parameters).toHaveProperty('type', 'object'); |
| 98 | + expect(tool.parameters).toHaveProperty('properties'); |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | + it('every tool should have an outputSchema', () => { |
| 103 | + METADATA_TOOLS.forEach(tool => { |
| 104 | + expect(tool.outputSchema).toBeDefined(); |
| 105 | + expect(tool.outputSchema).toHaveProperty('type', 'object'); |
| 106 | + }); |
| 107 | + }); |
| 108 | + |
| 109 | + it('every tool should have permissions defined', () => { |
| 110 | + METADATA_TOOLS.forEach(tool => { |
| 111 | + expect(tool.permissions).toBeDefined(); |
| 112 | + expect(tool.permissions!.length).toBeGreaterThan(0); |
| 113 | + }); |
| 114 | + }); |
| 115 | + |
| 116 | + it('every tool should be marked as builtIn', () => { |
| 117 | + METADATA_TOOLS.forEach(tool => { |
| 118 | + expect(tool.builtIn).toBe(true); |
| 119 | + }); |
| 120 | + }); |
| 121 | + |
| 122 | + it('write tools should require confirmation, read tools should not', () => { |
| 123 | + const writeTools = [createObjectTool, addFieldTool, modifyFieldTool, deleteFieldTool]; |
| 124 | + const readTools = [listObjectsTool, describeObjectTool]; |
| 125 | + |
| 126 | + writeTools.forEach(tool => { |
| 127 | + expect(tool.requiresConfirmation).toBe(true); |
| 128 | + }); |
| 129 | + readTools.forEach(tool => { |
| 130 | + expect(tool.requiresConfirmation).toBe(false); |
| 131 | + }); |
| 132 | + }); |
| 133 | +}); |
| 134 | + |
| 135 | +describe('METADATA_TOOLS aggregate', () => { |
| 136 | + it('should contain exactly 6 tools', () => { |
| 137 | + expect(METADATA_TOOLS).toHaveLength(6); |
| 138 | + }); |
| 139 | + |
| 140 | + it('should match METADATA_TOOL_NAMES ordering', () => { |
| 141 | + METADATA_TOOLS.forEach((tool, index) => { |
| 142 | + expect(tool.name).toBe(METADATA_TOOL_NAMES[index]); |
| 143 | + }); |
| 144 | + }); |
| 145 | + |
| 146 | + it('METADATA_TOOL_NAMES should contain all expected names', () => { |
| 147 | + expect(METADATA_TOOL_NAMES).toEqual([ |
| 148 | + 'create_object', |
| 149 | + 'add_field', |
| 150 | + 'modify_field', |
| 151 | + 'delete_field', |
| 152 | + 'list_objects', |
| 153 | + 'describe_object', |
| 154 | + ]); |
| 155 | + }); |
| 156 | + |
| 157 | + it('every tool name should follow snake_case convention', () => { |
| 158 | + METADATA_TOOL_NAMES.forEach(name => { |
| 159 | + expect(name).toMatch(/^[a-z_][a-z0-9_]*$/); |
| 160 | + }); |
| 161 | + }); |
| 162 | +}); |
0 commit comments