Skip to content

Simplify ProfilePathInfo and ensure profile variable is set during startup#2287

Open
JustinGrote wants to merge 5 commits into
mainfrom
fix/alwaysShowProfileVariable
Open

Simplify ProfilePathInfo and ensure profile variable is set during startup#2287
JustinGrote wants to merge 5 commits into
mainfrom
fix/alwaysShowProfileVariable

Conversation

@JustinGrote
Copy link
Copy Markdown
Collaborator

@JustinGrote JustinGrote commented May 13, 2026

PR Summary

Refactor the ProfilePathInfo structure to use a record type for simplicity. Ensure the profile variable is set during the startup process, regardless of whether profiles are loaded. This is to make behavior consistent with ConsoleHost and pwsh -noprofile ($profile is available regardless of if profiles were actually loaded or not)

PR Context

This change improves the clarity and efficiency of profile path handling and guarantees that the $PROFILE variable is always set, enhancing the initialization process for users.

Copilot AI review requested due to automatic review settings May 13, 2026 18:43
@JustinGrote JustinGrote self-assigned this May 13, 2026
Copy link
Copy Markdown
Collaborator Author

@JustinGrote JustinGrote left a comment

Choose a reason for hiding this comment

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

Validated working:
image.png

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 refactors profile path handling and changes host startup so $PROFILE is initialized even when profile scripts are not loaded.

Changes:

  • Splits profile handling into setting $PROFILE and loading profile scripts.
  • Adds startup flow to always set the profile variable and only conditionally load profile scripts.
  • Converts ProfilePathInfo into a positional record struct and updates tests for profile-variable behavior.

Reviewed changes

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

Show a summary per file
File Description
test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs Updates and adds tests for profile loading and $PROFILE initialization.
src/PowerShellEditorServices/Services/PowerShell/Utility/PowerShellExtensions.cs Separates $PROFILE setup from profile script loading.
src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs Calls profile-variable setup during startup before optional profile loading.
src/PowerShellEditorServices/Hosting/HostStartupInfo.cs Refactors ProfilePathInfo into a record struct.
src/PowerShellEditorServices.Hosting/Internal/EditorServicesRunner.cs Always creates a ProfilePathInfo from configured profile paths.
Comments suppressed due to low confidence (1)

src/PowerShellEditorServices/Services/PowerShell/Utility/PowerShellExtensions.cs:215

  • This repeats the same null-sensitive PSObject.AsPSObject call used when setting $PROFILE. If the profile object is unavailable and the paths are null, enabling profile loading will still fail here even if setting the variable is made tolerant; reuse the normalized profile value or coalesce CurrentUserCurrentHost before wrapping it.
            PSObject profileVariable = PSObject.AsPSObject(profilePaths.CurrentUserCurrentHost);

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

Comment thread src/PowerShellEditorServices/Hosting/HostStartupInfo.cs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/PowerShellEditorServices/Hosting/HostStartupInfo.cs
Copy link
Copy Markdown
Contributor

Copilot AI commented May 13, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • 1k9vsblobprodcus379.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --no-restore -warnaserror (dns block)
  • 1p7vsblobprodcus324.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • 4myvsblobprodcus32.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • 4zjvsblobprodcus390.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • 7tjvsblobprodcus341.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --no-restore -warnaserror (dns block)
  • 8xbvsblobprodcus382.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • c78vsblobprodcus322.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --no-restore -warnaserror (dns block)
  • cflvsblobprodcus383.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • ckzvsblobprodcus347.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • dlbvsblobprodcus316.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • e7bvsblobprodcus348.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • fdpvsblobprodcus345.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • gervsblobprodcus329.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • jd4vsblobprodcus366.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • jrqvsblobprodcus343.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • kh4vsblobprodcus325.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --no-restore -warnaserror (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --no-restore -warnaserror (dns block)
  • m6xvsblobprodcus342.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --no-restore -warnaserror (dns block)
  • o3svsblobprodcus318.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • ofvvsblobprodcus315.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • p2ovsblobprodcus312.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • pdfvsblobprodcus380.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • sqdvsblobprodcus333.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • tphvsblobprodcus375.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • ukkvsblobprodcus352.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • uy6vsblobprodcus34.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build --no-restore -warnaserror (dns block)
  • vwvvsblobprodcus334.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)
  • xupvsblobprodcus332.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@JustinGrote
Copy link
Copy Markdown
Collaborator Author

@copilot fix test:
[xUnit.net 00:00:36.22] CanHandleMissingProfilePaths [FAIL]
Failed CanHandleMissingProfilePaths [104 ms]
Error Message:
Assert.Equal() Failure: Values differ
Expected:
Actual:
Stack Trace:
at PowerShellEditorServices.Test.Session.PsesInternalHostTests.<>c__DisplayClass8_0.b__0(PowerShell pwsh, CancellationToken _) in /home/runner/work/PowerShellEditorServices/PowerShellEditorServices/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs:line 122
at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousPSDelegateTask.Run(CancellationToken cancellationToken) in /home/runner/work/PowerShellEditorServices/PowerShellEditorServices/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousDelegateTask.cs:line 95
at Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution.SynchronousTask`1.ExecuteSynchronously(CancellationToken executorCancellationToken) in /home/runner/work/PowerShellEditorServices/PowerShellEditorServices/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousTask.cs:line 92
--- End of stack trace from previous location ---
at PowerShellEditorServices.Test.Session.PsesInternalHostTests.CanHandleMissingProfilePaths() in /home/runner/work/PowerShellEditorServices/PowerShellEditorServices/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs:line 114
--- End of stack trace from previous location ---

auto-merge was automatically disabled May 14, 2026 01:26

Head branch was pushed to by a user without write access

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

@copilot fix test:
[xUnit.net 00:00:36.22] CanHandleMissingProfilePaths [FAIL]
Failed CanHandleMissingProfilePaths [104 ms]
...

Fixed in 8d5726d. SessionStateProxy.GetVariable("PROFILE") returns a PSObject (not a raw string), so Assert.Equal("", psObject) failed even though both displayed as empty. Added .ToString() to unwrap the PSObject before the comparison.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • 1k9vsblobprodcus379.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • 4myvsblobprodcus32.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • 4zjvsblobprodcus390.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • 7tjvsblobprodcus341.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • 8xbvsblobprodcus382.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • c78vsblobprodcus322.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • dlbvsblobprodcus316.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • e7bvsblobprodcus348.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • gervsblobprodcus329.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • jd4vsblobprodcus366.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • jrqvsblobprodcus343.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • kh4vsblobprodcus325.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • m6xvsblobprodcus342.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • o3svsblobprodcus318.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • ofvvsblobprodcus315.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • pdfvsblobprodcus380.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • sqdvsblobprodcus333.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • tphvsblobprodcus375.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • ukkvsblobprodcus352.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • uy6vsblobprodcus34.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)
  • xupvsblobprodcus332.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet test test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj --filter CanHandleMissingProfilePaths -f net8.0 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@JustinGrote
Copy link
Copy Markdown
Collaborator Author

@andyleejordan this should be good to go, I don't think the themis test failure is related, I suspect it has a race condition.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants