From 8c63bb692acb86c28c440242bedd805c46dc1e3f Mon Sep 17 00:00:00 2001 From: Eden Reich Date: Mon, 5 Oct 2026 18:16:47 +0200 Subject: [PATCH] fix(go): start the doc comments after the optional loadAgentCard on their own line The {{- if ExtendedAgentCard }} action trimmed the blank line before it, so the generated main.go ran the next doc comment into the closing brace of the function above. Without the extended agent card that was `} // newRootCmd builds...`, with it `}// loadAgentCard reads...`, which gofmt leaves as a trailing comment and godoc no longer attaches to the function. Trim after the action instead, so both layouts keep a blank line before each doc comment. --- internal/templates/cli_template_test.go | 39 ++++++++++++++++++++ internal/templates/languages/go/main.go.tmpl | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/internal/templates/cli_template_test.go b/internal/templates/cli_template_test.go index e29925ff..d9d63f72 100644 --- a/internal/templates/cli_template_test.go +++ b/internal/templates/cli_template_test.go @@ -275,3 +275,42 @@ func TestGoMainTemplate_AdvertisesRuntimeAuthScheme(t *testing.T) { }) } } + +// TestGoMainTemplate_DocCommentsStartOnTheirOwnLine verifies the optional +// loadAgentCard block leaves a blank line before the next doc comment, so gofmt +// never glues it onto the closing brace of the function above. +func TestGoMainTemplate_DocCommentsStartOnTheirOwnLine(t *testing.T) { + tests := []struct { + name string + extendedAgentCard bool + }{ + {"without the extended agent card", false}, + {"with the extended agent card", true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + r, err := NewRegistry("go") + if err != nil { + t.Fatalf("NewRegistry: %v", err) + } + tmpl, err := r.GetTemplate("main.go") + if err != nil { + t.Fatalf("GetTemplate(main.go): %v", err) + } + adl := minimalGoADL() + adl.Spec.Capabilities.ExtendedAgentCard = tt.extendedAgentCard + + rendered, err := NewWithRegistry("main.go", r).Execute(tmpl, Context{ADL: adl, Language: "go"}) + if err != nil { + t.Fatalf("Execute: %v", err) + } + + if !strings.Contains(rendered, "}\n\n// newRootCmd builds") { + t.Error("newRootCmd doc comment does not start on its own line after a blank line") + } + if tt.extendedAgentCard && !strings.Contains(rendered, "}\n\n// loadAgentCard reads") { + t.Error("loadAgentCard doc comment does not start on its own line after a blank line") + } + }) + } +} diff --git a/internal/templates/languages/go/main.go.tmpl b/internal/templates/languages/go/main.go.tmpl index 2f5b49b6..c6e67980 100644 --- a/internal/templates/languages/go/main.go.tmpl +++ b/internal/templates/languages/go/main.go.tmpl @@ -187,7 +187,7 @@ func advertiseAuthScheme(a2aServer server.A2AServer, auth serverConfig.AuthConfi return true } -{{- if .ADL.Spec.Capabilities.ExtendedAgentCard }} +{{ if .ADL.Spec.Capabilities.ExtendedAgentCard -}} // loadAgentCard reads a .well-known agent-card JSON file into a typed AgentCard. // It is used to seed the authenticated extended card (A2A spec section 7) from // the same static card the public endpoint serves; enrich the returned card with