Skip to content

Make required command validation generic via resource annotations for orchestrator pre-checks - #11944

Merged
Eric Erhardt (eerhardt) merged 22 commits into
mainfrom
copilot/make-validation-generic-resource-annotations
Feb 2, 2026
Merged

Eric Erhardt (eerhardt) merged 22 commits into
mainfrom
copilot/make-validation-generic-resource-annotations

Conversation

Copilot AI commented Oct 10, 2025 •

Copy link
Copy Markdown
Contributor

This pull request introduces a new, unified system for validating required commands/executables for resources using the RequiredCommandAnnotation and WithRequiredCommand extension methods. It removes legacy, resource-specific command validation classes and migrates all relevant code to use the new declarative approach. This results in a more flexible, reusable, and maintainable validation mechanism across the codebase. Additionally, documentation has been added to explain the new system, and JavaScript and Azure Functions resource extensions have been updated to utilize it.

Key changes:

Removal of Legacy Validators

  • Removed the FuncCoreToolsInstallationManager and DevTunnelCliInstallationManager classes, along with their registrations and usages, in favor of the new annotation-based system. [1] [2] [3] [4]
  • Updated project files to stop including RequiredCommandValidator.cs in both Azure Functions and DevTunnels projects. [1] [2]

Migration to RequiredCommandAnnotation

  • Updated Azure Functions resource extension to use WithRequiredCommand("func", ...) instead of the previous installation manager for validating Azure Functions Core Tools. [1] [2]
  • Updated DevTunnel resource extension to use a custom RequiredCommandAnnotation with a version validation callback for the devtunnel CLI, replacing the previous installation manager logic. [1] [2]

JavaScript Resource Improvements

  • Updated JavaScript resource extensions to declare required commands (node, npm, bun, yarn) using WithRequiredCommand, providing appropriate installation help links for each. [1] [2] [3] [4]

These changes make command validation more consistent, extensible, and easier to maintain across all resource types.

Fix #11943

Copilot AI changed the title [WIP] Make required command validation generic for orchestrator pre-checks Make required command validation generic via resource annotations for orchestrator pre-checks Oct 10, 2025
@github-actions

github-actions Bot commented Oct 11, 2025 •

Copy link
Copy Markdown
Contributor

🚀 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/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 11944

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 11944"

@DamianEdwards

Copy link
Copy Markdown
Member

Copilot fix the build failures, I see this error:

/home/runner/work/aspire/aspire/tests/Aspire.Hosting.Tests/CommandResolverTests.cs(3,1): error IDE2000: Avoid multiple blank lines (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide2000) [/home/runner/work/aspire/aspire/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj]

Copilot AI commented Oct 11, 2025

Copy link
Copy Markdown
Contributor Author

Copilot fix the build failures, I see this error:

...

Fixed the build failures. Removed the extra blank line in CommandResolverTests.cs that was causing the IDE2000 style violation. Build now succeeds with 0 warnings and 0 errors.

Commit: 5f2c8d9

@github-actions

github-actions Bot commented Jan 27, 2026 •

Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings

The following terminal recordings are available for commit 78f7f33:

Test Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateEmptyAppHostProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording

📹 Recordings uploaded automatically from CI run #21490341442

Refactor devtunnel CLI validation to use generic callback

Replaces DevTunnelCliInstallationManager with a callback-based version validation using RequiredCommandValidator. Updates resource startup logic to use the new approach, improves RequiredCommandValidationResult, and removes obsolete tests. Adds new targeted tests for CLI version validation. Cleans up project file references. This makes CLI validation more modular, testable, and consistent.
Add more tests.
Adjust namespaces.
Revert unnecessary changes.
@eerhardt
Eric Erhardt (eerhardt) marked this pull request as ready for review January 29, 2026 00:38
Copilot AI review requested due to automatic review settings January 29, 2026 00:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request introduces a unified, annotation-based system for validating required commands/executables before resources start. It replaces resource-specific validation classes with a declarative approach using RequiredCommandAnnotation and WithRequiredCommand extension methods, processed automatically by a new lifecycle hook integrated into the orchestrator.

Changes:

  • Introduced RequiredCommandAnnotation, RequiredCommandValidationContext, RequiredCommandValidationResult, IRequiredCommandValidator, and RequiredCommandValidationLifecycleHook to provide a generic, reusable validation infrastructure
  • Removed legacy validators (FuncCoreToolsInstallationManager, DevTunnelCliInstallationManager, PythonInstallationManager, UvInstallationManager) and base class (RequiredCommandValidator in Shared)
  • Migrated Azure Functions, DevTunnels, JavaScript, and Python resource extensions to use the new annotation-based system
  • Added comprehensive test coverage for the new system and updated existing tests

Reviewed changes

Copilot reviewed 55 out of 58 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
src/Aspire.Hosting/ApplicationModel/RequiredCommandAnnotation.cs New annotation class for declaring required commands on resources
src/Aspire.Hosting/ApplicationModel/RequiredCommandValidationContext.cs Context object passed to validation callbacks
src/Aspire.Hosting/ApplicationModel/RequiredCommandValidationResult.cs Result type for validation operations
src/Aspire.Hosting/ApplicationModel/IRequiredCommandValidator.cs Interface for command validation service
src/Aspire.Hosting/ApplicationModel/RequiredCommandValidator.cs Default implementation of command validation with coalescing
src/Aspire.Hosting/Lifecycle/RequiredCommandValidationLifecycleHook.cs Lifecycle hook that validates commands before resource start
src/Aspire.Hosting/RequiredCommandResourceExtensions.cs Extension methods for adding required command annotations
src/Aspire.Hosting/DistributedApplicationBuilder.cs Registers the new validation services and lifecycle hook
src/Aspire.Hosting.Azure.Functions/AzureFunctionsProjectResourceExtensions.cs Migrated to use WithRequiredCommand for "func"
src/Aspire.Hosting.DevTunnels/DevTunnelResourceBuilderExtensions.cs Migrated to use new validation system with custom version checking
src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs Added WithRequiredCommand for node, npm, bun, yarn, pnpm
src/Aspire.Hosting.Python/PythonAppResourceBuilderExtensions.cs Migrated to use WithRequiredCommand for python and uv
tests/Aspire.Hosting.Tests/RequiredCommandAnnotationTests.cs New comprehensive test suite for the annotation system
tests/Aspire.Hosting.Tests/PathLookupHelperTests.cs Tests for PATH lookup helper functionality
Localization files Added new message strings for validation errors
Files not reviewed (2)
  • src/Aspire.Hosting.DevTunnels/Resources/MessageStrings.Designer.cs: Language not supported
  • src/Aspire.Hosting/Resources/MessageStrings.Designer.cs: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@DamianEdwards

Damian Edwards (DamianEdwards) commented Jan 30, 2026 •

Copy link
Copy Markdown
Member

🧪 PR Verification Report (Comprehensive)

I've performed comprehensive verification of this PR testing all affected resource types: Node.js, Python, Azure Functions, and DevTunnels.

Test Environment

  • Aspire CLI Version: 13.2.0-pr.11944.g78f7f333 (installed via PR dogfood script)
  • Test App Location: D:\scratch\aspire\pr-11944\TestApp

Resources Tested

Resource Type Command(s) Validated Package Status
Node.js node, npm Aspire.Hosting.JavaScript ✅ Verified
Python (default) python Aspire.Hosting.Python ✅ Verified
Python (with UV) uv Aspire.Hosting.Python ✅ Verified
Azure Functions func Aspire.Hosting.Azure.Functions ✅ Verified
DevTunnels devtunnel Aspire.Hosting.DevTunnels ✅ Verified

✅ Test Results

Positive Test Case (All Commands Available)

When all tools are on PATH:

  • ✅ No warning notifications displayed
  • ✅ All resources start normally
  • ✅ No warnings in log output

Negative Test Case (Commands Missing)

Modified PATH to exclude tools (process-level only, not system-wide).

Log Output showing warnings for ALL affected resource types:

[Warning] RequiredCommandValidator: Resource 'funcapp' may fail to start:
Required command 'func' was not found on PATH or at the specified location.
For installation instructions, see: https://learn.microsoft.com/azure/azure-functions/functions-run-local#install-the-azure-functions-core-tools

[Warning] RequiredCommandValidator: Resource 'pythonuvapp-installer' may fail to start:
Required command 'uv' was not found on PATH or at the specified location.
For installation instructions, see: https://docs.astral.sh/uv/getting-started/installation/

[Warning] RequiredCommandValidator: Resource 'nodeapp' may fail to start:
Required command 'node' was not found on PATH or at the specified location.
For installation instructions, see: https://nodejs.org/en/download/

[Warning] RequiredCommandValidator: Resource 'nodeapp' may fail to start:
Required command 'npm' was not found on PATH or at the specified location.
For installation instructions, see: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm

✅ Validation for Each Integration

Node.js Integration

  • AddNodeApp() automatically adds WithRequiredCommand("node")
  • Package manager methods add respective commands (npm, yarn, bun, pnpm)
  • ✅ Notifications show with correct help links

Python Integration

  • AddPythonApp() adds WithRequiredCommand("python")
  • WithUv() adds WithRequiredCommand("uv") for the installer
  • ✅ Both python and uv validation working correctly

Azure Functions Integration

  • AddAzureFunctionsProject() adds WithRequiredCommand("func")
  • ✅ Notification shows with link to Azure Functions Core Tools installation

DevTunnels Integration

  • Uses custom validation with version checking
  • ✅ Still works correctly after PR changes (validated when devtunnel is on PATH)

✅ Features Verified

  1. ✅ WithRequiredCommand() correctly adds RequiredCommandAnnotation to resources
  2. ✅ RequiredCommandValidator validates commands on PATH before resource start
  3. ✅ Warning messages logged when commands are missing
  4. ✅ Dashboard displays user-friendly notification banners with help links
  5. ✅ Help links correctly configured for all integrations:
    • Node.js: nodejs.org
    • npm: npmjs.com
    • Python: python.org
    • UV: docs.astral.sh
    • Azure Functions: learn.microsoft.com
    • DevTunnels: learn.microsoft.com
  6. ✅ Notifications are properly coalesced (one per command, no duplicates)
  7. ✅ All existing integrations continue to work after refactoring

Verified using Aspire CLI dogfood build and Playwright/Edge for dashboard verification

dashboard-final-verification screenshot-all-scenarios

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I verified locally with Copliot CLI (see command above) and all seems to be good!

@eerhardt
Eric Erhardt (eerhardt) merged commit bbc9a8e into main Feb 2, 2026
334 checks passed
@eerhardt
Eric Erhardt (eerhardt) deleted the copilot/make-validation-generic-resource-annotations branch February 2, 2026 17:07
@dotnet-policy-service dotnet-policy-service Bot added this to the 13.2 milestone Feb 2, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make required command validation generic via resource annotations for orchestrator pre-checks

5 participants