Skip to content

Add test case to reproduce EndpointReference environment variable bug (#6548)#12830

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-endpointreference-variable
Draft

Add test case to reproduce EndpointReference environment variable bug (#6548)#12830
Copilot wants to merge 2 commits intomainfrom
copilot/fix-endpointreference-variable

Conversation

Copy link
Contributor

Copilot AI commented Nov 8, 2025

Description

Imports test case from issue #6548 to verify that EndpointReference environment variables evaluate to http://: (missing host and port) instead of the expected full URL when using WithReference(resource.GetEndpoint("http")).

The test demonstrates the bug without fixing it:

var dependency = builder
    .AddResource(new FakeResource("fake"))
    .WithHttpEndpoint();

var consumer = builder
    .AddContainer("test", "redis")
    .WithReference(dependency.GetEndpoint("http"));

var endpointAnnotation = dependency.Resource.Annotations.OfType<EndpointAnnotation>().Single();
endpointAnnotation.AllocatedEndpoint = new AllocatedEndpoint(endpointAnnotation, "localhost", 1234);

var envVars = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(consumer.Resource, ...);

// Currently fails: envVars["services__fake__http__0"] == "http://:" 
// Expected: "http://localhost:1234"

Fix will be addressed separately.

Fixes #6548

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
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No
Original prompt

This section details on the original issue you should resolve

<issue_title>[13.0] EndpointReference environment variable evaluating to http://: (i.e. missing host & port)</issue_title>
<issue_description>### Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a test in 9.5, in which I needed to run an in memory server on a port, and make sure a dependency connects to it. (Specifically the otel connector)

After upgrading to 13.0, the endpoint is not being resolved correctly, and rather than failing, is ending up with an empty host and port http://:.

Whilst this could be a problem with my test code, it does feel like WithEnvironment() should never be able to resolve with an empty port/host, so maybe something else is wrong.

Expected Behavior

The reference should contain the port & host from the allocated endpoint.

But even more so, I wouldn't expect the final environment value to end up with missing host or port - I'd expect some kind of error to be thrown if either of these evaluated to null/empty.

Steps To Reproduce

   [Test]
   public async Task test()
   {
      var builder = DistributedApplicationTestingBuilder.Create();

      var dependency = builder
         .AddResource(new FakeResource())
         .WithHttpEndpoint();

      var consumer = builder
         .AddContainer("test", "redis")
         .WithImageRegistry("docker.io")
         .WithReference(dependency.GetEndpoint("http"));

      var endpointAnnotation = dependency.Resource.Annotations.OfType<EndpointAnnotation>().Single();
      endpointAnnotation.AllocatedEndpoint = new AllocatedEndpoint(endpointAnnotation, "localhost", 1234);

      using var app = builder.Build();
      await app.StartAsync();

      var envVars = await consumer.Resource.GetEnvironmentVariableValuesAsync();
      Assert.That(envVars["services__fake__http__0"], Is.EqualTo("http://localhost:1234"));
      // Actual: `http://:`
   }

   public class FakeResource() : Resource("fake"), IResourceWithEndpoints { }

Exceptions (if any)

  Assert.That(envVars["services__fake__http__0"], Is.EqualTo("http://localhost:1234"))
  Expected string length 21 but was 8. Strings differ at index 7.
  Expected: "http://localhost:1234"
  But was:  "http://:"

.NET Version info

No response

Anything else?

No response</issue_description>

<agent_instructions>Import the test case in the issue (not the comment) into Aspire.Hosting.Tests. Do not attempt to fix the issue yet, lets just verify the failing behavior inside the repo and then we can look at understanding the cause.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix EndpointReference environment variable resolving to empty host and port Add test case to reproduce EndpointReference environment variable bug (#6548) Nov 8, 2025
Copilot AI requested a review from mitchdenny November 8, 2025 00:22
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.

[13.0] EndpointReference environment variable evaluating to http://: (i.e. missing host & port) Retry loop in ContainerReconciler exhausts system RAM

2 participants