Skip to content

Fix Ngrok integration on Aspire 13.3#1313

Open
esond wants to merge 2 commits into
CommunityToolkit:mainfrom
esond:fix/1309-ngrok-aspire-13.3-args-config
Open

Fix Ngrok integration on Aspire 13.3#1313
esond wants to merge 2 commits into
CommunityToolkit:mainfrom
esond:fix/1309-ngrok-aspire-13.3-args-config

Conversation

@esond
Copy link
Copy Markdown

@esond esond commented May 12, 2026

Closes #1309

After upgrading to Aspire 13.3, CommunityToolkit.Aspire.Hosting.Ngrok produced a broken container: no Cmd args, no YAML on the bind-mounted volume, and an immediate exit with Your configuration file must define at least one tunnel when using --all.

The root cause is that AddNgrok deferred both the YAML config write and WithArgs(...) into OnResourceEndpointsAllocated. Per the Aspire 13.3 release notes, argument-callback timing was reworked, and under 13.3 that callback either fires too late or not at all for arg/config setup, so the container starts uninitialized.

Changes

  • Move WithArgs onto the builder chain using the WithArgs(context => ...) callback form. The arg-time decision (--all vs --none) inspects NgrokEndpointAnnotation count from context.Resource.Annotations at args-resolution time.
  • Move the YAML config file write into OnBeforeResourceStarted, which fires after endpoint allocation and before the container starts on Aspire 13.3 (same pattern used by ActiveMQ, McpInspector, and Stripe in this repo).

Tests

Added NgrokArgsTests covering args resolution for the empty-endpoint, tunnel-endpoint, and resource-name-in-config-path cases. All 31 unit tests in the Ngrok test project pass.

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Contains NO breaking changes
  • Every new API (including internal ones) has full XML docs (no new public API surface)
  • Code follows all style conventions

Other information

Worth a sweep of other integrations that mutate args or write config files inside OnResourceEndpointsAllocated — they likely have the same problem on Aspire 13.3.

…g file write

Aspire 13.3 reworked OnResourceEndpointsAllocated callback timing,
which caused WithArgs and YAML config writes deferred inside that
callback to be dropped. The ngrok container started without args
and without its config file, then exited with "configuration file
must define at least one tunnel when using --all".

Move WithArgs onto the builder chain via the context callback form,
and move the YAML config write into OnBeforeResourceStarted (which
fires after endpoint allocation and before the container starts on
Aspire 13.3).
Copilot AI review requested due to automatic review settings May 12, 2026 03:06
@esond esond requested a review from esskar as a code owner May 12, 2026 03:06
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 12, 2026

🚀 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/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.sh | bash -s -- 1313

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/CommunityToolkit/Aspire/main/eng/scripts/dogfood-pr.ps1) } 1313"

@esond
Copy link
Copy Markdown
Author

esond commented May 12, 2026

@dotnet-policy-service agree

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes the CommunityToolkit.Aspire.Hosting.Ngrok hosting integration for Aspire 13.3 by ensuring ngrok container args are applied during args-resolution and the generated YAML config is written immediately before the resource starts.

Changes:

  • Moved ngrok container argument setup from OnResourceEndpointsAllocated to WithArgs(context => ...), selecting --all vs --none based on configured NgrokEndpointAnnotation entries.
  • Moved ngrok YAML config generation to OnBeforeResourceStarted to ensure the bind-mounted config file exists before container startup.
  • Added unit tests validating args resolution for no endpoints, with endpoints, and resource-name-based config path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/CommunityToolkit.Aspire.Hosting.Ngrok.Tests/NgrokArgsTests.cs Adds coverage for ngrok args callback behavior across endpoint/no-endpoint scenarios.
src/CommunityToolkit.Aspire.Hosting.Ngrok/NgrokExtensions.cs Adjusts lifecycle timing for args and config generation to be compatible with Aspire 13.3 startup behavior.

Comment thread src/CommunityToolkit.Aspire.Hosting.Ngrok/NgrokExtensions.cs Outdated
Matches the deconstruction name used in CreateNgrokConfigurationFileAsync.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ngrok integration broken on Aspire 13.3: WithArgs and config file never applied

2 participants