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

This commit is contained in:
Cian Johnston
2025-05-01 13:19:35 +01:00
committed by GitHub
parent ef00ae54f4
commit 4ac71e9fd9
2 changed files with 29 additions and 0 deletions

View File

@ -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) {

View File

@ -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) {