Expose command state snapshots to polyglot apphosts#17328
Conversation
Expose a curated resource snapshot projection to polyglot command state callbacks and validate health-gated command state usage across the polyglot validation apphosts. Co-authored-by: Copilot <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 17328Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 17328" |
There was a problem hiding this comment.
Pull request overview
This PR extends the polyglot AppHost SDK surface so CommandOptions.UpdateState callbacks can access a curated resource snapshot (health + lifecycle) via UpdateCommandStateContext.resourceSnapshot(), while keeping the raw .NET CustomResourceSnapshot unchanged for C# consumers.
Changes:
- Added an ATS-exported
resourceSnapshot()capability onUpdateCommandStateContextbacked by a new curatedUpdateCommandStateResourceSnapshotDTO. - Updated Python/Java/Go transports to recursively marshal callback-valued DTO properties so nested
CommandOptions.UpdateStatecallbacks register correctly. - Refreshed codegen/API baselines and updated polyglot AppHost samples to demonstrate health-gated command state.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/PolyglotAppHosts/Aspire.Hosting/TypeScript/apphost.ts | Adds a health-gated updateState command example using ctx.resourceSnapshot(). |
| tests/PolyglotAppHosts/Aspire.Hosting/Python/apphost.py | Adds a Python UpdateState command example using ctx.resource_snapshot. |
| tests/PolyglotAppHosts/Aspire.Hosting/Java/AppHost.java | Adds a Java UpdateState example using ctx.resourceSnapshot(). |
| tests/PolyglotAppHosts/Aspire.Hosting/Go/apphost.go | Adds a Go UpdateState example using ctx.ResourceSnapshot(). |
| tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts | Updates TS generated snapshot with HealthStatus, snapshot DTO, and resourceSnapshot() API. |
| tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/AtsTypeScriptCodeGeneratorTests.cs | Minor test refactor (stores aspire.ts content in a local variable). |
| tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs | Updates Rust generated snapshot with HealthStatus, snapshot DTO, and resource_snapshot(). |
| tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py | Updates Python generated snapshot with HealthStatus, snapshot DTO, resource_snapshot, and arg marshalling. |
| tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java | Updates Java generated snapshot with HealthStatus, snapshot DTO, transport marshalling, and resourceSnapshot(). |
| tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go | Updates Go generated snapshot with HealthStatus, snapshot DTO, and ResourceSnapshot(). |
| src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotation.cs | Adds the curated snapshot DTO and exports resourceSnapshot() while ignoring raw CustomResourceSnapshot for polyglot. |
| src/Aspire.Hosting/api/Aspire.Hosting.Capabilities.txt | Updates capabilities baseline for the new snapshot DTO + HealthStatus enum. |
| src/Aspire.Hosting/api/Aspire.Hosting.ats.txt | Updates ATS baseline for the new resourceSnapshot() capability + snapshot DTO. |
| src/Aspire.Hosting.CodeGeneration.Python/PythonModuleBuilder.cs | Updates Python transport template to recursively marshal callback-valued args. |
| src/Aspire.Hosting.CodeGeneration.Java/Resources/Transport.java | Updates Java transport template to recursively marshal callback-valued args. |
| src/Aspire.Hosting.CodeGeneration.Go/Resources/transport.go | Updates Go transport template to recursively marshal callback-valued args. |
|
Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
|
Materialize generated Java DTO capability returns from transport maps and mark nullable resource snapshot fields in the capability baseline. Co-authored-by: Copilot <[email protected]>
Ignore IServiceProvider on resource command callback contexts and update the generated ATS baselines/snapshots to remove those polyglot capabilities. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…ix-typescript-command-state-cont
Co-authored-by: Copilot <[email protected]>
…ities The Python AtsGeneratedAspire snapshot drifted when the polyglot transport marshalling change introduced the _marshal_transport_value helper but only the two-pass snapshot was refreshed. Refresh the ATS snapshot so the Python codegen tests pass on Linux and Windows runners. Also suppress the capability-removed TypeScript API compat diagnostics for ExecuteCommandContext.serviceProvider and UpdateCommandStateContext.serviceProvider. Both were intentionally hidden from ATS because polyglot apphosts cannot consume an IServiceProvider handle and the new resourceSnapshot projection covers the only useful use case (gating UpdateState callbacks on health). Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…ix-typescript-command-state-cont
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
❓ CLI E2E Tests unknown — 95 passed, 0 failed, 5 unknown (commit View all recordings
📹 Recordings uploaded automatically from CI run #26239952636 |
… support TypeScript AppHosts can now gate command state using ctx.resourceSnapshot() on UpdateCommandStateContext, exposed via the new UpdateCommandStateResourceSnapshot DTO added in microsoft/aspire#17328. Remove the outdated caution note that said TypeScript had no resourceSnapshot equivalent, and replace it with a working example that mirrors the C# health-gated command pattern. Also update the Japanese (ja) localization of the same page. Co-authored-by: Copilot <[email protected]>
|
Pull request created: #1042
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#1042 targeting Updated Note This draft PR needs human review before merging. |
Description
Polyglot AppHost command
updateStatecallbacks need access to the resource's latest snapshot so commands can be enabled or disabled based on health and lifecycle state. Before this change, TypeScript and the other generated SDKs did not expose that data onUpdateCommandStateContext, which made health-gated command state callbacks impossible to write in polyglot AppHosts.This adds a curated ATS resource snapshot projection for command state callbacks and exposes it as
resourceSnapshot()in the generated SDKs. The projection includes health and lifecycle state data without exporting the raw .NETCustomResourceSnapshot, and the polyglot validation apphosts now cover both health-gated command state and resource command execution.User-facing usage
TypeScript AppHosts can now gate command state directly from the resource snapshot:
The same API shape is validated in the Python, Java, and Go polyglot apphost samples.
Fixes #16769
Validation performed:
aspire restorefortests/PolyglotAppHosts/Aspire.Hostingin TypeScript, Python, Java, and Gonpx tsc --noEmit --project tsconfig.jsonapphost.pyand generated modulesjavac --enable-preview --source 25over generated module sources andAppHost.javago build -buildvcs=false ./...Checklist
<remarks />and<code />elements on your triple slash comments?