Skip to content

Conversation

@sebastienros
Copy link
Member

Description

When calling the method twice the parameter may be removed by mistake.

Fixes #10424 (review)

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
  • Does the change require an update in our Aspire docs?
    • Yes
    • No

Copilot AI review requested due to automatic review settings July 15, 2025 15:46
@github-actions github-actions bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Jul 15, 2025
@sebastienros sebastienros requested a review from eerhardt July 15, 2025 15:46
Copy link
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

This PR ensures that when WithApiKey is called multiple times, only the initially generated default parameter is removed, and subsequent custom parameters remain intact.

  • Update WithApiKey removal logic to target only the default key parameter.
  • Add a new unit test to verify the behavior when calling WithApiKey twice.

Reviewed Changes

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

File Description
tests/Aspire.Hosting.GitHub.Models.Tests/GitHubModelsExtensionTests.cs Added WithApiKeyCalledTwiceOnlyRemovesDefaultParameter test to confirm only the default key is removed on the first call.
src/Aspire.Hosting.GitHub.Models/GitHubModelsExtensions.cs Modified WithApiKey to remove the existing API key only if it matches the default parameter name.
Comments suppressed due to low confidence (1)

tests/Aspire.Hosting.GitHub.Models.Tests/GitHubModelsExtensionTests.cs:271

  • Add an assertion to verify that builder.Resource.Key.Name is updated to the new API key parameter (e.g., "secret-key2") after each call to WithApiKey, ensuring that the resource builder reflects the latest key.
        github.WithApiKey(builder.AddParameter("secret-key2", secret: true));

@davidfowl davidfowl merged commit da17009 into main Jul 15, 2025
276 checks passed
@davidfowl davidfowl deleted the sebros/fixapikey branch July 15, 2025 17:46
davidfowl pushed a commit that referenced this pull request Jul 15, 2025
* Fix parameter substitution in GitHub Models

* Use reference
davidfowl pushed a commit that referenced this pull request Jul 15, 2025
* Simplify GH Models API keys experience

* Fix parameter substitution in GitHub Models (#10428)

* Fix parameter substitution in GitHub Models

* Use reference

---------

Co-authored-by: Sebastien Ros <sebastienros@gmail.com>
@github-actions github-actions bot locked and limited conversation to collaborators Aug 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants