|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +package visitor |
| 4 | + |
| 5 | +import ( |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/mendixlabs/mxcli/mdl/ast" |
| 9 | +) |
| 10 | + |
| 11 | +func TestCreateModel(t *testing.T) { |
| 12 | + input := `CREATE MODEL MyModule.GPT4 ( |
| 13 | + Provider: MxCloudGenAI, |
| 14 | + Key: MyModule.APIKey, |
| 15 | + DisplayName: 'GPT-4 Turbo' |
| 16 | + );` |
| 17 | + prog, errs := Build(input) |
| 18 | + if len(errs) > 0 { |
| 19 | + for _, e := range errs { |
| 20 | + t.Errorf("Parse error: %v", e) |
| 21 | + } |
| 22 | + return |
| 23 | + } |
| 24 | + stmt, ok := prog.Statements[0].(*ast.CreateModelStmt) |
| 25 | + if !ok { |
| 26 | + t.Fatalf("Expected CreateModelStmt, got %T", prog.Statements[0]) |
| 27 | + } |
| 28 | + if stmt.Name.Module != "MyModule" || stmt.Name.Name != "GPT4" { |
| 29 | + t.Errorf("Expected MyModule.GPT4, got %s.%s", stmt.Name.Module, stmt.Name.Name) |
| 30 | + } |
| 31 | + if stmt.Provider != "MxCloudGenAI" { |
| 32 | + t.Errorf("Got Provider %q", stmt.Provider) |
| 33 | + } |
| 34 | + if stmt.Key == nil || stmt.Key.Name != "APIKey" { |
| 35 | + t.Error("Key mismatch") |
| 36 | + } |
| 37 | + if stmt.DisplayName != "GPT-4 Turbo" { |
| 38 | + t.Errorf("Got DisplayName %q", stmt.DisplayName) |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +func TestCreateConsumedMCPService(t *testing.T) { |
| 43 | + input := `CREATE CONSUMED MCP SERVICE MyModule.ToolService ( |
| 44 | + ProtocolVersion: v2025_03_26, |
| 45 | + Version: '0.0.1', |
| 46 | + ConnectionTimeoutSeconds: 30, |
| 47 | + Documentation: 'MCP tool service' |
| 48 | + );` |
| 49 | + prog, errs := Build(input) |
| 50 | + if len(errs) > 0 { |
| 51 | + for _, e := range errs { |
| 52 | + t.Errorf("Parse error: %v", e) |
| 53 | + } |
| 54 | + return |
| 55 | + } |
| 56 | + stmt, ok := prog.Statements[0].(*ast.CreateConsumedMCPServiceStmt) |
| 57 | + if !ok { |
| 58 | + t.Fatalf("Expected CreateConsumedMCPServiceStmt, got %T", prog.Statements[0]) |
| 59 | + } |
| 60 | + if stmt.ProtocolVersion != "v2025_03_26" { |
| 61 | + t.Errorf("Got ProtocolVersion %q", stmt.ProtocolVersion) |
| 62 | + } |
| 63 | + if stmt.Version != "0.0.1" { |
| 64 | + t.Errorf("Got Version %q", stmt.Version) |
| 65 | + } |
| 66 | + if stmt.ConnectionTimeoutSeconds != 30 { |
| 67 | + t.Errorf("Got ConnectionTimeoutSeconds %d", stmt.ConnectionTimeoutSeconds) |
| 68 | + } |
| 69 | + if stmt.InnerDocumentation != "MCP tool service" { |
| 70 | + t.Errorf("Got InnerDocumentation %q", stmt.InnerDocumentation) |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +func TestCreateKnowledgeBase(t *testing.T) { |
| 75 | + input := `CREATE KNOWLEDGE BASE MyModule.ProductKB ( |
| 76 | + Provider: MxCloudGenAI, |
| 77 | + Key: MyModule.KBKey, |
| 78 | + ModelDisplayName: 'Product Knowledge', |
| 79 | + ModelName: 'product-embeddings' |
| 80 | + );` |
| 81 | + prog, errs := Build(input) |
| 82 | + if len(errs) > 0 { |
| 83 | + for _, e := range errs { |
| 84 | + t.Errorf("Parse error: %v", e) |
| 85 | + } |
| 86 | + return |
| 87 | + } |
| 88 | + stmt, ok := prog.Statements[0].(*ast.CreateKnowledgeBaseStmt) |
| 89 | + if !ok { |
| 90 | + t.Fatalf("Expected CreateKnowledgeBaseStmt, got %T", prog.Statements[0]) |
| 91 | + } |
| 92 | + if stmt.Provider != "MxCloudGenAI" { |
| 93 | + t.Errorf("Got Provider %q", stmt.Provider) |
| 94 | + } |
| 95 | + if stmt.Key == nil || stmt.Key.Name != "KBKey" { |
| 96 | + t.Error("Key mismatch") |
| 97 | + } |
| 98 | + if stmt.ModelDisplayName != "Product Knowledge" { |
| 99 | + t.Errorf("Got ModelDisplayName %q", stmt.ModelDisplayName) |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +func TestCreateAgent_Basic(t *testing.T) { |
| 104 | + input := `CREATE AGENT MyModule.OrderAgent ( |
| 105 | + UsageType: Task, |
| 106 | + Model: MyModule.GPT4, |
| 107 | + Entity: MyModule.OrderContext, |
| 108 | + SystemPrompt: 'You are an order processing assistant.', |
| 109 | + ToolChoice: auto, |
| 110 | + MaxTokens: 4096, |
| 111 | + Temperature: 0.7 |
| 112 | + );` |
| 113 | + prog, errs := Build(input) |
| 114 | + if len(errs) > 0 { |
| 115 | + for _, e := range errs { |
| 116 | + t.Errorf("Parse error: %v", e) |
| 117 | + } |
| 118 | + return |
| 119 | + } |
| 120 | + stmt, ok := prog.Statements[0].(*ast.CreateAgentStmt) |
| 121 | + if !ok { |
| 122 | + t.Fatalf("Expected CreateAgentStmt, got %T", prog.Statements[0]) |
| 123 | + } |
| 124 | + if stmt.UsageType != "Task" { |
| 125 | + t.Errorf("Got UsageType %q", stmt.UsageType) |
| 126 | + } |
| 127 | + if stmt.Model == nil || stmt.Model.Name != "GPT4" { |
| 128 | + t.Error("Model mismatch") |
| 129 | + } |
| 130 | + if stmt.Entity == nil || stmt.Entity.Name != "OrderContext" { |
| 131 | + t.Error("Entity mismatch") |
| 132 | + } |
| 133 | + if stmt.MaxTokens == nil || *stmt.MaxTokens != 4096 { |
| 134 | + t.Error("MaxTokens mismatch") |
| 135 | + } |
| 136 | + if stmt.Temperature == nil || *stmt.Temperature != 0.7 { |
| 137 | + t.Error("Temperature mismatch") |
| 138 | + } |
| 139 | + if stmt.ToolChoice != "auto" { |
| 140 | + t.Errorf("Got ToolChoice %q", stmt.ToolChoice) |
| 141 | + } |
| 142 | +} |
0 commit comments