Skip to content

Revert ProjectLocator walk-stop behavior from #18683 - #18700

Merged
James Newton-King (JamesNK) merged 1 commit into
mainfrom
jamesnk/revert-project-locator-walk-stop
Jul 9, 2026
Merged

James Newton-King (JamesNK) merged 1 commit into
mainfrom
jamesnk/revert-project-locator-walk-stop

Conversation

@JamesNK

Copy link
Copy Markdown
Member

Description

Reverts the ProjectLocator "stop config walk at workspace root" behavior introduced in #18683.

The change removed:

  • The outer if (aspireConfig is not null) wrapper that prevented the parent directory walk from continuing past aspire.config.json when it had no appHost.path configured
  • The return null; after the .aspire/settings.json block that similarly stopped the walk
  • Associated comments explaining the walk-stop behavior
  • Two unit tests (GetAppHostFromSettings_StopsAtWorkspaceRootWhenLegacySettingsHasNoAppHostPath and GetAppHostFromSettings_StopsAtWorkspaceRootWhenAspireConfigJsonHasNoAppHostPath)

Validation

All 4606 CLI tests pass (0 failures, 36 skipped for platform reasons).

Remove the 'stop config walk at workspace root' logic that prevented
the parent directory walk from continuing past aspire.config.json or
.aspire/settings.json when they had no appHost path configured.

Also remove the two corresponding unit tests that validated the
walk-stop behavior.
Copilot AI review requested due to automatic review settings July 9, 2026 02:13
@github-actions

github-actions Bot commented Jul 9, 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 -- 18700

Or

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

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 PR reverts the "stop config walk at workspace root" behavior in ProjectLocator that was introduced as part of #18683. It restores the pre-#18683 behavior where GetAppHostProjectFileFromSettingsAsync continues walking up parent directories even when an aspire.config.json or .aspire/settings.json exists at the current level but does not specify an AppHost path.

Changes:

  • Removed the outer if (aspireConfig is not null) wrapper and the trailing return null; statements that previously halted the parent-directory walk at the workspace root, collapsing the config check back to a single aspireConfig?.AppHost?.Path is { } guard.
  • Deleted the two regression tests that asserted the walk stopped at the workspace root (GetAppHostFromSettings_StopsAtWorkspaceRootWhenLegacySettingsHasNoAppHostPath and GetAppHostFromSettings_StopsAtWorkspaceRootWhenAspireConfigJsonHasNoAppHostPath).

The revert is mechanically clean: control flow, brace balance, and indentation are all correct, the NUL-byte/invalid-path validation and warning paths are preserved, and no orphaned symbols or dangling references remain. The .aspire/settings.json sentinel that TemporaryWorkspace.CreateForCli plants still serves its separate ConfigurationHelper.GetConfigRootDirectory purpose. The main consideration for a human reviewer is that this removes a guard (and its test coverage) that #18683 added to prevent stale parent-directory config from contaminating results, so confirming the revert is intended and does not reintroduce that problem is worthwhile.

Reviewed changes

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

File Description
src/Aspire.Cli/Projects/ProjectLocator.cs Removes the walk-stop guard/return null; statements so the directory walk again continues to parent directories when no AppHost path is configured at the current level.
tests/Aspire.Cli.Tests/Projects/ProjectLocatorTests.cs Deletes the two unit tests that verified the now-removed walk-stop behavior.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Tests selector (audit mode)

The full test matrix and all jobs still run in audit mode. The tests and jobs below are what selective CI would run under enforcement.

2 / 99 test projects · 5 jobs, from 2 changed files.

Selected test projects (2 / 99)

Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests

Selected jobs (5)

cli-starter, deployment-e2e, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

📦 affected project Aspire.Cli
→ 1 test: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.Tests/Projects/ProjectLocatorTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

Job reasons

Job Triggered by
cli-starter • affected project Aspire.Cli
• selected test Aspire.Cli.Tests
deployment-e2e affected project Aspire.Cli
extension-e2e • src/Aspire.Cli/Projects/ProjectLocator.cs, tests/Aspire.Cli.Tests/Projects/ProjectLocatorTests.cs
• affected project Aspire.Cli
polyglot affected project Aspire.Cli
typescript-api-compat affected project Aspire.Cli

Selection computed for commit 88032ec.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@radical

Copy link
Copy Markdown
Member

[automated] The revert itself looks clean — it's the exact inverse of the ProjectLocator.cs portion of #18683 and correctly restores the forgiving walk-up. One thing worth calling out before this lands: it removes the only two tests near this behavior, but those two tests were non-guards, and nothing positive replaces them.

Both deleted tests plant a parent config that points at Stale.csproj but never create that file:

await File.WriteAllTextAsync(staleConfigPath, """{ "appHost": { "path": "Stale.csproj" } }""");
// ...
Assert.Null(foundAppHost);

Under the reverted (walk-past) behavior the walk does reach the parent, resolves Stale.csproj, finds it doesn't exist, and returns null anyway — so Assert.Null passes with or without the walk-stop. They never actually exercised the stop, so deleting them loses no real coverage. But that also means there's now no test asserting the intended walk-past behavior this PR is restoring — the exact behavior that regressed in #18683.

