Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Nov 4, 2024
1 parent b1c84b4 commit f861a36
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .aider.conf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ git: false
#code-theme: "monokai"

## edit the whole file
edit-format: whole
#edit-format: diff

## yesss
yes-always: true
Expand Down
50 changes: 47 additions & 3 deletions .aider/aider.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,62 @@ function Update-PesterTest {
if ($PSCmdlet.ShouldProcess($filename, "Running tests on $filename")) {
if ($script:xplat -contains $cmdName) {
Write-Warning "Running integration and unit tests for $filename"
aider --test --test-cmd "/workspace/tests/Configs/aider.test.ps1 -TestIntegration -ScriptAnalyzer $filename"
#aider --test --test-cmd "/workspace/tests/Configs/aider.test.ps1 -TestIntegration -ScriptAnalyzer $filename"
Test-Command -Path $filename -TestIntegration -ScriptAnalyzer
} else {
Write-Warning "Running unit tests for $filename"
aider --test --test-cmd "/workspace/tests/Configs/aider.test.ps1 $filename"
#aider --test --test-cmd "/workspace/tests/Configs/aider.test.ps1 $filename"
Test-Command -Path $filename -ScriptAnalyzer
}
}
}
}
}
}

function Test-Command {
[CmdletBinding()]
param (
[Parameter(Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[Alias('FullName')]
[string[]]$Path,
[ValidateSet('None', 'Normal', 'Detailed', 'Diagnostic')]
[string]$Show = "Normal",
[switch]$PassThru,
[switch]$TestIntegration,
[switch]$Coverage,
[switch]$DependencyCoverage,
[switch]$ScriptAnalyzer,
[switch]$NoReimport
)
process {
$cmdArgs = @()

# Build command line arguments
if ($PSBoundParameters.ContainsKey('Path')) {
$cmdArgs += $Path
}
if ($PSBoundParameters.ContainsKey('Show')) {
$cmdArgs += "-Show"
$cmdArgs += $Show
}
if ($PassThru) { $cmdArgs += "-PassThru" }
if ($TestIntegration) { $cmdArgs += "-TestIntegration" }
if ($Coverage) { $cmdArgs += "-Coverage" }
if ($DependencyCoverage) { $cmdArgs += "-DependencyCoverage" }
if ($ScriptAnalyzer) { $cmdArgs += "-ScriptAnalyzer" }
if ($NoReimport) { $cmdArgs += "-NoReimport" }

# Convert array to space-separated string
$cmdString = $cmdArgs -join ' '

Write-Warning "Running tests with command: $cmdString"
# Call aider with the constructed command string
# add a file!!
# it stops apparently, do while or 10 times
aider --test --test-cmd "/workspace/tests/Configs/aider.test.ps1 $cmdString" --edit-format diff --file $Path
}
}

function Repair-Error {
<#
Expand Down Expand Up @@ -679,7 +723,7 @@ function Invoke-Aider {
if ($VerbosePreference -eq 'Continue') {
Write-Verbose "Executing: aider $($arguments -join ' ')"
}
$arguments | write-warning

aider @arguments
}
}
Expand Down
98 changes: 60 additions & 38 deletions private/testing/Invoke-ManualPester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function Invoke-ManualPester {
WarningAction = "SilentlyContinue"
Global = $true
}
Import-Module @splat
Import-Module @splat *> $null
}

function Get-CoverageIndications($Path, $ModuleBase) {
Expand Down Expand Up @@ -166,7 +166,7 @@ function Invoke-ManualPester {
# exclude always used functions ?!
if ($f -in ('Connect-DbaInstance', 'Select-DefaultView', 'Stop-Function', 'Write-Message')) { continue }
# can I find a correspondence to a physical file (again, on the convenience of having Get-DbaFoo.ps1 actually defining Get-DbaFoo)?
$res = $allfiles | Where-Object { $_.Name.Replace('.ps1', '') -eq $f }
$res = $allfiles | Where-Object { $PSItem.Name.Replace('.ps1', '') -eq $f }
if ($res.count -gt 0) {
$testpaths += $res.FullName
}
Expand All @@ -189,53 +189,75 @@ function Invoke-ManualPester {
}
}

$invokeFormatterVersion = (Get-Command Invoke-Formatter -ErrorAction SilentlyContinue).Version
$HasScriptAnalyzer = $null -ne $invokeFormatterVersion
$MinimumPesterVersion = [Version] '4.0.0.0' # Because this is when -Show was introduced
$MaximumPesterVersion = [Version] '6.0.0.0' # Because we have either pester4 or pester5 tests
$PesterVersion = (Get-Command Invoke-Pester -ErrorAction SilentlyContinue).Version
$HasPester = $null -ne $PesterVersion
$ScriptAnalyzerCorrectVersion = '1.18.2'

if (!($HasScriptAnalyzer)) {
Write-Warning "Please install PSScriptAnalyzer"
Write-Warning " Install-Module -Name PSScriptAnalyzer -RequiredVersion '$ScriptAnalyzerCorrectVersion'"
Write-Warning " or go to https://github.com/PowerShell/PSScriptAnalyzer"
} else {
if ($invokeFormatterVersion -ne $ScriptAnalyzerCorrectVersion) {
Remove-Module PSScriptAnalyzer
try {
Import-Module PSScriptAnalyzer -RequiredVersion $ScriptAnalyzerCorrectVersion -ErrorAction Stop
} catch {
Write-Warning "Please install PSScriptAnalyzer $ScriptAnalyzerCorrectVersion"
Write-Warning " Install-Module -Name PSScriptAnalyzer -RequiredVersion '$ScriptAnalyzerCorrectVersion'"
}
# Version requirements
$ScriptAnalyzerRequiredVersion = '1.18.2'
$MinimumPesterVersion = [Version]'4.0.0.0'
$MaximumPesterVersion = [Version]'6.0.0.0'
$TargetPesterVersion = [Version]'5.3.3'

# Get all required modules at once (single expensive operation)
$availableModules = @{}
$foundModules = Get-Module -Name Pester, PSScriptAnalyzer -ListAvailable

foreach ($module in $foundModules) {
if (!$availableModules[$module.Name]) {
$availableModules[$module.Name] = @()
}
$availableModules[$module.Name] += $module
}

if (!($HasPester)) {
Write-Warning "Please install Pester"
Write-Warning " Install-Module -Name Pester -Force -SkipPublisherCheck"
Write-Warning " or go to https://github.com/pester/Pester"
# Sort versions once
$moduleNames = @($availableModules.Keys)
foreach ($name in $moduleNames) {
$availableModules[$name] = $availableModules[$name] | Sort-Object Version -Descending
}
if ($PesterVersion -lt $MinimumPesterVersion) {
Write-Warning "Please update Pester to at least 3.4.5"
Write-Warning " Install-Module -Name Pester -MaximumVersion '4.10' -Force -SkipPublisherCheck"
Write-Warning " or go to https://github.com/pester/Pester"

# If target Pester not found, use highest 5.x version
if (-not ($availableModules.Pester | Where-Object Version -eq $TargetPesterVersion)) {
$TargetPesterVersion = ($availableModules.Pester | Where-Object { $_.Version.Major -eq 5 } | Select-Object -First 1).Version
}
if ($PesterVersion -gt $MaximumPesterVersion) {
Write-Warning "Please get Pester to the 5.* release"
Write-Warning " Install-Module -Name Pester -MaximumVersion '5.6.1' -Force -SkipPublisherCheck"
Write-Warning " or go to https://github.com/pester/Pester"

# PSScriptAnalyzer checks
if (-not $availableModules.PSScriptAnalyzer) {
Write-Warning "PSScriptAnalyzer not found. Please install with:"
Write-Warning "Install-Module -Name PSScriptAnalyzer -RequiredVersion '$ScriptAnalyzerRequiredVersion'"
Write-Warning "or go to https://github.com/PowerShell/PSScriptAnalyzer"
return
}

if (($HasPester -and $HasScriptAnalyzer -and ($PesterVersion -ge $MinimumPesterVersion) -and ($PesterVersion -lt $MaximumPesterVersion) -and ($invokeFormatterVersion -eq $ScriptAnalyzerCorrectVersion)) -eq $false) {
Write-Warning "Exiting..."
$stopProcess = $true
$importedAnalyzerModule = Get-Module -Name PSScriptAnalyzer
if (-not $importedAnalyzerModule -or $importedAnalyzerModule.Version.ToString() -ne $ScriptAnalyzerRequiredVersion) {
if ($importedAnalyzerModule) { Remove-Module PSScriptAnalyzer -Force }
try {
Import-Module PSScriptAnalyzer -RequiredVersion $ScriptAnalyzerRequiredVersion -ErrorAction Stop
} catch {
Write-Warning "Failed to import PSScriptAnalyzer $ScriptAnalyzerRequiredVersion"
Write-Warning "Please install correct version: Install-Module -Name PSScriptAnalyzer -RequiredVersion '$ScriptAnalyzerRequiredVersion'"
return
}
}

# Pester checks
if (-not $availableModules.Pester) {
Write-Warning "Pester not found. Please install with:"
Write-Warning "Install-Module -Name Pester -Force -SkipPublisherCheck"
Write-Warning "or go to https://github.com/pester/Pester"
return
}

$importedPesterModule = Get-Module -Name Pester
$highestVersion = $availableModules.Pester[0].Version

if ($highestVersion -lt $MinimumPesterVersion -or $highestVersion -gt $MaximumPesterVersion) {
Write-Warning "Pester version must be between $MinimumPesterVersion and $MaximumPesterVersion"
Write-Warning "Install-Module -Name Pester -RequiredVersion $TargetPesterVersion -Force -SkipPublisherCheck"
return
}

if ($importedPesterModule -and $importedPesterModule.Version -ne $TargetPesterVersion) {
Remove-Module Pester -Force
Import-Module Pester -RequiredVersion $TargetPesterVersion -Force
}
}
process {
if ($stopProcess) {
Expand Down
9 changes: 8 additions & 1 deletion tests/Configs/aider.test.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
Import-Module /workspace/dbatools.psm1
Invoke-ManualPester -NoReimport $args
$PSDefaultParameterValues['*:Passthru'] = $true
Invoke-ManualPester -NoReimport -ErrorAction Stop $args -OutVariable testResults #-edit-format diff # -editor-model

if ($testResults.FailedCount -gt 0) {
exit 1
} else {
exit 0
}

0 comments on commit f861a36

Please sign in to comment.