| import json |
| from typing import Any |
|
|
| from tool_schemas import ( |
| TOOL_SCHEMAS, |
| get_tool_names, |
| get_tool_schema, |
| get_tool_schemas, |
| ) |
| from tools import TOOL_FUNCTIONS |
|
|
|
|
| EXPECTED_TOOL_NAMES = { |
| "search_books", |
| "create_order", |
| "get_order_status", |
| } |
|
|
|
|
| def validate_schema_structure( |
| schema: dict[str, Any], |
| ) -> None: |
| """Tek bir tool şemasının temel yapısını doğrular.""" |
|
|
| assert schema["type"] == "function" |
| assert "function" in schema |
|
|
| function = schema["function"] |
|
|
| assert isinstance(function["name"], str) |
| assert function["name"] |
| assert isinstance(function["description"], str) |
| assert function["description"] |
|
|
| parameters = function["parameters"] |
|
|
| assert parameters["type"] == "object" |
| assert isinstance(parameters["properties"], dict) |
| assert isinstance(parameters["required"], list) |
| assert parameters["additionalProperties"] is False |
|
|
| property_names = set(parameters["properties"]) |
| required_names = set(parameters["required"]) |
|
|
| assert required_names.issubset(property_names) |
|
|
|
|
| def print_schema( |
| schema: dict[str, Any], |
| ) -> None: |
| """Şemayı okunabilir JSON biçiminde yazdırır.""" |
|
|
| print( |
| json.dumps( |
| schema, |
| ensure_ascii=False, |
| indent=2, |
| ) |
| ) |
|
|
|
|
| def main() -> None: |
| print("=" * 80) |
| print("TOOL SCHEMA TESTLERİ") |
| print("=" * 80) |
|
|
| print("\n1. Tool sayısı kontrol ediliyor...") |
|
|
| assert len(TOOL_SCHEMAS) == 3 |
|
|
| print("✅ Toplam üç tool şeması bulundu.") |
|
|
| print("\n2. Tool isimleri kontrol ediliyor...") |
|
|
| schema_tool_names = get_tool_names() |
| function_tool_names = set(TOOL_FUNCTIONS) |
|
|
| assert schema_tool_names == EXPECTED_TOOL_NAMES |
| assert function_tool_names == EXPECTED_TOOL_NAMES |
| assert schema_tool_names == function_tool_names |
|
|
| print("✅ Şemalar ile Python fonksiyonlarının isimleri eşleşiyor.") |
|
|
| print("\n3. JSON Schema yapıları kontrol ediliyor...") |
|
|
| for schema in TOOL_SCHEMAS: |
| validate_schema_structure(schema) |
|
|
| print( |
| f"✅ {schema['function']['name']} " |
| "şeması geçerli." |
| ) |
|
|
| print("\n4. Zorunlu parametreler kontrol ediliyor...") |
|
|
| search_schema = get_tool_schema("search_books") |
| create_schema = get_tool_schema("create_order") |
| status_schema = get_tool_schema("get_order_status") |
|
|
| assert search_schema is not None |
| assert create_schema is not None |
| assert status_schema is not None |
|
|
| assert ( |
| search_schema["function"]["parameters"]["required"] |
| == [] |
| ) |
|
|
| assert set( |
| create_schema["function"]["parameters"]["required"] |
| ) == { |
| "book_id", |
| "quantity", |
| "customer_name", |
| } |
|
|
| assert ( |
| status_schema["function"]["parameters"]["required"] |
| == ["order_id"] |
| ) |
|
|
| print("✅ Zorunlu parametreler doğru.") |
|
|
| print("\n5. Strict mode kontrol ediliyor...") |
|
|
| normal_schemas = get_tool_schemas(strict=False) |
| strict_schemas = get_tool_schemas(strict=True) |
|
|
| for schema in normal_schemas: |
| assert "strict" not in schema["function"] |
|
|
| for schema in strict_schemas: |
| assert schema["function"]["strict"] is True |
|
|
| print("✅ Normal ve strict şemalar doğru üretildi.") |
|
|
| print("\n6. Orijinal şemaların değişmediği kontrol ediliyor...") |
|
|
| for schema in TOOL_SCHEMAS: |
| assert "strict" not in schema["function"] |
|
|
| print("✅ Şema kopyalama sistemi güvenli çalışıyor.") |
|
|
| print("\n" + "-" * 80) |
| print("MODELE GÖNDERİLECEK TOOL ŞEMALARI") |
| print("-" * 80) |
|
|
| for schema in TOOL_SCHEMAS: |
| print_schema(schema) |
| print("-" * 80) |
|
|
| print("\n" + "#" * 80) |
| print("🎉 BÜTÜN TOOL SCHEMA TESTLERİ BAŞARIYLA TAMAMLANDI") |
| print("#" * 80) |
|
|
|
|
| if __name__ == "__main__": |
| main() |