diff --git a/pkg/mcp/tools_delete_test.go b/pkg/mcp/tools_delete_test.go index 1bccc57df6..7cefc73416 100644 --- a/pkg/mcp/tools_delete_test.go +++ b/pkg/mcp/tools_delete_test.go @@ -8,6 +8,68 @@ import ( "knative.dev/func/pkg/mcp/mock" ) +// TestTool_Delete_Readonly ensures the delete tool returns an error when the server is in readonly mode. +func TestTool_Delete_Readonly(t *testing.T) { + client, _, err := newTestPairWithReadonly(t, true) + if err != nil { + t.Fatal(err) + } + + result, err := client.CallTool(t.Context(), &mcp.CallToolParams{ + Name: "delete", + Arguments: map[string]any{"name": "my-function"}, + }) + if err != nil { + t.Fatal(err) + } + if !result.IsError { + t.Fatal("expected error result for readonly server, got success") + } +} + +// TestTool_Delete_BothPathAndName ensures the delete tool returns a validation error +// when both path and name are provided simultaneously. +func TestTool_Delete_BothPathAndName(t *testing.T) { + client, _, err := newTestPair(t) + if err != nil { + t.Fatal(err) + } + + result, err := client.CallTool(t.Context(), &mcp.CallToolParams{ + Name: "delete", + Arguments: map[string]any{ + "path": "/some/path", + "name": "my-function", + }, + }) + if err != nil { + t.Fatal(err) + } + if !result.IsError { + t.Fatal("expected error result when both path and name are provided, got success") + } +} + +// TestTool_Delete_NeitherPathNorName ensures the delete tool returns a validation error +// when neither path nor name is provided. +func TestTool_Delete_NeitherPathNorName(t *testing.T) { + client, _, err := newTestPair(t) + if err != nil { + t.Fatal(err) + } + + result, err := client.CallTool(t.Context(), &mcp.CallToolParams{ + Name: "delete", + Arguments: map[string]any{}, + }) + if err != nil { + t.Fatal(err) + } + if !result.IsError { + t.Fatal("expected error result when neither path nor name is provided, got success") + } +} + // TestTool_Delete_Args ensures the delete tool executes with all arguments passed correctly. func TestTool_Delete_Args(t *testing.T) { // Test data - defined once and used for both input and validation diff --git a/pkg/mcp/tools_deploy_test.go b/pkg/mcp/tools_deploy_test.go index 4b8d2e83c4..2fc591237d 100644 --- a/pkg/mcp/tools_deploy_test.go +++ b/pkg/mcp/tools_deploy_test.go @@ -8,6 +8,25 @@ import ( "knative.dev/func/pkg/mcp/mock" ) +// TestTool_Deploy_Readonly ensures the deploy tool returns an error when the server is in readonly mode. +func TestTool_Deploy_Readonly(t *testing.T) { + client, _, err := newTestPairWithReadonly(t, true) + if err != nil { + t.Fatal(err) + } + + result, err := client.CallTool(t.Context(), &mcp.CallToolParams{ + Name: "deploy", + Arguments: map[string]any{"path": "."}, + }) + if err != nil { + t.Fatal(err) + } + if !result.IsError { + t.Fatal("expected error result for readonly server, got success") + } +} + // TestTool_Deploy_Args ensures the deploy tool executes with all arguments passed correctly. func TestTool_Deploy_Args(t *testing.T) { // Test data - defined once and used for both input and validation