Shorten TestDrive directory name
PR Summary
Pester currently uses a full GUID as its temp directory name, which uses 36 characters. This contributes to test errors when paths used in tests exceed the Windows max path of 260 characters.
The [IO.Path]::GetTempFileName() only uses 4 characters for the unique/random part of its filename. Pester should follow the same pattern and only use a temp directory with 4 characters.
Let's not use a GUID anymore, either. A GUID, when converted to a string, only uses hex characters: 0-9 and a-f, which gives us 65,536 unique possible values. Instead, lets use the first four characters of the file name returned by [IO.Path]::GetRandomFileName(). It generates a name that uses all letters of the alphabet and the numbers 0-9, which gives us 36^4 = 1,679,616 possible values.
Fix #2238
PR Checklist
- [x] PR has meaningful title
- [ ] Summary describes changes
- [ ] PR is ready to be merged
- If not, use the arrow next to
Create Pull Requestto mark it as a draft. PR can be markedReady for reviewwhen it's ready.
- If not, use the arrow next to
- [ ] Tests are added/update (if required)
- [ ] Documentation is updated/added (if required)
~Added good first issue to this. It should not be complex to replace the way the name is generated with the shortened ID. But what needs to be kept in place is the check that the item does not already exist.~
Not sure why I thought this is an ask for feature, rather than PR.
@fflaten any opinion on shortening the names?
Maybe we should also unify this with Test Registry?
@fflaten any opinion on shortening the names?
Sounds good, but 4 chars sounds a bit low without a Pester-prefix
Maybe we should also unify this with Test Registry?
Yes
@fflaten any opinion on shortening the names?
Sounds good, but 4 chars sounds a bit low without a Pester-prefix
The current test directory name doesn't have a Pester-prefix, it uses an inscrutable Guid. The object is to use as short a name as possible to avoid path too long issues. Adding a prefix would partially defeat that.
@fflaten ~I think we put them in our folder Temp/Pester/
We should just make it the same for registry, if that did not happen yet?
Update: I thought wrong, no Pester folder in TEMP. But we do doublecheck for conflicts though, so still okay?
The current test directory name doesn't have a Pester-prefix, it uses an inscrutable Guid.
Currently if cleanup doesn't run as expected (ex. cancelled script), then those guid-folders will be unidentifiable. "What keeps filling up my temp and is it safe to delete?" By adding a source hint like pester somewhere in the path we'd tackle that while also reducing risk of conflict with as few chars as 4. But it's not a critical issue and was just a suggestion as we rarely touch this.
The object is to use as short a name as possible to avoid path too long issues. Adding a prefix would partially defeat that.
10 vs 36 is still a solid improvement. If the last 6 chars breaks your solution then you're one long username from breaking and should modify the test code itself. So this PR is mostly a quality improvement and not a "every char counts" critical fix imo. 🙂