From c8aa10f4e090818d083d965b44fc733b8d6c9830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexey=20ALERT=20Rubash=D1=91ff?= Date: Thu, 27 Aug 2026 19:37:35 +0300 Subject: [PATCH] fix: show what a Dev Drive name looks like, and say it is not the file name The name question already explained what the name is for, and was still answered with the .vhdx file name typed three questions earlier. It now carries a worked example, and quotes the default so it does not run into the sentence. The line saying the name is not the file name appears only in virtual disk mode: in the other two modes no .vhdx exists in the run, so naming one would invent it. The mode comes from the script body, which is the only thing that knows it. Closes #106 Co-Authored-By: Claude Opus 5 --- dev_drive.Tests.ps1 | 37 ++++++++++++++++++++++++++++++++++++- dev_drive.ps1 | 15 +++++++++++---- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/dev_drive.Tests.ps1 b/dev_drive.Tests.ps1 index 20dc5f9..0d538df 100644 --- a/dev_drive.Tests.ps1 +++ b/dev_drive.Tests.ps1 @@ -747,6 +747,17 @@ Describe 'The script itself' { $formatAt | Should -BeGreaterThan $planAt } + It 'tells the name question which mode the run is in, rather than deciding for it' { + # The extra line belongs to virtual disk mode, and the body is the only thing that knows. + $call = @($script:Ast.FindAll({ + param($node) + $node -is [System.Management.Automation.Language.CommandAst] -and + $node.GetCommandName() -eq 'Request-DevDriveLabel' + }, $true)) + $call.Count | Should -Be 1 + $call[0].Extent.Text | Should -Match '-VhdxMode:\(\$mode -eq "Vhdx"\)' + } + It 'reads the name back off the volume instead of reporting the one it sent' { $content = Get-Content -Path $script:ScriptPath -Raw $formatAt = $content.IndexOf('Format-Volume -DriveLetter $devLetter') @@ -1832,6 +1843,30 @@ Describe 'Request-DevDriveLabel' { Request-DevDriveLabel -Default 'DevDrive' -MaxLength 32 | Should -Be 'DevDrive' } + It 'shows what a name looks like, rather than only describing one' { + # The question already said what the name is for, and was still answered with a file name. + Mock Read-Host { '' } + Request-DevDriveLabel -Default 'DevDrive' -MaxLength 32 | Out-Null + Should -Invoke Write-Host -ParameterFilter { $Object -match 'like "Projects \(D:\)"' } + } + + It 'quotes the name the Enter key gives, so it does not run into the sentence' { + Mock Read-Host { '' } + Request-DevDriveLabel -Default 'Projects' -MaxLength 32 | Out-Null + Should -Invoke Read-Host -ParameterFilter { $Prompt -match 'press Enter for "Projects"' } + } + + It 'says the name is not the file name only where a file was named, in ' -TestCases @( + @{ Mode = 'virtual disk mode'; Vhdx = $true; Expected = 1 } + @{ Mode = 'the other modes'; Vhdx = $false; Expected = 0 } + ) { + # In the other two modes no .vhdx exists in the run at all, so mentioning one invents it. + Mock Read-Host { '' } + Request-DevDriveLabel -Default 'DevDrive' -MaxLength 32 -VhdxMode:$Vhdx | Out-Null + Should -Invoke Write-Host -Times $Expected -Exactly ` + -ParameterFilter { $Object -match 'not the file name' } + } + It 'keeps asking until the answer is one the file system can take' { $script:answers = @('Dev:Drive', ('a' * 40), "bad`0name", 'Projects') $script:index = 0 @@ -1883,7 +1918,7 @@ Describe 'Request-DevDriveLabel' { It 'offers the name on the Enter key in the prompt itself' { Mock Read-Host { param($Prompt) $script:asked = $Prompt; return '' } Request-DevDriveLabel -Default 'MyDrive' -MaxLength 32 | Out-Null - $script:asked | Should -Match 'press Enter for MyDrive' + $script:asked | Should -Match 'press Enter for "MyDrive"' } } diff --git a/dev_drive.ps1 b/dev_drive.ps1 index 6d49a70..4e8b207 100644 --- a/dev_drive.ps1 +++ b/dev_drive.ps1 @@ -1863,13 +1863,19 @@ function Request-DevDriveLabel { <# The name the volume will carry. Enter keeps the one offered, as every other prompt here does. #> param( [Parameter(Mandatory)][string]$Default, - [int]$MaxLength = $script:DevDriveLabelMaxLength + [int]$MaxLength = $script:DevDriveLabelMaxLength, + [switch]$VhdxMode ) - Write-Host "`nThe Dev Drive carries a name, which is what File Explorer shows beside its letter." -ForegroundColor Cyan + Write-Host "`nThe Dev Drive carries a name, which is what File Explorer shows beside its letter, like `"Projects (D:)`"." -ForegroundColor Cyan + if ($VhdxMode) { + # Only here: this question follows the one that asked for a file path, and was answered with + # it. In the other modes no .vhdx exists, so naming one would invent it. + Write-Host "This is not the file name; the `".vhdx`" keeps the name you gave it." -ForegroundColor Cyan + } while ($true) { - $answer = Read-Host "Enter a name for the Dev Drive, or press Enter for $Default" + $answer = Read-Host "Enter a name for the Dev Drive, or press Enter for `"$Default`"" $verdict = Resolve-DevDriveLabelInput -Answer $answer -Default $Default -MaxLength $MaxLength if ($verdict.Rejection -eq 'TooLong') { @@ -2699,7 +2705,8 @@ if ($mode -eq "FreeSpace") { } # Asked here rather than in each mode: the name is the same question whatever created the volume. -$DevDriveLabel = Request-DevDriveLabel -Default $DevDriveDefaultLabel -MaxLength $DevDriveLabelMaxLength +$DevDriveLabel = Request-DevDriveLabel -Default $DevDriveDefaultLabel -MaxLength $DevDriveLabelMaxLength ` + -VhdxMode:($mode -eq "Vhdx") # Read before the question, not after: on a machine with this setting the answer is not a preference. $WritePolicy = Get-FixedDriveWritePolicy