Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(codersdk/toolsdk): ensure all tools include required fields of aisdk.Schema #17632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions codersdk/toolsdk/toolsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ var ListWorkspaces = Tool[ListWorkspacesArgs, []MinimalWorkspace]{
"description": "The owner of the workspaces to list. Use \"me\" to list workspaces for the authenticated user. If you do not specify an owner, \"me\" will be assumed by default.",
},
},
Required: []string{},
},
},
Handler: func(ctx context.Context, deps Deps, args ListWorkspacesArgs) ([]MinimalWorkspace, error) {
Expand Down Expand Up @@ -1256,6 +1257,7 @@ var DeleteTemplate = Tool[DeleteTemplateArgs, codersdk.Response]{
"type": "string",
},
},
Required: []string{"template_id"},
},
},
Handler: func(ctx context.Context, deps Deps, args DeleteTemplateArgs) (codersdk.Response, error) {
Expand Down
27 changes: 27 additions & 0 deletions codersdk/toolsdk/toolsdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,33 @@ func TestWithCleanContext(t *testing.T) {
})
}

func TestToolSchemaFields(t *testing.T) {
t.Parallel()

// Test that all tools have the required Schema fields (Properties and Required)
for _, tool := range toolsdk.All {
t.Run(tool.Tool.Name, func(t *testing.T) {
t.Parallel()

// Check that Properties is not nil
require.NotNil(t, tool.Tool.Schema.Properties,
"Tool %q missing Schema.Properties", tool.Tool.Name)

// Check that Required is not nil
require.NotNil(t, tool.Tool.Schema.Required,
"Tool %q missing Schema.Required", tool.Tool.Name)

// Ensure Properties has entries for all required fields
for _, requiredField := range tool.Tool.Schema.Required {
_, exists := tool.Tool.Schema.Properties[requiredField]
require.True(t, exists,
"Tool %q requires field %q but it is not defined in Properties",
tool.Tool.Name, requiredField)
}
})
}
}

// TestMain runs after all tests to ensure that all tools in this package have
// been tested once.
func TestMain(m *testing.M) {
Expand Down
Loading