Add ConditionalReferenceExpression with polyglot codegen support#14919
Add ConditionalReferenceExpression with polyglot codegen support#14919danegsta wants to merge 15 commits intorelease/13.2from
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14919Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14919" |
There was a problem hiding this comment.
Pull request overview
Adds a new lazy/deferred value provider to support reference-expression fragments that depend on state only known later in the lifecycle (notably Redis TLS), and updates Redis endpoint/URI scheme handling to be scheme-driven rather than hard-coded.
Changes:
- Introduces
DeferredValueProvider(runtime + manifest expression callbacks) and anEndpointReference.TlsValue(...)helper. - Adds
EndpointAnnotation.TlsEnabled/EndpointReference.TlsEnabledand wires Redis TLS to endpoint annotations (includingssl=trueconnection string fragment). - Updates Redis tests/manifests to use binding
{...scheme}and default Redis endpoint scheme toredis(andredisswhen TLS is enabled).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Aspire.Hosting.Tests/DeferredValueProviderTests.cs | New unit tests covering deferred provider behavior and interaction with ReferenceExpressionBuilder. |
| tests/Aspire.Hosting.Redis.Tests/ConnectionPropertiesTests.cs | Updates expected Redis URI manifest expression to use {...scheme} binding. |
| tests/Aspire.Hosting.Redis.Tests/AddRedisTests.cs | Updates Redis endpoint scheme expectations and adds TLS/dynamic-resolution coverage. |
| src/Aspire.Hosting/ApplicationModel/EndpointReference.cs | Adds TlsEnabled and TlsValue(...) to support TLS-dependent dynamic fragments. |
| src/Aspire.Hosting/ApplicationModel/EndpointAnnotation.cs | Adds TlsEnabled flag for endpoint-level TLS state. |
| src/Aspire.Hosting/ApplicationModel/DeferredValueProvider.cs | Adds new general-purpose deferred value provider implementation. |
| src/Aspire.Hosting.Redis/RedisResource.cs | Switches TLS handling to endpoint-based TLS state and scheme-driven URI/connection string fragments. |
| src/Aspire.Hosting.Redis/RedisBuilderExtensions.cs | Sets Redis primary endpoint scheme to redis and updates TLS enablement to mutate endpoint annotation state. |
You can also share your feedback on Copilot code review. Take the survey.
🎬 CLI E2E Test RecordingsThe following terminal recordings are available for commit
📹 Recordings uploaded automatically from CI run #22793531443 |
9404e2f to
a5aa70a
Compare
|
How does this affect the typescript support? |
Replace DeferredValueProvider with ConditionalReferenceExpression, a new type that models conditional values in connection strings (e.g., TLS ssl=true/empty). The CRE auto-generates its manifest name from the condition's ValueExpression at construction time. Key changes: - ConditionalReferenceExpression type with Create() factory, auto-name generation via condition sanitization, and manifest value.v0 support - EndpointReference.GetTlsValue returns CRE instead of using closure - ManifestPublishingContext writes CRE entries as value.v0 resources - Polyglot create()/toJSON() in all 5 ATS base files (TS, Go, Python, Java, Rust) with $condExpr JSON serialization format - ConditionalReferenceExpressionRef for server-side $condExpr unmarshalling in AtsMarshaller - Redis connection string tests updated with pattern matching to handle auto-generated CRE names and verify manifest value entries Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The MarshalToJson_ConditionalReferenceExpression_PreservesValueAfterRoundTrip
test was asserting an exact name ('test-tls') but names are now auto-generated
from the condition's ValueExpression. Use StartsWith assertion instead.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The merge brought in updated EndpointReference.getTlsValue which no longer takes parameterName. Updated all 5 language snapshots accordingly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
This should be merged into ReferenceExpression if we take this approach. |
- Add ReferenceExpression.CreateConditional() factory method - Add conditional mode with IsConditional, Condition, WhenTrue, WhenFalse properties - Unify ATS wire format: conditional uses $expr with condition/whenTrue/whenFalse - Remove ConditionalReferenceExpression class and ConditionalReferenceExpressionRef - Remove $condExpr from ATS protocol, remove ConditionalReferenceExpressionTypeId - Update all 5 polyglot base templates (TS, Python, Go, Java, Rust) - Update all 5 codegen generators to remove CRE special-casing - Make ReferenceExpression.Name internal - Migrate all tests to use new API
Description
Replaces
DeferredValueProviderwithConditionalReferenceExpression, a new type that models conditional values in connection strings and other reference expressions. This enables proper manifest publishing and polyglot code generation for conditional logic like TLSssl=truein Redis connection strings.ConditionalReferenceExpression
A ternary-style expression type that evaluates a boolean
IValueProvidercondition and selects between twoReferenceExpressionbranches (whenTrue/whenFalse). Key design decisions:ValueExpressionat construction time (e.g.,{redis.bindings.tcp.tlsEnabled}→cond-redis-bindings-tcp-tlsenabled), eliminating the need for explicit namingvalue.v0entries in the manifest, referenced via{name.value}in connection stringsCreate()factory: Follows the same pattern asReferenceExpression.CreatePolyglot ATS Support
All 5 polyglot language base files (TypeScript, Go, Python, Java, Rust) support:
create()factory method for client-side CRE constructiontoJSON()serialization using$condExprformat:{ "$condExpr": { "condition": <handle>, "whenTrue": <$expr>, "whenFalse": <$expr> } }$condExprunmarshalling viaConditionalReferenceExpressionRefinAtsMarshallerRedis TLS
Re-enables TLS by default for Redis container endpoints.
EndpointReference.GetTlsValuenow returns aConditionalReferenceExpressioninstead of using a closure-basedDeferredValueProvider, making it compatible with polyglot code generation.Fixes #13645
Changes
New files
src/Aspire.Hosting/ApplicationModel/ConditionalReferenceExpression.cs— Core type withCreate(), auto-name generation, manifest supportsrc/Aspire.Hosting.RemoteHost/Ats/ConditionalReferenceExpressionRef.cs— Server-side$condExprJSON unmarshallingtests/Aspire.Hosting.Tests/ConditionalReferenceExpressionTests.cs— 10 unit testsModified files
EndpointReference.cs—GetTlsValuereturns CRE instead of DeferredValueProviderRedisResource.cs— UpdatedBuildConnectionStringto use newGetTlsValuesignatureManifestPublishingContext.cs— Registers and writes CRE entries asvalue.v0resourcescreate()/toJSON()forConditionalReferenceExpressionConditionalReferenceExpressiontype$condExprunmarshalling testsRemoved files
DeferredValueProvider.cs— Replaced byConditionalReferenceExpressionDeferredValueProviderTests.cs— Replaced byConditionalReferenceExpressionTestsChecklist
<remarks />and<code />elements on your triple slash comments?aspire.devissue: