package pier_test import ( "net/http" "strings" "testing" "git.golem15.com/golem15/summercms/modules/pact" ) type optionalPathInput struct { ID string `json:"id,omitempty" path:"id"` } type requiredPathInput struct { ID string `json:"id" path:"id"` } type pageFields struct { Title string `json:"title"` } type embeddedInput struct { pageFields ID string `json:"id" path:"id"` } // TestCatalogPathFields pins plan 06's boot rules for tool inputs (the boot // half of A-WR-02, A-IN-07): a path field marked omitempty fails boot and // the error names the field, the same field without it compiles, and an // embedded struct (whose promoted fields would be body fields) fails boot // on a GET tool and compiles on a POST tool. func TestCatalogPathFields(t *testing.T) { route := func(method string) testRoute { return guarded(method, "/fields/{id}") } tool := func(method string, input any) pact.MCPTool { return pact.MCPTool{Name: "f", Description: "Fields.", Method: method, Path: "/fields/{id}", Input: input} } mount := func(method string, input any) error { _, err := catalogMount(t, routePlugin{id: "test.fields", routes: []testRoute{route(method)}, tools: []pact.MCPTool{tool(method, input)}}) return err } t.Run("an omitempty path field fails boot naming the field", func(t *testing.T) { err := mount(http.MethodGet, optionalPathInput{}) if err == nil || !strings.Contains(err.Error(), `path field "id" must be required`) { t.Fatalf("err = %v", err) } }) t.Run("a required path field compiles", func(t *testing.T) { if err := mount(http.MethodGet, requiredPathInput{}); err != nil { t.Fatal(err) } }) t.Run("an embedded struct fails boot on a GET tool", func(t *testing.T) { err := mount(http.MethodGet, embeddedInput{}) if err == nil || !strings.Contains(err.Error(), `embedded field "pageFields"`) || !strings.Contains(err.Error(), "GET") { t.Fatalf("err = %v", err) } }) t.Run("an embedded struct compiles on a POST tool", func(t *testing.T) { if err := mount(http.MethodPost, embeddedInput{}); err != nil { t.Fatal(err) } }) }