chore: update yaml tag for tools (#2356)

Update yaml tag in tools from `kind` to `type`.

Upcoming PRs: 
* Update config in `/tests` and `/docs`

Will resolve other unit tests failure in the final PR to keep things
simpler.
This commit is contained in:
Yuan Teoh
2026-01-26 17:53:37 -08:00
committed by Yuan Teoh
parent 83ebaf20b7
commit 474e480b2c
369 changed files with 4707 additions and 5752 deletions

View File

@@ -27,11 +27,11 @@ import (
sqladmin "google.golang.org/api/sqladmin/v1"
)
const kind string = "cloud-sql-postgres-create-instance"
const resourceType string = "cloud-sql-postgres-create-instance"
func init() {
if !tools.Register(kind, newConfig) {
panic(fmt.Sprintf("tool type %q already registered", kind))
if !tools.Register(resourceType, newConfig) {
panic(fmt.Sprintf("tool type %q already registered", resourceType))
}
}
@@ -52,7 +52,7 @@ type compatibleSource interface {
// Config defines the configuration for the create-instances tool.
type Config struct {
Name string `yaml:"name" validate:"required"`
Type string `yaml:"kind" validate:"required"`
Type string `yaml:"type" validate:"required"`
Description string `yaml:"description"`
Source string `yaml:"source" validate:"required"`
AuthRequired []string `yaml:"authRequired"`
@@ -61,9 +61,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -74,7 +74,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
}
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source kind must be `cloud-sql-admin`", kind)
return nil, fmt.Errorf("invalid source for %q tool: source type must be `cloud-sql-admin`", resourceType)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package cloudsqlpgcreateinstances_test
import (
"testing"
yaml "github.com/goccy/go-yaml"
"github.com/google/go-cmp/cmp"
"github.com/googleapis/genai-toolbox/internal/server"
"github.com/googleapis/genai-toolbox/internal/testutils"
@@ -37,11 +36,11 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
create-instance-tool:
kind: cloud-sql-postgres-create-instance
description: a test description
source: a-source
kind: tools
name: create-instance-tool
type: cloud-sql-postgres-create-instance
description: a test description
source: a-source
`,
want: server.ToolConfigs{
"create-instance-tool": cloudsqlpgcreateinstances.Config{
@@ -56,15 +55,11 @@ func TestParseFromYaml(t *testing.T) {
}
for _, tc := range tcs {
t.Run(tc.desc, func(t *testing.T) {
got := struct {
Tools server.ToolConfigs `yaml:"tools"`
}{}
// Parse contents
err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got)
_, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in))
if err != nil {
t.Fatalf("unable to unmarshal: %s", err)
}
if diff := cmp.Diff(tc.want, got.Tools); diff != "" {
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Fatalf("incorrect parse: diff %v", diff)
}
})

View File

@@ -27,11 +27,11 @@ import (
sqladmin "google.golang.org/api/sqladmin/v1"
)
const kind string = "postgres-upgrade-precheck"
const resourceType string = "postgres-upgrade-precheck"
func init() {
if !tools.Register(kind, newConfig) {
panic(fmt.Sprintf("tool type %q already registered", kind))
if !tools.Register(resourceType, newConfig) {
panic(fmt.Sprintf("tool type %q already registered", resourceType))
}
}
@@ -51,7 +51,7 @@ type compatibleSource interface {
// Config defines the configuration for the precheck-upgrade tool.
type Config struct {
Name string `yaml:"name" validate:"required"`
Type string `yaml:"kind" validate:"required"`
Type string `yaml:"type" validate:"required"`
Description string `yaml:"description"`
Source string `yaml:"source" validate:"required"`
AuthRequired []string `yaml:"authRequired"`
@@ -60,9 +60,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.

View File

@@ -17,7 +17,6 @@ package cloudsqlpgupgradeprecheck_test
import (
"testing"
yaml "github.com/goccy/go-yaml"
"github.com/google/go-cmp/cmp"
"github.com/googleapis/genai-toolbox/internal/server"
"github.com/googleapis/genai-toolbox/internal/testutils"
@@ -37,13 +36,13 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic precheck example",
in: `
tools:
precheck-upgrade-tool:
kind: postgres-upgrade-precheck
description: a precheck test description
source: some-admin-source
authRequired:
- https://www.googleapis.com/auth/cloud-platform
kind: tools
name: precheck-upgrade-tool
type: postgres-upgrade-precheck
description: a precheck test description
source: some-admin-source
authRequired:
- https://www.googleapis.com/auth/cloud-platform
`,
want: server.ToolConfigs{
"precheck-upgrade-tool": cloudsqlpgupgradeprecheck.Config{
@@ -58,11 +57,11 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "precheck example with no auth",
in: `
tools:
precheck-upgrade-tool-no-auth:
kind: postgres-upgrade-precheck
description: a precheck test description no auth
source: other-admin-source
kind: tools
name: precheck-upgrade-tool-no-auth
type: postgres-upgrade-precheck
description: a precheck test description no auth
source: other-admin-source
`,
want: server.ToolConfigs{
"precheck-upgrade-tool-no-auth": cloudsqlpgupgradeprecheck.Config{
@@ -77,15 +76,11 @@ func TestParseFromYaml(t *testing.T) {
}
for _, tc := range tcs {
t.Run(tc.desc, func(t *testing.T) {
got := struct {
Tools server.ToolConfigs `yaml:"tools"`
}{}
// Parse contents
err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got)
_, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in))
if err != nil {
t.Fatalf("unable to unmarshal: %s", err)
}
if diff := cmp.Diff(tc.want, got.Tools); diff != "" {
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Fatalf("incorrect parse: diff (-want +got):\n%s", diff)
}
})