New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InitialSessionState: Add support for configuring initial working directory #21446
base: master
Are you sure you want to change the base?
Conversation
8df7cd9
to
e1495e1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codefactor tests look like they need fixing, the PowerShell team won't really consider PRs ready until CI is green.
There should also be tests added for this new API to verify the new changes added. We should be testing things like
- We can set it to a custom location
- UNC paths work (Windows only and can use
\\localhost\...
) - Can set to a root of another drive, i.e.
Temp
and/orEnv
- Fails on invalid path (missing and invalid drive)
e1495e1
to
41f2506
Compare
I fixed the two issues mentioned in code review.
All of the codefactor issues are doc only, and most of the surrounding code is also breaking the rules. If you want me to fix the tests, I can, but I don't see any benefit from it. :)
If the WG wants me to add unit tests, I can, but none of the other properties on |
Unfortunately it's part of the CI tests, it needs to be fixed for it to be considered ready. It's part of the style tests of PowerShell and the documentation even derives what will be part of the docs when the it is live.
That doesn't mean you shouldn't add tests. Tests are critical to show that the code you've added works and also ensures there are no regressions in the future. I'm not part of the WG but you should always add tests to anything you touch regardless of whether or not there are existing ones. |
cf9f464
to
3402147
Compare
…or adding working directory configuration support (see next commit) Behavior should be unchanged, except that the catch-all `try` block was shortened to the relevant part of the function – exceptions thrown by the rest of the function are unrelated to drive and location configuration and indicate serious issues which should probably be propagated.
b149256
to
271eb67
Compare
271eb67
to
9028815
Compare
I removed the exception docstrings, which fixes most of the codefactor issues. One of the remaining issues does not make any sense (spacing around I also added a few unit tests for the I consider the PR ready to review.
Maybe if PowerShell maintainers heeded that advice, I wouldn't be finding PowerShell bugs every other week, but I digress. |
The rules that PowerShell uses don't like the
That's why adding tests are critical, we can't do much about existing tests but we can be sure that new features and fixes being added now have tests (where feasible). |
I don't believe the Pester test failures are related to my PR. |
PR Summary
Add support for configuring the initial working directory of a
Runspace
using a newWorkingDirectory
property onInitialSessionState
.I recommend reviewing the 2 commits separately, first one refactors the method without major changes in behavior, second one implements the feature.
PR Context
Resolves #17603.
Design questions
@vexx32 I have 2 questions about the design of the feature and related functionality:
1) If the working directory is invalid (does not exist, unknown drive,...), I propagate the exception back to the caller, without checking
ThrowOnRunspaceOpenError
. Should I add a check and suppress the exception if it's not set? My reasoning is that if a caller explicitly sets a custom working directory, he probably expects it to be valid and get notified when it's not, even when he's not interested in other initialization errors, but it's inconsistent with how other errors are handled.2) In the original implementation, there's a check for
if (context.EngineSessionState.ProviderCount > 0)
and if there are no providers, the function does not do anything, leaving the current drive and location unset. However, this results in subsequent accesses to the location throwing confusing internal errors (even from scripts running inside theRunspace
):For now, I've kept the original behavior, but it seems cleaner to me to throw an exception if there are no providers defined to avoid the confusing errors later on. I can either modify the behavior in a subsequent commit, or I can create a new PR after this one is done, just wanted to hear your opinion.
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).