Suggestion: add positive guards that would fail if the walk-stop were ever reintroduced. Two that map directly to the two reverted branches (aspire.config.json and legacy .aspire/settings.json):

[Fact]
public async Task GetAppHostFromSettings_AspireConfigJsonWithoutAppHostPath_ContinuesWalkingToParentConfig()
{
    // A common real case: a minimal per-directory config such as { "channel": "daily" }
    // with the actual AppHost configured in a parent directory. The walk must not stop
    // at the child config just because it has no appHost.path.
    using var workspace = TemporaryWorkspace.CreateForCli(outputHelper);

    var parentDir = workspace.WorkspaceRoot.CreateSubdirectory("parent");
    var appHostFile = new FileInfo(Path.Combine(parentDir.FullName, "AppHost.csproj"));
    await File.WriteAllTextAsync(appHostFile.FullName, "Not a real apphost");
    await File.WriteAllTextAsync(
        Path.Combine(parentDir.FullName, AspireConfigFile.FileName),
        """{ "appHost": { "path": "AppHost.csproj" } }""");

    var childDir = parentDir.CreateSubdirectory("child");
    await File.WriteAllTextAsync(
        Path.Combine(childDir.FullName, AspireConfigFile.FileName),
        """{ "channel": "daily" }""");

    var executionContext = CreateExecutionContext(childDir);
    var projectLocator = CreateProjectLocator(executionContext);

    var foundAppHost = await projectLocator.GetAppHostFromSettingsAsync(CancellationToken.None).DefaultTimeout();

    Assert.Equal(appHostFile.FullName, foundAppHost?.FullName);
}

[Fact]
public async Task GetAppHostFromSettings_LegacySettingsWithoutAppHostPath_ContinuesWalkingToParentConfig()
{
    // Same guard for the legacy .aspire/settings.json branch.
    using var workspace = TemporaryWorkspace.CreateForCli(outputHelper);

    var parentDir = workspace.WorkspaceRoot.CreateSubdirectory("parent");
    var appHostFile = new FileInfo(Path.Combine(parentDir.FullName, "AppHost.csproj"));
    await File.WriteAllTextAsync(appHostFile.FullName, "Not a real apphost");
    await File.WriteAllTextAsync(
        Path.Combine(parentDir.FullName, AspireConfigFile.FileName),
        """{ "appHost": { "path": "AppHost.csproj" } }""");

    var childDir = parentDir.CreateSubdirectory("child");
    var childSettingsDir = childDir.CreateSubdirectory(".aspire");
    await File.WriteAllTextAsync(Path.Combine(childSettingsDir.FullName, "settings.json"), "{}");

    var executionContext = CreateExecutionContext(childDir);
    var projectLocator = CreateProjectLocator(executionContext);

    var foundAppHost = await projectLocator.GetAppHostFromSettingsAsync(CancellationToken.None).DefaultTimeout();

    Assert.Equal(appHostFile.FullName, foundAppHost?.FullName);
}

Two notes on the shape:

  • These nest parent/ and parent/child/ inside the workspace and root the execution context at child, so the walk finds parent/AppHost.csproj before it ever reaches the workspace-root sentinel. That deliberately avoids mutating WorkspaceRoot.Parent! (the shared Workspace/ temp dir) the way the deleted tests did — under the restored walk-past behavior, sibling tests' walks can traverse that shared parent, so writing config there is a cross-test contamination hazard.
  • Compare FileInfo.FullName, not the FileInfo objects — FileInfo doesn't override Equals, so Assert.Equal(fileInfo, result) would be reference-equality and always fail. (Matches the existing style at line 79/221.)

Optionally, a "parent config points at a nonexistent path → null" test documents the exact scenario the deleted tests fumbled.

Note: this code is a sketch grounded in the existing test conventions in this file; it hasn't been run against the branch yet — worth a quick local run before committing.

@davidfowl

Copy link
Copy Markdown
Collaborator

No test caught this originally?

@JamesNK

Copy link
Copy Markdown
Member Author

There is no tests for this behavior one way or another. Reverting it because it doesn't need to change, and I don't know whether it is a bug fix or not.

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.

Approving since this is just the revert of an unintended change. We should do a follow up that adds tests to catches regressions agains the behavior (assuming it is the behavior we want)

@JamesNK
James Newton-King (JamesNK) merged commit d8d9093 into main Jul 9, 2026
667 of 670 checks passed
@JamesNK
James Newton-King (JamesNK) deleted the jamesnk/revert-project-locator-walk-stop branch July 9, 2026 23:51
@github-actions github-actions Bot added this to the 13.5 milestone Jul 9, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

docs_optional → internal_refactor

No signals triggered (signal_count = 0). This PR reverts internal ProjectLocator walk-stop behavior introduced in #18683 — removing the aspireConfig is not null wrapper and the early return null;, along with two associated unit tests. No new public types, options, CLI flags, or user-facing strings were added or changed. Both changed files (src/Aspire.Cli/Projects/ProjectLocator.cs and tests/Aspire.Cli.Tests/Projects/ProjectLocatorTests.cs) are internal implementation and test code. No documentation update is required.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants