Skip to content

Skip name validation for ProjectRebuilderResource - #15724

Merged
James Newton-King (JamesNK) merged 2 commits into
mainfrom
jamesnk/resource-name-length
Mar 31, 2026
Merged

James Newton-King (JamesNK) merged 2 commits into
mainfrom
jamesnk/resource-name-length

Conversation

@JamesNK

Copy link
Copy Markdown
Member

Description

Resource names have a 64-character limit enforced by ModelName.ValidateName. The ProjectRebuilderResource appends -rebuilder to the parent resource name, which can push it over the limit even when the user's resource name is valid.

Since rebuilder resources are never deployed, they don't need to follow naming rules. This PR adds internal constructors to Resource and ExecutableResource that skip name validation, and uses them in ProjectRebuilderResource.

Fixes #15693

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?

@github-actions

github-actions Bot commented Mar 31, 2026 •

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

Or

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

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

Fixes a failure mode where ProjectRebuilderResource can exceed the 64-character ModelName.ValidateName limit due to the -rebuilder suffix, even when the user-provided project resource name is valid. This is addressed by introducing internal “skip name validation” constructor paths and using them for the rebuilder resource (which is excluded from deployment/manifest).

Changes:

  • Add internal Resource / ExecutableResource constructors intended to bypass ModelName.ValidateName.
  • Update ProjectRebuilderResource to use the validation-skipping constructor path.
  • Add a unit test ensuring long rebuilder names do not throw.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/Aspire.Hosting.Tests/ModelNameTests.cs Adds coverage for creating a ProjectRebuilderResource with a >64 char name.
src/Aspire.Hosting/ApplicationModel/Resource.cs Introduces an internal constructor intended to bypass name validation.
src/Aspire.Hosting/ApplicationModel/ExecutableResource.cs Introduces an internal constructor intended to bypass name validation and forwards the flag to Resource.
src/Aspire.Hosting/ApplicationModel/ProjectRebuilderResource.cs Switches rebuilder construction to use the validation-skipping path.

Comment on lines +37 to +48
/// <summary>
/// Initializes a new instance of the <see cref="ExecutableResource"/> class without name validation.
/// Used for internal resources that are never deployed and don't need to follow naming rules.
/// </summary>
internal ExecutableResource(string name, string command, string workingDirectory, bool skipValidation) : base(name, skipValidation)
{
Annotations.Add(new ExecutableAnnotation
{
Command = ThrowIfNullOrEmpty(command),
WorkingDirectory = workingDirectory ?? throw new ArgumentNullException(nameof(workingDirectory)),
});
}

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

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

This overload forwards skipValidation to Resource, but Resource(string, bool) currently ignores the flag (it always skips validation except for a Debug.Assert). That makes it easy for an internal caller to unintentionally bypass naming validation in Release by passing skipValidation: false. Align the behavior with the parameter (or switch to a non-boolean opt-in) so the intent is enforced at runtime.

Copilot uses AI. Check for mistakes.
Rebuilder resources append '-rebuilder' to the parent resource name,
which can exceed the 64-character limit. Since these resources are never
deployed, skip validation by adding internal constructors to Resource
and ExecutableResource that bypass ModelName.ValidateName.

Fixes #15693

@davidfowl David Fowler (davidfowl) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We want this in 13.2.x as well.

PS: We also want this for installer based resources like npm which add a suffix. I wonder why we didn't see this pop up before...

@JamesNK

Copy link
Copy Markdown
Member Author

We want this in 13.2.x as well.

PS: We also want this for installer based resources like npm which add a suffix. I wonder why we didn't see this pop up before...

I think the difference is we only just added rebuilder resources. That means it regressed apps and people complained.

npm installers always had this problem but people immediately saw the error and just used a shorter name.

JavaScriptInstallerResource, PythonInstallerResource, and
PythonVenvCreatorResource also append suffixes to the parent
resource name and could exceed the 64-char limit. These are
never deployed, so skip validation for them as well.
@JamesNK

James Newton-King (JamesNK) commented Mar 31, 2026 •

Copy link
Copy Markdown
Member Author

PS: We also want this for installer based resources like npm which add a suffix. I wonder why we didn't see this pop up before...

Those resources for JavaScript/Python are in other assemblies and can't access internal ctor. We'd need to make the skipValidation flag public. That would be gross.

Maybe change name validation so it happens when the apphost is built, giving the opportunity to add a SkipNameValidation annotation to a resource after creating it. IMO do that in 13.3, and have this temp fix for 13.2.

@JamesNK

Copy link
Copy Markdown
Member Author

/backport to release/13.2

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/13.2 (link to workflow run)

@JamesNK
James Newton-King (JamesNK) merged commit 30f3928 into main Mar 31, 2026
256 checks passed
@JamesNK
James Newton-King (JamesNK) deleted the jamesnk/resource-name-length branch March 31, 2026 06:18
@github-actions

Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 52 recordings uploaded (commit 2a24af7)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RunWithMissingAwaitShowsHelpfulError ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
TypeScriptAppHostWithProjectReferenceIntegration ▶️ View Recording

📹 Recordings uploaded automatically from CI run #23780162913

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

No documentation update is required for this PR.

This change is an internal bug fix that adds internal constructors to Resource and ExecutableResource to skip name validation for deployer/installer resources (e.g., ProjectRebuilderResource, JavaScriptInstallerResource). There are no public API changes, no new user-facing features, and no behavior visible to end users. The fix resolves an edge case where appending suffixes like -rebuilder to a 64-character resource name caused an unexpected validation error — but the 64-character naming rule itself is unchanged and already documented.

Generated by PR Documentation Check · ● 122.2K · ◷

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.

Rebuilder resource will break app when it exceeds 64 characters

4 participants