Pester icon indicating copy to clipboard operation
Pester copied to clipboard

Shorten TestDrive directory name

Open splatteredbits opened this issue 3 years ago • 6 comments

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 Request to mark it as a draft. PR can be marked Ready for review when it's ready.
  • [ ] Tests are added/update (if required)
  • [ ] Documentation is updated/added (if required)

splatteredbits avatar Aug 11 '22 18:08 splatteredbits

~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.

nohwnd avatar Oct 02 '22 11:10 nohwnd

@fflaten any opinion on shortening the names?

Maybe we should also unify this with Test Registry?

nohwnd avatar Oct 02 '22 11:10 nohwnd

@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 avatar Oct 02 '22 11:10 fflaten

@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.

splatteredbits avatar Nov 09 '22 22:11 splatteredbits

@fflaten ~I think we put them in our folder Temp/Pester/ ?~ And same in registry? HKCU/../Pester/ and we double check that what we are creating does not exist yet, so imho it should be all okay.

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?

nohwnd avatar Nov 10 '22 06:11 nohwnd

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. 🙂

fflaten avatar Nov 10 '22 08:11 fflaten