mirror of
https://github.com/coder/coder.git
synced 2025-07-15 21:43:49 +00:00
fix(codersdk/toolsdk): ensure all tools include required fields of aisdk.Schema (#17632)
This commit is contained in:
@ -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) {
|
||||
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user