Repository navigation
Skip name validation for ProjectRebuilderResource - #15724
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15724Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15724" |
There was a problem hiding this comment.
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/ExecutableResourceconstructors intended to bypassModelName.ValidateName. - Update
ProjectRebuilderResourceto 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. |
| /// <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)), | ||
| }); | ||
| } |
There was a problem hiding this comment.
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.
a9dd4f0 to
0749511
Compare
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
0749511 to
32fe7f3
Compare
David Fowler (davidfowl)
left a comment
There was a problem hiding this comment.
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.
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. |
|
/backport to release/13.2 |
|
Started backporting to |
|
🎬 CLI E2E Test Recordings — 52 recordings uploaded (commit View recordings
📹 Recordings uploaded automatically from CI run #23780162913 |
This reverts commit 30f3928.
This reverts commit 30f3928.
|
No documentation update is required for this PR. This change is an internal bug fix that adds
|
Description
Resource names have a 64-character limit enforced by
ModelName.ValidateName. TheProjectRebuilderResourceappends-rebuilderto 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
ResourceandExecutableResourcethat skip name validation, and uses them inProjectRebuilderResource.Fixes #15693
Checklist
<remarks />and<code />elements on your triple slash comments?aspire.devissue: