tests/DiskUsage.Tests.ps1

$moduleRoot = Split-Path -Parent $PSScriptRoot
Import-Module (Join-Path $moduleRoot 'Octa.psd1') -Force

Describe 'Show-OctaDiskUsage' {
    It 'never changes registry or service state (SC-014-style non-mutation guarantee)' {
        # StartType (persistent config), not Status - see the same note in DiskHealth.Tests.ps1
        # for the real, reproduced-on-purpose reason a raw Status diff is the wrong check here.
        $before = Get-Service | Select-Object Name, StartType
        { Show-OctaDiskUsage -Path $env:TEMP -Top 3 | Out-Null } | Should Not Throw
        $after = Get-Service | Select-Object Name, StartType
        (Compare-Object $before $after -Property Name, StartType) | Should Be $null
    }

    It 'reports real, non-negative sizes for at most -Top folders' {
        $result = @(Show-OctaDiskUsage -Path $env:USERPROFILE -Top 5)
        ($result.Count -le 5) | Should Be $true
        foreach ($r in $result) {
            $r.SizeBytes | Should BeGreaterThan -1
        }
    }

    It 'reports an empty list for a path with no subfolders, without throwing' {
        $emptyDir = Join-Path $env:TEMP ('octa-diskusage-empty-{0}' -f [guid]::NewGuid())
        New-Item -ItemType Directory -Path $emptyDir -Force | Out-Null
        try {
            $result = @(Show-OctaDiskUsage -Path $emptyDir -Top 10)
            $result.Count | Should Be 0
        }
        finally {
            Remove-Item -Path $emptyDir -Recurse -Force -ErrorAction SilentlyContinue
        }
    }
}