Skip to content

Make new Go AppHosts gofmt-clean, ignore the generated SDK and check every resource - #21193

Merged
David Pine (IEvangelist) merged 11 commits into
mainfrom
ievangelist-go-scaffold-hygiene
Oct 28, 2026
Merged

David Pine (IEvangelist) merged 11 commits into
mainfrom
ievangelist-go-scaffold-hygiene

Conversation

@IEvangelist

@IEvangelist David Pine (IEvangelist) commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Description

A freshly scaffolded Go AppHost had several rough edges: the SDK that the CLI regenerates under .aspire/ was not ignored by git, apphost.go was not gofmt-clean, the scaffold output, the go-starter template and the generated SDK files took CRLF line endings on Windows, the launch profile ports came from a range that overlaps the Windows dynamic port range, 49 sample AppHosts used a log.Fatalf call that go vet rejects, and the starter's builder.Err() check could not see a failed AddRedis or AddGoApp.

  • Ignore the generated SDK. GoLanguageSupport.Scaffold now also writes a .gitignore containing .aspire/, where the CLI regenerates the SDK (.aspire/modules; it is large and rebuilt from the AppHost's integrations). The go-starter template gets the same one-line file, like the TypeScript, Python and Java starters, and TemplateGitIgnoreTests has a go-starter row. In a directory that already has a .gitignore, ScaffoldingService keeps it and appends only the missing entries (MergeGitIgnoreContent).
  • gofmt-clean apphost.go. The scaffold listed "log" before "apphost/modules/aspire" in one import group, which gofmt reorders, and ended without a final newline, which gofmt adds (a C# raw string literal drops the last newline). It now has two import groups and ends with a newline.
  • LF line endings at the source. gofmt rewrites a CRLF .go file, and three producers wrote CRLF on Windows. The scaffold's string literals take the line endings of the C# source (apphost.go, go.mod, apphost.run.json). The go-starter template is embedded and scaffolded exactly as it is checked out. The generated SDK files (go.mod, transport.go, base.go, aspire.go) mix raw string literals, StringWriter output and embedded resources. Scaffold now converts every file it returns to LF, GenerateDistributedApplication replaces CRLF with LF at its single exit point, and .gitattributes pins *.go and the go-starter directory to LF. The generator replaces only \r\n: ReplaceLineEndings would also split at U+2028, form feed and NEL, which Go allows inside comments and strings, and the generated doc comments carry the description text of the exported APIs.
  • Launch profile ports. apphost.run.json drew four ports from random.Next(10000, 65000), which overlaps the Windows dynamic port range (49152-65535). It now uses AppHostProfilePortGenerator, which the CLI templates and the TypeScript scaffold already use. Its fixed ranges all end below 22300 (dashboard 15000-15299 http and 17000-17299 https, OTLP 19000-19299 and 21000-21299, resource service 20000-20299 and 22000-22299). The shared file is linked into the Go code generation project.
  • Sample AppHosts pass go vet. 408 log.Fatalf(aspire.FormatError(err)) calls in 49 tests/PolyglotAppHosts/*/Go/apphost.go files became log.Fatal(aspire.FormatError(err)). go vet reports non-constant format string in call to log.Fatalf for the old form, and a % in an error message would be printed as a formatting verb. The edit is one token per line with line endings and BOMs unchanged, and no Fatalf(aspire.FormatError remains in the tree.
  • Playground comment. The example comment in playground/GoAppHost/apphost.go said AddRedis("cache", nil, nil), which no longer matches the generated signature, where optional parameters are a trailing options struct. It now says AddRedis("cache").
  • Check every resource handle. A child-returning call such as AddRedis or AddGoApp that fails records its error on the handle it returns, not on the builder, and Build() checks only the builder's own error, so the builder.Err() check in the template could not see it. The go-starter apphost.go now keeps the api handle and checks Err() on cache and api before Build(). The aspire init example comment shows the same loop, with AddRedis and AddPostgres. The template has no {{token}} placeholders, so aspire new aspire-go-starter writes this file as it is, and the apphost.go on the Go AppHost page in Document the Go AppHost: getting started, conventions and CLI references aspire.dev#1924 is the same text.
  • Tests. GoScaffoldTests (new, 15 test cases) covers the exact scaffold file set, LF line endings of the scaffold output and of the go-starter files, a .gitignore that ignores only .aspire/, the go.mod module, go, require and replace directives, the launch profile ports staying inside the shared generator ranges (five port seeds, including null), language detection on the scaffolded files, and gofmt-cleanliness of the scaffold output and of the go-starter sources as checked out. AtsGoCodeGeneratorTests gets GenerateDistributedApplication_WritesFilesWithLfLineEndings. The Go code generation test project links every go-starter file as a test input, plus the shared TemporaryWorkspace helper. No eng/github-ci/test-trigger-map.yml change is needed: tests/PolyglotAppHosts/** already routes to the polyglot job, the go-starter files are a None Include that the project graph sees, and .gitattributes already routes to every target, so this PR selects every test target. The handle check has no test of its own: nothing pins the content of the starter apphost.go or of the aspire init comment, and ScaffoldedAndStarterSources_AreGofmtClean covers their formatting.

Part of #21115

Not in this PR

  • Making the generated SDK (under .aspire/modules) gofmt-exact. About 30 emit sites write single-line blocks such as if x != nil { ... }, struct and const alignment differs, and the imports are space-indented, so gofmt -l lists the file. It is git-ignored and regenerated on every restore, and fixing it means changing those emit sites and re-accepting every generated-SDK snapshot.
  • Running go vet over the sample AppHosts in CI.
  • The experimentalPolyglotGo header comment in playground/GoAppHost/apphost.go, which goes away with the feature flag ([Go AppHost preview] Remove the feature flag and expose Go templates #21106).

Validation

Commands ran on Windows from the worktree root, on top of upstream/main 5ea175ce62 at head de7b79d7d2, with the repo-local SDK.

Command Exit Result
dotnet test --project tests\Aspire.Hosting.CodeGeneration.Go.Tests\Aspire.Hosting.CodeGeneration.Go.Tests.csproj --no-restore --no-launch-profile -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true" 0 49 passed, 0 failed, 0 skipped
dotnet test --project tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj --no-restore --no-launch-profile -- --filter-class "*.TemplateGitIgnoreTests" --filter-class "*.NewCommandTests" --filter-class "*.NewCommandTemplateConfigPersistenceTests" --filter-class "*.ScaffoldingServiceTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true" 0 165 passed, 0 failed, 0 skipped
git grep -n "Fatalf(aspire.FormatError" HEAD 1 no match (git grep exits 1 when nothing matches)

The Go run includes all of GoScaffoldTests. A --list-tests check showed the Cli run includes the new go-starter row of TemplateGitIgnoreTests.

Test-first check for the scaffold LF change: the two new tests Scaffold_WritesFilesWithLfLineEndings and ScaffoldedAndStarterSources_AreGofmtClean were run on their own, in a CRLF working tree, against the scaffold as it was before the ReplaceLineEndings line was added (the other changes already in place). Both failed (2 run, 2 failed). The first reported apphost.go, go.mod and apphost.run.json as containing CR. The second reported gofmt -l listing the scaffolded apphost.go with a whole-file diff. With the change both pass. This also shows that the gofmt test really runs gofmt when the tools are present. Running gofmt -d (Go 1.27.0) on a minimal file with the previous single import group, and on one without a final newline, confirms the other two fixes: gofmt moves "apphost/modules/aspire" above "log" and adds the missing final newline.

Test-first check for the starter and generator LF change: GoStarterFiles_UseLfLineEndings and GenerateDistributedApplication_WritesFilesWithLfLineEndings were run on their own against the source without this change, in a CRLF working tree. Both failed (2 run, 2 failed). With the change both pass, as part of the 49 above. Negative control: with the two new .gitattributes rules removed and the starter files re-created, GoStarterFiles_UseLfLineEndings and ScaffoldedAndStarterSources_AreGofmtClean failed again (the second with a gofmt diff of go-starter/api/main.go). With the rules restored and the files re-created, git ls-files --eol lists all 8 starter files as i/lf w/lf attr/text eol=lf and every test passes. The gofmt test now reads the starter files exactly as they are checked out, without converting them first.

ScaffoldedAndStarterSources_AreGofmtClean is marked [RequiresTools(["go", "gofmt"])]. When a tool is missing the attribute adds the category=failing trait, and the CI test runner filters that trait out (eng/Testing.targets), so the test is left out there rather than failed. GeneratedTransport_SupportsDuplexCommunication in the same project already works this way with [RequiresTools(["go"])]. The two new LF tests need no external tool and run everywhere.

go vet over the 53 sample AppHosts (Go 1.27.0). The first run generated one SDK from the union of all the samples' packages (80 packages) with a locally built Debug CLI and vetted every sample against it.

  • Before the change: 4 clean, 32 non-constant format string in call to log.Fatalf, 17 type errors.
  • After the change: 36 clean, 0 format string failures, the same 17 type errors.
  • The 17 type errors appear only in the shared SDK. Each of those 17 was vetted again against an SDK generated from only its own packages (in a scratch copy of tests/PolyglotAppHosts/<Sample>/Go: aspire restore --non-interactive --apphost apphost.go, then go vet ./...): 17 of 17 clean.
  • The scaffolded apphost.go with its go.mod, and the go-starter AppHost, were vetted the same way and also build with go build ./... (exit 0).

The CLI for these runs was a locally built Debug CLI from an earlier main (3ed7e9690b) plus an unrelated Go aspire docs api commit, not a build of this branch's base. The five commits between that main and 5ea175ce62 touch neither the Go or TypeScript code generators, the shared code generation, the type system, the remote host, nor any Go sample. These runs also predate the LF commits and the rebase onto 5ea175ce62; none of them changes the content of the samples or of the generated SDK, only its line endings.

Handle check and end-to-end runs (head de7b79d7d2). The first checks used a generated SDK that has AddRedis, AddGoApp and AddPostgres, from an earlier CLI build (this PR does not touch those APIs or Resource.Err()). The go-starter apphost.go with its go.mod builds and vets (go build, go vet, Go 1.27.0, both exit 0) and gofmt -l lists nothing. The aspire init example comment, uncommented in a scratch main.go with a []aspire.Resource{cache, db} slice, also builds and vets, and it is the text of the Scaffold raw string with the comment markers removed (compared as strings). The apphost.go fence on the Go AppHost page in microsoft/aspire.dev#1924 is byte-identical to the template once line endings are normalized.

Then I built the CLI from this head and ran it on Windows (a Debug build that targets net11.0, run as dotnet aspire.dll with the repo-local runtime; Go 1.27.0 with GOTOOLCHAIN=local, GOWORK=off and GOPROXY=off). The Go starter is still behind features__experimentalPolyglotGo until #21106 lands, so I set it. aspire new needed --version 17.0.0-dev: without it the CLI looks for a local Aspire.ProjectTemplates package of its own version and finds none.

  • aspire new aspire-go-starter --version 17.0.0-dev --name verifygo --non-interactive --suppress-agent-init exited 0. The apphost.go it wrote is byte-identical to the template (1224 bytes, LF only, no BOM), .gitignore is exactly .aspire/, and all 8 starter files have no CR. In that project gofmt -l lists nothing, and go build ./... and go vet ./... exit 0 against the SDK the command generated.
  • aspire init --language go in an empty directory exited 0 and wrote .gitignore (.aspire/), apphost.go with the new handle-loop comment, go.mod and aspire.config.json. The Go files and .gitignore have no CR and no BOM, gofmt -l lists nothing, and go build ./... and go vet ./... exit 0. aspire.config.json has CRLF on Windows because AspireConfigFile.Save uses the platform newline for every language; this PR does not change that.
  • A failed Add call at run time. In a copy of the starter I renamed the Go app to "cache", the name of the Redis resource, so AddGoApp fails on the server (Cannot add resource of type 'Aspire.Hosting.Go.GoAppResource' with name 'cache' because resource of type 'Aspire.Hosting.ApplicationModel.RedisResource' with that name already exists). With the new loop, aspire run --apphost apphost.go --isolated --non-interactive stopped before Run(), printed that message and exit status 1, and the CLI reported The Go apphost failed. In a second copy that skipped the loop and wrote the results to a file, builder.Err() was nil, cache.Err() was nil, api.Err() held that message and Build() returned nil, so a check of builder.Err() alone does not see the failure.

Overlap with open PRs: this PR shares files with #21183 (playground/GoAppHost/apphost.go), #21187 (GoLanguageSupport.cs), #21188 (AtsGoCodeGenerator.cs, AtsGoCodeGeneratorTests.cs), #21194 (AtsGoCodeGeneratorTests.cs), #21195 and #21197 (AtsGoCodeGenerator.cs, Aspire.Hosting.CodeGeneration.Go.csproj) and #21199 (AtsGoCodeGenerator.cs). A trial merge (git merge-tree --write-tree) of this head with the head of each of those seven PRs (0e65752d44, e1bb4c11ae, 9088dfe7fb, ffc59f2023, 7d33810c11, 82a44b0723, 4f5a7a84aa) was clean, as was a trial merge with each of the other open Go AppHost PRs and with upstream/main f4ae2cc424.

Not run:

  • aspire init --language go in a directory that already has a .gitignore or a go.mod. The run above used an empty directory. The .gitignore merge has two unit tests (MergeGitIgnoreContent_AppendsMissingEntriesWithoutOverwritingExistingContent and MergeGitIgnoreContent_DoesNotAddDuplicateAspireEntryWhenEquivalentEntryAlreadyExists).
  • The LF changes are observable only on CRLF inputs. On a Linux or macOS checkout the LF tests pass with or without them, and I ran on Windows only. A working tree checked out before the .gitattributes rule keeps CRLF in the go-starter files, because git does not rewrite existing files when an attribute changes, so GoStarterFiles_UseLfLineEndings fails there until the files are re-created (delete the go-starter directory and run git checkout -- <directory>). Fresh checkouts are not affected. Whether the official build checks the go-starter files out as LF or CRLF was not checked; the rule makes it LF either way.
  • The rest of Aspire.Cli.Tests, the CLI end-to-end tests, and the polyglot validation scripts under .github/workflows/polyglot-validation. test-go.sh there scaffolds with aspire init --language go and inserts code before the builder.Build() line; the scaffold keeps that line and both imports.
  • go vet over the 53 sample AppHosts with a CLI built from this head. Only the starter and the aspire init scaffold were run with it.
  • The output of the 36-sample union SDK vet run was not saved to a file, so only the per-sample runs above can be repeated from the description.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

The Go scaffold and the go-starter template did not write a .gitignore, so the generated SDK under .aspire/modules (tens of thousands of lines) would be committed with the user's AppHost. Add one that ignores .aspire/, matching what the TypeScript and Java scaffolds do. The scaffold's .gitignore goes through the existing ScaffoldingService merge, so brownfield directories keep their own entries.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
Put the standard library and module imports in separate groups and end apphost.go with a newline, which a C# raw string literal omits, so gofmt -l reports nothing for a new AppHost.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
Cover the scaffolded file set, the .gitignore, the go.mod replace directive against the generated SDK module, the launch profile, AppHost detection, and a gofmt check of the scaffolded and go-starter sources. The go-starter sources are copied next to the test assembly so the check works on any build host.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
go vet rejects log.Fatalf(aspire.FormatError(err)) because the format string is not a constant, so 49 of the 53 Go polyglot samples failed vet. FormatError returns finished text, not a format string, so log.Fatal is the correct call and also stops a '%' in an error message from being misread as a verb.

Only the 408 log.Fatalf(aspire.FormatError(...)) lines changed, all in tests/PolyglotAppHosts/*/Go/apphost.go. The edit is a byte-exact, idempotent replace so it can be re-run after a rebase.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
The generated AddRedis takes its optional settings as variadic options (AddRedis(name string, options ...*AddRedisOptions)), so the commented example no longer compiled when uncommented. It now matches the go-starter template.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
The Go scaffold drew four ports independently from 10000-65000, so two of them could collide and any of them could land in the Windows ephemeral range (49152 and up). The TypeScript scaffold and the CLI templates already use AppHostProfilePortGenerator, which gives each endpoint its own non-overlapping band below the ephemeral range; Go now links and uses the same file.

The scaffold test now covers a seeded and an unseeded request and asserts each port stays inside the shared bands.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
The ts, py and java starters are already asserted to ignore the workspace .aspire/ directory; the go-starter template now ships the same ignore entry, so it gets the same guard.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
The scaffold files are C# raw string literals, which take the line endings of the source file. In a Windows checkout that is CRLF, so a CLI built there wrote an apphost.go that gofmt -l reports. Scaffold now returns every file with LF line endings.

The gofmt test runs gofmt on exactly what Scaffold returns, and a new test asserts the scaffold contains no carriage returns. The port range test drops its upper-bound assertion: every shared range already ends below 49152, so the range assertion covers it.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21193

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21193"

@github-actions github-actions Bot added the area-integrations Issues pertaining to Aspire Integrations packages label Oct 20, 2026
@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 20, 2026 06:57
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are localized and covered by focused regression tests, with no unresolved blocking issues identified.

No open issues 🎉

What changed in this PR

Improves Go AppHost scaffolding and sample correctness as part of Go general-availability preparation.

Changes:

  • Produces LF, gofmt-clean scaffold output, ignores generated SDK files, and uses shared launch-profile port ranges.
  • Replaces unsafe formatted logging in 49 Go samples and corrects a playground example comment.
  • Adds scaffold, formatting, and starter .gitignore regression coverage.
File Description
tests/​PolyglotAppHosts/​Aspire.Hosting/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Yarp/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Valkey/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.SqlServer/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Seq/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Redis/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.RabbitMQ/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Qdrant/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Python/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.PostgreSQL/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Orleans/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Oracle/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.OpenAI/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Nats/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.MySql/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.MongoDB/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Milvus/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Maui/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Kubernetes/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Keycloak/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Kafka/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.JavaScript/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Garnet/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Foundry/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Docker/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.DevTunnels/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Blazor/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.WebPubSub/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.Storage/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.Sql/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.SignalR/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.ServiceBus/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.Search/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.Redis/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.PostgreSQL/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.OperationalInsights/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.Network/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.Kusto/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.KeyVault/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.Functions/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.EventHubs/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.CosmosDB/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.ContainerRegistry/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.CognitiveServices/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.AppService/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.ApplicationInsights/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.AppContainers/​Go/​apphost.go Logs error text without format interpretation.
tests/​PolyglotAppHosts/​Aspire.Hosting.Azure.AppConfiguration/​Go/​apphost.go Logs error text without format interpretation.
tests/​Aspire.Hosting.CodeGeneration.Go.Tests/​GoScaffoldTests.cs Tests scaffold contents, ports, detection, and formatting.
tests/​Aspire.Hosting.CodeGeneration.Go.Tests/​Aspire.Hosting.CodeGeneration.Go.Tests.csproj Includes shared workspace helper and starter test inputs.
tests/​Aspire.Cli.Tests/​Templating/​TemplateGitIgnoreTests.cs Adds Go starter ignore-file coverage.
src/​Aspire.Hosting.CodeGeneration.Go/​GoLanguageSupport.cs Fixes formatting, line endings, SDK ignores, and ports.
src/​Aspire.Hosting.CodeGeneration.Go/​Aspire.Hosting.CodeGeneration.Go.csproj Links the shared port generator.
src/​Aspire.Cli/​Templating/​Templates/​go-starter/​.gitignore Ignores generated .aspire/ contents.
playground/​GoAppHost/​apphost.go Corrects the commented Redis example.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

gofmt rewrites CRLF, and the Go starter template and the generated SDK
files were written with whatever line endings the build or checkout
machine used (CRLF on Windows).

- .gitattributes pins *.go and the go-starter template to LF.
- GenerateDistributedApplication replaces CRLF with LF at its single exit
  point, because its files mix raw string literals, StringWriter output
  and embedded resources.
- New tests assert that the go-starter files and the generated files have
  no carriage returns, and the gofmt test now checks the starter files
  exactly as they are checked out.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 21, 2026 13:48
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are focused and supported by regression coverage, with no blocking issues identified; tests were not rerun during this review.

No open issues 🎉

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

A failed child-returning Add call such as AddRedis or AddGoApp records its error on the handle it returns, not on the builder, so builder.Err() cannot see it. The go-starter template and the aspire init scaffold comment now keep each resource handle and check its Err() before Build().

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
@github-actions

This comment has been minimized.

@IEvangelist David Pine (IEvangelist) changed the title Make new Go AppHosts gofmt-clean and ignore the generated SDK Make new Go AppHosts gofmt-clean, ignore the generated SDK and check every resource Oct 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are bounded, have focused regression coverage, and leave no identified blocking issues.

No open issues 🎉

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@IEvangelist
David Pine (IEvangelist) marked this pull request as ready for review October 21, 2026 21:46
David Pine (IEvangelist) added a commit to microsoft/aspire.dev that referenced this pull request Oct 22, 2026
…ces (#1924)

> [!IMPORTANT]
> **Depends on:**
>
> - microsoft/aspire#21193: `go-apphost.mdx` shows what `aspire new
aspire-go-starter` writes, and the `.gitignore` that lists `.aspire/`
and the handle checks in the `apphost.go` fence come from that PR. Merge
this PR after it.
> - #1917: links to `/reference/api/go/` resolve only once the Go API
reference is on `release/17.0`.
> - microsoft/aspire#21183: these pages document Go without a feature
flag, but the CLI still requires the flag until that PR merges. The
pages go live at the GA docs swap, after the flag is removed.

## Summary

Adds Go AppHost documentation next to the existing C# and TypeScript
pages. This is the docs and samples child (microsoft/aspire#21112) of Go
AppHost GA (microsoft/aspire#21115). The content goes live at the GA
docs swap, because it targets `release/17.0`.

New pages, each with its sidebar entry in the same commit:

- **`app-host/go-apphost`:** getting started. Prerequisites, creating a
Go AppHost with `aspire new` and `aspire init`, running it, the
`apphost.go` and `aspire.config.json` layout, the generated SDK and
restore, adding integrations, orchestrating apps in other languages, and
debugging.
- **`app-host/go-apphost-conventions`:** how the Go API differs from C#:
names and handles, optional parameters, the error model, and
cancellation.

Edited pages:

- **`languages-and-runtimes/index.mdx` and
`architecture/multi-language-architecture.mdx`:** Go is listed and
explained next to TypeScript.
- **`integrations/frameworks/go/go-host.mdx` and `go-get-started.mdx`:**
`go-host.mdx` gets Go AppHost examples in tab groups beside the C# and
TypeScript ones, and its "Experimental Go AppHost templates" section
becomes "Write the AppHost in Go". `go-get-started.mdx` points to the
new getting started page. Nothing else links to the old anchor.
- **`reference/cli/commands/aspire-new.mdx`, `aspire-add.mdx`,
`aspire-restore.mdx` and `aspire-init.mdx`:** the Go templates,
`--language go`, and how Go AppHosts are added to and restored.
- **`reference/cli/configuration.mdx` and
`reference/cli/includes/config-settings-table.md`:** the Go feature flag
row is removed from the settings table, and the examples that used it
now use the Rust flag, because the Go AppHost doesn't require a flag at
GA.

Notes for reviewers:

- The Go AppHost doesn't require a feature flag at GA
(microsoft/aspire#21106), so the pages document none: `go-apphost.mdx`
has no flag caution, and the Go row is gone from the CLI configuration
reference. The CLI still requires the flag until microsoft/aspire#21183
removes it.
- `go-apphost.mdx` shows what `aspire new aspire-go-starter` writes. The
`.gitignore` that lists `.aspire/` and the handle checks in the
`apphost.go` fence come from microsoft/aspire#21193, so merge this PR
after it.
- Links to `/reference/api/go/` resolve only once the Go API reference
(#1917) is on `release/17.0`, because the link validator skips
`/reference/api/**`.
- Not in this PR, and tracked as follow-ups: Go tabs on the other pages
that have a TypeScript tab and no Go tab (1,030 tab groups in 173 files
when audited), Go in the site's AppHost-language pivot, which knows only
C# and TypeScript (#1926), and the Java, Python and Rust rows in the CLI
configuration reference, which still use the older
`experimentalPolyglot:<lang>` colon spelling instead of the flat keys
the CLI reads on `main` (#1925).

## Third-party links and affiliations

One link: `https://go.dev/dl/`, the official Go download page, in the
prerequisites of `go-apphost.mdx`. The author has no material
affiliation with the Go project. The loopback URLs in the
`aspire.config.json` sample are example values, not links.

## Validation

The frontend commands ran in `src/frontend`.

| Command | Result |
| --- | --- |
| `pnpm lint` | exit 0, ESLint `--max-warnings 0` clean, skill digests
up to date |
| `pnpm test:unit` | exit 0, 84 test files passed, 1169 tests passed, 1
skipped, 0 failed |
| `bash tests/scripts/test-forbidden-words.sh` | passed |
| `bash .github/scripts/check-forbidden-words.sh
5c48cfb
e961e1e` | exit 0, "No forbidden
phrases found in added lines." |
| `git diff --check upstream/release/17.0...HEAD` | exit 0, no output |
| `go build -o NUL ./fences/...` and `go vet ./fences/...` | both exit 0
for the 16 added Go fences and 1 existing one (17 packages, Go 1.27.0),
extracted from the page text and built against a real generated SDK |

- **Forbidden words:** run locally with an LF-writing `jq`, because the
Windows `jq` writes CRLF and made the first local run pass vacuously. CI
is the authority.
- **Rendering:** all 11 new and edited pages return 200 on a local dev
server that includes #1917, with their new content. The 19 distinct
internal links and 3 anchors added here resolve, including the Go API
reference routes.
- **CLI behavior:** `aspire init --language go --non-interactive
--suppress-agent-init`, with the Go feature flag set through the
environment, exited 0 and wrote `apphost.go`, `go.mod`,
`aspire.config.json` and `.aspire/modules`, which is what
`aspire-init.mdx` describes. The flag was set because the CLI still
requires it until microsoft/aspire#21183 removes it.
- **Starter scaffold:** `aspire new aspire-go-starter`, run with a CLI
built at the head of microsoft/aspire#21193 and the same feature flag,
exited 0 and wrote 8 files. The `apphost.go` fence is byte-identical to
the written file after line-ending normalization, the `go.mod` fence
matches its `go.mod`, and the file tree and `aspire.config.json` fence
show what it wrote, with example port numbers and without two hidden
bookkeeping files in `.aspire/modules/`. `go build ./...` and `go vet
./...` passed in the scaffolded project.
- **Negative control:** a Go fence that calls a method that doesn't
exist fails to compile, so the fence check can fail.
- **gofmt:** flags only the existing `main.go` fence in `go-host.mdx`
(4-space indentation), which this PR doesn't change.

Not run: `pnpm build`, an AppHost end to end, and `aspire add` or
`aspire restore` against a Go AppHost. What the `aspire new --language
go`, `aspire add` and `aspire restore` references say about Go comes
from reading the CLI source. The Go fences compile against an SDK
generated before the latest generator changes; they set no handle-typed
option fields, so they should be unaffected, but only the starter's
`apphost.go` fence was also built against a regenerated SDK, as part of
the scaffolded project. The fence build also predates the two commits
that remove the Go flag text and the commit that matches the starter's
scaffold; none of them changes a Go fence.

---------

Co-authored-by: David Pine <7679720+IEvangelist@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a nice cleanup. The handle check in the starter and the aspire init comment fixes a real gap, the LF and gofmt work is well covered, and the port ranges now match the other scaffolds. I ran Aspire.Hosting.CodeGeneration.Go.Tests locally on macOS with go and gofmt installed, and all 49 tests pass, including ScaffoldedAndStarterSources_AreGofmtClean. Approving. The items below are minor, so they can be small updates before merge or follow-ups.

  • Snapshot the scaffold output. GoScaffoldTests checks the scaffolded files with separate asserts, so nothing pins what apphost.go contains, including the new loop that checks each resource's Err(), which the description says has no test. A Verify snapshot of the scaffolded apphost.go (and go.mod) would follow the repo convention for generated text and cover that comment.
  • Small test nits. Some GoScaffoldTests cases create a TemporaryWorkspace that Scaffold never writes to, and [RequiresTools(["go", "gofmt"])] only needs gofmt. Neither is a problem, just noise.

A fresh aspire init writes the scaffold .gitignore as it is, so it has to end with a newline, like go-starter/.gitignore does. Line ending normalization now replaces only CRLF, consistent with AtsGoCodeGenerator.GenerateDistributedApplication.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

Selects the full PR test matrix + all PR-gated jobs (ALL) — a rule matching '.gitattributes' selects ALL


Selection computed for commit 6066934.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The scoped fixes have focused regression coverage and no blocking issues were identified; tests were not rerun in this environment.

No open issues 🎉

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

David Pine (IEvangelist) added a commit that referenced this pull request Oct 28, 2026
## Description

Adds CLI end-to-end coverage for Go AppHosts that mirrors what
TypeScript has, plus a `PolyglotGo` image variant that carries the Go
toolchain for those tests.

**Tests** (`tests/Aspire.Cli.EndToEnd.Tests`, 7 classes, 10 tests):

| Class | Mirrors | Covers |
| --- | --- | --- |
| `GoStarterTemplateTests` | `TypeScriptStarterTemplateTests` | `aspire
new` Go starter, then start, wait and stop |
| `GoEmptyAppHostTemplateTests` (2) |
`TypeScriptEmptyAppHostTemplateTests` | empty Go AppHost from the
template picker and from the direct template command |
| `GoCodegenValidationTests` | `TypeScriptCodegenValidationTests` |
restore generates the SDK files, and regenerates them when the SDK on
disk is stale (the baseline is put back after an `aspire add`) |
| `GoPolyglotApphostDirectoryTests` |
`TypeScriptPolyglotApphostDirectoryTests` | stop a running Go AppHost
through `--apphost <dir>` |
| `GoSecretAppHostTests` | `SecretTypeScriptAppHostTests` | secret
create, read, update, delete and environment-scoped secrets. `get` and
`list` output is checked with `grep`, and the JSON listing after the
delete must hold exactly the remaining secret |
| `GoPublishTests` (3) | `TypeScriptPublishTests` | Docker Compose
publish with a service callback, the default output directory, and the
Dockerfile generated for `AddGoApp` |
| `GoKubernetesDeployTests` | `KubernetesDeployTypeScriptTests` | Go
AppHost deployed to KinD with Helm, using the Helm defaults (namespace
`default`, chart version `0.1.0`); the `api` and `cache` pods must
become Ready |

**Image and CI plumbing**

- `tests/Shared/Docker/Dockerfile.e2e-polyglot-go`, the image build,
warm and load workflows, `eng/scripts/load-cli-e2e-images.sh`
(`--require-go`), `reproduce-flaky-tests.yml` and
`docs/ci/cli-e2e-images.md` get a `PolyglotGo` variant next to
`PolyglotJava`.
- The Go layer installs `docker-buildx`. `aspire deploy` builds the
`api` image with `docker buildx build` and throws when buildx is missing
(`DockerContainerRuntime`), while the shared polyglot base installs
`docker.io` with `--no-install-recommends`, which leaves buildx out. The
DotNet image (`Dockerfile.e2e`) installs it the same way. `kind`, `helm`
and `kubectl` are installed by the test at runtime.
- `run-tests.yml` downloads and loads that image for split jobs whose
short name contains `-Go`. The classes are all named `Go*` for that
reason: matching a bare `go` would also select names such as `MongoDB`
and `Config`.
- The three new `actions/*` pins reuse SHAs that are already pinned
elsewhere in the repository, so no allow-list change is needed.
- `Aspire.Hosting.Go` and `Aspire.Hosting.CodeGeneration.Go` join the
CLI E2E runtime-package consumers in
`eng/github-ci/test-trigger-map.yml`, next to the Java and TypeScript
code generation packages. Two `InlineData` rows in
`SelectTestsAcceptanceTests` cover the routing.

**Helpers.** `AppHostLanguagePromptSelection.Go`,
`AspireTemplate.GoStarter` and `GoEmptyAppHost`,
`AspireNewGoEmptyAppHostAsync`, and `EnableExperimentalGoSupportAsync`.
The last is the only place the E2E projects write
`features:experimentalPolyglotGo`, so removing the flag (#21106, in
draft #21183) deletes one helper and its ten call sites instead of
reworking each test.

The pickers type the entry's name (`Go API` for the starter, `Go` at the
language prompt) instead of counting `Down` presses, and each step waits
for the expected selection text before pressing Enter, so a wrong match
fails with a clear timeout instead of choosing another entry. The
`PolyglotGo` image has no .NET SDK, which drops the two C# starters from
the template list: a `Down` count that is right with an SDK clamps onto
`Empty AppHost` without one, which is how the first CI run failed. The
search prompt jumps to the first entry whose text contains what was
typed, ignoring case, so the selection no longer depends on what else a
picker lists.

Part of #21108.

### CI status

The first CI run (head `d24eb6c14a`) passed the CLI E2E image build
(including the `docker-buildx` line), `GoCodegenValidationTests`,
`GoEmptyAppHostTemplateTests` (2 tests),
`GoPolyglotApphostDirectoryTests`, `GoSecretAppHostTests` and 2 of the 3
`GoPublishTests`: 7 of the 10 tests. The other three
(`GoStarterTemplateTests`,
`GoPublishTests.PublishGoStarterGeneratesGoAppDockerfile` and
`GoKubernetesDeployTests`) failed for one reason, the 4 `Down` presses
to the Go starter.

On `c788f994e7`, which replaces the `Down` presses with type-ahead,
makes the Kubernetes AppHost callback-free and asserts the full secrets
listing, all seven classes passed: 10 of 10 tests, including
`GoStarterTemplateTests` (start, check that `cache` and `api` exist,
stop) and `GoKubernetesDeployTests`. No check on that head is failing on
its latest attempt (447 succeeded, 11 skipped).

The three commits after it (`dad6c38807`, `5506d5944a` and `962ebc83a4`)
tighten three assertions that could pass without proving anything (see
the findings below). On the last of them, `962ebc83a4`, all seven
classes passed again on `ubuntu-latest`: 10 of 10 tests, none skipped.
That includes the stale-SDK baseline and restore flow in
`GoCodegenValidationTests` and, in `GoKubernetesDeployTests`, a `kubectl
wait --for=condition=Ready` that exited 0 for both the `api` and `cache`
pods on a real kind cluster.

Three other jobs failed on the first attempt of that run and passed on a
rerun of the same commit. This PR changes nothing under `src/` or
`extension/`.

- `Hosting.Azure`
(`AzureFunctionsTests.AddAzureFunctionsProject_WorksWithMultipleProjects`)
failed on attempts 1 and 2 and passed on attempt 3.
- `KubernetesDeployWithMongoDBTests` failed on attempt 1, on a runner
with kernel `7.0.0-1017-azure`, and passed on attempt 2.
- The `java-apphost-debug-startup-timeout` VS Code extension E2E failed
on attempt 1 and passed on attempt 2.

The latest attempt of every check on `962ebc83a4` is green: 447
succeeded, 11 skipped.

### Findings that shaped the tests

- The Go starter's `api/go.mod` ships without a `go.sum`, and
`WithModTidy` only runs in run mode, so building the starter's container
fails with `missing go.sum entry` (reproduced with a scratch `go
build`). `GoPublishTests` asserts the generated Dockerfile only, and
`GoKubernetesDeployTests` runs `go mod tidy` in `api/` before deploying.
The product fix is not in this PR (item 1 of #21206).
- The Kubernetes test's AppHost passes no `WithHelm` callback. In the
generated Go SDK a `Configure` func inside an options struct panics the
options merge with `unexpected end of JSON input` (#18080, fix in
#21188), so the test uses the Helm defaults (namespace `default`, chart
version `0.1.0`) and takes the namespace and chart-version parameters
back once that fix lands (item 7 of #21206). The deploy path itself
(`AddKubernetesEnvironment`, `AddContainerRegistry`, `aspire deploy`) is
unchanged, so the test is not marked `[ActiveIssue]` and the trigger map
needs no new edge.
- Three checks are written so that doing nothing cannot pass:
- `secret get` and `secret list` are piped through `grep` and an `echo`
marker is awaited. The key and value are already on screen from the
typed `secret set` command, so waiting for that text alone always
succeeds.
- The codegen validation test copies the baseline `aspire.go` and
`.codegen-hash` aside, runs `aspire add Aspire.Hosting.SqlServer` (which
regenerates the SDK itself), puts the baseline back, checks that it is
stale, and only then runs `aspire restore`. A restore that does nothing
fails the test.
- The Kubernetes test runs `kubectl wait --for=condition=Ready` for the
`api` and `cache` pods, selected by `app.kubernetes.io/component`.
`kubectl get pods` exits 0 on an empty namespace and Helm's `--wait`
only waits for workloads that are in the chart, whereas `kubectl wait`
exits 1 with `no matching resources found` when nothing matches.

### Not in this PR

- An HTTP probe against the Go starter's API (item 6 of #21206).
`GoStarterTemplateTests` starts the AppHost and checks that `cache` and
`api` exist, which does not show that the API serves requests. No
existing helper reads a resource URL without `jq`, which the
`PolyglotGo` image does not carry, and the API probably needs host
networking to reach the Redis container (an inference, not run).
- The same weaknesses in the TypeScript and Java tests (#21210).
`TypeScriptCodegenValidationTests` and `JavaCodegenValidationTests` run
`aspire restore` right after an `aspire add` and compare the codegen
hash with the one from before the add, and
`KubernetesDeployTypeScriptTests` checks `kubectl get pods`, which exits
0 on an empty namespace.
- An ACA deployment test for the Go starter. A new class in
`Aspire.Deployment.EndToEnd.Tests` would run nightly against the real
Azure subscription and cannot be verified from here.
- Kubernetes `AddManifest` and `WithField` coverage. #18080 is an open
product bug.
- `.gitignore` assertions for the Go scaffold and starter. The templates
do not write a `.gitignore` entry on `main` yet. #21193 adds one, and
asserting it is item 3 of #21206.
- Brownfield `aspire init` in an existing Go repository (#21201).
Reading `ScaffoldingService` suggests an existing `go.mod` conflicts,
but no test was run.
- Go toolchain missing or too old diagnostics, which need an image
without Go.
- Go validation outside the CLI E2E tests, such as `go vet` in the
polyglot validation and a Go scenario in `cli-starter-validation`
(#21202).

## Validation

Windows, repo-local SDK, head `962ebc83a4` on top of `upstream/main`
`230d5ac2a8`. `main` has since gained one unrelated commit that touches
only `KubernetesDeployWithCertManagerTests.cs`, so no rebase was needed.
Rows 1 to 3 ran on this head. Rows 4 to 6 ran on `d24eb6c14a`: the later
commits change only E2E test sources and the shared Hex1b helpers, and
`Infrastructure.Tests` links neither (it links `TemporaryWorkspace.cs`,
`WindowsTrayTestPayload.cs` and `PathLookupHelper.cs` from the shared
directories) and does not read them, so those rows are unaffected.

| Command | Result |
| --- | --- |
| `dotnet build
tests\Aspire.Cli.EndToEnd.Tests\Aspire.Cli.EndToEnd.Tests.csproj -m:2
--no-restore` | 0 warnings, 0 errors |
| `dotnet build
tests\Aspire.Deployment.EndToEnd.Tests\Aspire.Deployment.EndToEnd.Tests.csproj
-m:2 --no-restore` | 0 warnings, 0 errors (compiles the shared Hex1b
helpers that gained the Go templates) |
| `dotnet test --project
tests\Aspire.Cli.EndToEnd.Tests\Aspire.Cli.EndToEnd.Tests.csproj
--no-restore --no-launch-profile -- --filter-class
"*.CliInstallStrategyTests" --filter-not-trait "quarantined=true"
--filter-not-trait "outerloop=true"` | 67 passed, 0 failed, 0 skipped.
`--list-tests` (placed before the `--`) discovers the same 67, all in
this class, including 4 new `PolyglotGo` cases |
| `dotnet build tests\Infrastructure.Tests\Infrastructure.Tests.csproj
-m:2 --no-restore` | 0 warnings, 0 errors |
| `dotnet test --project
tests\Infrastructure.Tests\Infrastructure.Tests.csproj --no-restore
--no-launch-profile -- --filter-method
"*.RealMapRepresentativeCliE2eRuntimeConsumerSelectsCliE2e"` | 4 passed,
0 failed |
| `dotnet test --project
tests\Infrastructure.Tests\Infrastructure.Tests.csproj --no-restore
--no-launch-profile -- --filter-namespace
"Infrastructure.Tests.TestTriggerMap"` | 351 total, 329 passed, 22
failed (exit 2) |

The 22 `TestTriggerMap` failures are pre-existing and Windows-only: 5
`SelectTestsCliTests` and 17 `PrComparisonBaseTests` data rows. A
control run on a clean `82c3b01ce1` (the `main` tip before this rebase)
gave 349 total, 327 passed and the same 22 failures, caused by `bash`
receiving mangled Windows paths and an `UnauthorizedAccessException`
deleting a temporary git repository. This branch adds the 2 passing
rows.

The shell fragments of the three newest commits were also run outside
CI. 27 cases ran against stub `aspire` and `kubectl` executables, with
the fragments extracted from the C# sources so the dry run cannot drift
from the tests: the `grep` checks accept the exact value and reject a
wrong, empty or longer one, the baseline snapshot and put-back restore
the stale SDK, and the `kubectl wait` command covers exactly `api` and
`cache`. Real `kubectl` v1.36.1 against a throwaway fake API server
confirmed the difference the Kubernetes test relies on: in an empty
namespace `kubectl get pods --no-headers` exits 0 while `kubectl wait
--for=condition=Ready` exits 1 with `no matching resources found`, and
with only an `api` pod Ready the wait exits 0 for `api` and 1 for
`cache`.

Not run locally: all seven new E2E classes. They need Docker (and kind
for the Kubernetes test), the CLI archive and the new `PolyglotGo`
image, so CI is their only execution. All ten passed on `c788f994e7` and
again on `962ebc83a4`, so the snapshot, put-back and restore flow in
`GoCodegenValidationTests` and the `kubectl wait` check on a real kind
cluster in `GoKubernetesDeployTests` have run end to end in CI. A
crash-looping `api` or an image pull failure fails the Kubernetes test
by design.

## Checklist

- Is this feature complete?
  - [ ] Yes. Ready to ship.
  - [x] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] Yes
  - [ ] No
- Did you add public API?
  - [ ] Yes
    - If yes, did you have an API Review for it?
      - [ ] Yes
      - [ ] No
- Did you add `<remarks />` and `<code />` elements on your triple slash
comments?
      - [ ] Yes
      - [ ] No
  - [x] No
- Does the change make any security assumptions or guarantees?
  - [ ] Yes
    - If yes, have you done a threat model and had a security review?
      - [ ] Yes
      - [ ] No
  - [x] No

---------

Co-authored-by: David Pine <7679720+IEvangelist@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
@IEvangelist
David Pine (IEvangelist) merged commit 7d47ae7 into main Oct 28, 2026
1283 of 1293 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Oct 28, 2026
David Pine (IEvangelist) added a commit that referenced this pull request Oct 28, 2026
> [!NOTE]
> **Merge order: land this PR after the other open Go generator PRs.**
It does not depend on any of them and is based on `main`, but it changes
files that #21188, #21193, #21194, #21195, #21197 and #21199 also change
(`AtsGoCodeGenerator.cs`, `Resources/base.go`, the Go generator tests
and the two Go snapshots).
>
> - When this PR was opened it merged cleanly (`git merge-tree`) with
every other open Go AppHost PR except #21197. The one conflict is two
lines in `EmitDtoCallbackToMap`: keep #21197's `GoStringLiteral(...)`
line and this PR's `clientExpression: null` argument.
> - If the Go snapshots conflict or go stale after another PR lands,
regenerate them by running the Go codegen test project twice, because
Verify rewrites the snapshots on the first run.
> - #21188 also rewrites `deepUpdate`, which fixes the options-struct
panic described under "Not covered".

## Description

In a Go AppHost, a callback whose parameter is a resource builder
(`Action<IResourceBuilder<T>>` in C#) received a nil value, so the first
call on it panicked. The host marshals callback arguments with the
declared parameter type, so a closed generic `IResourceBuilder<T>` is
sent with a closed-generic `$type` (`Type.FullName`, which embeds the
assembly-qualified `T`), while a builder returned from a capability is
sent with the plain id of `T`. The generated Go SDK registers wrappers
only for plain ids, so the transport left the raw handle in place and
`callbackArg[T]` fell back to the zero value of `T`, a nil interface.

The generated callback shim now builds the wrapper from the declared
parameter type instead of relying on `$type`, which is what the
TypeScript generator already does.

Fixes #21255

### Before and after

A Go AppHost from `aspire-go-empty` plus `Aspire.Hosting.Docker`, run
through `aspire publish` with the Go generator and runtime from `main`
versus this branch:

```go
env := builder.AddDockerComposeEnvironment("env")
env.ConfigureDashboard(func(dashboard aspire.DockerComposeAspireDashboardResource) {
	dashboard.WithHostPort(&aspire.WithHostPortOptions{Port: aspire.Float64Ptr(9003)})
})
```

| | Before | After |
|---|---|---|
| Callback argument | nil | usable
`DockerComposeAspireDashboardResource` |
| `aspire publish` | `panic: runtime error: invalid memory address or
nil pointer dereference`, the Go AppHost exits with status 2 and the CLI
exits with code 6 | exit 0, all 7 steps succeed, `docker-compose.yaml`
maps `9003:18888` on `env-dashboard` |

### What changed

- Go runtime (`Resources/base.go`): `callbackHandleArg[T](c, args, idx,
wrap)` returns `wrap(h, c)` when the argument is still a raw `*handle`
and otherwise defers to `callbackArg[T]`, so values the transport
already wrapped (plain resource and context ids) take the path they took
before.
- Generator (`AtsGoCodeGenerator`): a callback shim emits
`callbackHandleArg(s.client, args, i, new<Interface>FromHandle)` for a
handle-category parameter that has a generated constructor and a client
in scope. DTOs, enums, `CancellationToken` and DTO property callbacks
(which have no client) keep `callbackArg[T]`.
- Tests: a generator test that pins the emitted wrapper for
`PublishAsDockerFile`, and a Go-backed test (`[RequiresTools(["go"])]`)
that compiles the generated SDK and drives a callback over an in-memory
fake host with both a closed-generic and a registered `$type`. Both fail
on the old generator.
- Snapshots: regenerated.

### Reviewer notes

- **The snapshot diff is one mechanical transform.**
`callbackArg[X](args, N)` becomes `callbackHandleArg(s.client, args, N,
newXFromHandle)` at 260 call sites (259 changed lines) in
`TwoPassScanningGeneratedAspire.verified.go` and 11 call sites (10
changed lines) in `AtsGeneratedAspire.verified.go`, plus the 17-line
helper in the latter (it embeds `base.go`). Applying the inverse
transform to the new snapshots reproduces the files on `main` byte for
byte. Only the four `PublishAsDockerFile` shims for `ContainerResource`
(executable, dotnet tool, project and C# app) change behavior in those
snapshots; every other site is a context or event type that already
arrived wrapped.
- **More exports are fixed than the issue lists.** Across hosting and 19
integration assemblies, 27 declared `IResourceBuilder<T>` callback
parameters expand to 29 shims that were affected, for example
`WithDashboard` (Docker Compose and Kubernetes), `WithRedisInsight`,
`WithPgAdmin`, `WithMongoExpress`, `WithKafkaUI` and the Azure
`RunAsEmulator` and `RunAsContainer` overloads.
- **Not covered.**
- `ConfigureEnvFile` on Docker Compose takes `Action<IDictionary<string,
CapturedEnvironmentVariable>>` and has a related cause: its dictionary
argument still arrives as a zero-value `*Dict` with no handle behind it,
so using it panics. It is the only dictionary-typed callback parameter
in the 53 generated Go validation SDKs. A small generator change that
wraps it the same way worked in a local check; it is left out so this PR
stays about resource builders.
- DTO property callbacks have no client in scope; none of them takes a
resource builder today.
- Callbacks passed through an options struct (the project and C# app
`PublishAsDockerFile` overloads, and `ConfigureContainer` on Redis
`WithRedisInsight` and `WithRedisCommander`) panic earlier, in
`deepUpdate`, on `main` with or without this change. #21188 rewrites
`deepUpdate`. With a local workaround for `deepUpdate`, the Redis
callbacks received nil before this change and a live wrapper after it;
none of these overloads was run on a tree that contains #21188.
- Java appears to have the same weakness (read, not run). TypeScript and
Python already use the declared parameter type for the wrapper.
- No CI job runs a Go callback at runtime: `polyglot-validation.yml`
only compiles the Go validation AppHosts. The new Go-backed test covers
the transport against an in-memory fake host.
- Not run: Linux and macOS, `aspire run` with the dashboard UI (the
checks below use `aspire publish`, and the `PublishAsDockerFile`
callback does not run in run mode), `go test -race` (no C compiler on
the machine), and Rust.
- **Host-side alternative not taken.** Marshalling the plain resource
type id would fix every guest at once, but it changes the wire contract
that `CallbackProxyTests` pins.

### Validation

Windows, Go 1.27.0, Docker 29.9.1. The `dotnet test` runs are on the
final commit. The Go AppHost checks ran on the same change before a
clean rebase onto the current `main` (the patch is identical).

- `dotnet test --project
tests/Aspire.Hosting.CodeGeneration.Go.Tests/Aspire.Hosting.CodeGeneration.Go.Tests.csproj
--no-launch-profile -- --filter-not-trait "quarantined=true"
--filter-not-trait "outerloop=true"`: 35 passed, 0 failed, 0 skipped (33
on `main`). Run twice, and `git status` was clean after each run, so the
snapshots are stable.
- The same project with the old `AtsGoCodeGenerator.cs` and `base.go`
under the new tests and snapshots: 4 failed (both new tests and both
snapshot tests).
- `dotnet test --project
tests/Aspire.Hosting.RemoteHost.Tests/Aspire.Hosting.RemoteHost.Tests.csproj
--no-launch-profile -- --filter-class "*.CodeGenerationResolverTests"
--filter-class "*.IntegrationLoadContextTests" --filter-class
"*.ApiReferenceExportTests" --filter-class "*.ServiceErrorMessageTests"
--filter-not-trait "quarantined=true" --filter-not-trait
"outerloop=true"` (the classes that resolve the Go generator): 27
passed, 0 failed.
- Real Go AppHosts built with `aspire new aspire-go-empty`, then `aspire
restore` and `aspire publish`, before and after:
- `ConfigureDashboard` with `WithHostPort(9003)`: panic and CLI exit 6,
then exit 0 with all 7 steps and `9003:18888` on `env-dashboard`.
- `PublishAsDockerFile(func(c aspire.ContainerResource) {...})` on an
executable: panic and CLI exit 6, then a live wrapper whose calls
(entrypoint, environment, and `WaitFor` with the wrapper as an argument)
all appear in the compose file.
- 15 callbacks whose `$type` is a registered id
(`WithEnvironmentCallback`, `WithArgsCallback`, `SubscribeBeforeStart`
and others): the generated compose files are identical before and after.
- All 53 Go validation AppHosts under `tests/PolyglotAppHosts` pass
`aspire restore` and `go build` with this generator.
- A throwaway in-package test of `callbackHandleArg` (not committed): 14
observations, and 64 goroutines x 2000 calls with no bad results.

## Checklist

- Is this feature complete?
  - [x] Yes. Ready to ship.
  - [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] Yes
  - [ ] No
- Did you add public API?
  - [ ] Yes
    - If yes, did you have an API Review for it?
      - [ ] Yes
      - [ ] No
- Did you add `<remarks />` and `<code />` elements on your triple slash
comments?
      - [ ] Yes
      - [ ] No
  - [x] No
- Does the change make any security assumptions or guarantees?
  - [ ] Yes
    - If yes, have you done a threat model and had a security review?
      - [ ] Yes
      - [ ] No
  - [x] No

Co-authored-by: David Pine <7679720+IEvangelist@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

Branch: docs_required → already documented by name (PR notes the Go AppHost page was already written in microsoft/aspire.dev#1924 to match).

Triggered signals: polyglot_code_generator_changed (GoLanguageSupport.cs, AtsGoCodeGenerator.cs), pr_body_has_cli_flag_mention (only a dotnet test command in the PR body, not a product flag).

Existing docs coverage:

  • .gitignore for .aspire/: src/frontend/src/content/docs/app-host/go-apphost.mdx — "The starter's .gitignore already lists .aspire/."
  • Per-resource Err() check: app-host/go-apphost-conventions.mdx — "A failed Add call records its error on the handle that it returns, not on the builder, so builder.Err() doesn't report it."
  • log.Fatal(aspire.FormatError(err)) form: used throughout go-apphost.mdx and go-apphost-conventions.mdx.

The remaining changes (LF line endings, gofmt-clean output, launch-profile port ranges, test and sample cleanups) are internal with no documented user-facing surface.

David Pine (IEvangelist) added a commit that referenced this pull request Nov 5, 2026
> [!IMPORTANT]
> **Merge last.** This PR depends on the other open Go AppHost PRs and
must land after them.
>
> - **Must land first**, because each adds references to the flag that
this PR has to delete: #21189 (E2E helper and call sites), #21195
(`SdkExportCommandTests`) and #21196 (`GoAppHostToolingCheck` and its
tests).
> - **Must land first**, because it edits the same hunk of
`DefaultLanguageDiscovery.cs` and this PR rebases onto it: #21191.
> - **Should land first**, because removing the flag turns Go on for
everyone and these fixes should ship before it: #21186, #21187, #21188,
#21193, #21194, #21197 and #21199.

## Description

Removes the `experimentalPolyglotGo` feature flag so Go AppHosts are
available by default, the same way TypeScript AppHosts are. With no
flag, **Empty (Go AppHost)** and **Starter App (Go API + Redis, Go
AppHost)** are offered by interactive and non-interactive `aspire new`,
and Go is offered by `aspire init` language selection and `--language
go`.

**This is the GA switch for the Go AppHost epic (#21115) and must merge
last**, after the other children have landed: #21108 (E2E, publish,
deploy), #21110 (support policy, API review, packaging), #21112 (docs
and samples) and #21114 (VS Code debugging). It was opened as a draft so
CI exercises the 52 Go fixtures without the flag. It is ready for review
now, but not for merging.

What changed:

- **CLI:** `KnownFeatures` drops the Go flag and
`DefaultLanguageDiscovery` no longer marks Go experimental.
`LanguageInfo.IsExperimental` is kept because Python, Java and Rust
still use it.
- **Leftover key:** a stale `experimentalPolyglotGo` in a user's
configuration is ignored with no warning, matching what happened to the
TypeScript flag when it was removed. `Features` only reads named keys,
and the extension schemas set `additionalProperties: false`, so VS Code
flags the stale key.
- **Extension schemas:** `aspire-config`, `aspire-global-settings` and
`aspire-settings` are regenerated with
`extension/scripts/generate-schema.js`. Only the 16-line Go block is
removed from each.
- **Fixtures and CI:** 52
`tests/PolyglotAppHosts/*/Go/aspire.config.json` files and
`.github/workflows/polyglot-validation/Dockerfile.golang` no longer set
the key.
- **Java E2E picker offsets:** Go is always listed now, so with only the
Java flag set the `aspire init` language picker is C#, TypeScript, Go,
Java, and Java needs 3 Down presses instead of 2. The first CI run on
this PR timed out waiting for `> Java` in `JavaPolyglotTests`,
`JavaCodegenValidationTests` and `JavaPolyglotApphostDirectoryTests`;
each now presses Down once more, with a comment stating the picker
order. The order comes from `DefaultLanguageDiscovery`,
`LanguageService` and `CliTemplateFactory`. TypeScript flows are
unaffected because TypeScript sorts before Go.
- **Tests:** `DefaultLanguageDiscoveryTests`, `NewCommandTests`,
`ConfigCommandTests`, `NewCommandTemplateConfigPersistenceTests` and
`InitCommandTests` now expect Go without the flag, with 6 new tests. One
of them, `GetAvailableLanguagesAsync_ListsLanguagesInPickerOrder`, pins
the picker order so a future ungated language fails a unit test before
it breaks a Docker E2E run.
- **Docs:** `docs/specs/polyglot-apphost.md`, the Go code generation
README and `playground/GoAppHost/apphost.go` no longer mention the flag.

Fixes #21106

## Validation

| Command | Result |
| --- | --- |
| `.\restore.cmd` | passed |
| `dotnet build
tests\Aspire.Cli.EndToEnd.Tests\Aspire.Cli.EndToEnd.Tests.csproj -m:2
--no-restore` | 0 warnings, 0 errors |
| `dotnet test --project tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj
--no-launch-profile -- --filter-class "*.DefaultLanguageDiscoveryTests"
--filter-class "*.NewCommandTests" --filter-class "*.ConfigCommandTests"
--filter-class "*.NewCommandTemplateConfigPersistenceTests"
--filter-class "*.InitCommandTests" --filter-not-trait
"quarantined=true" --filter-not-trait "outerloop=true"` | 312 passed, 0
failed (run before the picker-order test was added) |
| `dotnet test --project tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj
--no-launch-profile -- --filter-class "*.DefaultLanguageDiscoveryTests"
--filter-not-trait "quarantined=true" --filter-not-trait
"outerloop=true"` | 39 passed, 0 failed (38 existing plus the
picker-order test) |
| `node extension\scripts\generate-schema.js` | only the Go block was
removed from each schema |
| repository-wide search for `experimentalPolyglotGo` and its variants |
0 hits |
| JSON parse of the 53 fixtures and 3 schemas | all parse, none contain
the flag |

Run in PR CI instead of locally, all passing on `0e65752d44`: the three
Java E2E tests (`JavaPolyglotTests`, `JavaCodegenValidationTests` and
`JavaPolyglotApphostDirectoryTests`; they need Docker, so CI was the
first execution of the extra Down press), `Infrastructure.Tests` and the
VS Code extension unit and E2E jobs.

Not run: the VS Code new-project flow in an extension host
(`extension/src/commands/new.ts` just runs `aspire new`).

### Before merging

- [ ] Search again for `experimentalPolyglotGo`,
`KnownFeatures.ExperimentalPolyglotGo`,
`EnableExperimentalGoSupportAsync`, `features__experimentalPolyglotGo`
and `experimentalPolyglot:go`, because open Go branches add flag setup
of their own and this PR must merge after all of them. Today that covers
#21189 (the `EnableExperimentalGoSupportAsync` helper and its call sites
in every Go scenario), #21195 (`SdkExportCommandTests` sets
`KnownFeatures.ExperimentalPolyglotGo`) and #21196
(`GoAppHostToolingCheckTests` builds its language discovery with the
flag, including a `goEnabled: false` case that stops being meaningful,
and `GoAppHostToolingCheck` has a comment that describes the flag). Each
of them stops compiling or goes stale once the flag is removed, so
delete or rewrite them here.
- [ ] Rebase onto #21191, which adds `DefaultHostingPackages =
["Aspire.Hosting.Go"]` to Go's `LanguageInfo` in the same hunk of
`DefaultLanguageDiscovery.cs` (#21045). Keep that initializer and drop
`IsExperimental: true`.
- [ ] Drop the Go experimental notes in the aspire.dev API reference and
docs at the same time.

## Checklist

- Is this feature complete?
  - [ ] Yes. Ready to ship.
  - [x] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] Yes
  - [ ] No
- Did you add public API?
  - [ ] Yes
    - If yes, did you have an API Review for it?
      - [ ] Yes
      - [ ] No
- Did you add `<remarks />` and `<code />` elements on your triple slash
comments?
      - [ ] Yes
      - [ ] No
  - [x] No
- Does the change make any security assumptions or guarantees?
  - [ ] Yes
    - If yes, have you done a threat model and had a security review?
      - [ ] Yes
      - [ ] No
  - [x] No

---------

Co-authored-by: David Pine <7679720+IEvangelist@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-integrations Issues pertaining to Aspire Integrations packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants