Skip to content

Commit b353c52

Browse files
drstrangelookerAnthrino
authored andcommitted
fixes for the return type of invoke, the import, and the prebuilt config test. fixes for integration tests
1 parent 469c745 commit b353c52

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

cmd/internal/imports.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ import (
120120
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetdimensions"
121121
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetexplores"
122122
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetfilters"
123+
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetlookmltests"
123124
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetlooks"
124125
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetmeasures"
125126
_ "github.com/googleapis/genai-toolbox/internal/tools/looker/lookergetmodels"

cmd/internal/tools_file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ func TestPrebuiltTools(t *testing.T) {
17781778
wantToolset: server.ToolsetConfigs{
17791779
"looker_tools": tools.ToolsetConfig{
17801780
Name: "looker_tools",
1781-
ToolNames: []string{"get_models", "get_explores", "get_dimensions", "get_measures", "get_filters", "get_parameters", "query", "query_sql", "query_url", "get_looks", "run_look", "make_look", "get_dashboards", "run_dashboard", "make_dashboard", "add_dashboard_element", "add_dashboard_filter", "generate_embed_url", "health_pulse", "health_analyze", "health_vacuum", "dev_mode", "get_projects", "get_project_files", "get_project_file", "create_project_file", "update_project_file", "delete_project_file", "get_project_directories", "create_project_directory", "delete_project_directory", "validate_project", "get_connections", "get_connection_schemas", "get_connection_databases", "get_connection_tables", "get_connection_table_columns"},
1781+
ToolNames: []string{"get_models", "get_explores", "get_dimensions", "get_measures", "get_filters", "get_parameters", "query", "query_sql", "query_url", "get_looks", "run_look", "make_look", "get_dashboards", "run_dashboard", "make_dashboard", "add_dashboard_element", "add_dashboard_filter", "generate_embed_url", "health_pulse", "health_analyze", "health_vacuum", "dev_mode", "get_projects", "get_project_files", "get_project_file", "create_project_file", "update_project_file", "delete_project_file", "get_project_directories", "create_project_directory", "delete_project_directory", "validate_project", "get_connections", "get_connection_schemas", "get_connection_databases", "get_connection_tables", "get_connection_table_columns", "get_lookml_tests"},
17821782
},
17831783
},
17841784
},

internal/tools/looker/lookergetlookmltests/lookergetlookmltests.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ package lookergetlookmltests
1717
import (
1818
"context"
1919
"fmt"
20+
"net/http"
2021

2122
yaml "github.com/goccy/go-yaml"
2223
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
2324
"github.com/googleapis/genai-toolbox/internal/sources"
2425
"github.com/googleapis/genai-toolbox/internal/tools"
26+
"github.com/googleapis/genai-toolbox/internal/util"
2527
"github.com/googleapis/genai-toolbox/internal/util/parameters"
2628

2729
"github.com/looker-open-source/sdk-codegen/go/rtl"
@@ -109,31 +111,31 @@ func (t Tool) ToConfig() tools.ToolConfig {
109111
return t.Config
110112
}
111113

112-
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
114+
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
113115
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
114116
if err != nil {
115-
return nil, err
117+
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
116118
}
117119

118120
sdk, err := source.GetLookerSDK(string(accessToken))
119121
if err != nil {
120-
return nil, fmt.Errorf("error getting sdk: %w", err)
122+
return nil, util.NewClientServerError(fmt.Sprintf("error getting sdk: %v", err), http.StatusInternalServerError, err)
121123
}
122124

123125
mapParams := params.AsMap()
124126
projectId, ok := mapParams["project_id"].(string)
125127
if !ok {
126-
return nil, fmt.Errorf("'project_id' must be a string, got %T", mapParams["project_id"])
128+
return nil, util.NewAgentError(fmt.Sprintf("'project_id' must be a string, got %T", mapParams["project_id"]), nil)
127129
}
128130

129-
var fileId *string
130-
if val, ok := mapParams["file_id"].(string); ok && val != "" {
131-
fileId = &val
131+
var fileId string
132+
if val, ok := mapParams["file_id"].(string); ok {
133+
fileId = val
132134
}
133135

134136
resp, err := sdk.AllLookmlTests(projectId, fileId, source.LookerApiSettings())
135137
if err != nil {
136-
return nil, fmt.Errorf("error retrieving lookml tests: %w", err)
138+
return nil, util.NewClientServerError(fmt.Sprintf("error retrieving lookml tests: %s", err), http.StatusInternalServerError, err)
137139
}
138140

139141
return resp, nil

tests/looker/looker_integration_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,14 +709,14 @@ func TestLooker(t *testing.T) {
709709
"parameters": []any{
710710
map[string]any{
711711
"authSources": []any{},
712-
"description": "The id of the project to retrieve LookML tests for.",
712+
"description": "The unique ID of the LookML project.",
713713
"name": "project_id",
714714
"required": true,
715715
"type": "string",
716716
},
717717
map[string]any{
718718
"authSources": []any{},
719-
"description": "Optional id of the file to filter tests by.",
719+
"description": "Optional ID of the file to filter tests by. This must be the complete file path from the project root (e.g., 'models/my_model.model.lkml').",
720720
"name": "file_id",
721721
"required": false,
722722
"type": "string",
@@ -1808,6 +1808,9 @@ func TestLooker(t *testing.T) {
18081808
wantResult = "\"errors\":[]"
18091809
tests.RunToolInvokeParametersTest(t, "validate_project", []byte(`{"project_id": "the_look"}`), wantResult)
18101810

1811+
wantResult = "[]"
1812+
tests.RunToolInvokeParametersTest(t, "get_lookml_tests", []byte(`{"project_id": "the_look"}`), wantResult)
1813+
18111814
wantResult = "production"
18121815
tests.RunToolInvokeParametersTest(t, "dev_mode", []byte(`{"devMode": false}`), wantResult)
18131816

0 commit comments

Comments
 (0)