Skip to content

Commit 4ac71e9

Browse files
authored
fix(codersdk/toolsdk): ensure all tools include required fields of aisdk.Schema (#17632)
1 parent ef00ae5 commit 4ac71e9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

codersdk/toolsdk/toolsdk.go

+2
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ var ListWorkspaces = Tool[ListWorkspacesArgs, []MinimalWorkspace]{
327327
"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.",
328328
},
329329
},
330+
Required: []string{},
330331
},
331332
},
332333
Handler: func(ctx context.Context, deps Deps, args ListWorkspacesArgs) ([]MinimalWorkspace, error) {
@@ -1256,6 +1257,7 @@ var DeleteTemplate = Tool[DeleteTemplateArgs, codersdk.Response]{
12561257
"type": "string",
12571258
},
12581259
},
1260+
Required: []string{"template_id"},
12591261
},
12601262
},
12611263
Handler: func(ctx context.Context, deps Deps, args DeleteTemplateArgs) (codersdk.Response, error) {

codersdk/toolsdk/toolsdk_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,33 @@ func TestWithCleanContext(t *testing.T) {
539539
})
540540
}
541541

542+
func TestToolSchemaFields(t *testing.T) {
543+
t.Parallel()
544+
545+
// Test that all tools have the required Schema fields (Properties and Required)
546+
for _, tool := range toolsdk.All {
547+
t.Run(tool.Tool.Name, func(t *testing.T) {
548+
t.Parallel()
549+
550+
// Check that Properties is not nil
551+
require.NotNil(t, tool.Tool.Schema.Properties,
552+
"Tool %q missing Schema.Properties", tool.Tool.Name)
553+
554+
// Check that Required is not nil
555+
require.NotNil(t, tool.Tool.Schema.Required,
556+
"Tool %q missing Schema.Required", tool.Tool.Name)
557+
558+
// Ensure Properties has entries for all required fields
559+
for _, requiredField := range tool.Tool.Schema.Required {
560+
_, exists := tool.Tool.Schema.Properties[requiredField]
561+
require.True(t, exists,
562+
"Tool %q requires field %q but it is not defined in Properties",
563+
tool.Tool.Name, requiredField)
564+
}
565+
})
566+
}
567+
}
568+
542569
// TestMain runs after all tests to ensure that all tools in this package have
543570
// been tested once.
544571
func TestMain(m *testing.M) {

0 commit comments

Comments
 (0)